mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Rename renderTarget -> innerRenderTarget; Remove TextureDrawer
This commit is contained in:
parent
991adb7449
commit
a9aa1589de
@ -34,12 +34,8 @@ type TexturePart struct {
|
||||
Src Rect
|
||||
}
|
||||
|
||||
type TextureDrawer interface {
|
||||
DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error
|
||||
}
|
||||
|
||||
// DrawWholeTexture draws the whole texture.
|
||||
func DrawWholeTexture(r TextureDrawer, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
||||
func DrawWholeTexture(r *RenderTarget, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
||||
w, h := texture.Size()
|
||||
parts := []TexturePart{
|
||||
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
||||
|
@ -27,12 +27,12 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
|
||||
return nil, err
|
||||
}
|
||||
|
||||
screen, err := newRenderTarget(screenWidth, screenHeight, gl.NEAREST)
|
||||
screen, err := newInnerRenderTarget(screenWidth, screenHeight, gl.NEAREST)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c := &graphicsContext{
|
||||
defaultR: &renderTarget{r, nil},
|
||||
defaultR: &innerRenderTarget{r, nil},
|
||||
screen: screen,
|
||||
screenScale: screenScale,
|
||||
}
|
||||
@ -40,8 +40,8 @@ func newGraphicsContext(screenWidth, screenHeight, screenScale int) (*graphicsCo
|
||||
}
|
||||
|
||||
type graphicsContext struct {
|
||||
screen *renderTarget
|
||||
defaultR *renderTarget
|
||||
screen *innerRenderTarget
|
||||
defaultR *innerRenderTarget
|
||||
screenScale int
|
||||
}
|
||||
|
||||
@ -65,7 +65,11 @@ func (c *graphicsContext) postUpdate() error {
|
||||
scale := float64(c.screenScale)
|
||||
geo := ScaleGeometry(scale, scale)
|
||||
clr := ColorMatrixI()
|
||||
if err := DrawWholeTexture(c.defaultR, c.screen.texture, geo, clr); err != nil {
|
||||
w, h := c.screen.texture.Size()
|
||||
parts := []TexturePart{
|
||||
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
||||
}
|
||||
if err := c.defaultR.DrawTexture(c.screen.texture, parts, geo, clr); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,12 @@ import (
|
||||
"math"
|
||||
)
|
||||
|
||||
type renderTarget struct {
|
||||
type innerRenderTarget struct {
|
||||
glRenderTarget *opengl.RenderTarget
|
||||
texture *Texture
|
||||
}
|
||||
|
||||
func newRenderTarget(width, height int, filter int) (*renderTarget, error) {
|
||||
func newInnerRenderTarget(width, height int, filter int) (*innerRenderTarget, error) {
|
||||
glTexture, err := opengl.NewTexture(width, height, filter)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -42,23 +42,18 @@ func newRenderTarget(width, height int, filter int) (*renderTarget, error) {
|
||||
}
|
||||
|
||||
texture := &Texture{glTexture}
|
||||
renderTarget := &renderTarget{glRenderTarget, texture}
|
||||
return renderTarget, nil
|
||||
return &innerRenderTarget{glRenderTarget, texture}, nil
|
||||
}
|
||||
|
||||
func (r *renderTarget) Texture() *Texture {
|
||||
return r.texture
|
||||
}
|
||||
|
||||
func (r *renderTarget) Size() (width, height int) {
|
||||
func (r *innerRenderTarget) size() (width, height int) {
|
||||
return r.glRenderTarget.Width(), r.glRenderTarget.Height()
|
||||
}
|
||||
|
||||
func (r *renderTarget) Clear() error {
|
||||
func (r *innerRenderTarget) Clear() error {
|
||||
return r.Fill(color.RGBA{0, 0, 0, 0})
|
||||
}
|
||||
|
||||
func (r *renderTarget) Fill(clr color.Color) error {
|
||||
func (r *innerRenderTarget) Fill(clr color.Color) error {
|
||||
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -73,7 +68,7 @@ func (r *renderTarget) Fill(clr color.Color) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *renderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||
func (r *innerRenderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -83,7 +78,7 @@ func (r *renderTarget) DrawTexture(texture *Texture, parts []TexturePart, geo Ge
|
||||
if r.texture != nil {
|
||||
targetNativeTexture = r.texture.glTexture.Native()
|
||||
}
|
||||
w, h := r.Size()
|
||||
w, h := r.size()
|
||||
projectionMatrix := r.glRenderTarget.ProjectionMatrix()
|
||||
shader.DrawTexture(glTexture.Native(), targetNativeTexture, w, h, projectionMatrix, quads, &geo, &color)
|
||||
return nil
|
||||
@ -120,15 +115,15 @@ type syncer interface {
|
||||
|
||||
type RenderTarget struct {
|
||||
syncer syncer
|
||||
inner *renderTarget
|
||||
inner *innerRenderTarget
|
||||
}
|
||||
|
||||
func (r *RenderTarget) Texture() *Texture {
|
||||
return r.inner.Texture()
|
||||
return r.inner.texture
|
||||
}
|
||||
|
||||
func (r *RenderTarget) Size() (width, height int) {
|
||||
return r.inner.Size()
|
||||
return r.inner.size()
|
||||
}
|
||||
|
||||
func (r *RenderTarget) Clear() (err error) {
|
||||
|
6
ui.go
6
ui.go
@ -145,12 +145,12 @@ func (u *ui) newTexture(img image.Image, filter int) (*Texture, error) {
|
||||
}
|
||||
|
||||
func (u *ui) newRenderTarget(width, height int, filter int) (*RenderTarget, error) {
|
||||
var renderTarget *renderTarget
|
||||
var innerRenderTarget *innerRenderTarget
|
||||
var err error
|
||||
u.use(func() {
|
||||
renderTarget, err = newRenderTarget(width, height, filter)
|
||||
innerRenderTarget, err = newInnerRenderTarget(width, height, filter)
|
||||
})
|
||||
return &RenderTarget{u, renderTarget}, err
|
||||
return &RenderTarget{u, innerRenderTarget}, err
|
||||
}
|
||||
|
||||
func (u *ui) run() {
|
||||
|
Loading…
Reference in New Issue
Block a user