Radium Engine
1.5.0
|
#include <Engine/Data/ShaderConfiguration.hpp>
Public Member Functions | |
ShaderConfiguration (const std::string &name) | |
ShaderConfiguration (const std::string &name, const std::string &vertexShader, const std::string &fragmentShader) | |
void | addShader (ShaderType type, const std::string &name) |
void | addShaderSource (ShaderType type, const std::string &source) |
void | addProperty (const std::string &prop) |
void | addProperties (const std::list< std::string > &props) |
void | removeProperty (const std::string &prop) |
void | addInclude (const std::string &incl, ShaderType type=ShaderType_FRAGMENT) |
void | addIncludes (const std::list< std::string > &incls, ShaderType type=ShaderType_FRAGMENT) |
void | removeInclude (const std::string &incl, ShaderType type=ShaderType_FRAGMENT) |
void | addNamedString (const std::string &includepath, const std::string &realfile) |
Manage named strings (see ShaderProgramManager::addNamedString) | |
bool | isComplete () const |
bool | operator< (const ShaderConfiguration &other) const |
std::set< std::string > | getProperties () const |
const std::vector< std::pair< std::string, ShaderType > > & | getIncludes () const |
const std::vector< std::pair< std::string, std::string > > & | getNamedStrings () const |
void | setVersion (const std::string &version) |
void | setName (const std::string &name) |
const std::string & | getName () const |
const std::string & | getVersion () const |
Static Public Member Functions | |
static ShaderConfiguration | getDefaultShaderConfig () |
static void | setOpenGLVersion (const glbinding::Version &version) |
set the OpenGL version to use in the generated header for shaders. More... | |
static std::string | getGLSLVersion () |
get the OpenGL version used in the generated header for shaders. More... | |
Friends | |
class | ShaderProgram |
std::ostream & | operator<< (std::ostream &stream, const ShaderConfiguration &config) |
A class used to create shader programs later on. A ShaderConfiguration should be added once to the ShaderConfigurationFactory, then the factory must be used to retrieve the added shader configurations. Typical use case : **************************** CREATION **************************** // Create the shader configuration once (see MainApplication::addBasicShaders for example) ShaderConfiguration config("MyConfig"); // Add shader files to the config (note that the file extensions can be whatever you want) config.addShader(ShaderType_VERTEX, "path/to/shader.vert.glsl"); config.addShader(ShaderType_FRAGMENT, "path/to/shader.frag.glsl"); // Same for other shader types. Vertex and fragment are required, other are optional // Note that, for a compute shader, only the compute shader is needed. // Add eventually some properties to the shader configuration config.addProperties( {"USE_MICROFACET;", "MICROFACET_DISTRIBUTION Trowbridge_Reitz;"} ); // Add also some includes if needed config.addInclude{"\"MicrofacetFunctions.glsl";"); // Add the configuration to the factory ShaderConfigurationFactory::addConfiguration(config);
**************************** USAGE **************************** // When you want to reuse created shader configurations, just set it using auto config = ShaderConfigurationFactory::getConfiguration("MyConfig"); // You can then use it to extract the shader from the ShaderProgramManager and use it auto shader = ShaderProgramManager::getInstance()->getShaderProgram(); shader->bind(); ...
Definition at line 61 of file ShaderConfiguration.hpp.
|
explicit |
Initializes a shader configuration with a name Warning: This does not query the corresponding configuration in the ShaderConfigurationFactory. The proper way to do this is by calling ShaderConfigurationFactory::getConfiguration(name);
Definition at line 47 of file ShaderConfiguration.cpp.
Ra::Engine::Data::ShaderConfiguration::ShaderConfiguration | ( | const std::string & | name, |
const std::string & | vertexShader, | ||
const std::string & | fragmentShader | ||
) |
Initializes a configuration with a name, a vertex and a fragment shader This does not add the configuration to the factory ShaderConfigurationFactory::addConfiguration(config) must be called.
Definition at line 50 of file ShaderConfiguration.cpp.
void Ra::Engine::Data::ShaderConfiguration::addInclude | ( | const std::string & | incl, |
ShaderType | type = ShaderType_FRAGMENT |
||
) |
Add a property in the form of an #include The same shader files with different properties leads to different shader programs
Definition at line 80 of file ShaderConfiguration.cpp.
void Ra::Engine::Data::ShaderConfiguration::addProperty | ( | const std::string & | prop | ) |
Add a property in the form of a #define The same shader files with different properties leads to different shader programs
Definition at line 66 of file ShaderConfiguration.cpp.
void Ra::Engine::Data::ShaderConfiguration::addShader | ( | ShaderType | type, |
const std::string & | name | ||
) |
Add a shader, from a file, given its type
type | the Type of the shader |
name | the file to load |
Definition at line 58 of file ShaderConfiguration.cpp.
void Ra::Engine::Data::ShaderConfiguration::addShaderSource | ( | ShaderType | type, |
const std::string & | source | ||
) |
Add a shader, given its glsl source code, of a given type. When a shader is added from a glsl source string, when reloading programs, only the parts coming from files are reloaded.
type | |
source | the source code of the shader |
Definition at line 62 of file ShaderConfiguration.cpp.
|
static |
get the OpenGL version used in the generated header for shaders.
Definition at line 178 of file ShaderConfiguration.cpp.
bool Ra::Engine::Data::ShaderConfiguration::isComplete | ( | ) | const |
Tell if a shader configuration has at least a vertex and a fragment shader, or a compute shader.
Definition at line 100 of file ShaderConfiguration.cpp.
|
static |
set the OpenGL version to use in the generated header for shaders.
glbinding::Version | (e.g. {4,1}) |
Definition at line 160 of file ShaderConfiguration.cpp.