From 38dcadb233cb7eda803279a7055734ffd8d26f9e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 1 Aug 2020 18:39:17 +0900 Subject: [PATCH] graphicsdriver/opengl: Add program error info to the error --- .../graphicsdriver/opengl/context_desktop.go | 20 +++++++++++++------ internal/graphicsdriver/opengl/context_js.go | 3 ++- .../graphicsdriver/opengl/context_mobile.go | 3 ++- .../opengl/gl/package_notwindows.go | 13 ++++++++++++ .../opengl/gl/package_windows.go | 9 +++++++++ 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/internal/graphicsdriver/opengl/context_desktop.go b/internal/graphicsdriver/opengl/context_desktop.go index 7743703a1..6dc49ba54 100644 --- a/internal/graphicsdriver/opengl/context_desktop.go +++ b/internal/graphicsdriver/opengl/context_desktop.go @@ -305,11 +305,12 @@ func (c *context) newShader(shaderType shaderType, source string) (shader, error var v int32 gl.GetShaderiv(s, gl.COMPILE_STATUS, &v) if v == gl.FALSE { - log := []byte{} - gl.GetShaderiv(uint32(s), gl.INFO_LOG_LENGTH, &v) - if v != 0 { - log = make([]byte, int(v)) - gl.GetShaderInfoLog(uint32(s), v, nil, (*uint8)(gl.Ptr(log))) + var l int32 + var log []byte + gl.GetShaderiv(uint32(s), gl.INFO_LOG_LENGTH, &l) + if l != 0 { + log = make([]byte, l) + gl.GetShaderInfoLog(s, l, nil, (*uint8)(gl.Ptr(log))) } return fmt.Errorf("opengl: shader compile failed: %s", log) } @@ -350,7 +351,14 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er var v int32 gl.GetProgramiv(p, gl.LINK_STATUS, &v) if v == gl.FALSE { - return errors.New("opengl: program error") + var l int32 + var log []byte + gl.GetProgramiv(p, gl.INFO_LOG_LENGTH, &l) + if l != 0 { + log = make([]byte, l) + gl.GetProgramInfoLog(p, l, nil, (*uint8)(gl.Ptr(log))) + } + return fmt.Errorf("opengl: program error: %s", log) } pr = program(p) return nil diff --git a/internal/graphicsdriver/opengl/context_js.go b/internal/graphicsdriver/opengl/context_js.go index 51bcfd224..7082ac449 100644 --- a/internal/graphicsdriver/opengl/context_js.go +++ b/internal/graphicsdriver/opengl/context_js.go @@ -395,7 +395,8 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er gl.Call("linkProgram", v) if !gl.Call("getProgramParameter", v, linkStatus).Bool() { - return program{}, errors.New("opengl: program error") + info := gl.Call("getProgramInfoLog", v).String() + return program{}, fmt.Errorf("opengl: program error: %s", info) } id := c.lastProgramID diff --git a/internal/graphicsdriver/opengl/context_mobile.go b/internal/graphicsdriver/opengl/context_mobile.go index 10d47b16a..61869767e 100644 --- a/internal/graphicsdriver/opengl/context_mobile.go +++ b/internal/graphicsdriver/opengl/context_mobile.go @@ -268,7 +268,8 @@ func (c *context) newProgram(shaders []shader, attributes []string) (program, er gl.LinkProgram(p) v := gl.GetProgrami(p, mgl.LINK_STATUS) if v == mgl.FALSE { - return program{}, errors.New("opengl: program error") + info := gl.GetProgramInfoLog(p) + return program{}, fmt.Errorf("opengl: program error: %s", info) } return program(p), nil } diff --git a/internal/graphicsdriver/opengl/gl/package_notwindows.go b/internal/graphicsdriver/opengl/gl/package_notwindows.go index 79e95a948..eda4f2224 100644 --- a/internal/graphicsdriver/opengl/gl/package_notwindows.go +++ b/internal/graphicsdriver/opengl/gl/package_notwindows.go @@ -132,6 +132,7 @@ package gl // typedef void (APIENTRYP GPGETINTEGERUI64I_VNV)(GLenum value, GLuint index, GLuint64EXT * result); // typedef void (APIENTRYP GPGETINTEGERV)(GLenum pname, GLint * data); // typedef void (APIENTRYP GPGETPOINTERI_VEXT)(GLenum pname, GLuint index, void ** params); +// typedef void (APIENTRYP GPGETPROGRAMINFOLOG)(GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog); // typedef void (APIENTRYP GPGETPROGRAMIV)(GLuint program, GLenum pname, GLint * params); // typedef void (APIENTRYP GPGETSHADERINFOLOG)(GLuint shader, GLsizei bufSize, GLsizei * length, GLchar * infoLog); // typedef void (APIENTRYP GPGETSHADERIV)(GLuint shader, GLenum pname, GLint * params); @@ -272,6 +273,9 @@ package gl // static void glowGetPointeri_vEXT(GPGETPOINTERI_VEXT fnptr, GLenum pname, GLuint index, void ** params) { // (*fnptr)(pname, index, params); // } +// static void glowGetProgramInfoLog(GPGETPROGRAMINFOLOG fnptr, GLuint program, GLsizei bufSize, GLsizei * length, GLchar * infoLog) { +// (*fnptr)(program, bufSize, length, infoLog); +// } // static void glowGetProgramiv(GPGETPROGRAMIV fnptr, GLuint program, GLenum pname, GLint * params) { // (*fnptr)(program, pname, params); // } @@ -409,6 +413,7 @@ var ( gpGetIntegerui64i_vNV C.GPGETINTEGERUI64I_VNV gpGetIntegerv C.GPGETINTEGERV gpGetPointeri_vEXT C.GPGETPOINTERI_VEXT + gpGetProgramInfoLog C.GPGETPROGRAMINFOLOG gpGetProgramiv C.GPGETPROGRAMIV gpGetShaderInfoLog C.GPGETSHADERINFOLOG gpGetShaderiv C.GPGETSHADERIV @@ -592,6 +597,10 @@ func GetPointeri_vEXT(pname uint32, index uint32, params *unsafe.Pointer) { C.glowGetPointeri_vEXT(gpGetPointeri_vEXT, (C.GLenum)(pname), (C.GLuint)(index), params) } +func GetProgramInfoLog(program uint32, bufSize int32, length *int32, infoLog *uint8) { + C.glowGetProgramInfoLog(gpGetProgramInfoLog, (C.GLuint)(program), (C.GLsizei)(bufSize), (*C.GLsizei)(unsafe.Pointer(length)), (*C.GLchar)(unsafe.Pointer(infoLog))) +} + func GetProgramiv(program uint32, pname uint32, params *int32) { C.glowGetProgramiv(gpGetProgramiv, (C.GLuint)(program), (C.GLenum)(pname), (*C.GLint)(unsafe.Pointer(params))) } @@ -828,6 +837,10 @@ func InitWithProcAddrFunc(getProcAddr func(name string) unsafe.Pointer) error { return errors.New("glGetIntegerv") } gpGetPointeri_vEXT = (C.GPGETPOINTERI_VEXT)(getProcAddr("glGetPointeri_vEXT")) + gpGetProgramInfoLog = (C.GPGETPROGRAMINFOLOG)(getProcAddr("glGetProgramInfoLog")) + if gpGetProgramInfoLog == nil { + return errors.New("glGetProgramInfoLog") + } gpGetProgramiv = (C.GPGETPROGRAMIV)(getProcAddr("glGetProgramiv")) if gpGetProgramiv == nil { return errors.New("glGetProgramiv") diff --git a/internal/graphicsdriver/opengl/gl/package_windows.go b/internal/graphicsdriver/opengl/gl/package_windows.go index c6d99dceb..9d1faf152 100644 --- a/internal/graphicsdriver/opengl/gl/package_windows.go +++ b/internal/graphicsdriver/opengl/gl/package_windows.go @@ -46,6 +46,7 @@ var ( gpGetIntegerui64i_vNV uintptr gpGetIntegerv uintptr gpGetPointeri_vEXT uintptr + gpGetProgramInfoLog uintptr gpGetProgramiv uintptr gpGetShaderInfoLog uintptr gpGetShaderiv uintptr @@ -229,6 +230,10 @@ func GetPointeri_vEXT(pname uint32, index uint32, params *unsafe.Pointer) { syscall.Syscall(gpGetPointeri_vEXT, 3, uintptr(pname), uintptr(index), uintptr(unsafe.Pointer(params))) } +func GetProgramInfoLog(program uint32, bufSize int32, length *int32, infoLog *uint8) { + syscall.Syscall6(gpGetProgramInfoLog, 4, uintptr(program), uintptr(bufSize), uintptr(unsafe.Pointer(length)), uintptr(unsafe.Pointer(infoLog)), 0, 0) +} + func GetProgramiv(program uint32, pname uint32, params *int32) { syscall.Syscall(gpGetProgramiv, 3, uintptr(program), uintptr(pname), uintptr(unsafe.Pointer(params))) } @@ -465,6 +470,10 @@ func InitWithProcAddrFunc(getProcAddr func(name string) uintptr) error { return errors.New("glGetIntegerv") } gpGetPointeri_vEXT = getProcAddr("glGetPointeri_vEXT") + gpGetProgramInfoLog = getProcAddr("glGetProgramInfoLog") + if gpGetProgramInfoLog == 0 { + return errors.New("glGetProgramInfoLog") + } gpGetProgramiv = getProcAddr("glGetProgramiv") if gpGetProgramiv == 0 { return errors.New("glGetProgramiv")