Hi everyone,
I have read about how to set uniforms in a node cullcallback.
Code:
class LightingCullCallback : public osg::NodeCallback
{
std::unordered_map<osgUtil::CullVisitor*, osg::ref_ptr<osg::StateSet>>
mCullVisitorStateSetMap;
public:
LightingCullCallback (int maxLightNb){}
virtual void operator() (osg::Node* node, osg::NodeVisitor* nv)
{
osgUtil::CullVisitor* pCullVisitor =
dynamic_cast<osgUtil::CullVisitor*>(nv);
if (pCullVisitor)
{
std::unordered_map<osgUtil::CullVisitor*,
osg::ref_ptr<osg::StateSet>>::iterator itStateSet =
mCullVisitorStateSetMap.find(pCullVisitor);
osg::ref_ptr<osg::StateSet> pStateSet = NULL;
if (itStateSet != mCullVisitorStateSetMap.end())
{
pStateSet = itStateSet->second;
}
else
{
pStateSet = new osg::StateSet;
InitUniform(pStateSet);
mCullVisitorStateSetMap.insert(std::make_pair(pCullVisitor, pStateSet));
}
UpdateUniform(pStateSet);
pCullVisitor->pushStateSet(pStateSet);
traverse(node, nv);
pCullVisitor->popStateSet();
}
}
};
I am looking for a similar way to do this with Drawable::CullCallback.
But as far as I understand traversal and stateset mechanisms, I can not find a
way to use pushStateSet and popStateSet in the Drawable::CullCallback.
I have tried to do this instead
Code:
struct SCameraStateSetMap
{
std::unordered_map<osg::Camera*, osg::ref_ptr<osg::StateSet>>
mCameraStateSetMap;
}
class LightingGeometryCullCallback : public osg::Drawable::CullCallback
{
SCameraStateSetMap* mpCameraStateSetMap;
public:
LightingGeometryCullCallback( SCameraStateSetMap* pCameraStateSetMap) :
mpCameraStateSetMap(pCameraStateSetMap) {}
virtual bool cull(osg::NodeVisitor* nv, osg::Drawable* drawable,
osg::RenderInfo* renderInfo) const
{
osgUtil::CullVisitor* pCullVisitor =
dynamic_cast<osgUtil::CullVisitor*>(nv);
if (pCullVisitor != NULL)
{
osg::Camera* pCamera = pCullVisitor->getCurrentCamera();
if (pCamera != NULL)
{
std::unordered_map<osg::Camera*,
osg::ref_ptr<osg::StateSet>>::iterator itStateSet =
mpCameraStateSetMap->mCameraStateSetMap.find(pCamera);
osg::ref_ptr<osg::StateSet> pStateSet = NULL;
if (itStateSet !=
mpCameraStateSetMap->mCameraStateSetMap.end())
{
pStateSet = itStateSet->second;
}
else
{
pStateSet = new osg::StateSet;
InitUniform(pStateSet);
mpCameraStateSetMap->mCameraStateSetMap.insert(std::make_pair(pCamera,
pStateSet));
}
UpdateUniform(pStateSet);
return IsCulled(drawable);
}
}
return true;
}
};
class LightingGeometryDrawCallback : public osg::Drawable::DrawCallback
{
SCameraStateSetMap* mpCameraStateSetMap;
public:
LightingGeometryDrawCallback( SCameraStateSetMap* pCameraStateSetMap) :
mpCameraStateSetMap(pCameraStateSetMap) {}
virtual void drawImplementation(osg::RenderInfo& renderInfo, const
osg::Drawable* drawable) const
{
osg::Camera* pCamera = renderInfo.getCurrentCamera();
if (pCamera != NULL)
{
std::unordered_map<osg::Camera*,
osg::ref_ptr<osg::StateSet>>::iterator itStateSet =
mpCameraStateSetMap->mCameraStateSetMap.find(pCamera);
if (itStateSet !=
mpCameraStateSetMap->mCameraStateSetMap.end())
{
renderInfo.getState()->pushStateSet(pStateSet);
renderInfo.getState()->apply();
drawable->drawImplementation(renderInfo);
renderInfo.getState()->popStateSet();
renderInfo.getState()->apply();
}
else
{
drawable->drawImplementation(renderInfo);
}
}
}
};
But not successful. Do I have a chance to get this work this way? Or another?
Thanks for taking the time to read.
Cheers,
Olivier[/code]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61463#61463
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org