Added basic code injection fields to osg::Shader,

creation of main shader to ShaderComposer and
collection of ShaderComponent to osg::State.
Also added very basic shader set up in osgshadecomposition example.
This commit is contained in:
Robert Osfield
2010-07-05 16:32:58 +00:00
parent 9f8670f50d
commit 751b0498fe
7 changed files with 194 additions and 56 deletions

View File

@@ -25,6 +25,7 @@
#include <osg/buffered_value>
#include <set>
#include <map>
namespace osg {
@@ -143,6 +144,24 @@ class OSG_EXPORT Shader : public osg::Object
bool loadShaderSourceFromFile( const std::string& fileName );
/** The code injection map used when generating the main shader during main shader composition.*/
typedef std::multimap<float, std::string> CodeInjectionMap;
/** Add code injection that will be placed in the main shader to enable support for this shader.
* The position is set up so that code to be inserted before the main() will have a negative value,
* a position between 0 and 1.0 will be inserted in main() and a position greater than 1.0 will
* be placed after the main().
* During shader composition all the code injections are sorted in ascending order and then
* placed in the appropriate section of the main shader. */
void addCodeInjection(float position, const std::string& code) { _codeInjectionMap.insert(CodeInjectionMap::value_type(position, code)); }
/** Get the code injection map.*/
CodeInjectionMap& getCodeInjectionMap() { return _codeInjectionMap; }
/** Get the const code injection map.*/
const CodeInjectionMap& getCodeInjectionMap() const { return _codeInjectionMap; }
/** Resize any per context GLObject buffers to specified size. */
virtual void resizeGLObjectBuffers(unsigned int maxSize);
@@ -242,6 +261,8 @@ class OSG_EXPORT Shader : public osg::Object
std::string _shaderFileName;
std::string _shaderSource;
osg::ref_ptr<ShaderBinary> _shaderBinary;
CodeInjectionMap _codeInjectionMap;
/** osg::Programs that this osg::Shader is attached to */
typedef std::set< osg::Program* > ProgramSet;

View File

@@ -38,11 +38,13 @@ class OSG_EXPORT ShaderComposer : public osg::Object
typedef std::vector< const osg::Shader* > Shaders;
virtual osg::Shader* composeMain(const Shaders& shaders);
virtual void addShaderToProgram(Program* program, const Shaders& shaders);
protected:
virtual ~ShaderComposer();
typedef std::map< ShaderComponents, ref_ptr<Program> > ProgramMap;
ProgramMap _programMap;

View File

@@ -142,6 +142,12 @@ class OSG_EXPORT State : public Referenced, public Observer
inline unsigned int getContextID() const { return _contextID; }
/* Set whether shader composition is enabled.*/
void setShaderCompositionEnabled(bool flag) { _shaderCompositionEnabled = flag; }
/* Get whether shader composition is enabled.*/
bool getShaderCompositionEnabled() const { return _shaderCompositionEnabled; }
/** Set the ShaderComposor object that implements shader composition.*/
void setShaderComposer(ShaderComposer* sc) { _shaderComposer = sc; }
@@ -250,6 +256,8 @@ class OSG_EXPORT State : public Referenced, public Observer
*/
void apply();
/** Apply any shader composed state.*/
void applyShaderComposition();
/** Set whether a particular OpenGL mode is valid in the current graphics context.
* Use to disable OpenGL modes that are not supported by current graphics drivers/context.*/