From 01385442424befee4076bbda1f3c276615e145bb Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 9 Jun 2019 21:18:41 +0200 Subject: [PATCH] ui/app/internal/gl: fix GetProgramInfoLog and GetShaderInfoLog I should read the manual more carefully. Signed-off-by: Elias Naur --- ui/app/internal/gl/functions.go | 26 ++++++++------------------ ui/app/internal/gl/gl.go | 1 + ui/app/internal/gl/gl_windows.go | 26 ++++++++------------------ 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/ui/app/internal/gl/functions.go b/ui/app/internal/gl/functions.go index d8fc6aa3..57243c4c 100644 --- a/ui/app/internal/gl/functions.go +++ b/ui/app/internal/gl/functions.go @@ -336,15 +336,10 @@ func (f *Functions) GetProgrami(p Program, pname Enum) int { } func (f *Functions) GetProgramInfoLog(p Program) string { - var plen C.GLsizei - C.glGetProgramInfoLog(C.GLuint(p.V), 0, &plen, nil) - if plen == 0 { - return "" - } - // Make room for the string and the null terminator. - buf := make([]byte, plen+1) - C.glGetProgramInfoLog(C.GLuint(p.V), C.GLsizei(len(buf)), &plen, (*C.GLchar)(unsafe.Pointer(&buf[0]))) - return string(buf[:len(buf)-1]) + n := f.GetProgrami(p, INFO_LOG_LENGTH) + buf := make([]byte, n) + C.glGetProgramInfoLog(C.GLuint(p.V), C.GLsizei(len(buf)), nil, (*C.GLchar)(unsafe.Pointer(&buf[0]))) + return string(buf) } func (f *Functions) GetQueryObjectuiv(query Query, pname Enum) uint { @@ -358,15 +353,10 @@ func (f *Functions) GetShaderi(s Shader, pname Enum) int { } func (f *Functions) GetShaderInfoLog(s Shader) string { - var plen C.GLsizei - C.glGetShaderInfoLog(C.GLuint(s.V), 0, &plen, nil) - if plen == 0 { - return "" - } - // Make room for the string and the null terminator. - buf := make([]byte, plen+1) - C.glGetShaderInfoLog(C.GLuint(s.V), C.GLsizei(len(buf)), &plen, (*C.GLchar)(unsafe.Pointer(&buf[0]))) - return string(buf[:len(buf)-1]) + n := f.GetShaderi(s, INFO_LOG_LENGTH) + buf := make([]byte, n) + C.glGetShaderInfoLog(C.GLuint(s.V), C.GLsizei(len(buf)), nil, (*C.GLchar)(unsafe.Pointer(&buf[0]))) + return string(buf) } func (f *Functions) GetString(pname Enum) string { diff --git a/ui/app/internal/gl/gl.go b/ui/app/internal/gl/gl.go index 0a114526..b86bb7b5 100644 --- a/ui/app/internal/gl/gl.go +++ b/ui/app/internal/gl/gl.go @@ -38,6 +38,7 @@ const ( FRAMEBUFFER_COMPLETE = 0x8cd5 HALF_FLOAT = 0x140b HALF_FLOAT_OES = 0x8d61 + INFO_LOG_LENGTH = 0x8B84 GREATER = 0x204 LINEAR = 0x2601 LINK_STATUS = 0x8b82 diff --git a/ui/app/internal/gl/gl_windows.go b/ui/app/internal/gl/gl_windows.go index f7c7d3db..253a8176 100644 --- a/ui/app/internal/gl/gl_windows.go +++ b/ui/app/internal/gl/gl_windows.go @@ -263,15 +263,10 @@ func (c *Functions) GetProgrami(p Program, pname Enum) int { return int(c.int32s[0]) } func (c *Functions) GetProgramInfoLog(p Program) string { - var n uintptr - syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), 0, uintptr(unsafe.Pointer(&n)), 0, 0, 0) - if n == 0 { - return "" - } - // Make space for the null terminator. - buf := make([]byte, n+1) - syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)), uintptr(unsafe.Pointer(&buf[0])), 0, 0) - return string(buf[:len(buf)-1]) + n := c.GetProgrami(p, INFO_LOG_LENGTH) + buf := make([]byte, n) + syscall.Syscall6(_glGetProgramInfoLog.Addr(), 4, uintptr(p.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0) + return string(buf) } func (c *Functions) GetQueryObjectuiv(query Query, pname Enum) uint { syscall.Syscall(_glGetQueryObjectuiv.Addr(), 3, uintptr(query.V), uintptr(pname), uintptr(unsafe.Pointer(&c.int32s[0]))) @@ -282,15 +277,10 @@ func (c *Functions) GetShaderi(s Shader, pname Enum) int { return int(c.int32s[0]) } func (c *Functions) GetShaderInfoLog(s Shader) string { - var n uintptr - syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), 0, uintptr(unsafe.Pointer(&n)), 0, 0, 0) - if n == 0 { - return "" - } - // Make space for the null terminator. - buf := make([]byte, n+1) - syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), uintptr(len(buf)), uintptr(unsafe.Pointer(&n)), uintptr(unsafe.Pointer(&buf[0])), 0, 0) - return string(buf[:len(buf)-1]) + n := c.GetShaderi(s, INFO_LOG_LENGTH) + buf := make([]byte, n) + syscall.Syscall6(_glGetShaderInfoLog.Addr(), 4, uintptr(s.V), uintptr(len(buf)), 0, uintptr(unsafe.Pointer(&buf[0])), 0, 0) + return string(buf) } func (c *Functions) GetString(pname Enum) string { s, _, _ := syscall.Syscall(_glGetString.Addr(), 1, uintptr(pname), 0, 0)