浏览代码

Allow disabling primitive restart index. Also, better handling of unsupported shader languages.

rdb 11 年之前
父节点
当前提交
0f35480fcf
共有 3 个文件被更改,包括 54 次插入20 次删除
  1. 37 20
      panda/src/glstuff/glGraphicsStateGuardian_src.cxx
  2. 15 0
      panda/src/glstuff/glmisc_src.cxx
  3. 2 0
      panda/src/glstuff/glmisc_src.h

+ 37 - 20
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -555,26 +555,30 @@ reset() {
 #ifndef OPENGLES
 #ifndef OPENGLES
   _glPrimitiveRestartIndex = NULL;
   _glPrimitiveRestartIndex = NULL;
 
 
-  if (is_at_least_gl_version(4, 3) || has_extension("GL_ARB_ES3_compatibility")) {
+  /*if (is_at_least_gl_version(4, 3) || has_extension("GL_ARB_ES3_compatibility")) {
     // As long as we enable this, OpenGL will always use the highest possible index
     // As long as we enable this, OpenGL will always use the highest possible index
     // for a numeric type as strip cut index, which coincides with our convention.
     // for a numeric type as strip cut index, which coincides with our convention.
     // This saves us a call to glPrimitiveRestartIndex.
     // This saves us a call to glPrimitiveRestartIndex.
     glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
     glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
     _supported_geom_rendering |= Geom::GR_strip_cut_index;
     _supported_geom_rendering |= Geom::GR_strip_cut_index;
 
 
-  } else if (is_at_least_gl_version(3, 1)) {
-    glEnable(GL_PRIMITIVE_RESTART);
-    _supported_geom_rendering |= Geom::GR_strip_cut_index;
+  } else
+  */
+  if (gl_support_primitive_restart_index) {
+    if (is_at_least_gl_version(3, 1)) {
+      glEnable(GL_PRIMITIVE_RESTART);
+      _supported_geom_rendering |= Geom::GR_strip_cut_index;
 
 
-    _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)
-      get_extension_func("glPrimitiveRestartIndex");
+      _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)
+        get_extension_func("glPrimitiveRestartIndex");
 
 
-  } else if (has_extension("GL_NV_primitive_restart")) {
-    glEnable(GL_PRIMITIVE_RESTART_NV);
-    _supported_geom_rendering |= Geom::GR_strip_cut_index;
+    } else if (has_extension("GL_NV_primitive_restart")) {
+      glEnable(GL_PRIMITIVE_RESTART_NV);
+      _supported_geom_rendering |= Geom::GR_strip_cut_index;
 
 
-    _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)
-      get_extension_func("glPrimitiveRestartIndexNV");
+      _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC)
+        get_extension_func("glPrimitiveRestartIndexNV");
+    }
   }
   }
 #endif
 #endif
 
 
@@ -4357,18 +4361,31 @@ prepare_shader(Shader *se) {
   ShaderContext *result = NULL;
   ShaderContext *result = NULL;
 
 
   switch (se->get_language()) {
   switch (se->get_language()) {
-#if defined(HAVE_CG) && !defined(OPENGLES)
-  case Shader::SL_Cg:
-    result = new CLP(CgShaderContext)(this, se);
-    break;
-#endif
-
   case Shader::SL_GLSL:
   case Shader::SL_GLSL:
     if (_supports_glsl) {
     if (_supports_glsl) {
       result = new CLP(ShaderContext)(this, se);
       result = new CLP(ShaderContext)(this, se);
       break;
       break;
+    } else {
+      GLCAT.error()
+        << "Tried to load GLSL shader, but GLSL shaders not supported.\n";
+      return NULL;
     }
     }
-    // Fall through.
+
+#if defined(HAVE_CG) && !defined(OPENGLES)
+  case Shader::SL_Cg:
+    if (_supports_basic_shaders) {
+      result = new CLP(CgShaderContext)(this, se);
+      break;
+    } else {
+      GLCAT.error()
+        << "Tried to load Cg shader, but basic shaders not supported.\n";
+      return NULL;
+    }
+#else
+    GLCAT.error()
+      << "Tried to load Cg shader, but Cg support not compiled in.\n";
+    return NULL;
+#endif
 
 
   default:
   default:
     GLCAT.error()
     GLCAT.error()
@@ -5157,7 +5174,9 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z,
   }
   }
 
 
   if (uses_mipmaps && _glGenerateMipmap != NULL) {
   if (uses_mipmaps && _glGenerateMipmap != NULL) {
+    glEnable(target);
     _glGenerateMipmap(target);
     _glGenerateMipmap(target);
+    glDisable(target);
   }
   }
 
 
   gtc->_has_storage = true;
   gtc->_has_storage = true;
@@ -6668,7 +6687,6 @@ void CLP(GraphicsStateGuardian)::
 set_draw_buffer(int rbtype) {
 set_draw_buffer(int rbtype) {
 #ifndef OPENGLES  // Draw buffers not supported by OpenGL ES.
 #ifndef OPENGLES  // Draw buffers not supported by OpenGL ES.
   if (_current_fbo) {
   if (_current_fbo) {
-
     GLuint buffers[16];
     GLuint buffers[16];
     int nbuffers = 0;
     int nbuffers = 0;
     int index = 0;
     int index = 0;
@@ -6705,7 +6723,6 @@ set_draw_buffer(int rbtype) {
     _glDrawBuffers(nbuffers, buffers);
     _glDrawBuffers(nbuffers, buffers);
 
 
   } else {
   } else {
-
     switch (rbtype & RenderBuffer::T_color) {
     switch (rbtype & RenderBuffer::T_color) {
     case RenderBuffer::T_front:
     case RenderBuffer::T_front:
       glDrawBuffer(GL_FRONT);
       glDrawBuffer(GL_FRONT);

+ 15 - 0
panda/src/glstuff/glmisc_src.cxx

@@ -244,6 +244,21 @@ ConfigVariableBool gl_enable_memory_barriers
             "this off may give a slight performance increase, but you "
             "this off may give a slight performance increase, but you "
             "have to know what you're doing."));
             "have to know what you're doing."));
 
 
+ConfigVariableBool gl_vertex_array_objects
+  ("gl-vertex-array-objects", true,
+   PRC_DESC("Setting this causes Panda to make use of vertex array "
+            "objects to more efficiently switch between sets of "
+            "vertex arrays.  This only has effect when vertex-arrays "
+            "and vertex-buffers are both set.  This should usually be "
+            "true unless you suspect a bug in the implementation. "));
+
+ConfigVariableBool gl_support_primitive_restart_index
+  ("gl-support-primitive-restart-index", true,
+   PRC_DESC("Setting this causes Panda to make use of primitive "
+            "restart indices to more efficiently render line "
+            "segment primitives.  Set to false if you suspect a bug "
+            "in the driver implementation."));
+
 extern ConfigVariableBool gl_parallel_arrays;
 extern ConfigVariableBool gl_parallel_arrays;
 
 
 void CLP(init_classes)() {
 void CLP(init_classes)() {

+ 2 - 0
panda/src/glstuff/glmisc_src.h

@@ -71,6 +71,8 @@ extern ConfigVariableBool gl_dump_compiled_shaders;
 extern ConfigVariableBool gl_immutable_texture_storage;
 extern ConfigVariableBool gl_immutable_texture_storage;
 extern ConfigVariableBool gl_use_bindless_texture;
 extern ConfigVariableBool gl_use_bindless_texture;
 extern ConfigVariableBool gl_enable_memory_barriers;
 extern ConfigVariableBool gl_enable_memory_barriers;
+extern ConfigVariableBool gl_vertex_array_objects;
+extern ConfigVariableBool gl_support_primitive_restart_index;
 
 
 extern EXPCL_GL void CLP(init_classes)();
 extern EXPCL_GL void CLP(init_classes)();