2 * Copyright (C) 1999-2002 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.
23 * Test that glXGetProcAddress works.
26 #define GLX_GLXEXT_PROTOTYPES
29 #include <X11/Xutil.h>
38 #define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001)
41 test_ActiveTextureARB(void *func
)
43 PFNGLACTIVETEXTUREARBPROC activeTexture
= (PFNGLACTIVETEXTUREARBPROC
) func
;
46 (*activeTexture
)(GL_TEXTURE1_ARB
);
47 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB
, &t
);
48 pass
= (t
== GL_TEXTURE1_ARB
);
49 (*activeTexture
)(GL_TEXTURE0_ARB
); /* restore default */
55 test_SecondaryColor3fEXT(void *func
)
57 PFNGLSECONDARYCOLOR3FEXTPROC secColor3f
= (PFNGLSECONDARYCOLOR3FEXTPROC
) func
;
60 (*secColor3f
)(1.0, 1.0, 0.0);
61 glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT
, color
);
62 pass
= (color
[0] == 1.0 && color
[1] == 1.0 && color
[2] == 0.0);
63 (*secColor3f
)(0.0, 0.0, 0.0); /* restore default */
69 test_ActiveStencilFaceEXT(void *func
)
71 PFNGLACTIVESTENCILFACEEXTPROC activeFace
= (PFNGLACTIVESTENCILFACEEXTPROC
) func
;
74 (*activeFace
)(GL_BACK
);
75 glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT
, &face
);
76 pass
= (face
== GL_BACK
);
77 (*activeFace
)(GL_FRONT
); /* restore default */
83 test_VertexAttrib1fvARB(void *func
)
85 PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB
= (PFNGLVERTEXATTRIB1FVARBPROC
) func
;
86 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
88 const GLfloat v
[1] = {25.0};
89 const GLfloat def
[1] = {0};
92 (*vertexAttrib1fvARB
)(6, v
);
93 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
94 pass
= (res
[0] == 25.0 && res
[1] == 0.0 && res
[2] == 0.0 && res
[3] == 1.0);
95 (*vertexAttrib1fvARB
)(6, def
);
100 test_VertexAttrib4NubvARB(void *func
)
102 PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB
= (PFNGLVERTEXATTRIB4NUBVARBPROC
) func
;
103 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
105 const GLubyte v
[4] = {255, 0, 255, 0};
106 const GLubyte def
[4] = {0, 0, 0, 255};
109 (*vertexAttrib4NubvARB
)(6, v
);
110 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
111 pass
= (res
[0] == 1.0 && res
[1] == 0.0 && res
[2] == 1.0 && res
[3] == 0.0);
112 (*vertexAttrib4NubvARB
)(6, def
);
118 test_VertexAttrib4NuivARB(void *func
)
120 PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB
= (PFNGLVERTEXATTRIB4NUIVARBPROC
) func
;
121 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
123 const GLuint v
[4] = {0xffffffff, 0, 0xffffffff, 0};
124 const GLuint def
[4] = {0, 0, 0, 0xffffffff};
127 (*vertexAttrib4NuivARB
)(6, v
);
128 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
129 pass
= (EQUAL(res
[0], 1.0) && EQUAL(res
[1], 0.0) && EQUAL(res
[2], 1.0) && EQUAL(res
[3], 0.0));
130 (*vertexAttrib4NuivARB
)(6, def
);
136 test_VertexAttrib4ivARB(void *func
)
138 PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB
= (PFNGLVERTEXATTRIB4IVARBPROC
) func
;
139 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
141 const GLint v
[4] = {1, 2, -3, 4};
142 const GLint def
[4] = {0, 0, 0, 1};
145 (*vertexAttrib4ivARB
)(6, v
);
146 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
147 pass
= (EQUAL(res
[0], 1.0) && EQUAL(res
[1], 2.0) && EQUAL(res
[2], -3.0) && EQUAL(res
[3], 4.0));
148 (*vertexAttrib4ivARB
)(6, def
);
154 test_VertexAttrib4NsvARB(void *func
)
156 PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB
= (PFNGLVERTEXATTRIB4NSVARBPROC
) func
;
157 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
159 const GLshort v
[4] = {0, 32767, 32767, 0};
160 const GLshort def
[4] = {0, 0, 0, 32767};
163 (*vertexAttrib4NsvARB
)(6, v
);
164 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
165 pass
= (EQUAL(res
[0], 0.0) && EQUAL(res
[1], 1.0) && EQUAL(res
[2], 1.0) && EQUAL(res
[3], 0.0));
166 (*vertexAttrib4NsvARB
)(6, def
);
172 test_VertexAttrib4NusvARB(void *func
)
174 PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB
= (PFNGLVERTEXATTRIB4NUSVARBPROC
) func
;
175 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB
= (PFNGLGETVERTEXATTRIBFVARBPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvARB");
177 const GLushort v
[4] = {0xffff, 0, 0xffff, 0};
178 const GLushort def
[4] = {0, 0, 0, 0xffff};
181 (*vertexAttrib4NusvARB
)(6, v
);
182 (*getVertexAttribfvARB
)(6, GL_CURRENT_VERTEX_ATTRIB_ARB
, res
);
183 pass
= (EQUAL(res
[0], 1.0) && EQUAL(res
[1], 0.0) && EQUAL(res
[2], 1.0) && EQUAL(res
[3], 0.0));
184 (*vertexAttrib4NusvARB
)(6, def
);
190 test_VertexAttrib4ubNV(void *func
)
192 PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV
= (PFNGLVERTEXATTRIB4UBNVPROC
) func
;
193 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV
= (PFNGLGETVERTEXATTRIBFVNVPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvNV");
195 const GLubyte v
[4] = {255, 0, 255, 0};
196 const GLubyte def
[4] = {0, 0, 0, 255};
199 (*vertexAttrib4ubNV
)(6, v
[0], v
[1], v
[2], v
[3]);
200 (*getVertexAttribfvNV
)(6, GL_CURRENT_ATTRIB_NV
, res
);
201 pass
= (res
[0] == 1.0 && res
[1] == 0.0 && res
[2] == 1.0 && res
[3] == 0.0);
202 (*vertexAttrib4ubNV
)(6, def
[0], def
[1], def
[2], def
[3]);
208 test_VertexAttrib2sNV(void *func
)
210 PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV
= (PFNGLVERTEXATTRIB2SNVPROC
) func
;
211 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV
= (PFNGLGETVERTEXATTRIBFVNVPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvNV");
213 const GLshort v
[2] = {2, -4,};
214 const GLshort def
[2] = {0, 0};
217 (*vertexAttrib2sNV
)(6, v
[0], v
[1]);
218 (*getVertexAttribfvNV
)(6, GL_CURRENT_ATTRIB_NV
, res
);
219 pass
= (EQUAL(res
[0], 2) && EQUAL(res
[1], -4) && EQUAL(res
[2], 0) && res
[3] == 1.0);
220 (*vertexAttrib2sNV
)(6, def
[0], def
[1]);
226 test_VertexAttrib3fNV(void *func
)
228 PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV
= (PFNGLVERTEXATTRIB3FNVPROC
) func
;
229 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV
= (PFNGLGETVERTEXATTRIBFVNVPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvNV");
231 const GLfloat v
[3] = {0.2, 0.4, 0.8};
232 const GLfloat def
[3] = {0, 0, 0};
235 (*vertexAttrib3fNV
)(6, v
[0], v
[1], v
[2]);
236 (*getVertexAttribfvNV
)(6, GL_CURRENT_ATTRIB_NV
, res
);
237 pass
= (EQUAL(res
[0], 0.2) && EQUAL(res
[1], 0.4) && EQUAL(res
[2], 0.8) && res
[3] == 1.0);
238 (*vertexAttrib3fNV
)(6, def
[0], def
[1], def
[2]);
244 test_VertexAttrib4dvNV(void *func
)
246 PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV
= (PFNGLVERTEXATTRIB4DVNVPROC
) func
;
247 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV
= (PFNGLGETVERTEXATTRIBFVNVPROC
) glXGetProcAddressARB((const GLubyte
*) "glGetVertexAttribfvNV");
249 const GLdouble v
[4] = {0.2, 0.4, 0.8, 1.2};
250 const GLdouble def
[4] = {0, 0, 0, 1};
253 (*vertexAttrib4dvNV
)(6, v
);
254 (*getVertexAttribfvNV
)(6, GL_CURRENT_ATTRIB_NV
, res
);
255 pass
= (EQUAL(res
[0], 0.2) && EQUAL(res
[1], 0.4) && EQUAL(res
[2], 0.8) && EQUAL(res
[3], 1.2));
256 (*vertexAttrib4dvNV
)(6, def
);
262 * The following header file is auto-generated with Python. The Python
263 * script looks in this file for functions named "test_*" as seen above.
265 #include "getproclist.h"
270 extension_supported(const char *haystack
, const char *needle
)
272 if (strstr(haystack
, needle
))
280 check_functions( const char *extensions
)
282 struct name_test_pair
*entry
;
283 int failures
= 0, passes
= 0;
284 int totalFail
= 0, totalPass
= 0;
287 for (entry
= functions
; entry
->name
; entry
++) {
288 if (entry
->name
[0] == '-') {
289 if (entry
->name
[1] == '1') {
290 /* check GL version X.Y */
291 const char *version
= (const char *) glGetString(GL_VERSION
);
292 if (version
[0] == entry
->name
[1] &&
293 version
[1] == entry
->name
[2] &&
294 version
[2] >= entry
->name
[3])
300 /* check if the named extension is available */
301 doTests
= extension_supported(extensions
, entry
->name
+1);
304 printf("Testing %s functions\n", entry
->name
+ 1);
305 totalFail
+= failures
;
311 void *funcPtr
= (void *) glXGetProcAddressARB((const GLubyte
*) entry
->name
);
315 printf(" Validating %s:", entry
->name
);
316 b
= (*entry
->test
)(funcPtr
);
322 printf(" FAIL!!!\n");
331 printf(" glXGetProcAddress(%s) failed!\n", entry
->name
);
336 if (doTests
&& (!(entry
+1)->name
|| (entry
+1)->name
[0] == '-')) {
338 printf(" %d failed.\n", failures
);
341 printf(" %d passed.\n", passes
);
345 totalFail
+= failures
;
348 printf("-----------------------------\n");
349 printf("Total: %d pass %d fail\n", totalPass
, totalFail
);
355 print_screen_info(Display
*dpy
, int scrnum
, Bool allowDirect
)
358 int attribSingle
[] = {
364 int attribDouble
[] = {
372 XSetWindowAttributes attr
;
376 XVisualInfo
*visinfo
;
377 int width
= 100, height
= 100;
379 root
= RootWindow(dpy
, scrnum
);
381 visinfo
= glXChooseVisual(dpy
, scrnum
, attribSingle
);
383 visinfo
= glXChooseVisual(dpy
, scrnum
, attribDouble
);
385 fprintf(stderr
, "Error: couldn't find RGB GLX visual\n");
390 attr
.background_pixel
= 0;
391 attr
.border_pixel
= 0;
392 attr
.colormap
= XCreateColormap(dpy
, root
, visinfo
->visual
, AllocNone
);
393 attr
.event_mask
= StructureNotifyMask
| ExposureMask
;
394 mask
= CWBackPixel
| CWBorderPixel
| CWColormap
| CWEventMask
;
395 win
= XCreateWindow(dpy
, root
, 0, 0, width
, height
,
396 0, visinfo
->depth
, InputOutput
,
397 visinfo
->visual
, mask
, &attr
);
399 ctx
= glXCreateContext( dpy
, visinfo
, NULL
, allowDirect
);
401 fprintf(stderr
, "Error: glXCreateContext failed\n");
402 XDestroyWindow(dpy
, win
);
406 if (glXMakeCurrent(dpy
, win
, ctx
)) {
407 check_functions( (const char *) glGetString(GL_EXTENSIONS
) );
410 fprintf(stderr
, "Error: glXMakeCurrent failed\n");
413 glXDestroyContext(dpy
, ctx
);
414 XDestroyWindow(dpy
, win
);
419 main(int argc
, char *argv
[])
421 char *displayName
= NULL
;
424 dpy
= XOpenDisplay(displayName
);
426 fprintf(stderr
, "Error: unable to open display %s\n", displayName
);
430 print_screen_info(dpy
, 0, GL_TRUE
);