blob: ca66025d2dcc19a919018ac71b1a892ddca32a89 [file] [log] [blame]
Brian Paul17fe22d2001-11-18 23:16:56 +00001/*
Brian Paul1cfae1a2002-11-07 16:23:40 +00002 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Brian Paul17fe22d2001-11-18 23:16:56 +00003 *
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 * Test that glXGetProcAddress works.
24 */
25
Brian Pauld4ece7b2001-11-21 17:21:41 +000026#define GLX_GLXEXT_PROTOTYPES
27
Brian Paul17fe22d2001-11-18 23:16:56 +000028#include <X11/Xlib.h>
29#include <X11/Xutil.h>
30#include <GL/gl.h>
31#include <GL/glx.h>
32#include <stdio.h>
33#include <stdlib.h>
34#include <string.h>
Brian Paul03f0ddb2003-09-03 17:21:51 +000035#include <math.h>
Brian Paul17fe22d2001-11-18 23:16:56 +000036
37
Brian Paul0699b0b2004-11-27 19:57:46 +000038typedef void (*generic_func)();
39
Brian Paul9a2121c2003-06-10 14:54:37 +000040#define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001)
41
Brian Paul1ec9b5a2006-05-31 20:36:52 +000042/**
43 * The following functions are used to check that the named OpenGL function
44 * actually does what it's supposed to do.
45 * The naming of these functions is signficant. The getprocaddress.py script
46 * scans this file and extracts these function names.
47 */
48
49
Brian Pauld1efbf02002-11-08 15:35:46 +000050static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000051test_ActiveTextureARB(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000052{
53 PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func;
54 GLint t;
55 GLboolean pass;
56 (*activeTexture)(GL_TEXTURE1_ARB);
57 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &t);
58 pass = (t == GL_TEXTURE1_ARB);
59 (*activeTexture)(GL_TEXTURE0_ARB); /* restore default */
60 return pass;
61}
Brian Paul17fe22d2001-11-18 23:16:56 +000062
Brian Pauld1efbf02002-11-08 15:35:46 +000063
64static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000065test_SecondaryColor3fEXT(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000066{
67 PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func;
68 GLfloat color[4];
69 GLboolean pass;
70 (*secColor3f)(1.0, 1.0, 0.0);
71 glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT, color);
72 pass = (color[0] == 1.0 && color[1] == 1.0 && color[2] == 0.0);
73 (*secColor3f)(0.0, 0.0, 0.0); /* restore default */
74 return pass;
75}
76
77
78static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000079test_ActiveStencilFaceEXT(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000080{
81 PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func;
82 GLint face;
83 GLboolean pass;
84 (*activeFace)(GL_BACK);
85 glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face);
86 pass = (face == GL_BACK);
87 (*activeFace)(GL_FRONT); /* restore default */
88 return pass;
89}
90
91
Brian Paul9a2121c2003-06-10 14:54:37 +000092static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000093test_VertexAttrib1fvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +000094{
95 PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) func;
96 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
97
98 const GLfloat v[1] = {25.0};
99 const GLfloat def[1] = {0};
100 GLfloat res[4];
101 GLboolean pass;
102 (*vertexAttrib1fvARB)(6, v);
103 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
104 pass = (res[0] == 25.0 && res[1] == 0.0 && res[2] == 0.0 && res[3] == 1.0);
105 (*vertexAttrib1fvARB)(6, def);
106 return pass;
107}
108
109static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000110test_VertexAttrib4NubvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000111{
112 PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func;
113 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
114
115 const GLubyte v[4] = {255, 0, 255, 0};
116 const GLubyte def[4] = {0, 0, 0, 255};
117 GLfloat res[4];
118 GLboolean pass;
119 (*vertexAttrib4NubvARB)(6, v);
120 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
121 pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
122 (*vertexAttrib4NubvARB)(6, def);
123 return pass;
124}
125
126
127static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000128test_VertexAttrib4NuivARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000129{
130 PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) func;
131 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
132
133 const GLuint v[4] = {0xffffffff, 0, 0xffffffff, 0};
134 const GLuint def[4] = {0, 0, 0, 0xffffffff};
135 GLfloat res[4];
136 GLboolean pass;
137 (*vertexAttrib4NuivARB)(6, v);
138 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
139 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
140 (*vertexAttrib4NuivARB)(6, def);
141 return pass;
142}
143
144
145static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000146test_VertexAttrib4ivARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000147{
148 PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) func;
149 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
150
151 const GLint v[4] = {1, 2, -3, 4};
152 const GLint def[4] = {0, 0, 0, 1};
153 GLfloat res[4];
154 GLboolean pass;
155 (*vertexAttrib4ivARB)(6, v);
156 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
157 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 2.0) && EQUAL(res[2], -3.0) && EQUAL(res[3], 4.0));
158 (*vertexAttrib4ivARB)(6, def);
159 return pass;
160}
161
162
163static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000164test_VertexAttrib4NsvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000165{
166 PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) func;
167 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
168
169 const GLshort v[4] = {0, 32767, 32767, 0};
170 const GLshort def[4] = {0, 0, 0, 32767};
171 GLfloat res[4];
172 GLboolean pass;
173 (*vertexAttrib4NsvARB)(6, v);
174 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
175 pass = (EQUAL(res[0], 0.0) && EQUAL(res[1], 1.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
176 (*vertexAttrib4NsvARB)(6, def);
177 return pass;
178}
179
180
181static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000182test_VertexAttrib4NusvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000183{
184 PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) func;
185 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
186
187 const GLushort v[4] = {0xffff, 0, 0xffff, 0};
188 const GLushort def[4] = {0, 0, 0, 0xffff};
189 GLfloat res[4];
190 GLboolean pass;
191 (*vertexAttrib4NusvARB)(6, v);
192 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
193 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
194 (*vertexAttrib4NusvARB)(6, def);
195 return pass;
196}
197
198
199static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000200test_VertexAttrib4ubNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000201{
202 PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func;
203 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
204
205 const GLubyte v[4] = {255, 0, 255, 0};
206 const GLubyte def[4] = {0, 0, 0, 255};
207 GLfloat res[4];
208 GLboolean pass;
209 (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]);
210 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
211 pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
212 (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]);
213 return pass;
214}
215
216
217static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000218test_VertexAttrib2sNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000219{
220 PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func;
221 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
222
223 const GLshort v[2] = {2, -4,};
224 const GLshort def[2] = {0, 0};
225 GLfloat res[4];
226 GLboolean pass;
227 (*vertexAttrib2sNV)(6, v[0], v[1]);
228 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
229 pass = (EQUAL(res[0], 2) && EQUAL(res[1], -4) && EQUAL(res[2], 0) && res[3] == 1.0);
230 (*vertexAttrib2sNV)(6, def[0], def[1]);
231 return pass;
232}
233
234
235static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000236test_VertexAttrib3fNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000237{
238 PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func;
239 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
240
241 const GLfloat v[3] = {0.2, 0.4, 0.8};
242 const GLfloat def[3] = {0, 0, 0};
243 GLfloat res[4];
244 GLboolean pass;
245 (*vertexAttrib3fNV)(6, v[0], v[1], v[2]);
246 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
247 pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && res[3] == 1.0);
248 (*vertexAttrib3fNV)(6, def[0], def[1], def[2]);
249 return pass;
250}
251
252
253static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000254test_VertexAttrib4dvNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000255{
256 PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func;
257 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
258
259 const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2};
260 const GLdouble def[4] = {0, 0, 0, 1};
261 GLfloat res[4];
262 GLboolean pass;
263 (*vertexAttrib4dvNV)(6, v);
264 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
265 pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && EQUAL(res[3], 1.2));
266 (*vertexAttrib4dvNV)(6, def);
267 return pass;
268}
Brian Pauld1efbf02002-11-08 15:35:46 +0000269
270
Brian Paul036173e2006-11-02 15:47:30 +0000271static GLboolean
Brian8b8a9702007-10-30 10:23:58 -0600272test_StencilFuncSeparateATI(generic_func func)
273{
274#ifdef GL_ATI_separate_stencil
275 PFNGLSTENCILFUNCSEPARATEATIPROC stencilFuncSeparateATI = (PFNGLSTENCILFUNCSEPARATEATIPROC) func;
276 GLint frontFunc, backFunc;
277 GLint frontRef, backRef;
278 GLint frontMask, backMask;
279 (*stencilFuncSeparateATI)(GL_LESS, GL_GREATER, 2, 0xa);
280 glGetIntegerv(GL_STENCIL_FUNC, &frontFunc);
281 glGetIntegerv(GL_STENCIL_BACK_FUNC, &backFunc);
282 glGetIntegerv(GL_STENCIL_REF, &frontRef);
283 glGetIntegerv(GL_STENCIL_BACK_REF, &backRef);
284 glGetIntegerv(GL_STENCIL_VALUE_MASK, &frontMask);
285 glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &backMask);
286 if (frontFunc != GL_LESS ||
287 backFunc != GL_GREATER ||
288 frontRef != 2 ||
289 backRef != 2 ||
290 frontMask != 0xa ||
291 backMask != 0xa)
292 return GL_FALSE;
293#endif
294 return GL_TRUE;
295}
296
297static GLboolean
Brian Paul036173e2006-11-02 15:47:30 +0000298test_StencilFuncSeparate(generic_func func)
299{
300#ifdef GL_VERSION_2_0
301 PFNGLSTENCILFUNCSEPARATEPROC stencilFuncSeparate = (PFNGLSTENCILFUNCSEPARATEPROC) func;
302 GLint frontFunc, backFunc;
303 GLint frontRef, backRef;
304 GLint frontMask, backMask;
305 (*stencilFuncSeparate)(GL_BACK, GL_GREATER, 2, 0xa);
306 glGetIntegerv(GL_STENCIL_FUNC, &frontFunc);
307 glGetIntegerv(GL_STENCIL_BACK_FUNC, &backFunc);
308 glGetIntegerv(GL_STENCIL_REF, &frontRef);
309 glGetIntegerv(GL_STENCIL_BACK_REF, &backRef);
310 glGetIntegerv(GL_STENCIL_VALUE_MASK, &frontMask);
311 glGetIntegerv(GL_STENCIL_BACK_VALUE_MASK, &backMask);
312 if (frontFunc != GL_ALWAYS ||
313 backFunc != GL_GREATER ||
314 frontRef != 0 ||
315 backRef != 2 ||
316 frontMask == 0xa || /* might be 0xff or ~0 */
317 backMask != 0xa)
318 return GL_FALSE;
319#endif
320 return GL_TRUE;
321}
322
323static GLboolean
324test_StencilOpSeparate(generic_func func)
325{
326#ifdef GL_VERSION_2_0
327 PFNGLSTENCILOPSEPARATEPROC stencilOpSeparate = (PFNGLSTENCILOPSEPARATEPROC) func;
328 GLint frontFail, backFail;
329 GLint frontZFail, backZFail;
330 GLint frontZPass, backZPass;
331 (*stencilOpSeparate)(GL_BACK, GL_INCR, GL_DECR, GL_INVERT);
332 glGetIntegerv(GL_STENCIL_FAIL, &frontFail);
333 glGetIntegerv(GL_STENCIL_BACK_FAIL, &backFail);
334 glGetIntegerv(GL_STENCIL_PASS_DEPTH_FAIL, &frontZFail);
335 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_FAIL, &backZFail);
336 glGetIntegerv(GL_STENCIL_PASS_DEPTH_PASS, &frontZPass);
337 glGetIntegerv(GL_STENCIL_BACK_PASS_DEPTH_PASS, &backZPass);
338 if (frontFail != GL_KEEP ||
339 backFail != GL_INCR ||
340 frontZFail != GL_KEEP ||
341 backZFail != GL_DECR ||
342 frontZPass != GL_KEEP ||
343 backZPass != GL_INVERT)
344 return GL_FALSE;
345#endif
346 return GL_TRUE;
347}
348
349static GLboolean
350test_StencilMaskSeparate(generic_func func)
351{
352#ifdef GL_VERSION_2_0
353 PFNGLSTENCILMASKSEPARATEPROC stencilMaskSeparate = (PFNGLSTENCILMASKSEPARATEPROC) func;
354 GLint frontMask, backMask;
355 (*stencilMaskSeparate)(GL_BACK, 0x1b);
356 glGetIntegerv(GL_STENCIL_WRITEMASK, &frontMask);
357 glGetIntegerv(GL_STENCIL_BACK_WRITEMASK, &backMask);
358 if (frontMask == 0x1b ||
359 backMask != 0x1b)
360 return GL_FALSE;
361#endif
362 return GL_TRUE;
363}
364
365
Brian Pauld1efbf02002-11-08 15:35:46 +0000366/*
Brian Paul1ec9b5a2006-05-31 20:36:52 +0000367 * The following file is auto-generated with Python.
Brian Pauld1efbf02002-11-08 15:35:46 +0000368 */
369#include "getproclist.h"
370
Brian Paul17fe22d2001-11-18 23:16:56 +0000371
372
Brian Paul17fe22d2001-11-18 23:16:56 +0000373static int
374extension_supported(const char *haystack, const char *needle)
375{
Brian Paul1ec9b5a2006-05-31 20:36:52 +0000376 const char *p = strstr(haystack, needle);
377 if (p) {
378 /* found string, make sure next char is space or zero */
379 const int len = strlen(needle);
380 if (p[len] == ' ' || p[len] == 0)
381 return 1;
382 else
383 return 0;
384 }
Brian Paul17fe22d2001-11-18 23:16:56 +0000385 else
386 return 0;
387}
388
389
390static void
Brian Pauld1efbf02002-11-08 15:35:46 +0000391check_functions( const char *extensions )
Brian Paul17fe22d2001-11-18 23:16:56 +0000392{
Brian Pauld1efbf02002-11-08 15:35:46 +0000393 struct name_test_pair *entry;
Brian Paul17fe22d2001-11-18 23:16:56 +0000394 int failures = 0, passes = 0;
Brian Pauld1efbf02002-11-08 15:35:46 +0000395 int totalFail = 0, totalPass = 0;
Brian Paul17fe22d2001-11-18 23:16:56 +0000396 int doTests;
Brian Paul17fe22d2001-11-18 23:16:56 +0000397
Brian Pauld1efbf02002-11-08 15:35:46 +0000398 for (entry = functions; entry->name; entry++) {
399 if (entry->name[0] == '-') {
Brian Paul036173e2006-11-02 15:47:30 +0000400 const char *version = (const char *) glGetString(GL_VERSION);
Brian Pauld1efbf02002-11-08 15:35:46 +0000401 if (entry->name[1] == '1') {
Brian Paul036173e2006-11-02 15:47:30 +0000402 /* check GL version 1.x */
403 if (version[0] == '1' &&
404 version[1] == '.' &&
405 version[2] >= entry->name[3])
406 doTests = 1;
407 else
408 doTests = 0;
409 }
410 else if (entry->name[1] == '2') {
411 if (version[0] == '2' &&
412 version[1] == '.' &&
Brian Paul35695992003-07-10 14:39:57 +0000413 version[2] >= entry->name[3])
414 doTests = 1;
415 else
416 doTests = 0;
Brian Paul17fe22d2001-11-18 23:16:56 +0000417 }
418 else {
419 /* check if the named extension is available */
Brian Pauld1efbf02002-11-08 15:35:46 +0000420 doTests = extension_supported(extensions, entry->name+1);
Brian Paul17fe22d2001-11-18 23:16:56 +0000421 }
422 if (doTests)
Brian Pauld1efbf02002-11-08 15:35:46 +0000423 printf("Testing %s functions\n", entry->name + 1);
424 totalFail += failures;
425 totalPass += passes;
Brian Paul17fe22d2001-11-18 23:16:56 +0000426 failures = 0;
427 passes = 0;
428 }
429 else if (doTests) {
Brian Paul0699b0b2004-11-27 19:57:46 +0000430 generic_func funcPtr = (generic_func) glXGetProcAddressARB((const GLubyte *) entry->name);
Brian Pauld1efbf02002-11-08 15:35:46 +0000431 if (funcPtr) {
432 if (entry->test) {
433 GLboolean b;
434 printf(" Validating %s:", entry->name);
435 b = (*entry->test)(funcPtr);
436 if (b) {
437 printf(" Pass\n");
438 passes++;
439 }
440 else {
441 printf(" FAIL!!!\n");
442 failures++;
443 }
444 }
445 else {
446 passes++;
447 }
Brian Paul17fe22d2001-11-18 23:16:56 +0000448 }
449 else {
Brian Pauld1efbf02002-11-08 15:35:46 +0000450 printf(" glXGetProcAddress(%s) failed!\n", entry->name);
Brian Paul17fe22d2001-11-18 23:16:56 +0000451 failures++;
452 }
453 }
454
Brian Pauld1efbf02002-11-08 15:35:46 +0000455 if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000456 if (failures > 0) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000457 printf(" %d failed.\n", failures);
Brian Paul17fe22d2001-11-18 23:16:56 +0000458 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000459 if (passes > 0) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000460 printf(" %d passed.\n", passes);
461 }
462 }
463 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000464 totalFail += failures;
465 totalPass += passes;
466
467 printf("-----------------------------\n");
468 printf("Total: %d pass %d fail\n", totalPass, totalFail);
Brian Paul17fe22d2001-11-18 23:16:56 +0000469}
470
471
472
473static void
474print_screen_info(Display *dpy, int scrnum, Bool allowDirect)
475{
476 Window win;
477 int attribSingle[] = {
478 GLX_RGBA,
479 GLX_RED_SIZE, 1,
480 GLX_GREEN_SIZE, 1,
481 GLX_BLUE_SIZE, 1,
Brian Paul036173e2006-11-02 15:47:30 +0000482 GLX_STENCIL_SIZE, 1,
Brian Paul17fe22d2001-11-18 23:16:56 +0000483 None };
484 int attribDouble[] = {
485 GLX_RGBA,
486 GLX_RED_SIZE, 1,
487 GLX_GREEN_SIZE, 1,
488 GLX_BLUE_SIZE, 1,
Brian Paul036173e2006-11-02 15:47:30 +0000489 GLX_STENCIL_SIZE, 1,
Brian Paul17fe22d2001-11-18 23:16:56 +0000490 GLX_DOUBLEBUFFER,
491 None };
492
493 XSetWindowAttributes attr;
494 unsigned long mask;
495 Window root;
496 GLXContext ctx;
497 XVisualInfo *visinfo;
498 int width = 100, height = 100;
499
500 root = RootWindow(dpy, scrnum);
501
502 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
503 if (!visinfo) {
504 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
505 if (!visinfo) {
506 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
507 return;
508 }
509 }
510
511 attr.background_pixel = 0;
512 attr.border_pixel = 0;
513 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
514 attr.event_mask = StructureNotifyMask | ExposureMask;
515 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
516 win = XCreateWindow(dpy, root, 0, 0, width, height,
517 0, visinfo->depth, InputOutput,
518 visinfo->visual, mask, &attr);
519
520 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
521 if (!ctx) {
522 fprintf(stderr, "Error: glXCreateContext failed\n");
523 XDestroyWindow(dpy, win);
524 return;
525 }
526
527 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000528 check_functions( (const char *) glGetString(GL_EXTENSIONS) );
Brian Paul17fe22d2001-11-18 23:16:56 +0000529 }
530 else {
531 fprintf(stderr, "Error: glXMakeCurrent failed\n");
532 }
533
534 glXDestroyContext(dpy, ctx);
535 XDestroyWindow(dpy, win);
536}
537
538
539int
540main(int argc, char *argv[])
541{
542 char *displayName = NULL;
543 Display *dpy;
544
545 dpy = XOpenDisplay(displayName);
546 if (!dpy) {
547 fprintf(stderr, "Error: unable to open display %s\n", displayName);
548 return -1;
549 }
550
551 print_screen_info(dpy, 0, GL_TRUE);
552
553 XCloseDisplay(dpy);
554
555 return 0;
556}