Radium Engine  1.5.20
Loading...
Searching...
No Matches
Ra::Engine::Data::ShaderConfiguration Class Referencefinal

#include <Engine/Data/ShaderConfiguration.hpp>

+ Collaboration diagram for Ra::Engine::Data::ShaderConfiguration:

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::stringgetProperties () 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::stringgetName () const
 
const std::stringgetVersion () 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.
 
static std::string getGLSLVersion ()
 get the OpenGL version used in the generated header for shaders.
 

Friends

class ShaderProgram
 
std::ostreamoperator<< (std::ostream &stream, const ShaderConfiguration &config)
 

Detailed Description

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(); ...

Todo
: make configuration and program (in the OpenGL sense) be packed. A shader configuration might contains a ShaderProgram after compiling. This will remove the need for ShaderConfigurationFactory as ShaderManager will offer the same services. Actually, there is redundancy between ShaderConfigurationFactory and ShaderProgramManager

Definition at line 61 of file ShaderConfiguration.hpp.

Constructor & Destructor Documentation

◆ ShaderConfiguration() [1/2]

Ra::Engine::Data::ShaderConfiguration::ShaderConfiguration ( const std::string & name)
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.

◆ ShaderConfiguration() [2/2]

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.

Member Function Documentation

◆ addInclude()

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.

+ Here is the call graph for this function:

◆ addIncludes()

void Ra::Engine::Data::ShaderConfiguration::addIncludes ( const std::list< std::string > & incls,
ShaderType type = ShaderType_FRAGMENT )

Definition at line 84 of file ShaderConfiguration.cpp.

◆ addNamedString()

void Ra::Engine::Data::ShaderConfiguration::addNamedString ( const std::string & includepath,
const std::string & realfile )

Manage named strings (see ShaderProgramManager::addNamedString)

Definition at line 95 of file ShaderConfiguration.cpp.

+ Here is the call graph for this function:

◆ addProperties()

void Ra::Engine::Data::ShaderConfiguration::addProperties ( const std::list< std::string > & props)

Definition at line 70 of file ShaderConfiguration.cpp.

◆ addProperty()

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.

+ Here is the call graph for this function:

◆ addShader()

void Ra::Engine::Data::ShaderConfiguration::addShader ( ShaderType type,
const std::string & name )

Add a shader, from a file, given its type

Parameters
typethe Type of the shader
namethe file to load

Definition at line 58 of file ShaderConfiguration.cpp.

◆ addShaderSource()

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.

Parameters
type
sourcethe source code of the shader

Definition at line 62 of file ShaderConfiguration.cpp.

◆ getDefaultShaderConfig()

static ShaderConfiguration Ra::Engine::Data::ShaderConfiguration::getDefaultShaderConfig ( )
inlinestatic

Definition at line 129 of file ShaderConfiguration.hpp.

◆ getGLSLVersion()

std::string Ra::Engine::Data::ShaderConfiguration::getGLSLVersion ( )
static

get the OpenGL version used in the generated header for shaders.

Returns

Definition at line 178 of file ShaderConfiguration.cpp.

◆ getIncludes()

const std::vector< std::pair< std::string, ShaderType > > & Ra::Engine::Data::ShaderConfiguration::getIncludes ( ) const

Definition at line 149 of file ShaderConfiguration.cpp.

◆ getName()

const std::string & Ra::Engine::Data::ShaderConfiguration::getName ( ) const
inline

Definition at line 134 of file ShaderConfiguration.hpp.

◆ getNamedStrings()

const std::vector< std::pair< std::string, std::string > > & Ra::Engine::Data::ShaderConfiguration::getNamedStrings ( ) const

Definition at line 154 of file ShaderConfiguration.cpp.

◆ getProperties()

std::set< std::string > Ra::Engine::Data::ShaderConfiguration::getProperties ( ) const

Definition at line 145 of file ShaderConfiguration.cpp.

◆ getVersion()

const std::string & Ra::Engine::Data::ShaderConfiguration::getVersion ( ) const
inline

Definition at line 135 of file ShaderConfiguration.hpp.

◆ isComplete()

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.

+ Here is the call graph for this function:

◆ operator<()

bool Ra::Engine::Data::ShaderConfiguration::operator< ( const ShaderConfiguration & other) const

Definition at line 106 of file ShaderConfiguration.cpp.

◆ removeInclude()

void Ra::Engine::Data::ShaderConfiguration::removeInclude ( const std::string & incl,
ShaderType type = ShaderType_FRAGMENT )

Definition at line 90 of file ShaderConfiguration.cpp.

◆ removeProperty()

void Ra::Engine::Data::ShaderConfiguration::removeProperty ( const std::string & prop)

Definition at line 76 of file ShaderConfiguration.cpp.

◆ setName()

void Ra::Engine::Data::ShaderConfiguration::setName ( const std::string & name)
inline

Definition at line 132 of file ShaderConfiguration.hpp.

◆ setOpenGLVersion()

void Ra::Engine::Data::ShaderConfiguration::setOpenGLVersion ( const glbinding::Version & version)
static

set the OpenGL version to use in the generated header for shaders.

Parameters
glbinding::Version(e.g. {4,1})

Definition at line 160 of file ShaderConfiguration.cpp.

+ Here is the call graph for this function:

◆ setVersion()

void Ra::Engine::Data::ShaderConfiguration::setVersion ( const std::string & version)
inline

Definition at line 131 of file ShaderConfiguration.hpp.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & stream,
const ShaderConfiguration & config )
friend

Definition at line 22 of file ShaderConfiguration.cpp.

◆ ShaderProgram

friend class ShaderProgram
friend

Definition at line 63 of file ShaderConfiguration.hpp.


The documentation for this class was generated from the following files: