• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright 2015 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 // formatutilsgl.cpp: Queries for GL image formats and their translations to native
8 // GL formats.
9 
10 #include "libANGLE/renderer/gl/formatutilsgl.h"
11 
12 #include <limits>
13 
14 #include "anglebase/no_destructor.h"
15 #include "common/string_utils.h"
16 #include "libANGLE/formatutils.h"
17 #include "platform/FeaturesGL.h"
18 
19 namespace rx
20 {
21 
22 namespace nativegl
23 {
24 
SupportRequirement()25 SupportRequirement::SupportRequirement()
26     : version(std::numeric_limits<GLuint>::max(), std::numeric_limits<GLuint>::max()),
27       versionExtensions(),
28       requiredExtensions()
29 {}
30 
31 SupportRequirement::SupportRequirement(const SupportRequirement &other) = default;
32 
~SupportRequirement()33 SupportRequirement::~SupportRequirement() {}
34 
InternalFormat()35 InternalFormat::InternalFormat() : texture(), filter(), textureAttachment(), renderbuffer() {}
36 
37 InternalFormat::InternalFormat(const InternalFormat &other) = default;
38 
~InternalFormat()39 InternalFormat::~InternalFormat() {}
40 
41 // supported = version || vertexExt
VersionOrExts(GLuint major,GLuint minor,const std::string & versionExt)42 static inline SupportRequirement VersionOrExts(GLuint major,
43                                                GLuint minor,
44                                                const std::string &versionExt)
45 {
46     SupportRequirement requirement;
47     requirement.version.major = major;
48     requirement.version.minor = minor;
49     angle::SplitStringAlongWhitespace(versionExt, &requirement.versionExtensions);
50     return requirement;
51 }
52 
53 // supported = version
VersionOnly(GLuint major,GLuint minor)54 static inline SupportRequirement VersionOnly(GLuint major, GLuint minor)
55 {
56     SupportRequirement requirement;
57     requirement.version.major = major;
58     requirement.version.minor = minor;
59     return requirement;
60 }
61 
62 // supported = any one of sets in exts
ExtsOnly(const std::vector<std::string> & exts)63 static inline SupportRequirement ExtsOnly(const std::vector<std::string> &exts)
64 {
65     SupportRequirement requirement;
66     requirement.version.major = 0;
67     requirement.version.minor = 0;
68     requirement.requiredExtensions.resize(exts.size());
69     for (size_t i = 0; i < exts.size(); i++)
70     {
71         angle::SplitStringAlongWhitespace(exts[i], &requirement.requiredExtensions[i]);
72     }
73     return requirement;
74 }
75 
76 // supported = ext
ExtsOnly(const std::string & ext)77 static inline SupportRequirement ExtsOnly(const std::string &ext)
78 {
79     return ExtsOnly(std::vector<std::string>({ext}));
80 }
81 
82 // supported = ext1 || ext2
ExtsOnly(const std::string & ext1,const std::string & ext2)83 static inline SupportRequirement ExtsOnly(const std::string &ext1, const std::string &ext2)
84 {
85     return ExtsOnly(std::vector<std::string>({ext1, ext2}));
86 }
87 
88 // supported = true
AlwaysSupported()89 static inline SupportRequirement AlwaysSupported()
90 {
91     SupportRequirement requirement;
92     requirement.version.major = 0;
93     requirement.version.minor = 0;
94     return requirement;
95 }
96 
97 // supported = false
NeverSupported()98 static inline SupportRequirement NeverSupported()
99 {
100     SupportRequirement requirement;
101     requirement.version.major = std::numeric_limits<GLuint>::max();
102     requirement.version.minor = std::numeric_limits<GLuint>::max();
103     return requirement;
104 }
105 
106 struct InternalFormatInfo
107 {
108     InternalFormat glesInfo;
109     InternalFormat glInfo;
110 };
111 
112 typedef std::pair<GLenum, InternalFormatInfo> InternalFormatInfoPair;
113 typedef std::map<GLenum, InternalFormatInfo> InternalFormatInfoMap;
114 
115 // A helper function to insert data into the format map with fewer characters.
InsertFormatMapping(InternalFormatInfoMap * map,GLenum internalFormat,const SupportRequirement & desktopTexture,const SupportRequirement & desktopFilter,const SupportRequirement & desktopRender,const SupportRequirement & esTexture,const SupportRequirement & esFilter,const SupportRequirement & esTextureAttachment,const SupportRequirement & esRenderbufferAttachment)116 static inline void InsertFormatMapping(InternalFormatInfoMap *map,
117                                        GLenum internalFormat,
118                                        const SupportRequirement &desktopTexture,
119                                        const SupportRequirement &desktopFilter,
120                                        const SupportRequirement &desktopRender,
121                                        const SupportRequirement &esTexture,
122                                        const SupportRequirement &esFilter,
123                                        const SupportRequirement &esTextureAttachment,
124                                        const SupportRequirement &esRenderbufferAttachment)
125 {
126     InternalFormatInfo formatInfo;
127     formatInfo.glInfo.texture = desktopTexture;
128     formatInfo.glInfo.filter  = desktopFilter;
129     // No difference spotted yet in Desktop GL texture attachment and renderbuffer capabilities
130     formatInfo.glInfo.textureAttachment   = desktopRender;
131     formatInfo.glInfo.renderbuffer        = desktopRender;
132     formatInfo.glesInfo.texture           = esTexture;
133     formatInfo.glesInfo.filter            = esFilter;
134     formatInfo.glesInfo.textureAttachment = esTextureAttachment;
135     formatInfo.glesInfo.renderbuffer      = esRenderbufferAttachment;
136     map->insert(std::make_pair(internalFormat, formatInfo));
137 }
138 
139 // Note 1: This map is used to determine extensions support, which is based on checking support for
140 // sized formats (this is ANGLE implementation limitation - D3D backend supports only sized formats)
141 // In order to determine support for extensions which introduce unsized formats, this map would say
142 // that a corresponding sized format is supported, instead. Thus, if this map says that a sized
143 // format is supported, this means that either the actual sized format or a corresponding unsized
144 // format is supported by the native driver.
145 // For example, GL_EXT_texture_rg provides support for RED_EXT format with UNSIGNED_BYTE type.
146 // Therefore, DetermineRGTextureSupport checks for GL_R8 support. Therefore this map says that
147 // GL_R8 (and not RED_EXT) is supported if GL_EXT_texture_rg is available. GL_R8 itself
148 // is supported in ES3, thus the combined condition is VersionOrExts(3, 0, "GL_EXT_texture_rg").
149 //
150 // Note 2: Texture Attachment support is checked also by SupportsNativeRendering().
151 // Unsized formats appear in this map for this reason. The assumption is
152 // that SupportsNativeRendering() will not check sized formats in the ES2 frontend
153 // and the information in unsized formats is correct, and not merged like for sized formats.
154 // In the ES3 frontend, it could happen that SupportsNativeRendering() would be wrong,
155 // but this will be mitigated by fall back to CPU-readback in TextureGL::copySubTextureHelper().
156 //
157 // Note 3: Because creating renderbuffers with unsized formats is impossible,
158 // the value of renderbuffer support is actually correct for the sized formats.
159 //
160 // Note 4: To determine whether a format is filterable, one must check both "Filter" and "Texture"
161 // support, like it is done in GenerateTextureFormatCaps().
162 // On the other hand, "Texture Attachment" support formula is self-contained.
163 //
164 // TODO(ynovikov): http://anglebug.com/2846 Verify support fields of BGRA, depth, stencil and
165 // compressed formats, and all formats for Desktop GL.
BuildInternalFormatInfoMap()166 static InternalFormatInfoMap BuildInternalFormatInfoMap()
167 {
168     InternalFormatInfoMap map;
169 
170     // clang-format off
171     //                       | Format              | OpenGL texture support                          | Filter           | OpenGL render support                        | OpenGL ES texture support                 | Filter           | OpenGL ES texture attachment support    | OpenGL ES renderbuffer support           |
172     InsertFormatMapping(&map, GL_R8,                VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOrExts(3, 0, "GL_EXT_texture_rg"),   AlwaysSupported(), VersionOrExts(3, 0, "GL_EXT_texture_rg"), VersionOrExts(3, 0, "GL_EXT_texture_rg")  );
173     InsertFormatMapping(&map, GL_R8_SNORM,          VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              VersionOnly(3, 0),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
174     InsertFormatMapping(&map, GL_RG8,               VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOrExts(3, 0, "GL_EXT_texture_rg"),   AlwaysSupported(), VersionOrExts(3, 0, "GL_EXT_texture_rg"), VersionOrExts(3, 0, "GL_EXT_texture_rg")  );
175     InsertFormatMapping(&map, GL_RG8_SNORM,         VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              VersionOnly(3, 0),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
176     InsertFormatMapping(&map, GL_RGB8,              AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), VersionOnly(2, 0),                        VersionOrExts(3, 0, "GL_OES_rgb8_rgba8")  );
177     InsertFormatMapping(&map, GL_RGB8_SNORM,        VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              VersionOnly(3, 0),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
178     InsertFormatMapping(&map, GL_RGB565,            AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), AlwaysSupported(),                        AlwaysSupported()                         );
179     InsertFormatMapping(&map, GL_RGBA4,             AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), AlwaysSupported(),                        AlwaysSupported()                         );
180     InsertFormatMapping(&map, GL_RGB5_A1,           AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), AlwaysSupported(),                        AlwaysSupported()                         );
181     InsertFormatMapping(&map, GL_RGBA8,             AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), VersionOnly(2, 0),                        VersionOrExts(3, 0, "GL_OES_rgb8_rgba8")  );
182     InsertFormatMapping(&map, GL_RGBA8_SNORM,       VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              VersionOnly(3, 0),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
183     InsertFormatMapping(&map, GL_RGB10_A2,          AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             VersionOnly(3, 0),                          AlwaysSupported(), VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
184     InsertFormatMapping(&map, GL_RGB10_A2UI,        VersionOrExts(3, 3, "GL_ARB_texture_rgb10_a2ui"), NeverSupported(),  AlwaysSupported(),                             VersionOnly(3, 0),                          NeverSupported(),  AlwaysSupported(),                        AlwaysSupported()                         );
185     InsertFormatMapping(&map, GL_SRGB8,             VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),       AlwaysSupported(), VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),    VersionOrExts(3, 0, "GL_EXT_sRGB"),         AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
186     InsertFormatMapping(&map, GL_SRGB8_ALPHA8,      VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),       AlwaysSupported(), VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),    VersionOrExts(3, 0, "GL_EXT_sRGB"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_EXT_sRGB"),       VersionOrExts(3, 0, "GL_EXT_sRGB")        );
187     InsertFormatMapping(&map, GL_R8I,               VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
188     InsertFormatMapping(&map, GL_R8UI,              VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
189     InsertFormatMapping(&map, GL_R16I,              VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
190     InsertFormatMapping(&map, GL_R16UI,             VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
191     InsertFormatMapping(&map, GL_R32I,              VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
192     InsertFormatMapping(&map, GL_R32UI,             VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
193     InsertFormatMapping(&map, GL_RG8I,              VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
194     InsertFormatMapping(&map, GL_RG8UI,             VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
195     InsertFormatMapping(&map, GL_RG16I,             VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
196     InsertFormatMapping(&map, GL_RG16UI,            VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
197     InsertFormatMapping(&map, GL_RG32I,             VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
198     InsertFormatMapping(&map, GL_RG32UI,            VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
199     InsertFormatMapping(&map, GL_RGB8I,             VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
200     InsertFormatMapping(&map, GL_RGB8UI,            VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
201     InsertFormatMapping(&map, GL_RGB16I,            VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
202     InsertFormatMapping(&map, GL_RGB16UI,           VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
203     InsertFormatMapping(&map, GL_RGB32I,            VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
204     InsertFormatMapping(&map, GL_RGB32UI,           VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
205     InsertFormatMapping(&map, GL_RGBA8I,            VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
206     InsertFormatMapping(&map, GL_RGBA8UI,           VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
207     InsertFormatMapping(&map, GL_RGBA16I,           VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
208     InsertFormatMapping(&map, GL_RGBA16UI,          VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
209     InsertFormatMapping(&map, GL_RGBA32I,           VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
210     InsertFormatMapping(&map, GL_RGBA32UI,          VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        VersionOnly(3, 0)                         );
211 
212     InsertFormatMapping(&map, GL_R16,               VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), ExtsOnly("GL_EXT_texture_norm16"),        ExtsOnly("GL_EXT_texture_norm16")         );
213     InsertFormatMapping(&map, GL_RG16,              VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), ExtsOnly("GL_EXT_texture_norm16"),        ExtsOnly("GL_EXT_texture_norm16")         );
214     InsertFormatMapping(&map, GL_RGB16,             AlwaysSupported(),                                AlwaysSupported(), NeverSupported(),                              ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
215     InsertFormatMapping(&map, GL_RGBA16,            AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), ExtsOnly("GL_EXT_texture_norm16"),        ExtsOnly("GL_EXT_texture_norm16")         );
216 
217     InsertFormatMapping(&map, GL_R16_SNORM,         VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
218     InsertFormatMapping(&map, GL_RG16_SNORM,        VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
219     InsertFormatMapping(&map, GL_RGB16_SNORM,       VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
220     InsertFormatMapping(&map, GL_RGBA16_SNORM,      VersionOnly(3, 1),                                AlwaysSupported(), NeverSupported(),                              ExtsOnly("GL_EXT_texture_norm16"),          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
221 
222     // Unsized formats
223     InsertFormatMapping(&map, GL_ALPHA,             NeverSupported(),                                 NeverSupported(),  NeverSupported(),                              AlwaysSupported(),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
224     InsertFormatMapping(&map, GL_LUMINANCE,         NeverSupported(),                                 NeverSupported(),  NeverSupported(),                              AlwaysSupported(),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
225     InsertFormatMapping(&map, GL_LUMINANCE_ALPHA,   NeverSupported(),                                 NeverSupported(),  NeverSupported(),                              AlwaysSupported(),                          AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
226     InsertFormatMapping(&map, GL_RED,               VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      ExtsOnly("GL_EXT_texture_rg"),              AlwaysSupported(), ExtsOnly("GL_EXT_texture_rg"),            NeverSupported()                          );
227     InsertFormatMapping(&map, GL_RG,                VersionOrExts(3, 0, "GL_ARB_texture_rg"),         AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg"),      ExtsOnly("GL_EXT_texture_rg"),              AlwaysSupported(), ExtsOnly("GL_EXT_texture_rg"),            NeverSupported()                          );
228     InsertFormatMapping(&map, GL_RGB,               AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), VersionOnly(2, 0),                        NeverSupported()                          );
229     InsertFormatMapping(&map, GL_RGBA,              AlwaysSupported(),                                AlwaysSupported(), AlwaysSupported(),                             AlwaysSupported(),                          AlwaysSupported(), VersionOnly(2, 0),                        NeverSupported()                          );
230     InsertFormatMapping(&map, GL_RED_INTEGER,       VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        NeverSupported()                          );
231     InsertFormatMapping(&map, GL_RG_INTEGER,        VersionOrExts(3, 0, "GL_ARB_texture_rg"),         NeverSupported(),  VersionOrExts(3, 0, "GL_ARB_texture_rg"),      VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        NeverSupported()                          );
232     InsertFormatMapping(&map, GL_RGB_INTEGER,       VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  NeverSupported(),                              VersionOnly(3, 0),                          NeverSupported(),  NeverSupported(),                         NeverSupported()                          );
233     InsertFormatMapping(&map, GL_RGBA_INTEGER,      VersionOrExts(3, 0, "GL_EXT_texture_integer"),    NeverSupported(),  VersionOrExts(3, 0, "GL_EXT_texture_integer"), VersionOnly(3, 0),                          NeverSupported(),  VersionOnly(3, 0),                        NeverSupported()                          );
234     InsertFormatMapping(&map, GL_SRGB,              VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),       AlwaysSupported(), VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),    ExtsOnly("GL_EXT_sRGB"),                    AlwaysSupported(), NeverSupported(),                         NeverSupported()                          );
235     InsertFormatMapping(&map, GL_SRGB_ALPHA,        VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),       AlwaysSupported(), VersionOrExts(2, 1, "GL_EXT_texture_sRGB"),    ExtsOnly("GL_EXT_sRGB"),                    AlwaysSupported(), ExtsOnly("GL_EXT_sRGB"),                  NeverSupported()                          );
236 
237     // From GL_EXT_texture_format_BGRA8888
238     InsertFormatMapping(&map, GL_BGRA8_EXT,         VersionOrExts(1, 2, "GL_EXT_bgra"),               AlwaysSupported(), VersionOrExts(1, 2, "GL_EXT_bgra"),            ExtsOnly("GL_EXT_texture_format_BGRA8888"), AlwaysSupported(), ExtsOnly("GL_EXT_texture_format_BGRA8888"), ExtsOnly("GL_EXT_texture_format_BGRA8888")                          );
239     InsertFormatMapping(&map, GL_BGRA_EXT,          VersionOrExts(1, 2, "GL_EXT_bgra"),               AlwaysSupported(), VersionOrExts(1, 2, "GL_EXT_bgra"),            ExtsOnly("GL_EXT_texture_format_BGRA8888"), AlwaysSupported(), ExtsOnly("GL_EXT_texture_format_BGRA8888"), ExtsOnly("GL_EXT_texture_format_BGRA8888")                          );
240 
241     // Floating point formats
242     // Note 1: GL_EXT_texture_shared_exponent and GL_ARB_color_buffer_float suggest that RGB9_E5
243     // would be renderable, but once support for renderable float textures got rolled into core GL
244     // spec it wasn't intended to be renderable. In practice it's not reliably renderable even
245     // with the extensions, there's a known bug in at least NVIDIA driver version 370.
246     //
247     // Note 2: It's a bit unclear whether texture attachments with GL_RGB16F should be supported
248     // in ES3 with GL_EXT_color_buffer_half_float. Probably not, since in ES3 type is HALF_FLOAT,
249     // but GL_EXT_color_buffer_half_float is applicable only to type HALF_FLOAT_OES.
250     //
251     // Note 3: GL_EXT_color_buffer_float implies that ES3.0 is supported, this simplifies the check.
252     //
253     //                       | Format              | OpenGL texture support                                       | Filter           | OpenGL render support                                                                  | OpenGL ES texture support                                         | Filter                                                 | OpenGL ES texture attachment support                                                                                                      | OpenGL ES renderbuffer support                                                                                    |
254     InsertFormatMapping(&map, GL_R11F_G11F_B10F,    VersionOrExts(3, 0, "GL_EXT_packed_float"),                    AlwaysSupported(), VersionOrExts(3, 0, "GL_EXT_packed_float GL_ARB_color_buffer_float"),                    VersionOnly(3, 0),                                                  AlwaysSupported(),                                       ExtsOnly("GL_EXT_color_buffer_float"),                                                                                                      ExtsOnly("GL_EXT_color_buffer_float")                                                                              );
255     InsertFormatMapping(&map, GL_RGB9_E5,           VersionOrExts(3, 0, "GL_EXT_texture_shared_exponent"),         AlwaysSupported(), NeverSupported(),                                                                        VersionOnly(3, 0),                                                  AlwaysSupported(),                                       NeverSupported(),                                                                                                                           NeverSupported()                                                                                                   );
256     InsertFormatMapping(&map, GL_R16F,              VersionOrExts(3, 0, "GL_ARB_texture_rg ARB_texture_float"),    AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float GL_ARB_color_buffer_float"), VersionOrExts(3, 0, "GL_OES_texture_half_float GL_EXT_texture_rg"), VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), ExtsOnly("GL_EXT_texture_storage GL_OES_texture_half_float GL_EXT_texture_rg GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float"), ExtsOnly("GL_EXT_texture_rg GL_OES_texture_half_float GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float"));
257     InsertFormatMapping(&map, GL_RG16F,             VersionOrExts(3, 0, "GL_ARB_texture_rg ARB_texture_float"),    AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float GL_ARB_color_buffer_float"), VersionOrExts(3, 0, "GL_OES_texture_half_float GL_EXT_texture_rg"), VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), ExtsOnly("GL_EXT_texture_storage GL_OES_texture_half_float GL_EXT_texture_rg GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float"), ExtsOnly("GL_EXT_texture_rg GL_OES_texture_half_float GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float"));
258     InsertFormatMapping(&map, GL_RGB16F,            VersionOrExts(3, 0, "GL_ARB_texture_float"),                   AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_float GL_ARB_color_buffer_float"),                   VersionOrExts(3, 0, "GL_OES_texture_half_float"),                   VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), ExtsOnly("GL_EXT_texture_storage GL_OES_texture_half_float GL_EXT_color_buffer_half_float"),                                                ExtsOnly("GL_OES_texture_half_float GL_EXT_color_buffer_half_float")                                               );
259     InsertFormatMapping(&map, GL_RGBA16F,           VersionOrExts(3, 0, "GL_ARB_texture_float"),                   AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_float GL_ARB_color_buffer_float"),                   VersionOrExts(3, 0, "GL_OES_texture_half_float"),                   VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), ExtsOnly("GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float"),                                                                    ExtsOnly("GL_EXT_color_buffer_half_float", "GL_EXT_color_buffer_float")                                            );
260     InsertFormatMapping(&map, GL_R32F,              VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float"), AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float GL_ARB_color_buffer_float"), VersionOrExts(3, 0, "GL_OES_texture_float GL_EXT_texture_rg"),      ExtsOnly("GL_OES_texture_float_linear"),                 ExtsOnly("GL_EXT_color_buffer_float"),                                                                                                      ExtsOnly("GL_EXT_color_buffer_float")                                                                              );
261     InsertFormatMapping(&map, GL_RG32F,             VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float"), AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_rg GL_ARB_texture_float GL_ARB_color_buffer_float"), VersionOrExts(3, 0, "GL_OES_texture_float GL_EXT_texture_rg"),      ExtsOnly("GL_OES_texture_float_linear"),                 ExtsOnly("GL_EXT_color_buffer_float"),                                                                                                      ExtsOnly("GL_EXT_color_buffer_float")                                                                              );
262     InsertFormatMapping(&map, GL_RGB32F,            VersionOrExts(3, 0, "GL_ARB_texture_float"),                   AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_float GL_ARB_color_buffer_float"),                   VersionOrExts(3, 0, "GL_OES_texture_float"),                        ExtsOnly("GL_OES_texture_float_linear"),                 NeverSupported(),                                                                                                                           NeverSupported()                                                                                                   );
263     InsertFormatMapping(&map, GL_RGBA32F,           VersionOrExts(3, 0, "GL_ARB_texture_float"),                   AlwaysSupported(), VersionOrExts(3, 0, "GL_ARB_texture_float GL_ARB_color_buffer_float"),                   VersionOrExts(3, 0, "GL_OES_texture_float"),                        ExtsOnly("GL_OES_texture_float_linear"),                 ExtsOnly("GL_EXT_color_buffer_float"),                                                                                                      ExtsOnly("GL_EXT_color_buffer_float")                                                                              );
264 
265     // Depth stencil formats
266     //                       | Format                  | OpenGL texture support                            | Filter                                     | OpenGL render support                             | OpenGL ES texture support                  | Filter                                     | OpenGL ES texture attachment support                                   | OpenGL ES renderbuffer support                                        |
267     InsertFormatMapping(&map, GL_DEPTH_COMPONENT16,     VersionOnly(1, 5),                                  VersionOrExts(1, 5, "GL_ARB_depth_texture"), VersionOnly(1, 5),                                  VersionOnly(2, 0),                           VersionOrExts(3, 0, "GL_OES_depth_texture"), VersionOnly(2, 0),                                                       VersionOnly(2, 0)                                                      );
268     InsertFormatMapping(&map, GL_DEPTH_COMPONENT24,     VersionOnly(1, 5),                                  VersionOrExts(1, 5, "GL_ARB_depth_texture"), VersionOnly(1, 5),                                  VersionOnly(2, 0),                           VersionOrExts(3, 0, "GL_OES_depth_texture"), VersionOnly(2, 0),                                                       VersionOnly(2, 0)                                                      );
269     InsertFormatMapping(&map, GL_DEPTH_COMPONENT32_OES, VersionOnly(1, 5),                                  VersionOrExts(1, 5, "GL_ARB_depth_texture"), VersionOnly(1, 5),                                  ExtsOnly("GL_OES_depth_texture"),            AlwaysSupported(),                           ExtsOnly("GL_OES_depth_texture"),                                        ExtsOnly("GL_OES_depth32")                                             );
270     InsertFormatMapping(&map, GL_DEPTH_COMPONENT32F,    VersionOrExts(3, 0, "GL_ARB_depth_buffer_float"),   AlwaysSupported(),                           VersionOrExts(3, 0, "GL_ARB_depth_buffer_float"),   VersionOnly(3, 0),                           VersionOrExts(3, 0, "GL_OES_depth_texture"), VersionOnly(3, 0),                                                       VersionOnly(3, 0)                                                      );
271     InsertFormatMapping(&map, GL_STENCIL_INDEX8,        VersionOrExts(3, 0, "GL_EXT_packed_depth_stencil"), NeverSupported(),                            VersionOrExts(3, 0, "GL_EXT_packed_depth_stencil"), VersionOnly(2, 0),                           NeverSupported(),                            VersionOnly(2, 0),                                                       VersionOnly(2, 0)                                                      );
272     InsertFormatMapping(&map, GL_DEPTH24_STENCIL8,      VersionOrExts(3, 0, "GL_ARB_framebuffer_object"),   VersionOrExts(3, 0, "GL_ARB_depth_texture"), VersionOrExts(3, 0, "GL_ARB_framebuffer_object"),   VersionOrExts(3, 0, "GL_OES_depth_texture"), AlwaysSupported(),                           VersionOrExts(3, 0, "GL_OES_depth_texture GL_OES_packed_depth_stencil"), VersionOrExts(3, 0, "GL_OES_depth_texture GL_OES_packed_depth_stencil"));
273     InsertFormatMapping(&map, GL_DEPTH32F_STENCIL8,     VersionOrExts(3, 0, "GL_ARB_depth_buffer_float"),   AlwaysSupported(),                           VersionOrExts(3, 0, "GL_ARB_depth_buffer_float"),   VersionOnly(3, 0),                           AlwaysSupported(),                           VersionOnly(3, 0),                                                       VersionOnly(3, 0)                                                      );
274     InsertFormatMapping(&map, GL_DEPTH_COMPONENT,       VersionOnly(1, 5),                                  VersionOrExts(1, 5, "GL_ARB_depth_texture"), VersionOnly(1, 5),                                  VersionOnly(2, 0),                           VersionOrExts(3, 0, "GL_OES_depth_texture"), VersionOnly(2, 0),                                                       VersionOnly(2, 0)                                                      );
275     InsertFormatMapping(&map, GL_DEPTH_STENCIL,         VersionOnly(1, 5),                                  VersionOrExts(1, 5, "GL_ARB_depth_texture"), VersionOnly(1, 5),                                  VersionOnly(2, 0),                           VersionOrExts(3, 0, "GL_OES_depth_texture"), VersionOnly(2, 0),                                                       VersionOnly(2, 0)                                                      );
276 
277     // Luminance alpha formats
278     //                      | Format                   | OpenGL texture support                     | Filter           | Render          | OpenGL ES texture support                       | Filter                                                 | OpenGL ES texture attachment support | OpenGL ES renderbuffer support  |
279     InsertFormatMapping(&map, GL_ALPHA8_EXT,             AlwaysSupported(),                           AlwaysSupported(), NeverSupported(), AlwaysSupported(),                                AlwaysSupported(),                                       NeverSupported(),                      NeverSupported()                );
280     InsertFormatMapping(&map, GL_LUMINANCE8_EXT,         AlwaysSupported(),                           AlwaysSupported(), NeverSupported(), AlwaysSupported(),                                AlwaysSupported(),                                       NeverSupported(),                      NeverSupported()                );
281     InsertFormatMapping(&map, GL_LUMINANCE8_ALPHA8_EXT,  AlwaysSupported(),                           AlwaysSupported(), NeverSupported(), AlwaysSupported(),                                AlwaysSupported(),                                       NeverSupported(),                      NeverSupported()                );
282     InsertFormatMapping(&map, GL_ALPHA16F_EXT,           VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_half_float"), VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), NeverSupported(),                      NeverSupported()                );
283     InsertFormatMapping(&map, GL_LUMINANCE16F_EXT,       VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_half_float"), VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), NeverSupported(),                      NeverSupported()                );
284     InsertFormatMapping(&map, GL_LUMINANCE_ALPHA16F_EXT, VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_half_float"), VersionOrExts(3, 0, "GL_OES_texture_half_float_linear"), NeverSupported(),                      NeverSupported()                );
285     InsertFormatMapping(&map, GL_ALPHA32F_EXT,           VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_float"),      ExtsOnly("GL_OES_texture_float_linear"),                 NeverSupported(),                      NeverSupported()                );
286     InsertFormatMapping(&map, GL_LUMINANCE32F_EXT,       VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_float"),      ExtsOnly("GL_OES_texture_float_linear"),                 NeverSupported(),                      NeverSupported()                );
287     InsertFormatMapping(&map, GL_LUMINANCE_ALPHA32F_EXT, VersionOrExts(3, 0, "GL_ARB_texture_float"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_texture_float"),      ExtsOnly("GL_OES_texture_float_linear"),                 NeverSupported(),                      NeverSupported()                );
288 
289     // EXT_texture_compression_rgtc formats
290     //                       | Format                                  | OpenGL texture support                                | Filter           | Render          | OpenGL ES texture support                  | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
291     InsertFormatMapping(&map, GL_COMPRESSED_RED_RGTC1_EXT,              VersionOrExts(3, 0, "GL_ARB_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
292     InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_RED_RGTC1_EXT,       VersionOrExts(3, 0, "GL_ARB_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
293     InsertFormatMapping(&map, GL_COMPRESSED_RED_GREEN_RGTC2_EXT,        VersionOrExts(3, 0, "GL_ARB_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
294     InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT, VersionOrExts(3, 0, "GL_ARB_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_rgtc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
295 
296     // EXT_texture_compression_bptc formats
297     //                       | Format                                   | OpenGL texture support                                | Filter           | Render          | OpenGL ES texture support                  | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
298     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT,         VersionOrExts(4, 2, "GL_ARB_texture_compression_bptc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_bptc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
299     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT,   VersionOrExts(4, 2, "GL_ARB_texture_compression_bptc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_bptc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
300     InsertFormatMapping(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,   VersionOrExts(4, 2, "GL_ARB_texture_compression_bptc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_bptc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
301     InsertFormatMapping(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, VersionOrExts(4, 2, "GL_ARB_texture_compression_bptc"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_bptc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                 );
302 
303     // Compressed formats, From ES 3.0.1 spec, table 3.16
304     //                       | Format                                      | OpenGL texture support                         | Filter           | Render          | OpenGL ES texture support                                                   | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
305     InsertFormatMapping(&map, GL_COMPRESSED_R11_EAC,                        VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_EAC_R11_unsigned_texture"),               AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
306     InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_R11_EAC,                 VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_EAC_R11_signed_texture"),                 AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
307     InsertFormatMapping(&map, GL_COMPRESSED_RG11_EAC,                       VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_EAC_RG11_unsigned_texture"),              AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
308     InsertFormatMapping(&map, GL_COMPRESSED_SIGNED_RG11_EAC,                VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_EAC_RG11_signed_texture"),                AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
309     InsertFormatMapping(&map, GL_COMPRESSED_RGB8_ETC2,                      VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_RGB8_texture"),                      AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
310     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ETC2,                     VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_sRGB8_texture"),                     AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
311     InsertFormatMapping(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,  VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_punchthroughA_RGBA8_texture"),       AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
312     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_punchthroughA_sRGB8_alpha_texture"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
313     InsertFormatMapping(&map, GL_COMPRESSED_RGBA8_ETC2_EAC,                 VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_RGBA8_texture"),                     AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
314     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,          VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "OES_compressed_ETC2_sRGB8_alpha8_texture"),              AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
315 
316     // From GL_EXT_texture_compression_dxt1
317     //                       | Format                            | OpenGL texture support                         | Filter           | Render          | OpenGL ES texture support                                                       | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
318     InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT,    ExtsOnly("GL_EXT_texture_compression_s3tc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1", "GL_EXT_texture_compression_s3tc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
319     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,   ExtsOnly("GL_EXT_texture_compression_s3tc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_dxt1", "GL_EXT_texture_compression_s3tc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
320 
321     // From GL_ANGLE_texture_compression_dxt3
322     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt3", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
323 
324     // From GL_ANGLE_texture_compression_dxt5
325     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, ExtsOnly("GL_EXT_texture_compression_s3tc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_ANGLE_texture_compression_dxt5", "GL_EXT_texture_compression_s3tc"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
326 
327     // From GL_EXT_texture_compression_s3tc_srgb
328     //                       | Format                                | OpenGL texture support                                         | Filter           | Render          | OpenGL ES texture support                                                                             | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
329     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT,       ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
330     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
331     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
332     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, ExtsOnly("GL_EXT_texture_compression_s3tc GL_EXT_texture_sRGB"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_compression_s3tc_srgb", "GL_EXT_texture_compression_s3tc GL_NV_sRGB_formats"), AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
333 
334     // From GL_OES_compressed_ETC1_RGB8_texture
335     InsertFormatMapping(&map, GL_ETC1_RGB8_OES,                   VersionOrExts(4, 3, "GL_ARB_ES3_compatibility"), AlwaysSupported(), NeverSupported(), VersionOrExts(3, 0, "GL_OES_compressed_ETC1_RGB8_texture"),       AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
336 
337     // From GL_OES_texture_compression_astc
338     //                       | Format                                   | OpenGL texture                                 | Filter           | Render          | OpenGL ES texture support                      | Filter           | ES attachment   | ES renderbuffer |
339     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
340     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
341     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
342     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
343     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
344     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
345     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
346     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR,           ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
347     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR,          ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
348     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR,          ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
349     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR,          ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
350     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR,         ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
351     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR,         ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
352     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR,         ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
353     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
354     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
355     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
356     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
357     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
358     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
359     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
360     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,   ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
361     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,  ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
362     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,  ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
363     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,  ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
364     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
365     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
366     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_KHR_texture_compression_astc_ldr"), AlwaysSupported(), NeverSupported(), NeverSupported());
367     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_3x3x3_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
368     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x3x3_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
369     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x4x3_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
370     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x4x4_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
371     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x4x4_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
372     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x5x4_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
373     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x5x5_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
374     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x5x5_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
375     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x6x5_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
376     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x6x6_OES,         NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
377     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
378     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
379     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
380     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
381     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
382     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
383     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
384     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
385     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
386     InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"),     AlwaysSupported(), NeverSupported(), NeverSupported());
387 
388     // From GL_IMG_texture_compression_pvrtc
389     //                       | Format                               | OpenGL texture support                         | Filter           | Render          | OpenGL ES texture support                      | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
390     InsertFormatMapping(&map, GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG,    ExtsOnly("GL_IMG_texture_compression_pvrtc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_IMG_texture_compression_pvrtc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
391     InsertFormatMapping(&map, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,    ExtsOnly("GL_IMG_texture_compression_pvrtc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_IMG_texture_compression_pvrtc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
392     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG,   ExtsOnly("GL_IMG_texture_compression_pvrtc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_IMG_texture_compression_pvrtc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
393     InsertFormatMapping(&map, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG,   ExtsOnly("GL_IMG_texture_compression_pvrtc"),     AlwaysSupported(), NeverSupported(), ExtsOnly("GL_IMG_texture_compression_pvrtc"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
394 
395     // From GL_EXT_pvrtc_sRGB
396     //                       | Format                                      | OpenGL texture support  | Filter          | Render          | OpenGL ES texture support      | Filter           | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
397     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT,          NeverSupported(),         NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
398     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT,          NeverSupported(),         NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
399     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT,    NeverSupported(),         NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
400     InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT,    NeverSupported(),         NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"),   AlwaysSupported(), NeverSupported(),                      NeverSupported()                );
401 
402     // clang-format on
403 
404     return map;
405 }
406 
GetInternalFormatMap()407 static const InternalFormatInfoMap &GetInternalFormatMap()
408 {
409     static const angle::base::NoDestructor<InternalFormatInfoMap> formatMap(
410         BuildInternalFormatInfoMap());
411     return *formatMap;
412 }
413 
GetInternalFormatInfo(GLenum internalFormat,StandardGL standard)414 const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, StandardGL standard)
415 {
416     const InternalFormatInfoMap &formatMap     = GetInternalFormatMap();
417     InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
418     if (iter != formatMap.end())
419     {
420         const InternalFormatInfo &info = iter->second;
421         switch (standard)
422         {
423             case STANDARD_GL_ES:
424                 return info.glesInfo;
425             case STANDARD_GL_DESKTOP:
426                 return info.glInfo;
427             default:
428                 UNREACHABLE();
429                 break;
430         }
431     }
432 
433     static const angle::base::NoDestructor<InternalFormat> defaultInternalFormat;
434     return *defaultInternalFormat;
435 }
436 
IsLUMAFormat(GLenum format)437 static bool IsLUMAFormat(GLenum format)
438 {
439     return (format == GL_LUMINANCE || format == GL_ALPHA || format == GL_LUMINANCE_ALPHA);
440 }
441 
EmulateLUMAFormat(const GLenum format)442 static GLenum EmulateLUMAFormat(const GLenum format)
443 {
444     // This is needed separately from EmulateLUMA because some format/type combinations that come in
445     // to GetNativeFormat don't have entries in the internal format map.
446 
447     ASSERT(IsLUMAFormat(format));
448 
449     if (format == GL_LUMINANCE || format == GL_ALPHA)
450         return GL_RED;
451 
452     return GL_RG;
453 }
454 
EmulateLUMA(const gl::InternalFormat & internalFormat)455 static const gl::InternalFormat &EmulateLUMA(const gl::InternalFormat &internalFormat)
456 {
457     ASSERT(IsLUMAFormat(internalFormat.format));
458 
459     // Work around deprecated luminance/alpha formats in the OpenGL core profile, and OpenGL ES 3.0
460     // and greater, by backing them with R or RG textures.
461     return gl::GetInternalFormatInfo(EmulateLUMAFormat(internalFormat.format), internalFormat.type);
462 }
463 
GetNativeInternalFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,const gl::InternalFormat & internalFormat)464 static GLenum GetNativeInternalFormat(const FunctionsGL *functions,
465                                       const angle::FeaturesGL &features,
466                                       const gl::InternalFormat &internalFormat)
467 {
468     GLenum result = internalFormat.internalFormat;
469 
470     if (functions->standard == STANDARD_GL_DESKTOP)
471     {
472         // Use sized internal formats whenever possible to guarantee the requested precision.
473         // On Desktop GL, passing an internal format of GL_RGBA will generate a GL_RGBA8 texture
474         // even if the provided type is GL_FLOAT.
475         result = internalFormat.sizedInternalFormat;
476 
477         if (features.avoid1BitAlphaTextureFormats.enabled && internalFormat.alphaBits == 1)
478         {
479             // Use an 8-bit format instead
480             result = GL_RGBA8;
481         }
482 
483         if (features.rgba4IsNotSupportedForColorRendering.enabled &&
484             internalFormat.sizedInternalFormat == GL_RGBA4)
485         {
486             // Use an 8-bit format instead
487             result = GL_RGBA8;
488         }
489 
490         if (internalFormat.sizedInternalFormat == GL_RGB565 &&
491             !functions->isAtLeastGL(gl::Version(4, 1)) &&
492             !functions->hasGLExtension("GL_ARB_ES2_compatibility"))
493         {
494             // GL_RGB565 is required for basic ES2 functionality but was not added to desktop GL
495             // until 4.1.
496             // Work around this by using an 8-bit format instead.
497             result = GL_RGB8;
498         }
499 
500         if (internalFormat.sizedInternalFormat == GL_BGRA8_EXT)
501         {
502             // GLES accepts GL_BGRA as an internal format but desktop GL only accepts it as a type.
503             // Update the internal format to GL_RGBA.
504             result = GL_RGBA8;
505         }
506 
507         if ((functions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
508         {
509             if (IsLUMAFormat(internalFormat.format))
510             {
511                 result = EmulateLUMA(internalFormat).sizedInternalFormat;
512             }
513         }
514     }
515     else if (functions->isAtLeastGLES(gl::Version(3, 0)))
516     {
517         if (internalFormat.componentType == GL_FLOAT)
518         {
519             if (!internalFormat.isLUMA())
520             {
521                 // Use sized internal formats for floating point textures.  Extensions such as
522                 // EXT_color_buffer_float require the sized formats to be renderable.
523                 result = internalFormat.sizedInternalFormat;
524             }
525             else if ((internalFormat.type == GL_FLOAT &&
526                       !functions->hasGLESExtension("GL_OES_texture_float")) ||
527                      (internalFormat.type == GL_HALF_FLOAT_OES &&
528                       !functions->hasGLESExtension("GL_OES_texture_half_float")))
529             {
530                 // The legacy luminance/alpha formats from OES_texture_float are emulated with R/RG
531                 // textures.
532                 if (IsLUMAFormat(internalFormat.format))
533                 {
534                     result = EmulateLUMA(internalFormat).sizedInternalFormat;
535                 }
536             }
537         }
538         else if (internalFormat.format == GL_RED_EXT || internalFormat.format == GL_RG_EXT)
539         {
540             // Workaround Adreno driver not supporting unsized EXT_texture_rg formats
541             result = internalFormat.sizedInternalFormat;
542         }
543         else if (internalFormat.colorEncoding == GL_SRGB)
544         {
545             if (features.unsizedsRGBReadPixelsDoesntTransform.enabled)
546             {
547                 // Work around some Adreno driver bugs that don't read back SRGB data correctly when
548                 // it's in unsized SRGB texture formats.
549                 result = internalFormat.sizedInternalFormat;
550             }
551             else if (!functions->hasGLESExtension("GL_EXT_sRGB"))
552             {
553                 // Unsized sRGB internal formats are unlikely to be supported by the
554                 // driver. Transform them to sized internal formats.
555                 if (internalFormat.internalFormat == GL_SRGB ||
556                     internalFormat.internalFormat == GL_SRGB_ALPHA_EXT)
557                 {
558                     result = internalFormat.sizedInternalFormat;
559                 }
560             }
561         }
562         else if ((internalFormat.internalFormat == GL_DEPTH_COMPONENT ||
563                   internalFormat.internalFormat == GL_DEPTH_STENCIL) &&
564                  !functions->hasGLESExtension("GL_OES_depth_texture"))
565         {
566             // Use ES 3.0 sized internal formats for depth/stencil textures when the driver doesn't
567             // advertise GL_OES_depth_texture, since it's likely the driver will reject unsized
568             // internal formats.
569             if (internalFormat.internalFormat == GL_DEPTH_COMPONENT &&
570                 internalFormat.type == GL_UNSIGNED_INT &&
571                 !functions->hasGLESExtension("GL_OES_depth32"))
572             {
573                 // Best-effort attempt to provide as many bits as possible.
574                 result = GL_DEPTH_COMPONENT24;
575                 // Note: could also consider promoting GL_DEPTH_COMPONENT / GL_UNSIGNED_SHORT to a
576                 // higher precision.
577             }
578             else
579             {
580                 result = internalFormat.sizedInternalFormat;
581             }
582         }
583     }
584 
585     return result;
586 }
587 
GetNativeFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)588 static GLenum GetNativeFormat(const FunctionsGL *functions,
589                               const angle::FeaturesGL &features,
590                               GLenum format,
591                               GLenum type)
592 {
593     GLenum result = format;
594 
595     if (functions->standard == STANDARD_GL_DESKTOP)
596     {
597         // The ES SRGB extensions require that the provided format is GL_SRGB or SRGB_ALPHA but
598         // the desktop GL extensions only accept GL_RGB or GL_RGBA.  Convert them.
599         if (format == GL_SRGB)
600         {
601             result = GL_RGB;
602         }
603 
604         if (format == GL_SRGB_ALPHA)
605         {
606             result = GL_RGBA;
607         }
608 
609         if ((functions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
610         {
611             // Work around deprecated luminance alpha formats in the OpenGL core profile by backing
612             // them with R or RG textures.
613             if (IsLUMAFormat(format))
614             {
615                 result = EmulateLUMAFormat(format);
616             }
617         }
618     }
619     else if (functions->isAtLeastGLES(gl::Version(3, 0)))
620     {
621         // Transform sRGB formats to RGB if either the GLES driver doesn't support GL_EXT_sRGB, or
622         // to work around Adreno driver bugs reading back unsized sRGB texture data.
623         if (!functions->hasGLESExtension("GL_EXT_sRGB") ||
624             features.unsizedsRGBReadPixelsDoesntTransform.enabled)
625         {
626             if (format == GL_SRGB)
627             {
628                 result = GL_RGB;
629             }
630 
631             if (format == GL_SRGB_ALPHA_EXT)
632             {
633                 result = GL_RGBA;
634             }
635         }
636 
637         if ((type == GL_FLOAT && !functions->hasGLESExtension("GL_OES_texture_float")) ||
638             (type == GL_HALF_FLOAT_OES &&
639              !functions->hasGLESExtension("GL_OES_texture_half_float")))
640         {
641             // On ES 3.0 systems that don't have GL_OES_texture_float or OES_texture_half_float, the
642             // LUMINANCE/ALPHA formats from those extensions must be emulated with R/RG textures.
643             if (IsLUMAFormat(format))
644             {
645                 result = EmulateLUMAFormat(format);
646             }
647         }
648     }
649 
650     return result;
651 }
652 
GetNativeCompressedFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format)653 static GLenum GetNativeCompressedFormat(const FunctionsGL *functions,
654                                         const angle::FeaturesGL &features,
655                                         GLenum format)
656 {
657     GLenum result = format;
658 
659     if (functions->standard == STANDARD_GL_DESKTOP)
660     {
661         if (format == GL_ETC1_RGB8_OES)
662         {
663             // GL_ETC1_RGB8_OES is not available in any desktop GL extension but the compression
664             // format is forwards compatible so just use the ETC2 format.
665             result = GL_COMPRESSED_RGB8_ETC2;
666         }
667     }
668 
669     if (functions->isAtLeastGLES(gl::Version(3, 0)))
670     {
671         if (format == GL_ETC1_RGB8_OES)
672         {
673             // Pass GL_COMPRESSED_RGB8_ETC2 as the target format in ES3 and higher because it
674             // becomes a core format.
675             result = GL_COMPRESSED_RGB8_ETC2;
676         }
677     }
678 
679     if (features.avoidDXT1sRGBTextureFormat.enabled)
680     {
681         if (format == GL_COMPRESSED_SRGB_S3TC_DXT1_EXT)
682         {
683             // Pass GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT instead to workaround driver bug.
684             result = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
685         }
686     }
687 
688     return result;
689 }
690 
GetNativeType(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)691 static GLenum GetNativeType(const FunctionsGL *functions,
692                             const angle::FeaturesGL &features,
693                             GLenum format,
694                             GLenum type)
695 {
696     GLenum result = type;
697 
698     if (functions->standard == STANDARD_GL_DESKTOP)
699     {
700         if (type == GL_HALF_FLOAT_OES)
701         {
702             // The enums differ for the OES half float extensions and desktop GL spec.
703             // Update it.
704             result = GL_HALF_FLOAT;
705         }
706     }
707     else if (functions->isAtLeastGLES(gl::Version(3, 0)))
708     {
709         if (type == GL_HALF_FLOAT_OES)
710         {
711             if (!IsLUMAFormat(format) || !functions->hasGLESExtension("GL_OES_texture_half_float"))
712             {
713                 // In ES3, the luminance formats come from OES_texture_half_float, which uses
714                 // HALF_FLOAT_OES. Other formats (like RGBA) use HALF_FLOAT (non-OES) in ES3.
715                 // If they're emulated (see above), use HALF_FLOAT.
716                 result = GL_HALF_FLOAT;
717             }
718         }
719     }
720     else if (functions->standard == STANDARD_GL_ES && functions->version == gl::Version(2, 0))
721     {
722         // On ES2, convert GL_HALF_FLOAT to GL_HALF_FLOAT_OES as a convenience for internal
723         // functions. It should not be possible to get here by a normal glTexImage2D call.
724         if (type == GL_HALF_FLOAT)
725         {
726             ASSERT(functions->hasGLExtension("GL_OES_texture_half_float"));
727             result = GL_HALF_FLOAT_OES;
728         }
729     }
730 
731     return result;
732 }
733 
GetNativeReadType(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum type)734 static GLenum GetNativeReadType(const FunctionsGL *functions,
735                                 const angle::FeaturesGL &features,
736                                 GLenum type)
737 {
738     GLenum result = type;
739 
740     if (functions->standard == STANDARD_GL_DESKTOP || functions->isAtLeastGLES(gl::Version(3, 0)))
741     {
742         if (type == GL_HALF_FLOAT_OES)
743         {
744             // The enums differ for the OES half float extensions and desktop GL spec. Update it.
745             result = GL_HALF_FLOAT;
746         }
747     }
748 
749     return result;
750 }
751 
GetNativeReadFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum attachmentReadFormat,GLenum format,GLenum type)752 static GLenum GetNativeReadFormat(const FunctionsGL *functions,
753                                   const angle::FeaturesGL &features,
754                                   GLenum attachmentReadFormat,
755                                   GLenum format,
756                                   GLenum type)
757 {
758     GLenum result = format;
759     if (features.readPixelsUsingImplementationColorReadFormatForNorm16.enabled &&
760         type == GL_UNSIGNED_SHORT && format == GL_RGBA &&
761         (attachmentReadFormat == GL_RED || attachmentReadFormat == GL_RG))
762     {
763         result = attachmentReadFormat;
764     }
765     return result;
766 }
767 
GetTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat,GLenum format,GLenum type)768 TexImageFormat GetTexImageFormat(const FunctionsGL *functions,
769                                  const angle::FeaturesGL &features,
770                                  GLenum internalFormat,
771                                  GLenum format,
772                                  GLenum type)
773 {
774     TexImageFormat result;
775     result.internalFormat = GetNativeInternalFormat(
776         functions, features, gl::GetInternalFormatInfo(internalFormat, type));
777     result.format = GetNativeFormat(functions, features, format, type);
778     result.type   = GetNativeType(functions, features, format, type);
779     return result;
780 }
781 
GetTexSubImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)782 TexSubImageFormat GetTexSubImageFormat(const FunctionsGL *functions,
783                                        const angle::FeaturesGL &features,
784                                        GLenum format,
785                                        GLenum type)
786 {
787     TexSubImageFormat result;
788     result.format = GetNativeFormat(functions, features, format, type);
789     result.type   = GetNativeType(functions, features, format, type);
790     return result;
791 }
792 
GetCompressedTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)793 CompressedTexImageFormat GetCompressedTexImageFormat(const FunctionsGL *functions,
794                                                      const angle::FeaturesGL &features,
795                                                      GLenum internalFormat)
796 {
797     CompressedTexImageFormat result;
798     result.internalFormat = GetNativeCompressedFormat(functions, features, internalFormat);
799     return result;
800 }
801 
GetCompressedSubTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format)802 CompressedTexSubImageFormat GetCompressedSubTexImageFormat(const FunctionsGL *functions,
803                                                            const angle::FeaturesGL &features,
804                                                            GLenum format)
805 {
806     CompressedTexSubImageFormat result;
807     result.format = GetNativeCompressedFormat(functions, features, format);
808     return result;
809 }
810 
GetCopyTexImageImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat,GLenum framebufferType)811 CopyTexImageImageFormat GetCopyTexImageImageFormat(const FunctionsGL *functions,
812                                                    const angle::FeaturesGL &features,
813                                                    GLenum internalFormat,
814                                                    GLenum framebufferType)
815 {
816     CopyTexImageImageFormat result;
817     result.internalFormat = GetNativeInternalFormat(
818         functions, features, gl::GetInternalFormatInfo(internalFormat, framebufferType));
819     return result;
820 }
821 
GetTexStorageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)822 TexStorageFormat GetTexStorageFormat(const FunctionsGL *functions,
823                                      const angle::FeaturesGL &features,
824                                      GLenum internalFormat)
825 {
826     TexStorageFormat result;
827     // TexStorage entrypoints accept both compressed and uncompressed formats.
828     // All compressed formats are sized.
829     gl::InternalFormat sizedFormatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
830     if (sizedFormatInfo.compressed)
831     {
832         result.internalFormat = GetNativeCompressedFormat(functions, features, internalFormat);
833     }
834     else
835     {
836         result.internalFormat = GetNativeInternalFormat(functions, features, sizedFormatInfo);
837     }
838 
839     return result;
840 }
841 
GetRenderbufferFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)842 RenderbufferFormat GetRenderbufferFormat(const FunctionsGL *functions,
843                                          const angle::FeaturesGL &features,
844                                          GLenum internalFormat)
845 {
846     RenderbufferFormat result;
847     result.internalFormat = GetNativeInternalFormat(functions, features,
848                                                     gl::GetSizedInternalFormatInfo(internalFormat));
849     return result;
850 }
GetReadPixelsFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum attachmentReadFormat,GLenum format,GLenum type)851 ReadPixelsFormat GetReadPixelsFormat(const FunctionsGL *functions,
852                                      const angle::FeaturesGL &features,
853                                      GLenum attachmentReadFormat,
854                                      GLenum format,
855                                      GLenum type)
856 {
857     ReadPixelsFormat result;
858     result.format = GetNativeReadFormat(functions, features, attachmentReadFormat, format, type);
859     result.type   = GetNativeReadType(functions, features, type);
860     return result;
861 }
862 }  // namespace nativegl
863 
864 }  // namespace rx
865