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
+42 -1
View File
@@ -67,6 +67,7 @@ typedef struct {
void (*glEnable)(GLenum cap);
void (*glEnableVertexAttribArray)(GLuint index);
void (*glFinish)(void);
void (*glFlush)(void);
void (*glFramebufferRenderbuffer)(GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer);
void (*glFramebufferTexture2D)(GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level);
void (*glGenBuffers)(GLsizei n, GLuint *buffers);
@@ -102,15 +103,17 @@ typedef struct {
void (*glVertexAttribPointer)(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const void *pointer);
void (*glViewport)(GLint x, GLint y, GLsizei width, GLsizei height);
void (*glBindVertexArray)(GLuint array);
void (*glBindBufferBase)(GLenum target, GLuint index, GLuint buffer);
GLuint (*glGetUniformBlockIndex)(GLuint program, const GLchar *uniformBlockName);
void (*glUniformBlockBinding)(GLuint program, GLuint uniformBlockIndex, GLuint uniformBlockBinding);
void (*glInvalidateFramebuffer)(GLenum target, GLsizei numAttachments, const GLenum *attachments);
void (*glBeginQuery)(GLenum target, GLuint id);
void (*glDeleteQueries)(GLsizei n, const GLuint *ids);
void (*glDeleteVertexArrays)(GLsizei n, const GLuint *ids);
void (*glEndQuery)(GLenum target);
void (*glGenQueries)(GLsizei n, GLuint *ids);
void (*glGenVertexArrays)(GLsizei n, GLuint *ids);
void (*glGetProgramBinary)(GLuint program, GLsizei bufsize, GLsizei *length, GLenum *binaryFormat, void *binary);
void (*glGetQueryObjectuiv)(GLuint id, GLenum pname, GLuint *params);
const GLubyte* (*glGetStringi)(GLenum name, GLuint index);
@@ -151,6 +154,10 @@ static void glBindTexture(glFunctions *f, GLenum target, GLuint texture) {
f->glBindTexture(target, texture);
}
static void glBindVertexArray(glFunctions *f, GLuint array) {
f->glBindVertexArray(array);
}
static void glBlendEquation(glFunctions *f, GLenum mode) {
f->glBlendEquation(mode);
}
@@ -256,6 +263,10 @@ static void glFinish(glFunctions *f) {
f->glFinish();
}
static void glFlush(glFunctions *f) {
f->glFlush();
}
static void glFramebufferRenderbuffer(glFunctions *f, GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer) {
f->glFramebufferRenderbuffer(target, attachment, renderbuffertarget, renderbuffer);
}
@@ -420,6 +431,10 @@ static void glDeleteQueries(glFunctions *f, GLsizei n, const GLuint *ids) {
f->glDeleteQueries(n, ids);
}
static void glDeleteVertexArrays(glFunctions *f, GLsizei n, const GLuint *ids) {
f->glDeleteVertexArrays(n, ids);
}
static void glEndQuery(glFunctions *f, GLenum target) {
f->glEndQuery(target);
}
@@ -432,6 +447,10 @@ static void glGenQueries(glFunctions *f, GLsizei n, GLuint *ids) {
f->glGenQueries(n, ids);
}
static void glGenVertexArrays(glFunctions *f, GLsizei n, GLuint *ids) {
f->glGenVertexArrays(n, ids);
}
static void glGetProgramBinary(glFunctions *f, GLuint program, GLsizei bufsize, GLsizei *length, GLenum *binaryFormat, void *binary) {
f->glGetProgramBinary(program, bufsize, length, binaryFormat, binary);
}
@@ -577,6 +596,7 @@ func (f *Functions) load(forceES bool) error {
f.f.glEnable = must("glEnable")
f.f.glEnableVertexAttribArray = must("glEnableVertexAttribArray")
f.f.glFinish = must("glFinish")
f.f.glFlush = must("glFlush")
f.f.glFramebufferRenderbuffer = must("glFramebufferRenderbuffer")
f.f.glFramebufferTexture2D = must("glFramebufferTexture2D")
f.f.glGenBuffers = must("glGenBuffers")
@@ -614,6 +634,7 @@ func (f *Functions) load(forceES bool) error {
// Extensions and GL ES 3 functions.
f.f.glBindBufferBase = load("glBindBufferBase")
f.f.glBindVertexArray = must("glBindVertexArray")
f.f.glGetUniformBlockIndex = load("glGetUniformBlockIndex")
f.f.glUniformBlockBinding = load("glUniformBlockBinding")
f.f.glInvalidateFramebuffer = load("glInvalidateFramebuffer")
@@ -644,6 +665,8 @@ func (f *Functions) load(forceES bool) error {
f.f.glGetQueryObjectuiv = load("glGetQueryObjectuivEXT")
}
f.f.glDeleteVertexArrays = load("glDeleteVertexArrays")
f.f.glGenVertexArrays = load("glGenVertexArrays")
f.f.glMemoryBarrier = load("glMemoryBarrier")
f.f.glDispatchCompute = load("glDispatchCompute")
f.f.glMapBufferRange = load("glMapBufferRange")
@@ -702,6 +725,10 @@ func (f *Functions) BindTexture(target Enum, t Texture) {
C.glBindTexture(&f.f, C.GLenum(target), C.GLuint(t.V))
}
func (f *Functions) BindVertexArray(a VertexArray) {
C.glBindVertexArray(&f.f, C.GLuint(a.V))
}
func (f *Functions) BlendEquation(mode Enum) {
C.glBlendEquation(&f.f, C.GLenum(mode))
}
@@ -783,6 +810,11 @@ func (f *Functions) CreateTexture() Texture {
return Texture{uint(f.uints[0])}
}
func (f *Functions) CreateVertexArray() VertexArray {
C.glGenVertexArrays(&f.f, 1, &f.uints[0])
return VertexArray{uint(f.uints[0])}
}
func (f *Functions) DeleteBuffer(v Buffer) {
f.uints[0] = C.GLuint(v.V)
C.glDeleteBuffers(&f.f, 1, &f.uints[0])
@@ -802,6 +834,11 @@ func (f *Functions) DeleteQuery(query Query) {
C.glDeleteQueries(&f.f, 1, &f.uints[0])
}
func (f *Functions) DeleteVertexArray(array VertexArray) {
f.uints[0] = C.GLuint(array.V)
C.glDeleteVertexArrays(&f.f, 1, &f.uints[0])
}
func (f *Functions) DeleteRenderbuffer(v Renderbuffer) {
f.uints[0] = C.GLuint(v.V)
C.glDeleteRenderbuffers(&f.f, 1, &f.uints[0])
@@ -864,6 +901,10 @@ func (f *Functions) Finish() {
C.glFinish(&f.f)
}
func (f *Functions) Flush() {
C.glFlush(&f.f)
}
func (f *Functions) FramebufferRenderbuffer(target, attachment, renderbuffertarget Enum, renderbuffer Renderbuffer) {
C.glFramebufferRenderbuffer(&f.f, C.GLenum(target), C.GLenum(attachment), C.GLenum(renderbuffertarget), C.GLuint(renderbuffer.V))
}