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