Added basic ShaderComponent class and beginnings osgshadercomposition example
This commit is contained in:
@@ -252,6 +252,31 @@ class OSG_EXPORT Shader : public osg::Object
|
||||
Shader& operator=(const Shader&); // disallowed
|
||||
};
|
||||
|
||||
|
||||
class OSG_EXPORT ShaderComponent : public osg::Object
|
||||
{
|
||||
public:
|
||||
|
||||
ShaderComponent();
|
||||
ShaderComponent(const ShaderComponent& sc,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
|
||||
META_Object(osg, ShaderComponent)
|
||||
|
||||
unsigned int addShader(osg::Shader* shader);
|
||||
void removeShader(unsigned int i);
|
||||
|
||||
osg::Shader* getShader(unsigned int i) { return _shaders[i].get(); }
|
||||
const osg::Shader* getShader(unsigned int i) const { return _shaders[i].get(); }
|
||||
|
||||
unsigned int getNumShaders() const { return _shaders.size(); }
|
||||
|
||||
protected:
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Shader> > Shaders;
|
||||
Shaders _shaders;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -38,12 +38,11 @@ class OSG_EXPORT ShaderAttribute : public StateAttribute
|
||||
void setType(Type type);
|
||||
virtual Type getType() const { return _type; }
|
||||
|
||||
unsigned int addShader(Shader* shader);
|
||||
void removeShader(unsigned int i);
|
||||
unsigned int getNumShaders() const { return _shaders.size(); }
|
||||
Shader* getShader(unsigned int i) { return _shaders[i].get(); }
|
||||
Shader* getShader(unsigned int i) const { return _shaders[i].get(); }
|
||||
|
||||
unsigned int addShader(Shader* shader) { return _shaderComponent->addShader(shader); }
|
||||
void removeShader(unsigned int i) { _shaderComponent->removeShader(i); }
|
||||
unsigned int getNumShaders() const { return _shaderComponent->getNumShaders(); }
|
||||
Shader* getShader(unsigned int i) { return _shaderComponent->getShader(i); }
|
||||
const Shader* getShader(unsigned int i) const { return _shaderComponent->getShader(i); }
|
||||
|
||||
unsigned int addUniform(Uniform* uniform);
|
||||
void removeUniform(unsigned int i);
|
||||
@@ -51,7 +50,6 @@ class OSG_EXPORT ShaderAttribute : public StateAttribute
|
||||
Uniform* getUniform(unsigned int i) { return _uniforms[i].get(); }
|
||||
const Uniform* getUniform(unsigned int i) const { return _uniforms[i].get(); }
|
||||
|
||||
|
||||
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const;
|
||||
|
||||
virtual void apply(State& state) const;
|
||||
@@ -68,13 +66,10 @@ class OSG_EXPORT ShaderAttribute : public StateAttribute
|
||||
|
||||
virtual ~ShaderAttribute();
|
||||
|
||||
typedef std::vector< osg::ref_ptr<osg::Shader> > Shaders;
|
||||
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
|
||||
|
||||
Type _type;
|
||||
Shaders _shaders;
|
||||
Uniforms _uniforms;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ class OSG_EXPORT ShaderComposer : public osg::Object
|
||||
ShaderComposer(const ShaderComposer& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
||||
META_Object(osg, ShaderComposer)
|
||||
|
||||
osg::Program* getOrCreateProgram() { return 0; }
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -1351,7 +1351,11 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
|
||||
GraphicsContext* _graphicsContext;
|
||||
unsigned int _contextID;
|
||||
osg::ref_ptr<ShaderComposer> _shaderComposer;
|
||||
|
||||
bool _shaderCompositionEnabled;
|
||||
bool _shaderCompositionDirty;
|
||||
osg::ref_ptr<ShaderComposer> _shaderComposer;
|
||||
osg::Program* _currentShaderCompositionProgram;
|
||||
|
||||
ref_ptr<FrameStamp> _frameStamp;
|
||||
|
||||
@@ -1413,12 +1417,15 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
{
|
||||
changed = false;
|
||||
last_applied_attribute = 0L;
|
||||
last_applied_shadercomponent = 0L;
|
||||
global_default_attribute = 0L;
|
||||
|
||||
}
|
||||
|
||||
/** apply an attribute if required, passing in attribute and appropriate attribute stack */
|
||||
bool changed;
|
||||
const StateAttribute* last_applied_attribute;
|
||||
const ShaderComponent* last_applied_shadercomponent;
|
||||
ref_ptr<const StateAttribute> global_default_attribute;
|
||||
AttributeVec attributeVec;
|
||||
};
|
||||
@@ -1493,6 +1500,13 @@ class OSG_EXPORT State : public Referenced, public Observer
|
||||
as.last_applied_attribute = attribute;
|
||||
attribute->apply(*this);
|
||||
|
||||
const ShaderComponent* sc = attribute->getShaderComponent();
|
||||
if (as.last_applied_shadercomponent != sc)
|
||||
{
|
||||
as.last_applied_shadercomponent = sc;
|
||||
_shaderCompositionDirty = true;
|
||||
}
|
||||
|
||||
if (_checkGLErrors==ONCE_PER_ATTRIBUTE) checkGLErrors(attribute);
|
||||
|
||||
return true;
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
#include <osg/Export>
|
||||
#include <osg/Object>
|
||||
#include <osg/StateAttributeCallback>
|
||||
#include <osg/Shader>
|
||||
#include <osg/GL>
|
||||
|
||||
#include <typeinfo>
|
||||
@@ -193,7 +194,9 @@ class OSG_EXPORT StateAttribute : public Object
|
||||
|
||||
StateAttribute(const StateAttribute& sa,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
|
||||
Object(sa,copyop),
|
||||
_updateCallback(copyop(sa._updateCallback.get()))
|
||||
_shaderComponent(sa._shaderComponent),
|
||||
_updateCallback(copyop(sa._updateCallback.get())),
|
||||
_eventCallback(copyop(sa._eventCallback.get()))
|
||||
{}
|
||||
|
||||
|
||||
@@ -262,6 +265,9 @@ class OSG_EXPORT StateAttribute : public Object
|
||||
*/
|
||||
inline unsigned int getNumParents() const { return static_cast<unsigned int>(_parents.size()); }
|
||||
|
||||
void setShaderComponent(ShaderComponent* sc) { _shaderComponent = sc; }
|
||||
ShaderComponent* getShaderComponent() { return _shaderComponent.get(); }
|
||||
const ShaderComponent* getShaderComponent() const { return _shaderComponent.get(); }
|
||||
|
||||
struct ModeUsage
|
||||
{
|
||||
@@ -341,6 +347,8 @@ class OSG_EXPORT StateAttribute : public Object
|
||||
ParentList _parents;
|
||||
friend class osg::StateSet;
|
||||
|
||||
ref_ptr<ShaderComponent> _shaderComponent;
|
||||
|
||||
ref_ptr<StateAttributeCallback> _updateCallback;
|
||||
ref_ptr<StateAttributeCallback> _eventCallback;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user