1 // 2 // Copyright (c) 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 // formatutils.h: Queries for GL image formats. 8 9 #ifndef LIBANGLE_FORMATUTILS_H_ 10 #define LIBANGLE_FORMATUTILS_H_ 11 12 #include <cstddef> 13 #include <ostream> 14 #include <stdint.h> 15 16 #include "angle_gl.h" 17 #include "libANGLE/Caps.h" 18 #include "libANGLE/Error.h" 19 #include "libANGLE/Version.h" 20 #include "libANGLE/angletypes.h" 21 22 namespace gl 23 { 24 struct VertexAttribute; 25 26 struct FormatType final 27 { 28 FormatType(); 29 FormatType(GLenum format_, GLenum type_); 30 FormatType(const FormatType &other) = default; 31 FormatType &operator=(const FormatType &other) = default; 32 33 bool operator<(const FormatType &other) const; 34 35 GLenum format; 36 GLenum type; 37 }; 38 39 struct Type 40 { 41 Type(); 42 43 GLuint bytes; 44 GLuint bytesShift; // Bit shift by this value to effectively divide/multiply by "bytes" in a more optimal way 45 bool specialInterpretation; 46 }; 47 const Type &GetTypeInfo(GLenum type); 48 49 // Information about an OpenGL internal format. Can be keyed on the internalFormat and type 50 // members. 51 struct InternalFormat 52 { 53 InternalFormat(); 54 InternalFormat(const InternalFormat &other); 55 56 GLuint computePixelBytes(GLenum formatType) const; 57 58 ErrorOrResult<GLuint> computeRowPitch(GLenum formatType, 59 GLsizei width, 60 GLint alignment, 61 GLint rowLength) const; 62 ErrorOrResult<GLuint> computeDepthPitch(GLsizei height, 63 GLint imageHeight, 64 GLuint rowPitch) const; 65 ErrorOrResult<GLuint> computeDepthPitch(GLenum formatType, 66 GLsizei width, 67 GLsizei height, 68 GLint alignment, 69 GLint rowLength, 70 GLint imageHeight) const; 71 72 ErrorOrResult<GLuint> computeCompressedImageSize(const Extents &size) const; 73 74 ErrorOrResult<GLuint> computeSkipBytes(GLuint rowPitch, 75 GLuint depthPitch, 76 const PixelStoreStateBase &state, 77 bool is3D) const; 78 79 ErrorOrResult<GLuint> computePackUnpackEndByte(GLenum formatType, 80 const Extents &size, 81 const PixelStoreStateBase &state, 82 bool is3D) const; 83 84 bool isLUMA() const; 85 GLenum getReadPixelsFormat() const; 86 GLenum getReadPixelsType(const Version &version) const; 87 88 // Return true if the format is a required renderbuffer format in the given version of the core 89 // spec. Note that it isn't always clear whether all the rules that apply to core required 90 // renderbuffer formats also apply to additional formats added by extensions. Because of this 91 // extension formats are conservatively not included. 92 bool isRequiredRenderbufferFormat(const Version &version) const; 93 94 bool operator==(const InternalFormat &other) const; 95 bool operator!=(const InternalFormat &other) const; 96 97 GLenum internalFormat; 98 99 bool sized; 100 GLenum sizedInternalFormat; 101 102 GLuint redBits; 103 GLuint greenBits; 104 GLuint blueBits; 105 106 GLuint luminanceBits; 107 108 GLuint alphaBits; 109 GLuint sharedBits; 110 111 GLuint depthBits; 112 GLuint stencilBits; 113 114 GLuint pixelBytes; 115 116 GLuint componentCount; 117 118 bool compressed; 119 GLuint compressedBlockWidth; 120 GLuint compressedBlockHeight; 121 122 GLenum format; 123 GLenum type; 124 125 GLenum componentType; 126 GLenum colorEncoding; 127 128 typedef bool (*SupportCheckFunction)(const Version &, const Extensions &); 129 SupportCheckFunction textureSupport; 130 SupportCheckFunction renderSupport; 131 SupportCheckFunction filterSupport; 132 }; 133 134 // A "Format" wraps an InternalFormat struct, querying it from either a sized internal format or 135 // unsized internal format and type. 136 // TODO(geofflang): Remove this, it doesn't add any more information than the InternalFormat object. 137 struct Format 138 { 139 // Sized types only. 140 explicit Format(GLenum internalFormat); 141 142 // Sized or unsized types. 143 explicit Format(const InternalFormat &internalFormat); 144 Format(GLenum internalFormat, GLenum type); 145 146 Format(const Format &other); 147 Format &operator=(const Format &other); 148 149 bool valid() const; 150 151 static Format Invalid(); 152 static bool SameSized(const Format &a, const Format &b); 153 static bool EquivalentForBlit(const Format &a, const Format &b); 154 155 friend std::ostream &operator<<(std::ostream &os, const Format &fmt); 156 157 // This is the sized info. 158 const InternalFormat *info; 159 }; 160 161 const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat); 162 const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type); 163 164 // Strip sizing information from an internal format. Doesn't necessarily validate that the internal 165 // format is valid. 166 GLenum GetUnsizedFormat(GLenum internalFormat); 167 168 typedef std::set<GLenum> FormatSet; 169 const FormatSet &GetAllSizedInternalFormats(); 170 171 // From the ESSL 3.00.4 spec: 172 // Vertex shader inputs can only be float, floating-point vectors, matrices, signed and unsigned 173 // integers and integer vectors. Vertex shader inputs cannot be arrays or structures. 174 175 enum AttributeType 176 { 177 ATTRIBUTE_FLOAT, 178 ATTRIBUTE_VEC2, 179 ATTRIBUTE_VEC3, 180 ATTRIBUTE_VEC4, 181 ATTRIBUTE_INT, 182 ATTRIBUTE_IVEC2, 183 ATTRIBUTE_IVEC3, 184 ATTRIBUTE_IVEC4, 185 ATTRIBUTE_UINT, 186 ATTRIBUTE_UVEC2, 187 ATTRIBUTE_UVEC3, 188 ATTRIBUTE_UVEC4, 189 ATTRIBUTE_MAT2, 190 ATTRIBUTE_MAT3, 191 ATTRIBUTE_MAT4, 192 ATTRIBUTE_MAT2x3, 193 ATTRIBUTE_MAT2x4, 194 ATTRIBUTE_MAT3x2, 195 ATTRIBUTE_MAT3x4, 196 ATTRIBUTE_MAT4x2, 197 ATTRIBUTE_MAT4x3, 198 }; 199 200 AttributeType GetAttributeType(GLenum enumValue); 201 202 enum VertexFormatType 203 { 204 VERTEX_FORMAT_INVALID, 205 VERTEX_FORMAT_SBYTE1, 206 VERTEX_FORMAT_SBYTE1_NORM, 207 VERTEX_FORMAT_SBYTE2, 208 VERTEX_FORMAT_SBYTE2_NORM, 209 VERTEX_FORMAT_SBYTE3, 210 VERTEX_FORMAT_SBYTE3_NORM, 211 VERTEX_FORMAT_SBYTE4, 212 VERTEX_FORMAT_SBYTE4_NORM, 213 VERTEX_FORMAT_UBYTE1, 214 VERTEX_FORMAT_UBYTE1_NORM, 215 VERTEX_FORMAT_UBYTE2, 216 VERTEX_FORMAT_UBYTE2_NORM, 217 VERTEX_FORMAT_UBYTE3, 218 VERTEX_FORMAT_UBYTE3_NORM, 219 VERTEX_FORMAT_UBYTE4, 220 VERTEX_FORMAT_UBYTE4_NORM, 221 VERTEX_FORMAT_SSHORT1, 222 VERTEX_FORMAT_SSHORT1_NORM, 223 VERTEX_FORMAT_SSHORT2, 224 VERTEX_FORMAT_SSHORT2_NORM, 225 VERTEX_FORMAT_SSHORT3, 226 VERTEX_FORMAT_SSHORT3_NORM, 227 VERTEX_FORMAT_SSHORT4, 228 VERTEX_FORMAT_SSHORT4_NORM, 229 VERTEX_FORMAT_USHORT1, 230 VERTEX_FORMAT_USHORT1_NORM, 231 VERTEX_FORMAT_USHORT2, 232 VERTEX_FORMAT_USHORT2_NORM, 233 VERTEX_FORMAT_USHORT3, 234 VERTEX_FORMAT_USHORT3_NORM, 235 VERTEX_FORMAT_USHORT4, 236 VERTEX_FORMAT_USHORT4_NORM, 237 VERTEX_FORMAT_SINT1, 238 VERTEX_FORMAT_SINT1_NORM, 239 VERTEX_FORMAT_SINT2, 240 VERTEX_FORMAT_SINT2_NORM, 241 VERTEX_FORMAT_SINT3, 242 VERTEX_FORMAT_SINT3_NORM, 243 VERTEX_FORMAT_SINT4, 244 VERTEX_FORMAT_SINT4_NORM, 245 VERTEX_FORMAT_UINT1, 246 VERTEX_FORMAT_UINT1_NORM, 247 VERTEX_FORMAT_UINT2, 248 VERTEX_FORMAT_UINT2_NORM, 249 VERTEX_FORMAT_UINT3, 250 VERTEX_FORMAT_UINT3_NORM, 251 VERTEX_FORMAT_UINT4, 252 VERTEX_FORMAT_UINT4_NORM, 253 VERTEX_FORMAT_SBYTE1_INT, 254 VERTEX_FORMAT_SBYTE2_INT, 255 VERTEX_FORMAT_SBYTE3_INT, 256 VERTEX_FORMAT_SBYTE4_INT, 257 VERTEX_FORMAT_UBYTE1_INT, 258 VERTEX_FORMAT_UBYTE2_INT, 259 VERTEX_FORMAT_UBYTE3_INT, 260 VERTEX_FORMAT_UBYTE4_INT, 261 VERTEX_FORMAT_SSHORT1_INT, 262 VERTEX_FORMAT_SSHORT2_INT, 263 VERTEX_FORMAT_SSHORT3_INT, 264 VERTEX_FORMAT_SSHORT4_INT, 265 VERTEX_FORMAT_USHORT1_INT, 266 VERTEX_FORMAT_USHORT2_INT, 267 VERTEX_FORMAT_USHORT3_INT, 268 VERTEX_FORMAT_USHORT4_INT, 269 VERTEX_FORMAT_SINT1_INT, 270 VERTEX_FORMAT_SINT2_INT, 271 VERTEX_FORMAT_SINT3_INT, 272 VERTEX_FORMAT_SINT4_INT, 273 VERTEX_FORMAT_UINT1_INT, 274 VERTEX_FORMAT_UINT2_INT, 275 VERTEX_FORMAT_UINT3_INT, 276 VERTEX_FORMAT_UINT4_INT, 277 VERTEX_FORMAT_FIXED1, 278 VERTEX_FORMAT_FIXED2, 279 VERTEX_FORMAT_FIXED3, 280 VERTEX_FORMAT_FIXED4, 281 VERTEX_FORMAT_HALF1, 282 VERTEX_FORMAT_HALF2, 283 VERTEX_FORMAT_HALF3, 284 VERTEX_FORMAT_HALF4, 285 VERTEX_FORMAT_FLOAT1, 286 VERTEX_FORMAT_FLOAT2, 287 VERTEX_FORMAT_FLOAT3, 288 VERTEX_FORMAT_FLOAT4, 289 VERTEX_FORMAT_SINT210, 290 VERTEX_FORMAT_UINT210, 291 VERTEX_FORMAT_SINT210_NORM, 292 VERTEX_FORMAT_UINT210_NORM, 293 VERTEX_FORMAT_SINT210_INT, 294 VERTEX_FORMAT_UINT210_INT, 295 }; 296 297 typedef std::vector<VertexFormatType> InputLayout; 298 299 struct VertexFormat : private angle::NonCopyable 300 { 301 VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn); 302 303 GLenum type; 304 GLboolean normalized; 305 GLuint components; 306 bool pureInteger; 307 }; 308 309 VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger); 310 VertexFormatType GetVertexFormatType(const VertexAttribute &attrib); 311 VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType); 312 const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType); 313 size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType); 314 315 // Check if an internal format is ever valid in ES3. Makes no checks about support for a specific 316 // context. 317 bool ValidES3InternalFormat(GLenum internalFormat); 318 319 // Implemented in format_map_autogen.cpp 320 bool ValidES3Format(GLenum format); 321 bool ValidES3Type(GLenum type); 322 bool ValidES3FormatCombination(GLenum format, GLenum type, GLenum internalFormat); 323 324 // Implemented in es3_copy_conversion_table_autogen.cpp 325 bool ValidES3CopyConversion(GLenum textureFormat, GLenum framebufferFormat); 326 327 } // namespace gl 328 329 #endif // LIBANGLE_FORMATUTILS_H_ 330