Commit 22f843a1 by Jamie Madill

Make a virtual method Texture::mipLevels to return the value of mip levels…

Make a virtual method Texture::mipLevels to return the value of mip levels defined as in the GL spec. Also known as the "q" function. TRAC #23961 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods
parent 2db197cd
...@@ -352,6 +352,11 @@ GLint Texture::creationLevels(GLsizei size) const ...@@ -352,6 +352,11 @@ GLint Texture::creationLevels(GLsizei size) const
return creationLevels(size, size); return creationLevels(size, size);
} }
int Texture::mipLevels() const
{
return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth()));
}
Texture2D::Texture2D(rx::Renderer *renderer, GLuint id) : Texture(renderer, id, GL_TEXTURE_2D) Texture2D::Texture2D(rx::Renderer *renderer, GLuint id) : Texture(renderer, id, GL_TEXTURE_2D)
{ {
mTexStorage = NULL; mTexStorage = NULL;
...@@ -731,10 +736,7 @@ bool Texture2D::isSamplerComplete(const SamplerState &samplerState) const ...@@ -731,10 +736,7 @@ bool Texture2D::isSamplerComplete(const SamplerState &samplerState) const
// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81. // Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
bool Texture2D::isMipmapComplete() const bool Texture2D::isMipmapComplete() const
{ {
GLsizei width = getBaseLevelWidth(); int q = mipLevels();
GLsizei height = getBaseLevelHeight();
int q = log2(std::max(width, height));
for (int level = 0; level <= q; level++) for (int level = 0; level <= q; level++)
{ {
...@@ -889,28 +891,28 @@ bool Texture2D::ensureRenderTarget() ...@@ -889,28 +891,28 @@ bool Texture2D::ensureRenderTarget()
void Texture2D::generateMipmaps() void Texture2D::generateMipmaps()
{ {
// Purge array levels 1 through q and reset them to represent the generated mipmap levels. // Purge array levels 1 through q and reset them to represent the generated mipmap levels.
unsigned int q = log2(std::max(getBaseLevelWidth(), getBaseLevelHeight())); int q = mipLevels();
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
redefineImage(i, getBaseLevelInternalFormat(), redefineImage(level, getBaseLevelInternalFormat(),
std::max(getBaseLevelWidth() >> i, 1), std::max(getBaseLevelWidth() >> level, 1),
std::max(getBaseLevelHeight() >> i, 1)); std::max(getBaseLevelHeight() >> level, 1));
} }
if (mTexStorage && mTexStorage->isRenderTarget()) if (mTexStorage && mTexStorage->isRenderTarget())
{ {
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
mTexStorage->generateMipmap(i); mTexStorage->generateMipmap(level);
mImageArray[i]->markClean(); mImageArray[level]->markClean();
} }
} }
else else
{ {
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
mRenderer->generateMipmap(mImageArray[i], mImageArray[i - 1]); mRenderer->generateMipmap(mImageArray[level], mImageArray[level - 1]);
} }
} }
} }
...@@ -1203,8 +1205,7 @@ bool TextureCubeMap::isMipmapCubeComplete() const ...@@ -1203,8 +1205,7 @@ bool TextureCubeMap::isMipmapCubeComplete() const
return false; return false;
} }
GLsizei size = getBaseLevelWidth(); int q = mipLevels();
int q = log2(size);
for (int face = 0; face < 6; face++) for (int face = 0; face < 6; face++)
{ {
...@@ -1533,14 +1534,13 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size ...@@ -1533,14 +1534,13 @@ void TextureCubeMap::storage(GLsizei levels, GLenum internalformat, GLsizei size
void TextureCubeMap::generateMipmaps() void TextureCubeMap::generateMipmaps()
{ {
// Purge array levels 1 through q and reset them to represent the generated mipmap levels. // Purge array levels 1 through q and reset them to represent the generated mipmap levels.
int q = log2(getBaseLevelWidth()); int q = mipLevels();
for (int faceIndex = 0; faceIndex < 6; faceIndex++) for (int faceIndex = 0; faceIndex < 6; faceIndex++)
{ {
for (int level = 1; level <= q; level++) for (int level = 1; level <= q; level++)
{ {
redefineImage(faceIndex, level, mImageArray[faceIndex][0]->getInternalFormat(), int faceLevelSize = (std::max(mImageArray[faceIndex][0]->getWidth() >> level, 1));
std::max(mImageArray[faceIndex][0]->getWidth() >> level, 1), redefineImage(faceIndex, level, mImageArray[faceIndex][0]->getInternalFormat(), faceLevelSize, faceLevelSize);
std::max(mImageArray[faceIndex][0]->getWidth() >> level, 1));
} }
} }
...@@ -1825,29 +1825,29 @@ void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GL ...@@ -1825,29 +1825,29 @@ void Texture3D::storage(GLsizei levels, GLenum internalformat, GLsizei width, GL
void Texture3D::generateMipmaps() void Texture3D::generateMipmaps()
{ {
// Purge array levels 1 through q and reset them to represent the generated mipmap levels. // Purge array levels 1 through q and reset them to represent the generated mipmap levels.
unsigned int q = log2(std::max(getBaseLevelWidth(), getBaseLevelHeight())); int q = mipLevels();
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
redefineImage(i, getBaseLevelInternalFormat(), redefineImage(level, getBaseLevelInternalFormat(),
std::max(getBaseLevelWidth() >> i, 1), std::max(getBaseLevelWidth() >> level, 1),
std::max(getBaseLevelHeight() >> i, 1), std::max(getBaseLevelHeight() >> level, 1),
std::max(getBaseLevelDepth() >> i, 1)); std::max(getBaseLevelDepth() >> level, 1));
} }
if (mTexStorage && mTexStorage->isRenderTarget()) if (mTexStorage && mTexStorage->isRenderTarget())
{ {
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
mTexStorage->generateMipmap(i); mTexStorage->generateMipmap(level);
mImageArray[i]->markClean(); mImageArray[level]->markClean();
} }
} }
else else
{ {
for (unsigned int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
mRenderer->generateMipmap(mImageArray[i], mImageArray[i - 1]); mRenderer->generateMipmap(mImageArray[level], mImageArray[level - 1]);
} }
} }
} }
...@@ -1926,11 +1926,7 @@ bool Texture3D::isSamplerComplete(const SamplerState &samplerState) const ...@@ -1926,11 +1926,7 @@ bool Texture3D::isSamplerComplete(const SamplerState &samplerState) const
bool Texture3D::isMipmapComplete() const bool Texture3D::isMipmapComplete() const
{ {
GLsizei width = getBaseLevelWidth(); int q = mipLevels();
GLsizei height = getBaseLevelHeight();
GLsizei depth = getBaseLevelDepth();
int q = log2(std::max(std::max(width, height), depth));
for (int level = 0; level <= q; level++) for (int level = 0; level <= q; level++)
{ {
...@@ -2400,10 +2396,10 @@ void Texture2DArray::generateMipmaps() ...@@ -2400,10 +2396,10 @@ void Texture2DArray::generateMipmaps()
GLenum baseFormat = getBaseLevelInternalFormat(); GLenum baseFormat = getBaseLevelInternalFormat();
// Purge array levels 1 through q and reset them to represent the generated mipmap levels. // Purge array levels 1 through q and reset them to represent the generated mipmap levels.
int q = log2(std::max(baseWidth, baseHeight)); int q = mipLevels();
for (int i = 1; i <= q; i++) for (int level = 1; level <= q; level++)
{ {
redefineImage(i, baseFormat, std::max(baseWidth >> i, 1), std::max(baseHeight >> i, 1), baseDepth); redefineImage(level, baseFormat, std::max(baseWidth >> level, 1), std::max(baseHeight >> level, 1), baseDepth);
} }
if (mTexStorage && mTexStorage->isRenderTarget()) if (mTexStorage && mTexStorage->isRenderTarget())
...@@ -2503,10 +2499,7 @@ bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState) const ...@@ -2503,10 +2499,7 @@ bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState) const
bool Texture2DArray::isMipmapComplete() const bool Texture2DArray::isMipmapComplete() const
{ {
GLsizei width = getBaseLevelWidth(); int q = mipLevels();
GLsizei height = getBaseLevelHeight();
int q = log2(std::max(width, height));
for (int level = 1; level <= q; level++) for (int level = 1; level <= q; level++)
{ {
......
...@@ -125,6 +125,7 @@ class Texture : public RefCountObject ...@@ -125,6 +125,7 @@ class Texture : public RefCountObject
GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const; GLint creationLevels(GLsizei width, GLsizei height, GLsizei depth) const;
GLint creationLevels(GLsizei width, GLsizei height) const; GLint creationLevels(GLsizei width, GLsizei height) const;
GLint creationLevels(GLsizei size) const; GLint creationLevels(GLsizei size) const;
int mipLevels() const;
virtual void createTexture() = 0; virtual void createTexture() = 0;
virtual void updateTexture() = 0; virtual void updateTexture() = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment