mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/graphicsdriver/opengl: skip checkFramebufferStatus on browsers
This commit is contained in:
parent
c5974390a8
commit
c29d4b24bb
@ -20,6 +20,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"image"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||
@ -336,15 +337,19 @@ func (c *context) newFramebuffer(texture textureNative, width, height int) (*fra
|
||||
c.bindFramebuffer(framebufferNative(f))
|
||||
|
||||
c.ctx.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, uint32(texture), 0)
|
||||
if s := c.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s != gl.FRAMEBUFFER_COMPLETE {
|
||||
if s != 0 {
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
|
||||
|
||||
if shouldCheckFramebufferStatus() {
|
||||
if s := c.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s != gl.FRAMEBUFFER_COMPLETE {
|
||||
if s != 0 {
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: %v", s)
|
||||
}
|
||||
if e := c.ctx.GetError(); e != gl.NO_ERROR {
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
|
||||
}
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
|
||||
}
|
||||
if e := c.ctx.GetError(); e != gl.NO_ERROR {
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: (glGetError) %d", e)
|
||||
}
|
||||
return nil, fmt.Errorf("opengl: creating framebuffer failed: unknown error")
|
||||
}
|
||||
|
||||
return &framebuffer{
|
||||
native: framebufferNative(f),
|
||||
viewportWidth: width,
|
||||
@ -356,9 +361,13 @@ func (c *context) bindStencilBuffer(f framebufferNative, r renderbufferNative) e
|
||||
c.bindFramebuffer(f)
|
||||
|
||||
c.ctx.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, uint32(r))
|
||||
if s := c.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s != gl.FRAMEBUFFER_COMPLETE {
|
||||
return errors.New(fmt.Sprintf("opengl: glFramebufferRenderbuffer failed: %d", s))
|
||||
|
||||
if shouldCheckFramebufferStatus() {
|
||||
if s := c.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s != gl.FRAMEBUFFER_COMPLETE {
|
||||
return fmt.Errorf("opengl: glFramebufferRenderbuffer failed: %d", s)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -496,3 +505,11 @@ func (c *context) glslVersion() glsl.GLSLVersion {
|
||||
}
|
||||
return glsl.GLSLVersionDefault
|
||||
}
|
||||
|
||||
func shouldCheckFramebufferStatus() bool {
|
||||
// CheckFramebufferStatus is slow and should be avoided especially in browsers.
|
||||
// See https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API/WebGL_best_practices#avoid_blocking_api_calls_in_production
|
||||
//
|
||||
// TODO: Should this be avoided in all environments?
|
||||
return runtime.GOOS != "js"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user