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,  0, 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, RequireES<2, 0>,                                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, RequireES<2, 0>,                                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, RequireES<2, 0>,                                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, RequireES<2, 0>,                                NeverSupported, NeverSupported);
1027     AddRGBAFormat(&map, GL_RGBA,           false,  8,  8,  8,  8, 0, GL_RGBA,           GL_UNSIGNED_BYTE,               GL_UNSIGNED_NORMALIZED, false, AlwaysSupported,                                  AlwaysSupported, RequireES<2, 0>,                                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.isiOSAppOnMac)
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,  0, 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     switch (internalFormat)
1525     {
1526         case GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG:
1527         case GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG:
1528         case GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG:
1529         case GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG:
1530         case GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT:
1531         case GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT:
1532         case GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT:
1533         case GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT:
1534             return true;
1535 
1536         default:
1537             return false;
1538     }
1539 }
1540 
MaybeOverrideLuminance(GLenum & format,GLenum & type,GLenum actualFormat,GLenum actualType)1541 void MaybeOverrideLuminance(GLenum &format, GLenum &type, GLenum actualFormat, GLenum actualType)
1542 {
1543     gl::InternalFormat internalFormat = gl::GetInternalFormatInfo(format, type);
1544     if (internalFormat.isLUMA())
1545     {
1546         // Ensure the format and type are compatible
1547         ASSERT(internalFormat.pixelBytes ==
1548                gl::GetInternalFormatInfo(actualFormat, actualType).pixelBytes);
1549 
1550         // For Luminance formats, override with the internal format. Since this is not
1551         // renderable, our pixel pack routines don't handle it correctly.
1552         format = actualFormat;
1553         type   = actualType;
1554     }
1555 }
1556 
GetAllSizedInternalFormats()1557 const FormatSet &GetAllSizedInternalFormats()
1558 {
1559     static angle::base::NoDestructor<FormatSet> formatSet(BuildAllSizedInternalFormatSet());
1560     return *formatSet;
1561 }
1562 
GetAttributeType(GLenum enumValue)1563 AttributeType GetAttributeType(GLenum enumValue)
1564 {
1565     switch (enumValue)
1566     {
1567         case GL_FLOAT:
1568             return ATTRIBUTE_FLOAT;
1569         case GL_FLOAT_VEC2:
1570             return ATTRIBUTE_VEC2;
1571         case GL_FLOAT_VEC3:
1572             return ATTRIBUTE_VEC3;
1573         case GL_FLOAT_VEC4:
1574             return ATTRIBUTE_VEC4;
1575         case GL_INT:
1576             return ATTRIBUTE_INT;
1577         case GL_INT_VEC2:
1578             return ATTRIBUTE_IVEC2;
1579         case GL_INT_VEC3:
1580             return ATTRIBUTE_IVEC3;
1581         case GL_INT_VEC4:
1582             return ATTRIBUTE_IVEC4;
1583         case GL_UNSIGNED_INT:
1584             return ATTRIBUTE_UINT;
1585         case GL_UNSIGNED_INT_VEC2:
1586             return ATTRIBUTE_UVEC2;
1587         case GL_UNSIGNED_INT_VEC3:
1588             return ATTRIBUTE_UVEC3;
1589         case GL_UNSIGNED_INT_VEC4:
1590             return ATTRIBUTE_UVEC4;
1591         case GL_FLOAT_MAT2:
1592             return ATTRIBUTE_MAT2;
1593         case GL_FLOAT_MAT3:
1594             return ATTRIBUTE_MAT3;
1595         case GL_FLOAT_MAT4:
1596             return ATTRIBUTE_MAT4;
1597         case GL_FLOAT_MAT2x3:
1598             return ATTRIBUTE_MAT2x3;
1599         case GL_FLOAT_MAT2x4:
1600             return ATTRIBUTE_MAT2x4;
1601         case GL_FLOAT_MAT3x2:
1602             return ATTRIBUTE_MAT3x2;
1603         case GL_FLOAT_MAT3x4:
1604             return ATTRIBUTE_MAT3x4;
1605         case GL_FLOAT_MAT4x2:
1606             return ATTRIBUTE_MAT4x2;
1607         case GL_FLOAT_MAT4x3:
1608             return ATTRIBUTE_MAT4x3;
1609         default:
1610             UNREACHABLE();
1611 #if !UNREACHABLE_IS_NORETURN
1612             return ATTRIBUTE_FLOAT;
1613 #endif
1614     }
1615 }
1616 
GetVertexFormatID(VertexAttribType type,GLboolean normalized,GLuint components,bool pureInteger)1617 angle::FormatID GetVertexFormatID(VertexAttribType type,
1618                                   GLboolean normalized,
1619                                   GLuint components,
1620                                   bool pureInteger)
1621 {
1622     switch (type)
1623     {
1624         case VertexAttribType::Byte:
1625             switch (components)
1626             {
1627                 case 1:
1628                     if (pureInteger)
1629                         return angle::FormatID::R8_SINT;
1630                     if (normalized)
1631                         return angle::FormatID::R8_SNORM;
1632                     return angle::FormatID::R8_SSCALED;
1633                 case 2:
1634                     if (pureInteger)
1635                         return angle::FormatID::R8G8_SINT;
1636                     if (normalized)
1637                         return angle::FormatID::R8G8_SNORM;
1638                     return angle::FormatID::R8G8_SSCALED;
1639                 case 3:
1640                     if (pureInteger)
1641                         return angle::FormatID::R8G8B8_SINT;
1642                     if (normalized)
1643                         return angle::FormatID::R8G8B8_SNORM;
1644                     return angle::FormatID::R8G8B8_SSCALED;
1645                 case 4:
1646                     if (pureInteger)
1647                         return angle::FormatID::R8G8B8A8_SINT;
1648                     if (normalized)
1649                         return angle::FormatID::R8G8B8A8_SNORM;
1650                     return angle::FormatID::R8G8B8A8_SSCALED;
1651                 default:
1652                     UNREACHABLE();
1653 #if !UNREACHABLE_IS_NORETURN
1654                     return angle::FormatID::NONE;
1655 #endif
1656             }
1657         case VertexAttribType::UnsignedByte:
1658             switch (components)
1659             {
1660                 case 1:
1661                     if (pureInteger)
1662                         return angle::FormatID::R8_UINT;
1663                     if (normalized)
1664                         return angle::FormatID::R8_UNORM;
1665                     return angle::FormatID::R8_USCALED;
1666                 case 2:
1667                     if (pureInteger)
1668                         return angle::FormatID::R8G8_UINT;
1669                     if (normalized)
1670                         return angle::FormatID::R8G8_UNORM;
1671                     return angle::FormatID::R8G8_USCALED;
1672                 case 3:
1673                     if (pureInteger)
1674                         return angle::FormatID::R8G8B8_UINT;
1675                     if (normalized)
1676                         return angle::FormatID::R8G8B8_UNORM;
1677                     return angle::FormatID::R8G8B8_USCALED;
1678                 case 4:
1679                     if (pureInteger)
1680                         return angle::FormatID::R8G8B8A8_UINT;
1681                     if (normalized)
1682                         return angle::FormatID::R8G8B8A8_UNORM;
1683                     return angle::FormatID::R8G8B8A8_USCALED;
1684                 default:
1685                     UNREACHABLE();
1686 #if !UNREACHABLE_IS_NORETURN
1687                     return angle::FormatID::NONE;
1688 #endif
1689             }
1690         case VertexAttribType::Short:
1691             switch (components)
1692             {
1693                 case 1:
1694                     if (pureInteger)
1695                         return angle::FormatID::R16_SINT;
1696                     if (normalized)
1697                         return angle::FormatID::R16_SNORM;
1698                     return angle::FormatID::R16_SSCALED;
1699                 case 2:
1700                     if (pureInteger)
1701                         return angle::FormatID::R16G16_SINT;
1702                     if (normalized)
1703                         return angle::FormatID::R16G16_SNORM;
1704                     return angle::FormatID::R16G16_SSCALED;
1705                 case 3:
1706                     if (pureInteger)
1707                         return angle::FormatID::R16G16B16_SINT;
1708                     if (normalized)
1709                         return angle::FormatID::R16G16B16_SNORM;
1710                     return angle::FormatID::R16G16B16_SSCALED;
1711                 case 4:
1712                     if (pureInteger)
1713                         return angle::FormatID::R16G16B16A16_SINT;
1714                     if (normalized)
1715                         return angle::FormatID::R16G16B16A16_SNORM;
1716                     return angle::FormatID::R16G16B16A16_SSCALED;
1717                 default:
1718                     UNREACHABLE();
1719 #if !UNREACHABLE_IS_NORETURN
1720                     return angle::FormatID::NONE;
1721 #endif
1722             }
1723         case VertexAttribType::UnsignedShort:
1724             switch (components)
1725             {
1726                 case 1:
1727                     if (pureInteger)
1728                         return angle::FormatID::R16_UINT;
1729                     if (normalized)
1730                         return angle::FormatID::R16_UNORM;
1731                     return angle::FormatID::R16_USCALED;
1732                 case 2:
1733                     if (pureInteger)
1734                         return angle::FormatID::R16G16_UINT;
1735                     if (normalized)
1736                         return angle::FormatID::R16G16_UNORM;
1737                     return angle::FormatID::R16G16_USCALED;
1738                 case 3:
1739                     if (pureInteger)
1740                         return angle::FormatID::R16G16B16_UINT;
1741                     if (normalized)
1742                         return angle::FormatID::R16G16B16_UNORM;
1743                     return angle::FormatID::R16G16B16_USCALED;
1744                 case 4:
1745                     if (pureInteger)
1746                         return angle::FormatID::R16G16B16A16_UINT;
1747                     if (normalized)
1748                         return angle::FormatID::R16G16B16A16_UNORM;
1749                     return angle::FormatID::R16G16B16A16_USCALED;
1750                 default:
1751                     UNREACHABLE();
1752 #if !UNREACHABLE_IS_NORETURN
1753                     return angle::FormatID::NONE;
1754 #endif
1755             }
1756         case VertexAttribType::Int:
1757             switch (components)
1758             {
1759                 case 1:
1760                     if (pureInteger)
1761                         return angle::FormatID::R32_SINT;
1762                     if (normalized)
1763                         return angle::FormatID::R32_SNORM;
1764                     return angle::FormatID::R32_SSCALED;
1765                 case 2:
1766                     if (pureInteger)
1767                         return angle::FormatID::R32G32_SINT;
1768                     if (normalized)
1769                         return angle::FormatID::R32G32_SNORM;
1770                     return angle::FormatID::R32G32_SSCALED;
1771                 case 3:
1772                     if (pureInteger)
1773                         return angle::FormatID::R32G32B32_SINT;
1774                     if (normalized)
1775                         return angle::FormatID::R32G32B32_SNORM;
1776                     return angle::FormatID::R32G32B32_SSCALED;
1777                 case 4:
1778                     if (pureInteger)
1779                         return angle::FormatID::R32G32B32A32_SINT;
1780                     if (normalized)
1781                         return angle::FormatID::R32G32B32A32_SNORM;
1782                     return angle::FormatID::R32G32B32A32_SSCALED;
1783                 default:
1784                     UNREACHABLE();
1785 #if !UNREACHABLE_IS_NORETURN
1786                     return angle::FormatID::NONE;
1787 #endif
1788             }
1789         case VertexAttribType::UnsignedInt:
1790             switch (components)
1791             {
1792                 case 1:
1793                     if (pureInteger)
1794                         return angle::FormatID::R32_UINT;
1795                     if (normalized)
1796                         return angle::FormatID::R32_UNORM;
1797                     return angle::FormatID::R32_USCALED;
1798                 case 2:
1799                     if (pureInteger)
1800                         return angle::FormatID::R32G32_UINT;
1801                     if (normalized)
1802                         return angle::FormatID::R32G32_UNORM;
1803                     return angle::FormatID::R32G32_USCALED;
1804                 case 3:
1805                     if (pureInteger)
1806                         return angle::FormatID::R32G32B32_UINT;
1807                     if (normalized)
1808                         return angle::FormatID::R32G32B32_UNORM;
1809                     return angle::FormatID::R32G32B32_USCALED;
1810                 case 4:
1811                     if (pureInteger)
1812                         return angle::FormatID::R32G32B32A32_UINT;
1813                     if (normalized)
1814                         return angle::FormatID::R32G32B32A32_UNORM;
1815                     return angle::FormatID::R32G32B32A32_USCALED;
1816                 default:
1817                     UNREACHABLE();
1818 #if !UNREACHABLE_IS_NORETURN
1819                     return angle::FormatID::NONE;
1820 #endif
1821             }
1822         case VertexAttribType::Float:
1823             switch (components)
1824             {
1825                 case 1:
1826                     return angle::FormatID::R32_FLOAT;
1827                 case 2:
1828                     return angle::FormatID::R32G32_FLOAT;
1829                 case 3:
1830                     return angle::FormatID::R32G32B32_FLOAT;
1831                 case 4:
1832                     return angle::FormatID::R32G32B32A32_FLOAT;
1833                 default:
1834                     UNREACHABLE();
1835 #if !UNREACHABLE_IS_NORETURN
1836                     return angle::FormatID::NONE;
1837 #endif
1838             }
1839         case VertexAttribType::HalfFloat:
1840         case VertexAttribType::HalfFloatOES:
1841             switch (components)
1842             {
1843                 case 1:
1844                     return angle::FormatID::R16_FLOAT;
1845                 case 2:
1846                     return angle::FormatID::R16G16_FLOAT;
1847                 case 3:
1848                     return angle::FormatID::R16G16B16_FLOAT;
1849                 case 4:
1850                     return angle::FormatID::R16G16B16A16_FLOAT;
1851                 default:
1852                     UNREACHABLE();
1853 #if !UNREACHABLE_IS_NORETURN
1854                     return angle::FormatID::NONE;
1855 #endif
1856             }
1857         case VertexAttribType::Fixed:
1858             switch (components)
1859             {
1860                 case 1:
1861                     return angle::FormatID::R32_FIXED;
1862                 case 2:
1863                     return angle::FormatID::R32G32_FIXED;
1864                 case 3:
1865                     return angle::FormatID::R32G32B32_FIXED;
1866                 case 4:
1867                     return angle::FormatID::R32G32B32A32_FIXED;
1868                 default:
1869                     UNREACHABLE();
1870 #if !UNREACHABLE_IS_NORETURN
1871                     return angle::FormatID::NONE;
1872 #endif
1873             }
1874         case VertexAttribType::Int2101010:
1875             if (pureInteger)
1876                 return angle::FormatID::R10G10B10A2_SINT;
1877             if (normalized)
1878                 return angle::FormatID::R10G10B10A2_SNORM;
1879             return angle::FormatID::R10G10B10A2_SSCALED;
1880         case VertexAttribType::UnsignedInt2101010:
1881             if (pureInteger)
1882                 return angle::FormatID::R10G10B10A2_UINT;
1883             if (normalized)
1884                 return angle::FormatID::R10G10B10A2_UNORM;
1885             return angle::FormatID::R10G10B10A2_USCALED;
1886         case VertexAttribType::Int1010102:
1887             switch (components)
1888             {
1889                 case 3:
1890                     if (pureInteger)
1891                         return angle::FormatID::X2R10G10B10_SINT_VERTEX;
1892                     if (normalized)
1893                         return angle::FormatID::X2R10G10B10_SNORM_VERTEX;
1894                     return angle::FormatID::X2R10G10B10_SSCALED_VERTEX;
1895                 case 4:
1896                     if (pureInteger)
1897                         return angle::FormatID::A2R10G10B10_SINT_VERTEX;
1898                     if (normalized)
1899                         return angle::FormatID::A2R10G10B10_SNORM_VERTEX;
1900                     return angle::FormatID::A2R10G10B10_SSCALED_VERTEX;
1901                 default:
1902                     UNREACHABLE();
1903 #if !UNREACHABLE_IS_NORETURN
1904                     return angle::FormatID::NONE;
1905 #endif
1906             }
1907         case VertexAttribType::UnsignedInt1010102:
1908             switch (components)
1909             {
1910                 case 3:
1911                     if (pureInteger)
1912                         return angle::FormatID::X2R10G10B10_UINT_VERTEX;
1913                     if (normalized)
1914                         return angle::FormatID::X2R10G10B10_UNORM_VERTEX;
1915                     return angle::FormatID::X2R10G10B10_USCALED_VERTEX;
1916 
1917                 case 4:
1918                     if (pureInteger)
1919                         return angle::FormatID::A2R10G10B10_UINT_VERTEX;
1920                     if (normalized)
1921                         return angle::FormatID::A2R10G10B10_UNORM_VERTEX;
1922                     return angle::FormatID::A2R10G10B10_USCALED_VERTEX;
1923                 default:
1924                     UNREACHABLE();
1925 #if !UNREACHABLE_IS_NORETURN
1926                     return angle::FormatID::NONE;
1927 #endif
1928             }
1929         default:
1930             UNREACHABLE();
1931 #if !UNREACHABLE_IS_NORETURN
1932             return angle::FormatID::NONE;
1933 #endif
1934     }
1935 }
1936 
GetVertexFormatID(const VertexAttribute & attrib,VertexAttribType currentValueType)1937 angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType)
1938 {
1939     if (!attrib.enabled)
1940     {
1941         return GetCurrentValueFormatID(currentValueType);
1942     }
1943     return attrib.format->id;
1944 }
1945 
GetCurrentValueFormatID(VertexAttribType currentValueType)1946 angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType)
1947 {
1948     switch (currentValueType)
1949     {
1950         case VertexAttribType::Float:
1951             return angle::FormatID::R32G32B32A32_FLOAT;
1952         case VertexAttribType::Int:
1953             return angle::FormatID::R32G32B32A32_SINT;
1954         case VertexAttribType::UnsignedInt:
1955             return angle::FormatID::R32G32B32A32_UINT;
1956         default:
1957             UNREACHABLE();
1958             return angle::FormatID::NONE;
1959     }
1960 }
1961 
GetVertexFormatFromID(angle::FormatID vertexFormatID)1962 const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
1963 {
1964     switch (vertexFormatID)
1965     {
1966         case angle::FormatID::R8_SSCALED:
1967         {
1968             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1969             return format;
1970         }
1971         case angle::FormatID::R8_SNORM:
1972         {
1973             static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1974             return format;
1975         }
1976         case angle::FormatID::R8G8_SSCALED:
1977         {
1978             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1979             return format;
1980         }
1981         case angle::FormatID::R8G8_SNORM:
1982         {
1983             static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1984             return format;
1985         }
1986         case angle::FormatID::R8G8B8_SSCALED:
1987         {
1988             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1989             return format;
1990         }
1991         case angle::FormatID::R8G8B8_SNORM:
1992         {
1993             static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1994             return format;
1995         }
1996         case angle::FormatID::R8G8B8A8_SSCALED:
1997         {
1998             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1999             return format;
2000         }
2001         case angle::FormatID::R8G8B8A8_SNORM:
2002         {
2003             static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
2004             return format;
2005         }
2006         case angle::FormatID::R8_USCALED:
2007         {
2008             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
2009             return format;
2010         }
2011         case angle::FormatID::R8_UNORM:
2012         {
2013             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
2014             return format;
2015         }
2016         case angle::FormatID::R8G8_USCALED:
2017         {
2018             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
2019             return format;
2020         }
2021         case angle::FormatID::R8G8_UNORM:
2022         {
2023             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
2024             return format;
2025         }
2026         case angle::FormatID::R8G8B8_USCALED:
2027         {
2028             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
2029             return format;
2030         }
2031         case angle::FormatID::R8G8B8_UNORM:
2032         {
2033             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
2034             return format;
2035         }
2036         case angle::FormatID::R8G8B8A8_USCALED:
2037         {
2038             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
2039             return format;
2040         }
2041         case angle::FormatID::R8G8B8A8_UNORM:
2042         {
2043             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
2044             return format;
2045         }
2046         case angle::FormatID::R16_SSCALED:
2047         {
2048             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
2049             return format;
2050         }
2051         case angle::FormatID::R16_SNORM:
2052         {
2053             static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
2054             return format;
2055         }
2056         case angle::FormatID::R16G16_SSCALED:
2057         {
2058             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
2059             return format;
2060         }
2061         case angle::FormatID::R16G16_SNORM:
2062         {
2063             static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
2064             return format;
2065         }
2066         case angle::FormatID::R16G16B16_SSCALED:
2067         {
2068             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
2069             return format;
2070         }
2071         case angle::FormatID::R16G16B16_SNORM:
2072         {
2073             static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
2074             return format;
2075         }
2076         case angle::FormatID::R16G16B16A16_SSCALED:
2077         {
2078             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
2079             return format;
2080         }
2081         case angle::FormatID::R16G16B16A16_SNORM:
2082         {
2083             static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
2084             return format;
2085         }
2086         case angle::FormatID::R16_USCALED:
2087         {
2088             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
2089             return format;
2090         }
2091         case angle::FormatID::R16_UNORM:
2092         {
2093             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
2094             return format;
2095         }
2096         case angle::FormatID::R16G16_USCALED:
2097         {
2098             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
2099             return format;
2100         }
2101         case angle::FormatID::R16G16_UNORM:
2102         {
2103             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
2104             return format;
2105         }
2106         case angle::FormatID::R16G16B16_USCALED:
2107         {
2108             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
2109             return format;
2110         }
2111         case angle::FormatID::R16G16B16_UNORM:
2112         {
2113             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
2114             return format;
2115         }
2116         case angle::FormatID::R16G16B16A16_USCALED:
2117         {
2118             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
2119             return format;
2120         }
2121         case angle::FormatID::R16G16B16A16_UNORM:
2122         {
2123             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
2124             return format;
2125         }
2126         case angle::FormatID::R32_SSCALED:
2127         {
2128             static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
2129             return format;
2130         }
2131         case angle::FormatID::R32_SNORM:
2132         {
2133             static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
2134             return format;
2135         }
2136         case angle::FormatID::R32G32_SSCALED:
2137         {
2138             static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
2139             return format;
2140         }
2141         case angle::FormatID::R32G32_SNORM:
2142         {
2143             static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
2144             return format;
2145         }
2146         case angle::FormatID::R32G32B32_SSCALED:
2147         {
2148             static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
2149             return format;
2150         }
2151         case angle::FormatID::R32G32B32_SNORM:
2152         {
2153             static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
2154             return format;
2155         }
2156         case angle::FormatID::R32G32B32A32_SSCALED:
2157         {
2158             static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
2159             return format;
2160         }
2161         case angle::FormatID::R32G32B32A32_SNORM:
2162         {
2163             static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
2164             return format;
2165         }
2166         case angle::FormatID::R32_USCALED:
2167         {
2168             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2169             return format;
2170         }
2171         case angle::FormatID::R32_UNORM:
2172         {
2173             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2174             return format;
2175         }
2176         case angle::FormatID::R32G32_USCALED:
2177         {
2178             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2179             return format;
2180         }
2181         case angle::FormatID::R32G32_UNORM:
2182         {
2183             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2184             return format;
2185         }
2186         case angle::FormatID::R32G32B32_USCALED:
2187         {
2188             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2189             return format;
2190         }
2191         case angle::FormatID::R32G32B32_UNORM:
2192         {
2193             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2194             return format;
2195         }
2196         case angle::FormatID::R32G32B32A32_USCALED:
2197         {
2198             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2199             return format;
2200         }
2201         case angle::FormatID::R32G32B32A32_UNORM:
2202         {
2203             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2204             return format;
2205         }
2206         case angle::FormatID::R8_SINT:
2207         {
2208             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2209             return format;
2210         }
2211         case angle::FormatID::R8G8_SINT:
2212         {
2213             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2214             return format;
2215         }
2216         case angle::FormatID::R8G8B8_SINT:
2217         {
2218             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2219             return format;
2220         }
2221         case angle::FormatID::R8G8B8A8_SINT:
2222         {
2223             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2224             return format;
2225         }
2226         case angle::FormatID::R8_UINT:
2227         {
2228             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2229             return format;
2230         }
2231         case angle::FormatID::R8G8_UINT:
2232         {
2233             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2234             return format;
2235         }
2236         case angle::FormatID::R8G8B8_UINT:
2237         {
2238             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2239             return format;
2240         }
2241         case angle::FormatID::R8G8B8A8_UINT:
2242         {
2243             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2244             return format;
2245         }
2246         case angle::FormatID::R16_SINT:
2247         {
2248             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2249             return format;
2250         }
2251         case angle::FormatID::R16G16_SINT:
2252         {
2253             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2254             return format;
2255         }
2256         case angle::FormatID::R16G16B16_SINT:
2257         {
2258             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2259             return format;
2260         }
2261         case angle::FormatID::R16G16B16A16_SINT:
2262         {
2263             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2264             return format;
2265         }
2266         case angle::FormatID::R16_UINT:
2267         {
2268             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2269             return format;
2270         }
2271         case angle::FormatID::R16G16_UINT:
2272         {
2273             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2274             return format;
2275         }
2276         case angle::FormatID::R16G16B16_UINT:
2277         {
2278             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2279             return format;
2280         }
2281         case angle::FormatID::R16G16B16A16_UINT:
2282         {
2283             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2284             return format;
2285         }
2286         case angle::FormatID::R32_SINT:
2287         {
2288             static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2289             return format;
2290         }
2291         case angle::FormatID::R32G32_SINT:
2292         {
2293             static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2294             return format;
2295         }
2296         case angle::FormatID::R32G32B32_SINT:
2297         {
2298             static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2299             return format;
2300         }
2301         case angle::FormatID::R32G32B32A32_SINT:
2302         {
2303             static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2304             return format;
2305         }
2306         case angle::FormatID::R32_UINT:
2307         {
2308             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2309             return format;
2310         }
2311         case angle::FormatID::R32G32_UINT:
2312         {
2313             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2314             return format;
2315         }
2316         case angle::FormatID::R32G32B32_UINT:
2317         {
2318             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2319             return format;
2320         }
2321         case angle::FormatID::R32G32B32A32_UINT:
2322         {
2323             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2324             return format;
2325         }
2326         case angle::FormatID::R32_FIXED:
2327         {
2328             static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2329             return format;
2330         }
2331         case angle::FormatID::R32G32_FIXED:
2332         {
2333             static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2334             return format;
2335         }
2336         case angle::FormatID::R32G32B32_FIXED:
2337         {
2338             static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2339             return format;
2340         }
2341         case angle::FormatID::R32G32B32A32_FIXED:
2342         {
2343             static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2344             return format;
2345         }
2346         case angle::FormatID::R16_FLOAT:
2347         {
2348             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2349             return format;
2350         }
2351         case angle::FormatID::R16G16_FLOAT:
2352         {
2353             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2354             return format;
2355         }
2356         case angle::FormatID::R16G16B16_FLOAT:
2357         {
2358             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2359             return format;
2360         }
2361         case angle::FormatID::R16G16B16A16_FLOAT:
2362         {
2363             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2364             return format;
2365         }
2366         case angle::FormatID::R32_FLOAT:
2367         {
2368             static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2369             return format;
2370         }
2371         case angle::FormatID::R32G32_FLOAT:
2372         {
2373             static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2374             return format;
2375         }
2376         case angle::FormatID::R32G32B32_FLOAT:
2377         {
2378             static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2379             return format;
2380         }
2381         case angle::FormatID::R32G32B32A32_FLOAT:
2382         {
2383             static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2384             return format;
2385         }
2386         case angle::FormatID::R10G10B10A2_SSCALED:
2387         {
2388             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2389             return format;
2390         }
2391         case angle::FormatID::R10G10B10A2_USCALED:
2392         {
2393             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2394             return format;
2395         }
2396         case angle::FormatID::R10G10B10A2_SNORM:
2397         {
2398             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2399             return format;
2400         }
2401         case angle::FormatID::R10G10B10A2_UNORM:
2402         {
2403             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2404             return format;
2405         }
2406         case angle::FormatID::R10G10B10A2_SINT:
2407         {
2408             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2409             return format;
2410         }
2411         case angle::FormatID::R10G10B10A2_UINT:
2412         {
2413             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2414             return format;
2415         }
2416         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2417         {
2418             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2419             return format;
2420         }
2421         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2422         {
2423             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2424             return format;
2425         }
2426         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
2427         {
2428             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2429             return format;
2430         }
2431         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
2432         {
2433             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2434             return format;
2435         }
2436         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2437         {
2438             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2439             return format;
2440         }
2441         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2442         {
2443             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2444             return format;
2445         }
2446         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
2447         {
2448             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2449             return format;
2450         }
2451         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
2452         {
2453             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2454             return format;
2455         }
2456         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
2457         {
2458             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2459             return format;
2460         }
2461         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
2462         {
2463             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2464             return format;
2465         }
2466         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
2467         {
2468             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2469             return format;
2470         }
2471         default:
2472         {
2473             static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2474             return format;
2475         }
2476     }
2477 }
2478 
GetVertexFormatSize(angle::FormatID vertexFormatID)2479 size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
2480 {
2481     switch (vertexFormatID)
2482     {
2483         case angle::FormatID::R8_SSCALED:
2484         case angle::FormatID::R8_SNORM:
2485         case angle::FormatID::R8_USCALED:
2486         case angle::FormatID::R8_UNORM:
2487         case angle::FormatID::R8_SINT:
2488         case angle::FormatID::R8_UINT:
2489             return 1;
2490 
2491         case angle::FormatID::R8G8_SSCALED:
2492         case angle::FormatID::R8G8_SNORM:
2493         case angle::FormatID::R8G8_USCALED:
2494         case angle::FormatID::R8G8_UNORM:
2495         case angle::FormatID::R8G8_SINT:
2496         case angle::FormatID::R8G8_UINT:
2497         case angle::FormatID::R16_SSCALED:
2498         case angle::FormatID::R16_SNORM:
2499         case angle::FormatID::R16_USCALED:
2500         case angle::FormatID::R16_UNORM:
2501         case angle::FormatID::R16_SINT:
2502         case angle::FormatID::R16_UINT:
2503         case angle::FormatID::R16_FLOAT:
2504             return 2;
2505 
2506         case angle::FormatID::R8G8B8_SSCALED:
2507         case angle::FormatID::R8G8B8_SNORM:
2508         case angle::FormatID::R8G8B8_USCALED:
2509         case angle::FormatID::R8G8B8_UNORM:
2510         case angle::FormatID::R8G8B8_SINT:
2511         case angle::FormatID::R8G8B8_UINT:
2512             return 3;
2513 
2514         case angle::FormatID::R8G8B8A8_SSCALED:
2515         case angle::FormatID::R8G8B8A8_SNORM:
2516         case angle::FormatID::R8G8B8A8_USCALED:
2517         case angle::FormatID::R8G8B8A8_UNORM:
2518         case angle::FormatID::R8G8B8A8_SINT:
2519         case angle::FormatID::R8G8B8A8_UINT:
2520         case angle::FormatID::R16G16_SSCALED:
2521         case angle::FormatID::R16G16_SNORM:
2522         case angle::FormatID::R16G16_USCALED:
2523         case angle::FormatID::R16G16_UNORM:
2524         case angle::FormatID::R16G16_SINT:
2525         case angle::FormatID::R16G16_UINT:
2526         case angle::FormatID::R32_SSCALED:
2527         case angle::FormatID::R32_SNORM:
2528         case angle::FormatID::R32_USCALED:
2529         case angle::FormatID::R32_UNORM:
2530         case angle::FormatID::R32_SINT:
2531         case angle::FormatID::R32_UINT:
2532         case angle::FormatID::R16G16_FLOAT:
2533         case angle::FormatID::R32_FIXED:
2534         case angle::FormatID::R32_FLOAT:
2535         case angle::FormatID::R10G10B10A2_SSCALED:
2536         case angle::FormatID::R10G10B10A2_USCALED:
2537         case angle::FormatID::R10G10B10A2_SNORM:
2538         case angle::FormatID::R10G10B10A2_UNORM:
2539         case angle::FormatID::R10G10B10A2_SINT:
2540         case angle::FormatID::R10G10B10A2_UINT:
2541         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2542         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2543         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2544         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2545         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
2546         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
2547         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
2548         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
2549         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
2550         case angle::FormatID::X2R10G10B10_UINT_VERTEX:
2551         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
2552         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
2553             return 4;
2554 
2555         case angle::FormatID::R16G16B16_SSCALED:
2556         case angle::FormatID::R16G16B16_SNORM:
2557         case angle::FormatID::R16G16B16_USCALED:
2558         case angle::FormatID::R16G16B16_UNORM:
2559         case angle::FormatID::R16G16B16_SINT:
2560         case angle::FormatID::R16G16B16_UINT:
2561         case angle::FormatID::R16G16B16_FLOAT:
2562             return 6;
2563 
2564         case angle::FormatID::R16G16B16A16_SSCALED:
2565         case angle::FormatID::R16G16B16A16_SNORM:
2566         case angle::FormatID::R16G16B16A16_USCALED:
2567         case angle::FormatID::R16G16B16A16_UNORM:
2568         case angle::FormatID::R16G16B16A16_SINT:
2569         case angle::FormatID::R16G16B16A16_UINT:
2570         case angle::FormatID::R32G32_SSCALED:
2571         case angle::FormatID::R32G32_SNORM:
2572         case angle::FormatID::R32G32_USCALED:
2573         case angle::FormatID::R32G32_UNORM:
2574         case angle::FormatID::R32G32_SINT:
2575         case angle::FormatID::R32G32_UINT:
2576         case angle::FormatID::R16G16B16A16_FLOAT:
2577         case angle::FormatID::R32G32_FIXED:
2578         case angle::FormatID::R32G32_FLOAT:
2579             return 8;
2580 
2581         case angle::FormatID::R32G32B32_SSCALED:
2582         case angle::FormatID::R32G32B32_SNORM:
2583         case angle::FormatID::R32G32B32_USCALED:
2584         case angle::FormatID::R32G32B32_UNORM:
2585         case angle::FormatID::R32G32B32_SINT:
2586         case angle::FormatID::R32G32B32_UINT:
2587         case angle::FormatID::R32G32B32_FIXED:
2588         case angle::FormatID::R32G32B32_FLOAT:
2589             return 12;
2590 
2591         case angle::FormatID::R32G32B32A32_SSCALED:
2592         case angle::FormatID::R32G32B32A32_SNORM:
2593         case angle::FormatID::R32G32B32A32_USCALED:
2594         case angle::FormatID::R32G32B32A32_UNORM:
2595         case angle::FormatID::R32G32B32A32_SINT:
2596         case angle::FormatID::R32G32B32A32_UINT:
2597         case angle::FormatID::R32G32B32A32_FIXED:
2598         case angle::FormatID::R32G32B32A32_FLOAT:
2599             return 16;
2600 
2601         case angle::FormatID::NONE:
2602         default:
2603             UNREACHABLE();
2604 #if !UNREACHABLE_IS_NORETURN
2605             return 0;
2606 #endif
2607     }
2608 }
2609 
ValidES3InternalFormat(GLenum internalFormat)2610 bool ValidES3InternalFormat(GLenum internalFormat)
2611 {
2612     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2613     return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2614 }
2615 
VertexFormat(GLenum typeIn,GLboolean normalizedIn,GLuint componentsIn,bool pureIntegerIn)2616 VertexFormat::VertexFormat(GLenum typeIn,
2617                            GLboolean normalizedIn,
2618                            GLuint componentsIn,
2619                            bool pureIntegerIn)
2620     : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
2621 {
2622     // float -> !normalized
2623     ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2624            normalized == GL_FALSE);
2625 }
2626 }  // namespace gl
2627