• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2014 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 #include "libANGLE/Caps.h"
8 
9 #include "common/angleutils.h"
10 #include "common/debug.h"
11 
12 #include "libANGLE/formatutils.h"
13 
14 #include "angle_gl.h"
15 
16 #include <algorithm>
17 #include <sstream>
18 
InsertExtensionString(const std::string & extension,bool supported,std::vector<std::string> * extensionVector)19 static void InsertExtensionString(const std::string &extension,
20                                   bool supported,
21                                   std::vector<std::string> *extensionVector)
22 {
23     if (supported)
24     {
25         extensionVector->push_back(extension);
26     }
27 }
28 
29 namespace gl
30 {
31 
32 TextureCaps::TextureCaps() = default;
33 
34 TextureCaps::TextureCaps(const TextureCaps &other) = default;
35 
36 TextureCaps &TextureCaps::operator=(const TextureCaps &other) = default;
37 
38 TextureCaps::~TextureCaps() = default;
39 
getMaxSamples() const40 GLuint TextureCaps::getMaxSamples() const
41 {
42     return !sampleCounts.empty() ? *sampleCounts.rbegin() : 0;
43 }
44 
getNearestSamples(GLuint requestedSamples) const45 GLuint TextureCaps::getNearestSamples(GLuint requestedSamples) const
46 {
47     if (requestedSamples == 0)
48     {
49         return 0;
50     }
51 
52     for (SupportedSampleSet::const_iterator i = sampleCounts.begin(); i != sampleCounts.end(); i++)
53     {
54         GLuint samples = *i;
55         if (samples >= requestedSamples)
56         {
57             return samples;
58         }
59     }
60 
61     return 0;
62 }
63 
GenerateMinimumTextureCaps(GLenum sizedInternalFormat,const Version & clientVersion,const Extensions & extensions)64 TextureCaps GenerateMinimumTextureCaps(GLenum sizedInternalFormat,
65                                        const Version &clientVersion,
66                                        const Extensions &extensions)
67 {
68     TextureCaps caps;
69 
70     const InternalFormat &internalFormatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
71     caps.texturable        = internalFormatInfo.textureSupport(clientVersion, extensions);
72     caps.filterable        = internalFormatInfo.filterSupport(clientVersion, extensions);
73     caps.textureAttachment = internalFormatInfo.textureAttachmentSupport(clientVersion, extensions);
74     caps.renderbuffer      = internalFormatInfo.renderbufferSupport(clientVersion, extensions);
75     caps.blendable         = internalFormatInfo.blendSupport(clientVersion, extensions);
76 
77     caps.sampleCounts.insert(0);
78     if (internalFormatInfo.isRequiredRenderbufferFormat(clientVersion))
79     {
80         if ((clientVersion.major >= 3 && clientVersion.minor >= 1) ||
81             (clientVersion.major >= 3 && !internalFormatInfo.isInt()))
82         {
83             caps.sampleCounts.insert(4);
84         }
85     }
86 
87     return caps;
88 }
89 
TextureCapsMap()90 TextureCapsMap::TextureCapsMap() {}
91 
~TextureCapsMap()92 TextureCapsMap::~TextureCapsMap() {}
93 
insert(GLenum internalFormat,const TextureCaps & caps)94 void TextureCapsMap::insert(GLenum internalFormat, const TextureCaps &caps)
95 {
96     angle::FormatID formatID = angle::Format::InternalFormatToID(internalFormat);
97     get(formatID)            = caps;
98 }
99 
clear()100 void TextureCapsMap::clear()
101 {
102     mFormatData.fill(TextureCaps());
103 }
104 
get(GLenum internalFormat) const105 const TextureCaps &TextureCapsMap::get(GLenum internalFormat) const
106 {
107     angle::FormatID formatID = angle::Format::InternalFormatToID(internalFormat);
108     return get(formatID);
109 }
110 
get(angle::FormatID formatID) const111 const TextureCaps &TextureCapsMap::get(angle::FormatID formatID) const
112 {
113     return mFormatData[formatID];
114 }
115 
get(angle::FormatID formatID)116 TextureCaps &TextureCapsMap::get(angle::FormatID formatID)
117 {
118     return mFormatData[formatID];
119 }
120 
set(angle::FormatID formatID,const TextureCaps & caps)121 void TextureCapsMap::set(angle::FormatID formatID, const TextureCaps &caps)
122 {
123     get(formatID) = caps;
124 }
125 
InitMinimumTextureCapsMap(const Version & clientVersion,const Extensions & extensions,TextureCapsMap * capsMap)126 void InitMinimumTextureCapsMap(const Version &clientVersion,
127                                const Extensions &extensions,
128                                TextureCapsMap *capsMap)
129 {
130     for (GLenum internalFormat : GetAllSizedInternalFormats())
131     {
132         capsMap->insert(internalFormat,
133                         GenerateMinimumTextureCaps(internalFormat, clientVersion, extensions));
134     }
135 }
136 
137 Extensions::Extensions() = default;
138 
139 Extensions::Extensions(const Extensions &other) = default;
140 
141 Extensions &Extensions::operator=(const Extensions &other) = default;
142 
getStrings() const143 std::vector<std::string> Extensions::getStrings() const
144 {
145     std::vector<std::string> extensionStrings;
146 
147     for (const auto &extensionInfo : GetExtensionInfoMap())
148     {
149         if (this->*(extensionInfo.second.ExtensionsMember))
150         {
151             extensionStrings.push_back(extensionInfo.first);
152         }
153     }
154 
155     return extensionStrings;
156 }
157 
158 Limitations::Limitations()                         = default;
159 Limitations::Limitations(const Limitations &other) = default;
160 
161 Limitations &Limitations::operator=(const Limitations &other) = default;
162 
GetFormatSupportBase(const TextureCapsMap & textureCaps,const GLenum * requiredFormats,size_t requiredFormatsSize,bool requiresTexturing,bool requiresFiltering,bool requiresAttachingTexture,bool requiresRenderbufferSupport,bool requiresBlending)163 static bool GetFormatSupportBase(const TextureCapsMap &textureCaps,
164                                  const GLenum *requiredFormats,
165                                  size_t requiredFormatsSize,
166                                  bool requiresTexturing,
167                                  bool requiresFiltering,
168                                  bool requiresAttachingTexture,
169                                  bool requiresRenderbufferSupport,
170                                  bool requiresBlending)
171 {
172     for (size_t i = 0; i < requiredFormatsSize; i++)
173     {
174         const TextureCaps &cap = textureCaps.get(requiredFormats[i]);
175         if (requiresTexturing && !cap.texturable)
176         {
177             return false;
178         }
179 
180         if (requiresFiltering && !cap.filterable)
181         {
182             return false;
183         }
184 
185         if (requiresAttachingTexture && !cap.textureAttachment)
186         {
187             return false;
188         }
189 
190         if (requiresRenderbufferSupport && !cap.renderbuffer)
191         {
192             return false;
193         }
194 
195         if (requiresBlending && !cap.blendable)
196         {
197             return false;
198         }
199     }
200 
201     return true;
202 }
203 
204 template <size_t N>
GetFormatSupport(const TextureCapsMap & textureCaps,const GLenum (& requiredFormats)[N],bool requiresTexturing,bool requiresFiltering,bool requiresAttachingTexture,bool requiresRenderbufferSupport,bool requiresBlending)205 static bool GetFormatSupport(const TextureCapsMap &textureCaps,
206                              const GLenum (&requiredFormats)[N],
207                              bool requiresTexturing,
208                              bool requiresFiltering,
209                              bool requiresAttachingTexture,
210                              bool requiresRenderbufferSupport,
211                              bool requiresBlending)
212 {
213     return GetFormatSupportBase(textureCaps, requiredFormats, N, requiresTexturing,
214                                 requiresFiltering, requiresAttachingTexture,
215                                 requiresRenderbufferSupport, requiresBlending);
216 }
217 
218 // Check for GL_OES_packed_depth_stencil support
DeterminePackedDepthStencilSupport(const TextureCapsMap & textureCaps)219 static bool DeterminePackedDepthStencilSupport(const TextureCapsMap &textureCaps)
220 {
221     constexpr GLenum requiredFormats[] = {
222         GL_DEPTH24_STENCIL8,
223     };
224 
225     return GetFormatSupport(textureCaps, requiredFormats, false, false, true, true, false);
226 }
227 
228 // Checks for GL_NV_read_depth support
DetermineReadDepthSupport(const TextureCapsMap & textureCaps)229 static bool DetermineReadDepthSupport(const TextureCapsMap &textureCaps)
230 {
231     constexpr GLenum requiredFormats[] = {
232         GL_DEPTH_COMPONENT16,
233     };
234 
235     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, false, false);
236 }
237 
238 // Checks for GL_NV_read_stencil support
DetermineReadStencilSupport(const TextureCapsMap & textureCaps)239 static bool DetermineReadStencilSupport(const TextureCapsMap &textureCaps)
240 {
241     constexpr GLenum requiredFormats[] = {
242         GL_STENCIL_INDEX8,
243     };
244 
245     return GetFormatSupport(textureCaps, requiredFormats, false, false, true, false, false);
246 }
247 
248 // Checks for GL_NV_depth_buffer_float2 support
DetermineDepthBufferFloat2Support(const TextureCapsMap & textureCaps)249 static bool DetermineDepthBufferFloat2Support(const TextureCapsMap &textureCaps)
250 {
251     constexpr GLenum requiredFormats[] = {
252         GL_DEPTH_COMPONENT32F,
253         GL_DEPTH32F_STENCIL8,
254     };
255 
256     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, false, false);
257 }
258 
259 // Checks for GL_OES_rgb8_rgba8 support
DetermineRGB8AndRGBA8TextureSupport(const TextureCapsMap & textureCaps)260 static bool DetermineRGB8AndRGBA8TextureSupport(const TextureCapsMap &textureCaps)
261 {
262     constexpr GLenum requiredFormats[] = {
263         GL_RGB8,
264         GL_RGBA8,
265     };
266 
267     return GetFormatSupport(textureCaps, requiredFormats, false, false, false, true, false);
268 }
269 
270 // Checks for GL_EXT_texture_format_BGRA8888 support
DetermineBGRA8TextureSupport(const TextureCapsMap & textureCaps)271 static bool DetermineBGRA8TextureSupport(const TextureCapsMap &textureCaps)
272 {
273     constexpr GLenum requiredFormats[] = {
274         GL_BGRA8_EXT,
275     };
276 
277     return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true, false);
278 }
279 
280 // Checks for GL_EXT_read_format_bgra support
DetermineBGRAReadFormatSupport(const TextureCapsMap & textureCaps)281 static bool DetermineBGRAReadFormatSupport(const TextureCapsMap &textureCaps)
282 {
283     constexpr GLenum requiredFormats[] = {
284         GL_BGRA8_EXT,
285         // TODO(http://anglebug.com/4302): GL_EXT_read_format_bgra specifies 2 more types, which are
286         // currently ignored. The equivalent formats would be: GL_BGRA4_ANGLEX, GL_BGR5_A1_ANGLEX
287     };
288 
289     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, true, false);
290 }
291 
292 // Checks for GL_OES_color_buffer_half_float support
DetermineColorBufferHalfFloatSupport(const TextureCapsMap & textureCaps)293 static bool DetermineColorBufferHalfFloatSupport(const TextureCapsMap &textureCaps)
294 {
295     // EXT_color_buffer_half_float issue #2 states that an implementation doesn't need to support
296     // rendering to any of the formats but is expected to be able to render to at least one. WebGL
297     // requires that at least RGBA16F is renderable so we make the same requirement.
298     constexpr GLenum requiredFormats[] = {
299         GL_RGBA16F,
300     };
301 
302     return GetFormatSupport(textureCaps, requiredFormats, false, false, true, true, false);
303 }
304 
305 // Checks for GL_OES_texture_half_float support
DetermineHalfFloatTextureSupport(const TextureCapsMap & textureCaps)306 static bool DetermineHalfFloatTextureSupport(const TextureCapsMap &textureCaps)
307 {
308     constexpr GLenum requiredFormats[] = {
309         GL_RGBA16F, GL_RGB16F, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE16F_EXT, GL_ALPHA16F_EXT,
310     };
311 
312     return GetFormatSupport(textureCaps, requiredFormats, true, false, false, false, false);
313 }
314 
315 // Checks for GL_OES_texture_half_float_linear support
DetermineHalfFloatTextureFilteringSupport(const TextureCapsMap & textureCaps,bool checkLegacyFormats)316 static bool DetermineHalfFloatTextureFilteringSupport(const TextureCapsMap &textureCaps,
317                                                       bool checkLegacyFormats)
318 {
319     constexpr GLenum requiredFormats[] = {GL_RGBA16F, GL_RGB16F};
320     // If GL_OES_texture_half_float is present, this extension must also support legacy formats
321     // introduced by that extension
322     constexpr GLenum requiredFormatsES2[] = {GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE16F_EXT,
323                                              GL_ALPHA16F_EXT};
324 
325     if (checkLegacyFormats &&
326         !GetFormatSupport(textureCaps, requiredFormatsES2, false, true, false, false, false))
327     {
328         return false;
329     }
330 
331     return GetFormatSupport(textureCaps, requiredFormats, false, true, false, false, false);
332 }
333 
334 // Checks for GL_OES_texture_float support
DetermineFloatTextureSupport(const TextureCapsMap & textureCaps)335 static bool DetermineFloatTextureSupport(const TextureCapsMap &textureCaps)
336 {
337     constexpr GLenum requiredFormats[] = {
338         GL_RGBA32F, GL_RGB32F, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE32F_EXT, GL_ALPHA32F_EXT,
339     };
340 
341     return GetFormatSupport(textureCaps, requiredFormats, true, false, false, false, false);
342 }
343 
344 // Checks for GL_OES_texture_float_linear support
DetermineFloatTextureFilteringSupport(const TextureCapsMap & textureCaps,bool checkLegacyFormats)345 static bool DetermineFloatTextureFilteringSupport(const TextureCapsMap &textureCaps,
346                                                   bool checkLegacyFormats)
347 {
348     constexpr GLenum requiredFormats[] = {
349         GL_RGBA32F,
350         GL_RGB32F,
351     };
352     // If GL_OES_texture_float is present, this extension must also support legacy formats
353     // introduced by that extension
354     constexpr GLenum requiredFormatsES2[] = {
355         GL_LUMINANCE_ALPHA32F_EXT,
356         GL_LUMINANCE32F_EXT,
357         GL_ALPHA32F_EXT,
358     };
359 
360     if (checkLegacyFormats &&
361         !GetFormatSupport(textureCaps, requiredFormatsES2, false, true, false, false, false))
362     {
363         return false;
364     }
365 
366     return GetFormatSupport(textureCaps, requiredFormats, false, true, false, false, false);
367 }
368 
369 // Checks for GL_EXT_texture_rg support
DetermineRGTextureSupport(const TextureCapsMap & textureCaps,bool checkHalfFloatFormats,bool checkFloatFormats)370 static bool DetermineRGTextureSupport(const TextureCapsMap &textureCaps,
371                                       bool checkHalfFloatFormats,
372                                       bool checkFloatFormats)
373 {
374     constexpr GLenum requiredFormats[] = {
375         GL_R8,
376         GL_RG8,
377     };
378     constexpr GLenum requiredHalfFloatFormats[] = {
379         GL_R16F,
380         GL_RG16F,
381     };
382     constexpr GLenum requiredFloatFormats[] = {
383         GL_R32F,
384         GL_RG32F,
385     };
386 
387     if (checkHalfFloatFormats &&
388         !GetFormatSupport(textureCaps, requiredHalfFloatFormats, true, false, false, false, false))
389     {
390         return false;
391     }
392 
393     if (checkFloatFormats &&
394         !GetFormatSupport(textureCaps, requiredFloatFormats, true, false, false, false, false))
395     {
396         return false;
397     }
398 
399     return GetFormatSupport(textureCaps, requiredFormats, true, true, true, true, false);
400 }
401 
DetermineTextureFormat2101010Support(const TextureCapsMap & textureCaps)402 static bool DetermineTextureFormat2101010Support(const TextureCapsMap &textureCaps)
403 {
404     // GL_EXT_texture_type_2_10_10_10_REV specifies both RGBA and RGB support whereas desktop GL
405     // only specifies RGBA support, so check both RGBA and RGB before marking as supported.
406     constexpr GLenum requiredFormats[] = {
407         GL_RGB10_A2,
408         GL_RGB10_UNORM_ANGLEX,
409     };
410 
411     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
412 }
413 
414 // Check for GL_EXT_texture_compression_dxt1 support
DetermineDXT1TextureSupport(const TextureCapsMap & textureCaps)415 static bool DetermineDXT1TextureSupport(const TextureCapsMap &textureCaps)
416 {
417     constexpr GLenum requiredFormats[] = {
418         GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
419         GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
420     };
421 
422     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
423 }
424 
425 // Check for GL_ANGLE_texture_compression_dxt3 support
DetermineDXT3TextureSupport(const TextureCapsMap & textureCaps)426 static bool DetermineDXT3TextureSupport(const TextureCapsMap &textureCaps)
427 {
428     constexpr GLenum requiredFormats[] = {
429         GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE,
430     };
431 
432     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
433 }
434 
435 // Check for GL_ANGLE_texture_compression_dxt5 support
DetermineDXT5TextureSupport(const TextureCapsMap & textureCaps)436 static bool DetermineDXT5TextureSupport(const TextureCapsMap &textureCaps)
437 {
438     constexpr GLenum requiredFormats[] = {
439         GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE,
440     };
441 
442     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
443 }
444 
445 // Check for GL_EXT_texture_compression_s3tc_srgb support
DetermineS3TCsRGBTextureSupport(const TextureCapsMap & textureCaps)446 static bool DetermineS3TCsRGBTextureSupport(const TextureCapsMap &textureCaps)
447 {
448     constexpr GLenum requiredFormats[] = {
449         GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,
450         GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,
451         GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,
452         GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,
453     };
454 
455     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
456 }
457 
458 // Check for GL_KHR_texture_compression_astc_ldr support
DetermineASTCLDRTextureSupport(const TextureCapsMap & textureCaps)459 static bool DetermineASTCLDRTextureSupport(const TextureCapsMap &textureCaps)
460 {
461     constexpr GLenum requiredFormats[] = {
462         GL_COMPRESSED_RGBA_ASTC_4x4_KHR,           GL_COMPRESSED_RGBA_ASTC_5x4_KHR,
463         GL_COMPRESSED_RGBA_ASTC_5x5_KHR,           GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
464         GL_COMPRESSED_RGBA_ASTC_6x6_KHR,           GL_COMPRESSED_RGBA_ASTC_8x5_KHR,
465         GL_COMPRESSED_RGBA_ASTC_8x6_KHR,           GL_COMPRESSED_RGBA_ASTC_8x8_KHR,
466         GL_COMPRESSED_RGBA_ASTC_10x5_KHR,          GL_COMPRESSED_RGBA_ASTC_10x6_KHR,
467         GL_COMPRESSED_RGBA_ASTC_10x8_KHR,          GL_COMPRESSED_RGBA_ASTC_10x10_KHR,
468         GL_COMPRESSED_RGBA_ASTC_12x10_KHR,         GL_COMPRESSED_RGBA_ASTC_12x12_KHR,
469         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,   GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,
470         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,   GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,
471         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,   GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,
472         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,   GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,
473         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,  GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,
474         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,  GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,
475         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR,
476     };
477 
478     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
479 }
480 
481 // Check for GL_OES_texture_compression_astc support
DetermineASTCOESTExtureSupport(const TextureCapsMap & textureCaps)482 static bool DetermineASTCOESTExtureSupport(const TextureCapsMap &textureCaps)
483 {
484     if (!DetermineASTCLDRTextureSupport(textureCaps))
485     {
486         return false;
487     }
488 
489     // The OES version of the extension also requires the 3D ASTC formats
490     constexpr GLenum requiredFormats[] = {
491         GL_COMPRESSED_RGBA_ASTC_3x3x3_OES,         GL_COMPRESSED_RGBA_ASTC_4x3x3_OES,
492         GL_COMPRESSED_RGBA_ASTC_4x4x3_OES,         GL_COMPRESSED_RGBA_ASTC_4x4x4_OES,
493         GL_COMPRESSED_RGBA_ASTC_5x4x4_OES,         GL_COMPRESSED_RGBA_ASTC_5x5x4_OES,
494         GL_COMPRESSED_RGBA_ASTC_5x5x5_OES,         GL_COMPRESSED_RGBA_ASTC_6x5x5_OES,
495         GL_COMPRESSED_RGBA_ASTC_6x6x5_OES,         GL_COMPRESSED_RGBA_ASTC_6x6x6_OES,
496         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES,
497         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES,
498         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES,
499         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES,
500         GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES,
501     };
502 
503     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
504 }
505 
506 // Check for GL_ETC1_RGB8_OES support
DetermineETC1RGB8TextureSupport(const TextureCapsMap & textureCaps)507 static bool DetermineETC1RGB8TextureSupport(const TextureCapsMap &textureCaps)
508 {
509     constexpr GLenum requiredFormats[] = {
510         GL_ETC1_RGB8_OES,
511     };
512 
513     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
514 }
515 
516 // Check for OES_compressed_ETC2_RGB8_texture support
DetermineETC2RGB8TextureSupport(const TextureCapsMap & textureCaps)517 static bool DetermineETC2RGB8TextureSupport(const TextureCapsMap &textureCaps)
518 {
519     constexpr GLenum requiredFormats[] = {
520         GL_COMPRESSED_RGB8_ETC2,
521     };
522 
523     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
524 }
525 
526 // Check for OES_compressed_ETC2_sRGB8_texture support
DetermineETC2sRGB8TextureSupport(const TextureCapsMap & textureCaps)527 static bool DetermineETC2sRGB8TextureSupport(const TextureCapsMap &textureCaps)
528 {
529     constexpr GLenum requiredFormats[] = {
530         GL_COMPRESSED_SRGB8_ETC2,
531     };
532 
533     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
534 }
535 
536 // Check for OES_compressed_ETC2_punchthroughA_RGBA8_texture support
DetermineETC2PunchthroughARGB8TextureSupport(const TextureCapsMap & textureCaps)537 static bool DetermineETC2PunchthroughARGB8TextureSupport(const TextureCapsMap &textureCaps)
538 {
539     constexpr GLenum requiredFormats[] = {
540         GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
541     };
542 
543     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
544 }
545 
546 // Check for OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture support
DetermineETC2PunchthroughAsRGB8AlphaTextureSupport(const TextureCapsMap & textureCaps)547 static bool DetermineETC2PunchthroughAsRGB8AlphaTextureSupport(const TextureCapsMap &textureCaps)
548 {
549     constexpr GLenum requiredFormats[] = {
550         GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
551     };
552 
553     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
554 }
555 
556 // Check for OES_compressed_ETC2_RGBA8_texture support
DetermineETC2RGBA8TextureSupport(const TextureCapsMap & textureCaps)557 static bool DetermineETC2RGBA8TextureSupport(const TextureCapsMap &textureCaps)
558 {
559     constexpr GLenum requiredFormats[] = {
560         GL_COMPRESSED_RGBA8_ETC2_EAC,
561     };
562 
563     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
564 }
565 
566 // Check for OES_compressed_ETC2_sRGB8_alpha8_texture support
DetermineETC2sRGB8Alpha8TextureSupport(const TextureCapsMap & textureCaps)567 static bool DetermineETC2sRGB8Alpha8TextureSupport(const TextureCapsMap &textureCaps)
568 {
569     constexpr GLenum requiredFormats[] = {
570         GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,
571     };
572 
573     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
574 }
575 
576 // Check for OES_compressed_EAC_R11_unsigned_texture support
DetermineEACR11UnsignedTextureSupport(const TextureCapsMap & textureCaps)577 static bool DetermineEACR11UnsignedTextureSupport(const TextureCapsMap &textureCaps)
578 {
579     constexpr GLenum requiredFormats[] = {
580         GL_COMPRESSED_R11_EAC,
581     };
582 
583     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
584 }
585 
586 // Check for OES_compressed_EAC_R11_signed_texture support
DetermineEACR11SignedTextureSupport(const TextureCapsMap & textureCaps)587 static bool DetermineEACR11SignedTextureSupport(const TextureCapsMap &textureCaps)
588 {
589     constexpr GLenum requiredFormats[] = {
590         GL_COMPRESSED_SIGNED_R11_EAC,
591     };
592 
593     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
594 }
595 
596 // Check for OES_compressed_EAC_RG11_unsigned_texture support
DetermineEACRG11UnsignedTextureSupport(const TextureCapsMap & textureCaps)597 static bool DetermineEACRG11UnsignedTextureSupport(const TextureCapsMap &textureCaps)
598 {
599     constexpr GLenum requiredFormats[] = {
600         GL_COMPRESSED_RG11_EAC,
601     };
602 
603     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
604 }
605 
606 // Check for OES_compressed_EAC_RG11_signed_texture support
DetermineEACRG11SignedTextureSupport(const TextureCapsMap & textureCaps)607 static bool DetermineEACRG11SignedTextureSupport(const TextureCapsMap &textureCaps)
608 {
609     constexpr GLenum requiredFormats[] = {
610         GL_COMPRESSED_SIGNED_RG11_EAC,
611     };
612 
613     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
614 }
615 
616 // Check for GL_EXT_sRGB support
DetermineSRGBTextureSupport(const TextureCapsMap & textureCaps)617 static bool DetermineSRGBTextureSupport(const TextureCapsMap &textureCaps)
618 {
619     constexpr GLenum requiredFilterFormats[] = {
620         GL_SRGB8,
621         GL_SRGB8_ALPHA8,
622     };
623 
624     constexpr GLenum requiredRenderFormats[] = {
625         GL_SRGB8_ALPHA8,
626     };
627 
628     return GetFormatSupport(textureCaps, requiredFilterFormats, true, true, false, false, false) &&
629            GetFormatSupport(textureCaps, requiredRenderFormats, true, false, true, true, false);
630 }
631 
632 // Check for GL_EXT_texture_sRGB_R8 support
DetermineSRGBR8TextureSupport(const TextureCapsMap & textureCaps)633 static bool DetermineSRGBR8TextureSupport(const TextureCapsMap &textureCaps)
634 {
635     constexpr GLenum requiredFilterFormats[] = {GL_SR8_EXT};
636 
637     return GetFormatSupport(textureCaps, requiredFilterFormats, true, true, false, false, false);
638 }
639 
640 // Check for GL_EXT_texture_sRGB_RG8 support
DetermineSRGBRG8TextureSupport(const TextureCapsMap & textureCaps)641 static bool DetermineSRGBRG8TextureSupport(const TextureCapsMap &textureCaps)
642 {
643     constexpr GLenum requiredFilterFormats[] = {GL_SRG8_EXT};
644 
645     return GetFormatSupport(textureCaps, requiredFilterFormats, true, true, false, false, false);
646 }
647 
648 // Check for GL_ANGLE_depth_texture support
DetermineDepthTextureANGLESupport(const TextureCapsMap & textureCaps)649 static bool DetermineDepthTextureANGLESupport(const TextureCapsMap &textureCaps)
650 {
651     constexpr GLenum requiredFormats[] = {
652         GL_DEPTH_COMPONENT16,
653 #if !ANGLE_PLATFORM_IOS_FAMILY
654         // anglebug.com/6082
655         // TODO(dino): Temporarily Removing the need for GL_DEPTH_COMPONENT32_OES
656         // because it is not supported on iOS.
657         // TODO(dino): I think this needs to be a runtime check when running an iOS app on Mac.
658         GL_DEPTH_COMPONENT32_OES,
659 #endif
660         GL_DEPTH24_STENCIL8_OES,
661     };
662 
663     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, false, false);
664 }
665 
666 // Check for GL_OES_depth_texture support
DetermineDepthTextureOESSupport(const TextureCapsMap & textureCaps)667 static bool DetermineDepthTextureOESSupport(const TextureCapsMap &textureCaps)
668 {
669     constexpr GLenum requiredFormats[] = {
670         GL_DEPTH_COMPONENT16,
671 #if !ANGLE_PLATFORM_IOS_FAMILY
672         // anglebug.com/6082
673         // TODO(dino): Temporarily Removing the need for GL_DEPTH_COMPONENT32_OES
674         // because it is not supported on iOS.
675         // TODO(dino): I think this needs to be a runtime check when running an iOS app on Mac.
676         GL_DEPTH_COMPONENT32_OES,
677 #endif
678     };
679 
680     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, true, false);
681 }
682 
683 // Check for GL_OES_depth24
DetermineDepth24OESSupport(const TextureCapsMap & textureCaps)684 static bool DetermineDepth24OESSupport(const TextureCapsMap &textureCaps)
685 {
686     constexpr GLenum requiredFormats[] = {
687         GL_DEPTH_COMPONENT24_OES,
688     };
689 
690     return GetFormatSupport(textureCaps, requiredFormats, false, false, false, true, false);
691 }
692 
693 // Check for GL_OES_depth32 support
DetermineDepth32Support(const TextureCapsMap & textureCaps)694 static bool DetermineDepth32Support(const TextureCapsMap &textureCaps)
695 {
696     constexpr GLenum requiredFormats[] = {
697         GL_DEPTH_COMPONENT32_OES,
698     };
699 
700     return GetFormatSupport(textureCaps, requiredFormats, false, false, true, true, false);
701 }
702 
703 // Check for GL_CHROMIUM_color_buffer_float_rgb support
DetermineColorBufferFloatRGBSupport(const TextureCapsMap & textureCaps)704 static bool DetermineColorBufferFloatRGBSupport(const TextureCapsMap &textureCaps)
705 {
706     constexpr GLenum requiredFormats[] = {
707         GL_RGB32F,
708     };
709 
710     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, false, false);
711 }
712 
713 // Check for GL_CHROMIUM_color_buffer_float_rgba support
DetermineColorBufferFloatRGBASupport(const TextureCapsMap & textureCaps)714 static bool DetermineColorBufferFloatRGBASupport(const TextureCapsMap &textureCaps)
715 {
716     constexpr GLenum requiredFormats[] = {
717         GL_RGBA32F,
718     };
719 
720     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, true, false);
721 }
722 
723 // Check for GL_EXT_color_buffer_float support
DetermineColorBufferFloatSupport(const TextureCapsMap & textureCaps)724 static bool DetermineColorBufferFloatSupport(const TextureCapsMap &textureCaps)
725 {
726     constexpr GLenum nonBlendableFormats[] = {
727         GL_R32F,
728         GL_RG32F,
729         GL_RGBA32F,
730     };
731 
732     constexpr GLenum blendableFormats[] = {
733         GL_R16F,
734         GL_RG16F,
735         GL_RGBA16F,
736         GL_R11F_G11F_B10F,
737     };
738 
739     return GetFormatSupport(textureCaps, nonBlendableFormats, true, false, true, true, false) &&
740            GetFormatSupport(textureCaps, blendableFormats, true, false, true, true, true);
741 }
742 
743 // Check for GL_EXT_float_blend support
DetermineFloatBlendSupport(const TextureCapsMap & textureCaps)744 static bool DetermineFloatBlendSupport(const TextureCapsMap &textureCaps)
745 {
746     constexpr GLenum requiredFormats[] = {
747         GL_R32F,
748         GL_RG32F,
749         GL_RGBA32F,
750     };
751 
752     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, true, true);
753 }
754 
755 // Check for GL_EXT_texture_norm16 support
DetermineTextureNorm16Support(const TextureCapsMap & textureCaps)756 static bool DetermineTextureNorm16Support(const TextureCapsMap &textureCaps)
757 {
758     constexpr GLenum requiredFilterFormats[] = {
759         GL_R16_EXT,       GL_RG16_EXT,       GL_RGB16_EXT,       GL_RGBA16_EXT,
760         GL_R16_SNORM_EXT, GL_RG16_SNORM_EXT, GL_RGB16_SNORM_EXT, GL_RGBA16_SNORM_EXT,
761     };
762 
763     constexpr GLenum requiredRenderFormats[] = {
764         GL_R16_EXT,
765         GL_RG16_EXT,
766         GL_RGBA16_EXT,
767     };
768 
769     return GetFormatSupport(textureCaps, requiredFilterFormats, true, true, false, false, false) &&
770            GetFormatSupport(textureCaps, requiredRenderFormats, true, false, true, true, false);
771 }
772 
773 // Check for EXT_texture_compression_rgtc support
DetermineRGTCTextureSupport(const TextureCapsMap & textureCaps)774 static bool DetermineRGTCTextureSupport(const TextureCapsMap &textureCaps)
775 {
776     constexpr GLenum requiredFormats[] = {
777         GL_COMPRESSED_RED_RGTC1_EXT, GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,
778         GL_COMPRESSED_RED_GREEN_RGTC2_EXT, GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT};
779 
780     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
781 }
782 
783 // Check for EXT_texture_compression_bptc support
DetermineBPTCTextureSupport(const TextureCapsMap & textureCaps)784 static bool DetermineBPTCTextureSupport(const TextureCapsMap &textureCaps)
785 {
786     constexpr GLenum requiredFormats[] = {
787         GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,
788         GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT};
789 
790     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
791 }
792 
793 // Check for GL_IMG_texture_compression_pvrtc support
DeterminePVRTCTextureSupport(const TextureCapsMap & textureCaps)794 static bool DeterminePVRTCTextureSupport(const TextureCapsMap &textureCaps)
795 {
796     constexpr GLenum requiredFormats[] = {
797         GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
798         GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG};
799 
800     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
801 }
802 
803 // Check for GL_EXT_pvrtc_sRGB support
DeterminePVRTCsRGBTextureSupport(const TextureCapsMap & textureCaps)804 static bool DeterminePVRTCsRGBTextureSupport(const TextureCapsMap &textureCaps)
805 {
806     constexpr GLenum requiredFormats[] = {
807         GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT,
808         GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT};
809 
810     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
811 }
812 
DetermineCompressedTextureETCSupport(const TextureCapsMap & textureCaps)813 bool DetermineCompressedTextureETCSupport(const TextureCapsMap &textureCaps)
814 {
815     constexpr GLenum requiredFormats[] = {GL_COMPRESSED_R11_EAC,
816                                           GL_COMPRESSED_SIGNED_R11_EAC,
817                                           GL_COMPRESSED_RG11_EAC,
818                                           GL_COMPRESSED_SIGNED_RG11_EAC,
819                                           GL_COMPRESSED_RGB8_ETC2,
820                                           GL_COMPRESSED_SRGB8_ETC2,
821                                           GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,
822                                           GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,
823                                           GL_COMPRESSED_RGBA8_ETC2_EAC,
824                                           GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC};
825 
826     return GetFormatSupport(textureCaps, requiredFormats, true, true, false, false, false);
827 }
828 
829 // Checks for GL_OES_texture_stencil8 support
DetermineStencilIndex8Support(const TextureCapsMap & textureCaps)830 static bool DetermineStencilIndex8Support(const TextureCapsMap &textureCaps)
831 {
832     constexpr GLenum requiredFormats[] = {
833         GL_STENCIL_INDEX8,
834     };
835 
836     return GetFormatSupport(textureCaps, requiredFormats, true, false, true, false, false);
837 }
838 
839 // Checks for GL_QCOM_render_shared_exponent support
DetermineRenderSharedExponentSupport(const TextureCapsMap & textureCaps)840 static bool DetermineRenderSharedExponentSupport(const TextureCapsMap &textureCaps)
841 {
842     constexpr GLenum requiredFormats[] = {
843         GL_RGB9_E5,
844     };
845 
846     return GetFormatSupport(textureCaps, requiredFormats, false, false, true, true, true);
847 }
848 
DetermineRenderSnormSupport(const TextureCapsMap & textureCaps,bool textureNorm16EXT)849 static bool DetermineRenderSnormSupport(const TextureCapsMap &textureCaps, bool textureNorm16EXT)
850 {
851     constexpr GLenum requiredSnorm8Formats[] = {
852         GL_R8_SNORM,
853         GL_RG8_SNORM,
854         GL_RGBA8_SNORM,
855     };
856 
857     constexpr GLenum requiredSnorm16Formats[] = {
858         GL_R16_SNORM_EXT,
859         GL_RG16_SNORM_EXT,
860         GL_RGBA16_SNORM_EXT,
861     };
862 
863     if (textureNorm16EXT &&
864         !GetFormatSupport(textureCaps, requiredSnorm16Formats, false, false, true, true, true))
865     {
866         return false;
867     }
868 
869     return GetFormatSupport(textureCaps, requiredSnorm8Formats, false, false, true, true, true);
870 }
871 
setTextureExtensionSupport(const TextureCapsMap & textureCaps)872 void Extensions::setTextureExtensionSupport(const TextureCapsMap &textureCaps)
873 {
874     // TODO(ynovikov): rgb8Rgba8OES, colorBufferHalfFloatEXT, textureHalfFloatOES,
875     // textureHalfFloatLinearOES, textureFloatOES, textureFloatLinearOES, textureRgEXT, sRGB,
876     // colorBufferFloatRgbCHROMIUM, colorBufferFloatRgbaCHROMIUM and colorBufferFloatEXT were
877     // verified. Verify the rest.
878     packedDepthStencilOES    = DeterminePackedDepthStencilSupport(textureCaps);
879     rgb8Rgba8OES             = DetermineRGB8AndRGBA8TextureSupport(textureCaps);
880     readDepthNV              = DetermineReadDepthSupport(textureCaps);
881     readStencilNV            = DetermineReadStencilSupport(textureCaps);
882     depthBufferFloat2NV      = DetermineDepthBufferFloat2Support(textureCaps);
883     textureFormatBGRA8888EXT = DetermineBGRA8TextureSupport(textureCaps);
884     readFormatBgraEXT        = DetermineBGRAReadFormatSupport(textureCaps);
885     textureHalfFloatOES      = DetermineHalfFloatTextureSupport(textureCaps);
886     textureHalfFloatLinearOES =
887         DetermineHalfFloatTextureFilteringSupport(textureCaps, textureHalfFloatOES);
888     textureFloatOES       = DetermineFloatTextureSupport(textureCaps);
889     textureFloatLinearOES = DetermineFloatTextureFilteringSupport(textureCaps, textureFloatOES);
890     textureRgEXT = DetermineRGTextureSupport(textureCaps, textureHalfFloatOES, textureFloatOES);
891     colorBufferHalfFloatEXT =
892         textureHalfFloatOES && DetermineColorBufferHalfFloatSupport(textureCaps);
893     textureType2101010REVEXT      = DetermineTextureFormat2101010Support(textureCaps);
894     textureCompressionDxt1EXT     = DetermineDXT1TextureSupport(textureCaps);
895     textureCompressionDxt3ANGLE   = DetermineDXT3TextureSupport(textureCaps);
896     textureCompressionDxt5ANGLE   = DetermineDXT5TextureSupport(textureCaps);
897     textureCompressionS3tcSrgbEXT = DetermineS3TCsRGBTextureSupport(textureCaps);
898     textureCompressionAstcLdrKHR  = DetermineASTCLDRTextureSupport(textureCaps);
899     textureCompressionAstcOES     = DetermineASTCOESTExtureSupport(textureCaps);
900     compressedETC1RGB8TextureOES  = DetermineETC1RGB8TextureSupport(textureCaps);
901     compressedETC2RGB8TextureOES  = DetermineETC2RGB8TextureSupport(textureCaps);
902     compressedETC2SRGB8TextureOES = DetermineETC2sRGB8TextureSupport(textureCaps);
903     compressedETC2PunchthroughARGBA8TextureOES =
904         DetermineETC2PunchthroughARGB8TextureSupport(textureCaps);
905     compressedETC2PunchthroughASRGB8AlphaTextureOES =
906         DetermineETC2PunchthroughAsRGB8AlphaTextureSupport(textureCaps);
907     compressedETC2RGBA8TextureOES       = DetermineETC2RGBA8TextureSupport(textureCaps);
908     compressedETC2SRGB8Alpha8TextureOES = DetermineETC2sRGB8Alpha8TextureSupport(textureCaps);
909     compressedEACR11UnsignedTextureOES  = DetermineEACR11UnsignedTextureSupport(textureCaps);
910     compressedEACR11SignedTextureOES    = DetermineEACR11SignedTextureSupport(textureCaps);
911     compressedEACRG11UnsignedTextureOES = DetermineEACRG11UnsignedTextureSupport(textureCaps);
912     compressedEACRG11SignedTextureOES   = DetermineEACRG11SignedTextureSupport(textureCaps);
913     sRGBEXT                             = DetermineSRGBTextureSupport(textureCaps);
914     textureSRGBR8EXT                    = DetermineSRGBR8TextureSupport(textureCaps);
915     textureSRGBRG8EXT                   = DetermineSRGBRG8TextureSupport(textureCaps);
916     depthTextureANGLE                   = DetermineDepthTextureANGLESupport(textureCaps);
917     depthTextureOES                     = DetermineDepthTextureOESSupport(textureCaps);
918     depth24OES                          = DetermineDepth24OESSupport(textureCaps);
919     depth32OES                          = DetermineDepth32Support(textureCaps);
920     colorBufferFloatRgbCHROMIUM         = DetermineColorBufferFloatRGBSupport(textureCaps);
921     colorBufferFloatRgbaCHROMIUM        = DetermineColorBufferFloatRGBASupport(textureCaps);
922     colorBufferFloatEXT                 = DetermineColorBufferFloatSupport(textureCaps);
923     floatBlendEXT                       = DetermineFloatBlendSupport(textureCaps);
924     textureNorm16EXT                    = DetermineTextureNorm16Support(textureCaps);
925     textureCompressionRgtcEXT           = DetermineRGTCTextureSupport(textureCaps);
926     textureCompressionBptcEXT           = DetermineBPTCTextureSupport(textureCaps);
927     textureCompressionPvrtcIMG          = DeterminePVRTCTextureSupport(textureCaps);
928     pvrtcSRGBEXT                        = DeterminePVRTCsRGBTextureSupport(textureCaps);
929     textureStencil8OES                  = DetermineStencilIndex8Support(textureCaps);
930     renderSharedExponentQCOM            = DetermineRenderSharedExponentSupport(textureCaps);
931     renderSnormEXT = DetermineRenderSnormSupport(textureCaps, textureNorm16EXT);
932 }
933 
934 TypePrecision::TypePrecision() = default;
935 
936 TypePrecision::TypePrecision(const TypePrecision &other) = default;
937 
938 TypePrecision &TypePrecision::operator=(const TypePrecision &other) = default;
939 
setIEEEFloat()940 void TypePrecision::setIEEEFloat()
941 {
942     range     = {{127, 127}};
943     precision = 23;
944 }
945 
setIEEEHalfFloat()946 void TypePrecision::setIEEEHalfFloat()
947 {
948     range     = {{15, 15}};
949     precision = 10;
950 }
951 
setTwosComplementInt(unsigned int bits)952 void TypePrecision::setTwosComplementInt(unsigned int bits)
953 {
954     range     = {{static_cast<GLint>(bits) - 1, static_cast<GLint>(bits) - 2}};
955     precision = 0;
956 }
957 
setSimulatedFloat(unsigned int r,unsigned int p)958 void TypePrecision::setSimulatedFloat(unsigned int r, unsigned int p)
959 {
960     range     = {{static_cast<GLint>(r), static_cast<GLint>(r)}};
961     precision = static_cast<GLint>(p);
962 }
963 
setSimulatedInt(unsigned int r)964 void TypePrecision::setSimulatedInt(unsigned int r)
965 {
966     range     = {{static_cast<GLint>(r), static_cast<GLint>(r)}};
967     precision = 0;
968 }
969 
get(GLint * returnRange,GLint * returnPrecision) const970 void TypePrecision::get(GLint *returnRange, GLint *returnPrecision) const
971 {
972     std::copy(range.begin(), range.end(), returnRange);
973     *returnPrecision = precision;
974 }
975 
976 Caps::Caps()                             = default;
977 Caps::Caps(const Caps &other)            = default;
978 Caps::~Caps()                            = default;
979 Caps &Caps::operator=(const Caps &other) = default;
980 
GenerateMinimumCaps(const Version & clientVersion,const Extensions & extensions)981 Caps GenerateMinimumCaps(const Version &clientVersion, const Extensions &extensions)
982 {
983     Caps caps;
984 
985     // GLES1 emulation (Minimums taken from Table 6.20 / 6.22 (ES 1.1 spec))
986     if (clientVersion < Version(2, 0))
987     {
988         caps.maxMultitextureUnits = 2;
989         caps.maxLights            = 8;
990         caps.maxClipPlanes        = 1;
991 
992         caps.maxModelviewMatrixStackDepth  = 16;
993         caps.maxProjectionMatrixStackDepth = 2;
994         caps.maxTextureMatrixStackDepth    = 2;
995 
996         caps.minSmoothPointSize = 1.0f;
997         caps.maxSmoothPointSize = 1.0f;
998     }
999 
1000     if (clientVersion >= Version(2, 0))
1001     {
1002         // Table 6.18
1003         caps.max2DTextureSize      = 64;
1004         caps.maxCubeMapTextureSize = 16;
1005         caps.maxViewportWidth      = caps.max2DTextureSize;
1006         caps.maxViewportHeight     = caps.max2DTextureSize;
1007         caps.minAliasedPointSize   = 1;
1008         caps.maxAliasedPointSize   = 1;
1009         caps.minAliasedLineWidth   = 1;
1010         caps.maxAliasedLineWidth   = 1;
1011 
1012         // Table 6.19
1013         caps.vertexHighpFloat.setSimulatedFloat(62, 16);
1014         caps.vertexMediumpFloat.setSimulatedFloat(14, 10);
1015         caps.vertexLowpFloat.setSimulatedFloat(1, 8);
1016         caps.vertexHighpInt.setSimulatedInt(16);
1017         caps.vertexMediumpInt.setSimulatedInt(10);
1018         caps.vertexLowpInt.setSimulatedInt(8);
1019         caps.fragmentHighpFloat.setSimulatedFloat(62, 16);
1020         caps.fragmentMediumpFloat.setSimulatedFloat(14, 10);
1021         caps.fragmentLowpFloat.setSimulatedFloat(1, 8);
1022         caps.fragmentHighpInt.setSimulatedInt(16);
1023         caps.fragmentMediumpInt.setSimulatedInt(10);
1024         caps.fragmentLowpInt.setSimulatedInt(8);
1025 
1026         // Table 6.20
1027         caps.maxVertexAttributes                              = 8;
1028         caps.maxVertexUniformVectors                          = 128;
1029         caps.maxVaryingVectors                                = 8;
1030         caps.maxCombinedTextureImageUnits                     = 8;
1031         caps.maxShaderTextureImageUnits[ShaderType::Fragment] = 8;
1032         caps.maxFragmentUniformVectors                        = 16;
1033         caps.maxRenderbufferSize                              = 1;
1034 
1035         // Table 3.35
1036         caps.maxSamples = 4;
1037     }
1038 
1039     if (clientVersion >= Version(3, 0))
1040     {
1041         // Table 6.28
1042         caps.maxElementIndex       = (1 << 24) - 1;
1043         caps.max3DTextureSize      = 256;
1044         caps.max2DTextureSize      = 2048;
1045         caps.maxArrayTextureLayers = 256;
1046         caps.maxLODBias            = 2.0f;
1047         caps.maxCubeMapTextureSize = 2048;
1048         caps.maxRenderbufferSize   = 2048;
1049         caps.maxDrawBuffers        = 4;
1050         caps.maxColorAttachments   = 4;
1051         caps.maxViewportWidth      = caps.max2DTextureSize;
1052         caps.maxViewportHeight     = caps.max2DTextureSize;
1053 
1054         // Table 6.29
1055         caps.compressedTextureFormats.push_back(GL_COMPRESSED_R11_EAC);
1056         caps.compressedTextureFormats.push_back(GL_COMPRESSED_SIGNED_R11_EAC);
1057         caps.compressedTextureFormats.push_back(GL_COMPRESSED_RG11_EAC);
1058         caps.compressedTextureFormats.push_back(GL_COMPRESSED_SIGNED_RG11_EAC);
1059         caps.compressedTextureFormats.push_back(GL_COMPRESSED_RGB8_ETC2);
1060         caps.compressedTextureFormats.push_back(GL_COMPRESSED_SRGB8_ETC2);
1061         caps.compressedTextureFormats.push_back(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2);
1062         caps.compressedTextureFormats.push_back(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2);
1063         caps.compressedTextureFormats.push_back(GL_COMPRESSED_RGBA8_ETC2_EAC);
1064         caps.compressedTextureFormats.push_back(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC);
1065         caps.vertexHighpFloat.setIEEEFloat();
1066         caps.vertexHighpInt.setTwosComplementInt(32);
1067         caps.vertexMediumpInt.setTwosComplementInt(16);
1068         caps.vertexLowpInt.setTwosComplementInt(8);
1069         caps.fragmentHighpFloat.setIEEEFloat();
1070         caps.fragmentHighpInt.setSimulatedInt(32);
1071         caps.fragmentMediumpInt.setTwosComplementInt(16);
1072         caps.fragmentLowpInt.setTwosComplementInt(8);
1073         caps.maxServerWaitTimeout = 0;
1074 
1075         // Table 6.31
1076         caps.maxVertexAttributes                            = 16;
1077         caps.maxShaderUniformComponents[ShaderType::Vertex] = 1024;
1078         caps.maxVertexUniformVectors                        = 256;
1079         caps.maxShaderUniformBlocks[ShaderType::Vertex]     = limits::kMinimumShaderUniformBlocks;
1080         caps.maxVertexOutputComponents = limits::kMinimumVertexOutputComponents;
1081         caps.maxShaderTextureImageUnits[ShaderType::Vertex] = 16;
1082 
1083         // Table 6.32
1084         caps.maxShaderUniformComponents[ShaderType::Fragment] = 896;
1085         caps.maxFragmentUniformVectors                        = 224;
1086         caps.maxShaderUniformBlocks[ShaderType::Fragment]     = limits::kMinimumShaderUniformBlocks;
1087         caps.maxFragmentInputComponents                       = 60;
1088         caps.maxShaderTextureImageUnits[ShaderType::Fragment] = 16;
1089         caps.minProgramTexelOffset                            = -8;
1090         caps.maxProgramTexelOffset                            = 7;
1091 
1092         // Table 6.33
1093         caps.maxUniformBufferBindings     = 24;
1094         caps.maxUniformBlockSize          = 16384;
1095         caps.uniformBufferOffsetAlignment = 256;
1096         caps.maxCombinedUniformBlocks     = 24;
1097         caps.maxVaryingComponents         = 60;
1098         caps.maxVaryingVectors            = 15;
1099         caps.maxCombinedTextureImageUnits = 32;
1100 
1101         // Table 6.34
1102         caps.maxTransformFeedbackInterleavedComponents = 64;
1103         caps.maxTransformFeedbackSeparateAttributes    = 4;
1104         caps.maxTransformFeedbackSeparateComponents    = 4;
1105     }
1106 
1107     if (clientVersion >= Version(3, 1))
1108     {
1109         // Table 20.40
1110         caps.maxFramebufferWidth    = 2048;
1111         caps.maxFramebufferHeight   = 2048;
1112         caps.maxFramebufferSamples  = 4;
1113         caps.maxSampleMaskWords     = 1;
1114         caps.maxColorTextureSamples = 1;
1115         caps.maxDepthTextureSamples = 1;
1116         caps.maxIntegerSamples      = 1;
1117 
1118         // Table 20.41
1119         caps.maxVertexAttribRelativeOffset = 2047;
1120         caps.maxVertexAttribBindings       = 16;
1121         caps.maxVertexAttribStride         = 2048;
1122 
1123         // Table 20.43
1124         caps.maxShaderAtomicCounterBuffers[ShaderType::Vertex] = 0;
1125         caps.maxShaderAtomicCounters[ShaderType::Vertex]       = 0;
1126         caps.maxShaderImageUniforms[ShaderType::Vertex]        = 0;
1127         caps.maxShaderStorageBlocks[ShaderType::Vertex]        = 0;
1128 
1129         // Table 20.44
1130         caps.maxShaderUniformComponents[ShaderType::Fragment]    = 1024;
1131         caps.maxFragmentUniformVectors                           = 256;
1132         caps.maxShaderAtomicCounterBuffers[ShaderType::Fragment] = 0;
1133         caps.maxShaderAtomicCounters[ShaderType::Fragment]       = 0;
1134         caps.maxShaderImageUniforms[ShaderType::Fragment]        = 0;
1135         caps.maxShaderStorageBlocks[ShaderType::Fragment]        = 0;
1136         caps.minProgramTextureGatherOffset                       = 0;
1137         caps.maxProgramTextureGatherOffset                       = 0;
1138 
1139         // Table 20.45
1140         caps.maxComputeWorkGroupCount                        = {{65535, 65535, 65535}};
1141         caps.maxComputeWorkGroupSize                         = {{128, 128, 64}};
1142         caps.maxComputeWorkGroupInvocations                  = 12;
1143         caps.maxShaderUniformBlocks[ShaderType::Compute]     = limits::kMinimumShaderUniformBlocks;
1144         caps.maxShaderTextureImageUnits[ShaderType::Compute] = 16;
1145         caps.maxComputeSharedMemorySize                      = 16384;
1146         caps.maxShaderUniformComponents[ShaderType::Compute] = 1024;
1147         caps.maxShaderAtomicCounterBuffers[ShaderType::Compute] = 1;
1148         caps.maxShaderAtomicCounters[ShaderType::Compute]       = 8;
1149         caps.maxShaderImageUniforms[ShaderType::Compute]        = 4;
1150         caps.maxShaderStorageBlocks[ShaderType::Compute]        = 4;
1151 
1152         // Table 20.46
1153         caps.maxUniformBufferBindings         = 36;
1154         caps.maxCombinedTextureImageUnits     = 48;
1155         caps.maxCombinedShaderOutputResources = 4;
1156 
1157         // Table 20.47
1158         caps.maxUniformLocations                = 1024;
1159         caps.maxAtomicCounterBufferBindings     = 1;
1160         caps.maxAtomicCounterBufferSize         = 32;
1161         caps.maxCombinedAtomicCounterBuffers    = 1;
1162         caps.maxCombinedAtomicCounters          = 8;
1163         caps.maxImageUnits                      = 4;
1164         caps.maxCombinedImageUniforms           = 4;
1165         caps.maxShaderStorageBufferBindings     = 4;
1166         caps.maxShaderStorageBlockSize          = 1 << 27;
1167         caps.maxCombinedShaderStorageBlocks     = 4;
1168         caps.shaderStorageBufferOffsetAlignment = 256;
1169     }
1170 
1171     if (extensions.blendFuncExtendedEXT)
1172     {
1173         caps.maxDualSourceDrawBuffers = 1;
1174     }
1175 
1176     if (extensions.textureRectangleANGLE)
1177     {
1178         caps.maxRectangleTextureSize = 64;
1179     }
1180 
1181     if (extensions.geometryShaderAny())
1182     {
1183         // Table 20.40 (GL_EXT_geometry_shader)
1184         caps.maxFramebufferLayers = 256;
1185         caps.layerProvokingVertex = GL_LAST_VERTEX_CONVENTION_EXT;
1186 
1187         // Table 20.43gs (GL_EXT_geometry_shader)
1188         caps.maxShaderUniformComponents[ShaderType::Geometry] = 1024;
1189         caps.maxShaderUniformBlocks[ShaderType::Geometry]     = limits::kMinimumShaderUniformBlocks;
1190         caps.maxGeometryInputComponents                       = 64;
1191         caps.maxGeometryOutputComponents                      = 64;
1192         caps.maxGeometryOutputVertices                        = 256;
1193         caps.maxGeometryTotalOutputComponents                 = 1024;
1194         caps.maxShaderTextureImageUnits[ShaderType::Geometry] = 16;
1195         caps.maxShaderAtomicCounterBuffers[ShaderType::Geometry] = 0;
1196         caps.maxShaderAtomicCounters[ShaderType::Geometry]       = 0;
1197         caps.maxShaderStorageBlocks[ShaderType::Geometry]        = 0;
1198         caps.maxGeometryShaderInvocations                        = 32;
1199 
1200         // Table 20.46 (GL_EXT_geometry_shader)
1201         caps.maxShaderImageUniforms[ShaderType::Geometry] = 0;
1202 
1203         // Table 20.46 (GL_EXT_geometry_shader)
1204         caps.maxUniformBufferBindings     = 48;
1205         caps.maxCombinedUniformBlocks     = 36;
1206         caps.maxCombinedTextureImageUnits = 64;
1207     }
1208 
1209     if (extensions.tessellationShaderEXT)
1210     {
1211         // Table 20.43 "Implementation Dependent Tessellation Shader Limits"
1212         caps.maxTessControlInputComponents                          = 64;
1213         caps.maxTessControlOutputComponents                         = 64;
1214         caps.maxShaderTextureImageUnits[ShaderType::TessControl]    = 16;
1215         caps.maxShaderUniformComponents[ShaderType::TessControl]    = 1024;
1216         caps.maxTessControlTotalOutputComponents                    = 2048;
1217         caps.maxShaderImageUniforms[ShaderType::TessControl]        = 0;
1218         caps.maxShaderAtomicCounters[ShaderType::TessControl]       = 0;
1219         caps.maxShaderAtomicCounterBuffers[ShaderType::TessControl] = 0;
1220 
1221         caps.maxTessPatchComponents = 120;
1222         caps.maxPatchVertices       = 32;
1223         caps.maxTessGenLevel        = 64;
1224 
1225         caps.maxTessEvaluationInputComponents                          = 64;
1226         caps.maxTessEvaluationOutputComponents                         = 64;
1227         caps.maxShaderTextureImageUnits[ShaderType::TessEvaluation]    = 16;
1228         caps.maxShaderUniformComponents[ShaderType::TessEvaluation]    = 1024;
1229         caps.maxShaderImageUniforms[ShaderType::TessEvaluation]        = 0;
1230         caps.maxShaderAtomicCounters[ShaderType::TessEvaluation]       = 0;
1231         caps.maxShaderAtomicCounterBuffers[ShaderType::TessEvaluation] = 0;
1232 
1233         // Table 20.46 "Implementation Dependent Aggregate Shader Limits"
1234         caps.maxUniformBufferBindings     = 72;
1235         caps.maxCombinedUniformBlocks     = 60;
1236         caps.maxCombinedTextureImageUnits = 96;
1237     }
1238 
1239     for (ShaderType shaderType : AllShaderTypes())
1240     {
1241         caps.maxCombinedShaderUniformComponents[shaderType] =
1242             caps.maxShaderUniformBlocks[shaderType] *
1243                 static_cast<GLuint>(caps.maxUniformBlockSize / 4) +
1244             caps.maxShaderUniformComponents[shaderType];
1245     }
1246 
1247     return caps;
1248 }
1249 }  // namespace gl
1250 
1251 namespace egl
1252 {
1253 
1254 Caps::Caps() = default;
1255 
1256 DisplayExtensions::DisplayExtensions() = default;
1257 
getStrings() const1258 std::vector<std::string> DisplayExtensions::getStrings() const
1259 {
1260     std::vector<std::string> extensionStrings;
1261 
1262     // clang-format off
1263     //                   | Extension name                                       | Supported flag                    | Output vector   |
1264     InsertExtensionString("EGL_EXT_create_context_robustness",                   createContextRobustness,            &extensionStrings);
1265     InsertExtensionString("EGL_ANGLE_d3d_share_handle_client_buffer",            d3dShareHandleClientBuffer,         &extensionStrings);
1266     InsertExtensionString("EGL_ANGLE_d3d_texture_client_buffer",                 d3dTextureClientBuffer,             &extensionStrings);
1267     InsertExtensionString("EGL_ANGLE_surface_d3d_texture_2d_share_handle",       surfaceD3DTexture2DShareHandle,     &extensionStrings);
1268     InsertExtensionString("EGL_ANGLE_query_surface_pointer",                     querySurfacePointer,                &extensionStrings);
1269     InsertExtensionString("EGL_ANGLE_window_fixed_size",                         windowFixedSize,                    &extensionStrings);
1270     InsertExtensionString("EGL_ANGLE_keyed_mutex",                               keyedMutex,                         &extensionStrings);
1271     InsertExtensionString("EGL_ANGLE_surface_orientation",                       surfaceOrientation,                 &extensionStrings);
1272     InsertExtensionString("EGL_ANGLE_direct_composition",                        directComposition,                  &extensionStrings);
1273     InsertExtensionString("EGL_ANGLE_windows_ui_composition",                    windowsUIComposition,               &extensionStrings);
1274     InsertExtensionString("EGL_NV_post_sub_buffer",                              postSubBuffer,                      &extensionStrings);
1275     InsertExtensionString("EGL_KHR_create_context",                              createContext,                      &extensionStrings);
1276     InsertExtensionString("EGL_KHR_image",                                       image,                              &extensionStrings);
1277     InsertExtensionString("EGL_KHR_image_base",                                  imageBase,                          &extensionStrings);
1278     InsertExtensionString("EGL_KHR_image_pixmap",                                imagePixmap,                        &extensionStrings);
1279     InsertExtensionString("EGL_EXT_image_gl_colorspace",                         imageGlColorspace,                  &extensionStrings);
1280     InsertExtensionString("EGL_KHR_gl_colorspace",                               glColorspace,                       &extensionStrings);
1281     InsertExtensionString("EGL_EXT_gl_colorspace_scrgb",                         glColorspaceScrgb,                  &extensionStrings);
1282     InsertExtensionString("EGL_EXT_gl_colorspace_scrgb_linear",                  glColorspaceScrgbLinear,            &extensionStrings);
1283     InsertExtensionString("EGL_EXT_gl_colorspace_display_p3",                    glColorspaceDisplayP3,              &extensionStrings);
1284     InsertExtensionString("EGL_EXT_gl_colorspace_display_p3_linear",             glColorspaceDisplayP3Linear,        &extensionStrings);
1285     InsertExtensionString("EGL_EXT_gl_colorspace_display_p3_passthrough",        glColorspaceDisplayP3Passthrough,   &extensionStrings);
1286     InsertExtensionString("EGL_ANGLE_colorspace_attribute_passthrough",          eglColorspaceAttributePassthroughANGLE,  &extensionStrings);
1287     InsertExtensionString("EGL_KHR_gl_texture_2D_image",                         glTexture2DImage,                   &extensionStrings);
1288     InsertExtensionString("EGL_KHR_gl_texture_cubemap_image",                    glTextureCubemapImage,              &extensionStrings);
1289     InsertExtensionString("EGL_KHR_gl_texture_3D_image",                         glTexture3DImage,                   &extensionStrings);
1290     InsertExtensionString("EGL_KHR_gl_renderbuffer_image",                       glRenderbufferImage,                &extensionStrings);
1291     InsertExtensionString("EGL_KHR_get_all_proc_addresses",                      getAllProcAddresses,                &extensionStrings);
1292     InsertExtensionString("EGL_KHR_stream",                                      stream,                             &extensionStrings);
1293     InsertExtensionString("EGL_KHR_stream_consumer_gltexture",                   streamConsumerGLTexture,            &extensionStrings);
1294     InsertExtensionString("EGL_NV_stream_consumer_gltexture_yuv",                streamConsumerGLTextureYUV,         &extensionStrings);
1295     InsertExtensionString("EGL_KHR_fence_sync",                                  fenceSync,                          &extensionStrings);
1296     InsertExtensionString("EGL_KHR_wait_sync",                                   waitSync,                           &extensionStrings);
1297     InsertExtensionString("EGL_ANGLE_stream_producer_d3d_texture",               streamProducerD3DTexture,           &extensionStrings);
1298     InsertExtensionString("EGL_ANGLE_create_context_webgl_compatibility",        createContextWebGLCompatibility,    &extensionStrings);
1299     InsertExtensionString("EGL_CHROMIUM_create_context_bind_generates_resource", createContextBindGeneratesResource, &extensionStrings);
1300     InsertExtensionString("EGL_CHROMIUM_sync_control",                           syncControlCHROMIUM,                &extensionStrings);
1301     InsertExtensionString("EGL_ANGLE_sync_control_rate",                         syncControlRateANGLE,               &extensionStrings);
1302     InsertExtensionString("EGL_KHR_swap_buffers_with_damage",                    swapBuffersWithDamage,              &extensionStrings);
1303     InsertExtensionString("EGL_EXT_pixel_format_float",                          pixelFormatFloat,                   &extensionStrings);
1304     InsertExtensionString("EGL_KHR_surfaceless_context",                         surfacelessContext,                 &extensionStrings);
1305     InsertExtensionString("EGL_ANGLE_display_texture_share_group",               displayTextureShareGroup,           &extensionStrings);
1306     InsertExtensionString("EGL_ANGLE_display_semaphore_share_group",             displaySemaphoreShareGroup,         &extensionStrings);
1307     InsertExtensionString("EGL_ANGLE_create_context_client_arrays",              createContextClientArrays,          &extensionStrings);
1308     InsertExtensionString("EGL_ANGLE_program_cache_control",                     programCacheControlANGLE,                &extensionStrings);
1309     InsertExtensionString("EGL_ANGLE_robust_resource_initialization",            robustResourceInitializationANGLE,       &extensionStrings);
1310     InsertExtensionString("EGL_ANGLE_iosurface_client_buffer",                   iosurfaceClientBuffer,              &extensionStrings);
1311     InsertExtensionString("EGL_ANGLE_metal_texture_client_buffer",               mtlTextureClientBuffer,             &extensionStrings);
1312     InsertExtensionString("EGL_ANGLE_create_context_extensions_enabled",         createContextExtensionsEnabled,     &extensionStrings);
1313     InsertExtensionString("EGL_ANDROID_presentation_time",                       presentationTime,                   &extensionStrings);
1314     InsertExtensionString("EGL_ANDROID_blob_cache",                              blobCache,                          &extensionStrings);
1315     InsertExtensionString("EGL_ANDROID_framebuffer_target",                      framebufferTargetANDROID,           &extensionStrings);
1316     InsertExtensionString("EGL_ANDROID_image_native_buffer",                     imageNativeBuffer,                  &extensionStrings);
1317     InsertExtensionString("EGL_ANDROID_get_frame_timestamps",                    getFrameTimestamps,                 &extensionStrings);
1318     InsertExtensionString("EGL_ANGLE_timestamp_surface_attribute",               timestampSurfaceAttributeANGLE,     &extensionStrings);
1319     InsertExtensionString("EGL_ANDROID_recordable",                              recordable,                         &extensionStrings);
1320     InsertExtensionString("EGL_ANGLE_power_preference",                          powerPreference,                    &extensionStrings);
1321     InsertExtensionString("EGL_ANGLE_wait_until_work_scheduled",                 waitUntilWorkScheduled,             &extensionStrings);
1322     InsertExtensionString("EGL_ANGLE_image_d3d11_texture",                       imageD3D11Texture,                  &extensionStrings);
1323     InsertExtensionString("EGL_ANDROID_create_native_client_buffer",             createNativeClientBufferANDROID,    &extensionStrings);
1324     InsertExtensionString("EGL_ANDROID_get_native_client_buffer",                getNativeClientBufferANDROID,       &extensionStrings);
1325     InsertExtensionString("EGL_ANDROID_native_fence_sync",                       nativeFenceSyncANDROID,             &extensionStrings);
1326     InsertExtensionString("EGL_ANGLE_create_context_backwards_compatible",       createContextBackwardsCompatible,   &extensionStrings);
1327     InsertExtensionString("EGL_KHR_no_config_context",                           noConfigContext,                    &extensionStrings);
1328     InsertExtensionString("EGL_IMG_context_priority",                            contextPriority,                    &extensionStrings);
1329     InsertExtensionString("EGL_KHR_create_context_no_error",                     createContextNoError,               &extensionStrings);
1330     InsertExtensionString("EGL_EXT_image_dma_buf_import",                        imageDmaBufImportEXT,               &extensionStrings);
1331     InsertExtensionString("EGL_EXT_image_dma_buf_import_modifiers",              imageDmaBufImportModifiersEXT,      &extensionStrings);
1332     InsertExtensionString("EGL_NOK_texture_from_pixmap",                         textureFromPixmapNOK,               &extensionStrings);
1333     InsertExtensionString("EGL_NV_robustness_video_memory_purge",                robustnessVideoMemoryPurgeNV,       &extensionStrings);
1334     InsertExtensionString("EGL_KHR_reusable_sync",                               reusableSyncKHR,                    &extensionStrings);
1335     InsertExtensionString("EGL_ANGLE_external_context_and_surface",              externalContextAndSurface,          &extensionStrings);
1336     InsertExtensionString("EGL_EXT_buffer_age",                                  bufferAgeEXT,                       &extensionStrings);
1337     InsertExtensionString("EGL_KHR_mutable_render_buffer",                       mutableRenderBufferKHR,             &extensionStrings);
1338     InsertExtensionString("EGL_EXT_protected_content",                           protectedContentEXT,                &extensionStrings);
1339     InsertExtensionString("EGL_ANGLE_create_surface_swap_interval",              createSurfaceSwapIntervalANGLE,     &extensionStrings);
1340     InsertExtensionString("EGL_ANGLE_context_virtualization",                    contextVirtualizationANGLE,         &extensionStrings);
1341     InsertExtensionString("EGL_KHR_lock_surface3",                               lockSurface3KHR,                    &extensionStrings);
1342     InsertExtensionString("EGL_ANGLE_vulkan_image",                              vulkanImageANGLE,                   &extensionStrings);
1343     InsertExtensionString("EGL_ANGLE_metal_create_context_ownership_identity",   metalCreateContextOwnershipIdentityANGLE, &extensionStrings);
1344     InsertExtensionString("EGL_KHR_partial_update",                              partialUpdateKHR,                   &extensionStrings);
1345     InsertExtensionString("EGL_ANGLE_metal_shared_event_sync",                   mtlSyncSharedEventANGLE,            &extensionStrings);
1346     // clang-format on
1347 
1348     return extensionStrings;
1349 }
1350 
1351 DeviceExtensions::DeviceExtensions() = default;
1352 
getStrings() const1353 std::vector<std::string> DeviceExtensions::getStrings() const
1354 {
1355     std::vector<std::string> extensionStrings;
1356 
1357     // clang-format off
1358     //                   | Extension name                                 | Supported flag                | Output vector   |
1359     InsertExtensionString("EGL_ANGLE_device_d3d",                          deviceD3D,                      &extensionStrings);
1360     InsertExtensionString("EGL_ANGLE_device_cgl",                          deviceCGL,                      &extensionStrings);
1361     InsertExtensionString("EGL_ANGLE_device_eagl",                         deviceEAGL,                     &extensionStrings);
1362     InsertExtensionString("EGL_ANGLE_device_metal",                        deviceMetal,                    &extensionStrings);
1363     InsertExtensionString("EGL_ANGLE_device_vulkan",                       deviceVulkan,                   &extensionStrings);
1364     InsertExtensionString("EGL_EXT_device_drm",                            deviceDrmEXT,                   &extensionStrings);
1365     InsertExtensionString("EGL_EXT_device_drm_render_node",                deviceDrmRenderNodeEXT,         &extensionStrings);
1366 
1367     // clang-format on
1368 
1369     return extensionStrings;
1370 }
1371 
1372 ClientExtensions::ClientExtensions()                              = default;
1373 ClientExtensions::ClientExtensions(const ClientExtensions &other) = default;
1374 
getStrings() const1375 std::vector<std::string> ClientExtensions::getStrings() const
1376 {
1377     std::vector<std::string> extensionStrings;
1378 
1379     // clang-format off
1380     //                   | Extension name                                    | Supported flag                   | Output vector   |
1381     InsertExtensionString("EGL_EXT_client_extensions",                        clientExtensions,                   &extensionStrings);
1382     InsertExtensionString("EGL_EXT_device_query",                             deviceQueryEXT,                     &extensionStrings);
1383     InsertExtensionString("EGL_EXT_platform_base",                            platformBase,                       &extensionStrings);
1384     InsertExtensionString("EGL_EXT_platform_device",                          platformDevice,                     &extensionStrings);
1385     InsertExtensionString("EGL_KHR_platform_gbm",                             platformGbmKHR,                     &extensionStrings);
1386     InsertExtensionString("EGL_EXT_platform_wayland",                         platformWaylandEXT,                 &extensionStrings);
1387     InsertExtensionString("EGL_ANGLE_platform_angle",                         platformANGLE,                      &extensionStrings);
1388     InsertExtensionString("EGL_ANGLE_platform_angle_d3d",                     platformANGLED3D,                   &extensionStrings);
1389     InsertExtensionString("EGL_ANGLE_platform_angle_d3d11on12",               platformANGLED3D11ON12,             &extensionStrings);
1390     InsertExtensionString("EGL_ANGLE_platform_angle_device_type_egl_angle",   platformANGLEDeviceTypeEGLANGLE,    &extensionStrings);
1391     InsertExtensionString("EGL_ANGLE_platform_angle_device_type_swiftshader", platformANGLEDeviceTypeSwiftShader, &extensionStrings);
1392     InsertExtensionString("EGL_ANGLE_platform_angle_opengl",                  platformANGLEOpenGL,                &extensionStrings);
1393     InsertExtensionString("EGL_ANGLE_platform_angle_null",                    platformANGLENULL,                  &extensionStrings);
1394     InsertExtensionString("EGL_ANGLE_platform_angle_vulkan",                  platformANGLEVulkan,                &extensionStrings);
1395     InsertExtensionString("EGL_ANGLE_platform_angle_metal",                   platformANGLEMetal,                 &extensionStrings);
1396     InsertExtensionString("EGL_ANGLE_platform_device_context_volatile_eagl",  platformANGLEDeviceContextVolatileEagl, &extensionStrings);
1397     InsertExtensionString("EGL_ANGLE_platform_device_context_volatile_cgl",   platformANGLEDeviceContextVolatileCgl, &extensionStrings);
1398     InsertExtensionString("EGL_ANGLE_platform_angle_device_id",               platformANGLEDeviceId,              &extensionStrings);
1399     InsertExtensionString("EGL_ANGLE_device_creation",                        deviceCreation,                     &extensionStrings);
1400     InsertExtensionString("EGL_ANGLE_device_creation_d3d11",                  deviceCreationD3D11,                &extensionStrings);
1401     InsertExtensionString("EGL_ANGLE_x11_visual",                             x11Visual,                          &extensionStrings);
1402     InsertExtensionString("EGL_ANGLE_experimental_present_path",              experimentalPresentPath,            &extensionStrings);
1403     InsertExtensionString("EGL_KHR_client_get_all_proc_addresses",            clientGetAllProcAddresses,          &extensionStrings);
1404     InsertExtensionString("EGL_KHR_debug",                                    debug,                              &extensionStrings);
1405     InsertExtensionString("EGL_ANGLE_feature_control",                        featureControlANGLE,                &extensionStrings);
1406     InsertExtensionString("EGL_ANGLE_display_power_preference",               displayPowerPreferenceANGLE,        &extensionStrings);
1407     // clang-format on
1408 
1409     return extensionStrings;
1410 }
1411 
1412 }  // namespace egl
1413