Now I can attach arbitrary shaders to sprites based on things that happen in the world.
This commit is contained in:
parent
bec8fe0a13
commit
787be78a69
6 changed files with 53 additions and 16 deletions
26
shaders.cpp
26
shaders.cpp
|
@ -7,17 +7,25 @@
|
|||
#include <memory>
|
||||
|
||||
namespace shaders {
|
||||
using std::shared_ptr, std::make_shared;
|
||||
using std::shared_ptr, std::make_shared;
|
||||
|
||||
static ShaderManager SMGR;
|
||||
static bool INITIALIZED = false;
|
||||
static int VERSION = 0;
|
||||
static ShaderManager SMGR;
|
||||
static bool INITIALIZED = false;
|
||||
static int VERSION = 0;
|
||||
|
||||
bool load_shader(std::string name, nlohmann::json& settings) {
|
||||
std::string file_name = settings["file_name"];
|
||||
auto ptr = std::make_shared<sf::Shader>();
|
||||
bool good = ptr->loadFromFile(file_name, sf::Shader::Type::Fragment);
|
||||
if(good) SMGR.shaders.try_emplace(name, name, file_name, ptr);
|
||||
inline void configure_shader_defaults(std::shared_ptr<sf::Shader> ptr) {
|
||||
ptr->setUniform("source", sf::Shader::CurrentTexture);
|
||||
}
|
||||
|
||||
bool load_shader(std::string name, nlohmann::json& settings) {
|
||||
std::string file_name = settings["file_name"];
|
||||
auto ptr = std::make_shared<sf::Shader>();
|
||||
bool good = ptr->loadFromFile(file_name, sf::Shader::Type::Fragment);
|
||||
|
||||
if(good) {
|
||||
configure_shader_defaults(ptr);
|
||||
SMGR.shaders.try_emplace(name, name, file_name, ptr);
|
||||
}
|
||||
return good;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue