]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/material/mipmap.cxx
Work around apparent OSG 3.2.0 normal binding bug.
[simgear.git] / simgear / scene / material / mipmap.cxx
index dedc62808f3f9d97de5f063eeef62a24ac76e43d..59a800daaee2334531dea116e0459673f1b87972 100644 (file)
@@ -22,6 +22,7 @@
 #include "EffectBuilder.hxx"
 
 #include <limits>
+#include <iomanip>
 
 #include <osg/Image>
 #include <osg/Vec4>
@@ -43,7 +44,7 @@ EffectNameValue<MipMapFunction> mipmapFunctionsInit[] =
 EffectPropertyMap<MipMapFunction> mipmapFunctions(mipmapFunctionsInit);
 
 MipMapTuple makeMipMapTuple(Effect* effect, const SGPropertyNode* props,
-                      const SGReaderWriterXMLOptions* options)
+                      const SGReaderWriterOptions* options)
 {
     const SGPropertyNode* pMipmapR
         = getEffectPropertyChild(effect, props, "function-r");
@@ -208,6 +209,7 @@ osg::Vec4::value_type computeComponent( int c, osg::Vec4 colors[2][2][2], bool c
     case PRODUCT: return computeProduct( c, colors, colorValid );
     case MIN: return computeMin( c, colors, colorValid );
     case MAX: return computeMax( c, colors, colorValid );
+    default: break;
     }
     return 0;
 }
@@ -226,6 +228,42 @@ osg::Vec4 computeColor( osg::Vec4 colors[2][2][2], bool colorValid[2][2][2], Mip
     return result;
 }
 
+void dumpMipmap( std::string n, int s, int t, int r, int c, unsigned char *d, const osg::Image::MipmapDataType &o )
+{
+    std::ofstream ofs( (n + ".dump").c_str() );
+    for ( osg::Image::MipmapDataType::size_type i = 0; i < o.size()+1; ++i )
+    {
+        ofs << s << " " << t << " " << r << std::endl;
+        unsigned int offset = 0;
+        if ( i > 0 )
+            offset = o[i-1];
+        unsigned char *p = &d[offset];
+        for ( int l = 0; l < r; ++l )
+        {
+            for ( int k = 0; k < t; ++k )
+            {
+                for ( int j = 0; j < s; ++j )
+                {
+                    ofs << "(";
+                    for ( int m = 0; m < c; ++m )
+                    {
+                        if ( m != 0 )
+                            ofs << " ";
+                        ofs << std::setw(3) << (unsigned int)*p++;
+                    }
+                    ofs << ")";
+                }
+                ofs << std::endl;
+            }
+            ofs << std::endl;
+        }
+        ofs << std::endl;
+        s >>= 1; if ( s == 0 ) s = 1;
+        t >>= 1; if ( t == 0 ) t = 1;
+        r >>= 1; if ( r == 0 ) r = 1;
+    }
+}
+
 osg::Image* computeMipmap( osg::Image* image, MipMapTuple attrs )
 {
     bool computeMipmap = false;
@@ -349,6 +387,7 @@ osg::Image* computeMipmap( osg::Image* image, MipMapTuple attrs )
             t = nt;
             r = nr;
         }
+        //dumpMipmap( image->getFileName(), image->s(), image->t(), image->r(), osg::Image::computeNumComponents(image->getPixelFormat()), data, mipmapOffsets );
         mipmaps->setImage( image->s(), image->t(), image->r(), 
             image->getInternalTextureFormat(), image->getPixelFormat(),
             image->getDataType(), data, osg::Image::USE_NEW_DELETE, image->getPacking() );