Hi all,

I have investigated a little deeper the problem... Indeed, on Windows platform, the number of mipmaps returned by osg::Image::computeNumberOfMipmapLevels( s, t, r ) is wrong, but it is correct on Linux platforms for the same dds file...
Here is attached a little test program that explains why (it is more or less a computeNumberOfMipmapLevels with s=t=1024 and r=1), and it is not linked to OSG. Compile it on Windows 32 bits (works on Win7 and WinXP) (g++ main.cpp -o main.exe) You will see the following result :

logf(wf)                   = 6.93147182464599609375
log(wd)                    = 6.93147180559945308431
logf(2.0f)                 = 0.69314718246459960938
log(2.0)                   = 0.69314718055994528623
logf(wf)/logf(2.0f)        = 10.00000000000000000000
log(wd)/log(2.0)           = 10.00000000000000000000
floor(logf(wf)/logf(2.0f)) = 9.00000000000000000000 -> Here is the error, it should be 10 too...
floor(log(wd)/log(2.0))    = 10.00000000000000000000
floor(testf)               = 10.00000000000000000000
floor(testd)               = 10.00000000000000000000

Replacing the include of math.h by cmath results in :

logf(wf)                   = 6.93147182464599609375
log(wd)                    = 6.93147180559945308431
logf(2.0f)                 = 0.69314718246459960938
log(2.0)                   = 0.69314718055994528623
logf(wf)/logf(2.0f)        = 10.00000000000000000000
log(wd)/log(2.0)           = 10.00000000000000000000
floor(logf(wf)/logf(2.0f)) = 10.00000000000000000000
floor(log(wd)/log(2.0))    = 10.00000000000000000000
floor(testf)               = 10.00000000000000000000
floor(testd)               = 10.00000000000000000000

Under Linux both solutions give the second results.
The problem is that osg/Math includes math.h and not cmath. I don't know which would be the best solution :
  • Replace math.h by cmath in include/osg/Math
  • Store the logf division (float testf = logf(wf)/logf(2.0f)) of osg::Image::computeNumberOfMipmapLevels( s, t, r ) in a float before computing the floor.

Up to the list to give the answer...

PS : this is also the solution to the discussion "osgPlugins : dds problem on windows platform" I launched 07/03/2011

Cheers,

Christian Schulte




Le 20/12/2012 15:15, Lukasz Izdebski a écrit :
Hi,
i probably have solution for this problem, i have found a bug in dds plugin
ReaderWriterDDS.cpp
Line 633
unsigned numMipmaps = osg::Image::computeNumberOfMipmapLevels( s, t, r );

when compute numMipmaps returns wrong number. this number is less then number of mipmaps in dds file( ddsd.dwMipMapCount ) . This bug makes that when dds mipmaps are loaded to opengl last mipmap (4x4) isn't loaded. and with combination with LINEAR_MIPMAP_LINEAR make this bug.


the numMipmaps should be taken form ddsd.dwMipMapCount


in attachment i send a corrected version of file.
... 

Thank you!

Cheers,
Lukasz

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=51653#51653




Attachments: 
http://forum.openscenegraph.org//files/readerwriterdds_204.cpp


_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


#include <math.h>
#include <stdio.h>
#include <iostream>

using namespace std;

int main(int argc, char** argv)
{
        double wd=1024.0;
        float  wf=1024.0;
        cout.precision(20);
        cout.setf(ios::fixed,ios::floatfield);
        cout<<"logf(wf)                   = "<<logf(wf)<<endl;
        cout<<"log(wd)                    = "<<log(wd)<<endl;
        cout<<"logf(2.0f)                 = "<<logf(2.0f)<<endl;
        cout<<"log(2.0)                   = "<<log(2.0)<<endl;
        cout<<"logf(wf)/logf(2.0f)        = "<<logf(wf)/logf(2.0f)<<endl;
        cout<<"log(wd)/log(2.0)           = "<<log(wd)/log(2.0)<<endl;
        cout<<"floor(logf(wf)/logf(2.0f)) = "<<floor(logf(wf)/logf(2.0f))<<endl;
        cout<<"floor(log(wd)/log(2.0))    = "<<floor(log(wd)/log(2.0))<<endl;
        float testf = logf(wf)/logf(2.0f);
        double testd = log(wd)/log(2.0);
        cout<<"floor(testf)               = "<<floor(testf)<<endl;
        cout<<"floor(testd)               = "<<floor(testd)<<endl;
        return 0;
}
_______________________________________________
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to