From 865760ffa4b7a4ff772fa3fc6e72d5bc50368e1a Mon Sep 17 00:00:00 2001 From: hiker Date: Fri, 24 Apr 2015 12:36:25 +1000 Subject: [PATCH] Fixed reloadShader functionality. --- src/graphics/irr_driver.hpp | 2 -- src/graphics/shader.cpp | 13 ++++++++++--- src/graphics/shader.hpp | 15 +++++++++------ src/utils/debug.cpp | 2 +- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index 5af343f98..cfe9feea0 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -560,8 +560,6 @@ public: // ----------------------------------------------------------------------- inline video::E_MATERIAL_TYPE getShader(const ShaderType num) {return m_shaders->getShader(num);} // ----------------------------------------------------------------------- - inline void updateShaders() {m_shaders->killShaders();} - // ------------------------------------------------------------------------ inline video::IShaderConstantSetCallBack* getCallback(const ShaderType num) { return (m_shaders == NULL ? NULL : m_shaders->m_callbacks[num]); diff --git a/src/graphics/shader.cpp b/src/graphics/shader.cpp index ad61cff66..d728650f9 100644 --- a/src/graphics/shader.cpp +++ b/src/graphics/shader.cpp @@ -28,8 +28,8 @@ #include #include -std::string ShaderBase::m_shader_header = ""; -std::vector ShaderBase::m_all_shaders; +std::string ShaderBase::m_shader_header = ""; +std::vector ShaderBase::m_all_kill_functions; // ---------------------------------------------------------------------------- /** Returns a string with the content of header.txt (which contains basic @@ -199,11 +199,18 @@ void ShaderBase::bypassUBO() const */ ShaderBase::ShaderBase() { - m_all_shaders.push_back(this); } // ShaderBase // ---------------------------------------------------------------------------- +void ShaderBase::updateShaders() +{ + for (unsigned int i = 0; i < m_all_kill_functions.size(); i++) + { + m_all_kill_functions[i](); + } +} // updateShaders +// ---------------------------------------------------------------------------- void ShaderBase::setAttribute(AttributeType type) { switch (type) diff --git a/src/graphics/shader.hpp b/src/graphics/shader.hpp index 9e59032ba..de88a527a 100644 --- a/src/graphics/shader.hpp +++ b/src/graphics/shader.hpp @@ -37,10 +37,11 @@ private: * this file repeatedly. */ static std::string m_shader_header; - /** Maintains a list of all shaders. */ - static std::vector m_all_shaders; protected: + /** Maintains a list of all shaders. */ + static std::vector m_all_kill_functions; + enum AttributeType { OBJECT, @@ -53,7 +54,6 @@ protected: void bypassUBO() const; -protected: // ------------------------------------------------------------------------ // Ends vararg template template @@ -81,9 +81,7 @@ protected: // ------------------------------------------------------------------------ const std::string& getHeader(); - GLuint loadShader(const std::string &file, unsigned type); -protected: void setAttribute(AttributeType type); public: @@ -91,7 +89,7 @@ public: int loadTFBProgram(const std::string &vertex_file_path, const char **varyings, unsigned varyingscount); - + static void updateShaders(); // ------------------------------------------------------------------------ /** Activates the shader calling glUseProgram. */ void use() { glUseProgram(m_program); } @@ -243,6 +241,11 @@ private: public: + Shader() + { + m_all_kill_functions.push_back(this->kill); + } + template void loadProgram(AttributeType type, Types ... args) { diff --git a/src/utils/debug.cpp b/src/utils/debug.cpp index b40481a27..e552f9820 100644 --- a/src/utils/debug.cpp +++ b/src/utils/debug.cpp @@ -296,7 +296,7 @@ bool onEvent(const SEvent &event) if(cmdID == DEBUG_GRAPHICS_RELOAD_SHADERS) { Log::info("Debug", "Reloading shaders..."); - irr_driver->updateShaders(); + ShaderBase::updateShaders(); } else if (cmdID == DEBUG_GRAPHICS_RESET) {