Sprinkle const-correctness in NifLoader

pull/3236/head
Alexei Kotov 2 months ago
parent 27f52d27b9
commit b71ec84004

@ -535,7 +535,7 @@ namespace NifOsg
return nullptr; return nullptr;
} }
bool handleEffect(const Nif::NiAVObject* nifNode, osg::StateSet* stateset) bool handleEffect(const Nif::NiAVObject* nifNode, osg::StateSet* stateset) const
{ {
if (nifNode->recType != Nif::RC_NiTextureEffect) if (nifNode->recType != Nif::RC_NiTextureEffect)
{ {
@ -592,7 +592,7 @@ namespace NifOsg
} }
// Get a default dataVariance for this node to be used as a hint by optimization (post)routines // Get a default dataVariance for this node to be used as a hint by optimization (post)routines
osg::ref_ptr<osg::Group> createNode(const Nif::NiAVObject* nifNode) static osg::ref_ptr<osg::Group> createNode(const Nif::NiAVObject* nifNode)
{ {
osg::ref_ptr<osg::Group> node; osg::ref_ptr<osg::Group> node;
osg::Object::DataVariance dataVariance = osg::Object::UNSPECIFIED; osg::Object::DataVariance dataVariance = osg::Object::UNSPECIFIED;
@ -863,7 +863,7 @@ namespace NifOsg
return node; return node;
} }
void handleMeshControllers(const Nif::NiAVObject* nifNode, osg::Node* node, static void handleMeshControllers(const Nif::NiAVObject* nifNode, osg::Node* node,
SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures, SceneUtil::CompositeStateSetUpdater* composite, const std::vector<unsigned int>& boundTextures,
int animflags) int animflags)
{ {
@ -891,7 +891,8 @@ namespace NifOsg
} }
} }
void handleNodeControllers(const Nif::NiAVObject* nifNode, osg::Node* node, int animflags, bool& isAnimated) void handleNodeControllers(
const Nif::NiAVObject* nifNode, osg::Node* node, int animflags, bool& isAnimated) const
{ {
for (Nif::NiTimeControllerPtr ctrl = nifNode->mController; !ctrl.empty(); ctrl = ctrl->mNext) for (Nif::NiTimeControllerPtr ctrl = nifNode->mController; !ctrl.empty(); ctrl = ctrl->mNext)
{ {
@ -969,7 +970,7 @@ namespace NifOsg
} }
void handleMaterialControllers(const Nif::NiProperty* materialProperty, void handleMaterialControllers(const Nif::NiProperty* materialProperty,
SceneUtil::CompositeStateSetUpdater* composite, int animflags, const osg::Material* baseMaterial) SceneUtil::CompositeStateSetUpdater* composite, int animflags, const osg::Material* baseMaterial) const
{ {
for (Nif::NiTimeControllerPtr ctrl = materialProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext) for (Nif::NiTimeControllerPtr ctrl = materialProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext)
{ {
@ -1026,8 +1027,9 @@ namespace NifOsg
VFS::Path::toNormalized(Misc::ResourceHelpers::correctTexturePath(path, mImageManager->getVFS()))); VFS::Path::toNormalized(Misc::ResourceHelpers::correctTexturePath(path, mImageManager->getVFS())));
} }
osg::ref_ptr<osg::Texture2D> attachTexture(const std::string& name, osg::ref_ptr<osg::Image> image, bool wrapS, static osg::ref_ptr<osg::Texture2D> attachTexture(const std::string& name, osg::ref_ptr<osg::Image> image,
bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset,
std::vector<unsigned int>& boundTextures)
{ {
osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D(image); osg::ref_ptr<osg::Texture2D> texture2d = new osg::Texture2D(image);
if (image) if (image)
@ -1047,14 +1049,14 @@ namespace NifOsg
} }
osg::ref_ptr<osg::Texture2D> attachExternalTexture(const std::string& name, const std::string& path, bool wrapS, osg::ref_ptr<osg::Texture2D> attachExternalTexture(const std::string& name, const std::string& path, bool wrapS,
bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) bool wrapT, unsigned int uvSet, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) const
{ {
return attachTexture(name, getTextureImage(path), wrapS, wrapT, uvSet, stateset, boundTextures); return attachTexture(name, getTextureImage(path), wrapS, wrapT, uvSet, stateset, boundTextures);
} }
osg::ref_ptr<osg::Texture2D> attachNiSourceTexture(const std::string& name, const Nif::NiSourceTexture* st, osg::ref_ptr<osg::Texture2D> attachNiSourceTexture(const std::string& name, const Nif::NiSourceTexture* st,
bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset, bool wrapS, bool wrapT, unsigned int uvSet, osg::StateSet* stateset,
std::vector<unsigned int>& boundTextures) std::vector<unsigned int>& boundTextures) const
{ {
return attachTexture(name, handleSourceTexture(st), wrapS, wrapT, uvSet, stateset, boundTextures); return attachTexture(name, handleSourceTexture(st), wrapS, wrapT, uvSet, stateset, boundTextures);
} }
@ -1070,7 +1072,7 @@ namespace NifOsg
} }
void handleTextureControllers(const Nif::NiProperty* texProperty, void handleTextureControllers(const Nif::NiProperty* texProperty,
SceneUtil::CompositeStateSetUpdater* composite, osg::StateSet* stateset, int animflags) SceneUtil::CompositeStateSetUpdater* composite, osg::StateSet* stateset, int animflags) const
{ {
for (Nif::NiTimeControllerPtr ctrl = texProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext) for (Nif::NiTimeControllerPtr ctrl = texProperty->mController; !ctrl.empty(); ctrl = ctrl->mNext)
{ {
@ -1122,7 +1124,7 @@ namespace NifOsg
void handleParticlePrograms(Nif::NiParticleModifierPtr modifier, Nif::NiParticleModifierPtr collider, void handleParticlePrograms(Nif::NiParticleModifierPtr modifier, Nif::NiParticleModifierPtr collider,
osg::Group* attachTo, osgParticle::ParticleSystem* partsys, osg::Group* attachTo, osgParticle::ParticleSystem* partsys,
osgParticle::ParticleProcessor::ReferenceFrame rf) osgParticle::ParticleProcessor::ReferenceFrame rf) const
{ {
osgParticle::ModularProgram* program = new osgParticle::ModularProgram; osgParticle::ModularProgram* program = new osgParticle::ModularProgram;
attachTo->addChild(program); attachTo->addChild(program);
@ -1189,7 +1191,7 @@ namespace NifOsg
// Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and // Load the initial state of the particle system, i.e. the initial particles and their positions, velocity and
// colors. // colors.
void handleParticleInitialState( static void handleParticleInitialState(
const Nif::NiAVObject* nifNode, ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl) const Nif::NiAVObject* nifNode, ParticleSystem* partsys, const Nif::NiParticleSystemController* partctrl)
{ {
auto particleNode = static_cast<const Nif::NiParticles*>(nifNode); auto particleNode = static_cast<const Nif::NiParticles*>(nifNode);
@ -1245,7 +1247,7 @@ namespace NifOsg
partsys->setInitialBound(box); partsys->setInitialBound(box);
} }
osg::ref_ptr<Emitter> handleParticleEmitter(const Nif::NiParticleSystemController* partctrl) static osg::ref_ptr<Emitter> handleParticleEmitter(const Nif::NiParticleSystemController* partctrl)
{ {
std::vector<int> targets; std::vector<int> targets;
if (partctrl->recType == Nif::RC_NiBSPArrayController && !partctrl->emitAtVertex()) if (partctrl->recType == Nif::RC_NiBSPArrayController && !partctrl->emitAtVertex())
@ -1743,7 +1745,7 @@ namespace NifOsg
parentNode->addChild(drawable); parentNode->addChild(drawable);
} }
osg::BlendFunc::BlendFuncMode getBlendMode(int mode) osg::BlendFunc::BlendFuncMode getBlendMode(int mode) const
{ {
switch (mode) switch (mode)
{ {
@ -1775,7 +1777,7 @@ namespace NifOsg
} }
} }
osg::AlphaFunc::ComparisonFunction getTestMode(int mode) osg::AlphaFunc::ComparisonFunction getTestMode(int mode) const
{ {
switch (mode) switch (mode)
{ {
@ -1801,7 +1803,7 @@ namespace NifOsg
} }
} }
osg::Stencil::Function getStencilFunction(Nif::NiStencilProperty::TestFunc func) osg::Stencil::Function getStencilFunction(Nif::NiStencilProperty::TestFunc func) const
{ {
using TestFunc = Nif::NiStencilProperty::TestFunc; using TestFunc = Nif::NiStencilProperty::TestFunc;
switch (func) switch (func)
@ -1829,7 +1831,7 @@ namespace NifOsg
} }
} }
osg::Stencil::Operation getStencilOperation(Nif::NiStencilProperty::Action op) osg::Stencil::Operation getStencilOperation(Nif::NiStencilProperty::Action op) const
{ {
using Action = Nif::NiStencilProperty::Action; using Action = Nif::NiStencilProperty::Action;
switch (op) switch (op)
@ -2002,7 +2004,7 @@ namespace NifOsg
return texEnv; return texEnv;
} }
void handleDepthFlags(osg::StateSet* stateset, bool depthTest, bool depthWrite) static void handleDepthFlags(osg::StateSet* stateset, bool depthTest, bool depthWrite)
{ {
if (!depthWrite && !depthTest) if (!depthWrite && !depthTest)
{ {
@ -2019,7 +2021,7 @@ namespace NifOsg
void handleTextureProperty(const Nif::NiTexturingProperty* texprop, const std::string& nodeName, void handleTextureProperty(const Nif::NiTexturingProperty* texprop, const std::string& nodeName,
osg::StateSet* stateset, SceneUtil::CompositeStateSetUpdater* composite, osg::StateSet* stateset, SceneUtil::CompositeStateSetUpdater* composite,
std::vector<unsigned int>& boundTextures, int animflags) std::vector<unsigned int>& boundTextures, int animflags) const
{ {
// overriding a parent NiTexturingProperty, so remove what was previously bound // overriding a parent NiTexturingProperty, so remove what was previously bound
clearBoundTextures(stateset, boundTextures); clearBoundTextures(stateset, boundTextures);
@ -2182,7 +2184,7 @@ namespace NifOsg
} }
void handleShaderMaterialNodeProperties( void handleShaderMaterialNodeProperties(
const Bgsm::MaterialFile* material, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) const Bgsm::MaterialFile* material, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) const
{ {
const unsigned int uvSet = 0; const unsigned int uvSet = 0;
const bool wrapS = material->wrapS(); const bool wrapS = material->wrapS();
@ -2222,7 +2224,7 @@ namespace NifOsg
handleDepthFlags(stateset, material->mDepthTest, material->mDepthWrite); handleDepthFlags(stateset, material->mDepthTest, material->mDepthWrite);
} }
void handleDecal(bool enabled, bool hasSortAlpha, osg::Node& node) void handleDecal(bool enabled, bool hasSortAlpha, osg::Node& node) const
{ {
if (!enabled) if (!enabled)
return; return;
@ -2236,7 +2238,7 @@ namespace NifOsg
stateset->setRenderBinDetails(1, "SORT_BACK_TO_FRONT"); stateset->setRenderBinDetails(1, "SORT_BACK_TO_FRONT");
} }
void handleAlphaTesting( static void handleAlphaTesting(
bool enabled, osg::AlphaFunc::ComparisonFunction function, int threshold, osg::Node& node) bool enabled, osg::AlphaFunc::ComparisonFunction function, int threshold, osg::Node& node)
{ {
if (enabled) if (enabled)
@ -2253,7 +2255,7 @@ namespace NifOsg
} }
void handleAlphaBlending( void handleAlphaBlending(
bool enabled, int sourceMode, int destMode, bool sort, bool& hasSortAlpha, osg::Node& node) bool enabled, int sourceMode, int destMode, bool sort, bool& hasSortAlpha, osg::Node& node) const
{ {
if (enabled) if (enabled)
{ {
@ -2288,8 +2290,8 @@ namespace NifOsg
} }
} }
void handleShaderMaterialDrawableProperties( void handleShaderMaterialDrawableProperties(const Bgsm::MaterialFile* shaderMat,
const Bgsm::MaterialFile* shaderMat, osg::ref_ptr<osg::Material> mat, osg::Node& node, bool& hasSortAlpha) osg::ref_ptr<osg::Material> mat, osg::Node& node, bool& hasSortAlpha) const
{ {
mat->setAlpha(osg::Material::FRONT_AND_BACK, shaderMat->mTransparency); mat->setAlpha(osg::Material::FRONT_AND_BACK, shaderMat->mTransparency);
handleAlphaTesting(shaderMat->mAlphaTest, osg::AlphaFunc::GREATER, shaderMat->mAlphaTestThreshold, node); handleAlphaTesting(shaderMat->mAlphaTest, osg::AlphaFunc::GREATER, shaderMat->mAlphaTestThreshold, node);
@ -2312,7 +2314,7 @@ namespace NifOsg
} }
void handleTextureSet(const Nif::BSShaderTextureSet* textureSet, bool wrapS, bool wrapT, void handleTextureSet(const Nif::BSShaderTextureSet* textureSet, bool wrapS, bool wrapT,
const std::string& nodeName, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) const std::string& nodeName, osg::StateSet* stateset, std::vector<unsigned int>& boundTextures) const
{ {
const unsigned int uvSet = 0; const unsigned int uvSet = 0;
@ -2653,9 +2655,9 @@ namespace NifOsg
// global sharing of State Attributes will reduce the number of GL calls as the osg::State will check by pointer // global sharing of State Attributes will reduce the number of GL calls as the osg::State will check by pointer
// to see if state is the same // to see if state is the same
template <class Attribute> template <class Attribute>
Attribute* shareAttribute(const osg::ref_ptr<Attribute>& attr) static Attribute* shareAttribute(const osg::ref_ptr<Attribute>& attr)
{ {
typedef std::set<osg::ref_ptr<Attribute>, CompareStateAttribute> Cache; using Cache = std::set<osg::ref_ptr<Attribute>, CompareStateAttribute>;
static Cache sCache; static Cache sCache;
static std::mutex sMutex; static std::mutex sMutex;
std::lock_guard<std::mutex> lock(sMutex); std::lock_guard<std::mutex> lock(sMutex);

Loading…
Cancel
Save