]> git.mxchange.org Git - simgear.git/commitdiff
Remove exceptions on missing texture names
authorJames Turner <zakalawe@mac.com>
Mon, 11 Nov 2013 07:02:10 +0000 (23:02 -0800)
committerJames Turner <zakalawe@mac.com>
Tue, 12 Nov 2013 22:23:09 +0000 (22:23 +0000)
simgear/scene/material/TextureBuilder.cxx

index da788d6e62adc089f552416dcb264b2456b22446..7858ea27502e9a4dde864ca046e642a6995e6667 100644 (file)
@@ -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<osg::Image> 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<osg::Image> 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<typename T>
 class TexBuilder : public TextureBuilder
@@ -300,7 +303,9 @@ Texture* TexBuilder<T>::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