From 30cdcfd574177fb28dfa3fd7710d3ac9de63d308 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 5 Jul 2013 00:49:17 +0900 Subject: [PATCH] Refactoring --- graphics/opengl/context.go | 6 ++---- graphics/opengl/device.go | 44 ++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 7e068632f..28bc42aed 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -66,11 +66,9 @@ func newContext(screenWidth, screenHeight, screenScale int) *Context { initializeShaders() - return context -} + context.screen = context.NewTexture(screenWidth, screenHeight) -func (context *Context) setScreen(screen graphics.Texture) { - context.screen = screen + return context } func (context *Context) Screen() graphics.Texture { diff --git a/graphics/opengl/device.go b/graphics/opengl/device.go index c8e6ab46e..9a09b6ea8 100644 --- a/graphics/opengl/device.go +++ b/graphics/opengl/device.go @@ -31,29 +31,21 @@ import ( ) type Device struct { - screenWidth int - screenHeight int - screenScale int - context *Context - offscreenTexture graphics.Texture - drawing chan chan func(graphics.Context) - updating chan chan func() + screenScale int + context *Context + drawing chan chan func(graphics.Context) + updating chan chan func() } func NewDevice(screenWidth, screenHeight, screenScale int, updating chan chan func()) *Device { context := newContext(screenWidth, screenHeight, screenScale) device := &Device{ - screenWidth: screenWidth, - screenHeight: screenHeight, - screenScale: screenScale, - drawing: make(chan chan func(graphics.Context)), - context: context, - updating: updating, + screenScale: screenScale, + drawing: make(chan chan func(graphics.Context)), + context: context, + updating: updating, } - device.offscreenTexture = - device.context.NewTexture(screenWidth, screenHeight) - device.context.setScreen(device.offscreenTexture) go func() { for { @@ -70,35 +62,35 @@ func (device *Device) Drawing() <-chan chan func(graphics.Context) { } func (device *Device) Update() { - g := device.context + context := device.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) - g.SetOffscreen(device.offscreenTexture.ID) - g.Clear() + context.SetOffscreen(context.Screen().ID) + context.Clear() ch := make(chan func(graphics.Context)) device.drawing <- 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_MAG_FILTER, C.GL_LINEAR) - g.resetOffscreen() - g.Clear() + context.resetOffscreen() + context.Clear() - scale := float64(g.screenScale) + scale := float64(context.screenScale) geometryMatrix := matrix.Geometry{ [2][3]float64{ {scale, 0, 0}, {0, scale, 0}, }, } - g.DrawTexture(device.offscreenTexture.ID, + context.DrawTexture(context.Screen().ID, geometryMatrix, matrix.IdentityColor()) - g.flush() + context.flush() } func (device *Device) TextureFactory() graphics.TextureFactory {