From df50171c1f0cf00c884c6e1dc544eb2781be857b Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 27 Oct 2013 23:55:44 +0900 Subject: [PATCH] Remove RenderTarget.SetAsViewport --- graphics/opengl/context.go | 45 +++++++++----------------- graphics/rendertarget/render_target.go | 11 +++---- 2 files changed, 20 insertions(+), 36 deletions(-) diff --git a/graphics/opengl/context.go b/graphics/opengl/context.go index 6b9e6f3b2..ed69d7f58 100644 --- a/graphics/opengl/context.go +++ b/graphics/opengl/context.go @@ -114,7 +114,7 @@ func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) { func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) { C.glFlush() - rt.SetAsOffscreen(func(framebuffer interface{}) { + rt.SetAsOffscreen(func(framebuffer interface{}, x, y, width, height int) { f := framebuffer.(rendertarget.Framebuffer) C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f)) err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER) @@ -125,39 +125,24 @@ func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) { C.glBlendFuncSeparate(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA, C.GL_ZERO, C.GL_ONE) - isUsingMainFramebuffer := rt == context.mainFramebufferTexture - setter := &viewportSetter{ - isUsingMainFramebuffer, - context.screenHeight * context.screenScale, - context, + C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) + + matrix := graphics.OrthoProjectionMatrix(x, width, y, height) + if rt == context.mainFramebufferTexture { + actualScreenHeight := context.screenHeight * context.screenScale + // Flip Y and move to fit with the top of the window. + matrix[1][1] *= -1 + matrix[1][3] += float64(actualScreenHeight) / float64(height) * 2 + } + + for j := 0; j < 4; j++ { + for i := 0; i < 4; i++ { + context.projectionMatrix[i+j*4] = float32(matrix[i][j]) + } } - rt.SetAsViewport(setter.Set) }) } -type viewportSetter struct { - isUsingMainFramebuffer bool - actualScreenHeight int - context *Context -} - -func (v *viewportSetter) Set(x, y, width, height int) { - C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height)) - - matrix := graphics.OrthoProjectionMatrix(x, width, y, height) - if v.isUsingMainFramebuffer { - // Flip Y and move to fit with the top of the window. - matrix[1][1] *= -1 - matrix[1][3] += float64(v.actualScreenHeight) / float64(height) * 2 - } - - for j := 0; j < 4; j++ { - for i := 0; i < 4; i++ { - v.context.projectionMatrix[i+j*4] = float32(matrix[i][j]) - } - } -} - func (context *Context) setMainFramebufferOffscreen() { context.setOffscreen(context.mainFramebufferTexture) } diff --git a/graphics/rendertarget/render_target.go b/graphics/rendertarget/render_target.go index e67abdf3c..d3c02e054 100644 --- a/graphics/rendertarget/render_target.go +++ b/graphics/rendertarget/render_target.go @@ -16,10 +16,9 @@ func NewWithFramebuffer(texture *texture.Texture, framebuffer interface{}) *Rend } } -func (renderTarget *RenderTarget) SetAsViewport(setter func(x, y, width, height int)) { - renderTarget.texture.SetAsViewport(setter) -} - -func (renderTarget *RenderTarget) SetAsOffscreen(setter func(framebuffer interface{})) { - setter(renderTarget.framebuffer) +func (renderTarget *RenderTarget) SetAsOffscreen( + setter func(framebuffer interface{}, x, y, width, height int)) { + renderTarget.texture.SetAsViewport(func(x, y, width, height int) { + setter(renderTarget.framebuffer, x, y, width, height) + }) }