Refactor data conversions for state commands
This mainly enforces the rules as descripted in ES 3.10, section
2.2.1 and 2.2.2, by enhancing the "queryconversions" to support
more rules, removing the scattered type convertors in "utilities"
, "mathutil" and "queryutils", and forcing to only use the
convertors in "queryconversions".
BUG=angleproject:2165
Change-Id: I73c1dc850e2b3b8a479ece1d9c5eb7ae4ce851fe
Reviewed-on: https://chromium-review.googlesource.com/680094
Commit-Queue: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/common/angleutils.h b/src/common/angleutils.h
index 99b8448..6365f4e 100644
--- a/src/common/angleutils.h
+++ b/src/common/angleutils.h
@@ -208,6 +208,7 @@
#define GL_BGRA4_ANGLEX 0x6ABC
#define GL_BGR5_A1_ANGLEX 0x6ABD
#define GL_INT_64_ANGLEX 0x6ABE
+#define GL_UINT_64_ANGLEX 0x6ABF
// Hidden enum for the NULL D3D device type.
#define EGL_PLATFORM_ANGLE_DEVICE_TYPE_NULL_ANGLE 0x6AC0
diff --git a/src/common/mathutil.h b/src/common/mathutil.h
index ccfab21..da2fe3a 100644
--- a/src/common/mathutil.h
+++ b/src/common/mathutil.h
@@ -60,37 +60,38 @@
return x;
}
-inline int clampToInt(unsigned int x)
-{
- return static_cast<int>(std::min(x, static_cast<unsigned int>(std::numeric_limits<int>::max())));
-}
-
template <typename DestT, typename SrcT>
inline DestT clampCast(SrcT value)
{
- static const DestT destLo = std::numeric_limits<DestT>::min();
- static const DestT destHi = std::numeric_limits<DestT>::max();
- static const SrcT srcLo = static_cast<SrcT>(destLo);
- static const SrcT srcHi = static_cast<SrcT>(destHi);
+ // For floating-point types with denormalization, min returns the minimum positive normalized
+ // value. To find the value that has no values less than it, use numeric_limits::lowest.
+ constexpr const long double destLo =
+ static_cast<long double>(std::numeric_limits<DestT>::lowest());
+ constexpr const long double destHi =
+ static_cast<long double>(std::numeric_limits<DestT>::max());
+ constexpr const long double srcLo =
+ static_cast<long double>(std::numeric_limits<SrcT>::lowest());
+ constexpr long double srcHi = static_cast<long double>(std::numeric_limits<SrcT>::max());
- // When value is outside of or equal to the limits for DestT we use the DestT limit directly.
- // This avoids undefined behaviors due to loss of precision when converting from floats to
- // integers:
- // destHi for ints is 2147483647 but the closest float number is around 2147483648, so when
- // doing a conversion from float to int we run into an UB because the float is outside of the
- // range representable by the int.
- if (value <= srcLo)
+ if (destHi < srcHi)
{
- return destLo;
+ DestT destMax = std::numeric_limits<DestT>::max();
+ if (value >= static_cast<SrcT>(destMax))
+ {
+ return destMax;
+ }
}
- else if (value >= srcHi)
+
+ if (destLo > srcLo)
{
- return destHi;
+ DestT destLow = std::numeric_limits<DestT>::lowest();
+ if (value <= static_cast<SrcT>(destLow))
+ {
+ return destLow;
+ }
}
- else
- {
- return static_cast<DestT>(value);
- }
+
+ return static_cast<DestT>(value);
}
template<typename T, typename MIN, typename MAX>
diff --git a/src/common/utilities.cpp b/src/common/utilities.cpp
index 03cb57c..efa175a 100644
--- a/src/common/utilities.cpp
+++ b/src/common/utilities.cpp
@@ -766,43 +766,6 @@
return name.substr(0, open);
}
-template <>
-GLuint ConvertToGLuint(GLfloat param)
-{
- return uiround<GLuint>(param);
-}
-
-template <>
-GLint ConvertToGLint(uint32_t param)
-{
- uint32_t max = static_cast<uint32_t>(std::numeric_limits<GLint>::max());
- return static_cast<GLint>(param >= max ? max : param);
-}
-
-template <>
-GLint ConvertToGLint(uint64_t param)
-{
- uint64_t max = static_cast<uint64_t>(std::numeric_limits<GLint>::max());
- return static_cast<GLint>(param >= max ? max : param);
-}
-
-template <>
-GLint ConvertToGLint(GLfloat param)
-{
- return iround<GLint>(param);
-}
-
-template <>
-GLint ConvertFromGLfloat(GLfloat param)
-{
- return iround<GLint>(param);
-}
-template <>
-GLuint ConvertFromGLfloat(GLfloat param)
-{
- return uiround<GLuint>(param);
-}
-
unsigned int ParseAndStripArrayIndex(std::string *name)
{
unsigned int subscript = GL_INVALID_INDEX;
diff --git a/src/common/utilities.h b/src/common/utilities.h
index b3d5d7d..84e1ff7 100644
--- a/src/common/utilities.h
+++ b/src/common/utilities.h
@@ -67,94 +67,6 @@
bool IsTriangleMode(GLenum drawMode);
bool IsIntegerFormat(GLenum unsizedFormat);
-// [OpenGL ES 3.0.2] Section 2.3.1 page 14
-// Data Conversion For State-Setting Commands
-// Floating-point values are rounded to the nearest integer, instead of truncated, as done by static_cast.
-template <typename outT> outT iround(GLfloat value) { return static_cast<outT>(value > 0.0f ? floor(value + 0.5f) : ceil(value - 0.5f)); }
-template <typename outT> outT uiround(GLfloat value) { return static_cast<outT>(value + 0.5f); }
-
-// Helper for converting arbitrary GL types to other GL types used in queries and state setting
-
-// TODO(jie.a.chen@intel.com): Add the conversion rule for all helpers as the spec requires:
-// "If a value is so large in magnitude that it cannot be represented with the requested type,"
-// "then the nearest value representable using the requested type is returned."
-
-template <typename ParamType>
-GLuint ConvertToGLuint(ParamType param)
-{
- return static_cast<GLuint>(param);
-}
-template <>
-GLuint ConvertToGLuint(GLfloat param);
-
-template <typename ParamType>
-GLint ConvertToGLint(ParamType param)
-{
- return static_cast<GLint>(param);
-}
-
-template <>
-GLint ConvertToGLint(uint32_t param);
-
-template <>
-GLint ConvertToGLint(uint64_t param);
-
-template <>
-GLint ConvertToGLint(GLfloat param);
-
-// Same conversion as uint
-template <typename ParamType>
-GLenum ConvertToGLenum(ParamType param)
-{
- return static_cast<GLenum>(ConvertToGLuint(param));
-}
-
-template <typename ParamType>
-GLfloat ConvertToGLfloat(ParamType param)
-{
- return static_cast<GLfloat>(param);
-}
-
-template <typename ParamType>
-ParamType ConvertFromGLfloat(GLfloat param)
-{
- return static_cast<ParamType>(param);
-}
-template <>
-GLint ConvertFromGLfloat(GLfloat param);
-template <>
-GLuint ConvertFromGLfloat(GLfloat param);
-
-template <typename ParamType>
-ParamType ConvertFromGLenum(GLenum param)
-{
- return static_cast<ParamType>(param);
-}
-
-template <typename ParamType>
-ParamType ConvertFromGLuint(GLuint param)
-{
- return static_cast<ParamType>(param);
-}
-
-template <typename ParamType>
-ParamType ConvertFromGLint(GLint param)
-{
- return static_cast<ParamType>(param);
-}
-
-template <typename ParamType>
-ParamType ConvertFromGLboolean(GLboolean param)
-{
- return static_cast<ParamType>(param ? GL_TRUE : GL_FALSE);
-}
-
-template <typename ParamType>
-ParamType ConvertFromGLint64(GLint64 param)
-{
- return clampCast<ParamType>(param);
-}
-
unsigned int ParseAndStripArrayIndex(std::string *name);
struct UniformTypeInfo final : angle::NonCopyable
diff --git a/src/libANGLE/Context.cpp b/src/libANGLE/Context.cpp
index 9c3c55d..f653245 100644
--- a/src/libANGLE/Context.cpp
+++ b/src/libANGLE/Context.cpp
@@ -118,7 +118,7 @@
gl::Error error = query->isResultAvailable(&available);
if (!error.isError())
{
- *params = gl::ConvertFromGLboolean<T>(available);
+ *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
}
return error;
}
diff --git a/src/libANGLE/State.cpp b/src/libANGLE/State.cpp
index 32029f6..b88d72a 100644
--- a/src/libANGLE/State.cpp
+++ b/src/libANGLE/State.cpp
@@ -12,16 +12,17 @@
#include <string.h>
#include "common/bitset_utils.h"
-#include "common/matrix_utils.h"
#include "common/mathutil.h"
-#include "libANGLE/Context.h"
+#include "common/matrix_utils.h"
#include "libANGLE/Caps.h"
+#include "libANGLE/Context.h"
#include "libANGLE/Debug.h"
#include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Query.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
+#include "libANGLE/queryconversions.h"
namespace
{
@@ -1851,10 +1852,14 @@
break;
case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break;
case GL_STENCIL_REF: *params = mStencilRef; break;
- case GL_STENCIL_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilMask); break;
+ case GL_STENCIL_VALUE_MASK:
+ *params = CastMaskValue(context, mDepthStencil.stencilMask);
+ break;
case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break;
case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break;
- case GL_STENCIL_BACK_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilBackMask); break;
+ case GL_STENCIL_BACK_VALUE_MASK:
+ *params = CastMaskValue(context, mDepthStencil.stencilBackMask);
+ break;
case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break;
case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break;
case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break;
@@ -1868,8 +1873,12 @@
case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break;
case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break;
case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break;
- case GL_STENCIL_WRITEMASK: *params = clampToInt(mDepthStencil.stencilWritemask); break;
- case GL_STENCIL_BACK_WRITEMASK: *params = clampToInt(mDepthStencil.stencilBackWritemask); break;
+ case GL_STENCIL_WRITEMASK:
+ *params = CastMaskValue(context, mDepthStencil.stencilWritemask);
+ break;
+ case GL_STENCIL_BACK_WRITEMASK:
+ *params = CastMaskValue(context, mDepthStencil.stencilBackWritemask);
+ break;
case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break;
case GL_IMPLEMENTATION_COLOR_READ_TYPE:
*params = mReadFramebuffer->getImplementationColorReadType(context);
diff --git a/src/libANGLE/queryconversions.cpp b/src/libANGLE/queryconversions.cpp
index 5beb809..78b8f84 100644
--- a/src/libANGLE/queryconversions.cpp
+++ b/src/libANGLE/queryconversions.cpp
@@ -24,18 +24,9 @@
return static_cast<GLint64>((static_cast<double>(0xFFFFFFFFULL) * value - 1.0) / 2.0);
}
-template <typename QueryT>
-QueryT ClampToQueryRange(GLint64 value)
-{
- const GLint64 min = static_cast<GLint64>(std::numeric_limits<QueryT>::min());
- const GLint64 max = static_cast<GLint64>(std::numeric_limits<QueryT>::max());
- return static_cast<QueryT>(clamp(value, min, max));
-}
-
template <typename QueryT, typename NativeT>
-QueryT CastStateValueToInt(GLenum pname, NativeT value)
+QueryT CastFromStateValueToInt(GLenum pname, NativeT value)
{
- GLenum queryType = GLTypeToGLenum<QueryT>::value;
GLenum nativeType = GLTypeToGLenum<NativeT>::value;
if (nativeType == GL_FLOAT)
@@ -43,37 +34,70 @@
// RGBA color values and DepthRangeF values are converted to integer using Equation 2.4 from Table 4.5
if (pname == GL_DEPTH_RANGE || pname == GL_COLOR_CLEAR_VALUE || pname == GL_DEPTH_CLEAR_VALUE || pname == GL_BLEND_COLOR)
{
- return ClampToQueryRange<QueryT>(ExpandFloatToInteger(static_cast<GLfloat>(value)));
+ return clampCast<QueryT>(ExpandFloatToInteger(static_cast<GLfloat>(value)));
}
else
{
- return gl::iround<QueryT>(static_cast<GLfloat>(value));
+ return clampCast<QueryT>(std::round(value));
}
}
- // Clamp 64-bit int values when casting to int
- if (nativeType == GL_INT_64_ANGLEX && queryType == GL_INT)
- {
- GLint64 minIntValue = static_cast<GLint64>(std::numeric_limits<GLint>::min());
- GLint64 maxIntValue = static_cast<GLint64>(std::numeric_limits<GLint>::max());
- GLint64 clampedValue = std::max(std::min(static_cast<GLint64>(value), maxIntValue), minIntValue);
- return static_cast<QueryT>(clampedValue);
- }
-
- return static_cast<QueryT>(value);
+ return clampCast<QueryT>(value);
}
+template <typename NativeT, typename QueryT>
+NativeT CastQueryValueToInt(GLenum pname, QueryT value)
+{
+ GLenum queryType = GLTypeToGLenum<QueryT>::value;
+
+ if (queryType == GL_FLOAT)
+ {
+ return static_cast<NativeT>(std::round(value));
+ }
+
+ return static_cast<NativeT>(value);
+}
+
+} // anonymous namespace
+
+// ES 3.10 Section 2.2.2
+// When querying bitmasks(such as SAMPLE_MASK_VALUE or STENCIL_WRITEMASK) with GetIntegerv, the
+// mask value is treated as a signed integer, so that mask values with the high bit set will not be
+// clamped when returned as signed integers.
+GLint CastMaskValue(const Context *context, GLuint value)
+{
+ return (context->getClientVersion() >= Version(3, 1) ? static_cast<GLint>(value)
+ : clampCast<GLint>(value));
+}
+
+template <typename QueryT, typename InternalT>
+QueryT CastFromGLintStateValue(GLenum pname, InternalT value)
+{
+ return CastFromStateValue<QueryT, GLint>(pname, clampCast<GLint, InternalT>(value));
+}
+
+template GLfloat CastFromGLintStateValue<GLfloat, GLenum>(GLenum pname, GLenum value);
+template GLint CastFromGLintStateValue<GLint, GLenum>(GLenum pname, GLenum value);
+template GLint64 CastFromGLintStateValue<GLint64, GLenum>(GLenum pname, GLenum value);
+template GLuint CastFromGLintStateValue<GLuint, GLenum>(GLenum pname, GLenum value);
+template GLfloat CastFromGLintStateValue<GLfloat, bool>(GLenum pname, bool value);
+template GLuint CastFromGLintStateValue<GLuint, bool>(GLenum pname, bool value);
+template GLint CastFromGLintStateValue<GLint, bool>(GLenum pname, bool value);
+template GLfloat CastFromGLintStateValue<GLfloat, size_t>(GLenum pname, size_t value);
+template GLint CastFromGLintStateValue<GLint, size_t>(GLenum pname, size_t value);
+
template <typename QueryT, typename NativeT>
-QueryT CastStateValue(GLenum pname, NativeT value)
+QueryT CastFromStateValue(GLenum pname, NativeT value)
{
GLenum queryType = GLTypeToGLenum<QueryT>::value;
switch (queryType)
{
case GL_INT:
- return CastStateValueToInt<QueryT, NativeT>(pname, value);
case GL_INT_64_ANGLEX:
- return CastStateValueToInt<QueryT, NativeT>(pname, value);
+ case GL_UNSIGNED_INT:
+ case GL_UINT_64_ANGLEX:
+ return CastFromStateValueToInt<QueryT, NativeT>(pname, value);
case GL_FLOAT:
return static_cast<QueryT>(value);
case GL_BOOL:
@@ -83,8 +107,50 @@
return 0;
}
}
+template GLint CastFromStateValue<GLint, GLint>(GLenum pname, GLint value);
+template GLint CastFromStateValue<GLint, GLint64>(GLenum pname, GLint64 value);
+template GLint64 CastFromStateValue<GLint64, GLint>(GLenum pname, GLint value);
+template GLint64 CastFromStateValue<GLint64, GLint64>(GLenum pname, GLint64 value);
+template GLfloat CastFromStateValue<GLfloat, GLint>(GLenum pname, GLint value);
+template GLfloat CastFromStateValue<GLfloat, GLfloat>(GLenum pname, GLfloat value);
+template GLint CastFromStateValue<GLint, GLfloat>(GLenum pname, GLfloat value);
+template GLuint CastFromStateValue<GLuint, GLint>(GLenum pname, GLint value);
+template GLuint CastFromStateValue<GLuint, GLuint>(GLenum pname, GLuint value);
+template GLint CastFromStateValue<GLint, GLboolean>(GLenum pname, GLboolean value);
+template GLint64 CastFromStateValue<GLint64, GLboolean>(GLenum pname, GLboolean value);
+template GLint CastFromStateValue<GLint, GLuint>(GLenum pname, GLuint value);
+template GLint64 CastFromStateValue<GLint64, GLuint>(GLenum pname, GLuint value);
+template GLuint64 CastFromStateValue<GLuint64, GLuint>(GLenum pname, GLuint value);
-} // anonymous namespace
+template <typename NativeT, typename QueryT>
+NativeT CastQueryValueTo(GLenum pname, QueryT value)
+{
+ GLenum nativeType = GLTypeToGLenum<NativeT>::value;
+
+ switch (nativeType)
+ {
+ case GL_INT:
+ case GL_INT_64_ANGLEX:
+ case GL_UNSIGNED_INT:
+ case GL_UINT_64_ANGLEX:
+ return CastQueryValueToInt<NativeT, QueryT>(pname, value);
+ case GL_FLOAT:
+ return static_cast<NativeT>(value);
+ case GL_BOOL:
+ return static_cast<NativeT>(value == static_cast<QueryT>(0) ? GL_FALSE : GL_TRUE);
+ default:
+ UNREACHABLE();
+ return 0;
+ }
+}
+
+template GLint CastQueryValueTo<GLint, GLfloat>(GLenum pname, GLfloat value);
+template GLboolean CastQueryValueTo<GLboolean, GLint>(GLenum pname, GLint value);
+template GLint CastQueryValueTo<GLint, GLint>(GLenum pname, GLint value);
+template GLfloat CastQueryValueTo<GLfloat, GLint>(GLenum pname, GLint value);
+template GLfloat CastQueryValueTo<GLfloat, GLfloat>(GLenum pname, GLfloat value);
+template GLuint CastQueryValueTo<GLuint, GLint>(GLenum pname, GLint value);
+template GLuint CastQueryValueTo<GLuint, GLfloat>(GLenum pname, GLfloat value);
template <typename QueryT>
void CastStateValues(Context *context, GLenum nativeType, GLenum pname,
@@ -97,7 +163,7 @@
for (unsigned int i = 0; i < numParams; ++i)
{
- outParams[i] = CastStateValue<QueryT>(pname, intParams[i]);
+ outParams[i] = CastFromStateValue<QueryT>(pname, intParams[i]);
}
}
else if (nativeType == GL_BOOL)
@@ -117,7 +183,7 @@
for (unsigned int i = 0; i < numParams; ++i)
{
- outParams[i] = CastStateValue<QueryT>(pname, floatParams[i]);
+ outParams[i] = CastFromStateValue<QueryT>(pname, floatParams[i]);
}
}
else if (nativeType == GL_INT_64_ANGLEX)
@@ -127,7 +193,7 @@
for (unsigned int i = 0; i < numParams; ++i)
{
- outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]);
+ outParams[i] = CastFromStateValue<QueryT>(pname, int64Params[i]);
}
}
else UNREACHABLE();
@@ -135,7 +201,7 @@
// Explicit template instantiation (how we export template functions in different files)
// The calls below will make CastStateValues successfully link with the GL state query types
-// The GL state query API types are: bool, int, uint, float, int64
+// The GL state query API types are: bool, int, uint, float, int64, uint64
template void CastStateValues<GLboolean>(Context *, GLenum, GLenum, unsigned int, GLboolean *);
template void CastStateValues<GLint>(Context *, GLenum, GLenum, unsigned int, GLint *);
@@ -158,7 +224,7 @@
for (unsigned int i = 0; i < numParams; ++i)
{
- outParams[i] = CastStateValue<QueryT>(pname, intParams[i]);
+ outParams[i] = CastFromStateValue<QueryT>(pname, intParams[i]);
}
}
else if (nativeType == GL_BOOL)
@@ -179,7 +245,7 @@
for (unsigned int i = 0; i < numParams; ++i)
{
- outParams[i] = CastStateValue<QueryT>(pname, int64Params[i]);
+ outParams[i] = CastFromStateValue<QueryT>(pname, int64Params[i]);
}
}
else
diff --git a/src/libANGLE/queryconversions.h b/src/libANGLE/queryconversions.h
index 5b96a3e..4cc32d6 100644
--- a/src/libANGLE/queryconversions.h
+++ b/src/libANGLE/queryconversions.h
@@ -18,7 +18,8 @@
// Helper class for converting a GL type to a GLenum:
// We can't use CastStateValueEnum generally, because of GLboolean + GLubyte overlap.
-// We restrict our use to CastStateValue, where it eliminates duplicate parameters.
+// We restrict our use to CastFromStateValue and CastQueryValueTo, where it eliminates
+// duplicate parameters.
template <typename GLType>
struct GLTypeToGLenum
@@ -47,17 +48,45 @@
static constexpr GLenum value = GL_INT_64_ANGLEX;
};
template <>
+struct GLTypeToGLenum<GLuint64>
+{
+ static constexpr GLenum value = GL_UINT_64_ANGLEX;
+};
+template <>
struct GLTypeToGLenum<GLfloat>
{
static constexpr GLenum value = GL_FLOAT;
};
-// The GL state query API types are: bool, int, uint, float, int64
+GLint CastMaskValue(const Context *context, GLuint value);
+
+template <typename QueryT, typename InternalT>
+QueryT CastFromGLintStateValue(GLenum pname, InternalT value);
+
+template <typename QueryT, typename NativeT>
+QueryT CastFromStateValue(GLenum pname, NativeT value);
+
+template <typename NativeT, typename QueryT>
+NativeT CastQueryValueTo(GLenum pname, QueryT value);
+
+template <typename ParamType>
+GLenum ConvertToGLenum(GLenum pname, ParamType param)
+{
+ return static_cast<GLenum>(CastQueryValueTo<GLuint>(pname, param));
+}
+
+template <typename ParamType>
+GLenum ConvertToGLenum(ParamType param)
+{
+ return ConvertToGLenum(GL_NONE, param);
+}
+
+// The GL state query API types are: bool, int, uint, float, int64, uint64
template <typename QueryT>
void CastStateValues(Context *context, GLenum nativeType, GLenum pname,
unsigned int numParams, QueryT *outParams);
-// The GL state query API types are: bool, int, uint, float, int64
+// The GL state query API types are: bool, int, uint, float, int64, uint64
template <typename QueryT>
void CastIndexedStateValues(Context *context,
GLenum nativeType,
diff --git a/src/libANGLE/queryutils.cpp b/src/libANGLE/queryutils.cpp
index ce94323..e7d5944 100644
--- a/src/libANGLE/queryutils.cpp
+++ b/src/libANGLE/queryutils.cpp
@@ -23,12 +23,14 @@
#include "libANGLE/Texture.h"
#include "libANGLE/Uniform.h"
#include "libANGLE/VertexAttribute.h"
+#include "libANGLE/queryconversions.h"
namespace gl
{
namespace
{
+
template <typename ParamType>
void QueryTexLevelParameterBase(const Texture *texture,
GLenum target,
@@ -42,66 +44,68 @@
switch (pname)
{
case GL_TEXTURE_RED_TYPE:
- *params = ConvertFromGLenum<ParamType>(info->redBits ? info->componentType : GL_NONE);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->redBits ? info->componentType : GL_NONE);
break;
case GL_TEXTURE_GREEN_TYPE:
- *params = ConvertFromGLenum<ParamType>(info->greenBits ? info->componentType : GL_NONE);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->greenBits ? info->componentType : GL_NONE);
break;
case GL_TEXTURE_BLUE_TYPE:
- *params = ConvertFromGLenum<ParamType>(info->blueBits ? info->componentType : GL_NONE);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->blueBits ? info->componentType : GL_NONE);
break;
case GL_TEXTURE_ALPHA_TYPE:
- *params = ConvertFromGLenum<ParamType>(info->alphaBits ? info->componentType : GL_NONE);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->alphaBits ? info->componentType : GL_NONE);
break;
case GL_TEXTURE_DEPTH_TYPE:
- *params = ConvertFromGLenum<ParamType>(info->depthBits ? info->componentType : GL_NONE);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->depthBits ? info->componentType : GL_NONE);
break;
case GL_TEXTURE_RED_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->redBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->redBits);
break;
case GL_TEXTURE_GREEN_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->greenBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->greenBits);
break;
case GL_TEXTURE_BLUE_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->blueBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->blueBits);
break;
case GL_TEXTURE_ALPHA_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->alphaBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->alphaBits);
break;
case GL_TEXTURE_DEPTH_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->depthBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->depthBits);
break;
case GL_TEXTURE_STENCIL_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->stencilBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->stencilBits);
break;
case GL_TEXTURE_SHARED_SIZE:
- *params = ConvertFromGLuint<ParamType>(info->sharedBits);
+ *params = CastFromGLintStateValue<ParamType>(pname, info->sharedBits);
break;
case GL_TEXTURE_INTERNAL_FORMAT:
- *params =
- ConvertFromGLenum<ParamType>(info->internalFormat ? info->internalFormat : GL_RGBA);
+ *params = CastFromGLintStateValue<ParamType>(
+ pname, info->internalFormat ? info->internalFormat : GL_RGBA);
break;
case GL_TEXTURE_WIDTH:
- *params =
- ConvertFromGLint<ParamType>(static_cast<GLint>(texture->getWidth(target, level)));
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getWidth(target, level));
break;
case GL_TEXTURE_HEIGHT:
- *params =
- ConvertFromGLint<ParamType>(static_cast<GLint>(texture->getHeight(target, level)));
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getHeight(target, level));
break;
case GL_TEXTURE_DEPTH:
- *params =
- ConvertFromGLint<ParamType>(static_cast<GLint>(texture->getDepth(target, level)));
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getDepth(target, level));
break;
case GL_TEXTURE_SAMPLES:
- *params = ConvertFromGLint<ParamType>(texture->getSamples(target, level));
+ *params = CastFromStateValue<ParamType>(pname, texture->getSamples(target, level));
break;
case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS:
- *params =
- ConvertFromGLboolean<ParamType>(texture->getFixedSampleLocations(target, level));
+ *params = CastFromStateValue<ParamType>(
+ pname, static_cast<GLint>(texture->getFixedSampleLocations(target, level)));
break;
case GL_TEXTURE_COMPRESSED:
- *params = ConvertFromGLboolean<ParamType>(info->compressed);
+ *params = CastFromStateValue<ParamType>(pname, static_cast<GLint>(info->compressed));
break;
default:
UNREACHABLE();
@@ -117,64 +121,64 @@
switch (pname)
{
case GL_TEXTURE_MAG_FILTER:
- *params = ConvertFromGLenum<ParamType>(texture->getMagFilter());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getMagFilter());
break;
case GL_TEXTURE_MIN_FILTER:
- *params = ConvertFromGLenum<ParamType>(texture->getMinFilter());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getMinFilter());
break;
case GL_TEXTURE_WRAP_S:
- *params = ConvertFromGLenum<ParamType>(texture->getWrapS());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getWrapS());
break;
case GL_TEXTURE_WRAP_T:
- *params = ConvertFromGLenum<ParamType>(texture->getWrapT());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getWrapT());
break;
case GL_TEXTURE_WRAP_R:
- *params = ConvertFromGLenum<ParamType>(texture->getWrapR());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getWrapR());
break;
case GL_TEXTURE_IMMUTABLE_FORMAT:
- *params = ConvertFromGLboolean<ParamType>(texture->getImmutableFormat());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getImmutableFormat());
break;
case GL_TEXTURE_IMMUTABLE_LEVELS:
- *params = ConvertFromGLuint<ParamType>(texture->getImmutableLevels());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getImmutableLevels());
break;
case GL_TEXTURE_USAGE_ANGLE:
- *params = ConvertFromGLenum<ParamType>(texture->getUsage());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getUsage());
break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- *params = ConvertFromGLfloat<ParamType>(texture->getMaxAnisotropy());
+ *params = CastFromStateValue<ParamType>(pname, texture->getMaxAnisotropy());
break;
case GL_TEXTURE_SWIZZLE_R:
- *params = ConvertFromGLenum<ParamType>(texture->getSwizzleRed());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getSwizzleRed());
break;
case GL_TEXTURE_SWIZZLE_G:
- *params = ConvertFromGLenum<ParamType>(texture->getSwizzleGreen());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getSwizzleGreen());
break;
case GL_TEXTURE_SWIZZLE_B:
- *params = ConvertFromGLenum<ParamType>(texture->getSwizzleBlue());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getSwizzleBlue());
break;
case GL_TEXTURE_SWIZZLE_A:
- *params = ConvertFromGLenum<ParamType>(texture->getSwizzleAlpha());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getSwizzleAlpha());
break;
case GL_TEXTURE_BASE_LEVEL:
- *params = ConvertFromGLuint<ParamType>(texture->getBaseLevel());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getBaseLevel());
break;
case GL_TEXTURE_MAX_LEVEL:
- *params = ConvertFromGLuint<ParamType>(texture->getMaxLevel());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getMaxLevel());
break;
case GL_TEXTURE_MIN_LOD:
- *params = ConvertFromGLfloat<ParamType>(texture->getSamplerState().minLod);
+ *params = CastFromStateValue<ParamType>(pname, texture->getSamplerState().minLod);
break;
case GL_TEXTURE_MAX_LOD:
- *params = ConvertFromGLfloat<ParamType>(texture->getSamplerState().maxLod);
+ *params = CastFromStateValue<ParamType>(pname, texture->getSamplerState().maxLod);
break;
case GL_TEXTURE_COMPARE_MODE:
- *params = ConvertFromGLenum<ParamType>(texture->getCompareMode());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getCompareMode());
break;
case GL_TEXTURE_COMPARE_FUNC:
- *params = ConvertFromGLenum<ParamType>(texture->getCompareFunc());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getCompareFunc());
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
- *params = ConvertFromGLenum<ParamType>(texture->getSRGBDecode());
+ *params = CastFromGLintStateValue<ParamType>(pname, texture->getSRGBDecode());
break;
default:
UNREACHABLE();
@@ -190,63 +194,64 @@
switch (pname)
{
case GL_TEXTURE_WRAP_S:
- texture->setWrapS(ConvertToGLenum(params[0]));
+ texture->setWrapS(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_WRAP_T:
- texture->setWrapT(ConvertToGLenum(params[0]));
+ texture->setWrapT(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_WRAP_R:
- texture->setWrapR(ConvertToGLenum(params[0]));
+ texture->setWrapR(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MIN_FILTER:
- texture->setMinFilter(ConvertToGLenum(params[0]));
+ texture->setMinFilter(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MAG_FILTER:
- texture->setMagFilter(ConvertToGLenum(params[0]));
+ texture->setMagFilter(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_USAGE_ANGLE:
- texture->setUsage(ConvertToGLenum(params[0]));
+ texture->setUsage(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- texture->setMaxAnisotropy(ConvertToGLfloat(params[0]));
+ texture->setMaxAnisotropy(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_TEXTURE_COMPARE_MODE:
- texture->setCompareMode(ConvertToGLenum(params[0]));
+ texture->setCompareMode(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_COMPARE_FUNC:
- texture->setCompareFunc(ConvertToGLenum(params[0]));
+ texture->setCompareFunc(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_SWIZZLE_R:
- texture->setSwizzleRed(ConvertToGLenum(params[0]));
+ texture->setSwizzleRed(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_SWIZZLE_G:
- texture->setSwizzleGreen(ConvertToGLenum(params[0]));
+ texture->setSwizzleGreen(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_SWIZZLE_B:
- texture->setSwizzleBlue(ConvertToGLenum(params[0]));
+ texture->setSwizzleBlue(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_SWIZZLE_A:
- texture->setSwizzleAlpha(ConvertToGLenum(params[0]));
+ texture->setSwizzleAlpha(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_BASE_LEVEL:
{
- context->handleError(texture->setBaseLevel(context, ConvertToGLuint(params[0])));
+ context->handleError(texture->setBaseLevel(
+ context, clampCast<GLuint>(CastQueryValueTo<GLint>(pname, params[0]))));
break;
}
case GL_TEXTURE_MAX_LEVEL:
- texture->setMaxLevel(ConvertToGLuint(params[0]));
+ texture->setMaxLevel(clampCast<GLuint>(CastQueryValueTo<GLint>(pname, params[0])));
break;
case GL_TEXTURE_MIN_LOD:
- texture->setMinLod(ConvertToGLfloat(params[0]));
+ texture->setMinLod(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_TEXTURE_MAX_LOD:
- texture->setMaxLod(ConvertToGLfloat(params[0]));
+ texture->setMaxLod(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_DEPTH_STENCIL_TEXTURE_MODE:
- texture->setDepthStencilTextureMode(ConvertToGLenum(params[0]));
+ texture->setDepthStencilTextureMode(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
- texture->setSRGBDecode(ConvertToGLenum(params[0]));
+ texture->setSRGBDecode(ConvertToGLenum(pname, params[0]));
break;
default:
UNREACHABLE();
@@ -260,37 +265,37 @@
switch (pname)
{
case GL_TEXTURE_MIN_FILTER:
- *params = ConvertFromGLenum<ParamType>(sampler->getMinFilter());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getMinFilter());
break;
case GL_TEXTURE_MAG_FILTER:
- *params = ConvertFromGLenum<ParamType>(sampler->getMagFilter());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getMagFilter());
break;
case GL_TEXTURE_WRAP_S:
- *params = ConvertFromGLenum<ParamType>(sampler->getWrapS());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getWrapS());
break;
case GL_TEXTURE_WRAP_T:
- *params = ConvertFromGLenum<ParamType>(sampler->getWrapT());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getWrapT());
break;
case GL_TEXTURE_WRAP_R:
- *params = ConvertFromGLenum<ParamType>(sampler->getWrapR());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getWrapR());
break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- *params = ConvertFromGLfloat<ParamType>(sampler->getMaxAnisotropy());
+ *params = CastFromStateValue<ParamType>(pname, sampler->getMaxAnisotropy());
break;
case GL_TEXTURE_MIN_LOD:
- *params = ConvertFromGLfloat<ParamType>(sampler->getMinLod());
+ *params = CastFromStateValue<ParamType>(pname, sampler->getMinLod());
break;
case GL_TEXTURE_MAX_LOD:
- *params = ConvertFromGLfloat<ParamType>(sampler->getMaxLod());
+ *params = CastFromStateValue<ParamType>(pname, sampler->getMaxLod());
break;
case GL_TEXTURE_COMPARE_MODE:
- *params = ConvertFromGLenum<ParamType>(sampler->getCompareMode());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getCompareMode());
break;
case GL_TEXTURE_COMPARE_FUNC:
- *params = ConvertFromGLenum<ParamType>(sampler->getCompareFunc());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getCompareFunc());
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
- *params = ConvertFromGLenum<ParamType>(sampler->getSRGBDecode());
+ *params = CastFromGLintStateValue<ParamType>(pname, sampler->getSRGBDecode());
break;
default:
UNREACHABLE();
@@ -304,37 +309,37 @@
switch (pname)
{
case GL_TEXTURE_WRAP_S:
- sampler->setWrapS(ConvertToGLenum(params[0]));
+ sampler->setWrapS(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_WRAP_T:
- sampler->setWrapT(ConvertToGLenum(params[0]));
+ sampler->setWrapT(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_WRAP_R:
- sampler->setWrapR(ConvertToGLenum(params[0]));
+ sampler->setWrapR(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MIN_FILTER:
- sampler->setMinFilter(ConvertToGLenum(params[0]));
+ sampler->setMinFilter(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MAG_FILTER:
- sampler->setMagFilter(ConvertToGLenum(params[0]));
+ sampler->setMagFilter(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MAX_ANISOTROPY_EXT:
- sampler->setMaxAnisotropy(ConvertToGLfloat(params[0]));
+ sampler->setMaxAnisotropy(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_TEXTURE_COMPARE_MODE:
- sampler->setCompareMode(ConvertToGLenum(params[0]));
+ sampler->setCompareMode(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_COMPARE_FUNC:
- sampler->setCompareFunc(ConvertToGLenum(params[0]));
+ sampler->setCompareFunc(ConvertToGLenum(pname, params[0]));
break;
case GL_TEXTURE_MIN_LOD:
- sampler->setMinLod(ConvertToGLfloat(params[0]));
+ sampler->setMinLod(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_TEXTURE_MAX_LOD:
- sampler->setMaxLod(ConvertToGLfloat(params[0]));
+ sampler->setMaxLod(CastQueryValueTo<GLfloat>(pname, params[0]));
break;
case GL_TEXTURE_SRGB_DECODE_EXT:
- sampler->setSRGBDecode(ConvertToGLenum(params[0]));
+ sampler->setSRGBDecode(ConvertToGLenum(pname, params[0]));
break;
default:
UNREACHABLE();
@@ -342,18 +347,6 @@
}
}
-template <typename ParamType, typename CurrentDataType>
-ParamType ConvertCurrentValue(CurrentDataType currentValue)
-{
- return static_cast<ParamType>(currentValue);
-}
-
-template <>
-GLint ConvertCurrentValue(GLfloat currentValue)
-{
- return iround<GLint>(currentValue);
-}
-
// Warning: you should ensure binding really matches attrib.bindingIndex before using this function.
template <typename ParamType, typename CurrentDataType, size_t CurrentValueCount>
void QueryVertexAttribBase(const VertexAttribute &attrib,
@@ -367,38 +360,38 @@
case GL_CURRENT_VERTEX_ATTRIB:
for (size_t i = 0; i < CurrentValueCount; ++i)
{
- params[i] = ConvertCurrentValue<ParamType>(currentValueData[i]);
+ params[i] = CastFromStateValue<ParamType>(pname, currentValueData[i]);
}
break;
case GL_VERTEX_ATTRIB_ARRAY_ENABLED:
- *params = ConvertFromGLboolean<ParamType>(attrib.enabled);
+ *params = CastFromStateValue<ParamType>(pname, static_cast<GLint>(attrib.enabled));
break;
case GL_VERTEX_ATTRIB_ARRAY_SIZE:
- *params = ConvertFromGLuint<ParamType>(attrib.size);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.size);
break;
case GL_VERTEX_ATTRIB_ARRAY_STRIDE:
- *params = ConvertFromGLuint<ParamType>(attrib.vertexAttribArrayStride);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.vertexAttribArrayStride);
break;
case GL_VERTEX_ATTRIB_ARRAY_TYPE:
- *params = ConvertFromGLenum<ParamType>(attrib.type);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.type);
break;
case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED:
- *params = ConvertFromGLboolean<ParamType>(attrib.normalized);
+ *params = CastFromStateValue<ParamType>(pname, static_cast<GLint>(attrib.normalized));
break;
case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:
- *params = ConvertFromGLuint<ParamType>(binding.getBuffer().id());
+ *params = CastFromGLintStateValue<ParamType>(pname, binding.getBuffer().id());
break;
case GL_VERTEX_ATTRIB_ARRAY_DIVISOR:
- *params = ConvertFromGLuint<ParamType>(binding.getDivisor());
+ *params = CastFromGLintStateValue<ParamType>(pname, binding.getDivisor());
break;
case GL_VERTEX_ATTRIB_ARRAY_INTEGER:
- *params = ConvertFromGLboolean<ParamType>(attrib.pureInteger);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.pureInteger);
break;
case GL_VERTEX_ATTRIB_BINDING:
- *params = ConvertFromGLuint<ParamType>(attrib.bindingIndex);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.bindingIndex);
break;
case GL_VERTEX_ATTRIB_RELATIVE_OFFSET:
- *params = ConvertFromGLuint<ParamType>(attrib.relativeOffset);
+ *params = CastFromGLintStateValue<ParamType>(pname, attrib.relativeOffset);
break;
default:
UNREACHABLE();
@@ -414,25 +407,25 @@
switch (pname)
{
case GL_BUFFER_USAGE:
- *params = ConvertFromGLenum<ParamType>(buffer->getUsage());
+ *params = CastFromGLintStateValue<ParamType>(pname, buffer->getUsage());
break;
case GL_BUFFER_SIZE:
- *params = ConvertFromGLint64<ParamType>(buffer->getSize());
+ *params = CastFromStateValue<ParamType>(pname, buffer->getSize());
break;
case GL_BUFFER_ACCESS_FLAGS:
- *params = ConvertFromGLuint<ParamType>(buffer->getAccessFlags());
+ *params = CastFromGLintStateValue<ParamType>(pname, buffer->getAccessFlags());
break;
case GL_BUFFER_ACCESS_OES:
- *params = ConvertFromGLenum<ParamType>(buffer->getAccess());
+ *params = CastFromGLintStateValue<ParamType>(pname, buffer->getAccess());
break;
case GL_BUFFER_MAPPED:
- *params = ConvertFromGLboolean<ParamType>(buffer->isMapped());
+ *params = CastFromStateValue<ParamType>(pname, buffer->isMapped());
break;
case GL_BUFFER_MAP_OFFSET:
- *params = ConvertFromGLint64<ParamType>(buffer->getMapOffset());
+ *params = CastFromStateValue<ParamType>(pname, buffer->getMapOffset());
break;
case GL_BUFFER_MAP_LENGTH:
- *params = ConvertFromGLint64<ParamType>(buffer->getMapLength());
+ *params = CastFromStateValue<ParamType>(pname, buffer->getMapLength());
break;
default:
UNREACHABLE();
@@ -445,13 +438,13 @@
switch (prop)
{
case GL_TYPE:
- return ConvertToGLint(var.type);
+ return clampCast<GLint>(var.type);
case GL_ARRAY_SIZE:
// TODO(jie.a.chen@intel.com): check array of array.
if (var.isArray() && !var.isStruct())
{
- return ConvertToGLint(var.elementCount());
+ return clampCast<GLint>(var.elementCount());
}
return 1;
@@ -465,7 +458,7 @@
}
// ES31 spec p84: This counts the terminating null char.
++length;
- return ConvertToGLint(length);
+ return clampCast<GLint>(length);
}
case GL_LOCATION:
@@ -532,16 +525,16 @@
switch (programInterface)
{
case GL_PROGRAM_INPUT:
- return ConvertToGLint(program->getAttributes().size());
+ return clampCast<GLint>(program->getAttributes().size());
case GL_PROGRAM_OUTPUT:
- return ConvertToGLint(program->getState().getOutputVariables().size());
+ return clampCast<GLint>(program->getState().getOutputVariables().size());
case GL_UNIFORM:
- return ConvertToGLint(program->getState().getUniforms().size());
+ return clampCast<GLint>(program->getState().getUniforms().size());
case GL_UNIFORM_BLOCK:
- return ConvertToGLint(program->getState().getUniformBlocks().size());
+ return clampCast<GLint>(program->getState().getUniformBlocks().size());
// TODO(jie.a.chen@intel.com): more interfaces.
case GL_TRANSFORM_FEEDBACK_VARYING:
@@ -563,7 +556,7 @@
GLint max = 0;
for (const T &resource : resources)
{
- max = std::max(max, ConvertToGLint((resource.*member).size()));
+ max = std::max(max, clampCast<GLint>((resource.*member).size()));
}
return max;
}
@@ -1014,30 +1007,30 @@
switch (pname)
{
case GL_UNIFORM_BLOCK_BINDING:
- *params = ConvertToGLint(program->getUniformBlockBinding(uniformBlockIndex));
+ *params = clampCast<GLint>(program->getUniformBlockBinding(uniformBlockIndex));
break;
case GL_UNIFORM_BLOCK_DATA_SIZE:
- *params = ConvertToGLint(uniformBlock.dataSize);
+ *params = clampCast<GLint>(uniformBlock.dataSize);
break;
case GL_UNIFORM_BLOCK_NAME_LENGTH:
- *params = ConvertToGLint(uniformBlock.nameWithArrayIndex().size() + 1);
+ *params = clampCast<GLint>(uniformBlock.nameWithArrayIndex().size() + 1);
break;
case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS:
- *params = ConvertToGLint(uniformBlock.memberIndexes.size());
+ *params = clampCast<GLint>(uniformBlock.memberIndexes.size());
break;
case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES:
for (size_t blockMemberIndex = 0; blockMemberIndex < uniformBlock.memberIndexes.size();
blockMemberIndex++)
{
params[blockMemberIndex] =
- ConvertToGLint(uniformBlock.memberIndexes[blockMemberIndex]);
+ clampCast<GLint>(uniformBlock.memberIndexes[blockMemberIndex]);
}
break;
case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER:
- *params = ConvertToGLint(uniformBlock.vertexStaticUse);
+ *params = static_cast<GLint>(uniformBlock.vertexStaticUse);
break;
case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER:
- *params = ConvertToGLint(uniformBlock.fragmentStaticUse);
+ *params = static_cast<GLint>(uniformBlock.fragmentStaticUse);
break;
default:
UNREACHABLE();
@@ -1052,7 +1045,7 @@
case GL_NUM_SAMPLE_COUNTS:
if (bufSize != 0)
{
- *params = static_cast<GLint>(format.sampleCounts.size());
+ *params = clampCast<GLint>(format.sampleCounts.size());
}
break;
@@ -1114,13 +1107,13 @@
switch (pname)
{
case GL_OBJECT_TYPE:
- *values = ConvertToGLint(GL_SYNC_FENCE);
+ *values = clampCast<GLint>(GL_SYNC_FENCE);
break;
case GL_SYNC_CONDITION:
- *values = ConvertToGLint(sync->getCondition());
+ *values = clampCast<GLint>(sync->getCondition());
break;
case GL_SYNC_FLAGS:
- *values = ConvertToGLint(sync->getFlags());
+ *values = clampCast<GLint>(sync->getFlags());
break;
case GL_SYNC_STATUS:
ANGLE_TRY(sync->getStatus(values));
@@ -1195,7 +1188,7 @@
framebuffer->setDefaultSamples(param);
break;
case GL_FRAMEBUFFER_DEFAULT_FIXED_SAMPLE_LOCATIONS:
- framebuffer->setDefaultFixedSampleLocations(static_cast<GLboolean>(param));
+ framebuffer->setDefaultFixedSampleLocations(CastQueryValueTo<GLboolean>(pname, param));
break;
default:
UNREACHABLE();
diff --git a/src/libANGLE/validationES.cpp b/src/libANGLE/validationES.cpp
index 21459cf..17eeb3e 100644
--- a/src/libANGLE/validationES.cpp
+++ b/src/libANGLE/validationES.cpp
@@ -21,6 +21,7 @@
#include "libANGLE/Uniform.h"
#include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h"
+#include "libANGLE/queryconversions.h"
#include "libANGLE/validationES2.h"
#include "libANGLE/validationES3.h"
@@ -33,6 +34,7 @@
{
namespace
{
+
bool ValidateDrawAttribs(ValidationContext *context,
GLint primcount,
GLint maxVertex,