Refactoring

This commit is contained in:
Hajime Hoshi 2013-07-05 00:49:17 +09:00
parent 508e5150de
commit 30cdcfd574
2 changed files with 20 additions and 30 deletions

View File

@ -66,11 +66,9 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context {
initializeShaders() initializeShaders()
return context context.screen = context.NewTexture(screenWidth, screenHeight)
}
func (context *Context) setScreen(screen graphics.Texture) { return context
context.screen = screen
} }
func (context *Context) Screen() graphics.Texture { func (context *Context) Screen() graphics.Texture {

View File

@ -31,11 +31,8 @@ import (
) )
type Device struct { type Device struct {
screenWidth int
screenHeight int
screenScale int screenScale int
context *Context context *Context
offscreenTexture graphics.Texture
drawing chan chan func(graphics.Context) drawing chan chan func(graphics.Context)
updating chan chan func() updating chan chan func()
} }
@ -44,16 +41,11 @@ func NewDevice(screenWidth, screenHeight, screenScale int, updating chan chan fu
context := newContext(screenWidth, screenHeight, screenScale) context := newContext(screenWidth, screenHeight, screenScale)
device := &Device{ device := &Device{
screenWidth: screenWidth,
screenHeight: screenHeight,
screenScale: screenScale, screenScale: screenScale,
drawing: make(chan chan func(graphics.Context)), drawing: make(chan chan func(graphics.Context)),
context: context, context: context,
updating: updating, updating: updating,
} }
device.offscreenTexture =
device.context.NewTexture(screenWidth, screenHeight)
device.context.setScreen(device.offscreenTexture)
go func() { go func() {
for { for {
@ -70,35 +62,35 @@ func (device *Device) Drawing() <-chan chan func(graphics.Context) {
} }
func (device *Device) Update() { func (device *Device) Update() {
g := device.context context := device.context
C.glEnable(C.GL_TEXTURE_2D) 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_MIN_FILTER, C.GL_NEAREST)
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST) C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_NEAREST)
g.SetOffscreen(device.offscreenTexture.ID) context.SetOffscreen(context.Screen().ID)
g.Clear() context.Clear()
ch := make(chan func(graphics.Context)) ch := make(chan func(graphics.Context))
device.drawing <- ch device.drawing <- ch
drawable := <-ch drawable := <-ch
drawable(g) drawable(context)
g.flush() context.flush()
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR) C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MIN_FILTER, C.GL_LINEAR)
C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR) C.glTexParameteri(C.GL_TEXTURE_2D, C.GL_TEXTURE_MAG_FILTER, C.GL_LINEAR)
g.resetOffscreen() context.resetOffscreen()
g.Clear() context.Clear()
scale := float64(g.screenScale) scale := float64(context.screenScale)
geometryMatrix := matrix.Geometry{ geometryMatrix := matrix.Geometry{
[2][3]float64{ [2][3]float64{
{scale, 0, 0}, {scale, 0, 0},
{0, scale, 0}, {0, scale, 0},
}, },
} }
g.DrawTexture(device.offscreenTexture.ID, context.DrawTexture(context.Screen().ID,
geometryMatrix, matrix.IdentityColor()) geometryMatrix, matrix.IdentityColor())
g.flush() context.flush()
} }
func (device *Device) TextureFactory() graphics.TextureFactory { func (device *Device) TextureFactory() graphics.TextureFactory {