blob: 95f34ade6277859007a8bce8c8e8603baf650c90 [file] [log] [blame]
Brian Pauld1efbf02002-11-08 15:35:46 +00001/* $Id: getprocaddress.c,v 1.6 2002/11/08 15:35:46 brianp Exp $ */
Brian Paul17fe22d2001-11-18 23:16:56 +00002
3/*
Brian Paul1cfae1a2002-11-07 16:23:40 +00004 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
Brian Paul17fe22d2001-11-18 23:16:56 +00005 *
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
Brian Pauld4ece7b2001-11-21 17:21:41 +000028#define GLX_GLXEXT_PROTOTYPES
29
Brian Paul17fe22d2001-11-18 23:16:56 +000030#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
Brian Pauld1efbf02002-11-08 15:35:46 +000039static GLboolean
40test_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}
Brian Paul17fe22d2001-11-18 23:16:56 +000051
Brian Pauld1efbf02002-11-08 15:35:46 +000052
53static GLboolean
54test_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
67static GLboolean
68test_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
Brian Paul17fe22d2001-11-18 23:16:56 +000089
90
Brian Paul17fe22d2001-11-18 23:16:56 +000091static int
92extension_supported(const char *haystack, const char *needle)
93{
94 if (strstr(haystack, needle))
95 return 1;
96 else
97 return 0;
98}
99
100
101static void
Brian Pauld1efbf02002-11-08 15:35:46 +0000102check_functions( const char *extensions )
Brian Paul17fe22d2001-11-18 23:16:56 +0000103{
Brian Pauld1efbf02002-11-08 15:35:46 +0000104 struct name_test_pair *entry;
Brian Paul17fe22d2001-11-18 23:16:56 +0000105 int failures = 0, passes = 0;
Brian Pauld1efbf02002-11-08 15:35:46 +0000106 int totalFail = 0, totalPass = 0;
Brian Paul17fe22d2001-11-18 23:16:56 +0000107 int doTests;
Brian Paul17fe22d2001-11-18 23:16:56 +0000108
Brian Pauld1efbf02002-11-08 15:35:46 +0000109 for (entry = functions; entry->name; entry++) {
110 if (entry->name[0] == '-') {
111 if (entry->name[1] == '1') {
Brian Paul17fe22d2001-11-18 23:16:56 +0000112 doTests = 1;
113 }
114 else {
115 /* check if the named extension is available */
Brian Pauld1efbf02002-11-08 15:35:46 +0000116 doTests = extension_supported(extensions, entry->name+1);
Brian Paul17fe22d2001-11-18 23:16:56 +0000117 }
118 if (doTests)
Brian Pauld1efbf02002-11-08 15:35:46 +0000119 printf("Testing %s functions\n", entry->name + 1);
120 totalFail += failures;
121 totalPass += passes;
Brian Paul17fe22d2001-11-18 23:16:56 +0000122 failures = 0;
123 passes = 0;
124 }
125 else if (doTests) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000126 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 }
Brian Paul17fe22d2001-11-18 23:16:56 +0000144 }
145 else {
Brian Pauld1efbf02002-11-08 15:35:46 +0000146 printf(" glXGetProcAddress(%s) failed!\n", entry->name);
Brian Paul17fe22d2001-11-18 23:16:56 +0000147 failures++;
148 }
149 }
150
Brian Pauld1efbf02002-11-08 15:35:46 +0000151 if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000152 if (failures > 0) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000153 printf(" %d failed.\n", failures);
Brian Paul17fe22d2001-11-18 23:16:56 +0000154 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000155 if (passes > 0) {
Brian Paul17fe22d2001-11-18 23:16:56 +0000156 printf(" %d passed.\n", passes);
157 }
158 }
159 }
Brian Pauld1efbf02002-11-08 15:35:46 +0000160 totalFail += failures;
161 totalPass += passes;
162
163 printf("-----------------------------\n");
164 printf("Total: %d pass %d fail\n", totalPass, totalFail);
Brian Paul17fe22d2001-11-18 23:16:56 +0000165}
166
167
168
169static void
170print_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)) {
Brian Pauld1efbf02002-11-08 15:35:46 +0000222 check_functions( (const char *) glGetString(GL_EXTENSIONS) );
Brian Paul17fe22d2001-11-18 23:16:56 +0000223 }
224 else {
225 fprintf(stderr, "Error: glXMakeCurrent failed\n");
226 }
227
228 glXDestroyContext(dpy, ctx);
229 XDestroyWindow(dpy, win);
230}
231
232
233int
234main(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}