GL_EXT_pixel_buffer_object test
[mesa.git] / progs / tests / getprocaddress.c
1 /*
2 * Copyright (C) 1999-2002 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 * Test that glXGetProcAddress works.
24 */
25
26 #define GLX_GLXEXT_PROTOTYPES
27
28 #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>
35 #include <math.h>
36
37
38 #define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001)
39
40 static GLboolean
41 test_ActiveTextureARB(void *func)
42 {
43 PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func;
44 GLint t;
45 GLboolean pass;
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 */
50 return pass;
51 }
52
53
54 static GLboolean
55 test_SecondaryColor3fEXT(void *func)
56 {
57 PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func;
58 GLfloat color[4];
59 GLboolean pass;
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 */
64 return pass;
65 }
66
67
68 static GLboolean
69 test_ActiveStencilFaceEXT(void *func)
70 {
71 PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func;
72 GLint face;
73 GLboolean pass;
74 (*activeFace)(GL_BACK);
75 glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face);
76 pass = (face == GL_BACK);
77 (*activeFace)(GL_FRONT); /* restore default */
78 return pass;
79 }
80
81
82 static GLboolean
83 test_VertexAttrib1fvARB(void *func)
84 {
85 PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) func;
86 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
87
88 const GLfloat v[1] = {25.0};
89 const GLfloat def[1] = {0};
90 GLfloat res[4];
91 GLboolean pass;
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);
96 return pass;
97 }
98
99 static GLboolean
100 test_VertexAttrib4NubvARB(void *func)
101 {
102 PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func;
103 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
104
105 const GLubyte v[4] = {255, 0, 255, 0};
106 const GLubyte def[4] = {0, 0, 0, 255};
107 GLfloat res[4];
108 GLboolean pass;
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);
113 return pass;
114 }
115
116
117 static GLboolean
118 test_VertexAttrib4NuivARB(void *func)
119 {
120 PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) func;
121 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
122
123 const GLuint v[4] = {0xffffffff, 0, 0xffffffff, 0};
124 const GLuint def[4] = {0, 0, 0, 0xffffffff};
125 GLfloat res[4];
126 GLboolean pass;
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);
131 return pass;
132 }
133
134
135 static GLboolean
136 test_VertexAttrib4ivARB(void *func)
137 {
138 PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) func;
139 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
140
141 const GLint v[4] = {1, 2, -3, 4};
142 const GLint def[4] = {0, 0, 0, 1};
143 GLfloat res[4];
144 GLboolean pass;
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);
149 return pass;
150 }
151
152
153 static GLboolean
154 test_VertexAttrib4NsvARB(void *func)
155 {
156 PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) func;
157 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
158
159 const GLshort v[4] = {0, 32767, 32767, 0};
160 const GLshort def[4] = {0, 0, 0, 32767};
161 GLfloat res[4];
162 GLboolean pass;
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);
167 return pass;
168 }
169
170
171 static GLboolean
172 test_VertexAttrib4NusvARB(void *func)
173 {
174 PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) func;
175 PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
176
177 const GLushort v[4] = {0xffff, 0, 0xffff, 0};
178 const GLushort def[4] = {0, 0, 0, 0xffff};
179 GLfloat res[4];
180 GLboolean pass;
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);
185 return pass;
186 }
187
188
189 static GLboolean
190 test_VertexAttrib4ubNV(void *func)
191 {
192 PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func;
193 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
194
195 const GLubyte v[4] = {255, 0, 255, 0};
196 const GLubyte def[4] = {0, 0, 0, 255};
197 GLfloat res[4];
198 GLboolean pass;
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]);
203 return pass;
204 }
205
206
207 static GLboolean
208 test_VertexAttrib2sNV(void *func)
209 {
210 PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func;
211 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
212
213 const GLshort v[2] = {2, -4,};
214 const GLshort def[2] = {0, 0};
215 GLfloat res[4];
216 GLboolean pass;
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]);
221 return pass;
222 }
223
224
225 static GLboolean
226 test_VertexAttrib3fNV(void *func)
227 {
228 PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func;
229 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
230
231 const GLfloat v[3] = {0.2, 0.4, 0.8};
232 const GLfloat def[3] = {0, 0, 0};
233 GLfloat res[4];
234 GLboolean pass;
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]);
239 return pass;
240 }
241
242
243 static GLboolean
244 test_VertexAttrib4dvNV(void *func)
245 {
246 PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func;
247 PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
248
249 const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2};
250 const GLdouble def[4] = {0, 0, 0, 1};
251 GLfloat res[4];
252 GLboolean pass;
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);
257 return pass;
258 }
259
260
261 /*
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.
264 */
265 #include "getproclist.h"
266
267
268
269 static int
270 extension_supported(const char *haystack, const char *needle)
271 {
272 if (strstr(haystack, needle))
273 return 1;
274 else
275 return 0;
276 }
277
278
279 static void
280 check_functions( const char *extensions )
281 {
282 struct name_test_pair *entry;
283 int failures = 0, passes = 0;
284 int totalFail = 0, totalPass = 0;
285 int doTests;
286
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])
295 doTests = 1;
296 else
297 doTests = 0;
298 }
299 else {
300 /* check if the named extension is available */
301 doTests = extension_supported(extensions, entry->name+1);
302 }
303 if (doTests)
304 printf("Testing %s functions\n", entry->name + 1);
305 totalFail += failures;
306 totalPass += passes;
307 failures = 0;
308 passes = 0;
309 }
310 else if (doTests) {
311 void *funcPtr = (void *) glXGetProcAddressARB((const GLubyte *) entry->name);
312 if (funcPtr) {
313 if (entry->test) {
314 GLboolean b;
315 printf(" Validating %s:", entry->name);
316 b = (*entry->test)(funcPtr);
317 if (b) {
318 printf(" Pass\n");
319 passes++;
320 }
321 else {
322 printf(" FAIL!!!\n");
323 failures++;
324 }
325 }
326 else {
327 passes++;
328 }
329 }
330 else {
331 printf(" glXGetProcAddress(%s) failed!\n", entry->name);
332 failures++;
333 }
334 }
335
336 if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
337 if (failures > 0) {
338 printf(" %d failed.\n", failures);
339 }
340 if (passes > 0) {
341 printf(" %d passed.\n", passes);
342 }
343 }
344 }
345 totalFail += failures;
346 totalPass += passes;
347
348 printf("-----------------------------\n");
349 printf("Total: %d pass %d fail\n", totalPass, totalFail);
350 }
351
352
353
354 static void
355 print_screen_info(Display *dpy, int scrnum, Bool allowDirect)
356 {
357 Window win;
358 int attribSingle[] = {
359 GLX_RGBA,
360 GLX_RED_SIZE, 1,
361 GLX_GREEN_SIZE, 1,
362 GLX_BLUE_SIZE, 1,
363 None };
364 int attribDouble[] = {
365 GLX_RGBA,
366 GLX_RED_SIZE, 1,
367 GLX_GREEN_SIZE, 1,
368 GLX_BLUE_SIZE, 1,
369 GLX_DOUBLEBUFFER,
370 None };
371
372 XSetWindowAttributes attr;
373 unsigned long mask;
374 Window root;
375 GLXContext ctx;
376 XVisualInfo *visinfo;
377 int width = 100, height = 100;
378
379 root = RootWindow(dpy, scrnum);
380
381 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
382 if (!visinfo) {
383 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
384 if (!visinfo) {
385 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
386 return;
387 }
388 }
389
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);
398
399 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
400 if (!ctx) {
401 fprintf(stderr, "Error: glXCreateContext failed\n");
402 XDestroyWindow(dpy, win);
403 return;
404 }
405
406 if (glXMakeCurrent(dpy, win, ctx)) {
407 check_functions( (const char *) glGetString(GL_EXTENSIONS) );
408 }
409 else {
410 fprintf(stderr, "Error: glXMakeCurrent failed\n");
411 }
412
413 glXDestroyContext(dpy, ctx);
414 XDestroyWindow(dpy, win);
415 }
416
417
418 int
419 main(int argc, char *argv[])
420 {
421 char *displayName = NULL;
422 Display *dpy;
423
424 dpy = XOpenDisplay(displayName);
425 if (!dpy) {
426 fprintf(stderr, "Error: unable to open display %s\n", displayName);
427 return -1;
428 }
429
430 print_screen_info(dpy, 0, GL_TRUE);
431
432 XCloseDisplay(dpy);
433
434 return 0;
435 }