~ | Shader hot reloading

This commit is contained in:
TheRedShip
2025-02-14 00:10:46 +01:00
parent 4ddacdaadd
commit 583e15685a
9 changed files with 90 additions and 40 deletions

View File

@ -50,12 +50,13 @@ void ShaderProgram::link()
}
}
void ShaderProgram::use() const
void ShaderProgram::use()
{
glUseProgram(_program);
this->watchForChanges();
}
void ShaderProgram::dispathCompute(GLuint x, GLuint y, GLuint z) const
void ShaderProgram::dispathCompute(GLuint x, GLuint y, GLuint z)
{
this->use();
glDispatchCompute(x, y, z);
@ -67,6 +68,19 @@ void ShaderProgram::bindImageTexture(GLuint texture_id, GLuint unit, GLenum acce
glBindImageTexture(unit, texture_id, 0, GL_FALSE, 0, access, format);
}
void ShaderProgram::watchForChanges(void)
{
for (Shader *shader : _shaders)
{
if (shader->hasChanged())
{
std::cout << "Shader " << shader->getFilePath() << " has changed" << std::endl;
this->reloadShaders();
break;
}
}
}
void ShaderProgram::reloadShaders(void)
{
std::cout << "Reloading shaders" << std::endl;