• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 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(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 OutType>
85 OutType ConvertGLenum(GLenum param)
86 {
87     return static_cast<OutType>(param);
88 }
89 
90 template <typename InType, typename OutType>
91 void ConvertGLenumValue(InType param, OutType *out)
92 {
93     *out = ConvertGLenum<OutType>(static_cast<GLenum>(param));
94 }
95 
96 template <typename PackedEnumType, typename OutType>
97 void ConvertPackedEnum(PackedEnumType param, OutType *out)
98 {
99     *out = static_cast<OutType>(ToGLenum(param));
100 }
101 
102 template <typename ParamType>
103 GLint ConvertToGLint(ParamType param)
104 {
105     return CastQueryValueTo<GLint>(GL_NONE, param);
106 }
107 
108 template <typename ParamType>
109 bool ConvertToBool(ParamType param)
110 {
111     return param != GL_FALSE;
112 }
113 
114 template <typename ParamType>
115 GLboolean ConvertToGLBoolean(ParamType param)
116 {
117     return param ? GL_TRUE : GL_FALSE;
118 }
119 
120 // The GL state query API types are: bool, int, uint, float, int64, uint64
121 template <typename QueryT>
122 void CastStateValues(const Context *context,
123                      GLenum nativeType,
124                      GLenum pname,
125                      unsigned int numParams,
126                      QueryT *outParams);
127 
128 // The GL state query API types are: bool, int, uint, float, int64, uint64
129 template <typename QueryT>
130 void CastIndexedStateValues(Context *context,
131                             GLenum nativeType,
132                             GLenum pname,
133                             GLuint index,
134                             unsigned int numParams,
135                             QueryT *outParams);
136 }  // namespace gl
137 
138 #endif  // LIBANGLE_QUERY_CONVERSIONS_H_
139