2 * Copyright (C) 2008 Brian Paul All Rights Reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include <GLES/gl.h> /* use OpenGL ES 1.x */
28 #include <GLES/glext.h>
34 typedef void (GL_APIENTRY *PFNGLINSERTEVENTMARKEREXT)(GLsizei length, const char *marker);
35 typedef void (GL_APIENTRY *PFNGLPUSHGROUPMARKEREXT)(GLsizei length, const char *marker);
36 typedef void (GL_APIENTRY *PFNGLPOPGROUPMARKEREXT)(void);
38 static PFNGLINSERTEVENTMARKEREXT glInsertEventMarkerEXT = NULL;
39 static PFNGLPUSHGROUPMARKEREXT glPushGroupMarkerEXT = NULL;
40 static PFNGLPOPGROUPMARKEREXT glPopGroupMarkerEXT = NULL;
42 GLboolean has_GL_EXT_debug_marker = GL_FALSE;
46 * Identical to gluCheckExtension, which is not part of GLU on Windows.
49 checkExtension(const char *extName, const GLubyte *extString)
51 const char *p = (const char *)extString;
52 const char *q = extName;
56 if (c == '\0' || c == ' ') {
57 if (q && *q == '\0') {
75 checkGlError(const char *call)
77 GLenum error = glGetError();
78 if (error != GL_NO_ERROR) {
79 fprintf(stderr, "error: %s -> 0x%04x\n", call, error);
95 if (has_GL_EXT_debug_marker) {
96 glPushGroupMarkerEXT(0, __FUNCTION__);
99 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
101 if (has_GL_EXT_debug_marker) {
102 glPopGroupMarkerEXT();
109 /* new window size or exposure */
111 reshape(int width, int height)
113 glViewport(0, 0, (GLint) width, (GLint) height);
120 const GLubyte *extensions;
122 extensions = glGetString(GL_EXTENSIONS);
123 checkGlError("glGetString(GL_EXTENSIONS)");
124 has_GL_EXT_debug_marker = checkExtension("GL_EXT_debug_marker", extensions);
126 if (has_GL_EXT_debug_marker) {
128 #define GET_PROC(name, type) \
129 name = (type)eglGetProcAddress(#name); \
131 fprintf(stderr, "error: eglGetProcAddress(\"" #name "\" returned NULL\n"); \
135 GET_PROC(glInsertEventMarkerEXT, PFNGLINSERTEVENTMARKEREXT)
136 GET_PROC(glPushGroupMarkerEXT, PFNGLPUSHGROUPMARKEREXT)
137 GET_PROC(glPopGroupMarkerEXT, PFNGLPOPGROUPMARKEREXT)
141 glInsertEventMarkerEXT(strlen("Init"), "Init - this should not be included");
144 glClearColor(0.4, 0.4, 0.4, 0.0);
148 main(int argc, char *argv[])
150 eglutInitWindowSize(300, 300);
151 eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
152 eglutInit(argc, argv);
154 eglutCreateWindow("debug_marker");
156 eglutReshapeFunc(reshape);
157 eglutDisplayFunc(draw);