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/validationES.cpp b/src/libANGLE/validationES.cpp
index 0657124..e56f731 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -517,22 +517,22 @@
}
}
-bool ValidTextureTarget(const ValidationContext *context, GLenum target)
+bool ValidTextureTarget(const ValidationContext *context, TextureType type)
{
- switch (target)
+ switch (type)
{
- case GL_TEXTURE_2D:
- case GL_TEXTURE_CUBE_MAP:
+ case TextureType::_2D:
+ case TextureType::CubeMap:
return true;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
return context->getExtensions().textureRectangle;
- case GL_TEXTURE_3D:
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_3D:
+ case TextureType::_2DArray:
return (context->getClientMajorVersion() >= 3);
- case GL_TEXTURE_2D_MULTISAMPLE:
+ case TextureType::_2DMultisample:
return (context->getClientVersion() >= Version(3, 1));
default:
@@ -540,15 +540,15 @@
}
}
-bool ValidTexture2DTarget(const ValidationContext *context, GLenum target)
+bool ValidTexture2DTarget(const ValidationContext *context, TextureType type)
{
- switch (target)
+ switch (type)
{
- case GL_TEXTURE_2D:
- case GL_TEXTURE_CUBE_MAP:
+ case TextureType::_2D:
+ case TextureType::CubeMap:
return true;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
return context->getExtensions().textureRectangle;
default:
@@ -556,12 +556,12 @@
}
}
-bool ValidTexture3DTarget(const ValidationContext *context, GLenum target)
+bool ValidTexture3DTarget(const ValidationContext *context, TextureType target)
{
switch (target)
{
- case GL_TEXTURE_3D:
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_3D:
+ case TextureType::_2DArray:
return (context->getClientMajorVersion() >= 3);
default:
@@ -571,9 +571,9 @@
// Most texture GL calls are not compatible with external textures, so we have a separate validation
// function for use in the GL calls that do
-bool ValidTextureExternalTarget(const ValidationContext *context, GLenum target)
+bool ValidTextureExternalTarget(const ValidationContext *context, TextureType target)
{
- return (target == GL_TEXTURE_EXTERNAL_OES) &&
+ return (target == TextureType::External) &&
(context->getExtensions().eglImageExternal ||
context->getExtensions().eglStreamConsumerExternal);
}
@@ -582,19 +582,19 @@
// usable as the destination of a 2D operation-- so a cube face is valid, but
// GL_TEXTURE_CUBE_MAP is not.
// Note: duplicate of IsInternalTextureTarget
-bool ValidTexture2DDestinationTarget(const ValidationContext *context, GLenum target)
+bool ValidTexture2DDestinationTarget(const ValidationContext *context, TextureTarget target)
{
switch (target)
{
- case GL_TEXTURE_2D:
- 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 TextureTarget::_2D:
+ case TextureTarget::CubeMapNegativeX:
+ case TextureTarget::CubeMapNegativeY:
+ case TextureTarget::CubeMapNegativeZ:
+ case TextureTarget::CubeMapPositiveX:
+ case TextureTarget::CubeMapPositiveY:
+ case TextureTarget::CubeMapPositiveZ:
return true;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureTarget::Rectangle:
return context->getExtensions().textureRectangle;
default:
return false;
@@ -665,34 +665,29 @@
return false;
}
-bool ValidTexture3DDestinationTarget(const ValidationContext *context, GLenum target)
+bool ValidTexture3DDestinationTarget(const ValidationContext *context, TextureType target)
{
switch (target)
{
- case GL_TEXTURE_3D:
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_3D:
+ case TextureType::_2DArray:
return true;
default:
return false;
}
}
-bool ValidTexLevelDestinationTarget(const ValidationContext *context, GLenum target)
+bool ValidTexLevelDestinationTarget(const ValidationContext *context, TextureType type)
{
- switch (target)
+ switch (type)
{
- case GL_TEXTURE_2D:
- 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 GL_TEXTURE_3D:
- case GL_TEXTURE_2D_ARRAY:
- case GL_TEXTURE_2D_MULTISAMPLE:
+ case TextureType::_2D:
+ case TextureType::_2DArray:
+ case TextureType::_2DMultisample:
+ case TextureType::CubeMap:
+ case TextureType::_3D:
return true;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
return context->getExtensions().textureRectangle;
default:
return false;
@@ -720,35 +715,25 @@
}
}
-bool ValidMipLevel(const ValidationContext *context, GLenum target, GLint level)
+bool ValidMipLevel(const ValidationContext *context, TextureType type, GLint level)
{
const auto &caps = context->getCaps();
size_t maxDimension = 0;
- switch (target)
+ switch (type)
{
- case GL_TEXTURE_2D:
+ case TextureType::_2D:
+ case TextureType::_2DArray:
+ case TextureType::_2DMultisample:
maxDimension = caps.max2DTextureSize;
break;
- case GL_TEXTURE_CUBE_MAP:
- 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:
maxDimension = caps.maxCubeMapTextureSize;
break;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
return level == 0;
- case GL_TEXTURE_3D:
+ case TextureType::_3D:
maxDimension = caps.max3DTextureSize;
break;
- case GL_TEXTURE_2D_ARRAY:
- maxDimension = caps.max2DTextureSize;
- break;
- case GL_TEXTURE_2D_MULTISAMPLE:
- maxDimension = caps.max2DTextureSize;
- break;
default:
UNREACHABLE();
}
@@ -757,7 +742,7 @@
}
bool ValidImageSizeParameters(ValidationContext *context,
- GLenum target,
+ TextureType target,
GLint level,
GLsizei width,
GLsizei height,
@@ -876,7 +861,7 @@
}
bool ValidImageDataSize(ValidationContext *context,
- GLenum textureTarget,
+ TextureType texType,
GLsizei width,
GLsizei height,
GLsizei depth,
@@ -900,7 +885,7 @@
const gl::Extents size(width, height, depth);
const auto &unpack = context->getGLState().getUnpackState();
- bool targetIs3D = textureTarget == GL_TEXTURE_3D || textureTarget == GL_TEXTURE_2D_ARRAY;
+ bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray;
auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D);
if (endByteOrErr.isError())
{
@@ -2256,7 +2241,7 @@
}
bool ValidateCopyTexImageParametersBase(ValidationContext *context,
- GLenum target,
+ TextureTarget target,
GLint level,
GLenum internalformat,
bool isSubImage,
@@ -2270,6 +2255,8 @@
GLint border,
Format *textureFormatOut)
{
+ TextureType texType = TextureTargetToType(target);
+
if (xoffset < 0 || yoffset < 0 || zoffset < 0)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset);
@@ -2295,7 +2282,7 @@
return false;
}
- if (!ValidMipLevel(context, target, level))
+ if (!ValidMipLevel(context, texType, level))
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel);
return false;
@@ -2346,30 +2333,25 @@
const gl::Caps &caps = context->getCaps();
GLuint maxDimension = 0;
- switch (target)
+ switch (texType)
{
- case GL_TEXTURE_2D:
+ case TextureType::_2D:
maxDimension = caps.max2DTextureSize;
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:
maxDimension = caps.maxCubeMapTextureSize;
break;
- case GL_TEXTURE_RECTANGLE_ANGLE:
+ case TextureType::Rectangle:
maxDimension = caps.maxRectangleTextureSize;
break;
- case GL_TEXTURE_2D_ARRAY:
+ case TextureType::_2DArray:
maxDimension = caps.max2DTextureSize;
break;
- case GL_TEXTURE_3D:
+ case TextureType::_3D:
maxDimension = caps.max3DTextureSize;
break;
@@ -2378,8 +2360,7 @@
return false;
}
- gl::Texture *texture =
- state.getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
+ gl::Texture *texture = state.getTargetTexture(texType);
if (!texture)
{
ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound);
@@ -2414,7 +2395,7 @@
}
else
{
- if (IsCubeMapTextureTarget(target) && width != height)
+ if (texType == TextureType::CubeMap && width != height)
{
ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete);
return false;
@@ -3258,7 +3239,7 @@
return true;
}
-bool ValidateEGLImageTargetTexture2DOES(Context *context, GLenum target, GLeglImageOES image)
+bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image)
{
if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal)
{
@@ -3266,9 +3247,9 @@
return false;
}
- switch (target)
+ switch (type)
{
- case GL_TEXTURE_2D:
+ case TextureType::_2D:
if (!context->getExtensions().eglImage)
{
context->handleError(InvalidEnum()
@@ -3276,7 +3257,7 @@
}
break;
- case GL_TEXTURE_EXTERNAL_OES:
+ case TextureType::External:
if (!context->getExtensions().eglImageExternal)
{
context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target "
@@ -4275,7 +4256,7 @@
}
bool ValidateGetTexParameterfvRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
@@ -4300,7 +4281,7 @@
}
bool ValidateGetTexParameterivRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLenum pname,
GLsizei bufSize,
GLsizei *length,
@@ -4325,7 +4306,7 @@
}
bool ValidateTexParameterfvRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLenum pname,
GLsizei bufSize,
const GLfloat *params)
@@ -4339,7 +4320,7 @@
}
bool ValidateTexParameterivRobustANGLE(Context *context,
- GLenum target,
+ TextureType target,
GLenum pname,
GLsizei bufSize,
const GLint *params)
@@ -4931,7 +4912,10 @@
return true;
}
-bool ValidateGetTexParameterBase(Context *context, GLenum target, GLenum pname, GLsizei *length)
+bool ValidateGetTexParameterBase(Context *context,
+ TextureType target,
+ GLenum pname,
+ GLsizei *length)
{
if (length)
{
@@ -5355,7 +5339,7 @@
template <typename ParamType>
bool ValidateTexParameterBase(Context *context,
- GLenum target,
+ TextureType target,
GLenum pname,
GLsizei bufSize,
const ParamType *params)
@@ -5398,8 +5382,7 @@
ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required);
return false;
}
- if (target == GL_TEXTURE_EXTERNAL_OES &&
- !context->getExtensions().eglImageExternalEssl3)
+ if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3)
{
context->handleError(InvalidEnum() << "ES3 texture parameters are not "
"available without "
@@ -5412,7 +5395,7 @@
break;
}
- if (target == GL_TEXTURE_2D_MULTISAMPLE)
+ if (target == TextureType::_2DMultisample)
{
switch (pname)
{
@@ -5438,7 +5421,7 @@
case GL_TEXTURE_WRAP_R:
{
bool restrictedWrapModes =
- target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ANGLE;
+ target == TextureType::External || target == TextureType::Rectangle;
if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes))
{
return false;
@@ -5449,7 +5432,7 @@
case GL_TEXTURE_MIN_FILTER:
{
bool restrictedMinFilter =
- target == GL_TEXTURE_EXTERNAL_OES || target == GL_TEXTURE_RECTANGLE_ANGLE;
+ target == TextureType::External || target == TextureType::Rectangle;
if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter))
{
return false;
@@ -5539,19 +5522,19 @@
context->handleError(InvalidValue() << "Base level must be at least 0.");
return false;
}
- if (target == GL_TEXTURE_EXTERNAL_OES && static_cast<GLuint>(params[0]) != 0)
+ if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0)
{
context->handleError(InvalidOperation()
<< "Base level must be 0 for external textures.");
return false;
}
- if (target == GL_TEXTURE_2D_MULTISAMPLE && static_cast<GLuint>(params[0]) != 0)
+ if (target == TextureType::_2DMultisample && static_cast<GLuint>(params[0]) != 0)
{
context->handleError(InvalidOperation()
<< "Base level must be 0 for multisampled textures.");
return false;
}
- if (target == GL_TEXTURE_RECTANGLE_ANGLE && static_cast<GLuint>(params[0]) != 0)
+ if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0)
{
context->handleError(InvalidOperation()
<< "Base level must be 0 for rectangle textures.");
@@ -5600,8 +5583,8 @@
return true;
}
-template bool ValidateTexParameterBase(Context *, GLenum, GLenum, GLsizei, const GLfloat *);
-template bool ValidateTexParameterBase(Context *, GLenum, GLenum, GLsizei, const GLint *);
+template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *);
+template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *);
bool ValidateVertexAttribIndex(ValidationContext *context, GLuint index)
{