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