Refactor Texture to track image information for size and format queries.
BUG=angle:681
Change-Id: Ifb3f52d6348e4479181e66f1c39578f49e9dcf76
Reviewed-on: https://chromium-review.googlesource.com/235613
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Brandon Jones <bajones@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/libANGLE/Texture.cpp b/src/libANGLE/Texture.cpp
index bee0ef0..e1e9d5d 100644
--- a/src/libANGLE/Texture.cpp
+++ b/src/libANGLE/Texture.cpp
@@ -79,49 +79,28 @@
return mUsage;
}
-GLint Texture::getBaseLevelWidth() const
+size_t Texture::getWidth(GLenum target, size_t level) const
{
- const rx::Image *baseImage = getBaseLevelImage();
- return (baseImage ? baseImage->getWidth() : 0);
+ ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target)));
+ return getImageDesc(ImageIdentifier(target, level)).size.width;
}
-GLint Texture::getBaseLevelHeight() const
+size_t Texture::getHeight(GLenum target, size_t level) const
{
- const rx::Image *baseImage = getBaseLevelImage();
- return (baseImage ? baseImage->getHeight() : 0);
+ ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target)));
+ return getImageDesc(ImageIdentifier(target, level)).size.height;
}
-GLint Texture::getBaseLevelDepth() const
+size_t Texture::getDepth(GLenum target, size_t level) const
{
- const rx::Image *baseImage = getBaseLevelImage();
- return (baseImage ? baseImage->getDepth() : 0);
+ ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target)));
+ return getImageDesc(ImageIdentifier(target, level)).size.depth;
}
-// Note: "base level image" is loosely defined to be any image from the base level,
-// where in the base of 2D array textures and cube maps there are several. Don't use
-// the base level image for anything except querying texture format and size.
-GLenum Texture::getBaseLevelInternalFormat() const
+GLenum Texture::getInternalFormat(GLenum target, size_t level) const
{
- const rx::Image *baseImage = getBaseLevelImage();
- return (baseImage ? baseImage->getInternalFormat() : GL_NONE);
-}
-
-GLsizei Texture::getWidth(const ImageIndex &index) const
-{
- rx::Image *image = mTexture->getImage(index);
- return image->getWidth();
-}
-
-GLsizei Texture::getHeight(const ImageIndex &index) const
-{
- rx::Image *image = mTexture->getImage(index);
- return image->getHeight();
-}
-
-GLenum Texture::getInternalFormat(const ImageIndex &index) const
-{
- rx::Image *image = mTexture->getImage(index);
- return image->getInternalFormat();
+ ASSERT(target == mTarget || (mTarget == GL_TEXTURE_CUBE_MAP && IsCubemapTextureTarget(target)));
+ return getImageDesc(ImageIdentifier(target, level)).internalFormat;
}
unsigned int Texture::getTextureSerial() const
@@ -144,16 +123,6 @@
return mImmutableLevelCount;
}
-int Texture::mipLevels() const
-{
- return log2(std::max(std::max(getBaseLevelWidth(), getBaseLevelHeight()), getBaseLevelDepth())) + 1;
-}
-
-const rx::Image *Texture::getBaseLevelImage() const
-{
- return (getImplementation()->getLayerCount(0) > 0 ? getImplementation()->getImage(0, 0) : NULL);
-}
-
Error Texture::setImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, GLenum format, GLenum type,
const PixelUnpackState &unpack, const uint8_t *pixels)
{
@@ -165,6 +134,8 @@
return error;
}
+ setImageDesc(ImageIdentifier(target, level), ImageDesc(size, GetSizedInternalFormat(internalFormat, type)));
+
return Error(GL_NO_ERROR);
}
@@ -187,6 +158,8 @@
return error;
}
+ setImageDesc(ImageIdentifier(target, level), ImageDesc(size, GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE)));
+
return Error(GL_NO_ERROR);
}
@@ -209,6 +182,9 @@
return error;
}
+ setImageDesc(ImageIdentifier(target, level), ImageDesc(Extents(sourceArea.width, sourceArea.height, 1),
+ GetSizedInternalFormat(internalFormat, GL_UNSIGNED_BYTE)));
+
return Error(GL_NO_ERROR);
}
@@ -231,6 +207,8 @@
}
mImmutableLevelCount = levels;
+ clearImageDescs();
+ setImageDescChain(levels, size, internalFormat);
return Error(GL_NO_ERROR);
}
@@ -244,9 +222,81 @@
return error;
}
+ ImageIdentifier baseLevel(mTarget == GL_TEXTURE_CUBE_MAP ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : mTarget, 0);
+ const ImageDesc &baseImageInfo = getImageDesc(baseLevel);
+ size_t mipLevels = log2(std::max(std::max(baseImageInfo.size.width, baseImageInfo.size.height), baseImageInfo.size.depth)) + 1;
+ setImageDescChain(mipLevels, baseImageInfo.size, baseImageInfo.internalFormat);
+
return Error(GL_NO_ERROR);
}
+void Texture::setImageDescChain(size_t levels, Extents baseSize, GLenum sizedInternalFormat)
+{
+ for (size_t level = 0; level < levels; level++)
+ {
+ Extents levelSize(std::max<size_t>(baseSize.width >> level, 1),
+ std::max<size_t>(baseSize.height >> level, 1),
+ (mTarget == GL_TEXTURE_2D_ARRAY) ? baseSize.depth : std::max<size_t>(baseSize.depth >> level, 1));
+ ImageDesc levelInfo(levelSize, sizedInternalFormat);
+
+ if (mTarget == GL_TEXTURE_CUBE_MAP)
+ {
+ for (size_t face = GL_TEXTURE_CUBE_MAP_POSITIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++)
+ {
+ setImageDesc(ImageIdentifier(face, level), levelInfo);
+ }
+ }
+ else
+ {
+ setImageDesc(ImageIdentifier(mTarget, level), levelInfo);
+ }
+ }
+}
+
+Texture::ImageIdentifier::ImageIdentifier()
+ : ImageIdentifier(GL_TEXTURE_2D, 0)
+{
+}
+
+Texture::ImageIdentifier::ImageIdentifier(GLenum target, size_t level)
+ : target(target),
+ level(level)
+{
+}
+
+bool Texture::ImageIdentifier::operator<(const ImageIdentifier &other) const
+{
+ return (target != other.target) ? target < other.target : level < other.level;
+}
+
+Texture::ImageDesc::ImageDesc()
+ : ImageDesc(Extents(0, 0, 0), GL_NONE)
+{
+}
+
+Texture::ImageDesc::ImageDesc(const Extents &size, GLenum internalFormat)
+ : size(size),
+ internalFormat(internalFormat)
+{
+}
+
+const Texture::ImageDesc &Texture::getImageDesc(const ImageIdentifier& index) const
+{
+ static const Texture::ImageDesc defaultDesc;
+ ImageDescMap::const_iterator iter = mImageDescs.find(index);
+ return (iter != mImageDescs.end()) ? iter->second : defaultDesc;
+}
+
+void Texture::setImageDesc(const ImageIdentifier& index, const ImageDesc &desc)
+{
+ mImageDescs[index] = desc;
+}
+
+void Texture::clearImageDescs()
+{
+ mImageDescs.clear();
+}
+
Texture2D::Texture2D(rx::TextureImpl *impl, GLuint id)
: Texture(impl, id, GL_TEXTURE_2D)
{
@@ -262,30 +312,6 @@
}
}
-GLsizei Texture2D::getWidth(GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, 0)->getWidth();
- else
- return 0;
-}
-
-GLsizei Texture2D::getHeight(GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, 0)->getHeight();
- else
- return 0;
-}
-
-GLenum Texture2D::getInternalFormat(GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, 0)->getInternalFormat();
- else
- return GL_NONE;
-}
-
Error Texture2D::setImage(GLenum target, size_t level, GLenum internalFormat, const Extents &size, GLenum format, GLenum type,
const PixelUnpackState &unpack, const uint8_t *pixels)
{
@@ -373,15 +399,15 @@
// Tests for 2D texture sampling completeness. [OpenGL ES 2.0.24] section 3.8.2 page 85.
bool Texture2D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const
{
- GLsizei width = getBaseLevelWidth();
- GLsizei height = getBaseLevelHeight();
-
- if (width <= 0 || height <= 0)
+ size_t width = getWidth(GL_TEXTURE_2D, 0);
+ size_t height = getHeight(GL_TEXTURE_2D, 0);
+ if (width == 0 || height == 0)
{
return false;
}
- if (!data.textureCaps->get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
+ GLenum internalFormat = getInternalFormat(GL_TEXTURE_2D, 0);
+ if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState))
{
return false;
}
@@ -417,7 +443,7 @@
// depth and stencil format (see table 3.13), the value of TEXTURE_COMPARE_-
// MODE is NONE, and either the magnification filter is not NEAREST or the mini-
// fication filter is neither NEAREST nor NEAREST_MIPMAP_NEAREST.
- const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(getInternalFormat(0));
+ const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat);
if (formatInfo.depthBits > 0 && data.clientVersion > 2)
{
if (samplerState.compareMode == GL_NONE)
@@ -433,22 +459,14 @@
return true;
}
-bool Texture2D::isCompressed(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).compressed;
-}
-
-bool Texture2D::isDepth(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
-}
-
// Tests for 2D texture (mipmap) completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
bool Texture2D::isMipmapComplete() const
{
- int levelCount = mipLevels();
+ size_t width = getWidth(GL_TEXTURE_2D, 0);
+ size_t height = getHeight(GL_TEXTURE_2D, 0);
- for (int level = 0; level < levelCount; level++)
+ size_t expectedMipLevels = log2(std::max(width, height)) + 1;
+ for (size_t level = 0; level < expectedMipLevels; level++)
{
if (!isLevelComplete(level))
{
@@ -459,19 +477,18 @@
return true;
}
-bool Texture2D::isLevelComplete(int level) const
+bool Texture2D::isLevelComplete(size_t level) const
{
+ ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
+
if (isImmutable())
{
return true;
}
- const rx::Image *baseImage = getBaseLevelImage();
-
- GLsizei width = baseImage->getWidth();
- GLsizei height = baseImage->getHeight();
-
- if (width <= 0 || height <= 0)
+ size_t width = getWidth(GL_TEXTURE_2D, 0);
+ size_t height = getHeight(GL_TEXTURE_2D, 0);
+ if (width == 0 || height == 0)
{
return false;
}
@@ -482,20 +499,17 @@
return true;
}
- ASSERT(level >= 1 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
- rx::Image *image = mTexture->getImage(level, 0);
-
- if (image->getInternalFormat() != baseImage->getInternalFormat())
+ if (getInternalFormat(GL_TEXTURE_2D, level) != getInternalFormat(GL_TEXTURE_2D, 0))
{
return false;
}
- if (image->getWidth() != std::max(1, width >> level))
+ if (getWidth(GL_TEXTURE_2D, level) != std::max<size_t>(1, width >> level))
{
return false;
}
- if (image->getHeight() != std::max(1, height >> level))
+ if (getHeight(GL_TEXTURE_2D, level) != std::max<size_t>(1, height >> level))
{
return false;
}
@@ -512,49 +526,22 @@
{
}
-GLsizei TextureCubeMap::getWidth(GLenum target, GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, targetToLayerIndex(target))->getWidth();
- else
- return 0;
-}
-
-GLsizei TextureCubeMap::getHeight(GLenum target, GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, targetToLayerIndex(target))->getHeight();
- else
- return 0;
-}
-
-GLenum TextureCubeMap::getInternalFormat(GLenum target, GLint level) const
-{
- if (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS)
- return mTexture->getImage(level, targetToLayerIndex(target))->getInternalFormat();
- else
- return GL_NONE;
-}
-
// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
bool TextureCubeMap::isCubeComplete() const
{
- int baseWidth = getBaseLevelWidth();
- int baseHeight = getBaseLevelHeight();
- GLenum baseFormat = getBaseLevelInternalFormat();
-
- if (baseWidth <= 0 || baseWidth != baseHeight)
+ size_t width = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
+ size_t height = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
+ if (width == 0 || width != height)
{
return false;
}
- for (int faceIndex = 1; faceIndex < 6; faceIndex++)
+ GLenum internalFormat = getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
+ for (GLenum face = GL_TEXTURE_CUBE_MAP_POSITIVE_X + 1; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++)
{
- const rx::Image *faceBaseImage = mTexture->getImage(0, faceIndex);
-
- if (faceBaseImage->getWidth() != baseWidth ||
- faceBaseImage->getHeight() != baseHeight ||
- faceBaseImage->getInternalFormat() != baseFormat )
+ if (getWidth(face, 0) != width ||
+ getHeight(face, 0) != height ||
+ getInternalFormat(face, 0) != internalFormat)
{
return false;
}
@@ -563,28 +550,18 @@
return true;
}
-bool TextureCubeMap::isCompressed(GLenum target, GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(target, level)).compressed;
-}
-
-bool TextureCubeMap::isDepth(GLenum target, GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(target, level)).depthBits > 0;
-}
-
// Tests for texture sampling completeness
bool TextureCubeMap::isSamplerComplete(const SamplerState &samplerState, const Data &data) const
{
- int size = getBaseLevelWidth();
-
bool mipmapping = IsMipmapFiltered(samplerState);
- if (!data.textureCaps->get(getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0)).filterable && !IsPointSampled(samplerState))
+ GLenum internalFormat = getInternalFormat(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
+ if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState))
{
return false;
}
+ size_t size = getWidth(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0);
if (!gl::isPow2(size) && !data.extensions->textureNPOT)
{
if (samplerState.wrapS != GL_CLAMP_TO_EDGE || samplerState.wrapT != GL_CLAMP_TO_EDGE || mipmapping)
@@ -645,11 +622,13 @@
return false;
}
- int levelCount = mipLevels();
+ size_t width = getWidth(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0);
+ size_t height = getHeight(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0);
- for (int face = 0; face < 6; face++)
+ size_t expectedMipLevels = log2(std::max(width, height)) + 1;
+ for (GLenum face = GL_TEXTURE_CUBE_MAP_NEGATIVE_X; face <= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; face++)
{
- for (int level = 1; level < levelCount; level++)
+ for (size_t level = 1; level < expectedMipLevels; level++)
{
if (!isFaceLevelComplete(face, level))
{
@@ -661,18 +640,17 @@
return true;
}
-bool TextureCubeMap::isFaceLevelComplete(int faceIndex, int level) const
+bool TextureCubeMap::isFaceLevelComplete(GLenum target, size_t level) const
{
- ASSERT(level >= 0 && faceIndex < 6 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, faceIndex) != NULL);
+ ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && IsCubemapTextureTarget(target));
if (isImmutable())
{
return true;
}
- int baseSize = getBaseLevelWidth();
-
- if (baseSize <= 0)
+ size_t baseSize = getWidth(target, 0);
+ if (baseSize == 0)
{
return false;
}
@@ -686,14 +664,12 @@
}
// Check that non-zero levels are consistent with the base level.
- const rx::Image *faceLevelImage = mTexture->getImage(level, faceIndex);
-
- if (faceLevelImage->getInternalFormat() != getBaseLevelInternalFormat())
+ if (getInternalFormat(target, level) != getInternalFormat(target, 0))
{
return false;
}
- if (faceLevelImage->getWidth() != std::max(1, baseSize >> level))
+ if (getWidth(target, level) != std::max<size_t>(1, baseSize >> level))
{
return false;
}
@@ -711,48 +687,18 @@
{
}
-GLsizei Texture3D::getWidth(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getWidth() : 0;
-}
-
-GLsizei Texture3D::getHeight(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getHeight() : 0;
-}
-
-GLsizei Texture3D::getDepth(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getDepth() : 0;
-}
-
-GLenum Texture3D::getInternalFormat(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
-}
-
-bool Texture3D::isCompressed(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).compressed;
-}
-
-bool Texture3D::isDepth(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
-}
-
bool Texture3D::isSamplerComplete(const SamplerState &samplerState, const Data &data) const
{
- GLsizei width = getBaseLevelWidth();
- GLsizei height = getBaseLevelHeight();
- GLsizei depth = getBaseLevelDepth();
-
- if (width <= 0 || height <= 0 || depth <= 0)
+ size_t width = getWidth(GL_TEXTURE_3D, 0);
+ size_t height = getHeight(GL_TEXTURE_3D, 0);
+ size_t depth = getDepth(GL_TEXTURE_3D, 0);
+ if (width == 0 || height == 0 || depth == 0)
{
return false;
}
- if (!data.textureCaps->get(getInternalFormat(0)).filterable && !IsPointSampled(samplerState))
+ GLenum internalFormat = getInternalFormat(GL_TEXTURE_3D, 0);
+ if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState))
{
return false;
}
@@ -767,9 +713,12 @@
bool Texture3D::isMipmapComplete() const
{
- int levelCount = mipLevels();
+ size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0);
+ size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0);
+ size_t depth = getDepth(GL_TEXTURE_3D, 0);
- for (int level = 0; level < levelCount; level++)
+ size_t expectedMipLevels = log2(std::max(std::max(width, height), depth)) + 1;
+ for (size_t level = 0; level < expectedMipLevels; level++)
{
if (!isLevelComplete(level))
{
@@ -780,20 +729,19 @@
return true;
}
-bool Texture3D::isLevelComplete(int level) const
+bool Texture3D::isLevelComplete(size_t level) const
{
- ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getImage(level, 0) != NULL);
+ ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
if (isImmutable())
{
return true;
}
- GLsizei width = getBaseLevelWidth();
- GLsizei height = getBaseLevelHeight();
- GLsizei depth = getBaseLevelDepth();
-
- if (width <= 0 || height <= 0 || depth <= 0)
+ size_t width = getWidth(GL_TEXTURE_3D, level);
+ size_t height = getHeight(GL_TEXTURE_3D, level);
+ size_t depth = getDepth(GL_TEXTURE_3D, level);
+ if (width == 0 || height == 0 || depth == 0)
{
return false;
}
@@ -803,24 +751,22 @@
return true;
}
- rx::Image *levelImage = mTexture->getImage(level, 0);
-
- if (levelImage->getInternalFormat() != getBaseLevelInternalFormat())
+ if (getInternalFormat(GL_TEXTURE_3D, level) != getInternalFormat(GL_TEXTURE_3D, 0))
{
return false;
}
- if (levelImage->getWidth() != std::max(1, width >> level))
+ if (getWidth(GL_TEXTURE_3D, level) != std::max<size_t>(1, width >> level))
{
return false;
}
- if (levelImage->getHeight() != std::max(1, height >> level))
+ if (getHeight(GL_TEXTURE_3D, level) != std::max<size_t>(1, height >> level))
{
return false;
}
- if (levelImage->getDepth() != std::max(1, depth >> level))
+ if (getDepth(GL_TEXTURE_3D, level) != std::max<size_t>(1, depth >> level))
{
return false;
}
@@ -837,48 +783,18 @@
{
}
-GLsizei Texture2DArray::getWidth(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getWidth() : 0;
-}
-
-GLsizei Texture2DArray::getHeight(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getHeight() : 0;
-}
-
-GLsizei Texture2DArray::getLayers(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS) ? mTexture->getLayerCount(level) : 0;
-}
-
-GLenum Texture2DArray::getInternalFormat(GLint level) const
-{
- return (level < IMPLEMENTATION_MAX_TEXTURE_LEVELS && mTexture->getLayerCount(level) > 0) ? mTexture->getImage(level, 0)->getInternalFormat() : GL_NONE;
-}
-
-bool Texture2DArray::isCompressed(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).compressed;
-}
-
-bool Texture2DArray::isDepth(GLint level) const
-{
- return GetInternalFormatInfo(getInternalFormat(level)).depthBits > 0;
-}
-
bool Texture2DArray::isSamplerComplete(const SamplerState &samplerState, const Data &data) const
{
- GLsizei width = getBaseLevelWidth();
- GLsizei height = getBaseLevelHeight();
- GLsizei depth = getLayers(0);
-
- if (width <= 0 || height <= 0 || depth <= 0)
+ size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0);
+ size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0);
+ size_t depth = getDepth(GL_TEXTURE_2D_ARRAY, 0);
+ if (width == 0 || height == 0 || depth == 0)
{
return false;
}
- if (!data.textureCaps->get(getBaseLevelInternalFormat()).filterable && !IsPointSampled(samplerState))
+ GLenum internalFormat = getInternalFormat(GL_TEXTURE_2D_ARRAY, 0);
+ if (!data.textureCaps->get(internalFormat).filterable && !IsPointSampled(samplerState))
{
return false;
}
@@ -893,9 +809,11 @@
bool Texture2DArray::isMipmapComplete() const
{
- int levelCount = mipLevels();
+ size_t width = getWidth(GL_TEXTURE_2D_ARRAY, 0);
+ size_t height = getHeight(GL_TEXTURE_2D_ARRAY, 0);
- for (int level = 1; level < levelCount; level++)
+ size_t expectedMipLevels = log2(std::max(width, height)) + 1;
+ for (size_t level = 1; level < expectedMipLevels; level++)
{
if (!isLevelComplete(level))
{
@@ -906,20 +824,19 @@
return true;
}
-bool Texture2DArray::isLevelComplete(int level) const
+bool Texture2DArray::isLevelComplete(size_t level) const
{
- ASSERT(level >= 0 && level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
+ ASSERT(level < IMPLEMENTATION_MAX_TEXTURE_LEVELS);
if (isImmutable())
{
return true;
}
- GLsizei width = getBaseLevelWidth();
- GLsizei height = getBaseLevelHeight();
- GLsizei layers = getLayers(0);
-
- if (width <= 0 || height <= 0 || layers <= 0)
+ size_t width = getWidth(GL_TEXTURE_2D_ARRAY, level);
+ size_t height = getHeight(GL_TEXTURE_2D_ARRAY, level);
+ size_t layers = getDepth(GL_TEXTURE_2D_ARRAY, 0);
+ if (width == 0 || height == 0 || layers == 0)
{
return false;
}
@@ -929,22 +846,22 @@
return true;
}
- if (getInternalFormat(level) != getInternalFormat(0))
+ if (getInternalFormat(GL_TEXTURE_2D_ARRAY, level) != getInternalFormat(GL_TEXTURE_2D_ARRAY, 0))
{
return false;
}
- if (getWidth(level) != std::max(1, width >> level))
+ if (getWidth(GL_TEXTURE_2D_ARRAY, level) != std::max<size_t>(1, width >> level))
{
return false;
}
- if (getHeight(level) != std::max(1, height >> level))
+ if (getHeight(GL_TEXTURE_2D_ARRAY, level) != std::max<size_t>(1, height >> level))
{
return false;
}
- if (getLayers(level) != layers)
+ if (getDepth(GL_TEXTURE_2D_ARRAY, level) != layers)
{
return false;
}