]> git.cworth.org Git - apitrace-tests/blob - apps/egl/gles1/debug_marker.c
Add --exact, --no-deps, or --no-prune to trim tests as needed
[apitrace-tests] / apps / egl / gles1 / debug_marker.c
1 /*
2  * Copyright (C) 2008  Brian Paul   All Rights Reserved.
3  * 
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:
10  * 
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  * 
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.
20  */
21
22
23 #include <assert.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include <GLES/gl.h>  /* use OpenGL ES 1.x */
28 #include <GLES/glext.h>
29 #include <EGL/egl.h>
30
31 #include "eglut.h"
32
33
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);
37
38 static PFNGLINSERTEVENTMARKEREXT glInsertEventMarkerEXT = NULL;
39 static PFNGLPUSHGROUPMARKEREXT glPushGroupMarkerEXT = NULL;
40 static PFNGLPOPGROUPMARKEREXT glPopGroupMarkerEXT = NULL;
41    
42 GLboolean has_GL_EXT_debug_marker = GL_FALSE;
43
44
45 /**
46  * Identical to gluCheckExtension, which is not part of GLU on Windows.
47  */
48 static GLboolean
49 checkExtension(const char *extName, const GLubyte *extString)
50 {
51    const char *p = (const char *)extString;
52    const char *q = extName;
53    char c;
54    do {
55        c = *p++;
56        if (c == '\0' || c == ' ') {
57            if (q && *q == '\0') {
58                return GL_TRUE;
59            } else {
60                q = extName;
61            }
62        } else {
63            if (q && *q == c) {
64                ++q;
65            } else {
66                q = 0;
67            }
68        }
69    } while (c);
70    return GL_FALSE;
71 }
72
73
74 static void
75 checkGlError(const char *call)
76 {
77    GLenum error = glGetError();
78    if (error != GL_NO_ERROR) {
79       fprintf(stderr, "error: %s -> 0x%04x\n", call, error);
80       exit(1);
81    }
82 }
83
84
85 static void
86 idle(void)
87 {
88    exit(0);
89 }
90
91
92 static void
93 draw(void)
94 {
95    if (has_GL_EXT_debug_marker) {
96        glPushGroupMarkerEXT(0, __FUNCTION__);
97    }
98
99    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
100
101    if (has_GL_EXT_debug_marker) {
102        glPopGroupMarkerEXT();
103    }
104
105    eglutIdleFunc(idle);
106 }
107
108
109 /* new window size or exposure */
110 static void
111 reshape(int width, int height)
112 {
113    glViewport(0, 0, (GLint) width, (GLint) height);
114 }
115
116
117 static void
118 init(void)
119 {
120    const GLubyte *extensions;
121       
122    extensions = glGetString(GL_EXTENSIONS);
123    checkGlError("glGetString(GL_EXTENSIONS)");
124    has_GL_EXT_debug_marker = checkExtension("GL_EXT_debug_marker", extensions);
125
126    if (has_GL_EXT_debug_marker) {
127
128 #define GET_PROC(name, type) \
129    name = (type)eglGetProcAddress(#name); \
130    if (!name) { \
131       fprintf(stderr, "error: eglGetProcAddress(\"" #name "\" returned NULL\n"); \
132       exit(1); \
133    }
134
135       GET_PROC(glInsertEventMarkerEXT, PFNGLINSERTEVENTMARKEREXT)
136       GET_PROC(glPushGroupMarkerEXT, PFNGLPUSHGROUPMARKEREXT)
137       GET_PROC(glPopGroupMarkerEXT, PFNGLPOPGROUPMARKEREXT)
138
139 #undef GET_PROC
140
141       glInsertEventMarkerEXT(strlen("Init"), "Init - this should not be included");
142    }
143
144    glClearColor(0.4, 0.4, 0.4, 0.0);
145 }
146
147 int
148 main(int argc, char *argv[])
149 {
150    eglutInitWindowSize(300, 300);
151    eglutInitAPIMask(EGLUT_OPENGL_ES1_BIT);
152    eglutInit(argc, argv);
153
154    eglutCreateWindow("debug_marker");
155
156    eglutReshapeFunc(reshape);
157    eglutDisplayFunc(draw);
158
159    init();
160
161    eglutMainLoop();
162
163    return 0;
164 }