xref: /aosp_15_r20/external/angle/src/libANGLE/formatutils.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
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 || internalformat == GL_BGRA8_SRGB_ANGLEX)
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 || internalformat == GL_RGBX8_SRGB_ANGLEX)
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 || internalformat == GL_BGRX8_SRGB_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/42261549 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, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, 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, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, 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, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, 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, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, RequireESOrExt<2, 0, &Extensions::framebufferObjectOES>, RequireES<2, 0>);
1112     AddRGBAFormat(&map, GL_RGBA8,             true,  8,  8,  8,  8, 0, GL_RGBA,         GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, false, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, 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     AddRGBAXFormat(&map, GL_RGBX8_SRGB_ANGLEX,      true,   FB< 8,  8,  8,  0, 8, 0>(), GL_RGB,          GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, true, AlwaysSupported,                                   AlwaysSupported, AlwaysSupported,                                   AlwaysSupported,                               NeverSupported);
1161 
1162     // Special format to emulate BGR8 with BGRA8 within ANGLE.
1163     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);
1164     AddRGBAXFormat(&map, GL_BGRX8_SRGB_ANGLEX,      true,  FB< 8,  8,  8,  0, 8, 0>(), GL_BGRA_EXT,     GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, true, NeverSupported,                                    AlwaysSupported,  NeverSupported,                                    NeverSupported,                                NeverSupported);
1165 
1166     // 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.
1167     //                 | Internal format     |sized| R | G | B | A |S | Format         | Type                             | Component type        | SRGB | Texture supported                                                                            | Filterable     | Texture attachment                               | Renderbuffer                                   | Blend
1168     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>);
1169 
1170     // Floating point formats
1171     //                 | Internal format |sized| R | G | B | A |S | Format | Type             | Component type | SRGB | Texture supported         | Filterable                                    | Texture attachment                          | Renderbuffer                            | Blend
1172     // It's not possible to have two entries per sized format.
1173     // E.g. for GL_RG16F, one with GL_HALF_FLOAT type and the other with GL_HALF_FLOAT_OES type.
1174     // So, GL_HALF_FLOAT type formats conditions are merged with GL_HALF_FLOAT_OES type conditions.
1175     AddRGBAFormat(&map, GL_R16F,          true, 16,  0,  0,  0, 0, GL_RED,  GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatRGSupport,    SizedHalfFloatFilterSupport,                    SizedHalfFloatRGTextureAttachmentSupport,     SizedHalfFloatRGRenderbufferSupport,       SizedHalfFloatRGRenderbufferSupport);
1176     AddRGBAFormat(&map, GL_RG16F,         true, 16, 16,  0,  0, 0, GL_RG,   GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatRGSupport,    SizedHalfFloatFilterSupport,                    SizedHalfFloatRGTextureAttachmentSupport,     SizedHalfFloatRGRenderbufferSupport,       SizedHalfFloatRGRenderbufferSupport);
1177     AddRGBAFormat(&map, GL_RGB16F,        true, 16, 16, 16,  0, 0, GL_RGB,  GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatSupport,      SizedHalfFloatFilterSupport,                    SizedHalfFloatRGBTextureAttachmentSupport,    SizedHalfFloatRGBRenderbufferSupport,      SizedHalfFloatRGBRenderbufferSupport);
1178     AddRGBAFormat(&map, GL_RGBA16F,       true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT,     GL_FLOAT,        false, SizedHalfFloatSupport,      SizedHalfFloatFilterSupport,                    SizedHalfFloatRGBATextureAttachmentSupport,   SizedHalfFloatRGBARenderbufferSupport,     SizedHalfFloatRGBARenderbufferSupport);
1179     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);
1180     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);
1181     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);
1182     AddRGBAFormat(&map, GL_RGBA32F,       true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT,          GL_FLOAT,        false, SizedFloatRGBASupport,      RequireExt<&Extensions::textureFloatLinearOES>, SizedFloatRGBARenderableSupport,              SizedFloatRGBARenderableSupport,           Float32BlendableSupport);
1183 
1184     // ANGLE Depth stencil formats
1185     //                         | Internal format         |sized| D |S | X | Format            | Type                             | Component type        | Texture supported                                                                            | Filterable                                                                             | Texture attachment                                                                           | Renderbuffer                                                                                              | Blend
1186     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);
1187     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);
1188     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);
1189     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);
1190     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);
1191     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);
1192     // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
1193 
1194     // Luminance alpha formats
1195     //                | Internal format           |sized| L | A | Format            | Type             | Component type        | Texture supported                                                           | Filterable                                     | Texture attachment | Renderbuffer | Blend
1196     AddLUMAFormat(&map, GL_ALPHA8_EXT,             true,  0,  8, GL_ALPHA,           GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported,                         NeverSupported,      NeverSupported, NeverSupported);
1197     AddLUMAFormat(&map, GL_LUMINANCE8_EXT,         true,  8,  0, GL_LUMINANCE,       GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported,                         NeverSupported,      NeverSupported, NeverSupported);
1198     AddLUMAFormat(&map, GL_LUMINANCE4_ALPHA4_OES,  true,  8,  8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::requiredInternalformatOES>,                              AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1199     AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT,  true,  8,  8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::textureStorageEXT, &Extensions::requiredInternalformatOES>, AlwaysSupported,                         NeverSupported,      NeverSupported, NeverSupported);
1200     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);
1201     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);
1202     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);
1203     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);
1204     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);
1205     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);
1206 
1207     // Compressed formats, From ES 3.0.1 spec, table 3.16
1208     //                       | Internal format                             |W |H |D | BS |CC| SRGB | Texture supported                                                          | Filterable     | Texture attachment | Renderbuffer  | Blend
1209     AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC,                        4, 4, 1,  64, 1, false, ETC2EACSupport<&Extensions::compressedEACR11UnsignedTextureOES>,              AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1210     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC,                 4, 4, 1,  64, 1, false, ETC2EACSupport<&Extensions::compressedEACR11SignedTextureOES>,                AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1211     AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC,                       4, 4, 1, 128, 2, false, ETC2EACSupport<&Extensions::compressedEACRG11UnsignedTextureOES>,             AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1212     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC,                4, 4, 1, 128, 2, false, ETC2EACSupport<&Extensions::compressedEACRG11SignedTextureOES>,               AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1213     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2,                      4, 4, 1,  64, 3, false, ETC2EACSupport<&Extensions::compressedETC2RGB8TextureOES>,                    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1214     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2,                     4, 4, 1,  64, 3, true,  ETC2EACSupport<&Extensions::compressedETC2SRGB8TextureOES>,                   AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1215     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,  4, 4, 1,  64, 4, false, ETC2EACSupport<&Extensions::compressedETC2PunchthroughARGBA8TextureOES>,      AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1216     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 1,  64, 4, true,  ETC2EACSupport<&Extensions::compressedETC2PunchthroughASRGB8AlphaTextureOES>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1217     AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC,                 4, 4, 1, 128, 4, false, ETC2EACSupport<&Extensions::compressedETC2RGBA8TextureOES>,                   AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1218     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,          4, 4, 1, 128, 4, true,  ETC2EACSupport<&Extensions::compressedETC2SRGB8Alpha8TextureOES>,             AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1219 
1220     // From GL_EXT_texture_compression_dxt1
1221     //                       | Internal format                   |W |H |D | BS |CC| SRGB | Texture supported                                    | Filterable     | Texture attachment | Renderbuffer  | Blend
1222     AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,    4, 4, 1,  64, 3, false, RequireExt<&Extensions::textureCompressionDxt1EXT>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1223     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,   4, 4, 1,  64, 4, false, RequireExt<&Extensions::textureCompressionDxt1EXT>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1224 
1225     // From GL_ANGLE_texture_compression_dxt3
1226     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionDxt3ANGLE>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1227 
1228     // From GL_ANGLE_texture_compression_dxt5
1229     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionDxt5ANGLE>,       AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1230 
1231     // From GL_OES_compressed_ETC1_RGB8_texture
1232     AddCompressedFormat(&map, GL_ETC1_RGB8_OES,                   4, 4, 1,  64, 3, false, RequireExt<&Extensions::compressedETC1RGB8TextureOES>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1233 
1234     // From GL_EXT_texture_compression_s3tc_srgb
1235     //                       | Internal format                       |W |H |D | BS |CC|SRGB | Texture supported                                 | Filterable     | Texture attachment | Renderbuffer  | Blend
1236     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,       4, 4, 1,  64, 3, true, RequireExt<&Extensions::textureCompressionS3tcSrgbEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1237     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 1,  64, 4, true, RequireExt<&Extensions::textureCompressionS3tcSrgbEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1238     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 1, 128, 4, true, RequireExt<&Extensions::textureCompressionS3tcSrgbEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1239     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 1, 128, 4, true, RequireExt<&Extensions::textureCompressionS3tcSrgbEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1240 
1241     // From GL_KHR_texture_compression_astc_ldr and KHR_texture_compression_astc_hdr and GL_OES_texture_compression_astc
1242     //                       | Internal format                          | W | H |D | BS |CC| SRGB | Texture supported                                    | Filterable     | Texture attachment | Renderbuffer  | Blend
1243     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR,            4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1244     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR,            5,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1245     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR,            5,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1246     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR,            6,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1247     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR,            6,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1248     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR,            8,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1249     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR,            8,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1250     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR,            8,  8, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1251     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR,          10,  5, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1252     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR,          10,  6, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1253     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR,          10,  8, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1254     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR,         10, 10, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1255     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR,         12, 10, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1256     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR,         12, 12, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1257 
1258     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,    4,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1259     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,    5,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1260     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,    5,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1261     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,    6,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1262     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,    6,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1263     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,    8,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1264     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,    8,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1265     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,    8,  8, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1266     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,  10,  5, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1267     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,  10,  6, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1268     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,  10,  8, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1269     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1270     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1271     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcLdrKHR>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1272 
1273     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_3x3x3_OES,          3,  3, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1274     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x3x3_OES,          4,  3, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1275     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4x3_OES,          4,  4, 3, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1276     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4x4_OES,          4,  4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1277     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4x4_OES,          5,  4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1278     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5x4_OES,          5,  5, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1279     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5x5_OES,          5,  5, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1280     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5x5_OES,          6,  5, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1281     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6x5_OES,          6,  6, 5, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1282     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6x6_OES,          6,  6, 6, 128, 4, false, RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1283 
1284     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES,  3,  3, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1285     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES,  4,  3, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1286     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES,  4,  4, 3, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1287     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES,  4,  4, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1288     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES,  5,  4, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1289     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES,  5,  5, 4, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1290     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES,  5,  5, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1291     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES,  6,  5, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1292     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES,  6,  6, 5, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1293     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES,  6,  6, 6, 128, 4, true,  RequireExt<&Extensions::textureCompressionAstcOES>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1294 
1295     // From EXT_texture_compression_rgtc
1296     //                       | Internal format                        | W | H |D | BS |CC| SRGB | Texture supported                              | Filterable     | Texture attachment | Renderbuffer  | Blend
1297     AddCompressedFormat(&map, GL_COMPRESSED_RED_RGTC1_EXT,              4,  4, 1,  64, 1, false, RequireExt<&Extensions::textureCompressionRgtcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1298     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,       4,  4, 1,  64, 1, false, RequireExt<&Extensions::textureCompressionRgtcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1299     AddCompressedFormat(&map, GL_COMPRESSED_RED_GREEN_RGTC2_EXT,        4,  4, 1, 128, 2, false, RequireExt<&Extensions::textureCompressionRgtcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1300     AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, 4,  4, 1, 128, 2, false, RequireExt<&Extensions::textureCompressionRgtcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1301 
1302     // From EXT_texture_compression_bptc
1303     //                       | Internal format                         | W | H |D | BS |CC| SRGB | Texture supported                              | Filterable     | Texture attachment | Renderbuffer  | Blend
1304     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,         4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBptcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1305     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,   4,  4, 1, 128, 4, true,  RequireExt<&Extensions::textureCompressionBptcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1306     AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,   4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBptcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1307     AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4,  4, 1, 128, 4, false, RequireExt<&Extensions::textureCompressionBptcEXT>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1308 
1309     // Paletted formats
1310     //                      | Internal format       |    | PS | Format | CC | Texture supported | Filterable     | Texture attachment | Renderbuffer  | Blend
1311     AddPalettedFormat(&map, GL_PALETTE4_RGB8_OES,      4,   3, GL_RGB,    3, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1312     AddPalettedFormat(&map, GL_PALETTE4_RGBA8_OES,     4,   4, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1313     AddPalettedFormat(&map, GL_PALETTE4_R5_G6_B5_OES,  4,   2, GL_RGB,    3, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1314     AddPalettedFormat(&map, GL_PALETTE4_RGBA4_OES,     4,   2, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1315     AddPalettedFormat(&map, GL_PALETTE4_RGB5_A1_OES,   4,   2, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1316     AddPalettedFormat(&map, GL_PALETTE8_RGB8_OES,      8,   3, GL_RGB,    3, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1317     AddPalettedFormat(&map, GL_PALETTE8_RGBA8_OES,     8,   4, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1318     AddPalettedFormat(&map, GL_PALETTE8_R5_G6_B5_OES,  8,   2, GL_RGB,    3, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1319     AddPalettedFormat(&map, GL_PALETTE8_RGBA4_OES,     8,   2, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1320     AddPalettedFormat(&map, GL_PALETTE8_RGB5_A1_OES,   8,   2, GL_RGBA,   4, RequireES1,         AlwaysSupported, NeverSupported,     NeverSupported, NeverSupported);
1321 
1322     // From GL_IMG_texture_compression_pvrtc
1323     //                       | Internal format                       | W | H | D | BS |CC| SRGB | Texture supported                                 | Filterable     | Texture attachment | Renderbuffer  | Blend
1324     AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,      4,  4,  1,  64,  3, false, RequireExt<&Extensions::textureCompressionPvrtcIMG>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1325     AddCompressedFormat(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,      8,  4,  1,  64,  3, false, RequireExt<&Extensions::textureCompressionPvrtcIMG>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1326     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,     4,  4,  1,  64,  4, false, RequireExt<&Extensions::textureCompressionPvrtcIMG>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1327     AddCompressedFormat(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,     8,  4,  1,  64,  4, false, RequireExt<&Extensions::textureCompressionPvrtcIMG>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1328 
1329     // From GL_EXT_pvrtc_sRGB
1330     //                       | Internal format                             | W | H | D | BS |CC| SRGB | Texture supported                                                                               | Filterable     | Texture attachment | Renderbuffer  | Blend
1331     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT,           8,  4,  1,  64,  3, true, RequireExtAndExt<&Extensions::textureCompressionPvrtcIMG, &Extensions::pvrtcSRGBEXT>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1332     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT,           4,  4,  1,  64,  3, true, RequireExtAndExt<&Extensions::textureCompressionPvrtcIMG, &Extensions::pvrtcSRGBEXT>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1333     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT,     8,  4,  1,  64,  4, true, RequireExtAndExt<&Extensions::textureCompressionPvrtcIMG, &Extensions::pvrtcSRGBEXT>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1334     AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT,     4,  4,  1,  64,  4, true, RequireExtAndExt<&Extensions::textureCompressionPvrtcIMG, &Extensions::pvrtcSRGBEXT>,    AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1335 
1336     // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
1337     // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
1338     // - All other stencil formats (all depth-stencil) are either float or normalized
1339     // - It affects only validation of internalformat in RenderbufferStorageMultisample.
1340     //                         | Internal format  |sized|D |S |X | Format          | Type            | Component type        | Texture supported                                    | Filterable    | Texture attachment                                   | Renderbuffer   | Blend
1341     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);
1342 
1343     // From GL_ANGLE_lossy_etc_decode
1344     //                       | Internal format                                                |W |H |D |BS |CC| SRGB | Texture supported                      | Filterable     | Texture attachment | Renderbuffer  | Blend
1345     AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE,                                 4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyEtcDecodeANGLE>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1346     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE,                      4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyEtcDecodeANGLE>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1347     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE,                     4, 4, 1, 64, 3, true,  RequireExt<&Extensions::lossyEtcDecodeANGLE>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1348     AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE,  4, 4, 1, 64, 3, false, RequireExt<&Extensions::lossyEtcDecodeANGLE>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1349     AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 1, 64, 3, true,  RequireExt<&Extensions::lossyEtcDecodeANGLE>, AlwaysSupported, NeverSupported,      NeverSupported, NeverSupported);
1350 
1351     // From GL_EXT_texture_norm16
1352     //                 | Internal format    |sized| R | G | B | A |S | Format | Type             | Component type        | SRGB | Texture supported                        | Filterable     | Texture attachment                                                          | Renderbuffer                                                                | Blend
1353     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>);
1354     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>);
1355     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>);
1356     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>);
1357     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);
1358     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);
1359     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>);
1360     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>);
1361 
1362     // From EXT_texture_sRGB_R8
1363     //                 | Internal format    |sized| R | G | B | A |S | Format | Type             | Component type        | SRGB | Texture supported                     | Filterable     | Texture attachment                    | Renderbuffer                          | Blend
1364     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);
1365 
1366     // From EXT_texture_sRGB_RG8
1367     //                 | Internal format    |sized| R | G | B | A |S | Format | Type             | Component type        | SRGB | Texture supported                     | Filterable     | Texture attachment                    | Renderbuffer                          | Blend
1368     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);
1369 
1370     // From GL_OES_required_internalformat
1371     // The |shared| bit shouldn't be 2. But given this hits assertion when bits
1372     // are checked, it's fine to have this bit set as 2 as a workaround.
1373     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, RequireExtAndExt<&Extensions::textureType2101010REVEXT,&Extensions::requiredInternalformatOES>, NeverSupported,  NeverSupported, NeverSupported, NeverSupported);
1374 
1375     // Unsized formats
1376     //                  | Internal format  |sized |    R | G | B | A |S |X   | Format           | Type                          | Component type        | SRGB | Texture supported                                  | Filterable     | Texture attachment                               | Renderbuffer  | Blend
1377     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);
1378     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);
1379     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);
1380     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);
1381     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);
1382     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);
1383     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);
1384     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);
1385     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);
1386     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);
1387     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);
1388     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);
1389     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);
1390     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);
1391     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);
1392     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);
1393     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);
1394     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);
1395     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);
1396     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);
1397     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);
1398     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);
1399     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);
1400     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);
1401 
1402     // Unsized integer formats
1403     //                 |Internal format |sized | R | G | B | A |S | Format         | Type                          | Component type | SRGB | Texture supported | Filterable    | Texture attachment | Renderbuffer  | Blend
1404     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);
1405     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);
1406     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);
1407     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);
1408     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);
1409     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);
1410     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);
1411     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);
1412     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);
1413     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);
1414     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);
1415     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);
1416     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);
1417     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);
1418     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);
1419     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);
1420     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);
1421     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);
1422     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);
1423     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);
1424     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);
1425     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);
1426     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);
1427     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);
1428     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);
1429 
1430     // Unsized floating point formats
1431     //                 |Internal format |sized | R | G | B | A |S | Format | Type                           | Comp    | SRGB | Texture supported                                                         | Filterable                                     | Texture attachment                             | Renderbuffer  | Blend
1432     AddRGBAFormat(&map, GL_RED,          false, 16,  0,  0,  0, 0, GL_RED,  GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1433     AddRGBAFormat(&map, GL_RG,           false, 16, 16,  0,  0, 0, GL_RG,   GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1434     AddRGBAFormat(&map, GL_RGB,          false, 16, 16, 16,  0, 0, GL_RGB,  GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1435     AddRGBAFormat(&map, GL_RGBA,         false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT,                   GL_FLOAT, false, NeverSupported,                                                             NeverSupported,                                  NeverSupported,                                  NeverSupported, NeverSupported);
1436     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);
1437     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);
1438     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);
1439     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);
1440     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);
1441     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);
1442     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);
1443     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);
1444     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);
1445     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);
1446 
1447     // Unsized luminance alpha formats
1448     //                 | Internal format   |sized | L | A | Format            | Type             | Component type        | Texture supported                        | Filterable                                     | Texture attachment | Renderbuffer  | Blend
1449     AddLUMAFormat(&map, GL_ALPHA,           false,  0,  8, GL_ALPHA,           GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1450     AddLUMAFormat(&map, GL_LUMINANCE,       false,  8,  0, GL_LUMINANCE,       GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1451     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false,  8,  8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE,  GL_UNSIGNED_NORMALIZED, AlwaysSupported,                           AlwaysSupported,                                 NeverSupported,      NeverSupported, NeverSupported);
1452     AddLUMAFormat(&map, GL_ALPHA,           false,  0, 16, GL_ALPHA,           GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExt<&Extensions::textureHalfFloatOES>, RequireExt<&Extensions::textureHalfFloatLinearOES>, NeverSupported,      NeverSupported, NeverSupported);
1453     AddLUMAFormat(&map, GL_LUMINANCE,       false, 16,  0, GL_LUMINANCE,       GL_HALF_FLOAT_OES, GL_FLOAT,               RequireExt<&Extensions::textureHalfFloatOES>, RequireExt<&Extensions::textureHalfFloatLinearOES>, NeverSupported,      NeverSupported, NeverSupported);
1454     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);
1455     AddLUMAFormat(&map, GL_ALPHA,           false,  0, 32, GL_ALPHA,           GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1456     AddLUMAFormat(&map, GL_LUMINANCE,       false, 32,  0, GL_LUMINANCE,       GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1457     AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT,          GL_FLOAT,               RequireExt<&Extensions::textureFloatOES>,  RequireExt<&Extensions::textureFloatLinearOES>,  NeverSupported,      NeverSupported, NeverSupported);
1458 
1459     // Unsized depth stencil formats
1460     //                         | Internal format   |sized | D |S | X | Format            | Type                             | Component type        | Texture supported                                       | Filterable     | Texture attachment                                                                  | Renderbuffer                                                                       | Blend
1461     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>);
1462     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>);
1463     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>);
1464     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>);
1465     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>);
1466     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>);
1467     AddDepthStencilFormat(&map, GL_STENCIL_INDEX,   false,  0, 8,  0, GL_STENCIL_INDEX,   GL_UNSIGNED_BYTE,                  GL_UNSIGNED_NORMALIZED, NeverSupported,                                           NeverSupported , NeverSupported,                                                                       NeverSupported,                                                                       NeverSupported);
1468 
1469     // Non-standard YUV formats
1470     //                 | Internal format                             | sized | Cr | Y | Cb | A | S | Format                              | Type            | Comp                  | SRGB | Texture supported                                       | Filterable                                              | Texture attachment                                      | Renderbuffer  | Blend
1471     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);
1472     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);
1473 
1474     // clang-format on
1475 
1476     return map;
1477 }
1478 
GetInternalFormatMap()1479 const InternalFormatInfoMap &GetInternalFormatMap()
1480 {
1481     static const angle::base::NoDestructor<InternalFormatInfoMap> formatMap(
1482         BuildInternalFormatInfoMap());
1483     return *formatMap;
1484 }
1485 
GetAndroidHardwareBufferFormatFromChannelSizes(const egl::AttributeMap & attribMap)1486 int GetAndroidHardwareBufferFormatFromChannelSizes(const egl::AttributeMap &attribMap)
1487 {
1488     // Retrieve channel size from attribute map. The default value should be 0, per spec.
1489     GLuint redSize   = static_cast<GLuint>(attribMap.getAsInt(EGL_RED_SIZE, 0));
1490     GLuint greenSize = static_cast<GLuint>(attribMap.getAsInt(EGL_GREEN_SIZE, 0));
1491     GLuint blueSize  = static_cast<GLuint>(attribMap.getAsInt(EGL_BLUE_SIZE, 0));
1492     GLuint alphaSize = static_cast<GLuint>(attribMap.getAsInt(EGL_ALPHA_SIZE, 0));
1493 
1494     GLenum glInternalFormat = 0;
1495     for (GLenum sizedInternalFormat : angle::android::kSupportedSizedInternalFormats)
1496     {
1497         const gl::InternalFormat &internalFormat = GetSizedInternalFormatInfo(sizedInternalFormat);
1498         ASSERT(internalFormat.internalFormat != GL_NONE && internalFormat.sized);
1499 
1500         if (internalFormat.isChannelSizeCompatible(redSize, greenSize, blueSize, alphaSize))
1501         {
1502             glInternalFormat = sizedInternalFormat;
1503             break;
1504         }
1505     }
1506 
1507     return (glInternalFormat != 0)
1508                ? angle::android::GLInternalFormatToNativePixelFormat(glInternalFormat)
1509                : 0;
1510 }
1511 
GetConfigColorBufferFormat(const egl::Config * config)1512 GLenum GetConfigColorBufferFormat(const egl::Config *config)
1513 {
1514     GLenum componentType = GL_NONE;
1515     switch (config->colorComponentType)
1516     {
1517         case EGL_COLOR_COMPONENT_TYPE_FIXED_EXT:
1518             componentType = GL_UNSIGNED_NORMALIZED;
1519             break;
1520         case EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT:
1521             componentType = GL_FLOAT;
1522             break;
1523         default:
1524             UNREACHABLE();
1525             return GL_NONE;
1526     }
1527 
1528     GLenum colorEncoding = GL_LINEAR;
1529 
1530     for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
1531     {
1532         const gl::InternalFormat &internalFormat = GetSizedInternalFormatInfo(sizedInternalFormat);
1533 
1534         if (internalFormat.componentType == componentType &&
1535             internalFormat.colorEncoding == colorEncoding &&
1536             internalFormat.isChannelSizeCompatible(config->redSize, config->greenSize,
1537                                                    config->blueSize, config->alphaSize))
1538         {
1539             return sizedInternalFormat;
1540         }
1541     }
1542 
1543     // Only expect to get here if there is no color bits in the config
1544     ASSERT(config->redSize == 0 && config->greenSize == 0 && config->blueSize == 0 &&
1545            config->alphaSize == 0);
1546     return GL_NONE;
1547 }
1548 
GetConfigDepthStencilBufferFormat(const egl::Config * config)1549 GLenum GetConfigDepthStencilBufferFormat(const egl::Config *config)
1550 {
1551     GLenum componentType = GL_UNSIGNED_NORMALIZED;
1552 
1553     for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
1554     {
1555         const gl::InternalFormat &internalFormat = GetSizedInternalFormatInfo(sizedInternalFormat);
1556 
1557         if (internalFormat.componentType == componentType &&
1558             static_cast<EGLint>(internalFormat.depthBits) == config->depthSize &&
1559             static_cast<EGLint>(internalFormat.stencilBits) == config->stencilSize)
1560         {
1561             return sizedInternalFormat;
1562         }
1563     }
1564 
1565     // Only expect to get here if there is no depth or stencil bits in the config
1566     ASSERT(config->depthSize == 0 && config->stencilSize == 0);
1567     return GL_NONE;
1568 }
1569 
BuildAllSizedInternalFormatSet()1570 static FormatSet BuildAllSizedInternalFormatSet()
1571 {
1572     FormatSet result;
1573 
1574     for (const auto &internalFormat : GetInternalFormatMap())
1575     {
1576         for (const auto &type : internalFormat.second)
1577         {
1578             if (type.second.sized)
1579             {
1580                 // TODO(jmadill): Fix this hack.
1581                 if (internalFormat.first == GL_BGR565_ANGLEX)
1582                     continue;
1583 
1584                 result.insert(internalFormat.first);
1585             }
1586         }
1587     }
1588 
1589     return result;
1590 }
1591 
GetPackedTypeInfo(GLenum type)1592 uint32_t GetPackedTypeInfo(GLenum type)
1593 {
1594     switch (type)
1595     {
1596         case GL_UNSIGNED_BYTE:
1597         case GL_BYTE:
1598         {
1599             static constexpr uint32_t kPacked = PackTypeInfo(1, false);
1600             return kPacked;
1601         }
1602         case GL_UNSIGNED_SHORT:
1603         case GL_SHORT:
1604         case GL_HALF_FLOAT:
1605         case GL_HALF_FLOAT_OES:
1606         {
1607             static constexpr uint32_t kPacked = PackTypeInfo(2, false);
1608             return kPacked;
1609         }
1610         case GL_UNSIGNED_INT:
1611         case GL_INT:
1612         case GL_FLOAT:
1613         {
1614             static constexpr uint32_t kPacked = PackTypeInfo(4, false);
1615             return kPacked;
1616         }
1617         case GL_UNSIGNED_SHORT_5_6_5:
1618         case GL_UNSIGNED_SHORT_4_4_4_4:
1619         case GL_UNSIGNED_SHORT_5_5_5_1:
1620         case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1621         case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
1622         {
1623             static constexpr uint32_t kPacked = PackTypeInfo(2, true);
1624             return kPacked;
1625         }
1626         case GL_UNSIGNED_INT_2_10_10_10_REV:
1627         case GL_UNSIGNED_INT_24_8:
1628         case GL_UNSIGNED_INT_10F_11F_11F_REV:
1629         case GL_UNSIGNED_INT_5_9_9_9_REV:
1630         {
1631             ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1632             static constexpr uint32_t kPacked = PackTypeInfo(4, true);
1633             return kPacked;
1634         }
1635         case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1636         {
1637             static constexpr uint32_t kPacked = PackTypeInfo(8, true);
1638             return kPacked;
1639         }
1640         default:
1641         {
1642             return 0;
1643         }
1644     }
1645 }
1646 
GetSizedInternalFormatInfo(GLenum internalFormat)1647 const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
1648 {
1649     static const InternalFormat defaultInternalFormat;
1650     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1651     auto iter                              = formatMap.find(internalFormat);
1652 
1653     // Sized internal formats only have one type per entry
1654     if (iter == formatMap.end() || iter->second.size() != 1)
1655     {
1656         return defaultInternalFormat;
1657     }
1658 
1659     const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1660     if (!internalFormatInfo.sized)
1661     {
1662         return defaultInternalFormat;
1663     }
1664 
1665     return internalFormatInfo;
1666 }
1667 
GetInternalFormatInfo(GLenum internalFormat,GLenum type)1668 const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1669 {
1670     static const InternalFormat defaultInternalFormat;
1671     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1672 
1673     auto internalFormatIter = formatMap.find(internalFormat);
1674     if (internalFormatIter == formatMap.end())
1675     {
1676         return defaultInternalFormat;
1677     }
1678 
1679     // If the internal format is sized, simply return it without the type check.
1680     if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1681     {
1682         return internalFormatIter->second.begin()->second;
1683     }
1684 
1685     auto typeIter = internalFormatIter->second.find(type);
1686     if (typeIter == internalFormatIter->second.end())
1687     {
1688         return defaultInternalFormat;
1689     }
1690 
1691     return typeIter->second;
1692 }
1693 
computePixelBytes(GLenum formatType) const1694 GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1695 {
1696     const auto &typeInfo = GetTypeInfo(formatType);
1697     GLuint components    = componentCount;
1698     // It shouldn't be these internal formats
1699     ASSERT(sizedInternalFormat != GL_RGBX8_SRGB_ANGLEX &&
1700            sizedInternalFormat != GL_BGRX8_SRGB_ANGLEX);
1701     if (sizedInternalFormat == GL_RGBX8_ANGLE)
1702     {
1703         components = 4;
1704     }
1705     else if (typeInfo.specialInterpretation)
1706     {
1707         components = 1;
1708     }
1709     return components * typeInfo.bytes;
1710 }
1711 
computeBufferRowLength(uint32_t width,uint32_t * resultOut) const1712 bool InternalFormat::computeBufferRowLength(uint32_t width, uint32_t *resultOut) const
1713 {
1714     CheckedNumeric<GLuint> checkedWidth(width);
1715 
1716     if (compressed)
1717     {
1718         angle::CheckedNumeric<uint32_t> checkedRowLength =
1719             rx::CheckedRoundUp<uint32_t>(width, compressedBlockWidth);
1720 
1721         return CheckedMathResult(checkedRowLength, resultOut);
1722     }
1723 
1724     return CheckedMathResult(checkedWidth, resultOut);
1725 }
1726 
computeBufferImageHeight(uint32_t height,uint32_t * resultOut) const1727 bool InternalFormat::computeBufferImageHeight(uint32_t height, uint32_t *resultOut) const
1728 {
1729     CheckedNumeric<GLuint> checkedHeight(height);
1730 
1731     if (compressed)
1732     {
1733         angle::CheckedNumeric<uint32_t> checkedImageHeight =
1734             rx::CheckedRoundUp<uint32_t>(height, compressedBlockHeight);
1735 
1736         return CheckedMathResult(checkedImageHeight, resultOut);
1737     }
1738 
1739     return CheckedMathResult(checkedHeight, resultOut);
1740 }
1741 
computePalettedImageRowPitch(GLsizei width,GLuint * resultOut) const1742 bool InternalFormat::computePalettedImageRowPitch(GLsizei width, GLuint *resultOut) const
1743 {
1744     ASSERT(paletted);
1745     switch (paletteBits)
1746     {
1747         case 4:
1748             *resultOut = (width + 1) / 2;
1749             return true;
1750         case 8:
1751             *resultOut = width;
1752             return true;
1753         default:
1754             UNREACHABLE();
1755             return false;
1756     }
1757 }
1758 
computeRowPitch(GLenum formatType,GLsizei width,GLint alignment,GLint rowLength,GLuint * resultOut) const1759 bool InternalFormat::computeRowPitch(GLenum formatType,
1760                                      GLsizei width,
1761                                      GLint alignment,
1762                                      GLint rowLength,
1763                                      GLuint *resultOut) const
1764 {
1765     if (paletted)
1766     {
1767         return computePalettedImageRowPitch(width, resultOut);
1768     }
1769 
1770     // Compressed images do not use pack/unpack parameters (rowLength).
1771     if (compressed)
1772     {
1773         return computeCompressedImageRowPitch(width, resultOut);
1774     }
1775 
1776     CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
1777     CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
1778 
1779     ASSERT(alignment > 0 && isPow2(alignment));
1780     CheckedNumeric<GLuint> checkedAlignment(alignment);
1781     auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1782     return CheckedMathResult(aligned, resultOut);
1783 }
1784 
computeDepthPitch(GLsizei height,GLint imageHeight,GLuint rowPitch,GLuint * resultOut) const1785 bool InternalFormat::computeDepthPitch(GLsizei height,
1786                                        GLint imageHeight,
1787                                        GLuint rowPitch,
1788                                        GLuint *resultOut) const
1789 {
1790     // Compressed images do not use pack/unpack parameters (imageHeight).
1791     if (compressed)
1792     {
1793         return computeCompressedImageDepthPitch(height, rowPitch, resultOut);
1794     }
1795 
1796     CheckedNumeric<GLuint> rowCount((imageHeight > 0) ? static_cast<GLuint>(imageHeight)
1797                                                       : static_cast<GLuint>(height));
1798     CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1799 
1800     return CheckedMathResult(checkedRowPitch * rowCount, resultOut);
1801 }
1802 
computeDepthPitch(GLenum formatType,GLsizei width,GLsizei height,GLint alignment,GLint rowLength,GLint imageHeight,GLuint * resultOut) const1803 bool InternalFormat::computeDepthPitch(GLenum formatType,
1804                                        GLsizei width,
1805                                        GLsizei height,
1806                                        GLint alignment,
1807                                        GLint rowLength,
1808                                        GLint imageHeight,
1809                                        GLuint *resultOut) const
1810 {
1811     GLuint rowPitch = 0;
1812     if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1813     {
1814         return false;
1815     }
1816     return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
1817 }
1818 
computeCompressedImageRowPitch(GLsizei width,GLuint * resultOut) const1819 bool InternalFormat::computeCompressedImageRowPitch(GLsizei width, GLuint *resultOut) const
1820 {
1821     ASSERT(compressed);
1822 
1823     CheckedNumeric<GLuint> checkedWidth(width);
1824     CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1825     const GLuint minBlockWidth = getCompressedImageMinBlocks().first;
1826 
1827     auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1828     if (numBlocksWide.IsValid() && numBlocksWide.ValueOrDie() < minBlockWidth)
1829     {
1830         numBlocksWide = minBlockWidth;
1831     }
1832     return CheckedMathResult(numBlocksWide * pixelBytes, resultOut);
1833 }
1834 
computeCompressedImageDepthPitch(GLsizei height,GLuint rowPitch,GLuint * resultOut) const1835 bool InternalFormat::computeCompressedImageDepthPitch(GLsizei height,
1836                                                       GLuint rowPitch,
1837                                                       GLuint *resultOut) const
1838 {
1839     ASSERT(compressed);
1840     ASSERT(rowPitch > 0 && rowPitch % pixelBytes == 0);
1841 
1842     CheckedNumeric<GLuint> checkedHeight(height);
1843     CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1844     CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
1845     const GLuint minBlockHeight = getCompressedImageMinBlocks().second;
1846 
1847     auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1848     if (numBlocksHigh.IsValid() && numBlocksHigh.ValueOrDie() < minBlockHeight)
1849     {
1850         numBlocksHigh = minBlockHeight;
1851     }
1852     return CheckedMathResult(numBlocksHigh * checkedRowPitch, resultOut);
1853 }
1854 
computeCompressedImageSize(const Extents & size,GLuint * resultOut) const1855 bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
1856 {
1857     CheckedNumeric<GLuint> checkedWidth(size.width);
1858     CheckedNumeric<GLuint> checkedHeight(size.height);
1859     CheckedNumeric<GLuint> checkedDepth(size.depth);
1860 
1861     if (paletted)
1862     {
1863         ASSERT(!compressed);
1864 
1865         GLuint paletteSize  = 1 << paletteBits;
1866         GLuint paletteBytes = paletteSize * pixelBytes;
1867 
1868         GLuint rowPitch;
1869         if (!computePalettedImageRowPitch(size.width, &rowPitch))
1870         {
1871             return false;
1872         }
1873 
1874         if (size.depth != 1)
1875         {
1876             return false;
1877         }
1878 
1879         CheckedNumeric<GLuint> checkedPaletteBytes(paletteBytes);
1880         CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1881 
1882         return CheckedMathResult(checkedPaletteBytes + checkedRowPitch * checkedHeight, resultOut);
1883     }
1884 
1885     CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1886     CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
1887     CheckedNumeric<GLuint> checkedBlockDepth(compressedBlockDepth);
1888     GLuint minBlockWidth, minBlockHeight;
1889     std::tie(minBlockWidth, minBlockHeight) = getCompressedImageMinBlocks();
1890 
1891     ASSERT(compressed);
1892     auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1893     auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1894     auto numBlocksDeep = (checkedDepth + checkedBlockDepth - 1u) / checkedBlockDepth;
1895     if (numBlocksWide.IsValid() && numBlocksWide.ValueOrDie() < minBlockWidth)
1896     {
1897         numBlocksWide = minBlockWidth;
1898     }
1899     if (numBlocksHigh.IsValid() && numBlocksHigh.ValueOrDie() < minBlockHeight)
1900     {
1901         numBlocksHigh = minBlockHeight;
1902     }
1903     auto bytes = numBlocksWide * numBlocksHigh * numBlocksDeep * pixelBytes;
1904     return CheckedMathResult(bytes, resultOut);
1905 }
1906 
getCompressedImageMinBlocks() const1907 std::pair<GLuint, GLuint> InternalFormat::getCompressedImageMinBlocks() const
1908 {
1909     GLuint minBlockWidth  = 0;
1910     GLuint minBlockHeight = 0;
1911 
1912     // Per the specification, a PVRTC block needs information from the 3 nearest blocks.
1913     // GL_IMG_texture_compression_pvrtc specifies the minimum size requirement in pixels, but
1914     // ANGLE's texture tables are written in terms of blocks. The 4BPP formats use 4x4 blocks, and
1915     // the 2BPP formats, 8x4 blocks. Therefore, both kinds of formats require a minimum of 2x2
1916     // blocks.
1917     if (IsPVRTC1Format(internalFormat))
1918     {
1919         minBlockWidth  = 2;
1920         minBlockHeight = 2;
1921     }
1922 
1923     return std::make_pair(minBlockWidth, minBlockHeight);
1924 }
1925 
computeSkipBytes(GLenum formatType,GLuint rowPitch,GLuint depthPitch,const PixelStoreStateBase & state,bool is3D,GLuint * resultOut) const1926 bool InternalFormat::computeSkipBytes(GLenum formatType,
1927                                       GLuint rowPitch,
1928                                       GLuint depthPitch,
1929                                       const PixelStoreStateBase &state,
1930                                       bool is3D,
1931                                       GLuint *resultOut) const
1932 {
1933     CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1934     CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
1935     CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1936     CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1937     CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
1938     CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
1939     auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
1940     if (!is3D)
1941     {
1942         checkedSkipImagesBytes = 0;
1943     }
1944     auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1945                      checkedSkipPixels * checkedPixelBytes;
1946     return CheckedMathResult(skipBytes, resultOut);
1947 }
1948 
computePackUnpackEndByte(GLenum formatType,const Extents & size,const PixelStoreStateBase & state,bool is3D,GLuint * resultOut) const1949 bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1950                                               const Extents &size,
1951                                               const PixelStoreStateBase &state,
1952                                               bool is3D,
1953                                               GLuint *resultOut) const
1954 {
1955     GLuint rowPitch = 0;
1956     if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
1957     {
1958         return false;
1959     }
1960 
1961     GLuint depthPitch = 0;
1962     if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1963     {
1964         return false;
1965     }
1966 
1967     CheckedNumeric<GLuint> checkedCopyBytes(0);
1968     if (compressed)
1969     {
1970         GLuint copyBytes = 0;
1971         if (!computeCompressedImageSize(size, &copyBytes))
1972         {
1973             return false;
1974         }
1975         checkedCopyBytes = copyBytes;
1976     }
1977     else if (size.height != 0 && (!is3D || size.depth != 0))
1978     {
1979         CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1980         checkedCopyBytes += size.width * bytes;
1981 
1982         CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1983         checkedCopyBytes += heightMinusOne * rowPitch;
1984 
1985         if (is3D)
1986         {
1987             CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1988             checkedCopyBytes += depthMinusOne * depthPitch;
1989         }
1990     }
1991 
1992     GLuint skipBytes = 0;
1993     if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1994     {
1995         return false;
1996     }
1997 
1998     CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
1999 
2000     return CheckedMathResult(endByte, resultOut);
2001 }
2002 
GetUnsizedFormat(GLenum internalFormat)2003 GLenum GetUnsizedFormat(GLenum internalFormat)
2004 {
2005     auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
2006     if (sizedFormatInfo.internalFormat != GL_NONE)
2007     {
2008         return sizedFormatInfo.format;
2009     }
2010 
2011     return internalFormat;
2012 }
2013 
CompressedFormatRequiresWholeImage(GLenum internalFormat)2014 bool CompressedFormatRequiresWholeImage(GLenum internalFormat)
2015 {
2016     // List of compressed texture format that require that the sub-image size is equal to texture's
2017     // respective mip level's size
2018     return IsPVRTC1Format(internalFormat);
2019 }
2020 
MaybeOverrideLuminance(GLenum & format,GLenum & type,GLenum actualFormat,GLenum actualType)2021 void MaybeOverrideLuminance(GLenum &format, GLenum &type, GLenum actualFormat, GLenum actualType)
2022 {
2023     gl::InternalFormat internalFormat = gl::GetInternalFormatInfo(format, type);
2024     if (internalFormat.isLUMA())
2025     {
2026         // Ensure the format and type are compatible
2027         ASSERT(internalFormat.pixelBytes ==
2028                gl::GetInternalFormatInfo(actualFormat, actualType).pixelBytes);
2029 
2030         // For Luminance formats, override with the internal format. Since this is not
2031         // renderable, our pixel pack routines don't handle it correctly.
2032         format = actualFormat;
2033         type   = actualType;
2034     }
2035 }
2036 
GetAllSizedInternalFormats()2037 const FormatSet &GetAllSizedInternalFormats()
2038 {
2039     static angle::base::NoDestructor<FormatSet> formatSet(BuildAllSizedInternalFormatSet());
2040     return *formatSet;
2041 }
2042 
GetAttributeType(GLenum enumValue)2043 AttributeType GetAttributeType(GLenum enumValue)
2044 {
2045     switch (enumValue)
2046     {
2047         case GL_FLOAT:
2048             return ATTRIBUTE_FLOAT;
2049         case GL_FLOAT_VEC2:
2050             return ATTRIBUTE_VEC2;
2051         case GL_FLOAT_VEC3:
2052             return ATTRIBUTE_VEC3;
2053         case GL_FLOAT_VEC4:
2054             return ATTRIBUTE_VEC4;
2055         case GL_INT:
2056             return ATTRIBUTE_INT;
2057         case GL_INT_VEC2:
2058             return ATTRIBUTE_IVEC2;
2059         case GL_INT_VEC3:
2060             return ATTRIBUTE_IVEC3;
2061         case GL_INT_VEC4:
2062             return ATTRIBUTE_IVEC4;
2063         case GL_UNSIGNED_INT:
2064             return ATTRIBUTE_UINT;
2065         case GL_UNSIGNED_INT_VEC2:
2066             return ATTRIBUTE_UVEC2;
2067         case GL_UNSIGNED_INT_VEC3:
2068             return ATTRIBUTE_UVEC3;
2069         case GL_UNSIGNED_INT_VEC4:
2070             return ATTRIBUTE_UVEC4;
2071         case GL_FLOAT_MAT2:
2072             return ATTRIBUTE_MAT2;
2073         case GL_FLOAT_MAT3:
2074             return ATTRIBUTE_MAT3;
2075         case GL_FLOAT_MAT4:
2076             return ATTRIBUTE_MAT4;
2077         case GL_FLOAT_MAT2x3:
2078             return ATTRIBUTE_MAT2x3;
2079         case GL_FLOAT_MAT2x4:
2080             return ATTRIBUTE_MAT2x4;
2081         case GL_FLOAT_MAT3x2:
2082             return ATTRIBUTE_MAT3x2;
2083         case GL_FLOAT_MAT3x4:
2084             return ATTRIBUTE_MAT3x4;
2085         case GL_FLOAT_MAT4x2:
2086             return ATTRIBUTE_MAT4x2;
2087         case GL_FLOAT_MAT4x3:
2088             return ATTRIBUTE_MAT4x3;
2089         default:
2090             UNREACHABLE();
2091             return ATTRIBUTE_FLOAT;
2092     }
2093 }
2094 
GetVertexFormatID(VertexAttribType type,GLboolean normalized,GLuint components,bool pureInteger)2095 angle::FormatID GetVertexFormatID(VertexAttribType type,
2096                                   GLboolean normalized,
2097                                   GLuint components,
2098                                   bool pureInteger)
2099 {
2100     switch (type)
2101     {
2102         case VertexAttribType::Byte:
2103             switch (components)
2104             {
2105                 case 1:
2106                     if (pureInteger)
2107                         return angle::FormatID::R8_SINT;
2108                     if (normalized)
2109                         return angle::FormatID::R8_SNORM;
2110                     return angle::FormatID::R8_SSCALED;
2111                 case 2:
2112                     if (pureInteger)
2113                         return angle::FormatID::R8G8_SINT;
2114                     if (normalized)
2115                         return angle::FormatID::R8G8_SNORM;
2116                     return angle::FormatID::R8G8_SSCALED;
2117                 case 3:
2118                     if (pureInteger)
2119                         return angle::FormatID::R8G8B8_SINT;
2120                     if (normalized)
2121                         return angle::FormatID::R8G8B8_SNORM;
2122                     return angle::FormatID::R8G8B8_SSCALED;
2123                 case 4:
2124                     if (pureInteger)
2125                         return angle::FormatID::R8G8B8A8_SINT;
2126                     if (normalized)
2127                         return angle::FormatID::R8G8B8A8_SNORM;
2128                     return angle::FormatID::R8G8B8A8_SSCALED;
2129                 default:
2130                     UNREACHABLE();
2131                     return angle::FormatID::NONE;
2132             }
2133         case VertexAttribType::UnsignedByte:
2134             switch (components)
2135             {
2136                 case 1:
2137                     if (pureInteger)
2138                         return angle::FormatID::R8_UINT;
2139                     if (normalized)
2140                         return angle::FormatID::R8_UNORM;
2141                     return angle::FormatID::R8_USCALED;
2142                 case 2:
2143                     if (pureInteger)
2144                         return angle::FormatID::R8G8_UINT;
2145                     if (normalized)
2146                         return angle::FormatID::R8G8_UNORM;
2147                     return angle::FormatID::R8G8_USCALED;
2148                 case 3:
2149                     if (pureInteger)
2150                         return angle::FormatID::R8G8B8_UINT;
2151                     if (normalized)
2152                         return angle::FormatID::R8G8B8_UNORM;
2153                     return angle::FormatID::R8G8B8_USCALED;
2154                 case 4:
2155                     if (pureInteger)
2156                         return angle::FormatID::R8G8B8A8_UINT;
2157                     if (normalized)
2158                         return angle::FormatID::R8G8B8A8_UNORM;
2159                     return angle::FormatID::R8G8B8A8_USCALED;
2160                 default:
2161                     UNREACHABLE();
2162                     return angle::FormatID::NONE;
2163             }
2164         case VertexAttribType::Short:
2165             switch (components)
2166             {
2167                 case 1:
2168                     if (pureInteger)
2169                         return angle::FormatID::R16_SINT;
2170                     if (normalized)
2171                         return angle::FormatID::R16_SNORM;
2172                     return angle::FormatID::R16_SSCALED;
2173                 case 2:
2174                     if (pureInteger)
2175                         return angle::FormatID::R16G16_SINT;
2176                     if (normalized)
2177                         return angle::FormatID::R16G16_SNORM;
2178                     return angle::FormatID::R16G16_SSCALED;
2179                 case 3:
2180                     if (pureInteger)
2181                         return angle::FormatID::R16G16B16_SINT;
2182                     if (normalized)
2183                         return angle::FormatID::R16G16B16_SNORM;
2184                     return angle::FormatID::R16G16B16_SSCALED;
2185                 case 4:
2186                     if (pureInteger)
2187                         return angle::FormatID::R16G16B16A16_SINT;
2188                     if (normalized)
2189                         return angle::FormatID::R16G16B16A16_SNORM;
2190                     return angle::FormatID::R16G16B16A16_SSCALED;
2191                 default:
2192                     UNREACHABLE();
2193                     return angle::FormatID::NONE;
2194             }
2195         case VertexAttribType::UnsignedShort:
2196             switch (components)
2197             {
2198                 case 1:
2199                     if (pureInteger)
2200                         return angle::FormatID::R16_UINT;
2201                     if (normalized)
2202                         return angle::FormatID::R16_UNORM;
2203                     return angle::FormatID::R16_USCALED;
2204                 case 2:
2205                     if (pureInteger)
2206                         return angle::FormatID::R16G16_UINT;
2207                     if (normalized)
2208                         return angle::FormatID::R16G16_UNORM;
2209                     return angle::FormatID::R16G16_USCALED;
2210                 case 3:
2211                     if (pureInteger)
2212                         return angle::FormatID::R16G16B16_UINT;
2213                     if (normalized)
2214                         return angle::FormatID::R16G16B16_UNORM;
2215                     return angle::FormatID::R16G16B16_USCALED;
2216                 case 4:
2217                     if (pureInteger)
2218                         return angle::FormatID::R16G16B16A16_UINT;
2219                     if (normalized)
2220                         return angle::FormatID::R16G16B16A16_UNORM;
2221                     return angle::FormatID::R16G16B16A16_USCALED;
2222                 default:
2223                     UNREACHABLE();
2224                     return angle::FormatID::NONE;
2225             }
2226         case VertexAttribType::Int:
2227             switch (components)
2228             {
2229                 case 1:
2230                     if (pureInteger)
2231                         return angle::FormatID::R32_SINT;
2232                     if (normalized)
2233                         return angle::FormatID::R32_SNORM;
2234                     return angle::FormatID::R32_SSCALED;
2235                 case 2:
2236                     if (pureInteger)
2237                         return angle::FormatID::R32G32_SINT;
2238                     if (normalized)
2239                         return angle::FormatID::R32G32_SNORM;
2240                     return angle::FormatID::R32G32_SSCALED;
2241                 case 3:
2242                     if (pureInteger)
2243                         return angle::FormatID::R32G32B32_SINT;
2244                     if (normalized)
2245                         return angle::FormatID::R32G32B32_SNORM;
2246                     return angle::FormatID::R32G32B32_SSCALED;
2247                 case 4:
2248                     if (pureInteger)
2249                         return angle::FormatID::R32G32B32A32_SINT;
2250                     if (normalized)
2251                         return angle::FormatID::R32G32B32A32_SNORM;
2252                     return angle::FormatID::R32G32B32A32_SSCALED;
2253                 default:
2254                     UNREACHABLE();
2255                     return angle::FormatID::NONE;
2256             }
2257         case VertexAttribType::UnsignedInt:
2258             switch (components)
2259             {
2260                 case 1:
2261                     if (pureInteger)
2262                         return angle::FormatID::R32_UINT;
2263                     if (normalized)
2264                         return angle::FormatID::R32_UNORM;
2265                     return angle::FormatID::R32_USCALED;
2266                 case 2:
2267                     if (pureInteger)
2268                         return angle::FormatID::R32G32_UINT;
2269                     if (normalized)
2270                         return angle::FormatID::R32G32_UNORM;
2271                     return angle::FormatID::R32G32_USCALED;
2272                 case 3:
2273                     if (pureInteger)
2274                         return angle::FormatID::R32G32B32_UINT;
2275                     if (normalized)
2276                         return angle::FormatID::R32G32B32_UNORM;
2277                     return angle::FormatID::R32G32B32_USCALED;
2278                 case 4:
2279                     if (pureInteger)
2280                         return angle::FormatID::R32G32B32A32_UINT;
2281                     if (normalized)
2282                         return angle::FormatID::R32G32B32A32_UNORM;
2283                     return angle::FormatID::R32G32B32A32_USCALED;
2284                 default:
2285                     UNREACHABLE();
2286                     return angle::FormatID::NONE;
2287             }
2288         case VertexAttribType::Float:
2289             switch (components)
2290             {
2291                 case 1:
2292                     return angle::FormatID::R32_FLOAT;
2293                 case 2:
2294                     return angle::FormatID::R32G32_FLOAT;
2295                 case 3:
2296                     return angle::FormatID::R32G32B32_FLOAT;
2297                 case 4:
2298                     return angle::FormatID::R32G32B32A32_FLOAT;
2299                 default:
2300                     UNREACHABLE();
2301                     return angle::FormatID::NONE;
2302             }
2303         case VertexAttribType::HalfFloat:
2304         case VertexAttribType::HalfFloatOES:
2305             switch (components)
2306             {
2307                 case 1:
2308                     return angle::FormatID::R16_FLOAT;
2309                 case 2:
2310                     return angle::FormatID::R16G16_FLOAT;
2311                 case 3:
2312                     return angle::FormatID::R16G16B16_FLOAT;
2313                 case 4:
2314                     return angle::FormatID::R16G16B16A16_FLOAT;
2315                 default:
2316                     UNREACHABLE();
2317                     return angle::FormatID::NONE;
2318             }
2319         case VertexAttribType::Fixed:
2320             switch (components)
2321             {
2322                 case 1:
2323                     return angle::FormatID::R32_FIXED;
2324                 case 2:
2325                     return angle::FormatID::R32G32_FIXED;
2326                 case 3:
2327                     return angle::FormatID::R32G32B32_FIXED;
2328                 case 4:
2329                     return angle::FormatID::R32G32B32A32_FIXED;
2330                 default:
2331                     UNREACHABLE();
2332                     return angle::FormatID::NONE;
2333             }
2334         case VertexAttribType::Int2101010:
2335             if (pureInteger)
2336                 return angle::FormatID::R10G10B10A2_SINT;
2337             if (normalized)
2338                 return angle::FormatID::R10G10B10A2_SNORM;
2339             return angle::FormatID::R10G10B10A2_SSCALED;
2340         case VertexAttribType::UnsignedInt2101010:
2341             if (pureInteger)
2342                 return angle::FormatID::R10G10B10A2_UINT;
2343             if (normalized)
2344                 return angle::FormatID::R10G10B10A2_UNORM;
2345             return angle::FormatID::R10G10B10A2_USCALED;
2346         case VertexAttribType::Int1010102:
2347             switch (components)
2348             {
2349                 case 3:
2350                     if (pureInteger)
2351                         return angle::FormatID::X2R10G10B10_SINT_VERTEX;
2352                     if (normalized)
2353                         return angle::FormatID::X2R10G10B10_SNORM_VERTEX;
2354                     return angle::FormatID::X2R10G10B10_SSCALED_VERTEX;
2355                 case 4:
2356                     if (pureInteger)
2357                         return angle::FormatID::A2R10G10B10_SINT_VERTEX;
2358                     if (normalized)
2359                         return angle::FormatID::A2R10G10B10_SNORM_VERTEX;
2360                     return angle::FormatID::A2R10G10B10_SSCALED_VERTEX;
2361                 default:
2362                     UNREACHABLE();
2363                     return angle::FormatID::NONE;
2364             }
2365         case VertexAttribType::UnsignedInt1010102:
2366             switch (components)
2367             {
2368                 case 3:
2369                     if (pureInteger)
2370                         return angle::FormatID::X2R10G10B10_UINT_VERTEX;
2371                     if (normalized)
2372                         return angle::FormatID::X2R10G10B10_UNORM_VERTEX;
2373                     return angle::FormatID::X2R10G10B10_USCALED_VERTEX;
2374 
2375                 case 4:
2376                     if (pureInteger)
2377                         return angle::FormatID::A2R10G10B10_UINT_VERTEX;
2378                     if (normalized)
2379                         return angle::FormatID::A2R10G10B10_UNORM_VERTEX;
2380                     return angle::FormatID::A2R10G10B10_USCALED_VERTEX;
2381                 default:
2382                     UNREACHABLE();
2383                     return angle::FormatID::NONE;
2384             }
2385         default:
2386             UNREACHABLE();
2387             return angle::FormatID::NONE;
2388     }
2389 }
2390 
GetVertexFormatID(const VertexAttribute & attrib,VertexAttribType currentValueType)2391 angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType)
2392 {
2393     if (!attrib.enabled)
2394     {
2395         return GetCurrentValueFormatID(currentValueType);
2396     }
2397     return attrib.format->id;
2398 }
2399 
GetCurrentValueFormatID(VertexAttribType currentValueType)2400 angle::FormatID GetCurrentValueFormatID(VertexAttribType currentValueType)
2401 {
2402     switch (currentValueType)
2403     {
2404         case VertexAttribType::Float:
2405             return angle::FormatID::R32G32B32A32_FLOAT;
2406         case VertexAttribType::Int:
2407             return angle::FormatID::R32G32B32A32_SINT;
2408         case VertexAttribType::UnsignedInt:
2409             return angle::FormatID::R32G32B32A32_UINT;
2410         default:
2411             UNREACHABLE();
2412             return angle::FormatID::NONE;
2413     }
2414 }
2415 
GetVertexFormatFromID(angle::FormatID vertexFormatID)2416 const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
2417 {
2418     switch (vertexFormatID)
2419     {
2420         case angle::FormatID::R8_SSCALED:
2421         {
2422             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
2423             return format;
2424         }
2425         case angle::FormatID::R8_SNORM:
2426         {
2427             static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
2428             return format;
2429         }
2430         case angle::FormatID::R8G8_SSCALED:
2431         {
2432             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
2433             return format;
2434         }
2435         case angle::FormatID::R8G8_SNORM:
2436         {
2437             static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
2438             return format;
2439         }
2440         case angle::FormatID::R8G8B8_SSCALED:
2441         {
2442             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
2443             return format;
2444         }
2445         case angle::FormatID::R8G8B8_SNORM:
2446         {
2447             static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
2448             return format;
2449         }
2450         case angle::FormatID::R8G8B8A8_SSCALED:
2451         {
2452             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
2453             return format;
2454         }
2455         case angle::FormatID::R8G8B8A8_SNORM:
2456         {
2457             static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
2458             return format;
2459         }
2460         case angle::FormatID::R8_USCALED:
2461         {
2462             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
2463             return format;
2464         }
2465         case angle::FormatID::R8_UNORM:
2466         {
2467             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
2468             return format;
2469         }
2470         case angle::FormatID::R8G8_USCALED:
2471         {
2472             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
2473             return format;
2474         }
2475         case angle::FormatID::R8G8_UNORM:
2476         {
2477             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
2478             return format;
2479         }
2480         case angle::FormatID::R8G8B8_USCALED:
2481         {
2482             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
2483             return format;
2484         }
2485         case angle::FormatID::R8G8B8_UNORM:
2486         {
2487             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
2488             return format;
2489         }
2490         case angle::FormatID::R8G8B8A8_USCALED:
2491         {
2492             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
2493             return format;
2494         }
2495         case angle::FormatID::R8G8B8A8_UNORM:
2496         {
2497             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
2498             return format;
2499         }
2500         case angle::FormatID::R16_SSCALED:
2501         {
2502             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
2503             return format;
2504         }
2505         case angle::FormatID::R16_SNORM:
2506         {
2507             static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
2508             return format;
2509         }
2510         case angle::FormatID::R16G16_SSCALED:
2511         {
2512             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
2513             return format;
2514         }
2515         case angle::FormatID::R16G16_SNORM:
2516         {
2517             static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
2518             return format;
2519         }
2520         case angle::FormatID::R16G16B16_SSCALED:
2521         {
2522             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
2523             return format;
2524         }
2525         case angle::FormatID::R16G16B16_SNORM:
2526         {
2527             static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
2528             return format;
2529         }
2530         case angle::FormatID::R16G16B16A16_SSCALED:
2531         {
2532             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
2533             return format;
2534         }
2535         case angle::FormatID::R16G16B16A16_SNORM:
2536         {
2537             static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
2538             return format;
2539         }
2540         case angle::FormatID::R16_USCALED:
2541         {
2542             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
2543             return format;
2544         }
2545         case angle::FormatID::R16_UNORM:
2546         {
2547             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
2548             return format;
2549         }
2550         case angle::FormatID::R16G16_USCALED:
2551         {
2552             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
2553             return format;
2554         }
2555         case angle::FormatID::R16G16_UNORM:
2556         {
2557             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
2558             return format;
2559         }
2560         case angle::FormatID::R16G16B16_USCALED:
2561         {
2562             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
2563             return format;
2564         }
2565         case angle::FormatID::R16G16B16_UNORM:
2566         {
2567             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
2568             return format;
2569         }
2570         case angle::FormatID::R16G16B16A16_USCALED:
2571         {
2572             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
2573             return format;
2574         }
2575         case angle::FormatID::R16G16B16A16_UNORM:
2576         {
2577             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
2578             return format;
2579         }
2580         case angle::FormatID::R32_SSCALED:
2581         {
2582             static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
2583             return format;
2584         }
2585         case angle::FormatID::R32_SNORM:
2586         {
2587             static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
2588             return format;
2589         }
2590         case angle::FormatID::R32G32_SSCALED:
2591         {
2592             static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
2593             return format;
2594         }
2595         case angle::FormatID::R32G32_SNORM:
2596         {
2597             static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
2598             return format;
2599         }
2600         case angle::FormatID::R32G32B32_SSCALED:
2601         {
2602             static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
2603             return format;
2604         }
2605         case angle::FormatID::R32G32B32_SNORM:
2606         {
2607             static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
2608             return format;
2609         }
2610         case angle::FormatID::R32G32B32A32_SSCALED:
2611         {
2612             static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
2613             return format;
2614         }
2615         case angle::FormatID::R32G32B32A32_SNORM:
2616         {
2617             static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
2618             return format;
2619         }
2620         case angle::FormatID::R32_USCALED:
2621         {
2622             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2623             return format;
2624         }
2625         case angle::FormatID::R32_UNORM:
2626         {
2627             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2628             return format;
2629         }
2630         case angle::FormatID::R32G32_USCALED:
2631         {
2632             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2633             return format;
2634         }
2635         case angle::FormatID::R32G32_UNORM:
2636         {
2637             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2638             return format;
2639         }
2640         case angle::FormatID::R32G32B32_USCALED:
2641         {
2642             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2643             return format;
2644         }
2645         case angle::FormatID::R32G32B32_UNORM:
2646         {
2647             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2648             return format;
2649         }
2650         case angle::FormatID::R32G32B32A32_USCALED:
2651         {
2652             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2653             return format;
2654         }
2655         case angle::FormatID::R32G32B32A32_UNORM:
2656         {
2657             static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2658             return format;
2659         }
2660         case angle::FormatID::R8_SINT:
2661         {
2662             static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2663             return format;
2664         }
2665         case angle::FormatID::R8G8_SINT:
2666         {
2667             static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2668             return format;
2669         }
2670         case angle::FormatID::R8G8B8_SINT:
2671         {
2672             static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2673             return format;
2674         }
2675         case angle::FormatID::R8G8B8A8_SINT:
2676         {
2677             static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2678             return format;
2679         }
2680         case angle::FormatID::R8_UINT:
2681         {
2682             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2683             return format;
2684         }
2685         case angle::FormatID::R8G8_UINT:
2686         {
2687             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2688             return format;
2689         }
2690         case angle::FormatID::R8G8B8_UINT:
2691         {
2692             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2693             return format;
2694         }
2695         case angle::FormatID::R8G8B8A8_UINT:
2696         {
2697             static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2698             return format;
2699         }
2700         case angle::FormatID::R16_SINT:
2701         {
2702             static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2703             return format;
2704         }
2705         case angle::FormatID::R16G16_SINT:
2706         {
2707             static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2708             return format;
2709         }
2710         case angle::FormatID::R16G16B16_SINT:
2711         {
2712             static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2713             return format;
2714         }
2715         case angle::FormatID::R16G16B16A16_SINT:
2716         {
2717             static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2718             return format;
2719         }
2720         case angle::FormatID::R16_UINT:
2721         {
2722             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2723             return format;
2724         }
2725         case angle::FormatID::R16G16_UINT:
2726         {
2727             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2728             return format;
2729         }
2730         case angle::FormatID::R16G16B16_UINT:
2731         {
2732             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2733             return format;
2734         }
2735         case angle::FormatID::R16G16B16A16_UINT:
2736         {
2737             static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2738             return format;
2739         }
2740         case angle::FormatID::R32_SINT:
2741         {
2742             static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2743             return format;
2744         }
2745         case angle::FormatID::R32G32_SINT:
2746         {
2747             static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2748             return format;
2749         }
2750         case angle::FormatID::R32G32B32_SINT:
2751         {
2752             static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2753             return format;
2754         }
2755         case angle::FormatID::R32G32B32A32_SINT:
2756         {
2757             static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2758             return format;
2759         }
2760         case angle::FormatID::R32_UINT:
2761         {
2762             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2763             return format;
2764         }
2765         case angle::FormatID::R32G32_UINT:
2766         {
2767             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2768             return format;
2769         }
2770         case angle::FormatID::R32G32B32_UINT:
2771         {
2772             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2773             return format;
2774         }
2775         case angle::FormatID::R32G32B32A32_UINT:
2776         {
2777             static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2778             return format;
2779         }
2780         case angle::FormatID::R32_FIXED:
2781         {
2782             static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2783             return format;
2784         }
2785         case angle::FormatID::R32G32_FIXED:
2786         {
2787             static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2788             return format;
2789         }
2790         case angle::FormatID::R32G32B32_FIXED:
2791         {
2792             static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2793             return format;
2794         }
2795         case angle::FormatID::R32G32B32A32_FIXED:
2796         {
2797             static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2798             return format;
2799         }
2800         case angle::FormatID::R16_FLOAT:
2801         {
2802             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2803             return format;
2804         }
2805         case angle::FormatID::R16G16_FLOAT:
2806         {
2807             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2808             return format;
2809         }
2810         case angle::FormatID::R16G16B16_FLOAT:
2811         {
2812             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2813             return format;
2814         }
2815         case angle::FormatID::R16G16B16A16_FLOAT:
2816         {
2817             static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2818             return format;
2819         }
2820         case angle::FormatID::R32_FLOAT:
2821         {
2822             static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2823             return format;
2824         }
2825         case angle::FormatID::R32G32_FLOAT:
2826         {
2827             static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2828             return format;
2829         }
2830         case angle::FormatID::R32G32B32_FLOAT:
2831         {
2832             static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2833             return format;
2834         }
2835         case angle::FormatID::R32G32B32A32_FLOAT:
2836         {
2837             static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2838             return format;
2839         }
2840         case angle::FormatID::R10G10B10A2_SSCALED:
2841         {
2842             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2843             return format;
2844         }
2845         case angle::FormatID::R10G10B10A2_USCALED:
2846         {
2847             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2848             return format;
2849         }
2850         case angle::FormatID::R10G10B10A2_SNORM:
2851         {
2852             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2853             return format;
2854         }
2855         case angle::FormatID::R10G10B10A2_UNORM:
2856         {
2857             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2858             return format;
2859         }
2860         case angle::FormatID::R10G10B10A2_SINT:
2861         {
2862             static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2863             return format;
2864         }
2865         case angle::FormatID::R10G10B10A2_UINT:
2866         {
2867             static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2868             return format;
2869         }
2870         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2871         {
2872             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2873             return format;
2874         }
2875         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2876         {
2877             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2878             return format;
2879         }
2880         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
2881         {
2882             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2883             return format;
2884         }
2885         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
2886         {
2887             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2888             return format;
2889         }
2890         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2891         {
2892             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2893             return format;
2894         }
2895         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2896         {
2897             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2898             return format;
2899         }
2900         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
2901         {
2902             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2903             return format;
2904         }
2905         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
2906         {
2907             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_FALSE, 4, false);
2908             return format;
2909         }
2910         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
2911         {
2912             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2913             return format;
2914         }
2915         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
2916         {
2917             static const VertexFormat format(GL_UNSIGNED_INT_10_10_10_2_OES, GL_TRUE, 4, false);
2918             return format;
2919         }
2920         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
2921         {
2922             static const VertexFormat format(GL_INT_10_10_10_2_OES, GL_FALSE, 4, true);
2923             return format;
2924         }
2925         default:
2926         {
2927             static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2928             return format;
2929         }
2930     }
2931 }
2932 
GetVertexFormatSize(angle::FormatID vertexFormatID)2933 size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
2934 {
2935     switch (vertexFormatID)
2936     {
2937         case angle::FormatID::R8_SSCALED:
2938         case angle::FormatID::R8_SNORM:
2939         case angle::FormatID::R8_USCALED:
2940         case angle::FormatID::R8_UNORM:
2941         case angle::FormatID::R8_SINT:
2942         case angle::FormatID::R8_UINT:
2943             return 1;
2944 
2945         case angle::FormatID::R8G8_SSCALED:
2946         case angle::FormatID::R8G8_SNORM:
2947         case angle::FormatID::R8G8_USCALED:
2948         case angle::FormatID::R8G8_UNORM:
2949         case angle::FormatID::R8G8_SINT:
2950         case angle::FormatID::R8G8_UINT:
2951         case angle::FormatID::R16_SSCALED:
2952         case angle::FormatID::R16_SNORM:
2953         case angle::FormatID::R16_USCALED:
2954         case angle::FormatID::R16_UNORM:
2955         case angle::FormatID::R16_SINT:
2956         case angle::FormatID::R16_UINT:
2957         case angle::FormatID::R16_FLOAT:
2958             return 2;
2959 
2960         case angle::FormatID::R8G8B8_SSCALED:
2961         case angle::FormatID::R8G8B8_SNORM:
2962         case angle::FormatID::R8G8B8_USCALED:
2963         case angle::FormatID::R8G8B8_UNORM:
2964         case angle::FormatID::R8G8B8_SINT:
2965         case angle::FormatID::R8G8B8_UINT:
2966             return 3;
2967 
2968         case angle::FormatID::R8G8B8A8_SSCALED:
2969         case angle::FormatID::R8G8B8A8_SNORM:
2970         case angle::FormatID::R8G8B8A8_USCALED:
2971         case angle::FormatID::R8G8B8A8_UNORM:
2972         case angle::FormatID::R8G8B8A8_SINT:
2973         case angle::FormatID::R8G8B8A8_UINT:
2974         case angle::FormatID::R16G16_SSCALED:
2975         case angle::FormatID::R16G16_SNORM:
2976         case angle::FormatID::R16G16_USCALED:
2977         case angle::FormatID::R16G16_UNORM:
2978         case angle::FormatID::R16G16_SINT:
2979         case angle::FormatID::R16G16_UINT:
2980         case angle::FormatID::R32_SSCALED:
2981         case angle::FormatID::R32_SNORM:
2982         case angle::FormatID::R32_USCALED:
2983         case angle::FormatID::R32_UNORM:
2984         case angle::FormatID::R32_SINT:
2985         case angle::FormatID::R32_UINT:
2986         case angle::FormatID::R16G16_FLOAT:
2987         case angle::FormatID::R32_FIXED:
2988         case angle::FormatID::R32_FLOAT:
2989         case angle::FormatID::R10G10B10A2_SSCALED:
2990         case angle::FormatID::R10G10B10A2_USCALED:
2991         case angle::FormatID::R10G10B10A2_SNORM:
2992         case angle::FormatID::R10G10B10A2_UNORM:
2993         case angle::FormatID::R10G10B10A2_SINT:
2994         case angle::FormatID::R10G10B10A2_UINT:
2995         case angle::FormatID::A2R10G10B10_SSCALED_VERTEX:
2996         case angle::FormatID::A2R10G10B10_USCALED_VERTEX:
2997         case angle::FormatID::A2R10G10B10_SINT_VERTEX:
2998         case angle::FormatID::A2R10G10B10_UINT_VERTEX:
2999         case angle::FormatID::A2R10G10B10_SNORM_VERTEX:
3000         case angle::FormatID::A2R10G10B10_UNORM_VERTEX:
3001         case angle::FormatID::X2R10G10B10_SSCALED_VERTEX:
3002         case angle::FormatID::X2R10G10B10_USCALED_VERTEX:
3003         case angle::FormatID::X2R10G10B10_SINT_VERTEX:
3004         case angle::FormatID::X2R10G10B10_UINT_VERTEX:
3005         case angle::FormatID::X2R10G10B10_SNORM_VERTEX:
3006         case angle::FormatID::X2R10G10B10_UNORM_VERTEX:
3007             return 4;
3008 
3009         case angle::FormatID::R16G16B16_SSCALED:
3010         case angle::FormatID::R16G16B16_SNORM:
3011         case angle::FormatID::R16G16B16_USCALED:
3012         case angle::FormatID::R16G16B16_UNORM:
3013         case angle::FormatID::R16G16B16_SINT:
3014         case angle::FormatID::R16G16B16_UINT:
3015         case angle::FormatID::R16G16B16_FLOAT:
3016             return 6;
3017 
3018         case angle::FormatID::R16G16B16A16_SSCALED:
3019         case angle::FormatID::R16G16B16A16_SNORM:
3020         case angle::FormatID::R16G16B16A16_USCALED:
3021         case angle::FormatID::R16G16B16A16_UNORM:
3022         case angle::FormatID::R16G16B16A16_SINT:
3023         case angle::FormatID::R16G16B16A16_UINT:
3024         case angle::FormatID::R32G32_SSCALED:
3025         case angle::FormatID::R32G32_SNORM:
3026         case angle::FormatID::R32G32_USCALED:
3027         case angle::FormatID::R32G32_UNORM:
3028         case angle::FormatID::R32G32_SINT:
3029         case angle::FormatID::R32G32_UINT:
3030         case angle::FormatID::R16G16B16A16_FLOAT:
3031         case angle::FormatID::R32G32_FIXED:
3032         case angle::FormatID::R32G32_FLOAT:
3033             return 8;
3034 
3035         case angle::FormatID::R32G32B32_SSCALED:
3036         case angle::FormatID::R32G32B32_SNORM:
3037         case angle::FormatID::R32G32B32_USCALED:
3038         case angle::FormatID::R32G32B32_UNORM:
3039         case angle::FormatID::R32G32B32_SINT:
3040         case angle::FormatID::R32G32B32_UINT:
3041         case angle::FormatID::R32G32B32_FIXED:
3042         case angle::FormatID::R32G32B32_FLOAT:
3043             return 12;
3044 
3045         case angle::FormatID::R32G32B32A32_SSCALED:
3046         case angle::FormatID::R32G32B32A32_SNORM:
3047         case angle::FormatID::R32G32B32A32_USCALED:
3048         case angle::FormatID::R32G32B32A32_UNORM:
3049         case angle::FormatID::R32G32B32A32_SINT:
3050         case angle::FormatID::R32G32B32A32_UINT:
3051         case angle::FormatID::R32G32B32A32_FIXED:
3052         case angle::FormatID::R32G32B32A32_FLOAT:
3053             return 16;
3054 
3055         case angle::FormatID::NONE:
3056         default:
3057             UNREACHABLE();
3058             return 0;
3059     }
3060 }
3061 
ConvertFormatSignedness(const angle::Format & format)3062 angle::FormatID ConvertFormatSignedness(const angle::Format &format)
3063 {
3064     switch (format.id)
3065     {
3066         // 1 byte signed to unsigned
3067         case angle::FormatID::R8_SINT:
3068             return angle::FormatID::R8_UINT;
3069         case angle::FormatID::R8_SNORM:
3070             return angle::FormatID::R8_UNORM;
3071         case angle::FormatID::R8_SSCALED:
3072             return angle::FormatID::R8_USCALED;
3073         case angle::FormatID::R8G8_SINT:
3074             return angle::FormatID::R8G8_UINT;
3075         case angle::FormatID::R8G8_SNORM:
3076             return angle::FormatID::R8G8_UNORM;
3077         case angle::FormatID::R8G8_SSCALED:
3078             return angle::FormatID::R8G8_USCALED;
3079         case angle::FormatID::R8G8B8_SINT:
3080             return angle::FormatID::R8G8B8_UINT;
3081         case angle::FormatID::R8G8B8_SNORM:
3082             return angle::FormatID::R8G8B8_UNORM;
3083         case angle::FormatID::R8G8B8_SSCALED:
3084             return angle::FormatID::R8G8B8_USCALED;
3085         case angle::FormatID::R8G8B8A8_SINT:
3086             return angle::FormatID::R8G8B8A8_UINT;
3087         case angle::FormatID::R8G8B8A8_SNORM:
3088             return angle::FormatID::R8G8B8A8_UNORM;
3089         case angle::FormatID::R8G8B8A8_SSCALED:
3090             return angle::FormatID::R8G8B8A8_USCALED;
3091         // 1 byte unsigned to signed
3092         case angle::FormatID::R8_UINT:
3093             return angle::FormatID::R8_SINT;
3094         case angle::FormatID::R8_UNORM:
3095             return angle::FormatID::R8_SNORM;
3096         case angle::FormatID::R8_USCALED:
3097             return angle::FormatID::R8_SSCALED;
3098         case angle::FormatID::R8G8_UINT:
3099             return angle::FormatID::R8G8_SINT;
3100         case angle::FormatID::R8G8_UNORM:
3101             return angle::FormatID::R8G8_SNORM;
3102         case angle::FormatID::R8G8_USCALED:
3103             return angle::FormatID::R8G8_SSCALED;
3104         case angle::FormatID::R8G8B8_UINT:
3105             return angle::FormatID::R8G8B8_SINT;
3106         case angle::FormatID::R8G8B8_UNORM:
3107             return angle::FormatID::R8G8B8_SNORM;
3108         case angle::FormatID::R8G8B8_USCALED:
3109             return angle::FormatID::R8G8B8_SSCALED;
3110         case angle::FormatID::R8G8B8A8_UINT:
3111             return angle::FormatID::R8G8B8A8_SINT;
3112         case angle::FormatID::R8G8B8A8_UNORM:
3113             return angle::FormatID::R8G8B8A8_SNORM;
3114         case angle::FormatID::R8G8B8A8_USCALED:
3115             return angle::FormatID::R8G8B8A8_SSCALED;
3116         // 2 byte signed to unsigned
3117         case angle::FormatID::R16_SINT:
3118             return angle::FormatID::R16_UINT;
3119         case angle::FormatID::R16_SNORM:
3120             return angle::FormatID::R16_UNORM;
3121         case angle::FormatID::R16_SSCALED:
3122             return angle::FormatID::R16_USCALED;
3123         case angle::FormatID::R16G16_SINT:
3124             return angle::FormatID::R16G16_UINT;
3125         case angle::FormatID::R16G16_SNORM:
3126             return angle::FormatID::R16G16_UNORM;
3127         case angle::FormatID::R16G16_SSCALED:
3128             return angle::FormatID::R16G16_USCALED;
3129         case angle::FormatID::R16G16B16_SINT:
3130             return angle::FormatID::R16G16B16_UINT;
3131         case angle::FormatID::R16G16B16_SNORM:
3132             return angle::FormatID::R16G16B16_UNORM;
3133         case angle::FormatID::R16G16B16_SSCALED:
3134             return angle::FormatID::R16G16B16_USCALED;
3135         case angle::FormatID::R16G16B16A16_SINT:
3136             return angle::FormatID::R16G16B16A16_UINT;
3137         case angle::FormatID::R16G16B16A16_SNORM:
3138             return angle::FormatID::R16G16B16A16_UNORM;
3139         case angle::FormatID::R16G16B16A16_SSCALED:
3140             return angle::FormatID::R16G16B16A16_USCALED;
3141         // 2 byte unsigned to signed
3142         case angle::FormatID::R16_UINT:
3143             return angle::FormatID::R16_SINT;
3144         case angle::FormatID::R16_UNORM:
3145             return angle::FormatID::R16_SNORM;
3146         case angle::FormatID::R16_USCALED:
3147             return angle::FormatID::R16_SSCALED;
3148         case angle::FormatID::R16G16_UINT:
3149             return angle::FormatID::R16G16_SINT;
3150         case angle::FormatID::R16G16_UNORM:
3151             return angle::FormatID::R16G16_SNORM;
3152         case angle::FormatID::R16G16_USCALED:
3153             return angle::FormatID::R16G16_SSCALED;
3154         case angle::FormatID::R16G16B16_UINT:
3155             return angle::FormatID::R16G16B16_SINT;
3156         case angle::FormatID::R16G16B16_UNORM:
3157             return angle::FormatID::R16G16B16_SNORM;
3158         case angle::FormatID::R16G16B16_USCALED:
3159             return angle::FormatID::R16G16B16_SSCALED;
3160         case angle::FormatID::R16G16B16A16_UINT:
3161             return angle::FormatID::R16G16B16A16_SINT;
3162         case angle::FormatID::R16G16B16A16_UNORM:
3163             return angle::FormatID::R16G16B16A16_SNORM;
3164         case angle::FormatID::R16G16B16A16_USCALED:
3165             return angle::FormatID::R16G16B16A16_SSCALED;
3166         // 4 byte signed to unsigned
3167         case angle::FormatID::R32_SINT:
3168             return angle::FormatID::R32_UINT;
3169         case angle::FormatID::R32_SNORM:
3170             return angle::FormatID::R32_UNORM;
3171         case angle::FormatID::R32_SSCALED:
3172             return angle::FormatID::R32_USCALED;
3173         case angle::FormatID::R32G32_SINT:
3174             return angle::FormatID::R32G32_UINT;
3175         case angle::FormatID::R32G32_SNORM:
3176             return angle::FormatID::R32G32_UNORM;
3177         case angle::FormatID::R32G32_SSCALED:
3178             return angle::FormatID::R32G32_USCALED;
3179         case angle::FormatID::R32G32B32_SINT:
3180             return angle::FormatID::R32G32B32_UINT;
3181         case angle::FormatID::R32G32B32_SNORM:
3182             return angle::FormatID::R32G32B32_UNORM;
3183         case angle::FormatID::R32G32B32_SSCALED:
3184             return angle::FormatID::R32G32B32_USCALED;
3185         case angle::FormatID::R32G32B32A32_SINT:
3186             return angle::FormatID::R32G32B32A32_UINT;
3187         case angle::FormatID::R32G32B32A32_SNORM:
3188             return angle::FormatID::R32G32B32A32_UNORM;
3189         case angle::FormatID::R32G32B32A32_SSCALED:
3190             return angle::FormatID::R32G32B32A32_USCALED;
3191         // 4 byte unsigned to signed
3192         case angle::FormatID::R32_UINT:
3193             return angle::FormatID::R32_SINT;
3194         case angle::FormatID::R32_UNORM:
3195             return angle::FormatID::R32_SNORM;
3196         case angle::FormatID::R32_USCALED:
3197             return angle::FormatID::R32_SSCALED;
3198         case angle::FormatID::R32G32_UINT:
3199             return angle::FormatID::R32G32_SINT;
3200         case angle::FormatID::R32G32_UNORM:
3201             return angle::FormatID::R32G32_SNORM;
3202         case angle::FormatID::R32G32_USCALED:
3203             return angle::FormatID::R32G32_SSCALED;
3204         case angle::FormatID::R32G32B32_UINT:
3205             return angle::FormatID::R32G32B32_SINT;
3206         case angle::FormatID::R32G32B32_UNORM:
3207             return angle::FormatID::R32G32B32_SNORM;
3208         case angle::FormatID::R32G32B32_USCALED:
3209             return angle::FormatID::R32G32B32_SSCALED;
3210         case angle::FormatID::R32G32B32A32_UINT:
3211             return angle::FormatID::R32G32B32A32_SINT;
3212         case angle::FormatID::R32G32B32A32_UNORM:
3213             return angle::FormatID::R32G32B32A32_SNORM;
3214         case angle::FormatID::R32G32B32A32_USCALED:
3215             return angle::FormatID::R32G32B32A32_SSCALED;
3216         // 1010102 signed to unsigned
3217         case angle::FormatID::R10G10B10A2_SINT:
3218             return angle::FormatID::R10G10B10A2_UINT;
3219         case angle::FormatID::R10G10B10A2_SSCALED:
3220             return angle::FormatID::R10G10B10A2_USCALED;
3221         case angle::FormatID::R10G10B10A2_SNORM:
3222             return angle::FormatID::R10G10B10A2_UNORM;
3223         // 1010102 unsigned to signed
3224         case angle::FormatID::R10G10B10A2_UINT:
3225             return angle::FormatID::R10G10B10A2_SINT;
3226         case angle::FormatID::R10G10B10A2_USCALED:
3227             return angle::FormatID::R10G10B10A2_SSCALED;
3228         case angle::FormatID::R10G10B10A2_UNORM:
3229             return angle::FormatID::R10G10B10A2_SNORM;
3230         default:
3231             UNREACHABLE();
3232             return angle::FormatID::NONE;
3233     }
3234 }
3235 
ValidES3InternalFormat(GLenum internalFormat)3236 bool ValidES3InternalFormat(GLenum internalFormat)
3237 {
3238     const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
3239     return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
3240 }
3241 
VertexFormat(GLenum typeIn,GLboolean normalizedIn,GLuint componentsIn,bool pureIntegerIn)3242 VertexFormat::VertexFormat(GLenum typeIn,
3243                            GLboolean normalizedIn,
3244                            GLuint componentsIn,
3245                            bool pureIntegerIn)
3246     : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
3247 {
3248     // float -> !normalized
3249     ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
3250            normalized == GL_FALSE);
3251 }
3252 }  // namespace gl
3253