Move validation of API errors out of Texture*::generateMipmaps() to the API.
TRAC #23959
Signed-off-by: Geoff Lang
Signed-off-by: Shannon Woods
diff --git a/src/libGLESv2/Texture.cpp b/src/libGLESv2/Texture.cpp
index cc8fe87..146c2a7 100644
--- a/src/libGLESv2/Texture.cpp
+++ b/src/libGLESv2/Texture.cpp
@@ -843,14 +843,6 @@
void Texture2D::generateMipmaps()
{
- if (!mRenderer->getNonPower2TextureSupport())
- {
- if (!isPow2(getBaseLevelWidth()) || !isPow2(getBaseLevelHeight()))
- {
- return gl::error(GL_INVALID_OPERATION);
- }
- }
-
// Purge array levels 1 through q and reset them to represent the generated mipmap levels.
unsigned int q = log2(std::max(getBaseLevelWidth(), getBaseLevelHeight()));
for (unsigned int i = 1; i <= q; i++)
@@ -1132,16 +1124,22 @@
// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
bool TextureCubeMap::isCubeComplete() const
{
- if (getBaseLevelWidth() <= 0 || getBaseLevelHeight() != getBaseLevelWidth())
+ int baseWidth = getBaseLevelWidth();
+ int baseHeight = getBaseLevelHeight();
+ GLenum baseFormat = getBaseLevelInternalFormat();
+
+ if (baseWidth <= 0 || baseWidth != baseHeight)
{
return false;
}
for (unsigned int face = 1; face < 6; face++)
{
- if (mImageArray[face][0]->getWidth() != getBaseLevelWidth() ||
- mImageArray[face][0]->getWidth() != getBaseLevelHeight() ||
- mImageArray[face][0]->getInternalFormat() != getBaseLevelInternalFormat())
+ const rx::Image &faceBaseImage = *mImageArray[face][0];
+
+ if (faceBaseImage.getWidth() != baseWidth ||
+ faceBaseImage.getHeight() != baseHeight ||
+ faceBaseImage.getInternalFormat() != baseFormat )
{
return false;
}
@@ -1489,19 +1487,6 @@
void TextureCubeMap::generateMipmaps()
{
- if (!isCubeComplete())
- {
- return gl::error(GL_INVALID_OPERATION);
- }
-
- if (!mRenderer->getNonPower2TextureSupport())
- {
- if (!isPow2(getBaseLevelWidth()))
- {
- return gl::error(GL_INVALID_OPERATION);
- }
- }
-
// Purge array levels 1 through q and reset them to represent the generated mipmap levels.
unsigned int q = log2(getBaseLevelWidth());
for (unsigned int f = 0; f < 6; f++)
diff --git a/src/libGLESv2/Texture.h b/src/libGLESv2/Texture.h
index 96ce450..34dfe52 100644
--- a/src/libGLESv2/Texture.h
+++ b/src/libGLESv2/Texture.h
@@ -243,6 +243,7 @@
void storage(GLsizei levels, GLenum internalformat, GLsizei size);
virtual bool isSamplerComplete(const SamplerState &samplerState) const;
+ bool isCubeComplete() const;
virtual void generateMipmaps();
@@ -266,7 +267,6 @@
virtual rx::TextureStorageInterface *getStorage(bool renderTarget);
virtual const rx::Image *getBaseLevelImage() const;
- bool isCubeComplete() const;
bool isMipmapCubeComplete() const;
bool isFaceLevelComplete(int face, int level) const;
void updateTextureFaceLevel(int face, int level);
diff --git a/src/libGLESv2/libGLESv2.cpp b/src/libGLESv2/libGLESv2.cpp
index fff0994..fb805c8 100644
--- a/src/libGLESv2/libGLESv2.cpp
+++ b/src/libGLESv2/libGLESv2.cpp
@@ -2223,6 +2223,23 @@
return gl::error(GL_INVALID_OPERATION);
}
+ // Non-power of 2 ES2 check
+ if (!context->supportsNonPower2Texture() && (!gl::isPow2(texture->getBaseLevelWidth()) || !gl::isPow2(texture->getBaseLevelHeight())))
+ {
+ ASSERT(context->getClientVersion() <= 2 && (target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP));
+ return gl::error(GL_INVALID_OPERATION);
+ }
+
+ // Cube completeness check
+ if (target == GL_TEXTURE_CUBE_MAP)
+ {
+ gl::TextureCubeMap *textureCube = static_cast<gl::TextureCubeMap *>(texture);
+ if (!textureCube->isCubeComplete())
+ {
+ return gl::error(GL_INVALID_OPERATION);
+ }
+ }
+
texture->generateMipmaps();
}
}