gpu/internal/opengl,app/internal/wm: generalize desktop OpenGL support

This changes moves the macOS specific setup for desktop OpenGL to the
portable opengl package. The opengl package already takes care of the
desktop OpenGL setup for sRGB framebuffers, and by moving the code we
avoid calling the wrong OpenGL functions in case both OpenGL.framework
and ANGLE libGLESv2.dylib is linked into the program.

Remove the interface casting expressions for gl.Functions; it wasn't
worth the trouble to keep updated.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2021-06-01 17:47:13 +02:00
parent c21897620b
commit 476d2269a6
9 changed files with 98 additions and 102 deletions
+13
View File
@@ -36,6 +36,10 @@ type Backend struct {
sRGBFBO *srgb.FBO
enabledSRGB bool
defFBO gl.Framebuffer
// defVertArray is bound during a frame. We don't need it, but
// core desktop OpenGL profile 3.3 requires some array bound.
defVertArray gl.VertexArray
}
// State tracking.
@@ -205,6 +209,10 @@ func (b *Backend) BeginFrame(clear bool, viewport image.Point) driver.Framebuffe
if b.enabledSRGB {
b.funcs.Enable(gl.FRAMEBUFFER_SRGB)
}
if !b.defVertArray.Valid() {
b.defVertArray = b.funcs.CreateVertexArray()
}
b.funcs.BindVertexArray(b.defVertArray)
}
b.funcs.BindFramebuffer(gl.FRAMEBUFFER, renderFBO)
if b.sRGBFBO != nil && !clear {
@@ -230,6 +238,8 @@ func (b *Backend) EndFrame() {
if b.enabledSRGB {
b.funcs.Disable(gl.FRAMEBUFFER_SRGB)
}
// For single-buffered framebuffers such as on macOS.
b.funcs.Flush()
}
func (b *Backend) Caps() driver.Caps {
@@ -368,6 +378,9 @@ func (b *Backend) Release() {
if b.sRGBFBO != nil {
b.sRGBFBO.Release()
}
if b.defVertArray.Valid() {
b.funcs.DeleteVertexArray(b.defVertArray)
}
*b = Backend{}
}