From 403488715e10398c50fe8856be6736a178b4c4e5 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 28 Mar 2006 17:04:10 +0000 Subject: [PATCH] compile-in reference to glXGetProcAddress() when possible --- .../glxdisplay/glxGraphicsStateGuardian.cxx | 32 ++++++++++++++----- .../src/glxdisplay/glxGraphicsStateGuardian.h | 17 +++++++++- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx index 1444391f44..856ca5752e 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx @@ -56,7 +56,7 @@ glxGraphicsStateGuardian(const FrameBufferProperties &properties, _libgl_handle = NULL; _checked_get_proc_address = false; - _glxGetProcAddress = NULL; + _glXGetProcAddress = NULL; } //////////////////////////////////////////////////////////////////// @@ -231,9 +231,24 @@ get_extension_func(const char *prefix, const char *name) { string fullname = string(prefix) + string(name); if (glx_get_proc_address) { + // First, check if we have glXGetProcAddress available. This will + // be superior if we can get it. + +#if defined(HAVE_GLXGETPROCADDRESS) + // If we are confident the system headers defined it, we can + // call it directly. This is more reliable than trying to + // determine its address dynamically. + return (void *)glXGetProcAddress((const GLubyte *)fullname.c_str()); + +#elif defined(HAVE_GLXGETPROCADDRESSARB) + // The ARB extension version is OK too. Sometimes the prototype + // isn't supplied for some reason. + return (void *)glXGetProcAddressARB((const GLubyte *)fullname.c_str()); + +#else + // Otherwise, we have to fiddle around with the dynamic runtime. + if (!_checked_get_proc_address) { - // First, check if we have glxGetProcAddress available. This will - // be superior if we can get it. const char *funcName = NULL; if (glx_is_at_least_version(1, 4)) { @@ -244,21 +259,22 @@ get_extension_func(const char *prefix, const char *name) { } if (funcName != NULL) { - _glxGetProcAddress = (PFNGLXGETPROCADDRESSPROC)get_system_func(funcName); - if (_glxGetProcAddress == NULL) { + _glXGetProcAddress = (PFNGLXGETPROCADDRESSPROC)get_system_func(funcName); + if (_glXGetProcAddress == NULL) { glxdisplay_cat.warning() << "Couldn't load function " << funcName << ", GL extensions may be unavailable.\n"; } } - + _checked_get_proc_address = true; } // Use glxGetProcAddress() if we've got it; it should be more robust. - if (_glxGetProcAddress != NULL) { - return (void *)_glxGetProcAddress((const GLubyte *)fullname.c_str()); + if (_glXGetProcAddress != NULL) { + return (void *)_glXGetProcAddress((const GLubyte *)fullname.c_str()); } +#endif // HAVE_GLXGETPROCADDRESS } if (glx_get_os_address) { diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.h b/panda/src/glxdisplay/glxGraphicsStateGuardian.h index ddcd4d4fbe..db8c3e3566 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.h +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.h @@ -26,6 +26,21 @@ #include +#if defined(GLX_VERSION_1_4) +// If the system header files give us version 1.4, we can assume it's +// safe to compile in a reference to glxGetProcAddress(). +#define HAVE_GLXGETPROCADDRESS 1 + +#elif defined(GLX_ARB_get_proc_address) +// Maybe the system header files give us the corresponding ARB call. +#define HAVE_GLXGETPROCADDRESSARB 1 + +// Sometimes the system header files don't define this prototype for +// some reason. +extern "C" void (*glXGetProcAddressARB(const GLubyte *procName))( void ); + +#endif + // This must be included after we have included glgsg.h (which // includes gl.h). #include "glxext.h" @@ -101,7 +116,7 @@ private: void *_libgl_handle; bool _checked_get_proc_address; - PFNGLXGETPROCADDRESSPROC _glxGetProcAddress; + PFNGLXGETPROCADDRESSPROC _glXGetProcAddress; public: static TypeHandle get_class_type() {