The reload mechanism for shaders is a bit better, but still to make them unique.

This commit is contained in:
Zed A. Shaw 2025-04-14 13:16:19 -04:00
parent 08bc48df3d
commit 19b9a4affd
7 changed files with 68 additions and 44 deletions

View file

@ -85,13 +85,16 @@ namespace guecs {
struct Shader {
float duration = 0.1f;
std::string name{"ui_shader"};
float u_time_end = 0.0;
bool active = false;
std::shared_ptr<sf::Clock> clock = nullptr;
float $u_time_end = 0.0;
bool $active = false;
std::shared_ptr<sf::Clock> $clock = nullptr;
std::shared_ptr<sf::Shader> $shader = nullptr;
int $shader_version = 0;
void init(lel::Cell &cell);
void run();
void step();
shared_ptr<sf::Shader> checkout_ptr();
};
struct Background {
@ -198,9 +201,11 @@ namespace guecs {
if($world.has<Shader>(ent)) {
auto& shader = $world.get<Shader>(ent);
if(shader.active) {
shader_ptr = shaders::get(shader.name);
shader_ptr->setUniform("is_shape", is_shape);
if(shader.$active) {
auto ptr = shader.checkout_ptr();
ptr->setUniform("is_shape", is_shape);
// NOTE: this is needed because SFML doesn't handle shared_ptr
shader_ptr = ptr.get();
}
}