Browse Source

display: Move shader capability checking from glGSG to Shader

rdb 5 years ago
parent
commit
5023951d06

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

@@ -737,6 +737,14 @@ set_shader_model(ShaderModel shader_model) {
   }
 }
 
+/**
+ * Returns a bitmask of the supported shader capabilities.
+ */
+INLINE int GraphicsStateGuardian::
+get_supported_shader_capabilities() const {
+  return _supported_shader_caps;
+}
+
 /**
  * Returns true if this particular GSG can implement (or would prefer to
  * implement) set color and/or color scale using materials and/or ambient

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

@@ -227,6 +227,9 @@ PUBLISHED:
   INLINE void set_shader_model(ShaderModel shader_model);
   MAKE_PROPERTY(shader_model, get_shader_model, set_shader_model);
 
+  INLINE int get_supported_shader_capabilities() const;
+  MAKE_PROPERTY(supported_shader_capabilities, get_supported_shader_capabilities);
+
   virtual int get_supported_geom_rendering() const;
 
   INLINE bool get_color_scale_via_lighting() const;

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

@@ -6231,16 +6231,6 @@ prepare_shader(Shader *se) {
 
 #ifndef OPENGLES_1
   if (_supports_glsl) {
-    int unsupported_caps = se->get_used_capabilities() & ~_supported_shader_caps;
-    if (unsupported_caps != 0) {
-      std::ostream &out = GLCAT.error()
-        << "Cannot load shader because the graphics back-end does not support "
-           "these capabilities: ";
-
-      ShaderModule::output_capabilities(out, unsupported_caps);
-      out << std::endl;
-    }
-
     push_group_marker(std::string("Prepare Shader ") + se->get_debug_name());
     ShaderContext *result = new CLP(ShaderContext)(this, se);
     pop_group_marker();

+ 17 - 0
panda/src/gobj/shader.cxx

@@ -2805,6 +2805,23 @@ prepare_now(PreparedGraphicsObjects *prepared_objects,
     return (*ci).second;
   }
 
+  int supported_caps = gsg->get_supported_shader_capabilities();
+  int unsupported_caps = _used_caps & ~supported_caps;
+  if (unsupported_caps != 0) {
+    std::ostream &out = shader_cat.error()
+      << "Cannot load shader because the graphics back-end does not support ";
+
+    if (supported_caps == 0) {
+      out << "shaders.";
+    } else {
+      out << "these capabilities: ";
+      ShaderModule::output_capabilities(out, unsupported_caps);
+    }
+    out << std::endl;
+
+    return nullptr;
+  }
+
   ShaderContext *tc = prepared_objects->prepare_shader_now(this, gsg);
   _contexts[prepared_objects] = tc;
 

+ 1 - 0
panda/src/gsgbase/graphicsStateGuardianBase.h

@@ -120,6 +120,7 @@ PUBLISHED:
   virtual bool get_supports_compressed_texture_format(int compression_mode) const=0;
 
   virtual bool get_supports_multisample() const=0;
+  virtual int get_supported_shader_capabilities() const=0;
   virtual int get_supported_geom_rendering() const=0;
   virtual bool get_supports_shadow_filter() const=0;