Browse Source

move extensions checking from wgldisplay to glstuff

David Rose 22 years ago
parent
commit
7e1501fd18

+ 111 - 15
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -48,6 +48,8 @@
 #include "nodePath.h"
 #include "dcast.h"
 #include "pvector.h"
+#include "vector_string.h"
+#include "string_utils.h"
 
 #ifdef DO_PSTATS
 #include "pStatTimer.h"
@@ -417,6 +419,17 @@ reset() {
     if(GLCAT.is_debug())
         GLCAT.debug() << "frame buffer depth < 8bits channel, enabling dithering\n";
   }
+
+  // Output the vendor and version strings.
+  show_gl_string("GL_VENDOR", GL_VENDOR);
+  show_gl_string("GL_RENDERER", GL_RENDERER);
+  show_gl_string("GL_VERSION", GL_VERSION);
+
+  // Save the extensions tokens.
+  save_extensions((const char *)glGetString(GL_EXTENSIONS));
+  get_extra_extensions();
+  report_extensions();
+
   report_gl_errors();
 }
 
@@ -1577,12 +1590,12 @@ draw_sphere(GeomSphere *geom, GeomContext *) {
   // Draw overall
   issuer.issue_color(G_OVERALL, ci);
 
-  GLUquadricObj *sph = gluNewQuadric();
-  gluQuadricNormals(sph, wants_normals() ? (GLenum)GLU_SMOOTH : (GLenum)GLU_NONE);
-  gluQuadricTexture(sph, wants_texcoords() ? (GLenum)GL_TRUE : (GLenum)GL_FALSE);
-  gluQuadricOrientation(sph, (GLenum)GLU_OUTSIDE);
-  gluQuadricDrawStyle(sph, (GLenum)GLU_FILL);
-  //gluQuadricDrawStyle(sph, (GLenum)GLU_LINE);
+  GLUquadricObj *sph = GLP(uNewQuadric)();
+  GLP(uQuadricNormals)(sph, wants_normals() ? (GLenum)GLU_SMOOTH : (GLenum)GLU_NONE);
+  GLP(uQuadricTexture)(sph, wants_texcoords() ? (GLenum)GL_TRUE : (GLenum)GL_FALSE);
+  GLP(uQuadricOrientation)(sph, (GLenum)GLU_OUTSIDE);
+  GLP(uQuadricDrawStyle)(sph, (GLenum)GLU_FILL);
+  //GLP(uQuadricDrawStyle)(sph, (GLenum)GLU_LINE);
 
   for (int i = 0; i < nprims; i++) {
     // Draw per primitive
@@ -1597,7 +1610,7 @@ draw_sphere(GeomSphere *geom, GeomContext *) {
     LVector3f v = edge - center;
     float r = sqrt(dot(v, v));
 
-    // Since gluSphere doesn't have a center parameter, we have to use
+    // Since GLP(uSphere) doesn't have a center parameter, we have to use
     // a matrix transform.
 
     GLP(MatrixMode)(GL_MODELVIEW);
@@ -1605,13 +1618,13 @@ draw_sphere(GeomSphere *geom, GeomContext *) {
     GLP(MultMatrixf)(LMatrix4f::translate_mat(center).get_data());
 
     // Now render the sphere using GLU calls.
-    gluSphere(sph, r, 16, 10);
+    GLP(uSphere)(sph, r, 16, 10);
 
     GLP(MatrixMode)(GL_MODELVIEW);
     GLP(PopMatrix)();
   }
 
-  gluDeleteQuadric(sph);
+  GLP(uDeleteQuadric)(sph);
   report_gl_errors();
   DO_PSTATS_STUFF(_draw_primitive_pcollector.stop());
 }
@@ -2621,7 +2634,7 @@ report_errors_loop(int line, const char *source_file, GLenum error_code) {
   static const int max_gl_errors_reported = 20;
   int count = 0;
   while ((count < max_gl_errors_reported) && (error_code != GL_NO_ERROR)) {
-    const GLubyte *error_string = gluErrorString(error_code);
+    const GLubyte *error_string = GLP(uErrorString)(error_code);
     if (error_string != (const GLubyte *)NULL) {
       GLCAT.error()
         << "at " << line << " of " << source_file << ": " 
@@ -2637,6 +2650,89 @@ report_errors_loop(int line, const char *source_file, GLenum error_code) {
 #endif
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::show_gl_string
+//       Access: Protected
+//  Description: Outputs the result of glGetString() on the indicated
+//               tag.
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsStateGuardian)::
+show_gl_string(const string &name, GLenum id) {
+  if (GLCAT.is_debug()) {
+    const GLubyte *text = GLP(GetString)(id);
+    if (text == (const GLubyte *)NULL) {
+      GLCAT.debug()
+        << "Unable to query " << name << "\n";
+    } else {
+      GLCAT.debug()
+        << name << " = " << (const char *)text << "\n";
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::save_extensions
+//       Access: Protected
+//  Description: Separates the string returned by GL_EXTENSIONS (or
+//               glx or wgl extensions) into its individual tokens
+//               and saves them in the _extensions member.
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsStateGuardian)::
+save_extensions(const char *extensions) {
+  if (extensions != (const char *)NULL) {
+    vector_string tokens;
+    extract_words(extensions, tokens);
+    
+    vector_string::iterator ti;
+    for (ti = tokens.begin(); ti != tokens.end(); ++ti) {
+      _extensions.insert(*ti);
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::get_extra_extensions
+//       Access: Protected, Virtual
+//  Description: This may be redefined by a derived class (e.g. glx or
+//               wgl) to get whatever further extensions strings may
+//               be appropriate to that interface, in addition to the
+//               GL extension strings return by glGetString().
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsStateGuardian)::
+get_extra_extensions() {
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::report_extensions
+//       Access: Protected
+//  Description: Outputs the list of GL extensions to notify, if debug
+//               mode is enabled.
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsStateGuardian)::
+report_extensions() const {
+  if (GLCAT.is_debug()) {
+    GLCAT.debug()
+      << "GL Extensions:\n";
+    pset<string>::const_iterator ei;
+    for (ei = _extensions.begin(); ei != _extensions.end(); ++ei) {
+      GLCAT.debug() << (*ei) << "\n";
+    }
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: GLGraphicsStateGuardian::has_extension
+//       Access: Protected
+//  Description: Returns true if the indicated extension is reported
+//               by the GL system, false otherwise.  The extension
+//               name is case-sensitive.
+////////////////////////////////////////////////////////////////////
+bool CLP(GraphicsStateGuardian)::
+has_extension(const string &extension) const {
+  return (_extensions.find(extension) != _extensions.end());
+}
+
+
 ////////////////////////////////////////////////////////////////////
 //     Function: CLP(GraphicsStateGuardian)::set_draw_buffer
 //       Access: Protected
@@ -2905,7 +3001,7 @@ apply_texture_immediate(Texture *tex) {
       } else 
 #endif
         {
-          gluBuild2DMipmaps(GL_TEXTURE_2D, internal_format,
+          GLP(uBuild2DMipmaps)(GL_TEXTURE_2D, internal_format,
                             xsize, ysize,
                             external_format, type, image);
 #ifndef NDEBUG
@@ -2929,7 +3025,7 @@ apply_texture_immediate(Texture *tex) {
   // want to give explict error for texture creation failure
   GLenum error_code = GLP(GetError)();
   if(error_code != GL_NO_ERROR) {
-    const GLubyte *error_string = gluErrorString(error_code);
+    const GLubyte *error_string = GLP(uErrorString)(error_code);
     GLCAT.error() << "GL texture creation failed for " << tex->get_name() << 
                         ((error_string != (const GLubyte *)NULL) ? " : " : "") << endl;
   }
@@ -2981,7 +3077,7 @@ draw_texture(TextureContext *tc, const DisplayRegion *dr) {
   GLP(MatrixMode)(GL_PROJECTION);
   GLP(PushMatrix)();
   GLP(LoadIdentity)();
-  gluOrtho2D(0, 1, 0, 1);
+  GLP(uOrtho2D)(0, 1, 0, 1);
 
   float txl, txr, tyt, tyb;
   txl = tyb = 0.0f;
@@ -3089,8 +3185,8 @@ draw_pixel_buffer(PixelBuffer *pb, const DisplayRegion *dr) {
   GLP(MatrixMode)( GL_PROJECTION );
   GLP(PushMatrix)();
   GLP(LoadIdentity)();
-  gluOrtho2D(0, props.get_x_size(),
-             0, props.get_y_size());
+  GLP(uOrtho2D)(0, props.get_x_size(),
+                0, props.get_y_size());
 
 #ifdef GSG_VERBOSE
   GLCAT.debug()

+ 9 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.h

@@ -29,6 +29,7 @@
 #include "pointerToArray.h"
 #include "fog.h"
 #include "graphicsWindow.h"
+#include "pset.h"
 
 class PlaneNode;
 class Light;
@@ -130,6 +131,12 @@ public:
 protected:
   static void report_errors_loop(int line, const char *source_file, 
                                  GLenum error_code);
+  void show_gl_string(const string &name, GLenum id);
+  void save_extensions(const char *extensions);
+  virtual void get_extra_extensions();
+  void report_extensions() const;
+  bool has_extension(const string &extension) const;
+
   virtual bool slot_new_light(int light_id);
   virtual void enable_lighting(bool enable);
   virtual void set_ambient_light(const Colorf &color);
@@ -295,6 +302,8 @@ protected:
 
   int _pass_number;
 
+  pset<string> _extensions;
+
 public:
   static GraphicsStateGuardian *
   make_GlGraphicsStateGuardian(const FactoryParams &params);

+ 2 - 5
panda/src/glxdisplay/glxGraphicsPipe.cxx

@@ -183,11 +183,8 @@ make_gsg(const FrameBufferProperties &properties) {
 
   // Now we can make a GSG.
   PT(glxGraphicsStateGuardian) gsg = 
-    new glxGraphicsStateGuardian(new_properties);
-  gsg->_context = context;
-  gsg->_fbconfig = fbconfig;
-  gsg->_display = _display;
-
+    new glxGraphicsStateGuardian(new_properties, context, fbconfig,
+                                 _display, _screen);
   return gsg.p();
 }
 

+ 21 - 4
panda/src/glxdisplay/glxGraphicsStateGuardian.cxx

@@ -27,11 +27,15 @@ TypeHandle glxGraphicsStateGuardian::_type_handle;
 //  Description:
 ////////////////////////////////////////////////////////////////////
 glxGraphicsStateGuardian::
-glxGraphicsStateGuardian(const FrameBufferProperties &properties) : 
-  GLGraphicsStateGuardian(properties)
+glxGraphicsStateGuardian(const FrameBufferProperties &properties,
+                         GLXContext context, GLXFBConfig fbconfig,
+                         Display *display, int screen) :
+  GLGraphicsStateGuardian(properties),
+  _context(context),
+  _fbconfig(fbconfig),
+  _display(display),
+  _screen(screen)
 {
-  _context = (GLXContext)NULL;
-  _display = NULL;
 }
 
 ////////////////////////////////////////////////////////////////////
@@ -46,3 +50,16 @@ glxGraphicsStateGuardian::
     _context = (GLXContext)NULL;
   }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: glxGraphicsStateGuardian::get_extra_extensions
+//       Access: Protected, Virtual
+//  Description: This may be redefined by a derived class (e.g. glx or
+//               wgl) to get whatever further extensions strings may
+//               be appropriate to that interface, in addition to the
+//               GL extension strings return by glGetString().
+////////////////////////////////////////////////////////////////////
+void glxGraphicsStateGuardian::
+get_extra_extensions() {
+  save_extensions(glXQueryExtensionsString(_display, _screen));
+}

+ 7 - 1
panda/src/glxdisplay/glxGraphicsStateGuardian.h

@@ -31,12 +31,18 @@
 ////////////////////////////////////////////////////////////////////
 class glxGraphicsStateGuardian : public GLGraphicsStateGuardian {
 public:
-  glxGraphicsStateGuardian(const FrameBufferProperties &properties);
+  glxGraphicsStateGuardian(const FrameBufferProperties &properties,
+                           GLXContext context, GLXFBConfig fbconfig,
+                           Display *display, int screen);
   virtual ~glxGraphicsStateGuardian();
 
   GLXContext _context;
   GLXFBConfig _fbconfig;
   Display *_display;
+  int _screen;
+
+protected:
+  virtual void get_extra_extensions();
 
 public:
   static TypeHandle get_class_type() {

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

@@ -413,6 +413,7 @@ open_window() {
 
   XVisualInfo *visual_info = 
     glXGetVisualFromFBConfig(_display, glxgsg->_fbconfig);
+
   if (visual_info == NULL) {
     // No X visual for this fbconfig; how can we open the window?
     glxdisplay_cat.error()

+ 22 - 67
panda/src/wgldisplay/wglGraphicsStateGuardian.cxx

@@ -62,34 +62,8 @@ void wglGraphicsStateGuardian::
 reset() {
   GLGraphicsStateGuardian::reset();
 
-  // Output the vendor and version strings.
-  show_gl_string("GL_VENDOR", GL_VENDOR);
-  show_gl_string("GL_RENDERER", GL_RENDERER);
-  show_gl_string("GL_VERSION", GL_VERSION);
-
-  // Save the extensions tokens.
-  save_extensions((const char *)glGetString(GL_EXTENSIONS));
-
-  // Also save the tokens listed by wglGetExtensionsString.  This is a
-  // little trickier, since the query function is itself an extension.
-  typedef const GLubyte *(*wglGetExtensionsStringEXT_proc)(void);
-  wglGetExtensionsStringEXT_proc wglGetExtensionsStringEXT = 
-    (wglGetExtensionsStringEXT_proc)wglGetProcAddress("wglGetExtensionsStringEXT");
-  if (wglGetExtensionsStringEXT != NULL) {
-    save_extensions((const char *)wglGetExtensionsStringEXT());
-  }
-
-  if (wgldisplay_cat.is_debug()) {
-    wgldisplay_cat.debug()
-      << "GL Extensions:\n";
-    pset<string>::const_iterator ei;
-    for (ei = _extensions.begin(); ei != _extensions.end(); ++ei) {
-      wgldisplay_cat.debug() << (*ei) << "\n";
-    }
-  }
-
-  _supports_pbuffer = (_extensions.count("WGL_ARB_pbuffer") != 0);
-  _supports_pixel_format = (_extensions.count("WGL_ARB_pixel_format") != 0);
+  _supports_pbuffer = has_extension("WGL_ARB_pbuffer");
+  _supports_pixel_format = has_extension("WGL_ARB_pixel_format");
 
   _wglCreatePbufferARB = 
     (wglCreatePbufferARB_proc)wglGetProcAddress("wglCreatePbufferARB");
@@ -132,6 +106,26 @@ reset() {
   }
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: wglGraphicsStateGuardian::get_extra_extensions
+//       Access: Protected, Virtual
+//  Description: This may be redefined by a derived class (e.g. glx or
+//               wgl) to get whatever further extensions strings may
+//               be appropriate to that interface, in addition to the
+//               GL extension strings return by glGetString().
+////////////////////////////////////////////////////////////////////
+void wglGraphicsStateGuardian::
+get_extra_extensions() {
+  // This is a little bit tricky, since the query function is itself
+  // an extension.
+  typedef const GLubyte *(*wglGetExtensionsStringEXT_proc)(void);
+  wglGetExtensionsStringEXT_proc wglGetExtensionsStringEXT = 
+    (wglGetExtensionsStringEXT_proc)wglGetProcAddress("wglGetExtensionsStringEXT");
+  if (wglGetExtensionsStringEXT != NULL) {
+    save_extensions((const char *)wglGetExtensionsStringEXT());
+  }
+}
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: wglGraphicsStateGuardian::make_context
@@ -156,42 +150,3 @@ make_context(HDC hdc) {
     return;
   }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsStateGuardian::show_gl_string
-//       Access: Private
-//  Description: Outputs the result of glGetString() on the indicated
-//               tag.
-////////////////////////////////////////////////////////////////////
-void wglGraphicsStateGuardian::
-show_gl_string(const string &name, GLenum id) {
-  if (wgldisplay_cat.is_debug()) {
-    const GLubyte *text = glGetString(id);
-    if (text == (const GLubyte *)NULL) {
-      wgldisplay_cat.debug()
-        << "Unable to query " << name << "\n";
-    } else {
-      wgldisplay_cat.debug()
-        << name << " = " << (const char *)text << "\n";
-    }
-  }
-}
-
-////////////////////////////////////////////////////////////////////
-//     Function: wglGraphicsStateGuardian::save_extensions
-//       Access: Private
-//  Description: Separates the string returned by GL_EXTENSIONS or
-//               wglGetExtensionsStringEXT into its individual tokens
-//               and saves them in the _extensions member.
-////////////////////////////////////////////////////////////////////
-void wglGraphicsStateGuardian::
-save_extensions(const char *extensions) {
-  vector_string tokens;
-  extract_words(extensions, tokens);
-
-  vector_string::iterator ti;
-  for (ti = tokens.begin(); ti != tokens.end(); ++ti) {
-    _extensions.insert(*ti);
-  }
-}
-

+ 3 - 4
panda/src/wgldisplay/wglGraphicsStateGuardian.h

@@ -40,10 +40,11 @@ public:
 
   virtual void reset();
 
+protected:
+  virtual void get_extra_extensions();
+
 private:
   void make_context(HDC hdc);
-  void show_gl_string(const string &name, GLenum id);
-  void save_extensions(const char *extensions);
 
   // All windows that share a particular GL context must also share
   // the same pixel format; therefore, we store the pixel format
@@ -53,8 +54,6 @@ private:
   bool _made_context;
   HGLRC _context;
 
-  pset<string> _extensions;
-
 public:
   bool _supports_pbuffer;