Browse Source

Support core-only OpenGL contexts in the default build.

This is a squashed commit of the following, as well as my own (rdb's) revisions:

commit 80662759a18607743316f75ee6aa4a63c3f8d8e6
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Thu Dec 1 15:07:29 2016 +0100

    Removed some useless fixed pipeline checks

commit 563b5dbe93b451006ddbf3797aabdda7482ef3de
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Thu Dec 1 14:19:21 2016 +0100

    Improved the LUMINANCE check system

commit 596036a8bb59d627f703bccfdc399dc31e1723a9
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Thu Dec 1 13:30:45 2016 +0100

    Removed some useless fixed pipeline checks

commit 0f7fa7cd33860c3cde1b4594731271170301b42d
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Thu Dec 1 13:26:07 2016 +0100

    Don't try to check if fixed pipeline is available before the context has been generated

commit 56ed18e29dcb0a7cb0feccd0d50038416637427f
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Thu Dec 1 13:14:49 2016 +0100

    Assuming the fixed pipeline is available in GL 3.1 contexts

commit 73075ead73be21c8ce9a468ed92eb2c8c7d548c4
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Fri Nov 4 12:59:45 2016 +0100

    Fixed errors while quering for GL_TEXTURE_LUMINANCE_SIZE and GL_TEXTURE_INTENSITY_SIZE in GL >= 4.0 core profile contexts

commit 3f799ed20be22f6f82de13445c5f9515a424ef9f
Author: Jose Luis Cercos Pita <[email protected]>
Date:   Fri Dec 16 10:01:03 2016 +0100

    Added fixed functions pipeline support check at runtime

Closes: 128
Jose Luis Cercos Pita 8 years ago
parent
commit
aa00138b34

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

@@ -538,6 +538,14 @@ get_supports_depth_stencil() const {
   return _supports_depth_stencil;
   return _supports_depth_stencil;
 }
 }
 
 
+/**
+ * Returns true if this particular GSG supports luminance textures.
+ */
+INLINE bool GraphicsStateGuardian::
+get_supports_luminance_texture() const {
+  return _supports_luminance_texture;
+}
+
 /**
 /**
  * Returns true if this particular GSG supports the filter mode FT_shadow for
  * Returns true if this particular GSG supports the filter mode FT_shadow for
  * depth textures.
  * depth textures.

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

@@ -253,6 +253,9 @@ GraphicsStateGuardian(CoordinateSystem internal_coordinate_system,
   _supports_geometry_instancing = false;
   _supports_geometry_instancing = false;
   _supports_indirect_draw = false;
   _supports_indirect_draw = false;
 
 
+  // We are safe assuming it has luminance support
+  _supports_luminance_texture = true;
+
   // Assume a maximum of 1 render target in absence of MRT.
   // Assume a maximum of 1 render target in absence of MRT.
   _max_color_targets = 1;
   _max_color_targets = 1;
   _supports_dual_source_blending = false;
   _supports_dual_source_blending = false;

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

@@ -154,6 +154,7 @@ PUBLISHED:
   INLINE bool get_supports_generate_mipmap() const;
   INLINE bool get_supports_generate_mipmap() const;
   INLINE bool get_supports_depth_texture() const;
   INLINE bool get_supports_depth_texture() const;
   INLINE bool get_supports_depth_stencil() const;
   INLINE bool get_supports_depth_stencil() const;
+  INLINE bool get_supports_luminance_texture() const;
   INLINE bool get_supports_shadow_filter() const;
   INLINE bool get_supports_shadow_filter() const;
   INLINE bool get_supports_sampler_objects() const;
   INLINE bool get_supports_sampler_objects() const;
   INLINE bool get_supports_basic_shaders() const;
   INLINE bool get_supports_basic_shaders() const;
@@ -203,6 +204,7 @@ PUBLISHED:
   MAKE_PROPERTY(supports_generate_mipmap, get_supports_generate_mipmap);
   MAKE_PROPERTY(supports_generate_mipmap, get_supports_generate_mipmap);
   MAKE_PROPERTY(supports_depth_texture, get_supports_depth_texture);
   MAKE_PROPERTY(supports_depth_texture, get_supports_depth_texture);
   MAKE_PROPERTY(supports_depth_stencil, get_supports_depth_stencil);
   MAKE_PROPERTY(supports_depth_stencil, get_supports_depth_stencil);
+  MAKE_PROPERTY(supports_luminance_texture, get_supports_luminance_texture);
   MAKE_PROPERTY(supports_shadow_filter, get_supports_shadow_filter);
   MAKE_PROPERTY(supports_shadow_filter, get_supports_shadow_filter);
   MAKE_PROPERTY(supports_sampler_objects, get_supports_sampler_objects);
   MAKE_PROPERTY(supports_sampler_objects, get_supports_sampler_objects);
   MAKE_PROPERTY(supports_basic_shaders, get_supports_basic_shaders);
   MAKE_PROPERTY(supports_basic_shaders, get_supports_basic_shaders);
@@ -597,6 +599,7 @@ protected:
   bool _supports_generate_mipmap;
   bool _supports_generate_mipmap;
   bool _supports_depth_texture;
   bool _supports_depth_texture;
   bool _supports_depth_stencil;
   bool _supports_depth_stencil;
+  bool _supports_luminance_texture;
   bool _supports_shadow_filter;
   bool _supports_shadow_filter;
   bool _supports_sampler_objects;
   bool _supports_sampler_objects;
   bool _supports_basic_shaders;
   bool _supports_basic_shaders;

+ 12 - 7
panda/src/glstuff/glCgShaderContext_src.cxx

@@ -145,7 +145,7 @@ CLP(CgShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderConte
 
 
     if (cgGetParameterBaseResource(p) == CG_ATTR0) {
     if (cgGetParameterBaseResource(p) == CG_ATTR0) {
       // The Cg toolkit claims that it is bound to a generic vertex attribute.
       // The Cg toolkit claims that it is bound to a generic vertex attribute.
-      if (_glsl_program != 0) {
+      if (_glgsg->has_fixed_function_pipeline() && _glsl_program != 0) {
         // This is where the Cg glslv compiler lies, making the stupid
         // This is where the Cg glslv compiler lies, making the stupid
         // assumption that we're using an NVIDIA card where generic attributes
         // assumption that we're using an NVIDIA card where generic attributes
         // are aliased with conventional vertex attributes.  Instead, it
         // are aliased with conventional vertex attributes.  Instead, it
@@ -246,7 +246,7 @@ CLP(CgShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderConte
       // A conventional texture coordinate set.
       // A conventional texture coordinate set.
       loc = CA_texcoord + cgGetParameterResourceIndex(p);
       loc = CA_texcoord + cgGetParameterResourceIndex(p);
 
 
-    } else {
+    } else if (_glgsg->has_fixed_function_pipeline()) {
       // Some other conventional vertex attribute.
       // Some other conventional vertex attribute.
       switch (res) {
       switch (res) {
       case CG_POSITION0:
       case CG_POSITION0:
@@ -276,6 +276,14 @@ CLP(CgShaderContext)(CLP(GraphicsStateGuardian) *glgsg, Shader *s) : ShaderConte
         GLCAT.error(false) << ".\n";
         GLCAT.error(false) << ".\n";
         loc = CA_unknown;
         loc = CA_unknown;
       }
       }
+    } else {
+      GLCAT.error()
+        << "Cg varying " << cgGetParameterName(p);
+      if (cgGetParameterSemantic(p)) {
+        GLCAT.error(false) << " : " << cgGetParameterSemantic(p);
+      }
+      GLCAT.error(false) << " is bound to a conventional vertex attribute, "
+                            "but the compatibility profile is not enabled.\n";
     }
     }
 
 
 #ifndef NDEBUG
 #ifndef NDEBUG
@@ -916,8 +924,7 @@ update_shader_vertex_arrays(ShaderContext *prev, bool force) {
       } else {
       } else {
         // There is no vertex column with this name; disable the attribute
         // There is no vertex column with this name; disable the attribute
         // array.
         // array.
-#ifdef SUPPORT_FIXED_FUNCTION
-        if (p == 0) {
+        if (_glgsg->has_fixed_function_pipeline() && p == 0) {
           // NOTE: if we disable attribute 0 in compatibility profile, the
           // NOTE: if we disable attribute 0 in compatibility profile, the
           // object will disappear.  In GLSL we fix this by forcing the vertex
           // object will disappear.  In GLSL we fix this by forcing the vertex
           // column to be at 0, but we don't have control over that with Cg.
           // column to be at 0, but we don't have control over that with Cg.
@@ -930,9 +937,7 @@ update_shader_vertex_arrays(ShaderContext *prev, bool force) {
             _glgsg->_glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
             _glgsg->_glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
           }
           }
 
 
-        } else
-#endif  // SUPPORT_FIXED_FUNCTION
-        if (p >= 0) {
+        } else if (p >= 0) {
           _glgsg->disable_vertex_attrib_array(p);
           _glgsg->disable_vertex_attrib_array(p);
 
 
           if (p == _color_attrib_index) {
           if (p == _color_attrib_index) {

+ 4 - 2
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -1165,8 +1165,10 @@ attach_tex(int layer, int view, Texture *attach, GLenum attachpoint) {
   glgsg->apply_texture(gtc);
   glgsg->apply_texture(gtc);
 
 
 #if !defined(OPENGLES) && defined(SUPPORT_FIXED_FUNCTION)
 #if !defined(OPENGLES) && defined(SUPPORT_FIXED_FUNCTION)
-  GLclampf priority = 1.0f;
-  glPrioritizeTextures(1, &gtc->_index, &priority);
+  if (glgsg->has_fixed_function_pipeline()) {
+    GLclampf priority = 1.0f;
+    glPrioritizeTextures(1, &gtc->_index, &priority);
+  }
 #endif
 #endif
 
 
 #ifndef OPENGLES
 #ifndef OPENGLES

+ 28 - 1
panda/src/glstuff/glGraphicsStateGuardian_src.I

@@ -130,6 +130,33 @@ get_gl_version_minor() const {
   return _gl_version_minor;
   return _gl_version_minor;
 }
 }
 
 
+/**
+ * Returns whether a core profile or a compatibility mode is considered.
+ */
+/*INLINE bool CLP(GraphicsStateGuardian)::
+has_core_profile() const {
+  return _core_profile;
+}*/
+
+/**
+ * Returns whether the fixed function pipeline is supported.
+ */
+INLINE bool CLP(GraphicsStateGuardian)::
+has_fixed_function_pipeline() const {
+#ifndef SUPPORT_FIXED_FUNCTION
+  return false;
+#elif defined(OPENGLES_1)
+  return true;
+#elif defined(OPENGLES)
+  return false;
+#else
+  // Otherwise, we can just check whether we are using a core profile or a
+  // compatibility mode. The variable _core_profile is already taking into
+  // account if a GL < 3.2 is considered (becoming false)
+  return !_core_profile;
+#endif
+}
+
 /**
 /**
  * Calls glFinish() if the config variable gl-finish is set True.
  * Calls glFinish() if the config variable gl-finish is set True.
  */
  */
@@ -363,7 +390,7 @@ enable_line_smooth(bool val) {
 INLINE void CLP(GraphicsStateGuardian)::
 INLINE void CLP(GraphicsStateGuardian)::
 enable_point_smooth(bool val) {
 enable_point_smooth(bool val) {
 #ifdef SUPPORT_FIXED_FUNCTION
 #ifdef SUPPORT_FIXED_FUNCTION
-  if (_point_smooth_enabled != val) {
+  if (has_fixed_function_pipeline() && _point_smooth_enabled != val) {
     _state_mask.clear_bit(TransparencyAttrib::get_class_slot());
     _state_mask.clear_bit(TransparencyAttrib::get_class_slot());
     _point_smooth_enabled = val;
     _point_smooth_enabled = val;
     if (val) {
     if (val) {

File diff suppressed because it is too large
+ 309 - 215
panda/src/glstuff/glGraphicsStateGuardian_src.cxx


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

@@ -399,6 +399,7 @@ public:
   INLINE const string &get_gl_version() const;
   INLINE const string &get_gl_version() const;
   INLINE int get_gl_version_major() const;
   INLINE int get_gl_version_major() const;
   INLINE int get_gl_version_minor() const;
   INLINE int get_gl_version_minor() const;
+  INLINE bool has_fixed_function_pipeline() const;
 
 
   virtual void set_state_and_transform(const RenderState *state,
   virtual void set_state_and_transform(const RenderState *state,
                                        const TransformState *transform);
                                        const TransformState *transform);
@@ -719,6 +720,11 @@ protected:
 
 
   pset<string> _extensions;
   pset<string> _extensions;
 
 
+#ifndef OPENGLES
+  // True for non-compatibility GL 3.2+ contexts.
+  bool _core_profile;
+#endif
+
 public:
 public:
   bool _supports_point_parameters;
   bool _supports_point_parameters;
   PFNGLPOINTPARAMETERFVPROC _glPointParameterfv;
   PFNGLPOINTPARAMETERFVPROC _glPointParameterfv;

Some files were not shown because too many files changed in this diff