Skip to content

Instantly share code, notes, and snippets.

@minexew
Created November 20, 2018 16:26
Show Gist options
  • Save minexew/7862643493e4335b75e633e2236f4abe to your computer and use it in GitHub Desktop.
Save minexew/7862643493e4335b75e633e2236f4abe to your computer and use it in GitHub Desktop.
// Renderer.hpp
class ShaderGlobal {
public:
ShaderGlobal(const char* name) {
this->handle = Rend::CreateShaderGlobal(name);
}
template <typename T>
void operator = (const T& value) {
Rend::UpdateShaderGlobal(this->handle, value);
}
private:
void* handle;
};
// Game.hpp
struct MyShaderGlobals {
ShaderGlobal sun_dir = "sun_dir",
sun_ambient = "sun_amb",
sun_diffuse = "sun_diff",
sun_specular = "sun_spec";
};
MyShaderGlobals shaderGlobal;
// Game.cpp
// Automagically propagate uniform to the current shader and any shaders bound in the future
shaderGlobal.sun_diffuse = Float4(1.0, 0.9, 0.5, 1.0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment