Fixed reloadShader functionality.

This commit is contained in:
hiker 2015-04-24 12:36:25 +10:00
parent 5d098488e6
commit 865760ffa4
4 changed files with 20 additions and 12 deletions

View File

@ -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]);

View File

@ -28,8 +28,8 @@
#include <sstream>
#include <stdio.h>
std::string ShaderBase::m_shader_header = "";
std::vector<ShaderBase *> ShaderBase::m_all_shaders;
std::string ShaderBase::m_shader_header = "";
std::vector<void(*)()> 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)

View File

@ -37,10 +37,11 @@ private:
* this file repeatedly. */
static std::string m_shader_header;
/** Maintains a list of all shaders. */
static std::vector<ShaderBase *> m_all_shaders;
protected:
/** Maintains a list of all shaders. */
static std::vector<void (*)()> m_all_kill_functions;
enum AttributeType
{
OBJECT,
@ -53,7 +54,6 @@ protected:
void bypassUBO() const;
protected:
// ------------------------------------------------------------------------
// Ends vararg template
template<typename ... Types>
@ -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<typename ... Types>
void loadProgram(AttributeType type, Types ... args)
{

View File

@ -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)
{