OpenWalnut
1.5.0dev
|
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader. More...
#include <WGEShader.h>
Classes | |
class | SafeUpdaterCallback |
Update callback which handles the shader reloading. More... | |
Public Types | |
typedef osg::ref_ptr< WGEShader > | RefPtr |
Convenience typedef for an osg::ref_ptr. More... | |
typedef osg::ref_ptr< const WGEShader > | ConstRefPtr |
Convenience typedef for an osg::ref_ptr; const. More... | |
Public Member Functions | |
WGEShader (std::string name, boost::filesystem::path search=WPathHelper::getShaderPath()) | |
Default constructor. More... | |
virtual | ~WGEShader () |
Destructor. More... | |
virtual void | apply (osg::ref_ptr< osg::Node > node) |
Apply this shader to the specified node. More... | |
virtual void | applyDirect (osg::State &state) |
If enabled, activate our program in the GL pipeline, performing any rebuild operations that might be pending. More... | |
virtual void | deactivate (osg::ref_ptr< osg::Node > node) |
Removes the shader from the specified node. More... | |
virtual void | reload () |
Initiate a reload of the shader during the next update cycle. More... | |
template<typename T > | |
WGEShaderDefine< T >::SPtr | setDefine (std::string key, T value) |
Sets a define which is include into the shader source code. More... | |
WGEShaderDefineSwitch::SPtr | setDefine (std::string key) |
Sets a define which is include into the shader source code. More... | |
void | addPreprocessor (WGEShaderPreprocessor::SPtr preproc) |
Adds the specified preprocessor to this shader. More... | |
void | removePreprocessor (WGEShaderPreprocessor::SPtr preproc) |
Removes the specified preprocessor. More... | |
void | clearPreprocessors () |
Removes all preprocessors. More... | |
Protected Types | |
typedef WSharedAssociativeContainer< std::map< WGEShaderPreprocessor::SPtr, boost::signals2::connection > > | PreprocessorsList |
The list of preprocessors - Type. More... | |
Protected Member Functions | |
std::string | processShaderRecursive (const std::string filename, bool optional=false, int level=0) |
This method searches and processes all includes in the shader source. More... | |
std::string | processShader (const std::string filename, bool optional=false) |
This method searches and processes all includes in the shader source. More... | |
void | reloadShader () |
This completely reloads the shader file and processes it. More... | |
void | updatePrograms () |
Handles all state changes in m_reload and m_deactivated. More... | |
Protected Attributes | |
boost::filesystem::path | m_shaderPath |
String that stores the location of all shader files. More... | |
std::string | m_name |
The name of the shader. More... | |
bool | m_reload |
Flag denoting whether a shader should be reloaded. More... | |
bool | m_shaderLoaded |
True if the shaders have been loaded successfully previously. More... | |
bool | m_deactivated |
Flag denoting whether a shader should be deactivated. More... | |
boost::signals2::connection | m_reloadSignalConnection |
Connection object to the reload signal from WGraphbicsEngine. More... | |
PreprocessorsList | m_preprocessors |
List of all pre-processing that need to be applied to this shader instance. More... | |
WGEShaderPreprocessor::SPtr | m_versionPreprocessor |
This preprocessor needs to be run LAST. More... | |
osg::ref_ptr< osg::Shader > | m_vertexShader |
the vertex shader object More... | |
osg::ref_ptr< osg::Shader > | m_fragmentShader |
the fragment shader object More... | |
osg::ref_ptr< osg::Shader > | m_geometryShader |
the geometry shader object More... | |
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
Definition at line 47 of file WGEShader.h.
typedef osg::ref_ptr< const WGEShader > WGEShader::ConstRefPtr |
Convenience typedef for an osg::ref_ptr; const.
Definition at line 58 of file WGEShader.h.
|
protected |
The list of preprocessors - Type.
Definition at line 215 of file WGEShader.h.
typedef osg::ref_ptr< WGEShader > WGEShader::RefPtr |
Convenience typedef for an osg::ref_ptr.
Definition at line 53 of file WGEShader.h.
WGEShader::WGEShader | ( | std::string | name, |
boost::filesystem::path | search = WPathHelper::getShaderPath() |
||
) |
Default constructor.
Loads the specified shader programs. The path that can be specified is optional but allows modules to load their own local shaders. The search order for shader files is as follows: 1. search, 2. search/shaders, 3. WPathHelper::getShaderPath()
name | the name of the shader. It gets searched in the shader path. |
search | the local search path. If not specified, the global shader path is used. |
Definition at line 49 of file WGEShader.cpp.
References WGraphicsEngine::getGraphicsEngine(), m_fragmentShader, m_geometryShader, m_reloadSignalConnection, m_versionPreprocessor, m_vertexShader, and reload().
|
virtual |
void WGEShader::addPreprocessor | ( | WGEShaderPreprocessor::SPtr | preproc | ) |
Adds the specified preprocessor to this shader.
The preprocessor is able to force shader reloads.
preproc | the preprocessor to add. |
Definition at line 359 of file WGEShader.cpp.
References WSharedObject< T >::getWriteTicket(), m_preprocessors, and reload().
Referenced by setDefine().
|
virtual |
Apply this shader to the specified node.
Use this method to ensure, that reload events can be handled properly during the update cycle.
node | the node where the program should be registered to. |
Definition at line 79 of file WGEShader.cpp.
References m_deactivated, m_reload, and m_shaderLoaded.
|
virtual |
If enabled, activate our program in the GL pipeline, performing any rebuild operations that might be pending.
In addition to the standard OSG functionality, it also loads/reloads the shader source from file.
state | the state to apply the shader program to. |
Definition at line 92 of file WGEShader.cpp.
References updatePrograms().
void WGEShader::clearPreprocessors | ( | ) |
Removes all preprocessors.
Be careful with this one since it removes the WGESHaderVersionPreprocessor too, which is mandatory.
Definition at line 384 of file WGEShader.cpp.
References WSharedObject< T >::getWriteTicket(), m_preprocessors, and reload().
|
virtual |
Removes the shader from the specified node.
node | the node where the program is registered to. |
Definition at line 98 of file WGEShader.cpp.
References m_deactivated, and m_shaderLoaded.
|
protected |
This method searches and processes all includes in the shader source.
The filenames in the include statement are assumed to be relative to this shader's path. It additionally applies preprocessors.
filename | the filename of the shader to process. |
optional | denotes whether a "file not found" is critical or not |
Definition at line 334 of file WGEShader.cpp.
References WSharedObject< T >::getReadTicket(), m_preprocessors, m_versionPreprocessor, and processShaderRecursive().
Referenced by reloadShader().
|
protected |
This method searches and processes all includes in the shader source.
The filenames in the include statement are assumed to be relative to this shader's path. It simply unrolls the code.
filename | the filename of the shader to process. |
optional | denotes whether a "file not found" is critical or not |
level | the inclusion level. This is used to avoid cycles. |
Definition at line 206 of file WGEShader.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), WPathHelper::getShaderPath(), and m_shaderPath.
Referenced by processShader().
|
virtual |
Initiate a reload of the shader during the next update cycle.
Definition at line 117 of file WGEShader.cpp.
References m_reload.
Referenced by addPreprocessor(), clearPreprocessors(), removePreprocessor(), and WGEShader().
|
protected |
This completely reloads the shader file and processes it.
It also resets m_reload to false.
Definition at line 122 of file WGEShader.cpp.
References WLogger::addLogMessage(), WLogger::getLogger(), m_fragmentShader, m_geometryShader, m_name, m_reload, m_shaderLoaded, m_vertexShader, and processShader().
Referenced by updatePrograms().
void WGEShader::removePreprocessor | ( | WGEShaderPreprocessor::SPtr | preproc | ) |
Removes the specified preprocessor.
Changes inside the preprocessor won't cause any updates anymore.
preproc | the preprocessor to remove. If not exists: nothing is done. |
Definition at line 372 of file WGEShader.cpp.
References WSharedObject< T >::getWriteTicket(), m_preprocessors, and reload().
WGEShaderDefineSwitch::SPtr WGEShader::setDefine | ( | std::string | key | ) |
Sets a define which is include into the shader source code.
This allows the preprocessor to turn on/off several parts of your code. In GLSL defines are a better choice when compared with a lot of branches (if-statements).
key | The name of the define |
Definition at line 398 of file WGEShader.cpp.
WGEShaderDefine< T >::SPtr WGEShader::setDefine | ( | std::string | key, |
T | value | ||
) |
Sets a define which is include into the shader source code.
This allows the preprocessor to turn on/off several parts of your code. In GLSL defines are a better choice when compared with a lot of branches (if-statements).
key | The name of the define |
value | The value of the define. If this is not specified, the define can be used as simple ifdef switch. |
Definition at line 277 of file WGEShader.h.
References addPreprocessor(), WGEShaderDefine< ValueType >::getName(), WSharedObject< T >::getReadTicket(), m_preprocessors, and WGEShaderDefine< ValueType >::setValue().
|
protected |
Handles all state changes in m_reload and m_deactivated.
It ensure that the shader programs are bound properly or deactivated.
Definition at line 177 of file WGEShader.cpp.
References m_deactivated, m_fragmentShader, m_geometryShader, m_reload, m_vertexShader, and reloadShader().
Referenced by applyDirect().
|
protected |
Flag denoting whether a shader should be deactivated.
Definition at line 205 of file WGEShader.h.
Referenced by apply(), deactivate(), and updatePrograms().
|
protected |
the fragment shader object
Definition at line 235 of file WGEShader.h.
Referenced by reloadShader(), updatePrograms(), and WGEShader().
|
protected |
the geometry shader object
Definition at line 240 of file WGEShader.h.
Referenced by reloadShader(), updatePrograms(), and WGEShader().
|
protected |
The name of the shader.
It is used to construct the actual filename to load.
Definition at line 190 of file WGEShader.h.
Referenced by reloadShader().
|
protected |
List of all pre-processing that need to be applied to this shader instance.
Definition at line 220 of file WGEShader.h.
Referenced by addPreprocessor(), clearPreprocessors(), processShader(), removePreprocessor(), and setDefine().
|
protected |
Flag denoting whether a shader should be reloaded.
Definition at line 195 of file WGEShader.h.
Referenced by apply(), reload(), reloadShader(), and updatePrograms().
|
protected |
Connection object to the reload signal from WGraphbicsEngine.
Definition at line 210 of file WGEShader.h.
Referenced by WGEShader(), and ~WGEShader().
|
protected |
True if the shaders have been loaded successfully previously.
Definition at line 200 of file WGEShader.h.
Referenced by apply(), deactivate(), and reloadShader().
|
protected |
String that stores the location of all shader files.
Definition at line 185 of file WGEShader.h.
Referenced by processShaderRecursive().
|
protected |
This preprocessor needs to be run LAST.
It handles version-statements in GLSL.
Definition at line 225 of file WGEShader.h.
Referenced by processShader(), and WGEShader().
|
protected |
the vertex shader object
Definition at line 230 of file WGEShader.h.
Referenced by reloadShader(), updatePrograms(), and WGEShader().