forked from mirror/openmw-tes3mp
Set the shader on the node containing the StateSet
This commit is contained in:
parent
d749b7f2a7
commit
b9931fb71c
2 changed files with 16 additions and 12 deletions
|
@ -26,6 +26,7 @@ namespace Shader
|
|||
, mMaterialOverridden(false)
|
||||
, mNormalHeight(false)
|
||||
, mTexStageRequiringTangents(-1)
|
||||
, mNode(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@ namespace Shader
|
|||
{
|
||||
if (node.getStateSet())
|
||||
{
|
||||
pushRequirements();
|
||||
pushRequirements(node);
|
||||
applyStateSet(node.getStateSet(), node);
|
||||
traverse(node);
|
||||
popRequirements();
|
||||
|
@ -234,9 +235,10 @@ namespace Shader
|
|||
}
|
||||
}
|
||||
|
||||
void ShaderVisitor::pushRequirements()
|
||||
void ShaderVisitor::pushRequirements(osg::Node& node)
|
||||
{
|
||||
mRequirements.push_back(mRequirements.back());
|
||||
mRequirements.back().mNode = &node;
|
||||
}
|
||||
|
||||
void ShaderVisitor::popRequirements()
|
||||
|
@ -244,8 +246,9 @@ namespace Shader
|
|||
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;
|
||||
if (mAllowedToModifyStateSets)
|
||||
writableStateSet = node.getOrCreateStateSet();
|
||||
|
@ -305,9 +308,9 @@ namespace Shader
|
|||
void ShaderVisitor::apply(osg::Geometry& geometry)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -350,9 +353,8 @@ namespace Shader
|
|||
rig->setSourceGeometry(sourceGeometry);
|
||||
}
|
||||
|
||||
// TODO: find a better place for the stateset
|
||||
if (useShader)
|
||||
createProgram(reqs, geometry);
|
||||
createProgram(reqs);
|
||||
}
|
||||
|
||||
if (needPop)
|
||||
|
@ -366,16 +368,15 @@ namespace Shader
|
|||
|
||||
if (drawable.getStateSet())
|
||||
{
|
||||
pushRequirements();
|
||||
pushRequirements(drawable);
|
||||
applyStateSet(drawable.getStateSet(), drawable);
|
||||
}
|
||||
|
||||
if (!mRequirements.empty())
|
||||
{
|
||||
const ShaderRequirements& reqs = mRequirements.back();
|
||||
// TODO: find a better place for the stateset
|
||||
if (reqs.mShaderRequired || mForceShaders)
|
||||
createProgram(reqs, drawable);
|
||||
createProgram(reqs);
|
||||
}
|
||||
|
||||
if (needPop)
|
||||
|
|
|
@ -52,7 +52,7 @@ namespace Shader
|
|||
|
||||
void applyStateSet(osg::ref_ptr<osg::StateSet> stateset, osg::Node& node);
|
||||
|
||||
void pushRequirements();
|
||||
void pushRequirements(osg::Node& node);
|
||||
void popRequirements();
|
||||
|
||||
private:
|
||||
|
@ -89,13 +89,16 @@ namespace Shader
|
|||
|
||||
// -1 == no tangents required
|
||||
int mTexStageRequiringTangents;
|
||||
|
||||
// the Node that requested these requirements
|
||||
osg::Node* mNode;
|
||||
};
|
||||
std::vector<ShaderRequirements> mRequirements;
|
||||
|
||||
std::string mDefaultVsTemplate;
|
||||
std::string mDefaultFsTemplate;
|
||||
|
||||
void createProgram(const ShaderRequirements& reqs, osg::Node& node);
|
||||
void createProgram(const ShaderRequirements& reqs);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue