Removed log2 and replaced the places where is was used with a new Image::computeNumberOfMipmapLevels method.
This commit is contained in:
@@ -234,6 +234,7 @@ class OSG_EXPORT Image : public Object
|
||||
static unsigned int computePixelSizeInBits(GLenum pixelFormat,GLenum type);
|
||||
static unsigned int computeRowWidthInBytes(int width,GLenum pixelFormat,GLenum type,int packing);
|
||||
static int computeNearestPowerOfTwo(int s,float bias=0.5f);
|
||||
static int computeNumberOfMipmapLevels(int s,int t = 1, int r = 1);
|
||||
|
||||
/** Precomputed mipmaps stuff. */
|
||||
typedef std::vector< unsigned int > MipmapDataType;
|
||||
|
||||
@@ -194,11 +194,6 @@ inline double RadiansToDegrees(double angle) { return angle*180.0/PI; }
|
||||
inline float round(float v) { return v>=0.0f?floorf(v+0.5f):ceilf(v-0.5f); }
|
||||
inline double round(double v) { return v>=0.0?floor(v+0.5):ceil(v-0.5); }
|
||||
|
||||
inline float log2(float v) { return logf(v) * static_cast<float>(INVLN_2); }
|
||||
inline double log2(double v) { return log(v) * INVLN_2; }
|
||||
inline float log2(int v) { return log2(static_cast<float>(v)); }
|
||||
inline float log2(unsigned int v) { return log2(static_cast<float>(v)); }
|
||||
|
||||
#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MWERKS__)
|
||||
inline bool isNaN(float v) { return _isnan(v)!=0; }
|
||||
inline bool isNaN(double v) { return _isnan(v)!=0; }
|
||||
|
||||
@@ -429,6 +429,13 @@ int Image::computeNearestPowerOfTwo(int s,float bias)
|
||||
return s;
|
||||
}
|
||||
|
||||
int Image::computeNumberOfMipmapLevels(int s,int t, int r)
|
||||
{
|
||||
int w = maximum(s, t);
|
||||
w = maximum(w, r);
|
||||
return 1 + static_cast<int>(floor(logf(w)/logf(2.0f)));
|
||||
}
|
||||
|
||||
unsigned int Image::getTotalSizeInBytesIncludingMipmaps() const
|
||||
{
|
||||
if (_mipmapData.empty())
|
||||
|
||||
@@ -414,7 +414,7 @@ void Texture1D::allocateMipmap(State& state) const
|
||||
|
||||
// compute number of mipmap levels
|
||||
int width = _textureWidth;
|
||||
int numMipmapLevels = 1 + (int)floor(log2(width));
|
||||
int numMipmapLevels = Image::computeNumberOfMipmapLevels(width);
|
||||
|
||||
// we do not reallocate the level 0, since it was already allocated
|
||||
width >>= 1;
|
||||
|
||||
@@ -408,7 +408,7 @@ void Texture2D::allocateMipmap(State& state) const
|
||||
// compute number of mipmap levels
|
||||
int width = _textureWidth;
|
||||
int height = _textureHeight;
|
||||
int numMipmapLevels = 1 + (int)floor(log2(maximum(width, height)));
|
||||
int numMipmapLevels = Image::computeNumberOfMipmapLevels(width, height);
|
||||
|
||||
// we do not reallocate the level 0, since it was already allocated
|
||||
width >>= 1;
|
||||
|
||||
@@ -464,7 +464,7 @@ void Texture2DArray::allocateMipmap(State& state) const
|
||||
// compute number of mipmap levels
|
||||
int width = _textureWidth;
|
||||
int height = _textureHeight;
|
||||
int numMipmapLevels = 1 + (int)floor(log2(maximum(width, height)));
|
||||
int numMipmapLevels = Image::computeNumberOfMipmapLevels(width, height);
|
||||
|
||||
// we do not reallocate the level 0, since it was already allocated
|
||||
width >>= 1;
|
||||
|
||||
@@ -456,7 +456,7 @@ void Texture3D::allocateMipmap(State& state) const
|
||||
int width = _textureWidth;
|
||||
int height = _textureHeight;
|
||||
int depth = _textureDepth;
|
||||
int numMipmapLevels = 1 + (int)floor(log2(maximum(width, maximum(depth, height))));
|
||||
int numMipmapLevels = Image::computeNumberOfMipmapLevels(width, height, depth);
|
||||
|
||||
// we do not reallocate the level 0, since it was already allocated
|
||||
width >>= 1;
|
||||
|
||||
@@ -384,7 +384,7 @@ void TextureCubeMap::allocateMipmap(State& state) const
|
||||
// compute number of mipmap levels
|
||||
int width = _textureWidth;
|
||||
int height = _textureHeight;
|
||||
int numMipmapLevels = 1 + (int)floor(log2(maximum(width, height)));
|
||||
int numMipmapLevels = Image::computeNumberOfMipmapLevels(width, height);
|
||||
|
||||
// we do not reallocate the level 0, since it was already allocated
|
||||
width >>= 1;
|
||||
|
||||
@@ -357,6 +357,10 @@ BEGIN_OBJECT_REFLECTOR(osg::Image)
|
||||
__int__computeNearestPowerOfTwo__int__float_S,
|
||||
"",
|
||||
"");
|
||||
I_StaticMethodWithDefaults3(int, computeNumberOfMipmapLevels, IN, int, s, , IN, int, t, 1, IN, int, r, 1,
|
||||
__int__computeNumberOfMipmapLevels__int__int__int_S,
|
||||
"",
|
||||
"");
|
||||
I_ProtectedMethod0(void, deallocateData,
|
||||
Properties::NON_VIRTUAL,
|
||||
Properties::NON_CONST,
|
||||
|
||||
Reference in New Issue
Block a user