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)
|
, 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)
|
||||||
|
|
|
@ -52,7 +52,7 @@ namespace Shader
|
||||||
|
|
||||||
void applyStateSet(osg::ref_ptr<osg::StateSet> stateset, osg::Node& node);
|
void applyStateSet(osg::ref_ptr<osg::StateSet> stateset, osg::Node& node);
|
||||||
|
|
||||||
void pushRequirements();
|
void pushRequirements(osg::Node& node);
|
||||||
void popRequirements();
|
void popRequirements();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -89,13 +89,16 @@ namespace Shader
|
||||||
|
|
||||||
// -1 == no tangents required
|
// -1 == no tangents required
|
||||||
int mTexStageRequiringTangents;
|
int mTexStageRequiringTangents;
|
||||||
|
|
||||||
|
// the Node that requested these requirements
|
||||||
|
osg::Node* mNode;
|
||||||
};
|
};
|
||||||
std::vector<ShaderRequirements> mRequirements;
|
std::vector<ShaderRequirements> mRequirements;
|
||||||
|
|
||||||
std::string mDefaultVsTemplate;
|
std::string mDefaultVsTemplate;
|
||||||
std::string mDefaultFsTemplate;
|
std::string mDefaultFsTemplate;
|
||||||
|
|
||||||
void createProgram(const ShaderRequirements& reqs, osg::Node& node);
|
void createProgram(const ShaderRequirements& reqs);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue