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 #include "angle_gl.h" 19 20 #include "common/mathutil.h" 21 22 namespace sh 23 { 24 struct ShaderVariable; 25 } 26 27 namespace gl 28 { 29 30 int VariableComponentCount(GLenum type); 31 GLenum VariableComponentType(GLenum type); 32 size_t VariableComponentSize(GLenum type); 33 size_t VariableInternalSize(GLenum type); 34 size_t VariableExternalSize(GLenum type); 35 int VariableRowCount(GLenum type); 36 int VariableColumnCount(GLenum type); 37 bool IsSamplerType(GLenum type); 38 bool IsImageType(GLenum type); 39 bool IsAtomicCounterType(GLenum type); 40 bool IsOpaqueType(GLenum type); 41 GLenum SamplerTypeToTextureType(GLenum samplerType); 42 bool IsMatrixType(GLenum type); 43 GLenum TransposeMatrixType(GLenum type); 44 int VariableRegisterCount(GLenum type); 45 int MatrixRegisterCount(GLenum type, bool isRowMajorMatrix); 46 int MatrixComponentCount(GLenum type, bool isRowMajorMatrix); 47 int VariableSortOrder(GLenum type); 48 GLenum VariableBoolVectorType(GLenum type); 49 50 int AllocateFirstFreeBits(unsigned int *bits, unsigned int allocationSize, unsigned int bitsSize); 51 52 static const GLenum FirstCubeMapTextureTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X; 53 static const GLenum LastCubeMapTextureTarget = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z; 54 bool IsCubeMapTextureTarget(GLenum target); 55 size_t CubeMapTextureTargetToLayerIndex(GLenum target); 56 GLenum LayerIndexToCubeMapTextureTarget(size_t index); 57 58 // Parse the base resource name and array indices. Returns the base name of the resource. 59 // If the provided name doesn't index an array, the outSubscripts vector will be empty. 60 // If the provided name indexes an array, the outSubscripts vector will contain indices with 61 // outermost array indices in the back. If an array index is invalid, GL_INVALID_INDEX is added to 62 // outSubscripts. 63 std::string ParseResourceName(const std::string &name, std::vector<unsigned int> *outSubscripts); 64 65 // Find the child field which matches 'fullName' == var.name + "." + field.name. 66 // Return nullptr if not found. 67 const sh::ShaderVariable *FindShaderVarField(const sh::ShaderVariable &var, 68 const std::string &fullName); 69 70 // Find the range of index values in the provided indices pointer. Primitive restart indices are 71 // only counted in the range if primitive restart is disabled. 72 IndexRange ComputeIndexRange(GLenum indexType, 73 const GLvoid *indices, 74 size_t count, 75 bool primitiveRestartEnabled); 76 77 // Get the primitive restart index value for the given index type. 78 GLuint GetPrimitiveRestartIndex(GLenum indexType); 79 80 bool IsTriangleMode(GLenum drawMode); 81 bool IsIntegerFormat(GLenum unsizedFormat); 82 83 // Returns the product of the sizes in the vector, or 1 if the vector is empty. Doesn't currently 84 // perform overflow checks. 85 unsigned int ArraySizeProduct(const std::vector<unsigned int> &arraySizes); 86 87 // Return the array index at the end of name, and write the length of name before the final array 88 // index into nameLengthWithoutArrayIndexOut. In case name doesn't include an array index, return 89 // GL_INVALID_INDEX and write the length of the original string. 90 unsigned int ParseArrayIndex(const std::string &name, size_t *nameLengthWithoutArrayIndexOut); 91 92 struct UniformTypeInfo final : angle::NonCopyable 93 { UniformTypeInfofinal94 constexpr UniformTypeInfo(GLenum type, 95 GLenum componentType, 96 GLenum textureType, 97 GLenum transposedMatrixType, 98 GLenum boolVectorType, 99 int rowCount, 100 int columnCount, 101 int componentCount, 102 size_t componentSize, 103 size_t internalSize, 104 size_t externalSize, 105 bool isSampler, 106 bool isMatrixType, 107 bool isImageType) 108 : type(type), 109 componentType(componentType), 110 textureType(textureType), 111 transposedMatrixType(transposedMatrixType), 112 boolVectorType(boolVectorType), 113 rowCount(rowCount), 114 columnCount(columnCount), 115 componentCount(componentCount), 116 componentSize(componentSize), 117 internalSize(internalSize), 118 externalSize(externalSize), 119 isSampler(isSampler), 120 isMatrixType(isMatrixType), 121 isImageType(isImageType) 122 { 123 } 124 125 GLenum type; 126 GLenum componentType; 127 GLenum textureType; 128 GLenum transposedMatrixType; 129 GLenum boolVectorType; 130 int rowCount; 131 int columnCount; 132 int componentCount; 133 size_t componentSize; 134 size_t internalSize; 135 size_t externalSize; 136 bool isSampler; 137 bool isMatrixType; 138 bool isImageType; 139 }; 140 141 const UniformTypeInfo &GetUniformTypeInfo(GLenum uniformType); 142 143 const char *GetGenericErrorMessage(GLenum error); 144 145 unsigned int ElementTypeSize(GLenum elementType); 146 147 } // namespace gl 148 149 namespace egl 150 { 151 static const EGLenum FirstCubeMapTextureTarget = EGL_GL_TEXTURE_CUBE_MAP_POSITIVE_X_KHR; 152 static const EGLenum LastCubeMapTextureTarget = EGL_GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_KHR; 153 bool IsCubeMapTextureTarget(EGLenum target); 154 size_t CubeMapTextureTargetToLayerIndex(EGLenum target); 155 EGLenum LayerIndexToCubeMapTextureTarget(size_t index); 156 bool IsTextureTarget(EGLenum target); 157 bool IsRenderbufferTarget(EGLenum target); 158 159 const char *GetGenericErrorMessage(EGLint error); 160 } // namespace egl 161 162 namespace egl_gl 163 { 164 GLenum EGLCubeMapTargetToGLCubeMapTarget(EGLenum eglTarget); 165 GLenum EGLImageTargetToGLTextureTarget(EGLenum eglTarget); 166 GLenum EGLTextureTargetToGLTextureTarget(EGLenum eglTarget); 167 GLuint EGLClientBufferToGLObjectHandle(EGLClientBuffer buffer); 168 } 169 170 namespace gl_egl 171 { 172 EGLenum GLComponentTypeToEGLColorComponentType(GLenum glComponentType); 173 } // namespace gl_egl 174 175 #if !defined(ANGLE_ENABLE_WINDOWS_STORE) 176 std::string getTempPath(); 177 void writeFile(const char* path, const void* data, size_t size); 178 #endif 179 180 #if defined (ANGLE_PLATFORM_WINDOWS) 181 void ScheduleYield(); 182 #endif 183 184 #endif // COMMON_UTILITIES_H_ 185