Browse Source

Add GL function pointers for indirect draw

rdb 10 years ago
parent
commit
bac5401a9d

+ 12 - 0
panda/src/display/graphicsStateGuardian.I

@@ -808,6 +808,18 @@ get_supports_geometry_instancing() const {
   return _supports_geometry_instancing;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: GraphicsStateGuardian::get_supports_indirect_draw
+//       Access: Published
+//  Description: Returns true if this particular GSG supports
+//               draw calls for which the information comes from a
+//               buffer.
+////////////////////////////////////////////////////////////////////
+INLINE bool GraphicsStateGuardian::
+get_supports_indirect_draw() const {
+  return _supports_indirect_draw;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: GraphicsStateGuardian::get_supports_occlusion_query
 //       Access: Published

+ 1 - 0
panda/src/display/graphicsStateGuardian.cxx

@@ -245,6 +245,7 @@ GraphicsStateGuardian(CoordinateSystem internal_coordinate_system,
   _supports_stencil_wrap = false;
   _supports_two_sided_stencil = false;
   _supports_geometry_instancing = false;
+  _supports_indirect_draw = false;
 
   // Assume a maximum of 1 render target in absence of MRT.
   _max_color_targets = 1;

+ 2 - 0
panda/src/display/graphicsStateGuardian.h

@@ -160,6 +160,7 @@ PUBLISHED:
   INLINE bool get_supports_stencil() const;
   INLINE bool get_supports_two_sided_stencil() const;
   INLINE bool get_supports_geometry_instancing() const;
+  INLINE bool get_supports_indirect_draw() const;
 
   INLINE bool get_supports_occlusion_query() const;
   INLINE bool get_supports_timer_query() const;
@@ -538,6 +539,7 @@ protected:
   bool _supports_stencil_wrap;
   bool _supports_two_sided_stencil;
   bool _supports_geometry_instancing;
+  bool _supports_indirect_draw;
 
   int _max_color_targets;
 

+ 18 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -1757,6 +1757,24 @@ reset() {
   }
 #endif
 
+  // Check if we support indirect draw.
+  _supports_indirect_draw = false;
+#ifndef OPENGLES
+  if (is_at_least_gl_version(4, 0) || has_extension("GL_ARB_draw_indirect")) {
+    _glDrawArraysIndirect = (PFNGLDRAWARRAYSINDIRECTPROC)
+      get_extension_func("glDrawArraysIndirect");
+    _glDrawElementsIndirect = (PFNGLDRAWELEMENTSINDIRECTPROC)
+      get_extension_func("glDrawElementsIndirect");
+
+    if (_glDrawArraysIndirect == NULL || _glDrawElementsIndirect == NULL) {
+      GLCAT.warning()
+        << "Indirect draw advertised as supported by OpenGL runtime, but could not get pointers to extension functions.\n";
+    } else {
+      _supports_indirect_draw = true;
+    }
+  }
+#endif
+
 #ifdef OPENGLES_2
   // In OpenGL ES 2.x, FBO's are supported in the core.
   _supports_framebuffer_object = true;

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

@@ -763,6 +763,11 @@ public:
   PFNGLDELETEVERTEXARRAYSPROC _glDeleteVertexArrays;
   PFNGLGENVERTEXARRAYSPROC _glGenVertexArrays;
 
+#ifndef OPENGLES
+  PFNGLDRAWARRAYSINDIRECTPROC _glDrawArraysIndirect;
+  PFNGLDRAWELEMENTSINDIRECTPROC _glDrawElementsIndirect;
+#endif
+
   bool _supports_framebuffer_object;
   PFNGLISRENDERBUFFEREXTPROC _glIsRenderbuffer;
   PFNGLBINDRENDERBUFFEREXTPROC _glBindRenderbuffer;