From e08d134dba0e5c83668f6c723325df2f22589582 Mon Sep 17 00:00:00 2001 From: David Rose Date: Thu, 5 Aug 2004 16:47:41 +0000 Subject: [PATCH] respect old versions of glx.h a little better --- panda/src/glxdisplay/config_glxdisplay.cxx | 2 ++ panda/src/glxdisplay/glxGraphicsBuffer.cxx | 7 +++++ panda/src/glxdisplay/glxGraphicsBuffer.h | 6 ++++ panda/src/glxdisplay/glxGraphicsPipe.cxx | 28 ++++++++++++++--- panda/src/glxdisplay/glxGraphicsPipe.h | 30 +++++++++++++++++-- .../glxdisplay/glxGraphicsStateGuardian.cxx | 12 ++++++-- .../src/glxdisplay/glxGraphicsStateGuardian.h | 18 +++++++++-- panda/src/glxdisplay/glxGraphicsWindow.cxx | 6 ++++ panda/src/glxdisplay/glxGraphicsWindow.h | 2 ++ panda/src/glxdisplay/glxext.h | 6 ++++ 10 files changed, 104 insertions(+), 13 deletions(-) diff --git a/panda/src/glxdisplay/config_glxdisplay.cxx b/panda/src/glxdisplay/config_glxdisplay.cxx index baa3078416..1e08a4e56a 100644 --- a/panda/src/glxdisplay/config_glxdisplay.cxx +++ b/panda/src/glxdisplay/config_glxdisplay.cxx @@ -47,7 +47,9 @@ init_libglxdisplay() { } initialized = true; +#ifdef HAVE_GLXFBCONFIG glxGraphicsBuffer::init_type(); +#endif // HAVE_GLXFBCONFIG glxGraphicsPipe::init_type(); glxGraphicsWindow::init_type(); glxGraphicsStateGuardian::init_type(); diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.cxx b/panda/src/glxdisplay/glxGraphicsBuffer.cxx index 93ae72a2ed..d28dcc8056 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.cxx +++ b/panda/src/glxdisplay/glxGraphicsBuffer.cxx @@ -25,6 +25,10 @@ #include "glgsg.h" #include "pStatTimer.h" +#ifdef HAVE_GLXFBCONFIG +// This whole class doesn't make sense unless we have the GLXFBConfig +// and associated GLXPbuffer interfaces available. + TypeHandle glxGraphicsBuffer::_type_handle; //////////////////////////////////////////////////////////////////// @@ -165,3 +169,6 @@ open_buffer() { _is_valid = true; return true; } + + +#endif // HAVE_GLXFBCONFIG diff --git a/panda/src/glxdisplay/glxGraphicsBuffer.h b/panda/src/glxdisplay/glxGraphicsBuffer.h index d816fd19aa..2c7ccf92dc 100644 --- a/panda/src/glxdisplay/glxGraphicsBuffer.h +++ b/panda/src/glxdisplay/glxGraphicsBuffer.h @@ -24,6 +24,10 @@ #include "glxGraphicsPipe.h" #include "graphicsBuffer.h" +#ifdef HAVE_GLXFBCONFIG +// This whole class doesn't make sense unless we have the GLXFBConfig +// and associated GLXPbuffer interfaces available. + //////////////////////////////////////////////////////////////////// // Class : glxGraphicsBuffer // Description : An offscreen buffer in the GLX environment. This @@ -68,4 +72,6 @@ private: #include "glxGraphicsBuffer.I" +#endif // HAVE_GLXFBCONFIG + #endif diff --git a/panda/src/glxdisplay/glxGraphicsPipe.cxx b/panda/src/glxdisplay/glxGraphicsPipe.cxx index 6bc4160712..d80509155b 100644 --- a/panda/src/glxdisplay/glxGraphicsPipe.cxx +++ b/panda/src/glxdisplay/glxGraphicsPipe.cxx @@ -186,15 +186,20 @@ make_gsg(const FrameBufferProperties &properties, FrameBufferProperties new_properties = properties; GLXContext context = NULL; - - GLXFBConfig fbconfig = choose_fbconfig(new_properties); XVisualInfo *visual = NULL; +#ifdef HAVE_GLXFBCONFIG + GLXFBConfig fbconfig = choose_fbconfig(new_properties); if (fbconfig != None) { context = glXCreateNewContext(_display, fbconfig, GLX_RGBA_TYPE, share_context, GL_TRUE); + if (context == NULL) { + fbconfig = None; + } } +#endif // HAVE_GLXFBCONFIG + if (context == NULL) { // If we couldn't create a context with the fbconfig interface, // try falling back to the older XVisual interface. @@ -202,7 +207,6 @@ make_gsg(const FrameBufferProperties &properties, if (visual != (XVisualInfo *)NULL) { context = glXCreateContext(_display, visual, None, GL_TRUE); - fbconfig = None; } } @@ -212,6 +216,7 @@ make_gsg(const FrameBufferProperties &properties, return NULL; } +#ifdef HAVE_GLXFBCONFIG if (visual == (XVisualInfo *)NULL) { // If we used the fbconfig to open the context, we still need to // get the associated XVisual. @@ -222,7 +227,14 @@ make_gsg(const FrameBufferProperties &properties, // Now we can make a GSG. PT(glxGraphicsStateGuardian) gsg = new glxGraphicsStateGuardian(new_properties, share_gsg, context, - fbconfig, visual, _display, _screen); + visual, _display, _screen, fbconfig); + +#else + PT(glxGraphicsStateGuardian) gsg = + new glxGraphicsStateGuardian(new_properties, share_gsg, context, + visual, _display, _screen); +#endif // HAVE_GLXFBCONFIG + return gsg.p(); } @@ -252,9 +264,14 @@ make_buffer(GraphicsStateGuardian *gsg, const string &name, return NULL; } +#ifdef HAVE_GLXFBCONFIG return new glxGraphicsBuffer(this, gsg, name, x_size, y_size, want_texture); +#else + return NULL; +#endif // HAVE_GLXFBCONFIG } +#ifdef HAVE_GLXFBCONFIG //////////////////////////////////////////////////////////////////// // Function: glxGraphicsPipe::choose_fbconfig // Access: Private @@ -471,7 +488,9 @@ choose_fbconfig(FrameBufferProperties &properties) const { return fbconfig; } +#endif // HAVE_GLXFBCONFIG +#ifdef HAVE_GLXFBCONFIG //////////////////////////////////////////////////////////////////// // Function: glxGraphicsPipe::try_for_fbconfig // Access: Private @@ -596,6 +615,7 @@ try_for_fbconfig(int framebuffer_mode, return fbconfig; } +#endif // HAVE_GLXFBCONFIG //////////////////////////////////////////////////////////////////// // Function: glxGraphicsPipe::choose visual diff --git a/panda/src/glxdisplay/glxGraphicsPipe.h b/panda/src/glxdisplay/glxGraphicsPipe.h index 669a1a3303..10dcdca7de 100644 --- a/panda/src/glxdisplay/glxGraphicsPipe.h +++ b/panda/src/glxdisplay/glxGraphicsPipe.h @@ -32,8 +32,6 @@ typedef int Display; typedef int Window; typedef int XErrorEvent; typedef int XVisualInfo; -typedef int GLXFBConfig; -typedef int GLXPbuffer; typedef int Atom; typedef int Cursor; typedef int XIM; @@ -42,10 +40,34 @@ typedef int XIC; #include #include +#if defined(GLX_VERSION_1_3) + // If the system glx version is at least 1.3, then we know we have + // GLXFBConfig and GLXPbuffer. + #define HAVE_GLXFBCONFIG +#endif + // This must be included after we have included glgsg.h (which -// includes gl.h). +// includes gl.h), and after we have checked GLX_VERSION_1_3. But we +// must also include it before we redefine the GLXFBConfig types, +// below. #include "glxext.h" +#if !defined(HAVE_GLXFBCONFIG) && defined(GLX_SGIX_fbconfig) && defined(GLX_SGIX_pbuffer) + // If the system glx version isn't 1.3, but these were defined as + // extensions, we can work with that. + #define GLX_RGBA_TYPE GLX_RGBA_TYPE_SGIX + #define GLXFBConfig GLXFBConfigSGIX + #define GLXPbuffer GLXPbufferSGIX + #define glXChooseFBConfig glXChooseFBConfigSGIX + #define glXCreateNewContext glXCreateContextWithConfigSGIX + #define glXGetVisualFromFBConfig glXGetVisualFromFBConfigSGIX + #define glXGetFBConfigAttrib glXGetFBConfigAttribSGIX + #define glXCreatePbuffer glXCreateGLXPbufferSGIX + #define glXDestroyPbuffer glXDestroyGLXPbufferSGIX + + #define HAVE_GLXFBCONFIG +#endif + #endif // CPPPARSER //////////////////////////////////////////////////////////////////// @@ -81,9 +103,11 @@ protected: int x_size, int y_size, bool want_texture); private: +#ifdef HAVE_GLXFBCONFIG GLXFBConfig choose_fbconfig(FrameBufferProperties &properties) const; GLXFBConfig try_for_fbconfig(int framebuffer_mode, int want_depth_bits, int want_color_bits) const; +#endif XVisualInfo *choose_visual(FrameBufferProperties &properties) const; XVisualInfo *try_for_visual(int framebuffer_mode, diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx index cdbe62c965..30e7f56541 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.cxx @@ -33,14 +33,20 @@ TypeHandle glxGraphicsStateGuardian::_type_handle; glxGraphicsStateGuardian:: glxGraphicsStateGuardian(const FrameBufferProperties &properties, glxGraphicsStateGuardian *share_with, - GLXContext context, GLXFBConfig fbconfig, - XVisualInfo *visual, Display *display, int screen) : + GLXContext context, XVisualInfo *visual, + Display *display, int screen +#ifdef HAVE_GLXFBCONFIG + , GLXFBConfig fbconfig +#endif // HAVE_GLXFBCONFIG + ) : GLGraphicsStateGuardian(properties), _context(context), - _fbconfig(fbconfig), _visual(visual), _display(display), _screen(screen) +#ifdef HAVE_GLXFBCONFIG + , _fbconfig(fbconfig) +#endif // HAVE_GLXFBCONFIG { if (share_with != (glxGraphicsStateGuardian *)NULL) { _prepared_objects = share_with->get_prepared_objects(); diff --git a/panda/src/glxdisplay/glxGraphicsStateGuardian.h b/panda/src/glxdisplay/glxGraphicsStateGuardian.h index b72a92df66..1d640a1e4f 100644 --- a/panda/src/glxdisplay/glxGraphicsStateGuardian.h +++ b/panda/src/glxdisplay/glxGraphicsStateGuardian.h @@ -37,20 +37,32 @@ //////////////////////////////////////////////////////////////////// class glxGraphicsStateGuardian : public GLGraphicsStateGuardian { public: +#ifdef HAVE_GLXFBCONFIG glxGraphicsStateGuardian(const FrameBufferProperties &properties, glxGraphicsStateGuardian *share_with, - GLXContext context, GLXFBConfig fbconfig, - XVisualInfo *visual, Display *display, int screen); + GLXContext context, XVisualInfo *visual, + Display *display, int screen, + GLXFBConfig fbconfig); +#else + glxGraphicsStateGuardian(const FrameBufferProperties &properties, + glxGraphicsStateGuardian *share_with, + GLXContext context, XVisualInfo *visual, + Display *display, int screen); +#endif // HAVE_GLXFBCONFIG + virtual ~glxGraphicsStateGuardian(); bool glx_is_at_least_version(int major_version, int minor_version) const; GLXContext _context; - GLXFBConfig _fbconfig; XVisualInfo *_visual; Display *_display; int _screen; +#ifdef HAVE_GLXFBCONFIG + GLXFBConfig _fbconfig; +#endif // HAVE_GLXFBCONFIG + protected: virtual void get_gl_version(); virtual void get_extra_extensions(); diff --git a/panda/src/glxdisplay/glxGraphicsWindow.cxx b/panda/src/glxdisplay/glxGraphicsWindow.cxx index 5928a2839a..77db55b420 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.cxx +++ b/panda/src/glxdisplay/glxGraphicsWindow.cxx @@ -525,11 +525,15 @@ open_window() { Window root_window = glx_pipe->get_root(); +#ifdef HAVE_GLXFBCONFIG if (glxgsg->_fbconfig != None) { setup_colormap(glxgsg->_fbconfig); } else { setup_colormap(visual_info); } +#else + setup_colormap(visual_info); +#endif // HAVE_GLXFBCONFIG _event_mask = ButtonPressMask | ButtonReleaseMask | @@ -681,6 +685,7 @@ set_wm_properties(const WindowProperties &properties) { sizeof(protocols) / sizeof(Atom)); } +#ifdef HAVE_GLXFBCONFIG //////////////////////////////////////////////////////////////////// // Function: glxGraphicsWindow::setup_colormap // Access: Private @@ -736,6 +741,7 @@ setup_colormap(GLXFBConfig fbconfig) { break; } } +#endif // HAVE_GLXFBCONFIG //////////////////////////////////////////////////////////////////// // Function: glxGraphicsWindow::setup_colormap diff --git a/panda/src/glxdisplay/glxGraphicsWindow.h b/panda/src/glxdisplay/glxGraphicsWindow.h index 795da59737..7846f37c57 100644 --- a/panda/src/glxdisplay/glxGraphicsWindow.h +++ b/panda/src/glxdisplay/glxGraphicsWindow.h @@ -55,7 +55,9 @@ protected: private: void set_wm_properties(const WindowProperties &properties); +#ifdef HAVE_GLXFBCONFIG void setup_colormap(GLXFBConfig fbconfig); +#endif // HAVE_GLXFBCONFIG void setup_colormap(XVisualInfo *visual); void handle_keystroke(XKeyEvent &event); void handle_keypress(XKeyEvent &event); diff --git a/panda/src/glxdisplay/glxext.h b/panda/src/glxdisplay/glxext.h index d5784a14cf..036ab6a824 100644 --- a/panda/src/glxdisplay/glxext.h +++ b/panda/src/glxdisplay/glxext.h @@ -327,6 +327,12 @@ typedef struct { #ifndef GLX_VERSION_1_3 #define GLX_VERSION_1_3 1 + /* drose: If the system glx.h isn't at least version 1.3, it won't + have defined these types, so we need to do so here in order for + the following to compile. */ +typedef struct __GLXFBConfigRec *GLXFBConfig; +typedef XID GLXPbuffer; + #ifdef GLX_GLXEXT_PROTOTYPES extern GLXFBConfig * glXGetFBConfigs (Display *, int, int *); extern GLXFBConfig * glXChooseFBConfig (Display *, int, const int *, int *);