Remove RenderTarget.SetAsViewport

This commit is contained in:
Hajime Hoshi 2013-10-27 23:55:44 +09:00
parent d97b7a2999
commit df50171c1f
2 changed files with 20 additions and 36 deletions

View File

@ -114,7 +114,7 @@ func (context *Context) SetOffscreen(renderTargetId graphics.RenderTargetId) {
func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) { func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) {
C.glFlush() C.glFlush()
rt.SetAsOffscreen(func(framebuffer interface{}) { rt.SetAsOffscreen(func(framebuffer interface{}, x, y, width, height int) {
f := framebuffer.(rendertarget.Framebuffer) f := framebuffer.(rendertarget.Framebuffer)
C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f)) C.glBindFramebuffer(C.GL_FRAMEBUFFER, C.GLuint(f))
err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER) err := C.glCheckFramebufferStatus(C.GL_FRAMEBUFFER)
@ -125,37 +125,22 @@ func (context *Context) setOffscreen(rt *grendertarget.RenderTarget) {
C.glBlendFuncSeparate(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA, C.glBlendFuncSeparate(C.GL_SRC_ALPHA, C.GL_ONE_MINUS_SRC_ALPHA,
C.GL_ZERO, C.GL_ONE) C.GL_ZERO, C.GL_ONE)
isUsingMainFramebuffer := rt == context.mainFramebufferTexture
setter := &viewportSetter{
isUsingMainFramebuffer,
context.screenHeight * context.screenScale,
context,
}
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)) C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
matrix := graphics.OrthoProjectionMatrix(x, width, y, height) matrix := graphics.OrthoProjectionMatrix(x, width, y, height)
if v.isUsingMainFramebuffer { if rt == context.mainFramebufferTexture {
actualScreenHeight := context.screenHeight * context.screenScale
// Flip Y and move to fit with the top of the window. // Flip Y and move to fit with the top of the window.
matrix[1][1] *= -1 matrix[1][1] *= -1
matrix[1][3] += float64(v.actualScreenHeight) / float64(height) * 2 matrix[1][3] += float64(actualScreenHeight) / float64(height) * 2
} }
for j := 0; j < 4; j++ { for j := 0; j < 4; j++ {
for i := 0; i < 4; i++ { for i := 0; i < 4; i++ {
v.context.projectionMatrix[i+j*4] = float32(matrix[i][j]) context.projectionMatrix[i+j*4] = float32(matrix[i][j])
} }
} }
})
} }
func (context *Context) setMainFramebufferOffscreen() { func (context *Context) setMainFramebufferOffscreen() {

View File

@ -16,10 +16,9 @@ func NewWithFramebuffer(texture *texture.Texture, framebuffer interface{}) *Rend
} }
} }
func (renderTarget *RenderTarget) SetAsViewport(setter func(x, y, width, height int)) { func (renderTarget *RenderTarget) SetAsOffscreen(
renderTarget.texture.SetAsViewport(setter) 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)
func (renderTarget *RenderTarget) SetAsOffscreen(setter func(framebuffer interface{})) { })
setter(renderTarget.framebuffer)
} }