graphicsdriver/opengl: Add program error info to the error

This commit is contained in:
Hajime Hoshi 2020-08-01 18:39:17 +09:00
parent a4334c5464
commit 38dcadb233
5 changed files with 40 additions and 8 deletions

View File

@ -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

View File

@ -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

View File

@ -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
}

View File

@ -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")

View File

@ -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")