multisample / polygon smooth test
[mesa.git] / progs / tests / getprocaddress.c
1 /* $Id: getprocaddress.c,v 1.6 2002/11/08 15:35:46 brianp Exp $ */
2
3 /*
4 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 /*
25 * Test that glXGetProcAddress works.
26 */
27
28 #define GLX_GLXEXT_PROTOTYPES
29
30 #include <X11/Xlib.h>
31 #include <X11/Xutil.h>
32 #include <GL/gl.h>
33 #include <GL/glx.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38
39 static GLboolean
40 test_ActiveTextureARB(void *func)
41 {
42 PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func;
43 GLint t;
44 GLboolean pass;
45 (*activeTexture)(GL_TEXTURE1_ARB);
46 glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &t);
47 pass = (t == GL_TEXTURE1_ARB);
48 (*activeTexture)(GL_TEXTURE0_ARB); /* restore default */
49 return pass;
50 }
51
52
53 static GLboolean
54 test_SecondaryColor3fEXT(void *func)
55 {
56 PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func;
57 GLfloat color[4];
58 GLboolean pass;
59 (*secColor3f)(1.0, 1.0, 0.0);
60 glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT, color);
61 pass = (color[0] == 1.0 && color[1] == 1.0 && color[2] == 0.0);
62 (*secColor3f)(0.0, 0.0, 0.0); /* restore default */
63 return pass;
64 }
65
66
67 static GLboolean
68 test_ActiveStencilFaceEXT(void *func)
69 {
70 PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func;
71 GLint face;
72 GLboolean pass;
73 (*activeFace)(GL_BACK);
74 glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face);
75 pass = (face == GL_BACK);
76 (*activeFace)(GL_FRONT); /* restore default */
77 return pass;
78 }
79
80
81
82
83 /*
84 * The following header file is auto-generated with Python. The Python
85 * script looks in this file for functions named "test_*" as seen above.
86 */
87 #include "getproclist.h"
88
89
90
91 static int
92 extension_supported(const char *haystack, const char *needle)
93 {
94 if (strstr(haystack, needle))
95 return 1;
96 else
97 return 0;
98 }
99
100
101 static void
102 check_functions( const char *extensions )
103 {
104 struct name_test_pair *entry;
105 int failures = 0, passes = 0;
106 int totalFail = 0, totalPass = 0;
107 int doTests;
108
109 for (entry = functions; entry->name; entry++) {
110 if (entry->name[0] == '-') {
111 if (entry->name[1] == '1') {
112 doTests = 1;
113 }
114 else {
115 /* check if the named extension is available */
116 doTests = extension_supported(extensions, entry->name+1);
117 }
118 if (doTests)
119 printf("Testing %s functions\n", entry->name + 1);
120 totalFail += failures;
121 totalPass += passes;
122 failures = 0;
123 passes = 0;
124 }
125 else if (doTests) {
126 void *funcPtr = (void *) glXGetProcAddressARB((const GLubyte *) entry->name);
127 if (funcPtr) {
128 if (entry->test) {
129 GLboolean b;
130 printf(" Validating %s:", entry->name);
131 b = (*entry->test)(funcPtr);
132 if (b) {
133 printf(" Pass\n");
134 passes++;
135 }
136 else {
137 printf(" FAIL!!!\n");
138 failures++;
139 }
140 }
141 else {
142 passes++;
143 }
144 }
145 else {
146 printf(" glXGetProcAddress(%s) failed!\n", entry->name);
147 failures++;
148 }
149 }
150
151 if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
152 if (failures > 0) {
153 printf(" %d failed.\n", failures);
154 }
155 if (passes > 0) {
156 printf(" %d passed.\n", passes);
157 }
158 }
159 }
160 totalFail += failures;
161 totalPass += passes;
162
163 printf("-----------------------------\n");
164 printf("Total: %d pass %d fail\n", totalPass, totalFail);
165 }
166
167
168
169 static void
170 print_screen_info(Display *dpy, int scrnum, Bool allowDirect)
171 {
172 Window win;
173 int attribSingle[] = {
174 GLX_RGBA,
175 GLX_RED_SIZE, 1,
176 GLX_GREEN_SIZE, 1,
177 GLX_BLUE_SIZE, 1,
178 None };
179 int attribDouble[] = {
180 GLX_RGBA,
181 GLX_RED_SIZE, 1,
182 GLX_GREEN_SIZE, 1,
183 GLX_BLUE_SIZE, 1,
184 GLX_DOUBLEBUFFER,
185 None };
186
187 XSetWindowAttributes attr;
188 unsigned long mask;
189 Window root;
190 GLXContext ctx;
191 XVisualInfo *visinfo;
192 int width = 100, height = 100;
193
194 root = RootWindow(dpy, scrnum);
195
196 visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
197 if (!visinfo) {
198 visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
199 if (!visinfo) {
200 fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
201 return;
202 }
203 }
204
205 attr.background_pixel = 0;
206 attr.border_pixel = 0;
207 attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
208 attr.event_mask = StructureNotifyMask | ExposureMask;
209 mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
210 win = XCreateWindow(dpy, root, 0, 0, width, height,
211 0, visinfo->depth, InputOutput,
212 visinfo->visual, mask, &attr);
213
214 ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
215 if (!ctx) {
216 fprintf(stderr, "Error: glXCreateContext failed\n");
217 XDestroyWindow(dpy, win);
218 return;
219 }
220
221 if (glXMakeCurrent(dpy, win, ctx)) {
222 check_functions( (const char *) glGetString(GL_EXTENSIONS) );
223 }
224 else {
225 fprintf(stderr, "Error: glXMakeCurrent failed\n");
226 }
227
228 glXDestroyContext(dpy, ctx);
229 XDestroyWindow(dpy, win);
230 }
231
232
233 int
234 main(int argc, char *argv[])
235 {
236 char *displayName = NULL;
237 Display *dpy;
238
239 dpy = XOpenDisplay(displayName);
240 if (!dpy) {
241 fprintf(stderr, "Error: unable to open display %s\n", displayName);
242 return -1;
243 }
244
245 print_screen_info(dpy, 0, GL_TRUE);
246
247 XCloseDisplay(dpy);
248
249 return 0;
250 }