forked from teamnwah/openmw-tes3coop
Reduce the number of osg::Material state by setting the default state on the graph root
This commit is contained in:
parent
e399e10607
commit
960d4a96c3
3 changed files with 23 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
|||
#include <osgViewer/CompositeViewer>
|
||||
#include <osgViewer/ViewerEventHandlers>
|
||||
#include <osg/LightModel>
|
||||
#include <osg/Material>
|
||||
#include <osg/Version>
|
||||
|
||||
#include <components/resource/scenemanager.hpp>
|
||||
|
@ -74,6 +75,12 @@ RenderWidget::RenderWidget(QWidget *parent, Qt::WindowFlags f)
|
|||
|
||||
mView->getCamera()->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||
mView->getCamera()->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
osg::ref_ptr<osg::Material> defaultMat (new osg::Material);
|
||||
defaultMat->setColorMode(osg::Material::OFF);
|
||||
defaultMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1));
|
||||
defaultMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1));
|
||||
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||
mView->getCamera()->getOrCreateStateSet()->getOrCreateStateSet()->setAttribute(defaultMat);
|
||||
|
||||
mView->setSceneData(mRootNode);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <osg/Light>
|
||||
#include <osg/LightModel>
|
||||
#include <osg/Fog>
|
||||
#include <osg/Material>
|
||||
#include <osg/PolygonMode>
|
||||
#include <osg/Group>
|
||||
#include <osg/UserDataContainer>
|
||||
|
@ -221,6 +222,12 @@ namespace MWRender
|
|||
sceneRoot->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::ON);
|
||||
sceneRoot->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::ON);
|
||||
sceneRoot->getOrCreateStateSet()->setMode(GL_NORMALIZE, osg::StateAttribute::ON);
|
||||
osg::ref_ptr<osg::Material> defaultMat (new osg::Material);
|
||||
defaultMat->setColorMode(osg::Material::OFF);
|
||||
defaultMat->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1));
|
||||
defaultMat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1,1,1,1));
|
||||
defaultMat->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4f(0.f, 0.f, 0.f, 0.f));
|
||||
sceneRoot->getOrCreateStateSet()->setAttribute(defaultMat);
|
||||
|
||||
sceneRoot->setNodeMask(Mask_Scene);
|
||||
sceneRoot->setName("Scene Root");
|
||||
|
|
|
@ -1758,6 +1758,15 @@ namespace NifOsg
|
|||
mat->setColorMode(osg::Material::AMBIENT);
|
||||
}
|
||||
|
||||
if (mat->getColorMode() == osg::Material::OFF
|
||||
&& mat->getDiffuse(osg::Material::FRONT_AND_BACK) == osg::Vec4f(1,1,1,1)
|
||||
&& mat->getAmbient(osg::Material::FRONT_AND_BACK) == osg::Vec4f(1,1,1,1)
|
||||
&& mat->getSpecular(osg::Material::FRONT_AND_BACK) == osg::Vec4f(0.f, 0.f, 0.f, 0.f))
|
||||
{
|
||||
// default state, skip
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: this could be replaced by a more generic mechanism of sharing any type of State Attribute
|
||||
// apply only for Materials for now
|
||||
mat = shareMaterial(mat);
|
||||
|
|
Loading…
Reference in a new issue