1 | // |
2 | // Copyright (c) 2002-2013 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 | // utilities.h: Conversion functions and other utility routines. |
8 | |
9 | #ifndef COMMON_UTILITIES_H_ |
10 | #define COMMON_UTILITIES_H_ |
11 | |
12 | #include <EGL/egl.h> |
13 | #include <EGL/eglext.h> |
14 | |
15 | #include <math.h> |
16 | #include <string> |
17 | #include <vector> |
18 | |
19 | #include "angle_gl.h" |
20 | |
21 | #include "common/PackedEnums.h" |
22 | #include "common/mathutil.h" |
23 | #include "common/platform.h" |
24 | |
25 | namespace sh |
26 | { |
27 | struct ShaderVariable; |
28 | } |
29 | |
30 | namespace gl |
31 | { |
32 | |
33 | int VariableComponentCount(GLenum type); |
34 | GLenum VariableComponentType(GLenum type); |
35 | size_t VariableComponentSize(GLenum type); |
36 | size_t VariableInternalSize(GLenum type); |
37 | size_t VariableExternalSize(GLenum type); |
38 | int VariableRowCount(GLenum type); |
39 | int VariableColumnCount(GLenum type); |
40 | bool IsSamplerType(GLenum type); |
41 | bool IsImageType(GLenum type); |
42 | bool IsImage2DType(GLenum type); |
43 | bool IsAtomicCounterType(GLenum type); |
44 | bool IsOpaqueType(GLenum type); |
45 | bool IsMatrixType(GLenum type); |
46 | GLenum TransposeMatrixType(GLenum type); |
47 | int VariableRegisterCount(GLenum type); |
48 | int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix); |
49 | int MatrixComponentCount(GLenum type, bool isRowMajorMatrix); |
50 | int VariableSortOrder(GLenum type); |
51 | GLenum VariableBoolVectorType(GLenum type); |
52 | |
53 | int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize); |
54 | |
55 | // Parse the base resource name and array indices. Returns the base name of the resource. |
56 | // If the provided name doesn't index an array, the outSubscripts vector will be empty. |
57 | // If the provided name indexes an array, the outSubscripts vector will contain indices with |
58 | // outermost array indices in the back. If an array index is invalid, GL_INVALID_INDEX is added to |
59 | // outSubscripts. |
60 | std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts); |
61 | |
62 | // Find the child field which matches 'fullName' == var.name + "." + field.name. |
63 | // Return nullptr if not found. |
64 | const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var, |
65 | const std::string &fullName); |
66 | |
67 | // Find the range of index values in the provided indices pointer. Primitive restart indices are |
68 | // only counted in the range if primitive restart is disabled. |
69 | IndexRange ComputeIndexRange(DrawElementsType indexType, |
70 | const GLvoid *indices, |
71 | size_t count, |
72 | bool primitiveRestartEnabled); |
73 | |
74 | // Get the primitive restart index value for the given index type. |
75 | GLuint GetPrimitiveRestartIndex(DrawElementsType indexType); |
76 | |
77 | bool IsTriangleMode(PrimitiveMode drawMode); |
78 | |
79 | namespace priv |
80 | { |
81 | extern const angle::PackedEnumMap<PrimitiveMode, bool>& gLineModes(); |
82 | } // namespace priv |
83 | |
84 | ANGLE_INLINE bool IsLineMode(PrimitiveMode primitiveMode) |
85 | { |
86 | return priv::gLineModes()[primitiveMode]; |
87 | } |
88 | |
89 | bool IsIntegerFormat(GLenum unsizedFormat); |
90 | |
91 | // Returns the product of the sizes in the vector, or 1 if the vector is empty. Doesn't currently |
92 | // perform overflow checks. |
93 | unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes); |
94 | |
95 | // Return the array index at the end of name, and write the length of name before the final array |
96 | // index into nameLengthWithoutArrayIndexOut. In case name doesn't include an array index, return |
97 | // GL_INVALID_INDEX and write the length of the original string. |
98 | unsigned int ParseArrayIndex(const std::string &name, size_t *nameLengthWithoutArrayIndexOut); |
99 | |
100 | enum class SamplerFormat : uint8_t |
101 | { |
102 | Float = 0, |
103 | Unsigned = 1, |
104 | Signed = 2, |
105 | Shadow = 3, |
106 | |
107 | InvalidEnum = 4, |
108 | EnumCount = 4, |
109 | }; |
110 | |
111 | struct UniformTypeInfo final : angle::NonCopyable |
112 | { |
113 | inline constexpr UniformTypeInfo(GLenum type, |
114 | GLenum componentType, |
115 | GLenum textureType, |
116 | GLenum transposedMatrixType, |
117 | GLenum boolVectorType, |
118 | SamplerFormat samplerFormat, |
119 | int rowCount, |
120 | int columnCount, |
121 | int componentCount, |
122 | size_t componentSize, |
123 | size_t internalSize, |
124 | size_t externalSize, |
125 | bool isSampler, |
126 | bool isMatrixType, |
127 | bool isImageType); |
128 | |
129 | GLenum type; |
130 | GLenum componentType; |
131 | GLenum textureType; |
132 | GLenum transposedMatrixType; |
133 | GLenum boolVectorType; |
134 | SamplerFormat samplerFormat; |
135 | int rowCount; |
136 | int columnCount; |
137 | int componentCount; |
138 | size_t componentSize; |
139 | size_t internalSize; |
140 | size_t externalSize; |
141 | bool isSampler; |
142 | bool isMatrixType; |
143 | bool isImageType; |
144 | }; |
145 | |
146 | inline constexpr UniformTypeInfo::UniformTypeInfo(GLenum type, |
147 | GLenum componentType, |
148 | GLenum textureType, |
149 | GLenum transposedMatrixType, |
150 | GLenum boolVectorType, |
151 | SamplerFormat samplerFormat, |
152 | int rowCount, |
153 | int columnCount, |
154 | int componentCount, |
155 | size_t componentSize, |
156 | size_t internalSize, |
157 | size_t externalSize, |
158 | bool isSampler, |
159 | bool isMatrixType, |
160 | bool isImageType) |
161 | : type(type), |
162 | componentType(componentType), |
163 | textureType(textureType), |
164 | transposedMatrixType(transposedMatrixType), |
165 | boolVectorType(boolVectorType), |
166 | samplerFormat(samplerFormat), |
167 | rowCount(rowCount), |
168 | columnCount(columnCount), |
169 | componentCount(componentCount), |
170 | componentSize(componentSize), |
171 | internalSize(internalSize), |
172 | externalSize(externalSize), |
173 | isSampler(isSampler), |
174 | isMatrixType(isMatrixType), |
175 | isImageType(isImageType) |
176 | {} |
177 | |
178 | const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType); |
179 | |
180 | const char *GetGenericErrorMessage(GLenum error); |
181 | |
182 | unsigned int ElementTypeSize(GLenum elementType); |
183 | |
184 | template <typename T> |
185 | T GetClampedVertexCount(size_t vertexCount) |
186 | { |
187 | static constexpr size_t kMax = static_cast<size_t>(std::numeric_limits<T>::max()); |
188 | return static_cast<T>(vertexCount > kMax ? kMax : vertexCount); |
189 | } |
190 | } // namespace gl |
191 | |
192 | namespace egl |
193 | { |
194 | static const EGLenum FirstCubeMapTextureTarget = EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR; |
195 | static const EGLenum LastCubeMapTextureTarget = EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR; |
196 | bool IsCubeMapTextureTarget(EGLenum target); |
197 | size_t CubeMapTextureTargetToLayerIndex(EGLenum target); |
198 | EGLenum LayerIndexToCubeMapTextureTarget(size_t index); |
199 | bool IsTextureTarget(EGLenum target); |
200 | bool IsRenderbufferTarget(EGLenum target); |
201 | bool IsExternalImageTarget(EGLenum target); |
202 | |
203 | const char *GetGenericErrorMessage(EGLint error); |
204 | } // namespace egl |
205 | |
206 | namespace egl_gl |
207 | { |
208 | GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer); |
209 | } |
210 | |
211 | namespace gl_egl |
212 | { |
213 | EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType); |
214 | EGLClientBuffer GLObjectHandleToEGLClientBuffer(GLuint handle); |
215 | } // namespace gl_egl |
216 | |
217 | #if !defined(ANGLE_ENABLE_WINDOWS_STORE) |
218 | std::string getTempPath(); |
219 | void writeFile(const char *path, const void *data, size_t size); |
220 | #endif |
221 | |
222 | #if defined(ANGLE_PLATFORM_WINDOWS) |
223 | void ScheduleYield(); |
224 | #endif |
225 | |
226 | #endif // COMMON_UTILITIES_H_ |
227 | |