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