Added basic ShaderComponent class and beginnings osgshadercomposition example

This commit is contained in:
Robert Osfield
2010-07-02 12:04:20 +00:00
parent aef5e36cf1
commit a55c4b7d70
12 changed files with 163 additions and 32 deletions

View File

@@ -36,6 +36,40 @@
using namespace osg;
///////////////////////////////////////////////////////////////////////////////////
//
// ShaderComponent
//
ShaderComponent::ShaderComponent()
{
}
ShaderComponent::ShaderComponent(const ShaderComponent& sc,const CopyOp& copyop):
osg::Object(sc, copyop),
_shaders(sc._shaders)
{
}
unsigned int ShaderComponent::addShader(osg::Shader* shader)
{
for(unsigned int i=0; i<_shaders.size();++i)
{
if (_shaders[i]==shader) return i;
}
_shaders.push_back(shader);
return _shaders.size()-1;
}
void ShaderComponent::removeShader(unsigned int i)
{
_shaders.erase(_shaders.begin()+i);
}
///////////////////////////////////////////////////////////////////////////////////
//
// ShaderBinary
//
ShaderBinary::ShaderBinary()
{
}

View File

@@ -19,11 +19,13 @@ using namespace osg;
ShaderAttribute::ShaderAttribute()
{
_shaderComponent = new osg::ShaderComponent;
}
ShaderAttribute::ShaderAttribute(const ShaderAttribute& sa,const CopyOp& copyop):
StateAttribute(sa,copyop),
_type(sa._type)
_type(sa._type),
_uniforms(sa._uniforms)
{
}
@@ -50,24 +52,6 @@ void ShaderAttribute::setType(Type type)
_type = type;
}
unsigned int ShaderAttribute::addShader(Shader* shader)
{
// check to see if shader already add, if so return the index of it
for(unsigned int i=0; i<_shaders.size(); ++i)
{
if (_shaders[i] == shader) return i;
}
// add shader and return it's position
_shaders.push_back(shader);
return _shaders.size()-1;
}
void ShaderAttribute::removeShader(unsigned int i)
{
_shaders.erase(_shaders.begin()+i);
}
unsigned int ShaderAttribute::addUniform(Uniform* uniform)
{
// check to see if uniform already add, if so return the index of it

View File

@@ -42,7 +42,10 @@ State::State():
_graphicsContext = 0;
_contextID = 0;
_shaderCompositionEnabled = true;
_shaderCompositionDirty = true;
_shaderComposer = new ShaderComposer;
_currentShaderCompositionProgram = 0L;
_identity = new osg::RefMatrix(); // default RefMatrix constructs to identity.
_initialViewMatrix = _identity;
@@ -512,6 +515,21 @@ void State::apply(const StateSet* dstate)
else if (unit<_textureAttributeMapList.size()) applyAttributeMapOnTexUnit(unit,_textureAttributeMapList[unit]);
}
if (_shaderCompositionEnabled)
{
if (_shaderCompositionDirty)
{
// built lits of current ShaderComponents
_currentShaderCompositionProgram = _shaderComposer->getOrCreateProgram();
}
if (_currentShaderCompositionProgram)
{
Program::PerContextProgram* pcp = _currentShaderCompositionProgram->getPCP(_contextID);
if (_lastAppliedProgramObject != pcp) applyAttribute(_currentShaderCompositionProgram);
}
}
applyUniformList(_uniformMap,dstate->getUniformList());
}
else

View File

@@ -18,7 +18,6 @@
using namespace osg;
StateAttribute::StateAttribute()
:Object(true)
{