From: James Turner Date: Mon, 11 Nov 2013 07:02:10 +0000 (-0800) Subject: Remove exceptions on missing texture names X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=8753811fe186344e4178e494d227804907df5fe8;p=simgear.git Remove exceptions on missing texture names --- diff --git a/simgear/scene/material/TextureBuilder.cxx b/simgear/scene/material/TextureBuilder.cxx index da788d6e..7858ea27 100644 --- a/simgear/scene/material/TextureBuilder.cxx +++ b/simgear/scene/material/TextureBuilder.cxx @@ -233,44 +233,47 @@ TexTuple makeTexTuple(Effect* effect, const SGPropertyNode* props, texType, mipmapFunctions); } -void setAttrs(const TexTuple& attrs, Texture* tex, +bool setAttrs(const TexTuple& attrs, Texture* tex, const SGReaderWriterOptions* options) { const string& imageName = attrs.get<0>(); - if (imageName.empty()) { - throw BuilderException("no image file"); - } else { - osgDB::ReaderWriter::ReadResult result; - result = osgDB::readImageFile(imageName, options); - osg::ref_ptr image; - if (result.success()) - image = result.getImage(); - if (image.valid()) - { - image = computeMipmap( image.get(), attrs.get<7>() ); - tex->setImage(GL_FRONT_AND_BACK, image.get()); - int s = image->s(); - int t = image->t(); - if (s <= t && 32 <= s) { - SGSceneFeatures::instance()->setTextureCompression(tex); - } else if (t < s && 32 <= t) { - SGSceneFeatures::instance()->setTextureCompression(tex); - } - tex->setMaxAnisotropy(SGSceneFeatures::instance() - ->getTextureFilter()); - } else { - SG_LOG(SG_INPUT, SG_ALERT, "failed to load effect texture file " - << imageName); + if (imageName.empty()) + return false; + + osgDB::ReaderWriter::ReadResult result; + result = osgDB::readImageFile(imageName, options); + osg::ref_ptr image; + if (result.success()) + image = result.getImage(); + if (image.valid()) + { + image = computeMipmap( image.get(), attrs.get<7>() ); + tex->setImage(GL_FRONT_AND_BACK, image.get()); + int s = image->s(); + int t = image->t(); + if (s <= t && 32 <= s) { + SGSceneFeatures::instance()->setTextureCompression(tex); + } else if (t < s && 32 <= t) { + SGSceneFeatures::instance()->setTextureCompression(tex); } + tex->setMaxAnisotropy(SGSceneFeatures::instance() + ->getTextureFilter()); + } else { + SG_LOG(SG_INPUT, SG_ALERT, "failed to load effect texture file " + << imageName); + return false; } + // texture->setDataVariance(osg::Object::STATIC); tex->setFilter(Texture::MIN_FILTER, attrs.get<1>()); tex->setFilter(Texture::MAG_FILTER, attrs.get<2>()); tex->setWrap(Texture::WRAP_S, attrs.get<3>()); tex->setWrap(Texture::WRAP_T, attrs.get<4>()); tex->setWrap(Texture::WRAP_R, attrs.get<5>()); + return true; } -} + +} // of anonymous namespace template class TexBuilder : public TextureBuilder @@ -300,7 +303,9 @@ Texture* TexBuilder::build(Effect* effect, Pass* pass, const SGPropertyNode* } tex = new T; - setAttrs(attrs, tex, options); + if (!setAttrs(attrs, tex, options)) + return NULL; + if (itr == texMap.end()) texMap.insert(make_pair(attrs, tex)); else