The reload mechanism for shaders is a bit better, but still to make them unique.
This commit is contained in:
parent
08bc48df3d
commit
19b9a4affd
7 changed files with 68 additions and 44 deletions
29
shaders.cpp
29
shaders.cpp
|
@ -10,7 +10,8 @@ namespace shaders {
|
|||
using std::shared_ptr, std::make_shared;
|
||||
|
||||
static ShaderManager SMGR;
|
||||
static bool initialized = false;
|
||||
static bool INITIALIZED = false;
|
||||
static int VERSION = 0;
|
||||
|
||||
bool load_shader(std::string name, nlohmann::json& settings) {
|
||||
std::string file_name = settings["file_name"];
|
||||
|
@ -21,9 +22,9 @@ namespace shaders {
|
|||
}
|
||||
|
||||
void init() {
|
||||
if(!initialized) {
|
||||
if(!INITIALIZED) {
|
||||
dbc::check(sf::Shader::isAvailable(), "no shaders?!");
|
||||
initialized = true;
|
||||
INITIALIZED = true;
|
||||
Config config("assets/shaders.json");
|
||||
bool good = load_shader("ERROR", config["ERROR"]);
|
||||
dbc::check(good, "Failed to load ERROR shader. Look in assets/shaders.json");
|
||||
|
@ -43,21 +44,27 @@ namespace shaders {
|
|||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<sf::Shader> get_shared(std::string& name) {
|
||||
dbc::check(initialized, "you forgot to shaders::init()");
|
||||
std::shared_ptr<sf::Shader> get(const std::string& name) {
|
||||
dbc::check(INITIALIZED, "you forgot to shaders::init()");
|
||||
dbc::check(SMGR.shaders.contains(name),
|
||||
fmt::format("shader name '{}' not in assets/shaders.json", name));
|
||||
auto& rec = SMGR.shaders.at(name);
|
||||
return rec.ptr;
|
||||
}
|
||||
|
||||
sf::Shader* get(std::string name) {
|
||||
return get_shared(name).get();
|
||||
}
|
||||
|
||||
void reload() {
|
||||
initialized = false;
|
||||
int reload() {
|
||||
VERSION++;
|
||||
INITIALIZED = false;
|
||||
SMGR.shaders.clear();
|
||||
init();
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
bool updated(int my_version) {
|
||||
return my_version != VERSION;
|
||||
}
|
||||
|
||||
int version() {
|
||||
return VERSION;
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue