1 //
2 // Copyright 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.cpp: Queries for GL image formats.
8 
9 #include "libANGLE/formatutils.h"
10 
11 #include "anglebase/no_destructor.h"
12 #include "common/mathutil.h"
13 #include "gpu_info_util/SystemInfo.h"
14 #include "libANGLE/Context.h"
15 #include "libANGLE/Framebuffer.h"
16 
17 using namespace angle;
18 
19 namespace gl
20 {
21 
22 // ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the
23 // implementation can decide the true, sized, internal format. The ES2FormatMap determines the
24 // internal format for all valid format and type combinations.
25 GLenum GetSizedFormatInternal(GLenum format, GLenum type);
26 
27 namespace
28 {
CheckedMathResult(const CheckedNumeric<GLuint> & value,GLuint * resultOut)29 bool CheckedMathResult(const CheckedNumeric<GLuint> &value, GLuint *resultOut)
30 {
31     if (!value.IsValid())
32     {
33         return false;
34     }
35     else
36     {
37         *resultOut = value.ValueOrDie();
38         return true;
39     }
40 }
41 
PackTypeInfo(GLuint bytes,bool specialized)42 constexpr uint32_t PackTypeInfo(GLuint bytes, bool specialized)
43 {
44     // static_assert within constexpr requires c++17
45     // static_assert(isPow2(bytes));
46     return bytes | (rx::Log2(bytes) << 8) | (specialized << 16);
47 }
48 
49 }  // anonymous namespace
50 
FormatType()51 FormatType::FormatType() : format(GL_NONE), type(GL_NONE) {}
52 
FormatType(GLenum format_,GLenum type_)53 FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_) {}
54 
operator <(const FormatType & other) const55 bool FormatType::operator<(const FormatType &other) const
56 {
57     if (format != other.format)
58         return format < other.format;
59     return type < other.type;
60 }
61 
operator <(const Type & a,const Type & b)62 bool operator<(const Type &a, const Type &b)
63 {
64     return memcmp(&a, &b, sizeof(Type)) < 0;
65 }
66 
67 // Information about internal formats
AlwaysSupported(const Version &,const Extensions &)68 static bool AlwaysSupported(const Version &, const Extensions &)
69 {
70     return true;
71 }
72 
NeverSupported(const Version &,const Extensions &)73 static bool NeverSupported(const Version &, const Extensions &)
74 {
75     return false;
76 }
77 
78 template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
RequireES(const Version & clientVersion,const Extensions &)79 static bool RequireES(const Version &clientVersion, const Extensions &)
80 {
81     return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
82 }
83 
84 // Check support for a single extension
85 template <ExtensionBool bool1>
RequireExt(const Version &,const Extensions & extensions)86 static bool RequireExt(const Version &, const Extensions &extensions)
87 {
88     return extensions.*bool1;
89 }
90 
91 // Check for a minimum client version or a single extension
92 template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
RequireESOrExt(const Version & clientVersion,const Extensions & extensions)93 static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
94 {
95     return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
96            extensions.*bool1;
97 }
98 
99 // Check for a minimum client version or two extensions
100 template <GLuint minCoreGLMajorVersion,
101           GLuint minCoreGLMinorVersion,
102           ExtensionBool bool1,
103           ExtensionBool bool2>
RequireESOrExtAndExt(const Version & clientVersion,const Extensions & extensions)104 static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
105 {
106     return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
107            (extensions.*bool1 && extensions.*bool2);
108 }
109 
110 // Check for a minimum client version or at least one of two extensions
111 template <GLuint minCoreGLMajorVersion,
112           GLuint minCoreGLMinorVersion,
113           ExtensionBool bool1,
114           ExtensionBool bool2>
RequireESOrExtOrExt(const Version & clientVersion,const Extensions & extensions)115 static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
116 {
117     return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
118            extensions.*bool1 || extensions.*bool2;
119 }
120 
121 // Check support for two extensions
122 template <ExtensionBool bool1, ExtensionBool bool2>
RequireExtAndExt(const Version &,const Extensions & extensions)123 static bool RequireExtAndExt(const Version &, const Extensions &extensions)
124 {
125     return extensions.*bool1 && extensions.*bool2;
126 }
127 
128 // Check support for either of two extensions
129 template <ExtensionBool bool1, ExtensionBool bool2>
RequireExtOrExt(const Version &,const Extensions & extensions)130 static bool RequireExtOrExt(const Version &, const Extensions &extensions)
131 {
132     return extensions.*bool1 || extensions.*bool2;
133 }
134 
135 // Check support for any of three extensions
136 template <ExtensionBool bool1, ExtensionBool bool2, ExtensionBool bool3>
RequireExtOrExtOrExt(const Version &,const Extensions & extensions)137 static bool RequireExtOrExtOrExt(const Version &, const Extensions &extensions)
138 {
139     return extensions.*bool1 || extensions.*bool2 || extensions.*bool3;
140 }
141 
142 // R8, RG8
SizedRGSupport(const Version & clientVersion,const Extensions & extensions)143 static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
144 {
145     return clientVersion >= Version(3, 0) || (extensions.textureStorage && extensions.textureRG);
146 }
147 
148 // R16F, RG16F with HALF_FLOAT_OES type
SizedHalfFloatOESRGSupport(const Version & clientVersion,const Extensions & extensions)149 static bool SizedHalfFloatOESRGSupport(const Version &clientVersion, const Extensions &extensions)
150 {
151     return extensions.textureStorage && extensions.textureHalfFloat && extensions.textureRG;
152 }
153 
SizedHalfFloatOESRGTextureAttachmentSupport(const Version & clientVersion,const Extensions & extensions)154 static bool SizedHalfFloatOESRGTextureAttachmentSupport(const Version &clientVersion,
155                                                         const Extensions &extensions)
156 {
157     return SizedHalfFloatOESRGSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
158 }
159 
160 // R16F, RG16F with either HALF_FLOAT_OES or HALF_FLOAT types
SizedHalfFloatRGSupport(const Version & clientVersion,const Extensions & extensions)161 static bool SizedHalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
162 {
163     // HALF_FLOAT
164     if (clientVersion >= Version(3, 0))
165     {
166         return true;
167     }
168     // HALF_FLOAT_OES
169     else
170     {
171         return SizedHalfFloatOESRGSupport(clientVersion, extensions);
172     }
173 }
174 
SizedHalfFloatRGTextureAttachmentSupport(const Version & clientVersion,const Extensions & extensions)175 static bool SizedHalfFloatRGTextureAttachmentSupport(const Version &clientVersion,
176                                                      const Extensions &extensions)
177 {
178     // HALF_FLOAT
179     if (clientVersion >= Version(3, 0))
180     {
181         // WebGL 2 supports EXT_color_buffer_half_float.
182         return extensions.colorBufferFloat ||
183                (extensions.webglCompatibility && extensions.colorBufferHalfFloat);
184     }
185     // HALF_FLOAT_OES
186     else
187     {
188         return SizedHalfFloatOESRGTextureAttachmentSupport(clientVersion, extensions);
189     }
190 }
191 
SizedHalfFloatRGRenderbufferSupport(const Version & clientVersion,const Extensions & extensions)192 static bool SizedHalfFloatRGRenderbufferSupport(const Version &clientVersion,
193                                                 const Extensions &extensions)
194 {
195     return (clientVersion >= Version(3, 0) ||
196             (extensions.textureHalfFloat && extensions.textureRG)) &&
197            (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
198 }
199 
200 // RGB16F, RGBA16F with HALF_FLOAT_OES type
SizedHalfFloatOESSupport(const Version & clientVersion,const Extensions & extensions)201 static bool SizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
202 {
203     return extensions.textureStorage && extensions.textureHalfFloat;
204 }
205 
SizedHalfFloatOESTextureAttachmentSupport(const Version & clientVersion,const Extensions & extensions)206 static bool SizedHalfFloatOESTextureAttachmentSupport(const Version &clientVersion,
207                                                       const Extensions &extensions)
208 {
209     return SizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
210 }
211 
212 // RGB16F, RGBA16F with either HALF_FLOAT_OES or HALF_FLOAT types
SizedHalfFloatSupport(const Version & clientVersion,const Extensions & extensions)213 static bool SizedHalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
214 {
215     // HALF_FLOAT
216     if (clientVersion >= Version(3, 0))
217     {
218         return true;
219     }
220     // HALF_FLOAT_OES
221     else
222     {
223         return SizedHalfFloatOESSupport(clientVersion, extensions);
224     }
225 }
226 
SizedHalfFloatFilterSupport(const Version & clientVersion,const Extensions & extensions)227 static bool SizedHalfFloatFilterSupport(const Version &clientVersion, const Extensions &extensions)
228 {
229     // HALF_FLOAT
230     if (clientVersion >= Version(3, 0))
231     {
232         return true;
233     }
234     // HALF_FLOAT_OES
235     else
236     {
237         return extensions.textureHalfFloatLinear;
238     }
239 }
240 
SizedHalfFloatRGBTextureAttachmentSupport(const Version & clientVersion,const Extensions & extensions)241 static bool SizedHalfFloatRGBTextureAttachmentSupport(const Version &clientVersion,
242                                                       const Extensions &extensions)
243 {
244     // HALF_FLOAT
245     if (clientVersion >= Version(3, 0))
246     {
247         // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
248         // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
249         // is possible, so assume that all GLES implementations support it.
250         // The WebGL version of the extension explicitly forbids RGB formats.
251         return extensions.colorBufferHalfFloat && !extensions.webglCompatibility;
252     }
253     // HALF_FLOAT_OES
254     else
255     {
256         return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
257     }
258 }
259 
SizedHalfFloatRGBRenderbufferSupport(const Version & clientVersion,const Extensions & extensions)260 static bool SizedHalfFloatRGBRenderbufferSupport(const Version &clientVersion,
261                                                  const Extensions &extensions)
262 {
263     return !extensions.webglCompatibility &&
264            ((clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
265             extensions.colorBufferHalfFloat);
266 }
267 
SizedHalfFloatRGBATextureAttachmentSupport(const Version & clientVersion,const Extensions & extensions)268 static bool SizedHalfFloatRGBATextureAttachmentSupport(const Version &clientVersion,
269                                                        const Extensions &extensions)
270 {
271     // HALF_FLOAT
272     if (clientVersion >= Version(3, 0))
273     {
274         // WebGL 2 supports EXT_color_buffer_half_float.
275         return extensions.colorBufferFloat ||
276                (extensions.webglCompatibility && extensions.colorBufferHalfFloat);
277     }
278     // HALF_FLOAT_OES
279     else
280     {
281         return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
282     }
283 }
284 
SizedHalfFloatRGBARenderbufferSupport(const Version & clientVersion,const Extensions & extensions)285 static bool SizedHalfFloatRGBARenderbufferSupport(const Version &clientVersion,
286                                                   const Extensions &extensions)
287 {
288     return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
289            (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
290 }
291 
292 // R32F, RG32F
SizedFloatRGSupport(const Version & clientVersion,const Extensions & extensions)293 static bool SizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
294 {
295     return clientVersion >= Version(3, 0) ||
296            (extensions.textureStorage && extensions.textureFloatOES && extensions.textureRG);
297 }
298 
299 // RGB32F
SizedFloatRGBSupport(const Version & clientVersion,const Extensions & extensions)300 static bool SizedFloatRGBSupport(const Version &clientVersion, const Extensions &extensions)
301 {
302     return clientVersion >= Version(3, 0) ||
303            (extensions.textureStorage && extensions.textureFloatOES) ||
304            extensions.colorBufferFloatRGB;
305 }
306 
307 // RGBA32F
SizedFloatRGBASupport(const Version & clientVersion,const Extensions & extensions)308 static bool SizedFloatRGBASupport(const Version &clientVersion, const Extensions &extensions)
309 {
310     return clientVersion >= Version(3, 0) ||
311            (extensions.textureStorage && extensions.textureFloatOES) ||
312            extensions.colorBufferFloatRGBA;
313 }
314 
SizedFloatRGBARenderableSupport(const Version & clientVersion,const Extensions & extensions)315 static bool SizedFloatRGBARenderableSupport(const Version &clientVersion,
316                                             const Extensions &extensions)
317 {
318     // This logic is the same for both Renderbuffers and TextureAttachment.
319     return extensions.colorBufferFloatRGBA ||  // ES2
320            extensions.colorBufferFloat;        // ES3
321 }
322 
Float32BlendableSupport(const Version & clientVersion,const Extensions & extensions)323 static bool Float32BlendableSupport(const Version &clientVersion, const Extensions &extensions)
324 {
325     // EXT_float_blend may be exposed on ES2 client contexts. Ensure that RGBA32F is renderable.
326     return (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat) &&
327            extensions.floatBlend;
328 }
329 
InternalFormat()330 InternalFormat::InternalFormat()
331     : internalFormat(GL_NONE),
332       sized(false),
333       sizedInternalFormat(GL_NONE),
334       redBits(0),
335       greenBits(0),
336       blueBits(0),
337       luminanceBits(0),
338       alphaBits(0),
339       sharedBits(0),
340       depthBits(0),
341       stencilBits(0),
342       pixelBytes(0),
343       componentCount(0),
344       compressed(false),
345       compressedBlockWidth(0),
346       compressedBlockHeight(0),
347       compressedBlockDepth(0),
348       format(GL_NONE),
349       type(GL_NONE),
350       componentType(GL_NONE),
351       colorEncoding(GL_NONE),
352       textureSupport(NeverSupported),
353       filterSupport(NeverSupported),
354       textureAttachmentSupport(NeverSupported),
355       renderbufferSupport(NeverSupported),
356       blendSupport(NeverSupported)
357 {}
358 
359 InternalFormat::InternalFormat(const InternalFormat &other) = default;
360 
361 InternalFormat &InternalFormat::operator=(const InternalFormat &other) = default;
362 
isLUMA() const363 bool InternalFormat::isLUMA() const
364 {
365     return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
366             (luminanceBits + alphaBits) > 0);
367 }
368 
getReadPixelsFormat(const Extensions & extensions) const369 GLenum InternalFormat::getReadPixelsFormat(const Extensions &extensions) const
370 {
371     switch (format)
372     {
373         case GL_BGRA_EXT:
374             // BGRA textures may be enabled but calling glReadPixels with BGRA is disallowed without
375             // GL_EXT_texture_format_BGRA8888.  Read as RGBA instead.
376             if (!extensions.readFormatBGRA)
377             {
378                 return GL_RGBA;
379             }
380             return GL_BGRA_EXT;
381 
382         default:
383             return format;
384     }
385 }
386 
getReadPixelsType(const Version & version) const387 GLenum InternalFormat::getReadPixelsType(const Version &version) const
388 {
389     switch (type)
390     {
391         case GL_HALF_FLOAT:
392         case GL_HALF_FLOAT_OES:
393             if (version < Version(3, 0))
394             {
395                 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
396                 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
397                 // OES_texture_half_float.  HALF_FLOAT becomes core in ES3 and is acceptable to use
398                 // as an IMPLEMENTATION_READ_TYPE.
399                 return GL_HALF_FLOAT_OES;
400             }
401             return GL_HALF_FLOAT;
402 
403         default:
404             return type;
405     }
406 }
407 
supportSubImage() const408 bool InternalFormat::supportSubImage() const
409 {
410     return !CompressedFormatRequiresWholeImage(internalFormat);
411 }
412 
isRequiredRenderbufferFormat(const Version & version) const413 bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
414 {
415     // GLES 3.0.5 section 4.4.2.2:
416     // "Implementations are required to support the same internal formats for renderbuffers as the
417     // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
418     // formats labelled "texture-only"."
419     if (!sized || compressed)
420     {
421         return false;
422     }
423 
424     // Luma formats.
425     if (isLUMA())
426     {
427         return false;
428     }
429 
430     // Depth/stencil formats.
431     if (depthBits > 0 || stencilBits > 0)
432     {
433         // GLES 2.0.25 table 4.5.
434         // GLES 3.0.5 section 3.8.3.1.
435         // GLES 3.1 table 8.14.
436 
437         // Required formats in all versions.
438         switch (internalFormat)
439         {
440             case GL_DEPTH_COMPONENT16:
441             case GL_STENCIL_INDEX8:
442                 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
443                 // is in section 4.4.2.2.
444                 return true;
445             default:
446                 break;
447         }
448         if (version.major < 3)
449         {
450             return false;
451         }
452         // Required formats in GLES 3.0 and up.
453         switch (internalFormat)
454         {
455             case GL_DEPTH_COMPONENT32F:
456             case GL_DEPTH_COMPONENT24:
457             case GL_DEPTH32F_STENCIL8:
458             case GL_DEPTH24_STENCIL8:
459                 return true;
460             default:
461                 return false;
462         }
463     }
464 
465     // RGBA formats.
466     // GLES 2.0.25 table 4.5.
467     // GLES 3.0.5 section 3.8.3.1.
468     // GLES 3.1 table 8.13.
469 
470     // Required formats in all versions.
471     switch (internalFormat)
472     {
473         case GL_RGBA4:
474         case GL_RGB5_A1:
475         case GL_RGB565:
476             return true;
477         default:
478             break;
479     }
480     if (version.major < 3)
481     {
482         return false;
483     }
484 
485     if (format == GL_BGRA_EXT)
486     {
487         return false;
488     }
489 
490     switch (componentType)
491     {
492         case GL_SIGNED_NORMALIZED:
493         case GL_FLOAT:
494             return false;
495         case GL_UNSIGNED_INT:
496         case GL_INT:
497             // Integer RGB formats are not required renderbuffer formats.
498             if (alphaBits == 0 && blueBits != 0)
499             {
500                 return false;
501             }
502             // All integer R and RG formats are required.
503             // Integer RGBA formats including RGB10_A2_UI are required.
504             return true;
505         case GL_UNSIGNED_NORMALIZED:
506             if (internalFormat == GL_SRGB8)
507             {
508                 return false;
509             }
510             return true;
511         default:
512             UNREACHABLE();
513 #if !UNREACHABLE_IS_NORETURN
514             return false;
515 #endif
516     }
517 }
518 
isInt() const519 bool InternalFormat::isInt() const
520 {
521     return componentType == GL_INT || componentType == GL_UNSIGNED_INT;
522 }
523 
isDepthOrStencil() const524 bool InternalFormat::isDepthOrStencil() const
525 {
526     return depthBits != 0 || stencilBits != 0;
527 }
528 
Format(GLenum internalFormat)529 Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat)) {}
530 
Format(const InternalFormat & internalFormat)531 Format::Format(const InternalFormat &internalFormat) : info(&internalFormat) {}
532 
Format(GLenum internalFormat,GLenum type)533 Format::Format(GLenum internalFormat, GLenum type)
534     : info(&GetInternalFormatInfo(internalFormat, type))
535 {}
536 
537 Format::Format(const Format &other) = default;
538 Format &Format::operator=(const Format &other) = default;
539 
valid() const540 bool Format::valid() const
541 {
542     return info->internalFormat != GL_NONE;
543 }
544 
545 // static
SameSized(const Format & a,const Format & b)546 bool Format::SameSized(const Format &a, const Format &b)
547 {
548     return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
549 }
550 
EquivalentBlitInternalFormat(GLenum internalformat)551 static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
552 {
553     // BlitFramebuffer works if the color channels are identically
554     // sized, even if there is a swizzle (for example, blitting from a
555     // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
556     // be expanded and/or autogenerated if that is found necessary.
557     if (internalformat == GL_BGRA8_EXT)
558         return GL_RGBA8;
559     return internalformat;
560 }
561 
562 // static
EquivalentForBlit(const Format & a,const Format & b)563 bool Format::EquivalentForBlit(const Format &a, const Format &b)
564 {
565     return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
566             EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
567 }
568 
569 // static
Invalid()570 Format Format::Invalid()
571 {
572     static Format invalid(GL_NONE, GL_NONE);
573     return invalid;
574 }
575 
operator <<(std::ostream & os,const Format & fmt)576 std::ostream &operator<<(std::ostream &os, const Format &fmt)
577 {
578     // TODO(ynovikov): return string representation when available
579     return FmtHex(os, fmt.info->sizedInternalFormat);
580 }
581 
operator ==(const InternalFormat & other) const582 bool InternalFormat::operator==(const InternalFormat &other) const
583 {
584     // We assume all internal formats are unique if they have the same internal format and type
585     return internalFormat == other.internalFormat && type == other.type;
586 }
587 
operator !=(const InternalFormat & other) const588 bool InternalFormat::operator!=(const InternalFormat &other) const
589 {
590     return !(*this == other);
591 }
592 
InsertFormatInfo(InternalFormatInfoMap * map,const InternalFormat & formatInfo)593 void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
594 {
595     ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
596     ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
597     (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
598 }
599 
AddRGBAFormat(InternalFormatInfoMap * map,GLenum internalFormat,bool sized,GLuint red,GLuint green,GLuint blue,GLuint alpha,GLuint shared,GLenum format,GLenum type,GLenum componentType,bool srgb,InternalFormat::SupportCheckFunction textureSupport,InternalFormat::SupportCheckFunction filterSupport,InternalFormat::SupportCheckFunction textureAttachmentSupport,InternalFormat::SupportCheckFunction renderbufferSupport,InternalFormat::SupportCheckFunction blendSupport)600 void AddRGBAFormat(InternalFormatInfoMap *map,
601                    GLenum internalFormat,
602                    bool sized,
603                    GLuint red,
604                    GLuint green,
605                    GLuint blue,
606                    GLuint alpha,
607                    GLuint shared,
608                    GLenum format,
609                    GLenum type,
610                    GLenum componentType,
611                    bool srgb,
612                    InternalFormat::SupportCheckFunction textureSupport,
613                    InternalFormat::SupportCheckFunction filterSupport,
614                    InternalFormat::SupportCheckFunction textureAttachmentSupport,
615                    InternalFormat::SupportCheckFunction renderbufferSupport,
616                    InternalFormat::SupportCheckFunction blendSupport)
617 {
618     InternalFormat formatInfo;
619     formatInfo.internalFormat = internalFormat;
620     formatInfo.sized          = sized;
621     formatInfo.sizedInternalFormat =
622         sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
623     formatInfo.redBits    = red;
624     formatInfo.greenBits  = green;
625     formatInfo.blueBits   = blue;
626     formatInfo.alphaBits  = alpha;
627     formatInfo.sharedBits = shared;
628     formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
629     formatInfo.componentCount =
630         ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
631     formatInfo.format                   = format;
632     formatInfo.type                     = type;
633     formatInfo.componentType            = componentType;
634     formatInfo.colorEncoding            = (srgb ? GL_SRGB : GL_LINEAR);
635     formatInfo.textureSupport           = textureSupport;
636     formatInfo.filterSupport            = filterSupport;
637     formatInfo.textureAttachmentSupport = textureAttachmentSupport;
638     formatInfo.renderbufferSupport      = renderbufferSupport;
639     formatInfo.blendSupport             = blendSupport;
640 
641     InsertFormatInfo(map, formatInfo);
642 }
643 
AddLUMAFormat(InternalFormatInfoMap * map,GLenum internalFormat,bool sized,GLuint luminance,GLuint alpha,GLenum format,GLenum type,GLenum componentType,InternalFormat::SupportCheckFunction textureSupport,InternalFormat::SupportCheckFunction filterSupport,InternalFormat::SupportCheckFunction textureAttachmentSupport,InternalFormat::SupportCheckFunction renderbufferSupport,InternalFormat::SupportCheckFunction blendSupport)644 static void AddLUMAFormat(InternalFormatInfoMap *map,
645                           GLenum internalFormat,
646                           bool sized,
647                           GLuint luminance,
648                           GLuint alpha,
649                           GLenum format,
650                           GLenum type,
651                           GLenum componentType,
652                           InternalFormat::SupportCheckFunction textureSupport,
653                           InternalFormat::SupportCheckFunction filterSupport,
654                           InternalFormat::SupportCheckFunction textureAttachmentSupport,
655                           InternalFormat::SupportCheckFunction renderbufferSupport,
656                           InternalFormat::SupportCheckFunction blendSupport)
657 {
658     InternalFormat formatInfo;
659     formatInfo.internalFormat = internalFormat;
660     formatInfo.sized          = sized;
661     formatInfo.sizedInternalFormat =
662         sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
663     formatInfo.luminanceBits            = luminance;
664     formatInfo.alphaBits                = alpha;
665     formatInfo.pixelBytes               = (luminance + alpha) / 8;
666     formatInfo.componentCount           = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
667     formatInfo.format                   = format;
668     formatInfo.type                     = type;
669     formatInfo.componentType            = componentType;
670     formatInfo.colorEncoding            = GL_LINEAR;
671     formatInfo.textureSupport           = textureSupport;
672     formatInfo.filterSupport            = filterSupport;
673     formatInfo.textureAttachmentSupport = textureAttachmentSupport;
674     formatInfo.renderbufferSupport      = renderbufferSupport;
675     formatInfo.blendSupport             = blendSupport;
676 
677     InsertFormatInfo(map, formatInfo);
678 }
679 
AddDepthStencilFormat(InternalFormatInfoMap * map,GLenum internalFormat,bool sized,GLuint depthBits,GLuint stencilBits,GLuint unusedBits,GLenum format,GLenum type,GLenum componentType,InternalFormat::SupportCheckFunction textureSupport,InternalFormat::SupportCheckFunction filterSupport,InternalFormat::SupportCheckFunction textureAttachmentSupport,InternalFormat::SupportCheckFunction renderbufferSupport,InternalFormat::SupportCheckFunction blendSupport)680 void AddDepthStencilFormat(InternalFormatInfoMap *map,
681                            GLenum internalFormat,
682                            bool sized,
683                            GLuint depthBits,
684                            GLuint stencilBits,
685                            GLuint unusedBits,
686                            GLenum format,
687                            GLenum type,
688                            GLenum componentType,
689                            InternalFormat::SupportCheckFunction textureSupport,
690                            InternalFormat::SupportCheckFunction filterSupport,
691                            InternalFormat::SupportCheckFunction textureAttachmentSupport,
692                            InternalFormat::SupportCheckFunction renderbufferSupport,
693                            InternalFormat::SupportCheckFunction blendSupport)
694 {
695     InternalFormat formatInfo;
696     formatInfo.internalFormat = internalFormat;
697     formatInfo.sized          = sized;
698     formatInfo.sizedInternalFormat =
699         sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
700     formatInfo.depthBits                = depthBits;
701     formatInfo.stencilBits              = stencilBits;
702     formatInfo.pixelBytes               = (depthBits + stencilBits + unusedBits) / 8;
703     formatInfo.componentCount           = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
704     formatInfo.format                   = format;
705     formatInfo.type                     = type;
706     formatInfo.componentType            = componentType;
707     formatInfo.colorEncoding            = GL_LINEAR;
708     formatInfo.textureSupport           = textureSupport;
709     formatInfo.filterSupport            = filterSupport;
710     formatInfo.textureAttachmentSupport = textureAttachmentSupport;
711     formatInfo.renderbufferSupport      = renderbufferSupport;
712     formatInfo.blendSupport             = blendSupport;
713 
714     InsertFormatInfo(map, formatInfo);
715 }
716 
AddCompressedFormat(InternalFormatInfoMap * map,GLenum internalFormat,GLuint compressedBlockWidth,GLuint compressedBlockHeight,GLuint compressedBlockDepth,GLuint compressedBlockSize,GLuint componentCount,bool srgb,InternalFormat::SupportCheckFunction textureSupport,InternalFormat::SupportCheckFunction filterSupport,InternalFormat::SupportCheckFunction textureAttachmentSupport,InternalFormat::SupportCheckFunction renderbufferSupport,InternalFormat::SupportCheckFunction blendSupport)717 void AddCompressedFormat(InternalFormatInfoMap *map,
718                          GLenum internalFormat,
719                          GLuint compressedBlockWidth,
720                          GLuint compressedBlockHeight,
721                          GLuint compressedBlockDepth,
722                          GLuint compressedBlockSize,
723                          GLuint componentCount,
724                          bool srgb,
725                          InternalFormat::SupportCheckFunction textureSupport,
726                          InternalFormat::SupportCheckFunction filterSupport,
727                          InternalFormat::SupportCheckFunction textureAttachmentSupport,
728                          InternalFormat::SupportCheckFunction renderbufferSupport,
729                          InternalFormat::SupportCheckFunction blendSupport)
730 {
731     InternalFormat formatInfo;
732     formatInfo.internalFormat           = internalFormat;
733     formatInfo.sized                    = true;
734     formatInfo.sizedInternalFormat      = internalFormat;
735     formatInfo.compressedBlockWidth     = compressedBlockWidth;
736     formatInfo.compressedBlockHeight    = compressedBlockHeight;
737     formatInfo.compressedBlockDepth     = compressedBlockDepth;
738     formatInfo.pixelBytes               = compressedBlockSize / 8;
739     formatInfo.componentCount           = componentCount;
740     formatInfo.format                   = internalFormat;
741     formatInfo.type                     = GL_UNSIGNED_BYTE;
742     formatInfo.componentType            = GL_UNSIGNED_NORMALIZED;
743     formatInfo.colorEncoding            = (srgb ? GL_SRGB : GL_LINEAR);
744     formatInfo.compressed               = true;
745     formatInfo.textureSupport           = textureSupport;
746     formatInfo.filterSupport            = filterSupport;
747     formatInfo.textureAttachmentSupport = textureAttachmentSupport;
748     formatInfo.renderbufferSupport      = renderbufferSupport;
749     formatInfo.blendSupport             = blendSupport;
750 
751     InsertFormatInfo(map, formatInfo);
752 }
753 
754 // Notes:
755 // 1. "Texture supported" includes all the means by which texture can be created, however,
756 //    GL_EXT_texture_storage in ES2 is a special case, when only glTexStorage* is allowed.
757 //    The assumption is that ES2 validation will not check textureSupport for sized formats.
758 //
759 // 2. Sized half float types are a combination of GL_HALF_FLOAT and GL_HALF_FLOAT_OES support,
760 //    due to a limitation that only one type for sized formats is allowed.
761 //
762 // TODO(ynovikov): http://anglebug.com/2846 Verify support fields of BGRA, depth, stencil
763 // and compressed formats. Perform texturable check as part of filterable and attachment checks.
BuildInternalFormatInfoMap()764 static InternalFormatInfoMap BuildInternalFormatInfoMap()
765 {
766     InternalFormatInfoMap map;
767 
768     // From ES 3.0.1 spec, table 3.12
769     map[GL_NONE][GL_NONE] = InternalFormat();
770 
771     // clang-format off
772 
773     //                 | Internal format     |sized| R | G | B | A |S | Format         | Type                             | Component type        | SRGB | Texture supported                                | Filterable     | Texture attachment                               | Renderbuffer                                   | Blend
774     AddRGBAFormat(&map, GL_R8,                true,  8,  0,  0,  0, 0, GL_RED,          GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, SizedRGSupport,                                    AlwaysSupported, SizedRGSupport,                                    RequireESOrExt<3, 0, &Extensions::textureRG>,    RequireESOrExt<3, 0, &Extensions::textureRG>);
775     AddRGBAFormat(&map, GL_R8_SNORM,          true,  8,  0,  0,  0, 0, GL_RED,          GL_BYTE,                           GL_SIGNED_NORMALIZED,   false, RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
776     AddRGBAFormat(&map, GL_RG8,               true,  8,  8,  0,  0, 0, GL_RG,           GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, SizedRGSupport,                                    AlwaysSupported, SizedRGSupport,                                    RequireESOrExt<3, 0, &Extensions::textureRG>,    RequireESOrExt<3, 0, &Extensions::textureRG>);
777     AddRGBAFormat(&map, GL_RG8_SNORM,         true,  8,  8,  0,  0, 0, GL_RG,           GL_BYTE,                           GL_SIGNED_NORMALIZED,   false, RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
778     AddRGBAFormat(&map, GL_RGB8,              true,  8,  8,  8,  0, 0, GL_RGB,          GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8OES>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8OES>);
779     AddRGBAFormat(&map, GL_RGB8_SNORM,        true,  8,  8,  8,  0, 0, GL_RGB,          GL_BYTE,                           GL_SIGNED_NORMALIZED,   false, RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
780     AddRGBAFormat(&map, GL_RGB565,            true,  5,  6,  5,  0, 0, GL_RGB,          GL_UNSIGNED_SHORT_5_6_5,           GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0>,                                 RequireES<2, 0>);
781     AddRGBAFormat(&map, GL_RGBA4,             true,  4,  4,  4,  4, 0, GL_RGBA,         GL_UNSIGNED_SHORT_4_4_4_4,         GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0>,                                 RequireES<2, 0>);
782     AddRGBAFormat(&map, GL_RGB5_A1,           true,  5,  5,  5,  1, 0, GL_RGBA,         GL_UNSIGNED_SHORT_5_5_5_1,         GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0>,                                 RequireES<2, 0>);
783     AddRGBAFormat(&map, GL_RGBA8,             true,  8,  8,  8,  8, 0, GL_RGBA,         GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8OES>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8OES>);
784     AddRGBAFormat(&map, GL_RGBA8_SNORM,       true,  8,  8,  8,  8, 0, GL_RGBA,         GL_BYTE,                           GL_SIGNED_NORMALIZED,   false, RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
785     AddRGBAFormat(&map, GL_RGB10_A2,          true, 10, 10, 10,  2, 0, GL_RGBA,         GL_UNSIGNED_INT_2_10_10_10_REV,    GL_UNSIGNED_NORMALIZED, false, RequireES<3, 0>,                                   AlwaysSupported, RequireES<3, 0>,                                   RequireES<3, 0>,                                 RequireES<3, 0>);
786     AddRGBAFormat(&map, GL_RGB10_A2UI,        true, 10, 10, 10,  2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV,    GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
787     AddRGBAFormat(&map, GL_SRGB8,             true,  8,  8,  8,  0, 0, GL_RGB,          GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, true,  RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
788     AddRGBAFormat(&map, GL_SRGB8_ALPHA8,      true,  8,  8,  8,  8, 0, GL_RGBA,         GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, true,  RequireESOrExt<3, 0, &Extensions::sRGB>,           AlwaysSupported, RequireES<3, 0>,                                   RequireESOrExt<3, 0, &Extensions::sRGB>,         RequireESOrExt<3, 0, &Extensions::sRGB>);
789     AddRGBAFormat(&map, GL_R11F_G11F_B10F,    true, 11, 11, 10,  0, 0, GL_RGB,          GL_UNSIGNED_INT_10F_11F_11F_REV,   GL_FLOAT,               false, RequireES<3, 0>,                                   AlwaysSupported, RequireExt<&Extensions::colorBufferFloat>,         RequireExt<&Extensions::colorBufferFloat>,       RequireExt<&Extensions::colorBufferFloat>);
790     AddRGBAFormat(&map, GL_RGB9_E5,           true,  9,  9,  9,  0, 5, GL_RGB,          GL_UNSIGNED_INT_5_9_9_9_REV,       GL_FLOAT,               false, RequireES<3, 0>,                                   AlwaysSupported, NeverSupported,                                    NeverSupported,                                  NeverSupported);
791     AddRGBAFormat(&map, GL_R8I,               true,  8,  0,  0,  0, 0, GL_RED_INTEGER,  GL_BYTE,                           GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
792     AddRGBAFormat(&map, GL_R8UI,              true,  8,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_BYTE,                  GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
793     AddRGBAFormat(&map, GL_R16I,              true, 16,  0,  0,  0, 0, GL_RED_INTEGER,  GL_SHORT,                          GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
794     AddRGBAFormat(&map, GL_R16UI,             true, 16,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_SHORT,                 GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
795     AddRGBAFormat(&map, GL_R32I,              true, 32,  0,  0,  0, 0, GL_RED_INTEGER,  GL_INT,                            GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
796     AddRGBAFormat(&map, GL_R32UI,             true, 32,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_INT,                   GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
797     AddRGBAFormat(&map, GL_RG8I,              true,  8,  8,  0,  0, 0, GL_RG_INTEGER,   GL_BYTE,                           GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
798     AddRGBAFormat(&map, GL_RG8UI,             true,  8,  8,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_BYTE,                  GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
799     AddRGBAFormat(&map, GL_RG16I,             true, 16, 16,  0,  0, 0, GL_RG_INTEGER,   GL_SHORT,                          GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
800     AddRGBAFormat(&map, GL_RG16UI,            true, 16, 16,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_SHORT,                 GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
801     AddRGBAFormat(&map, GL_RG32I,             true, 32, 32,  0,  0, 0, GL_RG_INTEGER,   GL_INT,                            GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
802     AddRGBAFormat(&map, GL_RG32UI,            true, 32, 32,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_INT,                   GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
803     AddRGBAFormat(&map, GL_RGB8I,             true,  8,  8,  8,  0, 0, GL_RGB_INTEGER,  GL_BYTE,                           GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
804     AddRGBAFormat(&map, GL_RGB8UI,            true,  8,  8,  8,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_BYTE,                  GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
805     AddRGBAFormat(&map, GL_RGB16I,            true, 16, 16, 16,  0, 0, GL_RGB_INTEGER,  GL_SHORT,                          GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
806     AddRGBAFormat(&map, GL_RGB16UI,           true, 16, 16, 16,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_SHORT,                 GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
807     AddRGBAFormat(&map, GL_RGB32I,            true, 32, 32, 32,  0, 0, GL_RGB_INTEGER,  GL_INT,                            GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
808     AddRGBAFormat(&map, GL_RGB32UI,           true, 32, 32, 32,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_INT,                   GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  NeverSupported,                                    NeverSupported,                                  NeverSupported);
809     AddRGBAFormat(&map, GL_RGBA8I,            true,  8,  8,  8,  8, 0, GL_RGBA_INTEGER, GL_BYTE,                           GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
810     AddRGBAFormat(&map, GL_RGBA8UI,           true,  8,  8,  8,  8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,                  GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
811     AddRGBAFormat(&map, GL_RGBA16I,           true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT,                          GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
812     AddRGBAFormat(&map, GL_RGBA16UI,          true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT,                 GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
813     AddRGBAFormat(&map, GL_RGBA32I,           true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT,                            GL_INT,                 false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
814     AddRGBAFormat(&map, GL_RGBA32UI,          true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT,                   GL_UNSIGNED_INT,        false, RequireES<3, 0>,                                   NeverSupported,  RequireES<3, 0>,                                   RequireES<3, 0>,                                 NeverSupported);
815 
816     AddRGBAFormat(&map, GL_BGRA8_EXT,         true,  8,  8,  8,  8, 0, GL_BGRA_EXT,     GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>,    AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>,    RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
817     AddRGBAFormat(&map, GL_BGRA4_ANGLEX,      true,  4,  4,  4,  4, 0, GL_BGRA_EXT,     GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>,    AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>,    RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
818     AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX,    true,  5,  5,  5,  1, 0, GL_BGRA_EXT,     GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>,    AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>,    RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
819 
820     // Special format that is used for D3D textures that are used within ANGLE via the
821     // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
822     // this format, but textures in this format can be created from D3D textures, and filtering them
823     // and rendering to them is allowed.
824     AddRGBAFormat(&map, GL_BGRA8_SRGB_ANGLEX, true,  8,  8,  8,  8, 0, GL_BGRA_EXT,     GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, true,  NeverSupported,                                    AlwaysSupported, AlwaysSupported,                                   AlwaysSupported,                               AlwaysSupported);
825 
826     // Special format which is not really supported, so always false for all supports.
827     AddRGBAFormat(&map, GL_BGRX8_ANGLEX,      true,  8,  8,  8,  0, 0, GL_BGRA_EXT,     GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, NeverSupported,                                    NeverSupported,  NeverSupported,                                    NeverSupported,                                NeverSupported);
828     AddRGBAFormat(&map, GL_BGR565_ANGLEX,     true,  5,  6,  5,  1, 0, GL_BGRA_EXT,     GL_UNSIGNED_SHORT_5_6_5,           GL_UNSIGNED_NORMALIZED, false, NeverSupported,                                    NeverSupported,  NeverSupported,                                    NeverSupported,                                NeverSupported);
829     AddRGBAFormat(&map, GL_BGR10_A2_ANGLEX,   true, 10, 10, 10,  2, 0, GL_BGRA_EXT,     GL_UNSIGNED_INT_2_10_10_10_REV,    GL_UNSIGNED_NORMALIZED, false, NeverSupported,                                    NeverSupported,  NeverSupported,                                    NeverSupported,                                NeverSupported);
830 
831     // Floating point formats
832     //                 | Internal format |sized| R | G | B | A |S | Format | Type             | Component type | SRGB | Texture supported         | Filterable                                    | Texture attachment                          | Renderbuffer                            | Blend
833     // It's not possible to have two entries per sized format.
834     // E.g. for GL_RG16F, one with GL_HALF_FLOAT type and the other with GL_HALF_FLOAT_OES type.
835     // So, GL_HALF_FLOAT type formats conditions are merged with GL_HALF_FLOAT_OES type conditions.
836     AddRGBAFormat(&map, GL_R16F,          true, 16,  0,  0,  0, 0, GL_RED,  GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatRGSupport,    SizedHalfFloatFilterSupport,                    SizedHalfFloatRGTextureAttachmentSupport,     SizedHalfFloatRGRenderbufferSupport,       SizedHalfFloatRGRenderbufferSupport);
837     AddRGBAFormat(&map, GL_RG16F,         true, 16, 16,  0,  0, 0, GL_RG,   GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatRGSupport,    SizedHalfFloatFilterSupport,                    SizedHalfFloatRGTextureAttachmentSupport,     SizedHalfFloatRGRenderbufferSupport,       SizedHalfFloatRGRenderbufferSupport);
838     AddRGBAFormat(&map, GL_RGB16F,        true, 16, 16, 16,  0, 0, GL_RGB,  GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatSupport,      SizedHalfFloatFilterSupport,                    SizedHalfFloatRGBTextureAttachmentSupport,    SizedHalfFloatRGBRenderbufferSupport,      SizedHalfFloatRGBRenderbufferSupport);
839     AddRGBAFormat(&map, GL_RGBA16F,       true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatSupport,      SizedHalfFloatFilterSupport,                    SizedHalfFloatRGBATextureAttachmentSupport,   SizedHalfFloatRGBARenderbufferSupport,     SizedHalfFloatRGBARenderbufferSupport);
840     AddRGBAFormat(&map, GL_R32F,          true, 32,  0,  0,  0, 0, GL_RED,  GL_FLOAT,          GL_FLOAT,        false, SizedFloatRGSupport,        RequireExt<&Extensions::textureFloatLinearOES>, RequireExt<&Extensions::colorBufferFloat>,    RequireExt<&Extensions::colorBufferFloat>, Float32BlendableSupport);
841     AddRGBAFormat(&map, GL_RG32F,         true, 32, 32,  0,  0, 0, GL_RG,   GL_FLOAT,          GL_FLOAT,        false, SizedFloatRGSupport,        RequireExt<&Extensions::textureFloatLinearOES>, RequireExt<&Extensions::colorBufferFloat>,    RequireExt<&Extensions::colorBufferFloat>, Float32BlendableSupport);
842     AddRGBAFormat(&map, GL_RGB32F,        true, 32, 32, 32,  0, 0, GL_RGB,  GL_FLOAT,          GL_FLOAT,        false, SizedFloatRGBSupport,       RequireExt<&Extensions::textureFloatLinearOES>, RequireExt<&Extensions::colorBufferFloatRGB>, NeverSupported,                            NeverSupported);
843     AddRGBAFormat(&map, GL_RGBA32F,       true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT,          GL_FLOAT,        false, SizedFloatRGBASupport,      RequireExt<&Extensions::textureFloatLinearOES>, SizedFloatRGBARenderableSupport,              SizedFloatRGBARenderableSupport,           Float32BlendableSupport);
844 
845     // ANGLE Depth stencil formats
846     //                         | Internal format         |sized| D |S | X | Format            | Type                             | Component type        | Texture supported                                                            | Filterable                                                                             | Texture attachment                                                                           | Renderbuffer                                                                                              | Blend
847     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16,     true, 16, 0,  0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,                 GL_UNSIGNED_NORMALIZED, RequireES<1, 0>,                                                               RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::depthTextureOES>, RequireES<1, 0>,                                                                               RequireES<1, 0>,                                                                                             RequireES<1, 0>);
848     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24,     true, 24, 0,  8, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,                   GL_UNSIGNED_NORMALIZED, RequireES<3, 0>,                                                               RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>,                                    RequireES<3, 0>,                                                                               RequireESOrExt<3, 0, &Extensions::depth24OES>,                                                               RequireESOrExt<3, 0, &Extensions::depth24OES>);
849     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F,    true, 32, 0,  0, GL_DEPTH_COMPONENT, GL_FLOAT,                          GL_FLOAT,               RequireES<3, 0>,                                                               RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>,                                    RequireES<3, 0>,                                                                               RequireES<3, 0>,                                                                                             RequireES<3, 0>);
850     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0,  0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,                   GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>, AlwaysSupported,                                                                         RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>,                 RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32OES>, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32OES>);
851     AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8,      true, 24, 8,  0, GL_DEPTH_STENCIL,   GL_UNSIGNED_INT_24_8,              GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>,                          AlwaysSupported,                                                                         RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencilOES>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencilOES>,               RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencilOES>);
852     AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8,     true, 32, 8, 24, GL_DEPTH_STENCIL,   GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT,               RequireESOrExt<3, 0, &Extensions::depthBufferFloat2NV>,                        AlwaysSupported,                                                                         RequireESOrExt<3, 0, &Extensions::depthBufferFloat2NV>,                                        RequireESOrExt<3, 0, &Extensions::depthBufferFloat2NV>,                                                      RequireESOrExt<3, 0, &Extensions::depthBufferFloat2NV>);
853     // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
854 
855     // Luminance alpha formats
856     //                | Internal format           |sized| L | A | Format            | Type             | Component type        | Texture supported                                                           | Filterable                                     | Texture attachment | Renderbuffer | Blend
857     AddLUMAFormat(&map, GL_ALPHA8_EXT,             true,  0,  8, GL_ALPHA,           GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>,                                      AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
858     AddLUMAFormat(&map, GL_LUMINANCE8_EXT,         true,  8,  0, GL_LUMINANCE,       GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>,                                      AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
859     AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT,  true,  8,  8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>,                                      AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
860     AddLUMAFormat(&map, GL_ALPHA16F_EXT,           true,  0, 16, GL_ALPHA,           GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
861     AddLUMAFormat(&map, GL_LUMINANCE16F_EXT,       true, 16,  0, GL_LUMINANCE,       GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
862     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
863     AddLUMAFormat(&map, GL_ALPHA32F_EXT,           true,  0, 32, GL_ALPHA,           GL_FLOAT,          GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
864     AddLUMAFormat(&map, GL_LUMINANCE32F_EXT,       true, 32,  0, GL_LUMINANCE,       GL_FLOAT,          GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
865     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT,          GL_FLOAT,               RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
866 
867     // Compressed formats, From ES 3.0.1 spec, table 3.16
868     //                       | Internal format                             |W |H |D | BS |CC| SRGB | Texture supported                                                                                                         | Filterable     | Texture attachment | Renderbuffer  | Blend
869     AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC,                        4, 4, 1,  64, 1, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11UnsignedTextureOES>,              AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
870     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC,                 4, 4, 1,  64, 1, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11SignedTextureOES>,                AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
871     AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC,                       4, 4, 1, 128, 2, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11UnsignedTextureOES>,             AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
872     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC,                4, 4, 1, 128, 2, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11SignedTextureOES>,               AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
873     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2,                      4, 4, 1,  64, 3, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGB8TextureOES>,                    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
874     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2,                     4, 4, 1,  64, 3, true,  RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8TextureOES>,                   AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
875     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,  4, 4, 1,  64, 3, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughARGB8TextureOES>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
876     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 1,  64, 3, true,  RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTextureOES>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
877     AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC,                 4, 4, 1, 128, 4, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGBA8TextureOES>,                   AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
878     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,          4, 4, 1, 128, 4, true,  RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Alpha8TextureOES>,             AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
879 
880     // From GL_EXT_texture_compression_dxt1
881     //                       | Internal format                   |W |H |D | BS |CC| SRGB | Texture supported                                    | Filterable     | Texture attachment | Renderbuffer  | Blend
882     AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,    4, 4, 1,  64, 3, false, RequireExt<&Extensions::textureCompressionDXT1>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
883     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,   4, 4, 1,  64, 4, false, RequireExt<&Extensions::textureCompressionDXT1>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
884 
885     // From GL_ANGLE_texture_compression_dxt3
886     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionDXT3>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
887 
888     // From GL_ANGLE_texture_compression_dxt5
889     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionDXT5>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
890 
891     // From GL_OES_compressed_ETC1_RGB8_texture
892     AddCompressedFormat(&map, GL_ETC1_RGB8_OES,                   4, 4, 1,  64, 3, false, RequireExt<&Extensions::compressedETC1RGB8TextureOES>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
893 
894     // From GL_EXT_texture_compression_s3tc_srgb
895     //                       | Internal format                       |W |H |D | BS |CC|SRGB | Texture supported                                 | Filterable     | Texture attachment | Renderbuffer  | Blend
896     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,       4, 4, 1,  64, 3, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
897     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 1,  64, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
898     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 1, 128, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
899     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 1, 128, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
900 
901     // From GL_KHR_texture_compression_astc_ldr and KHR_texture_compression_astc_hdr and GL_OES_texture_compression_astc
902     //                       | Internal format                          | W | H |D | BS |CC| SRGB | Texture supported                                    | Filterable     | Texture attachment | Renderbuffer  | Blend
903     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR,            4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
904     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR,            5,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
905     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR,            5,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
906     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR,            6,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
907     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR,            6,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
908     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR,            8,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
909     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR,            8,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
910     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR,            8,  8, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
911     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR,          10,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
912     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR,          10,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
913     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR,          10,  8, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
914     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR,         10, 10, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
915     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR,         12, 10, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
916     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR,         12, 12, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
917 
918     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,    4,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
919     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,    5,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
920     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,    5,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
921     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,    6,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
922     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,    6,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
923     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,    8,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
924     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,    8,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
925     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,    8,  8, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
926     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,  10,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
927     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,  10,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
928     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,  10,  8, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
929     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
930     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
931     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCLDRKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
932 
933     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_3x3x3_OES,          3,  3, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
934     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x3x3_OES,          4,  3, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
935     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4x3_OES,          4,  4, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
936     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4x4_OES,          4,  4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
937     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4x4_OES,          5,  4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
938     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5x4_OES,          5,  5, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
939     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5x5_OES,          5,  5, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
940     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5x5_OES,          6,  5, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
941     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6x5_OES,          6,  6, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
942     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6x6_OES,          6,  6, 6, 128, 4, false, RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
943 
944     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES,  3,  3, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
945     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES,  4,  3, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
946     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES,  4,  4, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
947     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES,  4,  4, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
948     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES,  5,  4, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
949     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES,  5,  5, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
950     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES,  5,  5, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
951     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES,  6,  5, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
952     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES,  6,  6, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
953     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES,  6,  6, 6, 128, 4, true,  RequireExt<&Extensions::textureCompressionASTCOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
954 
955     // From EXT_texture_compression_rgtc
956     //                       | Internal format                        | W | H |D | BS |CC| SRGB | Texture supported                              | Filterable     | Texture attachment | Renderbuffer  | Blend
957     AddCompressedFormat(&map, GL_COMPRESSED_RED_RGTC1_EXT,              4,  4, 1,  64, 1, false, RequireExt<&Extensions::textureCompressionRGTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
958     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,       4,  4, 1,  64, 1, false, RequireExt<&Extensions::textureCompressionRGTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
959     AddCompressedFormat(&map, GL_COMPRESSED_RED_GREEN_RGTC2_EXT,        4,  4, 1, 128, 2, false, RequireExt<&Extensions::textureCompressionRGTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
960     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, 4,  4, 1, 128, 2, false, RequireExt<&Extensions::textureCompressionRGTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
961 
962     // From EXT_texture_compression_bptc
963     //                       | Internal format                         | W | H |D | BS |CC| SRGB | Texture supported                              | Filterable     | Texture attachment | Renderbuffer  | Blend
964     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,         4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
965     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,   4,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
966     AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,   4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
967     AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
968 
969     // From GL_IMG_texture_compression_pvrtc
970     //                       | Internal format                       | W | H | D | BS |CC| SRGB | Texture supported                                 | Filterable     | Texture attachment | Renderbuffer  | Blend
971     AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,      4,  4,  1,  64,  3, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
972     AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,      8,  4,  1,  64,  3, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
973     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,     4,  4,  1,  64,  4, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
974     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,     8,  4,  1,  64,  4, false, RequireExt<&Extensions::compressedTexturePVRTC>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
975 
976     // From GL_EXT_pvrtc_sRGB
977     //                       | Internal format                             | W | H | D | BS |CC| SRGB | Texture supported                                     | Filterable     | Texture attachment | Renderbuffer  | Blend
978     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT,           8,  4,  1,  64,  3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
979     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT,           4,  4,  1,  64,  3, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
980     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT,     8,  4,  1,  64,  4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
981     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT,     4,  4,  1,  64,  4, true, RequireExt<&Extensions::compressedTexturePVRTCsRGB>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
982 
983     // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
984     // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
985     // - All other stencil formats (all depth-stencil) are either float or normalized
986     // - It affects only validation of internalformat in RenderbufferStorageMultisample.
987     //                         | Internal format  |sized|D |S |X | Format          | Type            | Component type        | Texture supported                               | Filterable    | Texture attachment                              | Renderbuffer   | Blend
988     AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireESOrExt<1, 0, &Extensions::stencilIndex8>, NeverSupported, RequireESOrExt<1, 0, &Extensions::stencilIndex8>, RequireES<1, 0>, RequireES<1, 0>);
989 
990     // From GL_ANGLE_lossy_etc_decode
991     //                       | Internal format                                                |W |H |D |BS |CC| SRGB | Texture supported                      | Filterable     | Texture attachment | Renderbuffer  | Blend
992     AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE,                                 4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
993     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE,                      4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
994     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE,                     4, 4, 1, 64, 3, true,  RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
995     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE,  4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
996     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 1, 64, 3, true,  RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
997 
998     // From GL_EXT_texture_norm16
999     //                 | Internal format    |sized| R | G | B | A |S | Format | Type             | Component type        | SRGB | Texture supported                     | Filterable     | Texture attachment                    | Renderbuffer                          | Blend
1000     AddRGBAFormat(&map, GL_R16_EXT,          true, 16,  0,  0,  0, 0, GL_RED,  GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
1001     AddRGBAFormat(&map, GL_R16_SNORM_EXT,    true, 16,  0,  0,  0, 0, GL_RED,  GL_SHORT,          GL_SIGNED_NORMALIZED,   false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1002     AddRGBAFormat(&map, GL_RG16_EXT,         true, 16, 16,  0,  0, 0, GL_RG,   GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
1003     AddRGBAFormat(&map, GL_RG16_SNORM_EXT,   true, 16, 16,  0,  0, 0, GL_RG,   GL_SHORT,          GL_SIGNED_NORMALIZED,   false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1004     AddRGBAFormat(&map, GL_RGB16_EXT,        true, 16, 16, 16,  0, 0, GL_RGB,  GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1005     AddRGBAFormat(&map, GL_RGB16_SNORM_EXT,  true, 16, 16, 16,  0, 0, GL_RGB,  GL_SHORT,          GL_SIGNED_NORMALIZED,   false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1006     AddRGBAFormat(&map, GL_RGBA16_EXT,       true, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
1007     AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT,          GL_SIGNED_NORMALIZED,   false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1008 
1009     // From EXT_texture_sRGB_R8
1010     //                 | Internal format    |sized| R | G | B | A |S | Format | Type             | Component type        | SRGB | Texture supported                     | Filterable     | Texture attachment                    | Renderbuffer                          | Blend
1011     AddRGBAFormat(&map, GL_SR8_EXT,          true,  8,  0,  0,  0, 0, GL_RED,  GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, true,  RequireExt<&Extensions::sRGBR8EXT>,     AlwaysSupported, NeverSupported,                         NeverSupported,                         NeverSupported);
1012 
1013     // Unsized formats
1014     //                 | Internal format  |sized | R | G | B | A |S | Format           | Type                          | Component type        | SRGB | Texture supported                               | Filterable     | Texture attachment                            | Renderbuffer  | Blend
1015     AddRGBAFormat(&map, GL_RED,            false,  8,  0,  0,  0, 0, GL_RED,            GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>,               AlwaysSupported, RequireExt<&Extensions::textureRG>,             NeverSupported, NeverSupported);
1016     AddRGBAFormat(&map, GL_RED,            false,  8,  0,  0,  0, 0, GL_RED,            GL_BYTE,                        GL_SIGNED_NORMALIZED,   false, NeverSupported,                                   NeverSupported,  NeverSupported,                                 NeverSupported, NeverSupported);
1017     AddRGBAFormat(&map, GL_RED,            false, 16,  0,  0,  0, 0, GL_RED,            GL_UNSIGNED_SHORT,              GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>,           AlwaysSupported, RequireExt<&Extensions::textureNorm16>,         NeverSupported, NeverSupported);
1018     AddRGBAFormat(&map, GL_RG,             false,  8,  8,  0,  0, 0, GL_RG,             GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>,               AlwaysSupported, RequireExt<&Extensions::textureRG>,             NeverSupported, NeverSupported);
1019     AddRGBAFormat(&map, GL_RG,             false,  8,  8,  0,  0, 0, GL_RG,             GL_BYTE,                        GL_SIGNED_NORMALIZED,   false, NeverSupported,                                   NeverSupported,  NeverSupported,                                 NeverSupported, NeverSupported);
1020     AddRGBAFormat(&map, GL_RG,             false, 16, 16,  0,  0, 0, GL_RG,             GL_UNSIGNED_SHORT,              GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>,           AlwaysSupported, RequireExt<&Extensions::textureNorm16>,         NeverSupported, NeverSupported);
1021     AddRGBAFormat(&map, GL_RGB,            false,  8,  8,  8,  0, 0, GL_RGB,            GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>,                                NeverSupported, NeverSupported);
1022     AddRGBAFormat(&map, GL_RGB,            false,  5,  6,  5,  0, 0, GL_RGB,            GL_UNSIGNED_SHORT_5_6_5,        GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>,                                NeverSupported, NeverSupported);
1023     AddRGBAFormat(&map, GL_RGB,            false,  8,  8,  8,  0, 0, GL_RGB,            GL_BYTE,                        GL_SIGNED_NORMALIZED,   false, NeverSupported,                                   NeverSupported,  NeverSupported,                                 NeverSupported, NeverSupported);
1024     AddRGBAFormat(&map, GL_RGB,            false, 10, 10, 10,  0, 0, GL_RGB,            GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormat2101010REV>, AlwaysSupported, NeverSupported,                                 NeverSupported, NeverSupported);
1025     AddRGBAFormat(&map, GL_RGBA,           false,  4,  4,  4,  4, 0, GL_RGBA,           GL_UNSIGNED_SHORT_4_4_4_4,      GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>,                                NeverSupported, NeverSupported);
1026     AddRGBAFormat(&map, GL_RGBA,           false,  5,  5,  5,  1, 0, GL_RGBA,           GL_UNSIGNED_SHORT_5_5_5_1,      GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>,                                NeverSupported, NeverSupported);
1027     AddRGBAFormat(&map, GL_RGBA,           false,  8,  8,  8,  8, 0, GL_RGBA,           GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>,                                NeverSupported, NeverSupported);
1028     AddRGBAFormat(&map, GL_RGBA,           false, 16, 16, 16, 16, 0, GL_RGBA,           GL_UNSIGNED_SHORT,              GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>,           AlwaysSupported, RequireExt<&Extensions::textureNorm16>,         NeverSupported, NeverSupported);
1029     AddRGBAFormat(&map, GL_RGBA,           false, 10, 10, 10,  2, 0, GL_RGBA,           GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormat2101010REV>, AlwaysSupported, NeverSupported,                                 NeverSupported, NeverSupported);
1030     AddRGBAFormat(&map, GL_RGBA,           false,  8,  8,  8,  8, 0, GL_RGBA,           GL_BYTE,                        GL_SIGNED_NORMALIZED,   false, NeverSupported,                                   NeverSupported,  NeverSupported,                                 NeverSupported, NeverSupported);
1031     AddRGBAFormat(&map, GL_SRGB,           false,  8,  8,  8,  0, 0, GL_SRGB,           GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, true,  RequireExt<&Extensions::sRGB>,                    AlwaysSupported, NeverSupported,                                 NeverSupported, NeverSupported);
1032     AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false,  8,  8,  8,  8, 0, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, true,  RequireExt<&Extensions::sRGB>,                    AlwaysSupported, RequireExt<&Extensions::sRGB>,                  NeverSupported, NeverSupported);
1033 #if (defined(ANGLE_PLATFORM_IOS) && !defined(ANGLE_PLATFORM_MACCATALYST)) || (defined(ANGLE_PLATFORM_MACCATALYST) && defined(ANGLE_CPU_ARM64))
1034     angle::SystemInfo info;
1035     if (angle::GetSystemInfo(&info))
1036     {
1037         if (info.needsEAGLOnMac)
1038         {
1039             // Using OpenGLES.framework.
1040             AddRGBAFormat(&map, GL_BGRA_EXT,       false,  8,  8,  8,  8, 0, GL_BGRA_EXT,       GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>,                                  AlwaysSupported, RequireES<2, 0>,                                NeverSupported, NeverSupported);
1041         }
1042         else
1043         {
1044             // Using OpenGL.framework.
1045             AddRGBAFormat(&map, GL_BGRA_EXT,       false,  8,  8,  8,  8, 0, GL_BGRA_EXT,       GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>,   AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported, NeverSupported);
1046         }
1047     }
1048 #else
1049     AddRGBAFormat(&map, GL_BGRA_EXT,       false,  8,  8,  8,  8, 0, GL_BGRA_EXT,       GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>,   AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported, NeverSupported);
1050 #endif
1051 
1052     // Unsized integer formats
1053     //                 |Internal format |sized | R | G | B | A |S | Format         | Type                          | Component type | SRGB | Texture supported | Filterable    | Texture attachment | Renderbuffer  | Blend
1054     AddRGBAFormat(&map, GL_RED_INTEGER,  false,  8,  0,  0,  0, 0, GL_RED_INTEGER,  GL_BYTE,                        GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1055     AddRGBAFormat(&map, GL_RED_INTEGER,  false,  8,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_BYTE,               GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1056     AddRGBAFormat(&map, GL_RED_INTEGER,  false, 16,  0,  0,  0, 0, GL_RED_INTEGER,  GL_SHORT,                       GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1057     AddRGBAFormat(&map, GL_RED_INTEGER,  false, 16,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_SHORT,              GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1058     AddRGBAFormat(&map, GL_RED_INTEGER,  false, 32,  0,  0,  0, 0, GL_RED_INTEGER,  GL_INT,                         GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1059     AddRGBAFormat(&map, GL_RED_INTEGER,  false, 32,  0,  0,  0, 0, GL_RED_INTEGER,  GL_UNSIGNED_INT,                GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1060     AddRGBAFormat(&map, GL_RG_INTEGER,   false,  8,  8,  0,  0, 0, GL_RG_INTEGER,   GL_BYTE,                        GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1061     AddRGBAFormat(&map, GL_RG_INTEGER,   false,  8,  8,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_BYTE,               GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1062     AddRGBAFormat(&map, GL_RG_INTEGER,   false, 16, 16,  0,  0, 0, GL_RG_INTEGER,   GL_SHORT,                       GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1063     AddRGBAFormat(&map, GL_RG_INTEGER,   false, 16, 16,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_SHORT,              GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1064     AddRGBAFormat(&map, GL_RG_INTEGER,   false, 32, 32,  0,  0, 0, GL_RG_INTEGER,   GL_INT,                         GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1065     AddRGBAFormat(&map, GL_RG_INTEGER,   false, 32, 32,  0,  0, 0, GL_RG_INTEGER,   GL_UNSIGNED_INT,                GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1066     AddRGBAFormat(&map, GL_RGB_INTEGER,  false,  8,  8,  8,  0, 0, GL_RGB_INTEGER,  GL_BYTE,                        GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1067     AddRGBAFormat(&map, GL_RGB_INTEGER,  false,  8,  8,  8,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_BYTE,               GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1068     AddRGBAFormat(&map, GL_RGB_INTEGER,  false, 16, 16, 16,  0, 0, GL_RGB_INTEGER,  GL_SHORT,                       GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1069     AddRGBAFormat(&map, GL_RGB_INTEGER,  false, 16, 16, 16,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_SHORT,              GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1070     AddRGBAFormat(&map, GL_RGB_INTEGER,  false, 32, 32, 32,  0, 0, GL_RGB_INTEGER,  GL_INT,                         GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1071     AddRGBAFormat(&map, GL_RGB_INTEGER,  false, 32, 32, 32,  0, 0, GL_RGB_INTEGER,  GL_UNSIGNED_INT,                GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1072     AddRGBAFormat(&map, GL_RGBA_INTEGER, false,  8,  8,  8,  8, 0, GL_RGBA_INTEGER, GL_BYTE,                        GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1073     AddRGBAFormat(&map, GL_RGBA_INTEGER, false,  8,  8,  8,  8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE,               GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1074     AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT,                       GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1075     AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT,              GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1076     AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT,                         GL_INT,          false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1077     AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT,                GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1078     AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 10, 10, 10,  2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>,    NeverSupported, NeverSupported,      NeverSupported, NeverSupported);
1079 
1080     // Unsized floating point formats
1081     //                 |Internal format |sized | R | G | B | A |S | Format | Type                           | Comp    | SRGB | Texture supported                                                         | Filterable                                     | Texture attachment                             | Renderbuffer  | Blend
1082     AddRGBAFormat(&map, GL_RED,          false, 16,  0,  0,  0, 0, GL_RED,  GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1083     AddRGBAFormat(&map, GL_RG,           false, 16, 16,  0,  0, 0, GL_RG,   GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1084     AddRGBAFormat(&map, GL_RGB,          false, 16, 16, 16,  0, 0, GL_RGB,  GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1085     AddRGBAFormat(&map, GL_RGBA,         false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1086     AddRGBAFormat(&map, GL_RED,          false, 16,  0,  0,  0, 0, GL_RED,  GL_HALF_FLOAT_OES,               GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>,    RequireExt<&Extensions::textureHalfFloatLinear>, AlwaysSupported,                                 NeverSupported, NeverSupported);
1087     AddRGBAFormat(&map, GL_RG,           false, 16, 16,  0,  0, 0, GL_RG,   GL_HALF_FLOAT_OES,               GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>,    RequireExt<&Extensions::textureHalfFloatLinear>, AlwaysSupported,                                 NeverSupported, NeverSupported);
1088     AddRGBAFormat(&map, GL_RGB,          false, 16, 16, 16,  0, 0, GL_RGB,  GL_HALF_FLOAT_OES,               GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>,                                  RequireExt<&Extensions::textureHalfFloatLinear>, RequireExt<&Extensions::colorBufferHalfFloat>,   NeverSupported, NeverSupported);
1089     AddRGBAFormat(&map, GL_RGBA,         false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES,               GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>,                                  RequireExt<&Extensions::textureHalfFloatLinear>, RequireExt<&Extensions::colorBufferHalfFloat>,   NeverSupported, NeverSupported);
1090     AddRGBAFormat(&map, GL_RED,          false, 32,  0,  0,  0, 0, GL_RED,  GL_FLOAT,                        GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloatOES, &Extensions::textureRG>,     RequireExt<&Extensions::textureFloatLinearOES>,  AlwaysSupported,                                 NeverSupported, NeverSupported);
1091     AddRGBAFormat(&map, GL_RG,           false, 32, 32,  0,  0, 0, GL_RG,   GL_FLOAT,                        GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloatOES, &Extensions::textureRG>,     RequireExt<&Extensions::textureFloatLinearOES>,  AlwaysSupported,                                 NeverSupported, NeverSupported);
1092     AddRGBAFormat(&map, GL_RGB,          false, 32, 32, 32,  0, 0, GL_RGB,  GL_FLOAT,                        GL_FLOAT, false, RequireExt<&Extensions::textureFloatOES>,                                   RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,                                  NeverSupported, NeverSupported);
1093     AddRGBAFormat(&map, GL_RGB,          false,  9,  9,  9,  0, 5, GL_RGB,  GL_UNSIGNED_INT_5_9_9_9_REV,     GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1094     AddRGBAFormat(&map, GL_RGB,          false, 11, 11, 10,  0, 0, GL_RGB,  GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1095     AddRGBAFormat(&map, GL_RGBA,         false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT,                        GL_FLOAT, false, RequireExt<&Extensions::textureFloatOES>,                                   RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,                                  NeverSupported, NeverSupported);
1096 
1097     // Unsized luminance alpha formats
1098     //                 | Internal format   |sized | L | A | Format            | Type             | Component type        | Texture supported                        | Filterable                                     | Texture attachment | Renderbuffer  | Blend
1099     AddLUMAFormat(&map, GL_ALPHA,           false,  0,  8, GL_ALPHA,           GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1100     AddLUMAFormat(&map, GL_LUMINANCE,       false,  8,  0, GL_LUMINANCE,       GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1101     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false,  8,  8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1102     AddLUMAFormat(&map, GL_ALPHA,           false,  0, 16, GL_ALPHA,           GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
1103     AddLUMAFormat(&map, GL_LUMINANCE,       false, 16,  0, GL_LUMINANCE,       GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
1104     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported,      NeverSupported, NeverSupported);
1105     AddLUMAFormat(&map, GL_ALPHA,           false,  0, 32, GL_ALPHA,           GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1106     AddLUMAFormat(&map, GL_LUMINANCE,       false, 32,  0, GL_LUMINANCE,       GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1107     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1108 
1109     // Unsized depth stencil formats
1110     //                         | Internal format   |sized | D |S | X | Format            | Type                             | Component type        | Texture supported                                       | Filterable     | Texture attachment                                                                  | Renderbuffer                                                                       | Blend
1111     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0,  0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT,                 GL_UNSIGNED_NORMALIZED, RequireES<1, 0>,                                          AlwaysSupported, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>,        RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>,        RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>);
1112     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0,  8, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,                   GL_UNSIGNED_NORMALIZED, RequireES<1, 0>,                                          AlwaysSupported, RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>,        RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>,        RequireExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES>);
1113     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0,  0, GL_DEPTH_COMPONENT, GL_FLOAT,                          GL_FLOAT,               RequireES<1, 0>,                                          AlwaysSupported, RequireES<1, 0>,                                                                      RequireES<1, 0>,                                                                      RequireES<1, 0>);
1114     AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 8,  0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8,              GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::packedDepthStencilOES>, AlwaysSupported, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>);
1115     AddDepthStencilFormat(&map, GL_DEPTH_STENCIL,   false, 24, 8,  0, GL_DEPTH_STENCIL,   GL_UNSIGNED_INT_24_8,              GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::packedDepthStencilOES>, AlwaysSupported, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>, RequireExtAndExt<&Extensions::packedDepthStencilOES, &Extensions::depthTextureANGLE>);
1116     AddDepthStencilFormat(&map, GL_DEPTH_STENCIL,   false, 32, 8, 24, GL_DEPTH_STENCIL,   GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT,               RequireESOrExt<3, 0, &Extensions::packedDepthStencilOES>, AlwaysSupported, RequireExt<&Extensions::packedDepthStencilOES>,                                       RequireExt<&Extensions::packedDepthStencilOES>,                                       RequireExt<&Extensions::packedDepthStencilOES>);
1117     AddDepthStencilFormat(&map, GL_STENCIL,         false,  0, 8,  0, GL_STENCIL,         GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, RequireES<1, 0>,                                          NeverSupported , RequireES<1, 0>,                                                                      RequireES<1, 0>,                                                                      RequireES<1, 0>);
1118     AddDepthStencilFormat(&map, GL_STENCIL_INDEX,   false,  0, 8,  0, GL_STENCIL_INDEX,   GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, RequireES<3, 1>,                                          NeverSupported , RequireES<3, 1>,                                                                      RequireES<3, 1>,                                                                      RequireES<3, 1>);
1119     // clang-format on
1120 
1121     return map;
1122 }
1123 
GetInternalFormatMap()1124 const InternalFormatInfoMap &GetInternalFormatMap()
1125 {
1126     static const angle::base::NoDestructor<InternalFormatInfoMap> formatMap(
1127         BuildInternalFormatInfoMap());
1128     return *formatMap;
1129 }
1130 
GetAndroidHardwareBufferFormatFromChannelSizes(const egl::AttributeMap & attribMap)1131 int GetAndroidHardwareBufferFormatFromChannelSizes(const egl::AttributeMap &attribMap)
1132 {
1133     // Retrieve channel size from attribute map. The default value should be 0, per spec.
1134     GLuint redSize   = static_cast<GLuint>(attribMap.getAsInt(EGL_RED_SIZE, 0));
1135     GLuint greenSize = static_cast<GLuint>(attribMap.getAsInt(EGL_GREEN_SIZE, 0));
1136     GLuint blueSize  = static_cast<GLuint>(attribMap.getAsInt(EGL_BLUE_SIZE, 0));
1137     GLuint alphaSize = static_cast<GLuint>(attribMap.getAsInt(EGL_ALPHA_SIZE, 0));
1138 
1139     GLenum glInternalFormat = 0;
1140     for (GLenum sizedInternalFormat : angle::android::kSupportedSizedInternalFormats)
1141     {
1142         const gl::InternalFormat &internalFormat = GetSizedInternalFormatInfo(sizedInternalFormat);
1143         ASSERT(internalFormat.internalFormat != GL_NONE && internalFormat.sized);
1144 
1145         if (internalFormat.isChannelSizeCompatible(redSize, greenSize, blueSize, alphaSize))
1146         {
1147             glInternalFormat = sizedInternalFormat;
1148             break;
1149         }
1150     }
1151 
1152     return (glInternalFormat != 0)
1153                ? angle::android::GLInternalFormatToNativePixelFormat(glInternalFormat)
1154                : 0;
1155 }
1156 
BuildAllSizedInternalFormatSet()1157 static FormatSet BuildAllSizedInternalFormatSet()
1158 {
1159     FormatSet result;
1160 
1161     for (const auto &internalFormat : GetInternalFormatMap())
1162     {
1163         for (const auto &type : internalFormat.second)
1164         {
1165             if (type.second.sized)
1166             {
1167                 // TODO(jmadill): Fix this hack.
1168                 if (internalFormat.first == GL_BGR565_ANGLEX)
1169                     continue;
1170 
1171                 result.insert(internalFormat.first);
1172             }
1173         }
1174     }
1175 
1176     return result;
1177 }
1178 
GetPackedTypeInfo(GLenum type)1179 uint32_t GetPackedTypeInfo(GLenum type)
1180 {
1181     switch (type)
1182     {
1183         case GL_UNSIGNED_BYTE:
1184         case GL_BYTE:
1185         {
1186             static constexpr uint32_t kPacked = PackTypeInfo(1, false);
1187             return kPacked;
1188         }
1189         case GL_UNSIGNED_SHORT:
1190         case GL_SHORT:
1191         case GL_HALF_FLOAT:
1192         case GL_HALF_FLOAT_OES:
1193         {
1194             static constexpr uint32_t kPacked = PackTypeInfo(2, false);
1195             return kPacked;
1196         }
1197         case GL_UNSIGNED_INT:
1198         case GL_INT:
1199         case GL_FLOAT:
1200         {
1201             static constexpr uint32_t kPacked = PackTypeInfo(4, false);
1202             return kPacked;
1203         }
1204         case GL_UNSIGNED_SHORT_5_6_5:
1205         case GL_UNSIGNED_SHORT_4_4_4_4:
1206         case GL_UNSIGNED_SHORT_5_5_5_1:
1207         case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1208         case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1209         {
1210             static constexpr uint32_t kPacked = PackTypeInfo(2, true);
1211             return kPacked;
1212         }
1213         case GL_UNSIGNED_INT_2_10_10_10_REV:
1214         case GL_UNSIGNED_INT_24_8:
1215         case GL_UNSIGNED_INT_10F_11F_11F_REV:
1216         case GL_UNSIGNED_INT_5_9_9_9_REV:
1217         {
1218             ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1219             static constexpr uint32_t kPacked = PackTypeInfo(4, true);
1220             return kPacked;
1221         }
1222         case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1223         {
1224             static constexpr uint32_t kPacked = PackTypeInfo(8, true);
1225             return kPacked;
1226         }
1227         default:
1228         {
1229             return 0;
1230         }
1231     }
1232 }
1233 
GetSizedInternalFormatInfo(GLenum internalFormat)1234 const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
1235 {
1236     static const InternalFormat defaultInternalFormat;
1237     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1238     auto iter                              = formatMap.find(internalFormat);
1239 
1240     // Sized internal formats only have one type per entry
1241     if (iter == formatMap.end() || iter->second.size() != 1)
1242     {
1243         return defaultInternalFormat;
1244     }
1245 
1246     const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1247     if (!internalFormatInfo.sized)
1248     {
1249         return defaultInternalFormat;
1250     }
1251 
1252     return internalFormatInfo;
1253 }
1254 
GetInternalFormatInfo(GLenum internalFormat,GLenum type)1255 const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1256 {
1257     static const InternalFormat defaultInternalFormat;
1258     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1259 
1260     auto internalFormatIter = formatMap.find(internalFormat);
1261     if (internalFormatIter == formatMap.end())
1262     {
1263         return defaultInternalFormat;
1264     }
1265 
1266     // If the internal format is sized, simply return it without the type check.
1267     if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1268     {
1269         return internalFormatIter->second.begin()->second;
1270     }
1271 
1272     auto typeIter = internalFormatIter->second.find(type);
1273     if (typeIter == internalFormatIter->second.end())
1274     {
1275         return defaultInternalFormat;
1276     }
1277 
1278     return typeIter->second;
1279 }
1280 
computePixelBytes(GLenum formatType) const1281 GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1282 {
1283     const auto &typeInfo = GetTypeInfo(formatType);
1284     GLuint components    = typeInfo.specialInterpretation ? 1u : componentCount;
1285     return components * typeInfo.bytes;
1286 }
1287 
computeBufferRowLength(uint32_t width,uint32_t * resultOut) const1288 bool InternalFormat::computeBufferRowLength(uint32_t width, uint32_t *resultOut) const
1289 {
1290     CheckedNumeric<GLuint> checkedWidth(width);
1291 
1292     if (compressed)
1293     {
1294         angle::CheckedNumeric<uint32_t> checkedRowLength =
1295             rx::CheckedRoundUp<uint32_t>(width, compressedBlockWidth);
1296 
1297         return CheckedMathResult(checkedRowLength, resultOut);
1298     }
1299 
1300     return CheckedMathResult(checkedWidth, resultOut);
1301 }
1302 
computeBufferImageHeight(uint32_t height,uint32_t * resultOut) const1303 bool InternalFormat::computeBufferImageHeight(uint32_t height, uint32_t *resultOut) const
1304 {
1305     CheckedNumeric<GLuint> checkedHeight(height);
1306 
1307     if (compressed)
1308     {
1309         angle::CheckedNumeric<uint32_t> checkedImageHeight =
1310             rx::CheckedRoundUp<uint32_t>(height, compressedBlockHeight);
1311 
1312         return CheckedMathResult(checkedImageHeight, resultOut);
1313     }
1314 
1315     return CheckedMathResult(checkedHeight, resultOut);
1316 }
1317 
computeRowPitch(GLenum formatType,GLsizei width,GLint alignment,GLint rowLength,GLuint * resultOut) const1318 bool InternalFormat::computeRowPitch(GLenum formatType,
1319                                      GLsizei width,
1320                                      GLint alignment,
1321                                      GLint rowLength,
1322                                      GLuint *resultOut) const
1323 {
1324     // Compressed images do not use pack/unpack parameters.
1325     if (compressed)
1326     {
1327         ASSERT(rowLength == 0);
1328         return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
1329     }
1330 
1331     CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
1332     CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
1333 
1334     ASSERT(alignment > 0 && isPow2(alignment));
1335     CheckedNumeric<GLuint> checkedAlignment(alignment);
1336     auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1337     return CheckedMathResult(aligned, resultOut);
1338 }
1339 
computeDepthPitch(GLsizei height,GLint imageHeight,GLuint rowPitch,GLuint * resultOut) const1340 bool InternalFormat::computeDepthPitch(GLsizei height,
1341                                        GLint imageHeight,
1342                                        GLuint rowPitch,
1343                                        GLuint *resultOut) const
1344 {
1345     CheckedNumeric<GLuint> pixelsHeight(imageHeight > 0 ? static_cast<GLuint>(imageHeight)
1346                                                         : static_cast<GLuint>(height));
1347 
1348     CheckedNumeric<GLuint> rowCount;
1349     if (compressed)
1350     {
1351         CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
1352         rowCount = (pixelsHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1353     }
1354     else
1355     {
1356         rowCount = pixelsHeight;
1357     }
1358 
1359     CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1360 
1361     return CheckedMathResult(checkedRowPitch * rowCount, resultOut);
1362 }
1363 
computeDepthPitch(GLenum formatType,GLsizei width,GLsizei height,GLint alignment,GLint rowLength,GLint imageHeight,GLuint * resultOut) const1364 bool InternalFormat::computeDepthPitch(GLenum formatType,
1365                                        GLsizei width,
1366                                        GLsizei height,
1367                                        GLint alignment,
1368                                        GLint rowLength,
1369                                        GLint imageHeight,
1370                                        GLuint *resultOut) const
1371 {
1372     GLuint rowPitch = 0;
1373     if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1374     {
1375         return false;
1376     }
1377     return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
1378 }
1379 
computeCompressedImageSize(const Extents & size,GLuint * resultOut) const1380 bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
1381 {
1382     CheckedNumeric<GLuint> checkedWidth(size.width);
1383     CheckedNumeric<GLuint> checkedHeight(size.height);
1384     CheckedNumeric<GLuint> checkedDepth(size.depth);
1385     CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1386     CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
1387     GLuint minBlockWidth, minBlockHeight;
1388     std::tie(minBlockWidth, minBlockHeight) = getCompressedImageMinBlocks();
1389 
1390     ASSERT(compressed);
1391     auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1392     auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1393     if (numBlocksWide.IsValid() && numBlocksWide.ValueOrDie() < minBlockWidth)
1394         numBlocksWide = minBlockWidth;
1395     if (numBlocksHigh.IsValid() && numBlocksHigh.ValueOrDie() < minBlockHeight)
1396         numBlocksHigh = minBlockHeight;
1397     auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1398     return CheckedMathResult(bytes, resultOut);
1399 }
1400 
getCompressedImageMinBlocks() const1401 std::pair<GLuint, GLuint> InternalFormat::getCompressedImageMinBlocks() const
1402 {
1403     GLuint minBlockWidth  = 0;
1404     GLuint minBlockHeight = 0;
1405 
1406     // Per the specification, a PVRTC block needs information from the 3 nearest blocks.
1407     // GL_IMG_texture_compression_pvrtc specifies the minimum size requirement in pixels, but
1408     // ANGLE's texture tables are written in terms of blocks. The 4BPP formats use 4x4 blocks, and
1409     // the 2BPP formats, 8x4 blocks. Therefore, both kinds of formats require a minimum of 2x2
1410     // blocks.
1411     switch (internalFormat)
1412     {
1413         case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
1414         case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
1415         case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
1416         case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
1417         case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
1418         case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
1419         case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
1420         case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
1421             minBlockWidth  = 2;
1422             minBlockHeight = 2;
1423             break;
1424 
1425         default:
1426             break;
1427     }
1428 
1429     return std::make_pair(minBlockWidth, minBlockHeight);
1430 }
1431 
computeSkipBytes(GLenum formatType,GLuint rowPitch,GLuint depthPitch,const PixelStoreStateBase & state,bool is3D,GLuint * resultOut) const1432 bool InternalFormat::computeSkipBytes(GLenum formatType,
1433                                       GLuint rowPitch,
1434                                       GLuint depthPitch,
1435                                       const PixelStoreStateBase &state,
1436                                       bool is3D,
1437                                       GLuint *resultOut) const
1438 {
1439     CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1440     CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
1441     CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1442     CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1443     CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
1444     CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
1445     auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
1446     if (!is3D)
1447     {
1448         checkedSkipImagesBytes = 0;
1449     }
1450     auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1451                      checkedSkipPixels * checkedPixelBytes;
1452     return CheckedMathResult(skipBytes, resultOut);
1453 }
1454 
computePackUnpackEndByte(GLenum formatType,const Extents & size,const PixelStoreStateBase & state,bool is3D,GLuint * resultOut) const1455 bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1456                                               const Extents &size,
1457                                               const PixelStoreStateBase &state,
1458                                               bool is3D,
1459                                               GLuint *resultOut) const
1460 {
1461     GLuint rowPitch = 0;
1462     if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
1463     {
1464         return false;
1465     }
1466 
1467     GLuint depthPitch = 0;
1468     if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1469     {
1470         return false;
1471     }
1472 
1473     CheckedNumeric<GLuint> checkedCopyBytes(0);
1474     if (compressed)
1475     {
1476         GLuint copyBytes = 0;
1477         if (!computeCompressedImageSize(size, &copyBytes))
1478         {
1479             return false;
1480         }
1481         checkedCopyBytes = copyBytes;
1482     }
1483     else if (size.height != 0 && (!is3D || size.depth != 0))
1484     {
1485         CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1486         checkedCopyBytes += size.width * bytes;
1487 
1488         CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1489         checkedCopyBytes += heightMinusOne * rowPitch;
1490 
1491         if (is3D)
1492         {
1493             CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1494             checkedCopyBytes += depthMinusOne * depthPitch;
1495         }
1496     }
1497 
1498     GLuint skipBytes = 0;
1499     if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1500     {
1501         return false;
1502     }
1503 
1504     CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
1505 
1506     return CheckedMathResult(endByte, resultOut);
1507 }
1508 
GetUnsizedFormat(GLenum internalFormat)1509 GLenum GetUnsizedFormat(GLenum internalFormat)
1510 {
1511     auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1512     if (sizedFormatInfo.internalFormat != GL_NONE)
1513     {
1514         return sizedFormatInfo.format;
1515     }
1516 
1517     return internalFormat;
1518 }
1519 
CompressedFormatRequiresWholeImage(GLenum internalFormat)1520 bool CompressedFormatRequiresWholeImage(GLenum internalFormat)
1521 {
1522     // List of compressed texture format that require that the sub-image size is equal to texture's
1523     // respective mip level's size
1524     return IsPVRTC1Format(internalFormat);
1525 }
1526 
MaybeOverrideLuminance(GLenum & format,GLenum & type,GLenum actualFormat,GLenum actualType)1527 void MaybeOverrideLuminance(GLenum &format, GLenum &type, GLenum actualFormat, GLenum actualType)
1528 {
1529     gl::InternalFormat internalFormat = gl::GetInternalFormatInfo(format, type);
1530     if (internalFormat.isLUMA())
1531     {
1532         // Ensure the format and type are compatible
1533         ASSERT(internalFormat.pixelBytes ==
1534                gl::GetInternalFormatInfo(actualFormat, actualType).pixelBytes);
1535 
1536         // For Luminance formats, override with the internal format. Since this is not
1537         // renderable, our pixel pack routines don't handle it correctly.
1538         format = actualFormat;
1539         type   = actualType;
1540     }
1541 }
1542 
GetAllSizedInternalFormats()1543 const FormatSet &GetAllSizedInternalFormats()
1544 {
1545     static angle::base::NoDestructor<FormatSet> formatSet(BuildAllSizedInternalFormatSet());
1546     return *formatSet;
1547 }
1548 
GetAttributeType(GLenum enumValue)1549 AttributeType GetAttributeType(GLenum enumValue)
1550 {
1551     switch (enumValue)
1552     {
1553         case GL_FLOAT:
1554             return ATTRIBUTE_FLOAT;
1555         case GL_FLOAT_VEC2:
1556             return ATTRIBUTE_VEC2;
1557         case GL_FLOAT_VEC3:
1558             return ATTRIBUTE_VEC3;
1559         case GL_FLOAT_VEC4:
1560             return ATTRIBUTE_VEC4;
1561         case GL_INT:
1562             return ATTRIBUTE_INT;
1563         case GL_INT_VEC2:
1564             return ATTRIBUTE_IVEC2;
1565         case GL_INT_VEC3:
1566             return ATTRIBUTE_IVEC3;
1567         case GL_INT_VEC4:
1568             return ATTRIBUTE_IVEC4;
1569         case GL_UNSIGNED_INT:
1570             return ATTRIBUTE_UINT;
1571         case GL_UNSIGNED_INT_VEC2:
1572             return ATTRIBUTE_UVEC2;
1573         case GL_UNSIGNED_INT_VEC3:
1574             return ATTRIBUTE_UVEC3;
1575         case GL_UNSIGNED_INT_VEC4:
1576             return ATTRIBUTE_UVEC4;
1577         case GL_FLOAT_MAT2:
1578             return ATTRIBUTE_MAT2;
1579         case GL_FLOAT_MAT3:
1580             return ATTRIBUTE_MAT3;
1581         case GL_FLOAT_MAT4:
1582             return ATTRIBUTE_MAT4;
1583         case GL_FLOAT_MAT2x3:
1584             return ATTRIBUTE_MAT2x3;
1585         case GL_FLOAT_MAT2x4:
1586             return ATTRIBUTE_MAT2x4;
1587         case GL_FLOAT_MAT3x2:
1588             return ATTRIBUTE_MAT3x2;
1589         case GL_FLOAT_MAT3x4:
1590             return ATTRIBUTE_MAT3x4;
1591         case GL_FLOAT_MAT4x2:
1592             return ATTRIBUTE_MAT4x2;
1593         case GL_FLOAT_MAT4x3:
1594             return ATTRIBUTE_MAT4x3;
1595         default:
1596             UNREACHABLE();
1597 #if !UNREACHABLE_IS_NORETURN
1598             return ATTRIBUTE_FLOAT;
1599 #endif
1600     }
1601 }
1602 
GetVertexFormatID(VertexAttribType type,GLboolean normalized,GLuint components,bool pureInteger)1603 angle::FormatID GetVertexFormatID(VertexAttribType type,
1604                                   GLboolean normalized,
1605                                   GLuint components,
1606                                   bool pureInteger)
1607 {
1608     switch (type)
1609     {
1610         case VertexAttribType::Byte:
1611             switch (components)
1612             {
1613                 case 1:
1614                     if (pureInteger)
1615                         return angle::FormatID::R8_SINT;
1616                     if (normalized)
1617                         return angle::FormatID::R8_SNORM;
1618                     return angle::FormatID::R8_SSCALED;
1619                 case 2:
1620                     if (pureInteger)
1621                         return angle::FormatID::R8G8_SINT;
1622                     if (normalized)
1623                         return angle::FormatID::R8G8_SNORM;
1624                     return angle::FormatID::R8G8_SSCALED;
1625                 case 3:
1626                     if (pureInteger)
1627                         return angle::FormatID::R8G8B8_SINT;
1628                     if (normalized)
1629                         return angle::FormatID::R8G8B8_SNORM;
1630                     return angle::FormatID::R8G8B8_SSCALED;
1631                 case 4:
1632                     if (pureInteger)
1633                         return angle::FormatID::R8G8B8A8_SINT;
1634                     if (normalized)
1635                         return angle::FormatID::R8G8B8A8_SNORM;
1636                     return angle::FormatID::R8G8B8A8_SSCALED;
1637                 default:
1638                     UNREACHABLE();
1639 #if !UNREACHABLE_IS_NORETURN
1640                     return angle::FormatID::NONE;
1641 #endif
1642             }
1643         case VertexAttribType::UnsignedByte:
1644             switch (components)
1645             {
1646                 case 1:
1647                     if (pureInteger)
1648                         return angle::FormatID::R8_UINT;
1649                     if (normalized)
1650                         return angle::FormatID::R8_UNORM;
1651                     return angle::FormatID::R8_USCALED;
1652                 case 2:
1653                     if (pureInteger)
1654                         return angle::FormatID::R8G8_UINT;
1655                     if (normalized)
1656                         return angle::FormatID::R8G8_UNORM;
1657                     return angle::FormatID::R8G8_USCALED;
1658                 case 3:
1659                     if (pureInteger)
1660                         return angle::FormatID::R8G8B8_UINT;
1661                     if (normalized)
1662                         return angle::FormatID::R8G8B8_UNORM;
1663                     return angle::FormatID::R8G8B8_USCALED;
1664                 case 4:
1665                     if (pureInteger)
1666                         return angle::FormatID::R8G8B8A8_UINT;
1667                     if (normalized)
1668                         return angle::FormatID::R8G8B8A8_UNORM;
1669                     return angle::FormatID::R8G8B8A8_USCALED;
1670                 default:
1671                     UNREACHABLE();
1672 #if !UNREACHABLE_IS_NORETURN
1673                     return angle::FormatID::NONE;
1674 #endif
1675             }
1676         case VertexAttribType::Short:
1677             switch (components)
1678             {
1679                 case 1:
1680                     if (pureInteger)
1681                         return angle::FormatID::R16_SINT;
1682                     if (normalized)
1683                         return angle::FormatID::R16_SNORM;
1684                     return angle::FormatID::R16_SSCALED;
1685                 case 2:
1686                     if (pureInteger)
1687                         return angle::FormatID::R16G16_SINT;
1688                     if (normalized)
1689                         return angle::FormatID::R16G16_SNORM;
1690                     return angle::FormatID::R16G16_SSCALED;
1691                 case 3:
1692                     if (pureInteger)
1693                         return angle::FormatID::R16G16B16_SINT;
1694                     if (normalized)
1695                         return angle::FormatID::R16G16B16_SNORM;
1696                     return angle::FormatID::R16G16B16_SSCALED;
1697                 case 4:
1698                     if (pureInteger)
1699                         return angle::FormatID::R16G16B16A16_SINT;
1700                     if (normalized)
1701                         return angle::FormatID::R16G16B16A16_SNORM;
1702                     return angle::FormatID::R16G16B16A16_SSCALED;
1703                 default:
1704                     UNREACHABLE();
1705 #if !UNREACHABLE_IS_NORETURN
1706                     return angle::FormatID::NONE;
1707 #endif
1708             }
1709         case VertexAttribType::UnsignedShort:
1710             switch (components)
1711             {
1712                 case 1:
1713                     if (pureInteger)
1714                         return angle::FormatID::R16_UINT;
1715                     if (normalized)
1716                         return angle::FormatID::R16_UNORM;
1717                     return angle::FormatID::R16_USCALED;
1718                 case 2:
1719                     if (pureInteger)
1720                         return angle::FormatID::R16G16_UINT;
1721                     if (normalized)
1722                         return angle::FormatID::R16G16_UNORM;
1723                     return angle::FormatID::R16G16_USCALED;
1724                 case 3:
1725                     if (pureInteger)
1726                         return angle::FormatID::R16G16B16_UINT;
1727                     if (normalized)
1728                         return angle::FormatID::R16G16B16_UNORM;
1729                     return angle::FormatID::R16G16B16_USCALED;
1730                 case 4:
1731                     if (pureInteger)
1732                         return angle::FormatID::R16G16B16A16_UINT;
1733                     if (normalized)
1734                         return angle::FormatID::R16G16B16A16_UNORM;
1735                     return angle::FormatID::R16G16B16A16_USCALED;
1736                 default:
1737                     UNREACHABLE();
1738 #if !UNREACHABLE_IS_NORETURN
1739                     return angle::FormatID::NONE;
1740 #endif
1741             }
1742         case VertexAttribType::Int:
1743             switch (components)
1744             {
1745                 case 1:
1746                     if (pureInteger)
1747                         return angle::FormatID::R32_SINT;
1748                     if (normalized)
1749                         return angle::FormatID::R32_SNORM;
1750                     return angle::FormatID::R32_SSCALED;
1751                 case 2:
1752                     if (pureInteger)
1753                         return angle::FormatID::R32G32_SINT;
1754                     if (normalized)
1755                         return angle::FormatID::R32G32_SNORM;
1756                     return angle::FormatID::R32G32_SSCALED;
1757                 case 3:
1758                     if (pureInteger)
1759                         return angle::FormatID::R32G32B32_SINT;
1760                     if (normalized)
1761                         return angle::FormatID::R32G32B32_SNORM;
1762                     return angle::FormatID::R32G32B32_SSCALED;
1763                 case 4:
1764                     if (pureInteger)
1765                         return angle::FormatID::R32G32B32A32_SINT;
1766                     if (normalized)
1767                         return angle::FormatID::R32G32B32A32_SNORM;
1768                     return angle::FormatID::R32G32B32A32_SSCALED;
1769                 default:
1770                     UNREACHABLE();
1771 #if !UNREACHABLE_IS_NORETURN
1772                     return angle::FormatID::NONE;
1773 #endif
1774             }
1775         case VertexAttribType::UnsignedInt:
1776             switch (components)
1777             {
1778                 case 1:
1779                     if (pureInteger)
1780                         return angle::FormatID::R32_UINT;
1781                     if (normalized)
1782                         return angle::FormatID::R32_UNORM;
1783                     return angle::FormatID::R32_USCALED;
1784                 case 2:
1785                     if (pureInteger)
1786                         return angle::FormatID::R32G32_UINT;
1787                     if (normalized)
1788                         return angle::FormatID::R32G32_UNORM;
1789                     return angle::FormatID::R32G32_USCALED;
1790                 case 3:
1791                     if (pureInteger)
1792                         return angle::FormatID::R32G32B32_UINT;
1793                     if (normalized)
1794                         return angle::FormatID::R32G32B32_UNORM;
1795                     return angle::FormatID::R32G32B32_USCALED;
1796                 case 4:
1797                     if (pureInteger)
1798                         return angle::FormatID::R32G32B32A32_UINT;
1799                     if (normalized)
1800                         return angle::FormatID::R32G32B32A32_UNORM;
1801                     return angle::FormatID::R32G32B32A32_USCALED;
1802                 default:
1803                     UNREACHABLE();
1804 #if !UNREACHABLE_IS_NORETURN
1805                     return angle::FormatID::NONE;
1806 #endif
1807             }
1808         case VertexAttribType::Float:
1809             switch (components)
1810             {
1811                 case 1:
1812                     return angle::FormatID::R32_FLOAT;
1813                 case 2:
1814                     return angle::FormatID::R32G32_FLOAT;
1815                 case 3:
1816                     return angle::FormatID::R32G32B32_FLOAT;
1817                 case 4:
1818                     return angle::FormatID::R32G32B32A32_FLOAT;
1819                 default:
1820                     UNREACHABLE();
1821 #if !UNREACHABLE_IS_NORETURN
1822                     return angle::FormatID::NONE;
1823 #endif
1824             }
1825         case VertexAttribType::HalfFloat:
1826         case VertexAttribType::HalfFloatOES:
1827             switch (components)
1828             {
1829                 case 1:
1830                     return angle::FormatID::R16_FLOAT;
1831                 case 2:
1832                     return angle::FormatID::R16G16_FLOAT;
1833                 case 3:
1834                     return angle::FormatID::R16G16B16_FLOAT;
1835                 case 4:
1836                     return angle::FormatID::R16G16B16A16_FLOAT;
1837                 default:
1838                     UNREACHABLE();
1839 #if !UNREACHABLE_IS_NORETURN
1840                     return angle::FormatID::NONE;
1841 #endif
1842             }
1843         case VertexAttribType::Fixed:
1844             switch (components)
1845             {
1846                 case 1:
1847                     return angle::FormatID::R32_FIXED;
1848                 case 2:
1849                     return angle::FormatID::R32G32_FIXED;
1850                 case 3:
1851                     return angle::FormatID::R32G32B32_FIXED;
1852                 case 4:
1853                     return angle::FormatID::R32G32B32A32_FIXED;
1854                 default:
1855                     UNREACHABLE();
1856 #if !UNREACHABLE_IS_NORETURN
1857                     return angle::FormatID::NONE;
1858 #endif
1859             }
1860         case VertexAttribType::Int2101010:
1861             if (pureInteger)
1862                 return angle::FormatID::R10G10B10A2_SINT;
1863             if (normalized)
1864                 return angle::FormatID::R10G10B10A2_SNORM;
1865             return angle::FormatID::R10G10B10A2_SSCALED;
1866         case VertexAttribType::UnsignedInt2101010:
1867             if (pureInteger)
1868                 return angle::FormatID::R10G10B10A2_UINT;
1869             if (normalized)
1870                 return angle::FormatID::R10G10B10A2_UNORM;
1871             return angle::FormatID::R10G10B10A2_USCALED;
1872         case VertexAttribType::Int1010102:
1873             switch (components)
1874             {
1875                 case 3:
1876                     if (pureInteger)
1877                         return angle::FormatID::X2R10G10B10_SINT_VERTEX;
1878                     if (normalized)
1879                         return angle::FormatID::X2R10G10B10_SNORM_VERTEX;
1880                     return angle::FormatID::X2R10G10B10_SSCALED_VERTEX;
1881                 case 4:
1882                     if (pureInteger)
1883                         return angle::FormatID::A2R10G10B10_SINT_VERTEX;
1884                     if (normalized)
1885                         return angle::FormatID::A2R10G10B10_SNORM_VERTEX;
1886                     return angle::FormatID::A2R10G10B10_SSCALED_VERTEX;
1887                 default:
1888                     UNREACHABLE();
1889 #if !UNREACHABLE_IS_NORETURN
1890                     return angle::FormatID::NONE;
1891 #endif
1892             }
1893         case VertexAttribType::UnsignedInt1010102:
1894             switch (components)
1895             {
1896                 case 3:
1897                     if (pureInteger)
1898                         return angle::FormatID::X2R10G10B10_UINT_VERTEX;
1899                     if (normalized)
1900                         return angle::FormatID::X2R10G10B10_UNORM_VERTEX;
1901                     return angle::FormatID::X2R10G10B10_USCALED_VERTEX;
1902 
1903                 case 4:
1904                     if (pureInteger)
1905                         return angle::FormatID::A2R10G10B10_UINT_VERTEX;
1906                     if (normalized)
1907                         return angle::FormatID::A2R10G10B10_UNORM_VERTEX;
1908                     return angle::FormatID::A2R10G10B10_USCALED_VERTEX;
1909                 default:
1910                     UNREACHABLE();
1911 #if !UNREACHABLE_IS_NORETURN
1912                     return angle::FormatID::NONE;
1913 #endif
1914             }
1915         default:
1916             UNREACHABLE();
1917 #if !UNREACHABLE_IS_NORETURN
1918             return angle::FormatID::NONE;
1919 #endif
1920     }
1921 }
1922 
GetVertexFormatID(const VertexAttribute & attrib,VertexAttribType currentValueType)1923 angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType)
1924 {
1925     if (!attrib.enabled)
1926     {
1927         return GetCurrentValueFormatID(currentValueType);
1928     }
1929     return attrib.format->id;
1930 }
1931 
GetCurrentValueFormatID(VertexAttribType currentValueType)1932 angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType)
1933 {
1934     switch (currentValueType)
1935     {
1936         case VertexAttribType::Float:
1937             return angle::FormatID::R32G32B32A32_FLOAT;
1938         case VertexAttribType::Int:
1939             return angle::FormatID::R32G32B32A32_SINT;
1940         case VertexAttribType::UnsignedInt:
1941             return angle::FormatID::R32G32B32A32_UINT;
1942         default:
1943             UNREACHABLE();
1944             return angle::FormatID::NONE;
1945     }
1946 }
1947 
GetVertexFormatFromID(angle::FormatID vertexFormatID)1948 const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
1949 {
1950     switch (vertexFormatID)
1951     {
1952         case angle::FormatID::R8_SSCALED:
1953         {
1954             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1955             return format;
1956         }
1957         case angle::FormatID::R8_SNORM:
1958         {
1959             static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1960             return format;
1961         }
1962         case angle::FormatID::R8G8_SSCALED:
1963         {
1964             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1965             return format;
1966         }
1967         case angle::FormatID::R8G8_SNORM:
1968         {
1969             static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1970             return format;
1971         }
1972         case angle::FormatID::R8G8B8_SSCALED:
1973         {
1974             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1975             return format;
1976         }
1977         case angle::FormatID::R8G8B8_SNORM:
1978         {
1979             static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1980             return format;
1981         }
1982         case angle::FormatID::R8G8B8A8_SSCALED:
1983         {
1984             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1985             return format;
1986         }
1987         case angle::FormatID::R8G8B8A8_SNORM:
1988         {
1989             static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1990             return format;
1991         }
1992         case angle::FormatID::R8_USCALED:
1993         {
1994             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1995             return format;
1996         }
1997         case angle::FormatID::R8_UNORM:
1998         {
1999             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
2000             return format;
2001         }
2002         case angle::FormatID::R8G8_USCALED:
2003         {
2004             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
2005             return format;
2006         }
2007         case angle::FormatID::R8G8_UNORM:
2008         {
2009             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
2010             return format;
2011         }
2012         case angle::FormatID::R8G8B8_USCALED:
2013         {
2014             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
2015             return format;
2016         }
2017         case angle::FormatID::R8G8B8_UNORM:
2018         {
2019             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
2020             return format;
2021         }
2022         case angle::FormatID::R8G8B8A8_USCALED:
2023         {
2024             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
2025             return format;
2026         }
2027         case angle::FormatID::R8G8B8A8_UNORM:
2028         {
2029             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
2030             return format;
2031         }
2032         case angle::FormatID::R16_SSCALED:
2033         {
2034             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
2035             return format;
2036         }
2037         case angle::FormatID::R16_SNORM:
2038         {
2039             static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
2040             return format;
2041         }
2042         case angle::FormatID::R16G16_SSCALED:
2043         {
2044             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
2045             return format;
2046         }
2047         case angle::FormatID::R16G16_SNORM:
2048         {
2049             static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
2050             return format;
2051         }
2052         case angle::FormatID::R16G16B16_SSCALED:
2053         {
2054             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
2055             return format;
2056         }
2057         case angle::FormatID::R16G16B16_SNORM:
2058         {
2059             static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
2060             return format;
2061         }
2062         case angle::FormatID::R16G16B16A16_SSCALED:
2063         {
2064             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
2065             return format;
2066         }
2067         case angle::FormatID::R16G16B16A16_SNORM:
2068         {
2069             static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
2070             return format;
2071         }
2072         case angle::FormatID::R16_USCALED:
2073         {
2074             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
2075             return format;
2076         }
2077         case angle::FormatID::R16_UNORM:
2078         {
2079             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
2080             return format;
2081         }
2082         case angle::FormatID::R16G16_USCALED:
2083         {
2084             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
2085             return format;
2086         }
2087         case angle::FormatID::R16G16_UNORM:
2088         {
2089             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
2090             return format;
2091         }
2092         case angle::FormatID::R16G16B16_USCALED:
2093         {
2094             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
2095             return format;
2096         }
2097         case angle::FormatID::R16G16B16_UNORM:
2098         {
2099             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
2100             return format;
2101         }
2102         case angle::FormatID::R16G16B16A16_USCALED:
2103         {
2104             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
2105             return format;
2106         }
2107         case angle::FormatID::R16G16B16A16_UNORM:
2108         {
2109             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
2110             return format;
2111         }
2112         case angle::FormatID::R32_SSCALED:
2113         {
2114             static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
2115             return format;
2116         }
2117         case angle::FormatID::R32_SNORM:
2118         {
2119             static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
2120             return format;
2121         }
2122         case angle::FormatID::R32G32_SSCALED:
2123         {
2124             static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
2125             return format;
2126         }
2127         case angle::FormatID::R32G32_SNORM:
2128         {
2129             static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
2130             return format;
2131         }
2132         case angle::FormatID::R32G32B32_SSCALED:
2133         {
2134             static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
2135             return format;
2136         }
2137         case angle::FormatID::R32G32B32_SNORM:
2138         {
2139             static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
2140             return format;
2141         }
2142         case angle::FormatID::R32G32B32A32_SSCALED:
2143         {
2144             static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
2145             return format;
2146         }
2147         case angle::FormatID::R32G32B32A32_SNORM:
2148         {
2149             static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
2150             return format;
2151         }
2152         case angle::FormatID::R32_USCALED:
2153         {
2154             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2155             return format;
2156         }
2157         case angle::FormatID::R32_UNORM:
2158         {
2159             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2160             return format;
2161         }
2162         case angle::FormatID::R32G32_USCALED:
2163         {
2164             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2165             return format;
2166         }
2167         case angle::FormatID::R32G32_UNORM:
2168         {
2169             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2170             return format;
2171         }
2172         case angle::FormatID::R32G32B32_USCALED:
2173         {
2174             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2175             return format;
2176         }
2177         case angle::FormatID::R32G32B32_UNORM:
2178         {
2179             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2180             return format;
2181         }
2182         case angle::FormatID::R32G32B32A32_USCALED:
2183         {
2184             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2185             return format;
2186         }
2187         case angle::FormatID::R32G32B32A32_UNORM:
2188         {
2189             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2190             return format;
2191         }
2192         case angle::FormatID::R8_SINT:
2193         {
2194             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2195             return format;
2196         }
2197         case angle::FormatID::R8G8_SINT:
2198         {
2199             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2200             return format;
2201         }
2202         case angle::FormatID::R8G8B8_SINT:
2203         {
2204             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2205             return format;
2206         }
2207         case angle::FormatID::R8G8B8A8_SINT:
2208         {
2209             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2210             return format;
2211         }
2212         case angle::FormatID::R8_UINT:
2213         {
2214             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2215             return format;
2216         }
2217         case angle::FormatID::R8G8_UINT:
2218         {
2219             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2220             return format;
2221         }
2222         case angle::FormatID::R8G8B8_UINT:
2223         {
2224             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2225             return format;
2226         }
2227         case angle::FormatID::R8G8B8A8_UINT:
2228         {
2229             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2230             return format;
2231         }
2232         case angle::FormatID::R16_SINT:
2233         {
2234             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2235             return format;
2236         }
2237         case angle::FormatID::R16G16_SINT:
2238         {
2239             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2240             return format;
2241         }
2242         case angle::FormatID::R16G16B16_SINT:
2243         {
2244             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2245             return format;
2246         }
2247         case angle::FormatID::R16G16B16A16_SINT:
2248         {
2249             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2250             return format;
2251         }
2252         case angle::FormatID::R16_UINT:
2253         {
2254             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2255             return format;
2256         }
2257         case angle::FormatID::R16G16_UINT:
2258         {
2259             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2260             return format;
2261         }
2262         case angle::FormatID::R16G16B16_UINT:
2263         {
2264             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2265             return format;
2266         }
2267         case angle::FormatID::R16G16B16A16_UINT:
2268         {
2269             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2270             return format;
2271         }
2272         case angle::FormatID::R32_SINT:
2273         {
2274             static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2275             return format;
2276         }
2277         case angle::FormatID::R32G32_SINT:
2278         {
2279             static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2280             return format;
2281         }
2282         case angle::FormatID::R32G32B32_SINT:
2283         {
2284             static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2285             return format;
2286         }
2287         case angle::FormatID::R32G32B32A32_SINT:
2288         {
2289             static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2290             return format;
2291         }
2292         case angle::FormatID::R32_UINT:
2293         {
2294             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2295             return format;
2296         }
2297         case angle::FormatID::R32G32_UINT:
2298         {
2299             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2300             return format;
2301         }
2302         case angle::FormatID::R32G32B32_UINT:
2303         {
2304             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2305             return format;
2306         }
2307         case angle::FormatID::R32G32B32A32_UINT:
2308         {
2309             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2310             return format;
2311         }
2312         case angle::FormatID::R32_FIXED:
2313         {
2314             static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2315             return format;
2316         }
2317         case angle::FormatID::R32G32_FIXED:
2318         {
2319             static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2320             return format;
2321         }
2322         case angle::FormatID::R32G32B32_FIXED:
2323         {
2324             static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2325             return format;
2326         }
2327         case angle::FormatID::R32G32B32A32_FIXED:
2328         {
2329             static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2330             return format;
2331         }
2332         case angle::FormatID::R16_FLOAT:
2333         {
2334             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2335             return format;
2336         }
2337         case angle::FormatID::R16G16_FLOAT:
2338         {
2339             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2340             return format;
2341         }
2342         case angle::FormatID::R16G16B16_FLOAT:
2343         {
2344             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2345             return format;
2346         }
2347         case angle::FormatID::R16G16B16A16_FLOAT:
2348         {
2349             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2350             return format;
2351         }
2352         case angle::FormatID::R32_FLOAT:
2353         {
2354             static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2355             return format;
2356         }
2357         case angle::FormatID::R32G32_FLOAT:
2358         {
2359             static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2360             return format;
2361         }
2362         case angle::FormatID::R32G32B32_FLOAT:
2363         {
2364             static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2365             return format;
2366         }
2367         case angle::FormatID::R32G32B32A32_FLOAT:
2368         {
2369             static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2370             return format;
2371         }
2372         case angle::FormatID::R10G10B10A2_SSCALED:
2373         {
2374             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2375             return format;
2376         }
2377         case angle::FormatID::R10G10B10A2_USCALED:
2378         {
2379             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2380             return format;
2381         }
2382         case angle::FormatID::R10G10B10A2_SNORM:
2383         {
2384             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2385             return format;
2386         }
2387         case angle::FormatID::R10G10B10A2_UNORM:
2388         {
2389             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2390             return format;
2391         }
2392         case angle::FormatID::R10G10B10A2_SINT:
2393         {
2394             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2395             return format;
2396         }
2397         case angle::FormatID::R10G10B10A2_UINT:
2398         {
2399             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2400             return format;
2401         }
2402         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2403         {
2404             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2405             return format;
2406         }
2407         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2408         {
2409             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2410             return format;
2411         }
2412         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
2413         {
2414             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2415             return format;
2416         }
2417         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
2418         {
2419             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2420             return format;
2421         }
2422         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2423         {
2424             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2425             return format;
2426         }
2427         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2428         {
2429             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2430             return format;
2431         }
2432         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
2433         {
2434             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2435             return format;
2436         }
2437         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
2438         {
2439             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2440             return format;
2441         }
2442         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
2443         {
2444             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2445             return format;
2446         }
2447         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
2448         {
2449             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2450             return format;
2451         }
2452         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
2453         {
2454             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2455             return format;
2456         }
2457         default:
2458         {
2459             static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2460             return format;
2461         }
2462     }
2463 }
2464 
GetVertexFormatSize(angle::FormatID vertexFormatID)2465 size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
2466 {
2467     switch (vertexFormatID)
2468     {
2469         case angle::FormatID::R8_SSCALED:
2470         case angle::FormatID::R8_SNORM:
2471         case angle::FormatID::R8_USCALED:
2472         case angle::FormatID::R8_UNORM:
2473         case angle::FormatID::R8_SINT:
2474         case angle::FormatID::R8_UINT:
2475             return 1;
2476 
2477         case angle::FormatID::R8G8_SSCALED:
2478         case angle::FormatID::R8G8_SNORM:
2479         case angle::FormatID::R8G8_USCALED:
2480         case angle::FormatID::R8G8_UNORM:
2481         case angle::FormatID::R8G8_SINT:
2482         case angle::FormatID::R8G8_UINT:
2483         case angle::FormatID::R16_SSCALED:
2484         case angle::FormatID::R16_SNORM:
2485         case angle::FormatID::R16_USCALED:
2486         case angle::FormatID::R16_UNORM:
2487         case angle::FormatID::R16_SINT:
2488         case angle::FormatID::R16_UINT:
2489         case angle::FormatID::R16_FLOAT:
2490             return 2;
2491 
2492         case angle::FormatID::R8G8B8_SSCALED:
2493         case angle::FormatID::R8G8B8_SNORM:
2494         case angle::FormatID::R8G8B8_USCALED:
2495         case angle::FormatID::R8G8B8_UNORM:
2496         case angle::FormatID::R8G8B8_SINT:
2497         case angle::FormatID::R8G8B8_UINT:
2498             return 3;
2499 
2500         case angle::FormatID::R8G8B8A8_SSCALED:
2501         case angle::FormatID::R8G8B8A8_SNORM:
2502         case angle::FormatID::R8G8B8A8_USCALED:
2503         case angle::FormatID::R8G8B8A8_UNORM:
2504         case angle::FormatID::R8G8B8A8_SINT:
2505         case angle::FormatID::R8G8B8A8_UINT:
2506         case angle::FormatID::R16G16_SSCALED:
2507         case angle::FormatID::R16G16_SNORM:
2508         case angle::FormatID::R16G16_USCALED:
2509         case angle::FormatID::R16G16_UNORM:
2510         case angle::FormatID::R16G16_SINT:
2511         case angle::FormatID::R16G16_UINT:
2512         case angle::FormatID::R32_SSCALED:
2513         case angle::FormatID::R32_SNORM:
2514         case angle::FormatID::R32_USCALED:
2515         case angle::FormatID::R32_UNORM:
2516         case angle::FormatID::R32_SINT:
2517         case angle::FormatID::R32_UINT:
2518         case angle::FormatID::R16G16_FLOAT:
2519         case angle::FormatID::R32_FIXED:
2520         case angle::FormatID::R32_FLOAT:
2521         case angle::FormatID::R10G10B10A2_SSCALED:
2522         case angle::FormatID::R10G10B10A2_USCALED:
2523         case angle::FormatID::R10G10B10A2_SNORM:
2524         case angle::FormatID::R10G10B10A2_UNORM:
2525         case angle::FormatID::R10G10B10A2_SINT:
2526         case angle::FormatID::R10G10B10A2_UINT:
2527         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2528         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2529         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2530         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2531         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
2532         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
2533         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
2534         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
2535         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
2536         case angle::FormatID::X2R10G10B10_UINT_VERTEX:
2537         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
2538         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
2539             return 4;
2540 
2541         case angle::FormatID::R16G16B16_SSCALED:
2542         case angle::FormatID::R16G16B16_SNORM:
2543         case angle::FormatID::R16G16B16_USCALED:
2544         case angle::FormatID::R16G16B16_UNORM:
2545         case angle::FormatID::R16G16B16_SINT:
2546         case angle::FormatID::R16G16B16_UINT:
2547         case angle::FormatID::R16G16B16_FLOAT:
2548             return 6;
2549 
2550         case angle::FormatID::R16G16B16A16_SSCALED:
2551         case angle::FormatID::R16G16B16A16_SNORM:
2552         case angle::FormatID::R16G16B16A16_USCALED:
2553         case angle::FormatID::R16G16B16A16_UNORM:
2554         case angle::FormatID::R16G16B16A16_SINT:
2555         case angle::FormatID::R16G16B16A16_UINT:
2556         case angle::FormatID::R32G32_SSCALED:
2557         case angle::FormatID::R32G32_SNORM:
2558         case angle::FormatID::R32G32_USCALED:
2559         case angle::FormatID::R32G32_UNORM:
2560         case angle::FormatID::R32G32_SINT:
2561         case angle::FormatID::R32G32_UINT:
2562         case angle::FormatID::R16G16B16A16_FLOAT:
2563         case angle::FormatID::R32G32_FIXED:
2564         case angle::FormatID::R32G32_FLOAT:
2565             return 8;
2566 
2567         case angle::FormatID::R32G32B32_SSCALED:
2568         case angle::FormatID::R32G32B32_SNORM:
2569         case angle::FormatID::R32G32B32_USCALED:
2570         case angle::FormatID::R32G32B32_UNORM:
2571         case angle::FormatID::R32G32B32_SINT:
2572         case angle::FormatID::R32G32B32_UINT:
2573         case angle::FormatID::R32G32B32_FIXED:
2574         case angle::FormatID::R32G32B32_FLOAT:
2575             return 12;
2576 
2577         case angle::FormatID::R32G32B32A32_SSCALED:
2578         case angle::FormatID::R32G32B32A32_SNORM:
2579         case angle::FormatID::R32G32B32A32_USCALED:
2580         case angle::FormatID::R32G32B32A32_UNORM:
2581         case angle::FormatID::R32G32B32A32_SINT:
2582         case angle::FormatID::R32G32B32A32_UINT:
2583         case angle::FormatID::R32G32B32A32_FIXED:
2584         case angle::FormatID::R32G32B32A32_FLOAT:
2585             return 16;
2586 
2587         case angle::FormatID::NONE:
2588         default:
2589             UNREACHABLE();
2590 #if !UNREACHABLE_IS_NORETURN
2591             return 0;
2592 #endif
2593     }
2594 }
2595 
ValidES3InternalFormat(GLenum internalFormat)2596 bool ValidES3InternalFormat(GLenum internalFormat)
2597 {
2598     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2599     return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2600 }
2601 
VertexFormat(GLenum typeIn,GLboolean normalizedIn,GLuint componentsIn,bool pureIntegerIn)2602 VertexFormat::VertexFormat(GLenum typeIn,
2603                            GLboolean normalizedIn,
2604                            GLuint componentsIn,
2605                            bool pureIntegerIn)
2606     : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
2607 {
2608     // float -> !normalized
2609     ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2610            normalized == GL_FALSE);
2611 }
2612 }  // namespace gl
2613