Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

getprocaddress.c 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. * Test that glXGetProcAddress works.
  23. */
  24. #define GLX_GLXEXT_PROTOTYPES
  25. #include <X11/Xlib.h>
  26. #include <X11/Xutil.h>
  27. #include <GL/gl.h>
  28. #include <GL/glx.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <math.h>
  33. #define EQUAL(X, Y) (fabs((X) - (Y)) < 0.001)
  34. static GLboolean
  35. test_ActiveTextureARB(void *func)
  36. {
  37. PFNGLACTIVETEXTUREARBPROC activeTexture = (PFNGLACTIVETEXTUREARBPROC) func;
  38. GLint t;
  39. GLboolean pass;
  40. (*activeTexture)(GL_TEXTURE1_ARB);
  41. glGetIntegerv(GL_ACTIVE_TEXTURE_ARB, &t);
  42. pass = (t == GL_TEXTURE1_ARB);
  43. (*activeTexture)(GL_TEXTURE0_ARB); /* restore default */
  44. return pass;
  45. }
  46. static GLboolean
  47. test_SecondaryColor3fEXT(void *func)
  48. {
  49. PFNGLSECONDARYCOLOR3FEXTPROC secColor3f = (PFNGLSECONDARYCOLOR3FEXTPROC) func;
  50. GLfloat color[4];
  51. GLboolean pass;
  52. (*secColor3f)(1.0, 1.0, 0.0);
  53. glGetFloatv(GL_CURRENT_SECONDARY_COLOR_EXT, color);
  54. pass = (color[0] == 1.0 && color[1] == 1.0 && color[2] == 0.0);
  55. (*secColor3f)(0.0, 0.0, 0.0); /* restore default */
  56. return pass;
  57. }
  58. static GLboolean
  59. test_ActiveStencilFaceEXT(void *func)
  60. {
  61. PFNGLACTIVESTENCILFACEEXTPROC activeFace = (PFNGLACTIVESTENCILFACEEXTPROC) func;
  62. GLint face;
  63. GLboolean pass;
  64. (*activeFace)(GL_BACK);
  65. glGetIntegerv(GL_ACTIVE_STENCIL_FACE_EXT, &face);
  66. pass = (face == GL_BACK);
  67. (*activeFace)(GL_FRONT); /* restore default */
  68. return pass;
  69. }
  70. static GLboolean
  71. test_VertexAttrib1fvARB(void *func)
  72. {
  73. PFNGLVERTEXATTRIB1FVARBPROC vertexAttrib1fvARB = (PFNGLVERTEXATTRIB1FVARBPROC) func;
  74. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  75. const GLfloat v[1] = {25.0};
  76. const GLfloat def[1] = {0};
  77. GLfloat res[4];
  78. GLboolean pass;
  79. (*vertexAttrib1fvARB)(6, v);
  80. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  81. pass = (res[0] == 25.0 && res[1] == 0.0 && res[2] == 0.0 && res[3] == 1.0);
  82. (*vertexAttrib1fvARB)(6, def);
  83. return pass;
  84. }
  85. static GLboolean
  86. test_VertexAttrib4NubvARB(void *func)
  87. {
  88. PFNGLVERTEXATTRIB4NUBVARBPROC vertexAttrib4NubvARB = (PFNGLVERTEXATTRIB4NUBVARBPROC) func;
  89. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  90. const GLubyte v[4] = {255, 0, 255, 0};
  91. const GLubyte def[4] = {0, 0, 0, 255};
  92. GLfloat res[4];
  93. GLboolean pass;
  94. (*vertexAttrib4NubvARB)(6, v);
  95. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  96. pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
  97. (*vertexAttrib4NubvARB)(6, def);
  98. return pass;
  99. }
  100. static GLboolean
  101. test_VertexAttrib4NuivARB(void *func)
  102. {
  103. PFNGLVERTEXATTRIB4NUIVARBPROC vertexAttrib4NuivARB = (PFNGLVERTEXATTRIB4NUIVARBPROC) func;
  104. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  105. const GLuint v[4] = {0xffffffff, 0, 0xffffffff, 0};
  106. const GLuint def[4] = {0, 0, 0, 0xffffffff};
  107. GLfloat res[4];
  108. GLboolean pass;
  109. (*vertexAttrib4NuivARB)(6, v);
  110. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  111. pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
  112. (*vertexAttrib4NuivARB)(6, def);
  113. return pass;
  114. }
  115. static GLboolean
  116. test_VertexAttrib4ivARB(void *func)
  117. {
  118. PFNGLVERTEXATTRIB4IVARBPROC vertexAttrib4ivARB = (PFNGLVERTEXATTRIB4IVARBPROC) func;
  119. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  120. const GLint v[4] = {1, 2, -3, 4};
  121. const GLint def[4] = {0, 0, 0, 1};
  122. GLfloat res[4];
  123. GLboolean pass;
  124. (*vertexAttrib4ivARB)(6, v);
  125. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  126. pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 2.0) && EQUAL(res[2], -3.0) && EQUAL(res[3], 4.0));
  127. (*vertexAttrib4ivARB)(6, def);
  128. return pass;
  129. }
  130. static GLboolean
  131. test_VertexAttrib4NsvARB(void *func)
  132. {
  133. PFNGLVERTEXATTRIB4NSVARBPROC vertexAttrib4NsvARB = (PFNGLVERTEXATTRIB4NSVARBPROC) func;
  134. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  135. const GLshort v[4] = {0, 32767, 32767, 0};
  136. const GLshort def[4] = {0, 0, 0, 32767};
  137. GLfloat res[4];
  138. GLboolean pass;
  139. (*vertexAttrib4NsvARB)(6, v);
  140. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  141. pass = (EQUAL(res[0], 0.0) && EQUAL(res[1], 1.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
  142. (*vertexAttrib4NsvARB)(6, def);
  143. return pass;
  144. }
  145. static GLboolean
  146. test_VertexAttrib4NusvARB(void *func)
  147. {
  148. PFNGLVERTEXATTRIB4NUSVARBPROC vertexAttrib4NusvARB = (PFNGLVERTEXATTRIB4NUSVARBPROC) func;
  149. PFNGLGETVERTEXATTRIBFVARBPROC getVertexAttribfvARB = (PFNGLGETVERTEXATTRIBFVARBPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvARB");
  150. const GLushort v[4] = {0xffff, 0, 0xffff, 0};
  151. const GLushort def[4] = {0, 0, 0, 0xffff};
  152. GLfloat res[4];
  153. GLboolean pass;
  154. (*vertexAttrib4NusvARB)(6, v);
  155. (*getVertexAttribfvARB)(6, GL_CURRENT_VERTEX_ATTRIB_ARB, res);
  156. pass = (EQUAL(res[0], 1.0) && EQUAL(res[1], 0.0) && EQUAL(res[2], 1.0) && EQUAL(res[3], 0.0));
  157. (*vertexAttrib4NusvARB)(6, def);
  158. return pass;
  159. }
  160. static GLboolean
  161. test_VertexAttrib4ubNV(void *func)
  162. {
  163. PFNGLVERTEXATTRIB4UBNVPROC vertexAttrib4ubNV = (PFNGLVERTEXATTRIB4UBNVPROC) func;
  164. PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
  165. const GLubyte v[4] = {255, 0, 255, 0};
  166. const GLubyte def[4] = {0, 0, 0, 255};
  167. GLfloat res[4];
  168. GLboolean pass;
  169. (*vertexAttrib4ubNV)(6, v[0], v[1], v[2], v[3]);
  170. (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
  171. pass = (res[0] == 1.0 && res[1] == 0.0 && res[2] == 1.0 && res[3] == 0.0);
  172. (*vertexAttrib4ubNV)(6, def[0], def[1], def[2], def[3]);
  173. return pass;
  174. }
  175. static GLboolean
  176. test_VertexAttrib2sNV(void *func)
  177. {
  178. PFNGLVERTEXATTRIB2SNVPROC vertexAttrib2sNV = (PFNGLVERTEXATTRIB2SNVPROC) func;
  179. PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
  180. const GLshort v[2] = {2, -4,};
  181. const GLshort def[2] = {0, 0};
  182. GLfloat res[4];
  183. GLboolean pass;
  184. (*vertexAttrib2sNV)(6, v[0], v[1]);
  185. (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
  186. pass = (EQUAL(res[0], 2) && EQUAL(res[1], -4) && EQUAL(res[2], 0) && res[3] == 1.0);
  187. (*vertexAttrib2sNV)(6, def[0], def[1]);
  188. return pass;
  189. }
  190. static GLboolean
  191. test_VertexAttrib3fNV(void *func)
  192. {
  193. PFNGLVERTEXATTRIB3FNVPROC vertexAttrib3fNV = (PFNGLVERTEXATTRIB3FNVPROC) func;
  194. PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
  195. const GLfloat v[3] = {0.2, 0.4, 0.8};
  196. const GLfloat def[3] = {0, 0, 0};
  197. GLfloat res[4];
  198. GLboolean pass;
  199. (*vertexAttrib3fNV)(6, v[0], v[1], v[2]);
  200. (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
  201. pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && res[3] == 1.0);
  202. (*vertexAttrib3fNV)(6, def[0], def[1], def[2]);
  203. return pass;
  204. }
  205. static GLboolean
  206. test_VertexAttrib4dvNV(void *func)
  207. {
  208. PFNGLVERTEXATTRIB4DVNVPROC vertexAttrib4dvNV = (PFNGLVERTEXATTRIB4DVNVPROC) func;
  209. PFNGLGETVERTEXATTRIBFVNVPROC getVertexAttribfvNV = (PFNGLGETVERTEXATTRIBFVNVPROC) glXGetProcAddressARB((const GLubyte *) "glGetVertexAttribfvNV");
  210. const GLdouble v[4] = {0.2, 0.4, 0.8, 1.2};
  211. const GLdouble def[4] = {0, 0, 0, 1};
  212. GLfloat res[4];
  213. GLboolean pass;
  214. (*vertexAttrib4dvNV)(6, v);
  215. (*getVertexAttribfvNV)(6, GL_CURRENT_ATTRIB_NV, res);
  216. pass = (EQUAL(res[0], 0.2) && EQUAL(res[1], 0.4) && EQUAL(res[2], 0.8) && EQUAL(res[3], 1.2));
  217. (*vertexAttrib4dvNV)(6, def);
  218. return pass;
  219. }
  220. /*
  221. * The following header file is auto-generated with Python. The Python
  222. * script looks in this file for functions named "test_*" as seen above.
  223. */
  224. #include "getproclist.h"
  225. static int
  226. extension_supported(const char *haystack, const char *needle)
  227. {
  228. if (strstr(haystack, needle))
  229. return 1;
  230. else
  231. return 0;
  232. }
  233. static void
  234. check_functions( const char *extensions )
  235. {
  236. struct name_test_pair *entry;
  237. int failures = 0, passes = 0;
  238. int totalFail = 0, totalPass = 0;
  239. int doTests;
  240. for (entry = functions; entry->name; entry++) {
  241. if (entry->name[0] == '-') {
  242. if (entry->name[1] == '1') {
  243. /* check GL version X.Y */
  244. const char *version = (const char *) glGetString(GL_VERSION);
  245. if (version[0] == entry->name[1] &&
  246. version[1] == entry->name[2] &&
  247. version[2] >= entry->name[3])
  248. doTests = 1;
  249. else
  250. doTests = 0;
  251. }
  252. else {
  253. /* check if the named extension is available */
  254. doTests = extension_supported(extensions, entry->name+1);
  255. }
  256. if (doTests)
  257. printf("Testing %s functions\n", entry->name + 1);
  258. totalFail += failures;
  259. totalPass += passes;
  260. failures = 0;
  261. passes = 0;
  262. }
  263. else if (doTests) {
  264. void *funcPtr = (void *) glXGetProcAddressARB((const GLubyte *) entry->name);
  265. if (funcPtr) {
  266. if (entry->test) {
  267. GLboolean b;
  268. printf(" Validating %s:", entry->name);
  269. b = (*entry->test)(funcPtr);
  270. if (b) {
  271. printf(" Pass\n");
  272. passes++;
  273. }
  274. else {
  275. printf(" FAIL!!!\n");
  276. failures++;
  277. }
  278. }
  279. else {
  280. passes++;
  281. }
  282. }
  283. else {
  284. printf(" glXGetProcAddress(%s) failed!\n", entry->name);
  285. failures++;
  286. }
  287. }
  288. if (doTests && (!(entry+1)->name || (entry+1)->name[0] == '-')) {
  289. if (failures > 0) {
  290. printf(" %d failed.\n", failures);
  291. }
  292. if (passes > 0) {
  293. printf(" %d passed.\n", passes);
  294. }
  295. }
  296. }
  297. totalFail += failures;
  298. totalPass += passes;
  299. printf("-----------------------------\n");
  300. printf("Total: %d pass %d fail\n", totalPass, totalFail);
  301. }
  302. static void
  303. print_screen_info(Display *dpy, int scrnum, Bool allowDirect)
  304. {
  305. Window win;
  306. int attribSingle[] = {
  307. GLX_RGBA,
  308. GLX_RED_SIZE, 1,
  309. GLX_GREEN_SIZE, 1,
  310. GLX_BLUE_SIZE, 1,
  311. None };
  312. int attribDouble[] = {
  313. GLX_RGBA,
  314. GLX_RED_SIZE, 1,
  315. GLX_GREEN_SIZE, 1,
  316. GLX_BLUE_SIZE, 1,
  317. GLX_DOUBLEBUFFER,
  318. None };
  319. XSetWindowAttributes attr;
  320. unsigned long mask;
  321. Window root;
  322. GLXContext ctx;
  323. XVisualInfo *visinfo;
  324. int width = 100, height = 100;
  325. root = RootWindow(dpy, scrnum);
  326. visinfo = glXChooseVisual(dpy, scrnum, attribSingle);
  327. if (!visinfo) {
  328. visinfo = glXChooseVisual(dpy, scrnum, attribDouble);
  329. if (!visinfo) {
  330. fprintf(stderr, "Error: couldn't find RGB GLX visual\n");
  331. return;
  332. }
  333. }
  334. attr.background_pixel = 0;
  335. attr.border_pixel = 0;
  336. attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone);
  337. attr.event_mask = StructureNotifyMask | ExposureMask;
  338. mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
  339. win = XCreateWindow(dpy, root, 0, 0, width, height,
  340. 0, visinfo->depth, InputOutput,
  341. visinfo->visual, mask, &attr);
  342. ctx = glXCreateContext( dpy, visinfo, NULL, allowDirect );
  343. if (!ctx) {
  344. fprintf(stderr, "Error: glXCreateContext failed\n");
  345. XDestroyWindow(dpy, win);
  346. return;
  347. }
  348. if (glXMakeCurrent(dpy, win, ctx)) {
  349. check_functions( (const char *) glGetString(GL_EXTENSIONS) );
  350. }
  351. else {
  352. fprintf(stderr, "Error: glXMakeCurrent failed\n");
  353. }
  354. glXDestroyContext(dpy, ctx);
  355. XDestroyWindow(dpy, win);
  356. }
  357. int
  358. main(int argc, char *argv[])
  359. {
  360. char *displayName = NULL;
  361. Display *dpy;
  362. dpy = XOpenDisplay(displayName);
  363. if (!dpy) {
  364. fprintf(stderr, "Error: unable to open display %s\n", displayName);
  365. return -1;
  366. }
  367. print_screen_info(dpy, 0, GL_TRUE);
  368. XCloseDisplay(dpy);
  369. return 0;
  370. }