compile-in reference to glXGetProcAddress() when possible

This commit is contained in:
David Rose 2006-03-28 17:04:10 +00:00
parent 09beba8436
commit 403488715e
2 changed files with 40 additions and 9 deletions

View File

@ -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) {

View File

@ -26,6 +26,21 @@
#include <GL/glx.h>
#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() {