1 // 2 // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 7 // queryconversions.h: Declaration of state query cast conversions 8 9 #ifndef LIBANGLE_QUERY_CONVERSIONS_H_ 10 #define LIBANGLE_QUERY_CONVERSIONS_H_ 11 12 #include "angle_gl.h" 13 #include "common/angleutils.h" 14 15 namespace gl 16 { 17 class Context; 18 19 // Helper class for converting a GL type to a GLenum: 20 // We can't use CastStateValueEnum generally, because of GLboolean + GLubyte overlap. 21 // We restrict our use to CastFromStateValue and CastQueryValueTo, where it eliminates 22 // duplicate parameters. 23 24 template <typename GLType> 25 struct GLTypeToGLenum 26 { 27 // static constexpr GLenum value; 28 }; 29 30 template <> 31 struct GLTypeToGLenum<GLint> 32 { 33 static constexpr GLenum value = GL_INT; 34 }; 35 template <> 36 struct GLTypeToGLenum<GLuint> 37 { 38 static constexpr GLenum value = GL_UNSIGNED_INT; 39 }; 40 template <> 41 struct GLTypeToGLenum<GLboolean> 42 { 43 static constexpr GLenum value = GL_BOOL; 44 }; 45 template <> 46 struct GLTypeToGLenum<GLint64> 47 { 48 static constexpr GLenum value = GL_INT_64_ANGLEX; 49 }; 50 template <> 51 struct GLTypeToGLenum<GLuint64> 52 { 53 static constexpr GLenum value = GL_UINT_64_ANGLEX; 54 }; 55 template <> 56 struct GLTypeToGLenum<GLfloat> 57 { 58 static constexpr GLenum value = GL_FLOAT; 59 }; 60 61 GLint CastMaskValue(const Context *context, GLuint value); 62 63 template <typename QueryT, typename InternalT> 64 QueryT CastFromGLintStateValue(GLenum pname, InternalT value); 65 66 template <typename QueryT, typename NativeT> 67 QueryT CastFromStateValue(GLenum pname, NativeT value); 68 69 template <typename NativeT, typename QueryT> 70 NativeT CastQueryValueTo(GLenum pname, QueryT value); 71 72 template <typename ParamType> 73 GLenum ConvertToGLenum(GLenum pname, ParamType param) 74 { 75 return static_cast<GLenum>(CastQueryValueTo<GLuint>(pname, param)); 76 } 77 78 template <typename ParamType> 79 GLenum ConvertToGLenum(ParamType param) 80 { 81 return ConvertToGLenum(GL_NONE, param); 82 } 83 84 template <typename ParamType> 85 GLenum ConvertToGLint(ParamType param) 86 { 87 return CastQueryValueTo<GLint>(GL_NONE, param); 88 } 89 90 template <typename ParamType> 91 bool ConvertToBool(ParamType param) 92 { 93 return param != GL_FALSE; 94 } 95 96 template <typename ParamType> 97 GLboolean ConvertToGLBoolean(ParamType param) 98 { 99 return param ? GL_TRUE : GL_FALSE; 100 } 101 102 // The GL state query API types are: bool, int, uint, float, int64, uint64 103 template <typename QueryT> 104 void CastStateValues(Context *context, GLenum nativeType, GLenum pname, 105 unsigned int numParams, QueryT *outParams); 106 107 // The GL state query API types are: bool, int, uint, float, int64, uint64 108 template <typename QueryT> 109 void CastIndexedStateValues(Context *context, 110 GLenum nativeType, 111 GLenum pname, 112 GLuint index, 113 unsigned int numParams, 114 QueryT *outParams); 115 } 116 117 #endif // LIBANGLE_QUERY_CONVERSIONS_H_ 118