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