Use packed enums for the texture types and targets, part 1
In OpenGL there are two enum "sets" used by the API that are very
similar: texture types (or bind point) and texture targets. They only
differ in that texture types have GL_TEXTURE_CUBEMAP and target have
GL_TEXTURE_CUBEMAP_[POSITIVE|NEGATIVE]_[X|Y|Z].
This is a problem because in ANGLE we use GLenum to pass around both
types of data, making it difficult to know which of type and target a
variable is.
In addition these enums are placed somewhat randomly in the space of
OpenGL enums, making it slow to have a mapping from texture types to
some data. Such a mapping is in hot-code with gl::State::mTextures.
This commit stack makes the texture types and target enums be
translated to internal packed enums right at the OpenGL entry point
and used throughout ANGLE to have type safety and performance gains.
This is the first of two commit which does the refactor for all of the
validation and stops inside gl::Context. This was the best place to
split patches without having many conversions from packed enums to GL
enums.
BUG=angleproject:2169
Change-Id: Ib43da7e71c253bd9fe210fb0ec0de61bc286e6d3
Reviewed-on: https://chromium-review.googlesource.com/758835
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/libANGLE/validationES3.cpp b/src/libANGLE/validationES3.cpp
index a08ae78..2c9c4f8 100644
--- a/src/libANGLE/validationES3.cpp
+++ b/src/libANGLE/validationES3.cpp
@@ -66,14 +66,14 @@
Texture *texture,
GLint level)
{
- GLenum texTarget = texture->getTarget();
- if (!ValidMipLevel(context, texTarget, level))
+ TextureType type = texture->getType();
+ if (!ValidMipLevel(context, type, level))
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel);
return false;
}
- const auto &format = texture->getFormat(texTarget, level);
+ const auto &format = texture->getFormat(NonCubeTextureTypeToTarget(type), level);
if (format.info->compressed)
{
ANGLE_VALIDATION_ERR(context, InvalidOperation(), CompressedTexturesNotAttachable);
@@ -137,7 +137,7 @@
} // anonymous namespace
static bool ValidateTexImageFormatCombination(gl::Context *context,
- GLenum target,
+ TextureType target,
GLenum internalFormat,
GLenum format,
GLenum type)
@@ -171,7 +171,7 @@
// texture image specification commands only if target is TEXTURE_2D, TEXTURE_2D_ARRAY, or
// TEXTURE_CUBE_MAP.Using these formats in conjunction with any other target will result in an
// INVALID_OPERATION error.
- if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
+ if (target == TextureType::_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
{
context->handleError(InvalidOperation() << "Format cannot be GL_DEPTH_COMPONENT or "
"GL_DEPTH_STENCIL if target is "
@@ -198,7 +198,7 @@
}
bool ValidateES3TexImageParametersBase(Context *context,
- GLenum target,
+ TextureTarget target,
GLint level,
GLenum internalformat,
bool isCompressed,
@@ -215,8 +215,10 @@
GLsizei imageSize,
const void *pixels)
{
+ TextureType texType = TextureTargetToType(target);
+
// Validate image size
- if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage))
+ if (!ValidImageSizeParameters(context, texType, level, width, height, depth, isSubImage))
{
context->handleError(InvalidValue());
return false;
@@ -240,9 +242,9 @@
const gl::Caps &caps = context->getCaps();
- switch (target)
+ switch (texType)
{
- case GL_TEXTURE_2D:
+ case TextureType::_2D:
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
{
@@ -251,7 +253,7 @@
}
break;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
ASSERT(level == 0);
if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
static_cast<GLuint>(height) > caps.maxRectangleTextureSize)
@@ -267,12 +269,7 @@
}
break;
- case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
- case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
- case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
+ case TextureType::CubeMap:
if (!isSubImage && width != height)
{
context->handleError(InvalidValue());
@@ -286,7 +283,7 @@
}
break;
- case GL_TEXTURE_3D:
+ case TextureType::_3D:
if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level))
@@ -296,7 +293,7 @@
}
break;
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_2DArray:
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(depth) > caps.maxArrayTextureLayers)
@@ -311,8 +308,7 @@
return false;
}
- gl::Texture *texture =
- context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
+ gl::Texture *texture = context->getTargetTexture(texType);
if (!texture)
{
context->handleError(InvalidOperation());
@@ -384,7 +380,7 @@
return false;
}
- if (target == GL_TEXTURE_3D)
+ if (texType == TextureType::_3D)
{
context->handleError(InvalidOperation());
return false;
@@ -392,7 +388,8 @@
}
else
{
- if (!ValidateTexImageFormatCombination(context, target, actualInternalFormat, format, type))
+ if (!ValidateTexImageFormatCombination(context, texType, actualInternalFormat, format,
+ type))
{
return false;
}
@@ -438,7 +435,7 @@
}
GLenum sizeCheckFormat = isSubImage ? format : internalformat;
- if (!ValidImageDataSize(context, target, width, height, depth, sizeCheckFormat, type, pixels,
+ if (!ValidImageDataSize(context, texType, width, height, depth, sizeCheckFormat, type, pixels,
imageSize))
{
return false;
@@ -477,7 +474,7 @@
}
bool ValidateES3TexImage2DParameters(Context *context,
- GLenum target,
+ TextureTarget target,
GLint level,
GLenum internalformat,
bool isCompressed,
@@ -506,7 +503,7 @@
}
bool ValidateES3TexImage3DParameters(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLenum internalformat,
bool isCompressed,
@@ -529,16 +526,17 @@
return false;
}
- if (IsETC2EACFormat(format) && target != GL_TEXTURE_2D_ARRAY)
+ if (IsETC2EACFormat(format) && target != TextureType::_2DArray)
{
// ES 3.1, Section 8.7, page 169.
ANGLE_VALIDATION_ERR(context, InvalidOperation(), InternalFormatRequiresTexture2DArray);
return false;
}
- return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed,
- isSubImage, xoffset, yoffset, zoffset, width, height,
- depth, border, format, type, bufSize, pixels);
+ return ValidateES3TexImageParametersBase(context, NonCubeTextureTypeToTarget(target), level,
+ internalformat, isCompressed, isSubImage, xoffset,
+ yoffset, zoffset, width, height, depth, border, format,
+ type, bufSize, pixels);
}
struct EffectiveInternalFormatInfo
@@ -784,7 +782,7 @@
}
bool ValidateES3CopyTexImageParametersBase(ValidationContext *context,
- GLenum target,
+ TextureTarget target,
GLint level,
GLenum internalformat,
bool isSubImage,
@@ -850,7 +848,7 @@
}
bool ValidateES3CopyTexImage2DParameters(ValidationContext *context,
- GLenum target,
+ TextureTarget target,
GLint level,
GLenum internalformat,
bool isSubImage,
@@ -875,7 +873,7 @@
}
bool ValidateES3CopyTexImage3DParameters(ValidationContext *context,
- GLenum target,
+ TextureType target,
GLint level,
GLenum internalformat,
bool isSubImage,
@@ -894,13 +892,13 @@
return false;
}
- return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
- xoffset, yoffset, zoffset, x, y, width, height,
- border);
+ return ValidateES3CopyTexImageParametersBase(context, NonCubeTextureTypeToTarget(target), level,
+ internalformat, isSubImage, xoffset, yoffset,
+ zoffset, x, y, width, height, border);
}
bool ValidateES3TexStorageParametersBase(Context *context,
- GLenum target,
+ TextureType target,
GLsizei levels,
GLenum internalformat,
GLsizei width,
@@ -914,7 +912,7 @@
}
GLsizei maxDim = std::max(width, height);
- if (target != GL_TEXTURE_2D_ARRAY)
+ if (target != TextureType::_2DArray)
{
maxDim = std::max(maxDim, depth);
}
@@ -929,7 +927,7 @@
switch (target)
{
- case GL_TEXTURE_2D:
+ case TextureType::_2D:
{
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize)
@@ -940,7 +938,7 @@
}
break;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
{
if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize ||
static_cast<GLuint>(height) > caps.maxRectangleTextureSize || levels != 1)
@@ -951,7 +949,7 @@
}
break;
- case GL_TEXTURE_CUBE_MAP:
+ case TextureType::CubeMap:
{
if (width != height)
{
@@ -967,7 +965,7 @@
}
break;
- case GL_TEXTURE_3D:
+ case TextureType::_3D:
{
if (static_cast<GLuint>(width) > caps.max3DTextureSize ||
static_cast<GLuint>(height) > caps.max3DTextureSize ||
@@ -979,7 +977,7 @@
}
break;
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_2DArray:
{
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize ||
@@ -1022,7 +1020,7 @@
return false;
}
- if (formatInfo.compressed && target == GL_TEXTURE_RECTANGLE_ANGLE)
+ if (formatInfo.compressed && target == TextureType::Rectangle)
{
context->handleError(InvalidEnum() << "Rectangle texture cannot have a compressed format.");
return false;
@@ -1032,7 +1030,7 @@
}
bool ValidateES3TexStorage2DParameters(Context *context,
- GLenum target,
+ TextureType target,
GLsizei levels,
GLenum internalformat,
GLsizei width,
@@ -1050,7 +1048,7 @@
}
bool ValidateES3TexStorage3DParameters(Context *context,
- GLenum target,
+ TextureType target,
GLsizei levels,
GLenum internalformat,
GLsizei width,
@@ -1369,7 +1367,7 @@
}
bool ValidateCompressedTexImage3D(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLenum internalformat,
GLsizei width,
@@ -1418,7 +1416,7 @@
}
// 3D texture target validation
- if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY)
+ if (target != TextureType::_3D && target != TextureType::_2DArray)
{
context->handleError(InvalidEnum() << "Must specify a valid 3D texture destination target");
return false;
@@ -1436,7 +1434,7 @@
}
bool ValidateCompressedTexImage3DRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLenum internalformat,
GLsizei width,
@@ -1881,7 +1879,7 @@
}
bool ValidateCopyTexSubImage3D(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint xoffset,
GLint yoffset,
@@ -1902,7 +1900,7 @@
}
bool ValidateTexImage3D(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint internalformat,
GLsizei width,
@@ -1925,7 +1923,7 @@
}
bool ValidateTexImage3DRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint internalformat,
GLsizei width,
@@ -1954,7 +1952,7 @@
}
bool ValidateTexSubImage3D(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint xoffset,
GLint yoffset,
@@ -1978,7 +1976,7 @@
}
bool ValidateTexSubImage3DRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint xoffset,
GLint yoffset,
@@ -2008,7 +2006,7 @@
}
bool ValidateCompressedTexSubImage3D(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint xoffset,
GLint yoffset,
@@ -2062,7 +2060,7 @@
}
bool ValidateCompressedTexSubImage3DRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLint level,
GLint xoffset,
GLint yoffset,
@@ -3639,7 +3637,7 @@
}
bool ValidateTexStorage2D(Context *context,
- GLenum target,
+ TextureType target,
GLsizei levels,
GLenum internalformat,
GLsizei width,
@@ -3661,7 +3659,7 @@
}
bool ValidateTexStorage3D(Context *context,
- GLenum target,
+ TextureType target,
GLsizei levels,
GLenum internalformat,
GLsizei width,