1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* Copyright (c) 2019, NVIDIA CORPORATION.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and/or associated documentation files (the
* "Materials"), to deal in the Materials without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Materials, and to
* permit persons to whom the Materials are furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be included
* unaltered in all copies or substantial portions of the Materials.
* Any additions, deletions, or changes to the original source files
* must be clearly indicated in accompanying documentation.
*
* THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
*/
#if defined(USE_DISPATCH_ASM)
#include <GL/glx.h>
#include <GL/gl.h>
#include <stdio.h>
#include <stdlib.h>
#include "dummy/GLX_dummy.h"
int main(int argc, char **argv)
{
PFNGLXEXAMPLEEXTENSIONFUNCTION ptr_glXExampleExtensionFunction;
PFNGLXEXAMPLEEXTENSIONFUNCTION ptr_glXExampleExtensionFunction2;
__GLXextFuncPtr proc;
Display *dpy = NULL;
int result = 0;
int i;
// Load the function pointer first, before libGLX can load the dummy vendor
// library. That'll force libGLX to generate an entrypoint stub.
ptr_glXExampleExtensionFunction = (PFNGLXEXAMPLEEXTENSIONFUNCTION)
glXGetProcAddress((const GLubyte *) "glXExampleExtensionFunction");
if (ptr_glXExampleExtensionFunction == NULL) {
printf("Can't look up glXExampleExtensionFunction\n");
return 1;
}
printf("Got glXExampleExtensionFunction at address %p\n", ptr_glXExampleExtensionFunction);
// Call glXGetProcAddress to generate more dummy dispatch stubs, and then a
// second extension function. This tests that the generated dispatch stubs
// can correctly handle a large index.
for (i=0; i<4094; i++) {
char buf[50];
snprintf(buf, sizeof(buf), "glXUndefined%dDUMMY", i);
proc = glXGetProcAddress((const GLubyte *) buf);
if (proc == NULL) {
printf("Failed to generate stub for dummy function %d %s\n", i, buf);
return 1;
}
}
ptr_glXExampleExtensionFunction2 = (PFNGLXEXAMPLEEXTENSIONFUNCTION)
glXGetProcAddress((const GLubyte *) "glXExampleExtensionFunction2");
if (ptr_glXExampleExtensionFunction2 == NULL) {
printf("Can't look up glXExampleExtensionFunction\n");
return 1;
}
printf("Got glXExampleExtensionFunction2 at address %p\n", ptr_glXExampleExtensionFunction2);
// Make one more call to glXGetProcAddress. This should return NULL.
proc = glXGetProcAddress((const GLubyte *) "glXLastUndefinedDummy");
if (proc != NULL) {
printf("Last glXGetProcAddress returned non-NULL: %p\n", proc);
return 1;
}
dpy = XOpenDisplay(NULL);
if (dpy == NULL) {
printf("Can't open display\n");
return 1;
}
// Call glXGetClientString to force libGLX to load the vendor library.
glXGetClientString(dpy, GLX_EXTENSIONS);
ptr_glXExampleExtensionFunction(dpy, 0, &result);
if (result != 1) {
printf("Unexpected glXExampleExtensionFunction() return value: %d\n", result);
XCloseDisplay(dpy);
return 1;
}
ptr_glXExampleExtensionFunction2(dpy, 0, &result);
if (result != 2) {
printf("Unexpected glXExampleExtensionFunction2() return value: %d\n", result);
XCloseDisplay(dpy);
return 1;
}
printf("%p - %p = %d\n", ptr_glXExampleExtensionFunction2,
ptr_glXExampleExtensionFunction,
(int) (((intptr_t) ptr_glXExampleExtensionFunction2) - ((intptr_t) ptr_glXExampleExtensionFunction)));
XCloseDisplay(dpy);
return 0;
}
#else // defined(USE_DISPATCH_ASM)
int main(int argc, char **argv)
{
// If libGLX can't generate new dispatch stubs, then just skip this test.
return 77;
}
#endif // defined(USE_DISPATCH_ASM)
|