mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
Remove RenderTarget.SetAsViewport
This commit is contained in:
parent
d97b7a2999
commit
df50171c1f
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user