Skip to content

Commit

Permalink
internal/gl: implement glGetProgramBinary
Browse files Browse the repository at this point in the history
Useful for debugging shader compiler issues, such as those that may
cause

linebender/vello#83

Signed-off-by: Elias Naur <[email protected]>
  • Loading branch information
eliasnaur committed Apr 18, 2021
1 parent 3b69b5e commit f930e3f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/gl/gl.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const (
NUM_EXTENSIONS = 0x821D
ONE = 0x1
ONE_MINUS_SRC_ALPHA = 0x303
PROGRAM_BINARY_LENGTH = 0x8741
QUERY_RESULT = 0x8866
QUERY_RESULT_AVAILABLE = 0x8867
R16F = 0x822d
Expand Down
17 changes: 17 additions & 0 deletions internal/gl/gl_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ static void (*_glBeginQuery)(GLenum target, GLuint id);
static void (*_glDeleteQueries)(GLsizei n, const GLuint *ids);
static void (*_glEndQuery)(GLenum target);
static void (*_glGenQueries)(GLsizei n, GLuint *ids);
static void (*_glGetProgramBinary)(GLuint program, GLsizei bufsize, GLsizei *length, GLenum *binaryFormat, void *binary);
static void (*_glGetQueryObjectuiv)(GLuint id, GLenum pname, GLuint *params);
static const GLubyte* (*_glGetStringi)(GLenum name, GLuint index);
static void (*_glMemoryBarrier)(GLbitfield barriers);
Expand Down Expand Up @@ -111,6 +112,10 @@ __attribute__ ((visibility ("hidden"))) void gio_glGenQueries(GLsizei n, GLuint
_glGenQueries(n, ids);
}
__attribute__ ((visibility ("hidden"))) void gio_glGetProgramBinary(GLuint program, GLsizei bufsize, GLsizei *length, GLenum *binaryFormat, void *binary) {
_glGetProgramBinary(program, bufsize, length, binaryFormat, binary);
}
__attribute__ ((visibility ("hidden"))) void gio_glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) {
_glGetQueryObjectuiv(id, pname, params);
}
Expand Down Expand Up @@ -180,6 +185,7 @@ __attribute__((constructor)) static void gio_loadGLFunctions() {
_glBindImageTexture = dlsym(RTLD_DEFAULT, "glBindImageTexture");
_glTexStorage2D = dlsym(RTLD_DEFAULT, "glTexStorage2D");
_glBlitFramebuffer = dlsym(RTLD_DEFAULT, "glBlitFramebuffer");
_glGetProgramBinary = dlsym(RTLD_DEFAULT, "glGetProgramBinary");
}
*/
import "C"
Expand Down Expand Up @@ -443,6 +449,17 @@ func (f *Functions) GetProgrami(p Program, pname Enum) int {
return int(f.ints[0])
}

func (f *Functions) GetProgramBinary(p Program) []byte {
sz := f.GetProgrami(p, PROGRAM_BINARY_LENGTH)
if sz == 0 {
return nil
}
buf := make([]byte, sz)
var format C.GLenum
C.gio_glGetProgramBinary(C.GLuint(p.V), C.GLsizei(sz), nil, &format, unsafe.Pointer(&buf[0]))
return buf
}

func (f *Functions) GetProgramInfoLog(p Program) string {
n := f.GetProgrami(p, INFO_LOG_LENGTH)
buf := make([]byte, n)
Expand Down

0 comments on commit f930e3f

Please sign in to comment.