Remove Canvas.ToTexture

This commit is contained in:
Hajime Hoshi 2013-11-29 22:45:18 +09:00
parent e8c518735b
commit 89c33eac85
4 changed files with 28 additions and 14 deletions

View File

@ -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())
}

View File

@ -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)
}

View File

@ -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)

View File

@ -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()
}