int main(int argc, char **argv) { initDummyVendors(); ptr_glVertex3fv = (pfn_glVertex3fv) __glDispatchGetProcAddress("glVertex3fv"); if (ptr_glVertex3fv == NULL) { printf("Can't look up function glVertex3fv\n"); return 1; } // Start with a quick sanity test. Make sure the normal dispatch table // works before we try patching anything. if (!testDummyVendor(2)) { return 1; } // Start with a vendor that supports patching. Even after releasing the // current context, the entrypoints will remain patched. if (!testDummyVendor(0)) { return 1; } // Test the same vendor again. if (!testDummyVendor(0)) { return 1; } // Switch to another vendor that also supports patching. This should // unpatch everything, then patch again with the new callbacks. if (!testDummyVendor(1)) { return 1; } // Switch to a vendor that doesn't support patching. This should unpatch // the entrypoints so that it goes through the normal dispatch table. if (!testDummyVendor(2)) { return 1; } cleanupDummyVendors(); return 0; }
/** * Looks up a dispatch function from a vendor library. * * If the vendor library provides a dispatch function, then it will allocate a * dispatch index for it. * * If the vendor library exports it as a normal OpenGL function, then it will * return a dispatch function from libGLdispatch. * * This function is used from __glXGetGLXDispatchAddress and as the callback to * glvndUpdateEntrypoints. */ static GLVNDentrypointStub __glXFindVendorDispatchAddress(const char *procName, __GLXvendorInfo *vendor) { __GLXextFuncPtr addr = NULL; addr = vendor->staticDispatch-> glxvc.getDispatchAddress((const GLubyte *) procName); if (addr != NULL) { // Allocate the new dispatch index. if (!AllocDispatchIndex(vendor, (const GLubyte *) procName)) { addr = NULL; } return addr; } // If we didn't find a GLX dispatch function, then check for a normal // OpenGL function. This should handle any case where a GL extension // function starts with "glX". addr = vendor->staticDispatch->glxvc.getProcAddress((const GLubyte *) procName); if (addr != NULL) { addr = __glDispatchGetProcAddress(procName); } return addr; }