From ffbde58774b84d31d9dda18f11cd3d240005f40d Mon Sep 17 00:00:00 2001 From: aignacio_sf <> Date: Fri, 10 Feb 2006 20:35:59 +0000 Subject: [PATCH] Added get_load_error function. Needed to know if the file was properly loaded or not before using a shader. --- panda/src/pgraph/shader.I | 18 ++++++++++++++---- panda/src/pgraph/shader.cxx | 16 +++++++++------- panda/src/pgraph/shader.h | 20 +++++++++++--------- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/panda/src/pgraph/shader.I b/panda/src/pgraph/shader.I index 10125eaaf5..ef9f14c861 100644 --- a/panda/src/pgraph/shader.I +++ b/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 { diff --git a/panda/src/pgraph/shader.cxx b/panda/src/pgraph/shader.cxx index 57d9fa622f..09675fa246 100644 --- a/panda/src/pgraph/shader.cxx +++ b/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() { diff --git a/panda/src/pgraph/shader.h b/panda/src/pgraph/shader.h index 702a47b9b3..0fae0ac19a 100644 --- a/panda/src/pgraph/shader.h +++ b/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();