Remove RenderTarget.Width/Height

This commit is contained in:
Hajime Hoshi 2013-10-16 23:06:35 +09:00
parent 20f9a990ac
commit 5679120f29
5 changed files with 23 additions and 26 deletions

View File

@ -19,6 +19,13 @@ type Rects struct {
rectColor *color.RGBA
}
const (
rectTextureWidth = 16
rectTextureHeight = 16
offscreenWidth = 256
offscreenHeight = 240
)
func New() *Rects {
return &Rects{
rectTextureInited: false,
@ -29,8 +36,8 @@ func New() *Rects {
}
func (game *Rects) Init(tf graphics.TextureFactory) {
game.rectTexture = tf.NewRenderTarget(16, 16)
game.offscreen = tf.NewRenderTarget(256, 240)
game.rectTexture = tf.NewRenderTarget(rectTextureWidth, rectTextureHeight)
game.offscreen = tf.NewRenderTarget(offscreenWidth, offscreenHeight)
}
func (game *Rects) Update(context ebiten.GameContext) {
@ -41,18 +48,18 @@ func (game *Rects) Update(context ebiten.GameContext) {
game.rectBounds.Height =
rand.Intn(context.ScreenHeight() - game.rectBounds.Y)
game.rectColor.R = uint8(rand.Intn(256))
game.rectColor.G = uint8(rand.Intn(256))
game.rectColor.B = uint8(rand.Intn(256))
game.rectColor.A = uint8(rand.Intn(256))
game.rectColor.R = uint8(rand.Intn(math.MaxUint8))
game.rectColor.G = uint8(rand.Intn(math.MaxUint8))
game.rectColor.B = uint8(rand.Intn(math.MaxUint8))
game.rectColor.A = uint8(rand.Intn(math.MaxUint8))
}
func (game *Rects) rectGeometryMatrix() matrix.Geometry {
geometryMatrix := matrix.IdentityGeometry()
scaleX := float64(game.rectBounds.Width) /
float64(game.rectTexture.Width())
float64(rectTextureWidth)
scaleY := float64(game.rectBounds.Height) /
float64(game.rectTexture.Height())
float64(rectTextureHeight)
geometryMatrix.Scale(scaleX, scaleY)
geometryMatrix.Translate(
float64(game.rectBounds.X), float64(game.rectBounds.Y))

View File

@ -19,7 +19,6 @@ type TexturePart struct {
}
type Context interface {
Screen() RenderTarget
Clear()
Fill(r, g, b uint8)
DrawTexture(textureID TextureID,
@ -29,6 +28,7 @@ type Context interface {
parts []TexturePart,
geometryMatrix matrix.Geometry,
colorMatrix matrix.Color)
ResetOffscreen()
SetOffscreen(renderTargetID RenderTargetID)
}
@ -50,8 +50,6 @@ type TextureID int
type RenderTarget interface {
Texture() Texture
ID() RenderTargetID
Width() int
Height() int
}
type RenderTargetID int

View File

@ -51,10 +51,6 @@ func (context *Context) Init() {
context.screenWidth, context.screenHeight).(*RenderTarget)
}
func (context *Context) Screen() graphics.RenderTarget {
return context.screen
}
func (context *Context) Clear() {
context.Fill(0, 0, 0)
}
@ -136,6 +132,10 @@ func (context *Context) DrawTextureParts(
C.glDisableClientState(C.GL_VERTEX_ARRAY)
}
func (context *Context) ResetOffscreen() {
context.setOffscreen(context.screen)
}
func abs(x int) int {
if x < 0 {
return -x
@ -189,7 +189,7 @@ func (context *Context) projectionMatrix() [16]float32 {
e41 = -1
e42 = -1
} else {
height := float32(texture.Height())
height := float32(texture.height)
e11 = float32(2) / float32(texture.textureWidth)
e22 = -1 * float32(2) / float32(texture.textureHeight)
e41 = -1

View File

@ -34,7 +34,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
C.glEnable(C.GL_TEXTURE_2D)
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_NEAREST)
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
context.SetOffscreen(context.Screen().ID())
context.ResetOffscreen()
context.Clear()
draw(context)
@ -53,7 +53,7 @@ func (device *Device) Update(draw func(graphics.Context)) {
{0, scale, 0},
},
}
context.DrawTexture(context.Screen().Texture().ID(),
context.DrawTexture(context.screen.Texture().ID(),
geometryMatrix, matrix.IdentityColor())
context.flush()
}

View File

@ -144,11 +144,3 @@ func (renderTarget *RenderTarget) Texture() graphics.Texture {
func (renderTarget *RenderTarget) ID() graphics.RenderTargetID {
return graphics.RenderTargetID(renderTarget.id)
}
func (renderTarget *RenderTarget) Width() int {
return renderTarget.width
}
func (renderTarget *RenderTarget) Height() int {
return renderTarget.height
}