Replace DrawWhole with DrawWholeTexture and DrawWholeRenderTarget

This commit is contained in:
Hajime Hoshi 2014-12-17 23:06:14 +09:00
parent f3e4d1703d
commit 0e673670c0
6 changed files with 23 additions and 24 deletions

View File

@ -45,8 +45,6 @@ func NewGameScene() *GameScene {
} }
} }
const emptyWidth = 16
const emptyHeight = 16
const fieldWidth = blockWidth * fieldBlockNumX const fieldWidth = blockWidth * fieldBlockNumX
const fieldHeight = blockHeight * fieldBlockNumY const fieldHeight = blockHeight * fieldBlockNumY
@ -115,10 +113,11 @@ func (s *GameScene) Draw(context ebiten.GraphicsContext, textures *Textures) {
context.Fill(0xff, 0xff, 0xff) context.Fill(0xff, 0xff, 0xff)
field := textures.GetTexture("empty") field := textures.GetTexture("empty")
geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(emptyWidth), float64(fieldHeight)/float64(emptyHeight)) w, h := field.Size()
geoMat := ebiten.ScaleGeometry(float64(fieldWidth)/float64(w), float64(fieldHeight)/float64(h))
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number? geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
colorMat := ebiten.ScaleColor(color.RGBA{0, 0, 0, 0x80}) colorMat := ebiten.ScaleColor(color.RGBA{0, 0, 0, 0x80})
ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat) ebiten.DrawWholeTexture(context, field, geoMat, colorMat)
geoMat = ebiten.GeometryMatrixI() geoMat = ebiten.GeometryMatrixI()
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) geoMat.Concat(ebiten.TranslateGeometry(20, 20))

View File

@ -78,21 +78,11 @@ func (s *SceneManager) Draw(context ebiten.GraphicsContext, textures *Textures)
context.PopRenderTarget() context.PopRenderTarget()
color := ebiten.ColorMatrixI() color := ebiten.ColorMatrixI()
ebiten.DrawWhole( ebiten.DrawWholeRenderTarget(context, from, ebiten.GeometryMatrixI(), color)
context.RenderTarget(from),
ScreenWidth,
ScreenHeight,
ebiten.GeometryMatrixI(),
color)
alpha := float64(s.transitionCount) / float64(transitionMaxCount) alpha := float64(s.transitionCount) / float64(transitionMaxCount)
color.Elements[3][3] = alpha color.Elements[3][3] = alpha
ebiten.DrawWhole( ebiten.DrawWholeRenderTarget(context, to, ebiten.GeometryMatrixI(), color)
context.RenderTarget(to),
ScreenWidth,
ScreenHeight,
ebiten.GeometryMatrixI(),
color)
} }
func (s *SceneManager) GoTo(scene Scene) { func (s *SceneManager) GoTo(scene Scene) {

View File

@ -42,7 +42,7 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error {
geo.Concat(ebiten.ScaleGeometry(0.5, 0.5)) geo.Concat(ebiten.ScaleGeometry(0.5, 0.5))
geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2)) geo.Concat(ebiten.TranslateGeometry(screenWidth/2, screenHeight/2))
clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180) clr := ebiten.RotateHue(float64(g.count%180) * 2 * math.Pi / 180)
ebiten.DrawWhole(gr.Texture(g.gophersTexture), w, h, geo, clr) ebiten.DrawWholeTexture(gr, g.gophersTexture, geo, clr)
return nil return nil
} }

View File

@ -59,11 +59,11 @@ func (g *Game) Update(gr ebiten.GraphicsContext) error {
clr := ebiten.ScaleColor(color.RGBA{0xff, 0x40, 0x40, 0xff}) clr := ebiten.ScaleColor(color.RGBA{0xff, 0x40, 0x40, 0xff})
theta := 2.0 * math.Pi * float64(g.count%60) / 60.0 theta := 2.0 * math.Pi * float64(g.count%60) / 60.0
clr.Concat(ebiten.RotateHue(theta)) clr.Concat(ebiten.RotateHue(theta))
ebiten.DrawWhole(gr.RenderTarget(g.brushRenderTarget), 1, 1, geo, clr) ebiten.DrawWholeRenderTarget(gr, g.brushRenderTarget, geo, clr)
gr.PopRenderTarget() gr.PopRenderTarget()
} }
ebiten.DrawWhole(gr.RenderTarget(g.canvasRenderTarget), screenWidth, screenHeight, ebiten.GeometryMatrixI(), ebiten.ColorMatrixI()) ebiten.DrawWholeRenderTarget(gr, g.canvasRenderTarget, ebiten.GeometryMatrixI(), ebiten.ColorMatrixI())
ebitenutil.DebugPrint(gr, fmt.Sprintf("(%d, %d)", mx, my)) ebitenutil.DebugPrint(gr, fmt.Sprintf("(%d, %d)", mx, my))
return nil return nil

View File

@ -41,12 +41,22 @@ type Drawer interface {
Draw(parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error Draw(parts []TexturePart, geo GeometryMatrix, color ColorMatrix) error
} }
// DrawWhole draws the whole texture. // DrawWholeTexture draws the whole texture.
func DrawWhole(drawer Drawer, width, height int, geo GeometryMatrix, color ColorMatrix) error { func DrawWholeTexture(g GraphicsContext, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
w, h := texture.Size()
parts := []TexturePart{ parts := []TexturePart{
{0, 0, Rect{0, 0, width, height}}, {0, 0, Rect{0, 0, w, h}},
} }
return drawer.Draw(parts, geo, color) return g.Texture(texture).Draw(parts, geo, color)
}
// DrawWholeRenderTarget draws the whole render target.
func DrawWholeRenderTarget(g GraphicsContext, renderTarget *RenderTarget, geo GeometryMatrix, color ColorMatrix) error {
w, h := renderTarget.Size()
parts := []TexturePart{
{0, 0, Rect{0, 0, w, h}},
}
return g.RenderTarget(renderTarget).Draw(parts, geo, color)
} }
// A GraphicsContext is the interface that means a context of rendering. // A GraphicsContext is the interface that means a context of rendering.

View File

@ -103,7 +103,7 @@ func (c *graphicsContext) postUpdate() {
scale := float64(c.screenScale) scale := float64(c.screenScale)
geo := GeometryMatrixI() geo := GeometryMatrixI()
geo.Concat(ScaleGeometry(scale, scale)) geo.Concat(ScaleGeometry(scale, scale))
DrawWhole(c.RenderTarget(c.screen), c.screenWidth, c.screenHeight, geo, ColorMatrixI()) DrawWholeRenderTarget(c, c.screen, geo, ColorMatrixI())
gl.Flush() gl.Flush()
} }