From 0f8f19958a4abfd9ccaba6ff4f58e7bbc4e6c302 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sat, 30 May 2015 04:26:00 +0200 Subject: [PATCH] NifLoader: Fix empty StateSets being created in some cases --- components/nifosg/nifloader.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/components/nifosg/nifloader.cpp b/components/nifosg/nifloader.cpp index 219f6e194..1f089f0c4 100644 --- a/components/nifosg/nifloader.cpp +++ b/components/nifosg/nifloader.cpp @@ -1075,8 +1075,6 @@ namespace NifOsg static void handleProperty(const Nif::Property *property, osg::Node *node, SceneUtil::CompositeStateSetUpdater* composite, Resource::TextureManager* textureManager, std::map& boundTextures, int animflags) { - osg::StateSet* stateset = node->getOrCreateStateSet(); - switch (property->recType) { case Nif::RC_NiStencilProperty: @@ -1095,6 +1093,7 @@ namespace NifOsg break; } + osg::StateSet* stateset = node->getOrCreateStateSet(); stateset->setAttribute(frontFace, osg::StateAttribute::ON); stateset->setMode(GL_CULL_FACE, stencilprop->data.drawMode == 3 ? osg::StateAttribute::OFF : osg::StateAttribute::ON); @@ -1117,7 +1116,7 @@ namespace NifOsg osg::PolygonMode* mode = new osg::PolygonMode; mode->setMode(osg::PolygonMode::FRONT_AND_BACK, wireprop->flags == 0 ? osg::PolygonMode::FILL : osg::PolygonMode::LINE); - stateset->setAttributeAndModes(mode, osg::StateAttribute::ON); + node->getOrCreateStateSet()->setAttributeAndModes(mode, osg::StateAttribute::ON); break; } case Nif::RC_NiZBufferProperty: @@ -1126,7 +1125,7 @@ namespace NifOsg // VER_MW doesn't support a DepthFunction according to NifSkope osg::Depth* depth = new osg::Depth; depth->setWriteMask((zprop->flags>>1)&1); - stateset->setAttributeAndModes(depth, osg::StateAttribute::ON); + node->getOrCreateStateSet()->setAttributeAndModes(depth, osg::StateAttribute::ON); break; } // OSG groups the material properties that NIFs have separate, so we have to parse them all again when one changed @@ -1141,6 +1140,7 @@ namespace NifOsg { const Nif::NiAlphaProperty* alphaprop = static_cast(property); osg::BlendFunc* blendfunc = new osg::BlendFunc; + osg::StateSet* stateset = node->getOrCreateStateSet(); if (alphaprop->flags&1) { blendfunc->setFunction(getBlendMode((alphaprop->flags>>1)&0xf), @@ -1174,6 +1174,7 @@ namespace NifOsg case Nif::RC_NiTexturingProperty: { const Nif::NiTexturingProperty* texprop = static_cast(property); + osg::StateSet* stateset = node->getOrCreateStateSet(); for (int i=0; itextures[i].inUse)