mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
opengl: Reduce calls of glSetViewport
This commit is contained in:
parent
4c2650c721
commit
e5965d7771
@ -39,9 +39,11 @@ type Context struct {
|
||||
context
|
||||
}
|
||||
|
||||
func (c *Context) bindFramebuffer(f Framebuffer) {
|
||||
func (c *Context) bindFramebuffer(f Framebuffer) bool {
|
||||
if c.lastFramebuffer != f {
|
||||
c.bindFramebufferImpl(f)
|
||||
c.lastFramebuffer = f
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
@ -228,8 +228,9 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
|
||||
|
||||
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
|
||||
return c.RunOnContextThread(func() error {
|
||||
c.bindFramebuffer(f)
|
||||
gl.Viewport(0, 0, int32(width), int32(height))
|
||||
if c.bindFramebuffer(f) {
|
||||
gl.Viewport(0, 0, int32(width), int32(height))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
@ -205,9 +205,10 @@ func (c *Context) NewFramebuffer(t Texture) (Framebuffer, error) {
|
||||
}
|
||||
|
||||
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
|
||||
c.bindFramebuffer(f)
|
||||
gl := c.gl
|
||||
gl.Viewport(0, 0, width, height)
|
||||
if c.bindFramebuffer(f) {
|
||||
gl := c.gl
|
||||
gl.Viewport(0, 0, width, height)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -182,9 +182,10 @@ func (c *Context) NewFramebuffer(texture Texture) (Framebuffer, error) {
|
||||
}
|
||||
|
||||
func (c *Context) SetViewport(f Framebuffer, width, height int) error {
|
||||
gl := c.gl
|
||||
c.bindFramebuffer(f)
|
||||
gl.Viewport(0, 0, width, height)
|
||||
if c.bindFramebuffer(f) {
|
||||
gl := c.gl
|
||||
gl.Viewport(0, 0, width, height)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user