31 #include <boost/filesystem.hpp>
32 #include <boost/signals2/signal.hpp>
34 #include <osg/NodeCallback>
35 #include <osg/Program>
38 #include "../../common/WPathHelper.h"
39 #include "../../common/WSharedAssociativeContainer.h"
41 #include "WGEShaderDefine.h"
42 #include "WGEShaderPreprocessor.h"
53 typedef osg::ref_ptr< WGEShader >
RefPtr;
75 using osg::Program::apply;
83 virtual void apply( osg::ref_ptr< osg::Node > node );
98 virtual void deactivate( osg::ref_ptr< osg::Node > node );
114 template <
typename T >
170 std::string
processShader(
const std::string filename,
bool optional =
false );
264 virtual void operator()( osg::Node* node, osg::NodeVisitor* nv );
276 template <
typename T >
286 if( define && ( define->
getName() == key ) )
This class is able to provide arbitrary values as define statements in GLSL code.
void setValue(const ValueType &value)
Sets the new value for this define.
std::shared_ptr< WGEShaderDefine< ValueType > > SPtr
Shared pointer for this class.
std::string getName() const
Returns the name of the define.
std::shared_ptr< WGEShaderPreprocessor > SPtr
Shared pointer for this class.
Update callback which handles the shader reloading.
SafeUpdaterCallback(WGEShader *shader)
Constructor.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
Callback method called by the NodeVisitor when visiting a node.
WGEShader * m_shader
The shader belonging to the node currently getting updated.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
bool m_shaderLoaded
True if the shaders have been loaded successfully previously.
osg::ref_ptr< osg::Shader > m_vertexShader
the vertex shader object
virtual void deactivate(osg::ref_ptr< osg::Node > node)
Removes the shader from the specified node.
std::string processShaderRecursive(const std::string filename, bool optional=false, int level=0)
This method searches and processes all includes in the shader source.
WGEShaderDefine< T >::SPtr setDefine(std::string key, T value)
Sets a define which is include into the shader source code.
virtual void reload()
Initiate a reload of the shader during the next update cycle.
void updatePrograms()
Handles all state changes in m_reload and m_deactivated.
osg::ref_ptr< osg::Shader > m_fragmentShader
the fragment shader object
virtual void applyDirect(osg::State &state)
If enabled, activate our program in the GL pipeline, performing any rebuild operations that might be ...
WGEShaderPreprocessor::SPtr m_versionPreprocessor
This preprocessor needs to be run LAST.
void removePreprocessor(WGEShaderPreprocessor::SPtr preproc)
Removes the specified preprocessor.
void reloadShader()
This completely reloads the shader file and processes it.
boost::signals2::connection m_reloadSignalConnection
Connection object to the reload signal from WGraphbicsEngine.
virtual void apply(osg::ref_ptr< osg::Node > node)
Apply this shader to the specified node.
WGEShader(std::string name, boost::filesystem::path search=WPathHelper::getShaderPath())
Default constructor.
bool m_reload
Flag denoting whether a shader should be reloaded.
void clearPreprocessors()
Removes all preprocessors.
bool m_deactivated
Flag denoting whether a shader should be deactivated.
void addPreprocessor(WGEShaderPreprocessor::SPtr preproc)
Adds the specified preprocessor to this shader.
osg::ref_ptr< osg::Shader > m_geometryShader
the geometry shader object
boost::filesystem::path m_shaderPath
String that stores the location of all shader files.
virtual ~WGEShader()
Destructor.
osg::ref_ptr< WGEShader > RefPtr
Convenience typedef for an osg::ref_ptr.
osg::ref_ptr< const WGEShader > ConstRefPtr
Convenience typedef for an osg::ref_ptr; const.
std::string processShader(const std::string filename, bool optional=false)
This method searches and processes all includes in the shader source.
WSharedAssociativeContainer< std::map< WGEShaderPreprocessor::SPtr, boost::signals2::connection > > PreprocessorsList
The list of preprocessors - Type.
std::string m_name
The name of the shader.
PreprocessorsList m_preprocessors
List of all pre-processing that need to be applied to this shader instance.
static boost::filesystem::path getShaderPath()
The path to the global shaders.
This class provides a common interface for thread-safe access to associative containers (set,...
T::const_iterator ConstIterator
A typedef for the correct const iterator useful to traverse this sequence container.
std::shared_ptr< WSharedObjectTicketRead< T > > ReadTicket
Type for read tickets.
ReadTicket getReadTicket() const
Returns a ticket to get read access to the contained data.