]> git.cworth.org Git - apitrace-tests/blob - apps/gl/gremedy.c
Test for GREMEDY support.
[apitrace-tests] / apps / gl / gremedy.c
1 /*
2  * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3  *
4  * Permission to use, copy, modify, distribute, and sell this software and
5  * its documentation for any purpose is hereby granted without fee, provided
6  * that (i) the above copyright notices and this permission notice appear in
7  * all copies of the software and related documentation, and (ii) the name of
8  * Silicon Graphics may not be used in any advertising or
9  * publicity relating to the software without the specific, prior written
10  * permission of Silicon Graphics.
11  *
12  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13  * ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24
25
26 #ifdef _WIN32
27 #include <windows.h>
28 #endif
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33
34 #include <GL/glew.h>
35 #ifdef __APPLE__
36 #  include <OpenGL/glu.h>
37 #  include <GLUT/glut.h>
38 #else
39 #  include <GL/glu.h>
40 #  include <GL/glut.h>
41 #endif
42
43
44 static int win;
45
46
47 static void checkGlError(const char *call) {
48    GLenum error = glGetError();
49    if (error != GL_NO_ERROR) {
50       fprintf(stderr, "error: %s -> %s\n", call, gluErrorString(error));
51       exit(1);
52    }
53 }
54
55 static void Init(void)
56 {
57    const GLubyte *extensions;
58    GLboolean has_GL_GREMEDY_string_marker;
59    GLboolean has_GL_GREMEDY_frame_terminator;
60       
61    extensions = glGetString(GL_EXTENSIONS);
62    checkGlError("glGetString(GL_EXTENSIONS)");
63    has_GL_GREMEDY_string_marker = gluCheckExtension("GL_GREMEDY_string_marker", extensions);
64    has_GL_GREMEDY_frame_terminator = gluCheckExtension("GL_GREMEDY_string_marker", extensions);
65
66    if (GLEW_VERSION_3_0) {
67       GLint has_GL3_GREMEDY_string_marker = 0;
68       GLint has_GL3_GREMEDY_frame_terminator = 0;
69       GLint i;
70
71       GLint num_extensions = 0;
72       glGetIntegerv(GL_NUM_EXTENSIONS, &num_extensions);
73       checkGlError("glGetIntegerv(GL_NUM_EXTENSIONS)");
74
75       for (i = 0; i < num_extensions; ++i) {
76          const char *extension;
77
78          extension = (const char *)glGetStringi(GL_EXTENSIONS, i);
79          checkGlError("glGetStringi(GL_EXTENSIONS, i)");
80
81          if (strlen(extension) == 0) {
82             fprintf(stderr, "error: glGetStringi returned empty string\n");
83             exit(1);
84          }
85
86          if (strcmp(extension, "GL_GREMEDY_string_marker_count") == 0) {
87             ++has_GL3_GREMEDY_string_marker;
88          }
89
90          if (strcmp(extension, "GL_GREMEDY_frame_terminator") == 0) {
91             ++has_GL3_GREMEDY_frame_terminator;
92          }
93       }
94
95       if (!!has_GL_GREMEDY_string_marker != !!has_GL3_GREMEDY_string_marker) {
96          fprintf(stderr, "error: GL_GREMEDY_string_marker not consistently supported by GL3\n");
97          exit(1);
98       }
99
100       if (!!has_GL_GREMEDY_frame_terminator != !!has_GL3_GREMEDY_frame_terminator) {
101          fprintf(stderr, "error: GL_GREMEDY_frame_terminator not consistently supported by GL3\n");
102          exit(1);
103       }
104    }
105
106    glewInit();
107
108    if (!!has_GL_GREMEDY_string_marker != !!GLEW_GREMEDY_string_marker) {
109       fprintf(stderr, "error: GL_GREMEDY_string_marker not consistently supported by GLEW\n");
110       exit(1);
111    }
112
113    if (!!has_GL_GREMEDY_frame_terminator != !!GLEW_GREMEDY_frame_terminator) {
114       fprintf(stderr, "error: GL_GREMEDY_frame_terminator not consistently supported by GLEW\n");
115       exit(1);
116    }
117
118    if (GLEW_GREMEDY_string_marker) {
119       glStringMarkerGREMEDY(strlen("Init"), "Init - this should not be included");
120    }
121
122    glClearColor(0.3, 0.1, 0.3, 1.0);
123 }
124
125 static void Reshape(int width, int height)
126 {
127    if (GLEW_GREMEDY_string_marker) {
128       glStringMarkerGREMEDY(0, __FUNCTION__);
129    }
130
131    glViewport(0, 0, (GLint)width, (GLint)height);
132
133    glMatrixMode(GL_PROJECTION);
134    glLoadIdentity();
135    glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
136    glMatrixMode(GL_MODELVIEW);
137 }
138
139 static void Draw(void)
140 {
141    if (GLEW_GREMEDY_string_marker) {
142       glStringMarkerGREMEDY(0, __FUNCTION__);
143    }
144
145    glClear(GL_COLOR_BUFFER_BIT); 
146
147    glBegin(GL_TRIANGLES);
148    glColor3f(.8,0,0); 
149    glVertex3f(-0.9, -0.9, -30.0);
150    glColor3f(0,.9,0); 
151    glVertex3f( 0.9, -0.9, -30.0);
152    glColor3f(0,0,.7); 
153    glVertex3f( 0.0,  0.9, -30.0);
154    glEnd();
155
156    glFlush();
157
158    if (GLEW_GREMEDY_frame_terminator) {
159       glFrameTerminatorGREMEDY();
160    }
161
162    glutDestroyWindow(win);
163    
164    exit(0);
165 }
166
167 int main(int argc, char **argv)
168 {
169    glutInit(&argc, argv);
170
171    glutInitWindowPosition(0, 0);
172    glutInitWindowSize(250, 250);
173
174    glutInitDisplayMode(GLUT_RGB | GLUT_ALPHA | GLUT_SINGLE);
175
176    win = glutCreateWindow(*argv);
177    if (!win) {
178       exit(1);
179    }
180
181    Init();
182
183    glutReshapeFunc(Reshape);
184    glutDisplayFunc(Draw);
185    glutMainLoop();
186    return 0;
187 }