From 0f35480fcf4bd66b89ceb96432db7c2662081ed7 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 3 Nov 2014 02:29:05 +0000 Subject: [PATCH 1/5] Allow disabling primitive restart index. Also, better handling of unsupported shader languages. --- .../glstuff/glGraphicsStateGuardian_src.cxx | 57 ++++++++++++------- panda/src/glstuff/glmisc_src.cxx | 15 +++++ panda/src/glstuff/glmisc_src.h | 2 + 3 files changed, 54 insertions(+), 20 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index cd821a60c4..98ebfcf0c8 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -555,26 +555,30 @@ reset() { #ifndef OPENGLES _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 // for a numeric type as strip cut index, which coincides with our convention. // This saves us a call to glPrimitiveRestartIndex. glEnable(GL_PRIMITIVE_RESTART_FIXED_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 @@ -4357,18 +4361,31 @@ prepare_shader(Shader *se) { ShaderContext *result = NULL; 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: if (_supports_glsl) { result = new CLP(ShaderContext)(this, se); 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: GLCAT.error() @@ -5157,7 +5174,9 @@ framebuffer_copy_to_texture(Texture *tex, int view, int z, } if (uses_mipmaps && _glGenerateMipmap != NULL) { + glEnable(target); _glGenerateMipmap(target); + glDisable(target); } gtc->_has_storage = true; @@ -6668,7 +6687,6 @@ void CLP(GraphicsStateGuardian):: set_draw_buffer(int rbtype) { #ifndef OPENGLES // Draw buffers not supported by OpenGL ES. if (_current_fbo) { - GLuint buffers[16]; int nbuffers = 0; int index = 0; @@ -6705,7 +6723,6 @@ set_draw_buffer(int rbtype) { _glDrawBuffers(nbuffers, buffers); } else { - switch (rbtype & RenderBuffer::T_color) { case RenderBuffer::T_front: glDrawBuffer(GL_FRONT); diff --git a/panda/src/glstuff/glmisc_src.cxx b/panda/src/glstuff/glmisc_src.cxx index 3c1d8a2b86..bf2163452f 100644 --- a/panda/src/glstuff/glmisc_src.cxx +++ b/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 " "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; void CLP(init_classes)() { diff --git a/panda/src/glstuff/glmisc_src.h b/panda/src/glstuff/glmisc_src.h index c57046ee27..5b2c601691 100644 --- a/panda/src/glstuff/glmisc_src.h +++ b/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_use_bindless_texture; 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)(); From ce1282c7e3c013a0e6f24a0206639d79ec1cc297 Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 4 Nov 2014 14:14:49 +0000 Subject: [PATCH 2/5] Fixes for primitive restart index stuff --- .../glstuff/glGraphicsStateGuardian_src.cxx | 45 ++++++++++++------- .../src/glstuff/glGraphicsStateGuardian_src.h | 2 + 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 98ebfcf0c8..090472bfaa 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -553,27 +553,27 @@ reset() { } #ifndef OPENGLES + _primitive_restart_gl3 = false; + _primitive_restart_nv = false; _glPrimitiveRestartIndex = NULL; - /*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 - // for a numeric type as strip cut index, which coincides with our convention. - // This saves us a call to glPrimitiveRestartIndex. - glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); - _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); + 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 + // for a numeric type as strip cut index, which coincides with our convention. + // This saves us a call to glPrimitiveRestartIndex. + glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX); + _supported_geom_rendering |= Geom::GR_strip_cut_index; + + } else if (is_at_least_gl_version(3, 1)) { + _primitive_restart_gl3 = true; _supported_geom_rendering |= Geom::GR_strip_cut_index; _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC) get_extension_func("glPrimitiveRestartIndex"); } else if (has_extension("GL_NV_primitive_restart")) { - glEnable(GL_PRIMITIVE_RESTART_NV); + _primitive_restart_nv = true; _supported_geom_rendering |= Geom::GR_strip_cut_index; _glPrimitiveRestartIndex = (PFNGLPRIMITIVERESTARTINDEXPROC) @@ -3892,10 +3892,16 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { (_supported_geom_rendering & GeomEnums::GR_strip_cut_index) != 0) { // One long triangle strip, connected by strip cut indices. #ifndef OPENGLES - if (_glPrimitiveRestartIndex != NULL) { + if (_primitive_restart_gl3) { + glEnable(GL_PRIMITIVE_RESTART); + _glPrimitiveRestartIndex(reader->get_strip_cut_index()); + + } else if (_primitive_restart_nv) { + glEnableClientState(GL_PRIMITIVE_RESTART_NV); _glPrimitiveRestartIndex(reader->get_strip_cut_index()); } -#endif +#endif // !OPENGLES + cerr << "yeahp\n"; int num_vertices = reader->get_num_vertices(); _vertices_other_pcollector.add_level(num_vertices); @@ -3911,7 +3917,7 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { get_numeric_type(reader->get_index_type()), client_pointer, _instance_count); } else -#endif +#endif // !OPENGLES { _glDrawRangeElements(GL_LINE_STRIP, reader->get_min_vertex(), @@ -3920,6 +3926,15 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { get_numeric_type(reader->get_index_type()), client_pointer); } + +#ifndef OPENGLES + if (_primitive_restart_gl3) { + glDisable(GL_PRIMITIVE_RESTART); + + } else if (_primitive_restart_nv) { + glDisableClientState(GL_PRIMITIVE_RESTART_NV); + } +#endif // !OPENGLES } else { // Send the individual line strips, stepping over the // strip-cut indices. diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.h b/panda/src/glstuff/glGraphicsStateGuardian_src.h index 3d79791f72..bd6e9efec2 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.h +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.h @@ -600,6 +600,8 @@ public: #ifndef OPENGLES PFNGLPRIMITIVERESTARTINDEXPROC _glPrimitiveRestartIndex; + bool _primitive_restart_gl3; + bool _primitive_restart_nv; #endif bool _supports_vertex_blend; From 5ee64279a433bfd4eff7f021deef3feba4dcbddd Mon Sep 17 00:00:00 2001 From: rdb Date: Tue, 4 Nov 2014 15:07:01 +0000 Subject: [PATCH 3/5] Oops, stupid debug message, how embarrassing --- panda/src/glstuff/glGraphicsStateGuardian_src.cxx | 1 - 1 file changed, 1 deletion(-) diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index 090472bfaa..6adcb3b4c0 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -3901,7 +3901,6 @@ draw_linestrips(const GeomPrimitivePipelineReader *reader, bool force) { _glPrimitiveRestartIndex(reader->get_strip_cut_index()); } #endif // !OPENGLES - cerr << "yeahp\n"; int num_vertices = reader->get_num_vertices(); _vertices_other_pcollector.add_level(num_vertices); From 980ed44a59b6a3c56818cd414047eba0990ae845 Mon Sep 17 00:00:00 2001 From: David Rose Date: Tue, 4 Nov 2014 19:16:02 +0000 Subject: [PATCH 4/5] fix py2exe support --- .../extensions_native/extension_native_helpers.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/direct/src/extensions_native/extension_native_helpers.py b/direct/src/extensions_native/extension_native_helpers.py index 8cfbe1e53d..961f8f8636 100644 --- a/direct/src/extensions_native/extension_native_helpers.py +++ b/direct/src/extensions_native/extension_native_helpers.py @@ -101,11 +101,20 @@ def Dtool_PreloadDLL(module): # Nowadays, we can compile libpandaexpress with libpanda into a # .pyd file called panda3d/core.pyd which can be imported without # any difficulty. Let's see if this is the case. -if Dtool_FindModule("panda3d.core"): - from panda3d.core import * -else: + +# In order to support things like py2exe that play games with the +# physical python files on disk, we can't entirely rely on +# Dtool_FindModule to find our panda3d.core module. However, we +# should be able to import it. To differentiate the old-style Panda +# build (with .dll's) from the new-style Panda build (with .pyd's), we +# first try to import libpandaexpress directly; if it succeeds we're +# in an old-style build, and if it fails we must be in a new-style +# build. +try: Dtool_PreloadDLL("libpandaexpress") from libpandaexpress import * +except ImportError: + from panda3d.core import * def Dtool_ObjectToDict(cls, name, obj): cls.DtoolClassDict[name] = obj; From 9f46ad7835c5068f6d57ce0f3ca80144dc480fce Mon Sep 17 00:00:00 2001 From: rdb Date: Sun, 9 Nov 2014 11:09:24 +0000 Subject: [PATCH 5/5] FreezeTool shouldn't assume that panda3d.py exists --- direct/src/showutil/FreezeTool.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/direct/src/showutil/FreezeTool.py b/direct/src/showutil/FreezeTool.py index 4f0ac57ca4..5c9afac00e 100644 --- a/direct/src/showutil/FreezeTool.py +++ b/direct/src/showutil/FreezeTool.py @@ -1383,7 +1383,7 @@ class PandaModuleFinder(modulefinder.ModuleFinder): # A special case: map a reference to the "panda3d.blah" # module into the appropriate Panda3D dll. m = getattr(panda3d, partname, None) - if m: + if m and hasattr(m, '__libraries__'): libname = m.__libraries__[-1] partname = libname fqname = libname