From a9aa1589de550a1e8439e86272e2f88577772901 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 21 Dec 2014 00:46:50 +0900 Subject: [PATCH] Rename renderTarget -> innerRenderTarget; Remove TextureDrawer --- graphics.go | 6 +----- graphicscontext.go | 14 +++++++++----- rendertarget.go | 27 +++++++++++---------------- ui.go | 6 +++--- 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/graphics.go b/graphics.go index f60557ffb..7da77c209 100644 --- a/graphics.go +++ b/graphics.go @@ -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)}}, diff --git a/graphicscontext.go b/graphicscontext.go index 132dd0a37..93232cac7 100644 --- a/graphicscontext.go +++ b/graphicscontext.go @@ -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 } diff --git a/rendertarget.go b/rendertarget.go index 8d75e802f..fa7c196d0 100644 --- a/rendertarget.go +++ b/rendertarget.go @@ -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) { diff --git a/ui.go b/ui.go index b5fba1f33..bf59af055 100644 --- a/ui.go +++ b/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() {