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) g.Fill(0, 0, 0)
game.offscreenInited = true game.offscreenInited = true
} }
g.DrawTexture(g.ToTexture(game.rectTextureId), g.DrawRenderTarget(game.rectTextureId,
game.rectGeometryMatrix(), game.rectGeometryMatrix(),
game.rectColorMatrix()) game.rectColorMatrix())
g.ResetOffscreen() g.ResetOffscreen()
g.DrawTexture(g.ToTexture(game.offscreenId), g.DrawRenderTarget(game.offscreenId,
matrix.IdentityGeometry(), matrix.IdentityGeometry(),
matrix.IdentityColor()) matrix.IdentityColor())
} }

View File

@ -19,17 +19,23 @@ type TexturePart struct {
} }
type Canvas interface { type Canvas interface {
ToTexture(id RenderTargetId) TextureId
Clear() Clear()
Fill(r, g, b uint8) Fill(r, g, b uint8)
DrawTexture(id TextureId, DrawTexture(id TextureId,
geometryMatrix matrix.Geometry, geometryMatrix matrix.Geometry,
colorMatrix matrix.Color) colorMatrix matrix.Color)
DrawRenderTarget(id RenderTargetId,
geometryMatrix matrix.Geometry,
colorMatrix matrix.Color)
DrawTextureParts(id TextureId, DrawTextureParts(id TextureId,
parts []TexturePart, parts []TexturePart,
geometryMatrix matrix.Geometry, geometryMatrix matrix.Geometry,
colorMatrix matrix.Color) colorMatrix matrix.Color)
DrawRenderTargetParts(id RenderTargetId,
parts []TexturePart,
geometryMatrix matrix.Geometry,
colorMatrix matrix.Color)
ResetOffscreen() ResetOffscreen()
SetOffscreen(id RenderTargetId) SetOffscreen(id RenderTargetId)
} }

View File

@ -38,10 +38,6 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
return context return context
} }
func (context *Context) ToTexture(renderTargetId graphics.RenderTargetId) graphics.TextureId {
return context.ids.ToTexture(renderTargetId)
}
func (context *Context) Clear() { func (context *Context) Clear() {
context.Fill(0, 0, 0) context.Fill(0, 0, 0)
} }
@ -57,19 +53,31 @@ func (context *Context) Fill(r, g, b uint8) {
} }
func (context *Context) DrawTexture( func (context *Context) DrawTexture(
textureId graphics.TextureId, id graphics.TextureId,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { geometryMatrix matrix.Geometry, colorMatrix matrix.Color) {
tex := context.ids.TextureAt(textureId) tex := context.ids.TextureAt(id)
context.offscreen.DrawTexture(tex, geometryMatrix, colorMatrix) context.offscreen.DrawTexture(tex, geometryMatrix, colorMatrix)
} }
func (context *Context) DrawTextureParts( func (context *Context) DrawRenderTarget(
textureId graphics.TextureId, parts []graphics.TexturePart, id graphics.RenderTargetId,
geometryMatrix matrix.Geometry, colorMatrix matrix.Color) { 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) 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. // Init initializes the context. The initial state is saved for each GL context.
func (context *Context) Init() { func (context *Context) Init() {
C.glEnable(C.GL_TEXTURE_2D) C.glEnable(C.GL_TEXTURE_2D)

View File

@ -33,7 +33,7 @@ func (device *Device) Update(draw func(graphics.Canvas)) {
scale := float64(device.screenScale) scale := float64(device.screenScale)
geometryMatrix := matrix.IdentityGeometry() geometryMatrix := matrix.IdentityGeometry()
geometryMatrix.Scale(scale, scale) geometryMatrix.Scale(scale, scale)
context.DrawTexture(context.ToTexture(context.screenId), context.DrawRenderTarget(context.screenId,
geometryMatrix, matrix.IdentityColor()) geometryMatrix, matrix.IdentityColor())
context.flush() context.flush()
} }