Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

getprocaddress.c 6.5KB

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