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