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