I was summoned so I respond. Version of DDS plugin before my additions was
using this code to compute number of mipmaps (see revision 10369 of
ReaderWriterDDS.cpp ):
//debugging messages
> float power2_s = logf((float)s)/logf((float)2);
> float power2_t = logf((float)t)/logf((float)2);
> osg::notify(osg::INFO) << "ReadDDSFile INFO : ddsd.dwMipMapCount =
> "<<ddsd.dwMipMapCount<<std::endl;
> osg::notify(osg::INFO) << "ReadDDSFile INFO : s = "<<s<<std::endl;
> osg::notify(osg::INFO) << "ReadDDSFile INFO : t = "<<t<<std::endl;
> osg::notify(osg::INFO) << "ReadDDSFile INFO :
> power2_s="<<power2_s<<std::endl;
> osg::notify(osg::INFO) << "ReadDDSFile INFO :
> power2_t="<<power2_t<<std::endl;
> mipmaps.resize((unsigned int)osg::maximum(power2_s,power2_t),0);
>
>
I replaced above with call to osg::Image::computeNumberOfMipmapLevels
because this was the same math. But I also encountered problems with
memory access errors with DDS files which did not contain full mipmap chain
(with 3D Volume textures mostly) and then I added line which updates
numOfMipmaps if file have lower number than theoretical number.
Hope that explanation excludes me from the list of people to blame ;-). I
agree that probably using number of mipmaps from file ignoring theoretical
number could be the best idea. However, if log function does not work as it
should, it has to be fixed as highest priority as its used in many other
places in OSG.
On a side note: I was always surprised by use of floating point math in
mipmap number computation:
logf((float)s)/logf((float)2);
I would rather use folowing fixed point code instead (which would avoid log
problem entirely):
num_mipmaps = 1 + max( MostSignificantBit( width ), MostSignificantBit(
height ) );
with
int MostSignifcantBit( unsigned int i )
{
if( i == 0 )
return -1
int bit = 0;
if( i >= 0x10000 ) { bit += 16; i >>= 16; }
if( i >= 0x100 ) { bit += 8; i >>= 8; }
if( i >= 0x10 ) { bit += 4; i >>= 4; }
if( i >= 0x4 ) { bit += 2; i >>= 2; }
if( i >= 0x2 ) { bit += 1; i >>= 1; }
return bit;
}
Cheers,
Wojtek
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org