blob: 2480ed44cc7d4677a0581e9cba5d6ba19442c573 [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 Pauld1efbf02002-11-08 15:35:46 +000042static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000043test_ActiveTextureARB(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000044{
45 PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func;
46 GLint t;
47 GLboolean pass;
48 (*activeTexture)(GL_TEXTURE1_ARB);
49 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &t);
50 pass = (t == GL_TEXTURE1_ARB);
51 (*activeTexture)(GL_TEXTURE0_ARB); /* restore default */
52 return pass;
53}
Brian Paul17fe22d2001-11-18 23:16:56 +000054
Brian Pauld1efbf02002-11-08 15:35:46 +000055
56static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000057test_SecondaryColor3fEXT(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000058{
59 PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func;
60 GLfloat color[4];
61 GLboolean pass;
62 (*secColor3f)(1.0, 1.0, 0.0);
63 glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT, color);
64 pass = (color[0] == 1.0 && color[1] == 1.0 && color[2] == 0.0);
65 (*secColor3f)(0.0, 0.0, 0.0); /* restore default */
66 return pass;
67}
68
69
70static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000071test_ActiveStencilFaceEXT(generic_func func)
Brian Pauld1efbf02002-11-08 15:35:46 +000072{
73 PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func;
74 GLint face;
75 GLboolean pass;
76 (*activeFace)(GL_BACK);
77 glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face);
78 pass = (face == GL_BACK);
79 (*activeFace)(GL_FRONT); /* restore default */
80 return pass;
81}
82
83
Brian Paul9a2121c2003-06-10 14:54:37 +000084static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +000085test_VertexAttrib1fvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +000086{
87 PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) func;
88 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
89
90 const GLfloat v[1] = {25.0};
91 const GLfloat def[1] = {0};
92 GLfloat res[4];
93 GLboolean pass;
94 (*vertexAttrib1fvARB)(6, v);
95 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
96 pass = (res[0] == 25.0 && res[1] == 0.0 && res[2] == 0.0 && res[3] == 1.0);
97 (*vertexAttrib1fvARB)(6, def);
98 return pass;
99}
100
101static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000102test_VertexAttrib4NubvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000103{
104 PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func;
105 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
106
107 const GLubyte v[4] = {255, 0, 255, 0};
108 const GLubyte def[4] = {0, 0, 0, 255};
109 GLfloat res[4];
110 GLboolean pass;
111 (*vertexAttrib4NubvARB)(6, v);
112 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
113 pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
114 (*vertexAttrib4NubvARB)(6, def);
115 return pass;
116}
117
118
119static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000120test_VertexAttrib4NuivARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000121{
122 PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) func;
123 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
124
125 const GLuint v[4] = {0xffffffff, 0, 0xffffffff, 0};
126 const GLuint def[4] = {0, 0, 0, 0xffffffff};
127 GLfloat res[4];
128 GLboolean pass;
129 (*vertexAttrib4NuivARB)(6, v);
130 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
131 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
132 (*vertexAttrib4NuivARB)(6, def);
133 return pass;
134}
135
136
137static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000138test_VertexAttrib4ivARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000139{
140 PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) func;
141 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
142
143 const GLint v[4] = {1, 2, -3, 4};
144 const GLint def[4] = {0, 0, 0, 1};
145 GLfloat res[4];
146 GLboolean pass;
147 (*vertexAttrib4ivARB)(6, v);
148 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
149 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 2.0) && EQUAL(res[2], -3.0) && EQUAL(res[3], 4.0));
150 (*vertexAttrib4ivARB)(6, def);
151 return pass;
152}
153
154
155static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000156test_VertexAttrib4NsvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000157{
158 PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) func;
159 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
160
161 const GLshort v[4] = {0, 32767, 32767, 0};
162 const GLshort def[4] = {0, 0, 0, 32767};
163 GLfloat res[4];
164 GLboolean pass;
165 (*vertexAttrib4NsvARB)(6, v);
166 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
167 pass = (EQUAL(res[0], 0.0) && EQUAL(res[1], 1.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
168 (*vertexAttrib4NsvARB)(6, def);
169 return pass;
170}
171
172
173static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000174test_VertexAttrib4NusvARB(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000175{
176 PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) func;
177 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
178
179 const GLushort v[4] = {0xffff, 0, 0xffff, 0};
180 const GLushort def[4] = {0, 0, 0, 0xffff};
181 GLfloat res[4];
182 GLboolean pass;
183 (*vertexAttrib4NusvARB)(6, v);
184 (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
185 pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
186 (*vertexAttrib4NusvARB)(6, def);
187 return pass;
188}
189
190
191static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000192test_VertexAttrib4ubNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000193{
194 PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func;
195 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
196
197 const GLubyte v[4] = {255, 0, 255, 0};
198 const GLubyte def[4] = {0, 0, 0, 255};
199 GLfloat res[4];
200 GLboolean pass;
201 (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]);
202 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
203 pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
204 (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]);
205 return pass;
206}
207
208
209static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000210test_VertexAttrib2sNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000211{
212 PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func;
213 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
214
215 const GLshort v[2] = {2, -4,};
216 const GLshort def[2] = {0, 0};
217 GLfloat res[4];
218 GLboolean pass;
219 (*vertexAttrib2sNV)(6, v[0], v[1]);
220 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
221 pass = (EQUAL(res[0], 2) && EQUAL(res[1], -4) && EQUAL(res[2], 0) && res[3] == 1.0);
222 (*vertexAttrib2sNV)(6, def[0], def[1]);
223 return pass;
224}
225
226
227static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000228test_VertexAttrib3fNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000229{
230 PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func;
231 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
232
233 const GLfloat v[3] = {0.2, 0.4, 0.8};
234 const GLfloat def[3] = {0, 0, 0};
235 GLfloat res[4];
236 GLboolean pass;
237 (*vertexAttrib3fNV)(6, v[0], v[1], v[2]);
238 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
239 pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && res[3] == 1.0);
240 (*vertexAttrib3fNV)(6, def[0], def[1], def[2]);
241 return pass;
242}
243
244
245static GLboolean
Brian Paul0699b0b2004-11-27 19:57:46 +0000246test_VertexAttrib4dvNV(generic_func func)
Brian Paul9a2121c2003-06-10 14:54:37 +0000247{
248 PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func;
249 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
250
251 const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2};
252 const GLdouble def[4] = {0, 0, 0, 1};
253 GLfloat res[4];
254 GLboolean pass;
255 (*vertexAttrib4dvNV)(6, v);
256 (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
257 pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && EQUAL(res[3], 1.2));
258 (*vertexAttrib4dvNV)(6, def);
259 return pass;
260}
Brian Pauld1efbf02002-11-08 15:35:46 +0000261
262
263/*
264 * The following header file is auto-generated with Python. The Python
265 * script looks in this file for functions named "test_*" as seen above.
266 */
267#include "getproclist.h"
268
Brian Paul17fe22d2001-11-18 23:16:56 +0000269
270
Brian Paul17fe22d2001-11-18 23:16:56 +0000271static int
272extension_supported(const char *haystack, const char *needle)
273{
274 if (strstr(haystack, needle))
275 return 1;
276 else
277 return 0;
278}
279
280
281static void
Brian Pauld1efbf02002-11-08 15:35:46 +0000282check_functions( const char *extensions )
Brian Paul17fe22d2001-11-18 23:16:56 +0000283{
Brian Pauld1efbf02002-11-08 15:35:46 +0000284 struct name_test_pair *entry;
Brian Paul17fe22d2001-11-18 23:16:56 +0000285 int failures = 0, passes = 0;
Brian Pauld1efbf02002-11-08 15:35:46 +0000286 int totalFail = 0, totalPass = 0;
Brian Paul17fe22d2001-11-18 23:16:56 +0000287 int doTests;
Brian Paul17fe22d2001-11-18 23:16:56 +0000288
Brian Pauld1efbf02002-11-08 15:35:46 +0000289 for (entry = functions; entry->name; entry++) {
290 if (entry->name[0] == '-') {
Brian Paule4b23562005-05-04 20:11:35 +0000291 /* XXX update for OpenGL 2.0 */
Brian Pauld1efbf02002-11-08 15:35:46 +0000292 if (entry->name[1] == '1') {
Brian Paul35695992003-07-10 14:39:57 +0000293 /* check GL version X.Y */
294 const char *version = (const char *) glGetString(GL_VERSION);
295 if (version[0] == entry->name[1] &&
296 version[1] == entry->name[2] &&
297 version[2] >= entry->name[3])
298 doTests = 1;
299 else
300 doTests = 0;
Brian Paul17fe22d2001-11-18 23:16:56 +0000301 }
302 else {
303 /* check if the named extension is available */
Brian Pauld1efbf02002-11-08 15:35:46 +0000304 doTests = extension_supported(extensions, entry->name+1);
Brian Paul17fe22d2001-11-18 23:16:56 +0000305 }
306 if (doTests)
Brian Pauld1efbf02002-11-08 15:35:46 +0000307 printf("Testing %s functions\n", entry->name + 1);
308 totalFail += failures;
309 totalPass += passes;
Brian Paul17fe22d2001-11-18 23:16:56 +0000310 failures = 0;
311 passes = 0;
312 }
313 else if (doTests) {
Brian Paul0699b0b2004-11-27 19:57:46 +0000314 generic_func funcPtr = (generic_func) glXGetProcAddressARB((const GLubyte *) entry->name);
Brian Pauld1efbf02002-11-08 15:35:46 +0000315 if (funcPtr) {
316 if (entry->test) {
317 GLboolean b;
318 printf(" Validating %s:", entry->name);
319 b = (*entry->test)(funcPtr);
320 if (b) {
321 printf(" Pass\n");
322 passes++;
323 }
324 else {
325 printf(" FAIL!!!\n");
326 failures++;
327 }
328 }
329 else {
330 passes++;
331 }
Brian Paul17fe22d2001-11-18 23:16:56 +0000332 }
333 else {
Brian Pauld1efbf02002-11-08 15:35:46 +0000334 printf(" glXGetProcAddress(%s) failed!\n", entry->name);
Brian Paul17fe22d2001-11-18 23:16:56 +0000335 failures++;
336 }
337 }
338
Brian Pauld1efbf02002-11-08 15:35:46 +0000339 if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000340 if (failures > 0) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000341 printf(" %d failed.\n", failures);
Brian Paul17fe22d2001-11-18 23:16:56 +0000342 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000343 if (passes > 0) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000344 printf(" %d passed.\n", passes);
345 }
346 }
347 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000348 totalFail += failures;
349 totalPass += passes;
350
351 printf("-----------------------------\n");
352 printf("Total: %d pass %d fail\n", totalPass, totalFail);
Brian Paul17fe22d2001-11-18 23:16:56 +0000353}
354
355
356
357static void
358print_screen_info(Display *dpy, int scrnum, Bool allowDirect)
359{
360 Window win;
361 int attribSingle[] = {
362 GLX_RGBA,
363 GLX_RED_SIZE, 1,
364 GLX_GREEN_SIZE, 1,
365 GLX_BLUE_SIZE, 1,
366 None };
367 int attribDouble[] = {
368 GLX_RGBA,
369 GLX_RED_SIZE, 1,
370 GLX_GREEN_SIZE, 1,
371 GLX_BLUE_SIZE, 1,
372 GLX_DOUBLEBUFFER,
373 None };
374
375 XSetWindowAttributes attr;
376 unsigned long mask;
377 Window root;
378 GLXContext ctx;
379 XVisualInfo *visinfo;
380 int width = 100, height = 100;
381
382 root = RootWindow(dpy, scrnum);
383
384 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
385 if (!visinfo) {
386 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
387 if (!visinfo) {
388 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
389 return;
390 }
391 }
392
393 attr.background_pixel = 0;
394 attr.border_pixel = 0;
395 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
396 attr.event_mask = StructureNotifyMask | ExposureMask;
397 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
398 win = XCreateWindow(dpy, root, 0, 0, width, height,
399 0, visinfo->depth, InputOutput,
400 visinfo->visual, mask, &attr);
401
402 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
403 if (!ctx) {
404 fprintf(stderr, "Error: glXCreateContext failed\n");
405 XDestroyWindow(dpy, win);
406 return;
407 }
408
409 if (glXMakeCurrent(dpy, win, ctx)) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000410 check_functions( (const char *) glGetString(GL_EXTENSIONS) );
Brian Paul17fe22d2001-11-18 23:16:56 +0000411 }
412 else {
413 fprintf(stderr, "Error: glXMakeCurrent failed\n");
414 }
415
416 glXDestroyContext(dpy, ctx);
417 XDestroyWindow(dpy, win);
418}
419
420
421int
422main(int argc, char *argv[])
423{
424 char *displayName = NULL;
425 Display *dpy;
426
427 dpy = XOpenDisplay(displayName);
428 if (!dpy) {
429 fprintf(stderr, "Error: unable to open display %s\n", displayName);
430 return -1;
431 }
432
433 print_screen_info(dpy, 0, GL_TRUE);
434
435 XCloseDisplay(dpy);
436
437 return 0;
438}