From 89c33eac85018cb6715e47cd29d88c9abf90d14d Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 29 Nov 2013 22:45:18 +0900 Subject: [PATCH] Remove Canvas.ToTexture --- example/game/rects/rects.go | 4 ++-- graphics/graphics.go | 10 ++++++++-- graphics/opengl/context.go | 26 +++++++++++++++++--------- graphics/opengl/device.go | 2 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/example/game/rects/rects.go b/example/game/rects/rects.go index 35f021bfc..d20284a9a 100644 --- a/example/game/rects/rects.go +++ b/example/game/rects/rects.go @@ -98,12 +98,12 @@ func (game *Rects) Draw(g graphics.Canvas) { g.Fill(0, 0, 0) game.offscreenInited = true } - g.DrawTexture(g.ToTexture(game.rectTextureId), + g.DrawRenderTarget(game.rectTextureId, game.rectGeometryMatrix(), game.rectColorMatrix()) g.ResetOffscreen() - g.DrawTexture(g.ToTexture(game.offscreenId), + g.DrawRenderTarget(game.offscreenId, matrix.IdentityGeometry(), matrix.IdentityColor()) } diff --git a/graphics/graphics.go b/graphics/graphics.go index af3e713ad..ba9d587bd 100644 --- a/graphics/graphics.go +++ b/graphics/graphics.go @@ -19,17 +19,23 @@ type TexturePart struct { } type Canvas interface { - ToTexture(id RenderTargetId) TextureId - Clear() Fill(r, g, b uint8) DrawTexture(id TextureId, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) + DrawRenderTarget(id RenderTargetId, + geometryMatrix matrix.Geometry, + colorMatrix matrix.Color) DrawTextureParts(id TextureId, parts []TexturePart, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) + DrawRenderTargetParts(id RenderTargetId, + parts []TexturePart, + geometryMatrix matrix.Geometry, + colorMatrix matrix.Color) + ResetOffscreen() SetOffscreen(id RenderTargetId) } diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 18c53f5fc..6b7e40972 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -38,10 +38,6 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context { return context } -func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId { - return context.ids.ToTexture(renderTargetId) -} - func (context *Context) Clear() { context.Fill(0, 0, 0) } @@ -57,19 +53,31 @@ func (context *Context) Fill(r, g, b uint8) { } func (context *Context) DrawTexture( - textureId graphics.TextureId, + id graphics.TextureId, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { - tex := context.ids.TextureAt(textureId) + tex := context.ids.TextureAt(id) context.offscreen.DrawTexture(tex, geometryMatrix, colorMatrix) } -func (context *Context) DrawTextureParts( - textureId graphics.TextureId, parts []graphics.TexturePart, +func (context *Context) DrawRenderTarget( + id graphics.RenderTargetId, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { - tex := context.ids.TextureAt(textureId) + context.DrawTexture(context.ids.ToTexture(id), geometryMatrix, colorMatrix) +} + +func (context *Context) DrawTextureParts( + id graphics.TextureId, parts []graphics.TexturePart, + geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { + tex := context.ids.TextureAt(id) context.offscreen.DrawTextureParts(tex, parts, geometryMatrix, colorMatrix) } +func (context *Context) DrawRenderTargetParts( + id graphics.RenderTargetId, parts []graphics.TexturePart, + geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { + context.DrawTextureParts(context.ids.ToTexture(id), parts, geometryMatrix, colorMatrix) +} + // Init initializes the context. The initial state is saved for each GL context. func (context *Context) Init() { C.glEnable(C.GL_TEXTURE_2D) diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index 239beb85b..4a6f00d1a 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -33,7 +33,7 @@ func (device *Device) Update(draw func(graphics.Canvas)) { scale := float64(device.screenScale) geometryMatrix := matrix.IdentityGeometry() geometryMatrix.Scale(scale, scale) - context.DrawTexture(context.ToTexture(context.screenId), + context.DrawRenderTarget(context.screenId, geometryMatrix, matrix.IdentityColor()) context.flush() }