Browse Source

respect old versions of glx.h a little better

David Rose 21 years ago
parent
commit
e08d134dba

+ 2 - 0
panda/src/glxdisplay/config_glxdisplay.cxx

@@ -47,7 +47,9 @@ init_libglxdisplay() {
   }
   }
   initialized = true;
   initialized = true;
 
 
+#ifdef HAVE_GLXFBCONFIG
   glxGraphicsBuffer::init_type();
   glxGraphicsBuffer::init_type();
+#endif  // HAVE_GLXFBCONFIG
   glxGraphicsPipe::init_type();
   glxGraphicsPipe::init_type();
   glxGraphicsWindow::init_type();
   glxGraphicsWindow::init_type();
   glxGraphicsStateGuardian::init_type();
   glxGraphicsStateGuardian::init_type();

+ 7 - 0
panda/src/glxdisplay/glxGraphicsBuffer.cxx

@@ -25,6 +25,10 @@
 #include "glgsg.h"
 #include "glgsg.h"
 #include "pStatTimer.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;
 TypeHandle glxGraphicsBuffer::_type_handle;
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -165,3 +169,6 @@ open_buffer() {
   _is_valid = true;
   _is_valid = true;
   return true;
   return true;
 }
 }
+
+
+#endif  // HAVE_GLXFBCONFIG

+ 6 - 0
panda/src/glxdisplay/glxGraphicsBuffer.h

@@ -24,6 +24,10 @@
 #include "glxGraphicsPipe.h"
 #include "glxGraphicsPipe.h"
 #include "graphicsBuffer.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
 //       Class : glxGraphicsBuffer
 // Description : An offscreen buffer in the GLX environment.  This
 // Description : An offscreen buffer in the GLX environment.  This
@@ -68,4 +72,6 @@ private:
 
 
 #include "glxGraphicsBuffer.I"
 #include "glxGraphicsBuffer.I"
 
 
+#endif  // HAVE_GLXFBCONFIG
+
 #endif
 #endif

+ 24 - 4
panda/src/glxdisplay/glxGraphicsPipe.cxx

@@ -186,15 +186,20 @@ make_gsg(const FrameBufferProperties &properties,
 
 
   FrameBufferProperties new_properties = properties;
   FrameBufferProperties new_properties = properties;
   GLXContext context = NULL;
   GLXContext context = NULL;
-
-  GLXFBConfig fbconfig = choose_fbconfig(new_properties);
   XVisualInfo *visual = NULL;
   XVisualInfo *visual = NULL;
 
 
+#ifdef HAVE_GLXFBCONFIG
+  GLXFBConfig fbconfig = choose_fbconfig(new_properties);
   if (fbconfig != None) {
   if (fbconfig != None) {
     context = 
     context = 
       glXCreateNewContext(_display, fbconfig, GLX_RGBA_TYPE, share_context,
       glXCreateNewContext(_display, fbconfig, GLX_RGBA_TYPE, share_context,
                           GL_TRUE);
                           GL_TRUE);
+    if (context == NULL) {
+      fbconfig = None;
+    }
   }
   }
+#endif  // HAVE_GLXFBCONFIG
+
   if (context == NULL) {
   if (context == NULL) {
     // If we couldn't create a context with the fbconfig interface,
     // If we couldn't create a context with the fbconfig interface,
     // try falling back to the older XVisual interface.
     // try falling back to the older XVisual interface.
@@ -202,7 +207,6 @@ make_gsg(const FrameBufferProperties &properties,
 
 
     if (visual != (XVisualInfo *)NULL) {
     if (visual != (XVisualInfo *)NULL) {
       context = glXCreateContext(_display, visual, None, GL_TRUE);
       context = glXCreateContext(_display, visual, None, GL_TRUE);
-      fbconfig = None;
     }
     }
   }
   }
 
 
@@ -212,6 +216,7 @@ make_gsg(const FrameBufferProperties &properties,
     return NULL;
     return NULL;
   }
   }
 
 
+#ifdef HAVE_GLXFBCONFIG
   if (visual == (XVisualInfo *)NULL) {
   if (visual == (XVisualInfo *)NULL) {
     // If we used the fbconfig to open the context, we still need to
     // If we used the fbconfig to open the context, we still need to
     // get the associated XVisual.
     // get the associated XVisual.
@@ -222,7 +227,14 @@ make_gsg(const FrameBufferProperties &properties,
   // Now we can make a GSG.
   // Now we can make a GSG.
   PT(glxGraphicsStateGuardian) gsg = 
   PT(glxGraphicsStateGuardian) gsg = 
     new glxGraphicsStateGuardian(new_properties, share_gsg, context, 
     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();
   return gsg.p();
 }
 }
 
 
@@ -252,9 +264,14 @@ make_buffer(GraphicsStateGuardian *gsg, const string &name,
     return NULL;
     return NULL;
   }
   }
 
 
+#ifdef HAVE_GLXFBCONFIG
   return new glxGraphicsBuffer(this, gsg, name, x_size, y_size, want_texture);
   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
 //     Function: glxGraphicsPipe::choose_fbconfig
 //       Access: Private
 //       Access: Private
@@ -471,7 +488,9 @@ choose_fbconfig(FrameBufferProperties &properties) const {
 
 
   return fbconfig;
   return fbconfig;
 }
 }
+#endif  // HAVE_GLXFBCONFIG
 
 
+#ifdef HAVE_GLXFBCONFIG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: glxGraphicsPipe::try_for_fbconfig
 //     Function: glxGraphicsPipe::try_for_fbconfig
 //       Access: Private
 //       Access: Private
@@ -596,6 +615,7 @@ try_for_fbconfig(int framebuffer_mode,
 
 
   return fbconfig;
   return fbconfig;
 }
 }
+#endif  // HAVE_GLXFBCONFIG
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: glxGraphicsPipe::choose visual
 //     Function: glxGraphicsPipe::choose visual

+ 27 - 3
panda/src/glxdisplay/glxGraphicsPipe.h

@@ -32,8 +32,6 @@ typedef int Display;
 typedef int Window;
 typedef int Window;
 typedef int XErrorEvent;
 typedef int XErrorEvent;
 typedef int XVisualInfo;
 typedef int XVisualInfo;
-typedef int GLXFBConfig;
-typedef int GLXPbuffer;
 typedef int Atom;
 typedef int Atom;
 typedef int Cursor;
 typedef int Cursor;
 typedef int XIM;
 typedef int XIM;
@@ -42,10 +40,34 @@ typedef int XIC;
 #include <X11/Xlib.h>
 #include <X11/Xlib.h>
 #include <GL/glx.h>
 #include <GL/glx.h>
 
 
+#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
 // 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"
 #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
 #endif  // CPPPARSER
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -81,9 +103,11 @@ protected:
                                          int x_size, int y_size, bool want_texture);
                                          int x_size, int y_size, bool want_texture);
 
 
 private:
 private:
+#ifdef HAVE_GLXFBCONFIG
   GLXFBConfig choose_fbconfig(FrameBufferProperties &properties) const;
   GLXFBConfig choose_fbconfig(FrameBufferProperties &properties) const;
   GLXFBConfig try_for_fbconfig(int framebuffer_mode,
   GLXFBConfig try_for_fbconfig(int framebuffer_mode,
                                int want_depth_bits, int want_color_bits) const;
                                int want_depth_bits, int want_color_bits) const;
+#endif
 
 
   XVisualInfo *choose_visual(FrameBufferProperties &properties) const;
   XVisualInfo *choose_visual(FrameBufferProperties &properties) const;
   XVisualInfo *try_for_visual(int framebuffer_mode,
   XVisualInfo *try_for_visual(int framebuffer_mode,

+ 9 - 3
panda/src/glxdisplay/glxGraphicsStateGuardian.cxx

@@ -33,14 +33,20 @@ TypeHandle glxGraphicsStateGuardian::_type_handle;
 glxGraphicsStateGuardian::
 glxGraphicsStateGuardian::
 glxGraphicsStateGuardian(const FrameBufferProperties &properties,
 glxGraphicsStateGuardian(const FrameBufferProperties &properties,
                          glxGraphicsStateGuardian *share_with,
                          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),
   GLGraphicsStateGuardian(properties),
   _context(context),
   _context(context),
-  _fbconfig(fbconfig),
   _visual(visual),
   _visual(visual),
   _display(display),
   _display(display),
   _screen(screen)
   _screen(screen)
+#ifdef HAVE_GLXFBCONFIG
+  , _fbconfig(fbconfig)
+#endif  // HAVE_GLXFBCONFIG
 {
 {
   if (share_with != (glxGraphicsStateGuardian *)NULL) {
   if (share_with != (glxGraphicsStateGuardian *)NULL) {
     _prepared_objects = share_with->get_prepared_objects();
     _prepared_objects = share_with->get_prepared_objects();

+ 15 - 3
panda/src/glxdisplay/glxGraphicsStateGuardian.h

@@ -37,20 +37,32 @@
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 class glxGraphicsStateGuardian : public GLGraphicsStateGuardian {
 class glxGraphicsStateGuardian : public GLGraphicsStateGuardian {
 public:
 public:
+#ifdef HAVE_GLXFBCONFIG
   glxGraphicsStateGuardian(const FrameBufferProperties &properties,
   glxGraphicsStateGuardian(const FrameBufferProperties &properties,
                            glxGraphicsStateGuardian *share_with,
                            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();
   virtual ~glxGraphicsStateGuardian();
 
 
   bool glx_is_at_least_version(int major_version, int minor_version) const;
   bool glx_is_at_least_version(int major_version, int minor_version) const;
 
 
   GLXContext _context;
   GLXContext _context;
-  GLXFBConfig _fbconfig;
   XVisualInfo *_visual;
   XVisualInfo *_visual;
   Display *_display;
   Display *_display;
   int _screen;
   int _screen;
 
 
+#ifdef HAVE_GLXFBCONFIG
+  GLXFBConfig _fbconfig;
+#endif  // HAVE_GLXFBCONFIG
+
 protected:
 protected:
   virtual void get_gl_version();
   virtual void get_gl_version();
   virtual void get_extra_extensions();
   virtual void get_extra_extensions();

+ 6 - 0
panda/src/glxdisplay/glxGraphicsWindow.cxx

@@ -525,11 +525,15 @@ open_window() {
 
 
   Window root_window = glx_pipe->get_root();
   Window root_window = glx_pipe->get_root();
 
 
+#ifdef HAVE_GLXFBCONFIG
   if (glxgsg->_fbconfig != None) {
   if (glxgsg->_fbconfig != None) {
     setup_colormap(glxgsg->_fbconfig);
     setup_colormap(glxgsg->_fbconfig);
   } else {
   } else {
     setup_colormap(visual_info);
     setup_colormap(visual_info);
   }
   }
+#else
+  setup_colormap(visual_info);
+#endif  // HAVE_GLXFBCONFIG
 
 
   _event_mask =
   _event_mask =
     ButtonPressMask | ButtonReleaseMask |
     ButtonPressMask | ButtonReleaseMask |
@@ -681,6 +685,7 @@ set_wm_properties(const WindowProperties &properties) {
                   sizeof(protocols) / sizeof(Atom));
                   sizeof(protocols) / sizeof(Atom));
 }
 }
 
 
+#ifdef HAVE_GLXFBCONFIG
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: glxGraphicsWindow::setup_colormap
 //     Function: glxGraphicsWindow::setup_colormap
 //       Access: Private
 //       Access: Private
@@ -736,6 +741,7 @@ setup_colormap(GLXFBConfig fbconfig) {
       break;
       break;
   }
   }
 }
 }
+#endif  // HAVE_GLXFBCONFIG
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: glxGraphicsWindow::setup_colormap
 //     Function: glxGraphicsWindow::setup_colormap

+ 2 - 0
panda/src/glxdisplay/glxGraphicsWindow.h

@@ -55,7 +55,9 @@ protected:
 private:
 private:
   void set_wm_properties(const WindowProperties &properties);
   void set_wm_properties(const WindowProperties &properties);
 
 
+#ifdef HAVE_GLXFBCONFIG
   void setup_colormap(GLXFBConfig fbconfig);
   void setup_colormap(GLXFBConfig fbconfig);
+#endif  // HAVE_GLXFBCONFIG
   void setup_colormap(XVisualInfo *visual);
   void setup_colormap(XVisualInfo *visual);
   void handle_keystroke(XKeyEvent &event);
   void handle_keystroke(XKeyEvent &event);
   void handle_keypress(XKeyEvent &event);
   void handle_keypress(XKeyEvent &event);

+ 6 - 0
panda/src/glxdisplay/glxext.h

@@ -327,6 +327,12 @@ typedef struct {
 
 
 #ifndef GLX_VERSION_1_3
 #ifndef GLX_VERSION_1_3
 #define GLX_VERSION_1_3 1
 #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
 #ifdef GLX_GLXEXT_PROTOTYPES
 extern GLXFBConfig * glXGetFBConfigs (Display *, int, int *);
 extern GLXFBConfig * glXGetFBConfigs (Display *, int, int *);
 extern GLXFBConfig * glXChooseFBConfig (Display *, int, const int *, int *);
 extern GLXFBConfig * glXChooseFBConfig (Display *, int, const int *, int *);