mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +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) {
|
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,39 +125,24 @@ 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
|
C.glViewport(C.GLint(x), C.GLint(y), C.GLsizei(width), C.GLsizei(height))
|
||||||
setter := &viewportSetter{
|
|
||||||
isUsingMainFramebuffer,
|
matrix := graphics.OrthoProjectionMatrix(x, width, y, height)
|
||||||
context.screenHeight * context.screenScale,
|
if rt == context.mainFramebufferTexture {
|
||||||
context,
|
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() {
|
func (context *Context) setMainFramebufferOffscreen() {
|
||||||
context.setOffscreen(context.mainFramebufferTexture)
|
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)) {
|
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)
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user