I can now apply shaders to any GUI element, but I need a shader manager that will allow for hot reloading and tracking input/output variables.

This commit is contained in:
Zed A. Shaw 2025-04-13 15:17:08 -04:00
parent 80b4faf940
commit a5b8e411e3
8 changed files with 121 additions and 16 deletions

View file

@ -81,6 +81,19 @@ namespace guecs {
std::string name;
};
struct Shader {
float duration = 0.1f;
std::string name{DEFAULT_UI_SHADER};
float u_time_end = 0.0;
bool active = false;
std::shared_ptr<sf::Shader> ptr = nullptr;
std::shared_ptr<sf::Clock> clock = nullptr;
void init(lel::Cell &cell);
void run();
void step();
};
struct Background {
float x = 0.0f;
float y = 0.0f;
@ -178,6 +191,22 @@ namespace guecs {
remove<Comp>(ent);
}
template<typename T>
void render_helper(sf::RenderWindow& window, DinkyECS::Entity ent, bool is_shape, T& target) {
sf::Shader *shader_ptr = nullptr;
if($world.has<Shader>(ent)) {
auto& shader = $world.get<Shader>(ent);
if(shader.active) {
shader_ptr = shader.ptr.get();
shader_ptr->setUniform("is_shape", is_shape);
}
}
window.draw(*target, shader_ptr);
}
void show_sprite(string region, string sprite_name);
void show_text(string region, wstring content);
void update_text(string region, wstring content);
@ -186,4 +215,5 @@ namespace guecs {
};
Clickable make_action(DinkyECS::World& target, Events::GUI event);
}