mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-04 08:55:35 +00:00
all: remove Z buffer support
It is no longer needed by any rendering backend. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -67,17 +67,13 @@ type glState struct {
|
||||
storeBuf gl.Buffer
|
||||
storeBufs [4]gl.Buffer
|
||||
vertArray gl.VertexArray
|
||||
depthMask bool
|
||||
depthFunc gl.Enum
|
||||
srgb bool
|
||||
blend struct {
|
||||
enable bool
|
||||
srcRGB, dstRGB gl.Enum
|
||||
srcA, dstA gl.Enum
|
||||
}
|
||||
depthTest bool
|
||||
clearColor [4]float32
|
||||
clearDepth float32
|
||||
viewport [4]int
|
||||
unpack_row_length int
|
||||
}
|
||||
@@ -108,11 +104,9 @@ type gpuTexture struct {
|
||||
}
|
||||
|
||||
type gpuFramebuffer struct {
|
||||
backend *Backend
|
||||
obj gl.Framebuffer
|
||||
hasDepth bool
|
||||
depthBuf gl.Renderbuffer
|
||||
foreign bool
|
||||
backend *Backend
|
||||
obj gl.Framebuffer
|
||||
foreign bool
|
||||
}
|
||||
|
||||
type gpuBuffer struct {
|
||||
@@ -286,10 +280,6 @@ func (b *Backend) queryState() glState {
|
||||
arrayBuf: gl.Buffer(b.funcs.GetBinding(gl.ARRAY_BUFFER_BINDING)),
|
||||
elemBuf: gl.Buffer(b.funcs.GetBinding(gl.ELEMENT_ARRAY_BUFFER_BINDING)),
|
||||
drawFBO: gl.Framebuffer(b.funcs.GetBinding(gl.FRAMEBUFFER_BINDING)),
|
||||
depthMask: b.funcs.GetInteger(gl.DEPTH_WRITEMASK) != gl.FALSE,
|
||||
depthTest: b.funcs.IsEnabled(gl.DEPTH_TEST),
|
||||
depthFunc: gl.Enum(b.funcs.GetInteger(gl.DEPTH_FUNC)),
|
||||
clearDepth: b.funcs.GetFloat(gl.DEPTH_CLEAR_VALUE),
|
||||
clearColor: b.funcs.GetFloat4(gl.COLOR_CLEAR_VALUE),
|
||||
viewport: b.funcs.GetInteger4(gl.VIEWPORT),
|
||||
unpack_row_length: b.funcs.GetInteger(gl.UNPACK_ROW_LENGTH),
|
||||
@@ -346,8 +336,6 @@ func (b *Backend) restoreState(dst glState) {
|
||||
src.set(f, gl.BLEND, dst.blend.enable)
|
||||
bf := dst.blend
|
||||
src.setBlendFuncSeparate(f, bf.srcRGB, bf.dstRGB, bf.srcA, bf.dstA)
|
||||
src.set(f, gl.DEPTH_TEST, dst.depthTest)
|
||||
src.setDepthFunc(f, dst.depthFunc)
|
||||
src.set(f, gl.FRAMEBUFFER_SRGB, dst.srgb)
|
||||
src.bindVertexArray(f, dst.vertArray)
|
||||
src.useProgram(f, dst.prog)
|
||||
@@ -360,8 +348,6 @@ func (b *Backend) restoreState(dst glState) {
|
||||
src.bindBufferBase(f, gl.SHADER_STORAGE_BUFFER, i, b)
|
||||
}
|
||||
src.bindBuffer(f, gl.SHADER_STORAGE_BUFFER, dst.storeBuf)
|
||||
src.setDepthMask(f, dst.depthMask)
|
||||
src.setClearDepth(f, dst.clearDepth)
|
||||
col := dst.clearColor
|
||||
src.setClearColor(f, col[0], col[1], col[2], col[3])
|
||||
for i, attr := range dst.vertAttribs {
|
||||
@@ -583,13 +569,6 @@ func (s *glState) pixelStorei(f *gl.Functions, pname gl.Enum, val int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) setClearDepth(f *gl.Functions, d float32) {
|
||||
if d != s.clearDepth {
|
||||
f.ClearDepthf(d)
|
||||
s.clearDepth = d
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) setClearColor(f *gl.Functions, r, g, b, a float32) {
|
||||
col := [4]float32{r, g, b, a}
|
||||
if col != s.clearColor {
|
||||
@@ -606,13 +585,6 @@ func (s *glState) setViewport(f *gl.Functions, x, y, width, height int) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) setDepthFunc(f *gl.Functions, df gl.Enum) {
|
||||
if df != s.depthFunc {
|
||||
f.DepthFunc(df)
|
||||
s.depthFunc = df
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) setBlendFuncSeparate(f *gl.Functions, srcRGB, dstRGB, srcA, dstA gl.Enum) {
|
||||
if srcRGB != s.blend.srcRGB || dstRGB != s.blend.dstRGB || srcA != s.blend.srcA || dstA != s.blend.dstA {
|
||||
s.blend.srcRGB = srcRGB
|
||||
@@ -623,13 +595,6 @@ func (s *glState) setBlendFuncSeparate(f *gl.Functions, srcRGB, dstRGB, srcA, ds
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) setDepthMask(f *gl.Functions, enable bool) {
|
||||
if enable != s.depthMask {
|
||||
f.DepthMask(enable)
|
||||
s.depthMask = enable
|
||||
}
|
||||
}
|
||||
|
||||
func (s *glState) set(f *gl.Functions, target gl.Enum, enable bool) {
|
||||
switch target {
|
||||
case gl.FRAMEBUFFER_SRGB:
|
||||
@@ -642,11 +607,6 @@ func (s *glState) set(f *gl.Functions, target gl.Enum, enable bool) {
|
||||
return
|
||||
}
|
||||
s.blend.enable = enable
|
||||
case gl.DEPTH_TEST:
|
||||
if enable == s.depthTest {
|
||||
return
|
||||
}
|
||||
s.depthTest = enable
|
||||
default:
|
||||
panic("unknown enable")
|
||||
}
|
||||
@@ -672,7 +632,7 @@ func (b *Backend) IsTimeContinuous() bool {
|
||||
return b.funcs.GetInteger(gl.GPU_DISJOINT_EXT) == gl.FALSE
|
||||
}
|
||||
|
||||
func (b *Backend) NewFramebuffer(tex driver.Texture, depthBits int) (driver.Framebuffer, error) {
|
||||
func (b *Backend) NewFramebuffer(tex driver.Texture) (driver.Framebuffer, error) {
|
||||
glErr(b.funcs)
|
||||
gltex := tex.(*gpuTexture)
|
||||
fb := b.funcs.CreateFramebuffer()
|
||||
@@ -683,25 +643,6 @@ func (b *Backend) NewFramebuffer(tex driver.Texture, depthBits int) (driver.Fram
|
||||
return nil, err
|
||||
}
|
||||
b.funcs.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, gltex.obj, 0)
|
||||
if depthBits > 0 {
|
||||
size := gl.Enum(gl.DEPTH_COMPONENT16)
|
||||
switch {
|
||||
case depthBits > 24:
|
||||
size = gl.DEPTH_COMPONENT32F
|
||||
case depthBits > 16:
|
||||
size = gl.DEPTH_COMPONENT24
|
||||
}
|
||||
depthBuf := b.funcs.CreateRenderbuffer()
|
||||
b.glstate.bindRenderbuffer(b.funcs, gl.RENDERBUFFER, depthBuf)
|
||||
b.funcs.RenderbufferStorage(gl.RENDERBUFFER, size, gltex.width, gltex.height)
|
||||
b.funcs.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthBuf)
|
||||
fbo.depthBuf = depthBuf
|
||||
fbo.hasDepth = true
|
||||
if err := glErr(b.funcs); err != nil {
|
||||
fbo.Release()
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if st := b.funcs.CheckFramebufferStatus(gl.FRAMEBUFFER); st != gl.FRAMEBUFFER_COMPLETE {
|
||||
fbo.Release()
|
||||
return nil, fmt.Errorf("incomplete framebuffer, status = 0x%x, err = %d", st, b.funcs.GetError())
|
||||
@@ -840,10 +781,6 @@ func (b *Backend) useProgram(p *gpuProgram) {
|
||||
b.state.prog = p
|
||||
}
|
||||
|
||||
func (b *Backend) SetDepthTest(enable bool) {
|
||||
b.glstate.set(b.funcs, gl.DEPTH_TEST, enable)
|
||||
}
|
||||
|
||||
func (b *Backend) BlendFunc(sfactor, dfactor driver.BlendFactor) {
|
||||
src, dst := toGLBlendFactor(sfactor), toGLBlendFactor(dfactor)
|
||||
b.glstate.setBlendFuncSeparate(b.funcs, src, dst, src, dst)
|
||||
@@ -864,10 +801,6 @@ func toGLBlendFactor(f driver.BlendFactor) gl.Enum {
|
||||
}
|
||||
}
|
||||
|
||||
func (b *Backend) DepthMask(mask bool) {
|
||||
b.glstate.setDepthMask(b.funcs, mask)
|
||||
}
|
||||
|
||||
func (b *Backend) SetBlend(enable bool) {
|
||||
b.glstate.set(b.funcs, gl.BLEND, enable)
|
||||
}
|
||||
@@ -913,24 +846,6 @@ func (b *Backend) Clear(colR, colG, colB, colA float32) {
|
||||
b.funcs.Clear(gl.COLOR_BUFFER_BIT)
|
||||
}
|
||||
|
||||
func (b *Backend) ClearDepth(d float32) {
|
||||
b.glstate.setClearDepth(b.funcs, d)
|
||||
b.funcs.Clear(gl.DEPTH_BUFFER_BIT)
|
||||
}
|
||||
|
||||
func (b *Backend) DepthFunc(f driver.DepthFunc) {
|
||||
var glfunc gl.Enum
|
||||
switch f {
|
||||
case driver.DepthFuncGreater:
|
||||
glfunc = gl.GREATER
|
||||
case driver.DepthFuncGreaterEqual:
|
||||
glfunc = gl.GEQUAL
|
||||
default:
|
||||
panic("unsupported depth func")
|
||||
}
|
||||
b.glstate.setDepthFunc(b.funcs, glfunc)
|
||||
}
|
||||
|
||||
func (b *Backend) NewInputLayout(vs driver.ShaderSources, layout []driver.InputDesc) (driver.InputLayout, error) {
|
||||
if len(vs.Inputs) != len(layout) {
|
||||
return nil, fmt.Errorf("NewInputLayout: got %d inputs, expected %d", len(layout), len(vs.Inputs))
|
||||
@@ -1222,7 +1137,7 @@ func (b *Backend) BlitFramebuffer(dst, src driver.Framebuffer, srect, drect imag
|
||||
b.funcs.BlitFramebuffer(
|
||||
srect.Min.X, srect.Min.Y, srect.Max.X, srect.Max.Y,
|
||||
drect.Min.X, drect.Min.Y, drect.Max.X, drect.Max.Y,
|
||||
gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT|gl.STENCIL_BUFFER_BIT,
|
||||
gl.COLOR_BUFFER_BIT,
|
||||
gl.NEAREST)
|
||||
}
|
||||
|
||||
@@ -1250,9 +1165,6 @@ func (f *gpuFramebuffer) Release() {
|
||||
panic("framebuffer not created by NewFramebuffer")
|
||||
}
|
||||
f.backend.glstate.deleteFramebuffer(f.backend.funcs, f.obj)
|
||||
if f.hasDepth {
|
||||
f.backend.glstate.deleteRenderbuffer(f.backend.funcs, f.depthBuf)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *gpuFramebuffer) ImplementsRenderTarget() {}
|
||||
|
||||
@@ -22,7 +22,6 @@ type SRGBFBO struct {
|
||||
viewport image.Point
|
||||
fbo gl.Framebuffer
|
||||
tex gl.Texture
|
||||
depth gl.Renderbuffer
|
||||
blitted bool
|
||||
quad gl.Buffer
|
||||
prog gl.Program
|
||||
@@ -47,7 +46,6 @@ func NewSRGBFBO(f *gl.Functions, state *glState) (*SRGBFBO, error) {
|
||||
format: srgbTriple,
|
||||
fbo: f.CreateFramebuffer(),
|
||||
tex: f.CreateTexture(),
|
||||
depth: f.CreateRenderbuffer(),
|
||||
}
|
||||
state.bindTexture(f, 0, s.tex)
|
||||
f.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
|
||||
@@ -87,7 +85,6 @@ func (s *SRGBFBO) Blit() {
|
||||
s.c.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
|
||||
s.state.bindFramebuffer(s.c, gl.FRAMEBUFFER, s.fbo)
|
||||
s.c.InvalidateFramebuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0)
|
||||
s.c.InvalidateFramebuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT)
|
||||
}
|
||||
|
||||
func (s *SRGBFBO) Framebuffer() gl.Framebuffer {
|
||||
@@ -104,11 +101,8 @@ func (s *SRGBFBO) Refresh(viewport image.Point) error {
|
||||
s.viewport = viewport
|
||||
s.state.bindTexture(s.c, 0, s.tex)
|
||||
s.c.TexImage2D(gl.TEXTURE_2D, 0, s.format.internalFormat, viewport.X, viewport.Y, s.format.format, s.format.typ)
|
||||
s.state.bindRenderbuffer(s.c, gl.RENDERBUFFER, s.depth)
|
||||
s.c.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, viewport.X, viewport.Y)
|
||||
s.state.bindFramebuffer(s.c, gl.FRAMEBUFFER, s.fbo)
|
||||
s.c.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, s.tex, 0)
|
||||
s.c.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, s.depth)
|
||||
if st := s.c.CheckFramebufferStatus(gl.FRAMEBUFFER); st != gl.FRAMEBUFFER_COMPLETE {
|
||||
return fmt.Errorf("sRGB framebuffer incomplete (%dx%d), status: %#x error: %x", viewport.X, viewport.Y, st, s.c.GetError())
|
||||
}
|
||||
@@ -135,7 +129,6 @@ func (s *SRGBFBO) Refresh(viewport image.Point) error {
|
||||
func (s *SRGBFBO) Release() {
|
||||
s.state.deleteFramebuffer(s.c, s.fbo)
|
||||
s.state.deleteTexture(s.c, s.tex)
|
||||
s.state.deleteRenderbuffer(s.c, s.depth)
|
||||
if s.blitted {
|
||||
s.state.deleteBuffer(s.c, s.quad)
|
||||
s.state.deleteProgram(s.c, s.prog)
|
||||
|
||||
Reference in New Issue
Block a user