|
|
@ -26,6 +26,7 @@ namespace Shader
|
|
|
|
, mMaterialOverridden(false)
|
|
|
|
, mMaterialOverridden(false)
|
|
|
|
, mNormalHeight(false)
|
|
|
|
, mNormalHeight(false)
|
|
|
|
, mTexStageRequiringTangents(-1)
|
|
|
|
, mTexStageRequiringTangents(-1)
|
|
|
|
|
|
|
|
, mNode(NULL)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -69,7 +70,7 @@ namespace Shader
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (node.getStateSet())
|
|
|
|
if (node.getStateSet())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushRequirements();
|
|
|
|
pushRequirements(node);
|
|
|
|
applyStateSet(node.getStateSet(), node);
|
|
|
|
applyStateSet(node.getStateSet(), node);
|
|
|
|
traverse(node);
|
|
|
|
traverse(node);
|
|
|
|
popRequirements();
|
|
|
|
popRequirements();
|
|
|
@ -234,9 +235,10 @@ namespace Shader
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::pushRequirements()
|
|
|
|
void ShaderVisitor::pushRequirements(osg::Node& node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRequirements.push_back(mRequirements.back());
|
|
|
|
mRequirements.push_back(mRequirements.back());
|
|
|
|
|
|
|
|
mRequirements.back().mNode = &node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::popRequirements()
|
|
|
|
void ShaderVisitor::popRequirements()
|
|
|
@ -244,8 +246,9 @@ namespace Shader
|
|
|
|
mRequirements.pop_back();
|
|
|
|
mRequirements.pop_back();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void ShaderVisitor::createProgram(const ShaderRequirements &reqs, osg::Node& node)
|
|
|
|
void ShaderVisitor::createProgram(const ShaderRequirements &reqs)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
osg::Node& node = *reqs.mNode;
|
|
|
|
osg::StateSet* writableStateSet = NULL;
|
|
|
|
osg::StateSet* writableStateSet = NULL;
|
|
|
|
if (mAllowedToModifyStateSets)
|
|
|
|
if (mAllowedToModifyStateSets)
|
|
|
|
writableStateSet = node.getOrCreateStateSet();
|
|
|
|
writableStateSet = node.getOrCreateStateSet();
|
|
|
@ -305,9 +308,9 @@ namespace Shader
|
|
|
|
void ShaderVisitor::apply(osg::Geometry& geometry)
|
|
|
|
void ShaderVisitor::apply(osg::Geometry& geometry)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool needPop = (geometry.getStateSet() != NULL);
|
|
|
|
bool needPop = (geometry.getStateSet() != NULL);
|
|
|
|
if (geometry.getStateSet())
|
|
|
|
if (geometry.getStateSet()) // TODO: check if stateset affects shader permutation before pushing it
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushRequirements();
|
|
|
|
pushRequirements(geometry);
|
|
|
|
applyStateSet(geometry.getStateSet(), geometry);
|
|
|
|
applyStateSet(geometry.getStateSet(), geometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -350,9 +353,8 @@ namespace Shader
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
rig->setSourceGeometry(sourceGeometry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: find a better place for the stateset
|
|
|
|
|
|
|
|
if (useShader)
|
|
|
|
if (useShader)
|
|
|
|
createProgram(reqs, geometry);
|
|
|
|
createProgram(reqs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needPop)
|
|
|
|
if (needPop)
|
|
|
@ -366,16 +368,15 @@ namespace Shader
|
|
|
|
|
|
|
|
|
|
|
|
if (drawable.getStateSet())
|
|
|
|
if (drawable.getStateSet())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pushRequirements();
|
|
|
|
pushRequirements(drawable);
|
|
|
|
applyStateSet(drawable.getStateSet(), drawable);
|
|
|
|
applyStateSet(drawable.getStateSet(), drawable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
if (!mRequirements.empty())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
const ShaderRequirements& reqs = mRequirements.back();
|
|
|
|
// TODO: find a better place for the stateset
|
|
|
|
|
|
|
|
if (reqs.mShaderRequired || mForceShaders)
|
|
|
|
if (reqs.mShaderRequired || mForceShaders)
|
|
|
|
createProgram(reqs, drawable);
|
|
|
|
createProgram(reqs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (needPop)
|
|
|
|
if (needPop)
|
|
|
|