Просмотр исходного кода

Added get_load_error function. Needed to know if the file was properly loaded or not before using a shader.

aignacio_sf 20 лет назад
Родитель
Сommit
ffbde58774
3 измененных файлов с 34 добавлено и 20 удалено
  1. 14 4
      panda/src/pgraph/shader.I
  2. 9 7
      panda/src/pgraph/shader.cxx
  3. 11 9
      panda/src/pgraph/shader.h

+ 14 - 4
panda/src/pgraph/shader.I

@@ -30,7 +30,7 @@ get_file() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::get_body
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE const string &Shader::
 get_body() const {
@@ -40,7 +40,7 @@ get_body() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::get_name
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE const string &Shader::
 get_name() const {
@@ -50,17 +50,27 @@ get_name() const {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::get_loaded
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE bool Shader::
 get_loaded() const {
   return _loaded;
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: Shader::get_load_error
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE bool Shader::
+get_load_error() const {
+  return _load_error;
+}
+
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::get_preprocessor
 //       Access: Published
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 INLINE int Shader::
 get_preprocessor() const {

+ 9 - 7
panda/src/pgraph/shader.cxx

@@ -26,16 +26,17 @@ Shader::MakeTable Shader::_make_table;
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::Constructor
 //       Access: Private
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 Shader::
 Shader() {
+  this -> _load_error = false;
 }
 
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::Destructor
 //       Access: Private
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 Shader::
 ~Shader() {
@@ -51,7 +52,7 @@ Shader::
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::load
 //       Access: Published, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 CPT(Shader) Shader::
 load(const string &file, int preprocessor) {
@@ -61,7 +62,7 @@ load(const string &file, int preprocessor) {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::load
 //       Access: Published, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 CPT(Shader) Shader::
 load(const Filename &file, int preprocessor) {
@@ -80,6 +81,7 @@ load(const Filename &file, int preprocessor) {
   if (!vfs->read_file(file, result->_body, true)) {
     cerr << "Could not read shader file: " << file << "\n";
     result->_body = "";
+    result->_load_error = true;
   }
   _load_table[key] = result;
   return result;
@@ -88,7 +90,7 @@ load(const Filename &file, int preprocessor) {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::make
 //       Access: Published, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 CPT(Shader) Shader::
 make(const string &body, int preprocessor) {
@@ -116,7 +118,7 @@ make(const string &body, int preprocessor) {
 //               shader text in Cg, GLSL, HLSL, or whatever.  The
 //               macro preprocessor will be able to query the RenderState
 //               and generate different shader code for different states.
-//               
+//
 //               The macroexpansion of the shader is stored in an object
 //               of class ShaderExpansion.  This is somewhat expensive
 //               to generate, so the ShaderExpansion is cached inside the
@@ -153,7 +155,7 @@ macroexpand(const RenderState *context) const {
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::register_with_read_factory
 //       Access: Public, Static
-//  Description: 
+//  Description:
 ////////////////////////////////////////////////////////////////////
 void Shader::
 register_with_read_factory() {

+ 11 - 9
panda/src/pgraph/shader.h

@@ -28,7 +28,7 @@ class ShaderExpansion;
 
 ////////////////////////////////////////////////////////////////////
 //       Class : Shader
-// Description : 
+// Description :
 ////////////////////////////////////////////////////////////////////
 
 class EXPCL_PANDA Shader: public TypedWritableReferenceCount {
@@ -36,37 +36,39 @@ PUBLISHED:
   static CPT(Shader) load(const Filename &file, int preprocessor=0);
   static CPT(Shader) load(const string &file,   int preprocessor=0);
   static CPT(Shader) make(const string &body,   int preprocessor=0);
-  
+
   INLINE const string   &get_name() const;
   INLINE const Filename &get_file() const;
   INLINE const string   &get_body() const;
   INLINE int             get_preprocessor() const;
   INLINE bool            get_loaded() const;
-  
+  INLINE bool            get_load_error() const;
+
   PT(ShaderExpansion) macroexpand(const RenderState *context) const;
-  
+
 public:
   Shader();
   ~Shader();
-  
+
 private:
   string   _name;
   Filename _file;
   string   _body;
   bool     _loaded;
+  bool     _load_error;
   int      _preprocessor;
-  
+
   PT(ShaderExpansion) _fixed_expansion;
-  
+
   typedef pair < Filename, int > LoadTableKey;
   typedef pair < string,   int > MakeTableKey;
 
   typedef pmap < LoadTableKey , Shader * > LoadTable;
   typedef pmap < MakeTableKey , Shader * > MakeTable;
-  
+
   static LoadTable _load_table;
   static MakeTable _make_table;
-  
+
 public:
   static void register_with_read_factory();