aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Waller <p@pwaller.net>2014-03-17 09:05:44 +0000
committerPeter Waller <p@pwaller.net>2014-03-17 09:05:44 +0000
commit45a63e63bf73f5f98ab120e36f243989592cb035 (patch)
tree86f3e3eff216535dfa27ed0389758769af4da728
parente7d541a2bdc771b569d65f48e6358d0309524e28 (diff)
parenta22da3fab54677ac0384ace54a6eca002a0bd968 (diff)
downloadgl-45a63e63bf73f5f98ab120e36f243989592cb035.tar.gz
Merge pull request #137 from kiryl/master
Implement bindings for debug output feature
-rw-r--r--debugoutput.go93
-rw-r--r--gl_defs.go22
2 files changed, 115 insertions, 0 deletions
diff --git a/debugoutput.go b/debugoutput.go
new file mode 100644
index 0000000..122f22b
--- /dev/null
+++ b/debugoutput.go
@@ -0,0 +1,93 @@
+// Copyright 2012 The go-gl Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package gl
+
+import "unsafe"
+
+// #include "gl.h"
+//
+// void goDebugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, char *message);
+//
+// static inline void debugProcCB(GLenum source,
+// GLenum type,
+// GLuint id,
+// GLenum severity,
+// GLsizei length,
+// const GLchar* message,
+// void* userParam)
+// {
+// goDebugCB(source, type, id, severity, length, (char *)message);
+// }
+//
+// static inline void glDebugMessageCB(void)
+// {
+// glDebugMessageCallbackARB(debugProcCB, NULL);
+// }
+//
+// /*
+// * Depending on glew version 'message' could be 'GLchar*' or 'char*' which
+// * causes problems in more strict Go type system. Let's work it around in C
+// */
+// static inline void __glDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity,
+// GLsizei length, const char *message)
+// {
+// glDebugMessageInsertARB(source, type, id, severity, length, message);
+// }
+//
+// static inline void GetDebugMessageLog(GLuint count, GLsizei bufSize, GLenum *sources,
+// GLenum *types, GLuint *ids, GLenum *severities, GLsizei *lengths, char *messageLog)
+// {
+// glGetDebugMessageLogARB(count, bufSize, sources, types, ids, severities, lengths, messageLog);
+// }
+import "C"
+
+type debugProc func(source GLenum, typ GLenum, id uint, severity GLenum, message string)
+
+var debugCB debugProc
+
+//export goDebugCB
+func goDebugCB(source GLenum, typ GLenum, id GLuint, severity GLenum, length GLsizei, message *C.char) {
+ debugCB(source, typ, uint(id), severity, C.GoStringN(message, C.int(length)))
+}
+
+func DebugMessageCallback(cbfunc debugProc) {
+ if cbfunc == nil {
+ C.glDebugMessageCallbackARB(nil, nil)
+ } else {
+ debugCB = cbfunc
+ C.glDebugMessageCB()
+ }
+}
+
+func DebugMessageControl(source GLenum, typ GLenum, severity GLenum, ids []uint, enabled bool) {
+ C.glDebugMessageControlARB(C.GLenum(source), C.GLenum(typ), C.GLenum(severity),
+ C.GLsizei(len(ids)), (*C.GLuint)(unsafe.Pointer(&ids)), glBool(enabled))
+}
+
+func DebugMessageInsert(source GLenum, typ GLenum, id uint, severity GLenum, message string) {
+ C.__glDebugMessageInsert(C.GLenum(source), C.GLenum(typ), C.GLuint(id), C.GLenum(severity),
+ C.GLsizei(len(message)), C.CString(message))
+}
+
+func GetNextDebugMessage() (msg string, source GLenum, typ GLenum, id uint, severity GLenum) {
+ length := []int32{0}
+ GetIntegerv(DEBUG_NEXT_LOGGED_MESSAGE_LENGTH, length)
+ if length[0] < 1 {
+ msg = ""
+ return
+ }
+
+ buf := C.malloc(C.size_t(length[0]))
+ defer C.free(buf)
+
+ _id := []GLuint{0}
+ C.GetDebugMessageLog(C.GLuint(1), C.GLsizei(length[0]),
+ (*C.GLenum)(&source), (*C.GLenum)(&typ), (*C.GLuint)(&_id[0]),
+ (*C.GLenum)(&severity), nil, (*C.char)(buf))
+
+ id = uint(_id[0])
+ msg = C.GoString((*C.char)(buf))
+ return
+}
diff --git a/gl_defs.go b/gl_defs.go
index 26d17a3..075af1b 100644
--- a/gl_defs.go
+++ b/gl_defs.go
@@ -261,6 +261,26 @@ const (
DECAL = C.GL_DECAL
DECR_WRAP = C.GL_DECR_WRAP
DECR = C.GL_DECR
+ DEBUG_OUTPUT_SYNCHRONOUS = C.GL_DEBUG_OUTPUT_SYNCHRONOUS_ARB
+ DEBUG_NEXT_LOGGED_MESSAGE_LENGTH = C.GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH_ARB
+ DEBUG_CALLBACK_FUNCTION = C.GL_DEBUG_CALLBACK_FUNCTION_ARB
+ DEBUG_CALLBACK_USER_PARAM = C.GL_DEBUG_CALLBACK_USER_PARAM_ARB
+ DEBUG_SOURCE_API = C.GL_DEBUG_SOURCE_API_ARB
+ DEBUG_SOURCE_WINDOW_SYSTEM = C.GL_DEBUG_SOURCE_WINDOW_SYSTEM_ARB
+ DEBUG_SOURCE_SHADER_COMPILER = C.GL_DEBUG_SOURCE_SHADER_COMPILER_ARB
+ DEBUG_SOURCE_THIRD_PARTY = C.GL_DEBUG_SOURCE_THIRD_PARTY_ARB
+ DEBUG_SOURCE_APPLICATION = C.GL_DEBUG_SOURCE_APPLICATION_ARB
+ DEBUG_SOURCE_OTHER = C.GL_DEBUG_SOURCE_OTHER_ARB
+ DEBUG_TYPE_ERROR = C.GL_DEBUG_TYPE_ERROR_ARB
+ DEBUG_TYPE_DEPRECATED_BEHAVIOR = C.GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR_ARB
+ DEBUG_TYPE_UNDEFINED_BEHAVIOR = C.GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR_ARB
+ DEBUG_TYPE_PORTABILITY = C.GL_DEBUG_TYPE_PORTABILITY_ARB
+ DEBUG_TYPE_PERFORMANCE = C.GL_DEBUG_TYPE_PERFORMANCE_ARB
+ DEBUG_TYPE_OTHER = C.GL_DEBUG_TYPE_OTHER_ARB
+ DEBUG_LOGGED_MESSAGES = C.GL_DEBUG_LOGGED_MESSAGES_ARB
+ DEBUG_SEVERITY_HIGH = C.GL_DEBUG_SEVERITY_HIGH_ARB
+ DEBUG_SEVERITY_MEDIUM = C.GL_DEBUG_SEVERITY_MEDIUM_ARB
+ DEBUG_SEVERITY_LOW = C.GL_DEBUG_SEVERITY_LOW_ARB
DELETE_STATUS = C.GL_DELETE_STATUS
DEPTH24_STENCIL8 = C.GL_DEPTH24_STENCIL8
DEPTH32F_STENCIL8 = C.GL_DEPTH32F_STENCIL8
@@ -608,6 +628,8 @@ const (
MAX_CONVOLUTION_HEIGHT = C.GL_MAX_CONVOLUTION_HEIGHT
MAX_CONVOLUTION_WIDTH = C.GL_MAX_CONVOLUTION_WIDTH
MAX_CUBE_MAP_TEXTURE_SIZE = C.GL_MAX_CUBE_MAP_TEXTURE_SIZE
+ MAX_DEBUG_LOGGED_MESSAGES = C.GL_MAX_DEBUG_LOGGED_MESSAGES_ARB
+ MAX_DEBUG_MESSAGE_LENGTH = C.GL_MAX_DEBUG_MESSAGE_LENGTH_ARB
MAX_DEPTH_TEXTURE_SAMPLES = C.GL_MAX_DEPTH_TEXTURE_SAMPLES
MAX_DRAW_BUFFERS = C.GL_MAX_DRAW_BUFFERS
MAX_ELEMENTS_INDICES = C.GL_MAX_ELEMENTS_INDICES