mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/graphicsdriver/opengl: use an appropriate stencil buffer format
This commit is contained in:
parent
21670691b1
commit
4de6da0a50
@ -316,7 +316,30 @@ func (c *context) newRenderbuffer(width, height int) (renderbufferNative, error)
|
||||
renderbuffer := renderbufferNative(r)
|
||||
c.bindRenderbuffer(renderbuffer)
|
||||
|
||||
c.ctx.RenderbufferStorage(gl.RENDERBUFFER, c.stencilFormat(), int32(width), int32(height))
|
||||
var stencilFormat uint32
|
||||
if c.ctx.IsES() {
|
||||
// https://docs.gl/es2/glRenderbufferStorage
|
||||
// > Must be one of the following symbolic constants: GL_RGBA4, GL_RGB565, GL_RGB5_A1,
|
||||
// > GL_DEPTH_COMPONENT16, or GL_STENCIL_INDEX8.
|
||||
//
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/renderbufferStorage
|
||||
// > A GLenum specifying the internal format of the renderbuffer. Possible values:
|
||||
// > * gl.RGBA4: 4 red bits, 4 green bits, 4 blue bits 4 alpha bits.
|
||||
// > * gl.RGB565: 5 red bits, 6 green bits, 5 blue bits.
|
||||
// > * gl.RGB5_A1: 5 red bits, 5 green bits, 5 blue bits, 1 alpha bit.
|
||||
// > * gl.DEPTH_COMPONENT16: 16 depth bits.
|
||||
// > * gl.STENCIL_INDEX8: 8 stencil bits.
|
||||
// > * gl.DEPTH_STENCIL
|
||||
stencilFormat = gl.STENCIL_INDEX8
|
||||
} else {
|
||||
// GL_STENCIL_INDEX8 might not be available with OpenGL 2.1.
|
||||
// https://www.khronos.org/opengl/wiki/Image_Format
|
||||
// > There are only 2 depth/stencil formats, each providing 8 stencil bits: GL_DEPTH24_STENCIL8 and GL_DEPTH32F_STENCIL8.
|
||||
// > [...]
|
||||
// > Stencil formats can only be used for Textures if OpenGL 4.4 or ARB_texture_stencil8 is available.
|
||||
stencilFormat = gl.DEPTH24_STENCIL8
|
||||
}
|
||||
c.ctx.RenderbufferStorage(gl.RENDERBUFFER, stencilFormat, int32(width), int32(height))
|
||||
|
||||
return renderbuffer, nil
|
||||
}
|
||||
|
@ -16,16 +16,9 @@ package opengl
|
||||
|
||||
import (
|
||||
"syscall/js"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
)
|
||||
|
||||
type contextImpl struct {
|
||||
canvas js.Value
|
||||
webGL2 bool
|
||||
}
|
||||
|
||||
func (*context) stencilFormat() uint32 {
|
||||
// gl.DEPTH24_STENCIL8 is not available on WebGL1.
|
||||
return gl.STENCIL_INDEX8
|
||||
}
|
||||
|
@ -16,15 +16,5 @@
|
||||
|
||||
package opengl
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver/opengl/gl"
|
||||
)
|
||||
|
||||
type contextImpl struct {
|
||||
}
|
||||
|
||||
func (*context) stencilFormat() uint32 {
|
||||
// GL_STENCIL_INDEX8 might not be available with OpenGL 2.1.
|
||||
// https://www.khronos.org/opengl/wiki/Image_Format
|
||||
return gl.DEPTH24_STENCIL8
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user