From 5f8de423f190bbb79a62f804151bc24824fa32d8 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 2 Feb 2018 04:16:08 -0500 Subject: Add m-esr52 at 52.6.0 --- gfx/angle/src/libANGLE/queryconversions.cpp | 219 ++++++++++++++++++++++++++++ 1 file changed, 219 insertions(+) create mode 100755 gfx/angle/src/libANGLE/queryconversions.cpp (limited to 'gfx/angle/src/libANGLE/queryconversions.cpp') diff --git a/gfx/angle/src/libANGLE/queryconversions.cpp b/gfx/angle/src/libANGLE/queryconversions.cpp new file mode 100755 index 000000000..611fbc4ba --- /dev/null +++ b/gfx/angle/src/libANGLE/queryconversions.cpp @@ -0,0 +1,219 @@ +// +// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. +// + +// queryconversions.cpp: Implementation of state query cast conversions + +#include "libANGLE/queryconversions.h" + +#include + +#include "libANGLE/Context.h" +#include "common/utilities.h" + +namespace gl +{ + +namespace +{ + +GLint64 ExpandFloatToInteger(GLfloat value) +{ + return static_cast((static_cast(0xFFFFFFFFULL) * value - 1.0) / 2.0); +} + +template +QueryT ClampToQueryRange(GLint64 value) +{ + const GLint64 min = static_cast(std::numeric_limits::min()); + const GLint64 max = static_cast(std::numeric_limits::max()); + return static_cast(clamp(value, min, max)); +} + +template +QueryT CastStateValueToInt(GLenum pname, NativeT value) +{ + GLenum queryType = GLTypeToGLenum::value; + GLenum nativeType = GLTypeToGLenum::value; + + if (nativeType == GL_FLOAT) + { + // 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(ExpandFloatToInteger(static_cast(value))); + } + else + { + return gl::iround(static_cast(value)); + } + } + + // Clamp 64-bit int values when casting to int + if (nativeType == GL_INT_64_ANGLEX && queryType == GL_INT) + { + GLint64 minIntValue = static_cast(std::numeric_limits::min()); + GLint64 maxIntValue = static_cast(std::numeric_limits::max()); + GLint64 clampedValue = std::max(std::min(static_cast(value), maxIntValue), minIntValue); + return static_cast(clampedValue); + } + + return static_cast(value); +} + +template +QueryT CastStateValue(GLenum pname, NativeT value) +{ + GLenum queryType = GLTypeToGLenum::value; + + switch (queryType) + { + case GL_INT: + return CastStateValueToInt(pname, value); + case GL_INT_64_ANGLEX: + return CastStateValueToInt(pname, value); + case GL_FLOAT: + return static_cast(value); + case GL_BOOL: + return static_cast(value == static_cast(0) ? GL_FALSE : GL_TRUE); + default: + UNREACHABLE(); + return 0; + } +} + +} // anonymous namespace + +template +void CastStateValues(Context *context, GLenum nativeType, GLenum pname, + unsigned int numParams, QueryT *outParams) +{ + if (nativeType == GL_INT) + { + std::vector intParams(numParams, 0); + context->getIntegerv(pname, intParams.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = CastStateValue(pname, intParams[i]); + } + } + else if (nativeType == GL_BOOL) + { + std::vector boolParams(numParams, GL_FALSE); + context->getBooleanv(pname, boolParams.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = (boolParams[i] == GL_FALSE ? static_cast(0) : static_cast(1)); + } + } + else if (nativeType == GL_FLOAT) + { + std::vector floatParams(numParams, 0.0f); + context->getFloatv(pname, floatParams.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = CastStateValue(pname, floatParams[i]); + } + } + else if (nativeType == GL_INT_64_ANGLEX) + { + std::vector int64Params(numParams, 0); + context->getInteger64v(pname, int64Params.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = CastStateValue(pname, int64Params[i]); + } + } + else UNREACHABLE(); +} + +// 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 + +template void CastStateValues(Context *, GLenum, GLenum, unsigned int, GLboolean *); +template void CastStateValues(Context *, GLenum, GLenum, unsigned int, GLint *); +template void CastStateValues(Context *, GLenum, GLenum, unsigned int, GLuint *); +template void CastStateValues(Context *, GLenum, GLenum, unsigned int, GLfloat *); +template void CastStateValues(Context *, GLenum, GLenum, unsigned int, GLint64 *); + +template +void CastIndexedStateValues(Context *context, + GLenum nativeType, + GLenum pname, + GLuint index, + unsigned int numParams, + QueryT *outParams) +{ + if (nativeType == GL_INT) + { + std::vector intParams(numParams, 0); + context->getIntegeri_v(pname, index, intParams.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = CastStateValue(pname, intParams[i]); + } + } + else if (nativeType == GL_BOOL) + { + std::vector boolParams(numParams, GL_FALSE); + context->getBooleani_v(pname, index, boolParams.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = + (boolParams[i] == GL_FALSE ? static_cast(0) : static_cast(1)); + } + } + else if (nativeType == GL_INT_64_ANGLEX) + { + std::vector int64Params(numParams, 0); + context->getInteger64i_v(pname, index, int64Params.data()); + + for (unsigned int i = 0; i < numParams; ++i) + { + outParams[i] = CastStateValue(pname, int64Params[i]); + } + } + else + UNREACHABLE(); +} + +template void CastIndexedStateValues(Context *, + GLenum, + GLenum, + GLuint index, + unsigned int, + GLboolean *); +template void CastIndexedStateValues(Context *, + GLenum, + GLenum, + GLuint index, + unsigned int, + GLint *); +template void CastIndexedStateValues(Context *, + GLenum, + GLenum, + GLuint index, + unsigned int, + GLuint *); +template void CastIndexedStateValues(Context *, + GLenum, + GLenum, + GLuint index, + unsigned int, + GLfloat *); +template void CastIndexedStateValues(Context *, + GLenum, + GLenum, + GLuint index, + unsigned int, + GLint64 *); +} -- cgit v1.2.3