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 // Floating point formats
259 // Note 1: GL_EXT_texture_shared_exponent and GL_ARB_color_buffer_float suggest that RGB9_E5
260 // would be renderable, but once support for renderable float textures got rolled into core GL
261 // spec it wasn't intended to be renderable. In practice it's not reliably renderable even
262 // with the extensions, there's a known bug in at least NVIDIA driver version 370.
263 //
264 // Note 2: It's a bit unclear whether texture attachments with GL_RGB16F should be supported
265 // in ES3 with GL_EXT_color_buffer_half_float. Probably not, since in ES3 type is HALF_FLOAT,
266 // but GL_EXT_color_buffer_half_float is applicable only to type HALF_FLOAT_OES.
267 //
268 // Note 3: GL_EXT_color_buffer_float implies that ES3.0 is supported, this simplifies the check.
269 //
270 // | Format | OpenGL texture support | Filter | OpenGL render support | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
271 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") );
272 InsertFormatMapping(&map, GL_RGB9_E5, VersionOrExts(3, 0, "GL_EXT_texture_shared_exponent"), AlwaysSupported(), NeverSupported(), VersionOnly(3, 0), AlwaysSupported(), NeverSupported(), NeverSupported() );
273 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"));
274 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"));
275 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") );
276 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") );
277 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") );
278 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") );
279 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() );
280 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") );
281
282 // Depth stencil formats
283 // | Format | OpenGL texture support | Filter | OpenGL render support | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
284 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) );
285 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) );
286 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") );
287 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) );
288 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) );
289 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"));
290 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) );
291 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) );
292 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) );
293
294 // Luminance alpha formats
295 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
296 InsertFormatMapping(&map, GL_ALPHA8_EXT, AlwaysSupported(), AlwaysSupported(), NeverSupported(), AlwaysSupported(), AlwaysSupported(), NeverSupported(), NeverSupported() );
297 InsertFormatMapping(&map, GL_LUMINANCE8_EXT, AlwaysSupported(), AlwaysSupported(), NeverSupported(), AlwaysSupported(), AlwaysSupported(), NeverSupported(), NeverSupported() );
298 InsertFormatMapping(&map, GL_LUMINANCE8_ALPHA8_EXT, AlwaysSupported(), AlwaysSupported(), NeverSupported(), AlwaysSupported(), AlwaysSupported(), NeverSupported(), NeverSupported() );
299 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() );
300 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() );
301 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() );
302 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() );
303 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() );
304 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() );
305
306 // GL_EXT_texture_sRGB_R8 and GL_EXT_texture_sRGB_RG8 formats
307 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
308 InsertFormatMapping(&map, GL_SR8_EXT, ExtsOnly("GL_EXT_texture_sRGB_R8"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_sRGB_R8"), AlwaysSupported(), NeverSupported(), NeverSupported() );
309 InsertFormatMapping(&map, GL_SRG8_EXT, ExtsOnly("GL_EXT_texture_sRGB_RG8"), AlwaysSupported(), NeverSupported(), ExtsOnly("GL_EXT_texture_sRGB_RG8"), AlwaysSupported(), NeverSupported(), NeverSupported() );
310
311 // EXT_texture_compression_rgtc formats
312 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
313 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() );
314 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() );
315 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() );
316 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() );
317
318 // EXT_texture_compression_bptc formats
319 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
320 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() );
321 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() );
322 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() );
323 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() );
324
325 // Compressed formats, From ES 3.0.1 spec, table 3.16
326 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
327 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() );
328 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() );
329 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() );
330 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() );
331 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() );
332 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() );
333 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() );
334 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() );
335 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() );
336 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() );
337
338 // From GL_EXT_texture_compression_dxt1
339 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
340 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() );
341 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() );
342
343 // From GL_ANGLE_texture_compression_dxt3
344 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() );
345
346 // From GL_ANGLE_texture_compression_dxt5
347 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() );
348
349 // From GL_EXT_texture_compression_s3tc_srgb
350 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
351 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() );
352 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() );
353 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() );
354 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() );
355
356 // From GL_OES_compressed_ETC1_RGB8_texture
357 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() );
358
359 // From GL_OES_texture_compression_astc
360 // | Format | OpenGL texture | Filter | Render | OpenGL ES texture support | Filter | ES attachment | ES renderbuffer |
361 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());
362 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());
363 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());
364 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());
365 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());
366 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());
367 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());
368 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());
369 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());
370 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());
371 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());
372 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());
373 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());
374 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());
375 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());
376 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());
377 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());
378 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());
379 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());
380 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());
381 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());
382 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());
383 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());
384 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());
385 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());
386 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());
387 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());
388 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());
389 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_3x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
390 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
391 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x4x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
392 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_4x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
393 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
394 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x5x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
395 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_5x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
396 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
397 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x6x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
398 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_ASTC_6x6x6_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
399 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
400 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
401 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
402 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
403 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
404 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
405 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
406 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
407 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
408 InsertFormatMapping(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_OES_texture_compression_astc"), AlwaysSupported(), NeverSupported(), NeverSupported());
409
410 // From GL_IMG_texture_compression_pvrtc
411 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
412 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() );
413 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() );
414 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() );
415 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() );
416
417 // From GL_EXT_pvrtc_sRGB
418 // | Format | OpenGL texture support | Filter | Render | OpenGL ES texture support | Filter | OpenGL ES texture attachment support | OpenGL ES renderbuffer support |
419 InsertFormatMapping(&map, GL_COMPRESSED_SRGB_PVRTC_2BPPV1_EXT, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"), AlwaysSupported(), NeverSupported(), NeverSupported() );
420 InsertFormatMapping(&map, GL_COMPRESSED_SRGB_PVRTC_4BPPV1_EXT, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"), AlwaysSupported(), NeverSupported(), NeverSupported() );
421 InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_2BPPV1_EXT, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"), AlwaysSupported(), NeverSupported(), NeverSupported() );
422 InsertFormatMapping(&map, GL_COMPRESSED_SRGB_ALPHA_PVRTC_4BPPV1_EXT, NeverSupported(), NeverSupported(), NeverSupported(), ExtsOnly("GL_EXT_pvrtc_sRGB"), AlwaysSupported(), NeverSupported(), NeverSupported() );
423
424 // clang-format on
425
426 return map;
427 }
428
GetInternalFormatMap()429 static const InternalFormatInfoMap &GetInternalFormatMap()
430 {
431 static const angle::base::NoDestructor<InternalFormatInfoMap> formatMap(
432 BuildInternalFormatInfoMap());
433 return *formatMap;
434 }
435
GetInternalFormatInfo(GLenum internalFormat,StandardGL standard)436 const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, StandardGL standard)
437 {
438 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
439 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
440 if (iter != formatMap.end())
441 {
442 const InternalFormatInfo &info = iter->second;
443 switch (standard)
444 {
445 case STANDARD_GL_ES:
446 return info.glesInfo;
447 case STANDARD_GL_DESKTOP:
448 return info.glInfo;
449 default:
450 UNREACHABLE();
451 break;
452 }
453 }
454
455 static const angle::base::NoDestructor<InternalFormat> defaultInternalFormat;
456 return *defaultInternalFormat;
457 }
458
IsLUMAFormat(GLenum format)459 static bool IsLUMAFormat(GLenum format)
460 {
461 return (format == GL_LUMINANCE || format == GL_ALPHA || format == GL_LUMINANCE_ALPHA);
462 }
463
EmulateLUMAFormat(const GLenum format)464 static GLenum EmulateLUMAFormat(const GLenum format)
465 {
466 // This is needed separately from EmulateLUMA because some format/type combinations that come in
467 // to GetNativeFormat don't have entries in the internal format map.
468
469 ASSERT(IsLUMAFormat(format));
470
471 if (format == GL_LUMINANCE || format == GL_ALPHA)
472 return GL_RED;
473
474 return GL_RG;
475 }
476
EmulateLUMA(const gl::InternalFormat & internalFormat)477 static const gl::InternalFormat &EmulateLUMA(const gl::InternalFormat &internalFormat)
478 {
479 ASSERT(IsLUMAFormat(internalFormat.format));
480
481 // Work around deprecated luminance/alpha formats in the OpenGL core profile, and OpenGL ES 3.0
482 // and greater, by backing them with R or RG textures.
483 return gl::GetInternalFormatInfo(EmulateLUMAFormat(internalFormat.format), internalFormat.type);
484 }
485
GetNativeInternalFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,const gl::InternalFormat & internalFormat)486 static GLenum GetNativeInternalFormat(const FunctionsGL *functions,
487 const angle::FeaturesGL &features,
488 const gl::InternalFormat &internalFormat)
489 {
490 GLenum result = internalFormat.internalFormat;
491
492 if (functions->standard == STANDARD_GL_DESKTOP)
493 {
494 // Use sized internal formats whenever possible to guarantee the requested precision.
495 // On Desktop GL, passing an internal format of GL_RGBA will generate a GL_RGBA8 texture
496 // even if the provided type is GL_FLOAT.
497 result = internalFormat.sizedInternalFormat;
498
499 if (features.avoid1BitAlphaTextureFormats.enabled && internalFormat.alphaBits == 1)
500 {
501 // Use an 8-bit format instead
502 result = GL_RGBA8;
503 }
504
505 if (internalFormat.sizedInternalFormat == GL_RGBA4 &&
506 (features.rgba4IsNotSupportedForColorRendering.enabled ||
507 features.promotePackedFormatsTo8BitPerChannel.enabled))
508 {
509 // Use an 8-bit format instead
510 result = GL_RGBA8;
511 }
512
513 if (internalFormat.sizedInternalFormat == GL_RGB565 &&
514 ((!functions->isAtLeastGL(gl::Version(4, 1)) &&
515 !functions->hasGLExtension("GL_ARB_ES2_compatibility")) ||
516 features.promotePackedFormatsTo8BitPerChannel.enabled))
517 {
518 // GL_RGB565 is required for basic ES2 functionality but was not added to desktop GL
519 // until 4.1.
520 // Work around this by using an 8-bit format instead.
521 result = GL_RGB8;
522 }
523
524 if (internalFormat.sizedInternalFormat == GL_BGRA8_EXT)
525 {
526 // GLES accepts GL_BGRA as an internal format but desktop GL only accepts it as a type.
527 // Update the internal format to GL_RGBA.
528 result = GL_RGBA8;
529 }
530
531 if ((functions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
532 {
533 if (IsLUMAFormat(internalFormat.format))
534 {
535 result = EmulateLUMA(internalFormat).sizedInternalFormat;
536 }
537 }
538 }
539 else if (functions->isAtLeastGLES(gl::Version(3, 0)))
540 {
541 if (internalFormat.componentType == GL_FLOAT)
542 {
543 if (!internalFormat.isLUMA())
544 {
545 // Use sized internal formats for floating point textures. Extensions such as
546 // EXT_color_buffer_float require the sized formats to be renderable.
547 result = internalFormat.sizedInternalFormat;
548 }
549 else if ((internalFormat.type == GL_FLOAT &&
550 !functions->hasGLESExtension("GL_OES_texture_float")) ||
551 (internalFormat.type == GL_HALF_FLOAT_OES &&
552 !functions->hasGLESExtension("GL_OES_texture_half_float")))
553 {
554 // The legacy luminance/alpha formats from OES_texture_float are emulated with R/RG
555 // textures.
556 if (IsLUMAFormat(internalFormat.format))
557 {
558 result = EmulateLUMA(internalFormat).sizedInternalFormat;
559 }
560 }
561 }
562 else if (internalFormat.format == GL_RED_EXT || internalFormat.format == GL_RG_EXT)
563 {
564 // Workaround Adreno driver not supporting unsized EXT_texture_rg formats
565 result = internalFormat.sizedInternalFormat;
566 }
567 else if (internalFormat.colorEncoding == GL_SRGB)
568 {
569 if (features.unsizedsRGBReadPixelsDoesntTransform.enabled)
570 {
571 // Work around some Adreno driver bugs that don't read back SRGB data correctly when
572 // it's in unsized SRGB texture formats.
573 result = internalFormat.sizedInternalFormat;
574 }
575 else if (!functions->hasGLESExtension("GL_EXT_sRGB"))
576 {
577 // Unsized sRGB internal formats are unlikely to be supported by the
578 // driver. Transform them to sized internal formats.
579 if (internalFormat.internalFormat == GL_SRGB ||
580 internalFormat.internalFormat == GL_SRGB_ALPHA_EXT)
581 {
582 result = internalFormat.sizedInternalFormat;
583 }
584 }
585 }
586 else if ((internalFormat.internalFormat == GL_DEPTH_COMPONENT ||
587 internalFormat.internalFormat == GL_DEPTH_STENCIL) &&
588 !functions->hasGLESExtension("GL_OES_depth_texture"))
589 {
590 // Use ES 3.0 sized internal formats for depth/stencil textures when the driver doesn't
591 // advertise GL_OES_depth_texture, since it's likely the driver will reject unsized
592 // internal formats.
593 if (internalFormat.internalFormat == GL_DEPTH_COMPONENT &&
594 internalFormat.type == GL_UNSIGNED_INT &&
595 !functions->hasGLESExtension("GL_OES_depth32"))
596 {
597 // Best-effort attempt to provide as many bits as possible.
598 result = GL_DEPTH_COMPONENT24;
599 // Note: could also consider promoting GL_DEPTH_COMPONENT / GL_UNSIGNED_SHORT to a
600 // higher precision.
601 }
602 else
603 {
604 result = internalFormat.sizedInternalFormat;
605 }
606 }
607 }
608
609 return result;
610 }
611
GetNativeFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)612 static GLenum GetNativeFormat(const FunctionsGL *functions,
613 const angle::FeaturesGL &features,
614 GLenum format,
615 GLenum type)
616 {
617 GLenum result = format;
618
619 if (functions->standard == STANDARD_GL_DESKTOP)
620 {
621 // The ES SRGB extensions require that the provided format is GL_SRGB or SRGB_ALPHA but
622 // the desktop GL extensions only accept GL_RGB or GL_RGBA. Convert them.
623 if (format == GL_SRGB)
624 {
625 result = GL_RGB;
626 }
627
628 if (format == GL_SRGB_ALPHA)
629 {
630 result = GL_RGBA;
631 }
632
633 if ((functions->profile & GL_CONTEXT_CORE_PROFILE_BIT) != 0)
634 {
635 // Work around deprecated luminance alpha formats in the OpenGL core profile by backing
636 // them with R or RG textures.
637 if (IsLUMAFormat(format))
638 {
639 result = EmulateLUMAFormat(format);
640 }
641 }
642 }
643 else if (functions->isAtLeastGLES(gl::Version(3, 0)))
644 {
645 // Transform sRGB formats to RGB if either the GLES driver doesn't support GL_EXT_sRGB, or
646 // to work around Adreno driver bugs reading back unsized sRGB texture data.
647 if (!functions->hasGLESExtension("GL_EXT_sRGB") ||
648 features.unsizedsRGBReadPixelsDoesntTransform.enabled)
649 {
650 if (format == GL_SRGB)
651 {
652 result = GL_RGB;
653 }
654
655 if (format == GL_SRGB_ALPHA_EXT)
656 {
657 result = GL_RGBA;
658 }
659 }
660
661 if ((type == GL_FLOAT && !functions->hasGLESExtension("GL_OES_texture_float")) ||
662 (type == GL_HALF_FLOAT_OES &&
663 !functions->hasGLESExtension("GL_OES_texture_half_float")))
664 {
665 // On ES 3.0 systems that don't have GL_OES_texture_float or OES_texture_half_float, the
666 // LUMINANCE/ALPHA formats from those extensions must be emulated with R/RG textures.
667 if (IsLUMAFormat(format))
668 {
669 result = EmulateLUMAFormat(format);
670 }
671 }
672 }
673
674 return result;
675 }
676
GetNativeCompressedFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format)677 static GLenum GetNativeCompressedFormat(const FunctionsGL *functions,
678 const angle::FeaturesGL &features,
679 GLenum format)
680 {
681 GLenum result = format;
682
683 if (functions->standard == STANDARD_GL_DESKTOP)
684 {
685 if (format == GL_ETC1_RGB8_OES)
686 {
687 // GL_ETC1_RGB8_OES is not available in any desktop GL extension but the compression
688 // format is forwards compatible so just use the ETC2 format.
689 result = GL_COMPRESSED_RGB8_ETC2;
690 }
691 }
692
693 if (functions->isAtLeastGLES(gl::Version(3, 0)))
694 {
695 if (format == GL_ETC1_RGB8_OES)
696 {
697 // Pass GL_COMPRESSED_RGB8_ETC2 as the target format in ES3 and higher because it
698 // becomes a core format.
699 result = GL_COMPRESSED_RGB8_ETC2;
700 }
701 }
702
703 return result;
704 }
705
GetNativeType(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)706 static GLenum GetNativeType(const FunctionsGL *functions,
707 const angle::FeaturesGL &features,
708 GLenum format,
709 GLenum type)
710 {
711 GLenum result = type;
712
713 if (functions->standard == STANDARD_GL_DESKTOP)
714 {
715 if (type == GL_HALF_FLOAT_OES)
716 {
717 // The enums differ for the OES half float extensions and desktop GL spec.
718 // Update it.
719 result = GL_HALF_FLOAT;
720 }
721 }
722 else if (functions->isAtLeastGLES(gl::Version(3, 0)))
723 {
724 if (type == GL_HALF_FLOAT_OES)
725 {
726 if (!IsLUMAFormat(format) || !functions->hasGLESExtension("GL_OES_texture_half_float"))
727 {
728 // In ES3, the luminance formats come from OES_texture_half_float, which uses
729 // HALF_FLOAT_OES. Other formats (like RGBA) use HALF_FLOAT (non-OES) in ES3.
730 // If they're emulated (see above), use HALF_FLOAT.
731 result = GL_HALF_FLOAT;
732 }
733 }
734 }
735 else if (functions->isAtLeastGLES(gl::Version(2, 0)))
736 {
737 // On ES2, convert GL_HALF_FLOAT to GL_HALF_FLOAT_OES as a convenience for internal
738 // functions. It should not be possible to get here by a normal glTexImage2D call.
739 if (type == GL_HALF_FLOAT)
740 {
741 ASSERT(functions->hasGLESExtension("GL_OES_texture_half_float"));
742 result = GL_HALF_FLOAT_OES;
743 }
744 }
745
746 return result;
747 }
748
GetNativeReadType(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum type)749 static GLenum GetNativeReadType(const FunctionsGL *functions,
750 const angle::FeaturesGL &features,
751 GLenum type)
752 {
753 GLenum result = type;
754
755 if (functions->standard == STANDARD_GL_DESKTOP || functions->isAtLeastGLES(gl::Version(3, 0)))
756 {
757 if (type == GL_HALF_FLOAT_OES)
758 {
759 // The enums differ for the OES half float extensions and desktop GL spec. Update it.
760 result = GL_HALF_FLOAT;
761 }
762 }
763
764 return result;
765 }
766
GetNativeReadFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum attachmentReadFormat,GLenum format,GLenum type)767 static GLenum GetNativeReadFormat(const FunctionsGL *functions,
768 const angle::FeaturesGL &features,
769 GLenum attachmentReadFormat,
770 GLenum format,
771 GLenum type)
772 {
773 GLenum result = format;
774 if (features.readPixelsUsingImplementationColorReadFormatForNorm16.enabled &&
775 type == GL_UNSIGNED_SHORT && format == GL_RGBA &&
776 (attachmentReadFormat == GL_RED || attachmentReadFormat == GL_RG))
777 {
778 result = attachmentReadFormat;
779 }
780 return result;
781 }
782
GetTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat,GLenum format,GLenum type)783 TexImageFormat GetTexImageFormat(const FunctionsGL *functions,
784 const angle::FeaturesGL &features,
785 GLenum internalFormat,
786 GLenum format,
787 GLenum type)
788 {
789 TexImageFormat result;
790 result.internalFormat = GetNativeInternalFormat(
791 functions, features, gl::GetInternalFormatInfo(internalFormat, type));
792 result.format = GetNativeFormat(functions, features, format, type);
793 result.type = GetNativeType(functions, features, format, type);
794 return result;
795 }
796
GetTexSubImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format,GLenum type)797 TexSubImageFormat GetTexSubImageFormat(const FunctionsGL *functions,
798 const angle::FeaturesGL &features,
799 GLenum format,
800 GLenum type)
801 {
802 TexSubImageFormat result;
803 result.format = GetNativeFormat(functions, features, format, type);
804 result.type = GetNativeType(functions, features, format, type);
805 return result;
806 }
807
GetCompressedTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)808 CompressedTexImageFormat GetCompressedTexImageFormat(const FunctionsGL *functions,
809 const angle::FeaturesGL &features,
810 GLenum internalFormat)
811 {
812 CompressedTexImageFormat result;
813 result.internalFormat = GetNativeCompressedFormat(functions, features, internalFormat);
814 return result;
815 }
816
GetCompressedSubTexImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum format)817 CompressedTexSubImageFormat GetCompressedSubTexImageFormat(const FunctionsGL *functions,
818 const angle::FeaturesGL &features,
819 GLenum format)
820 {
821 CompressedTexSubImageFormat result;
822 result.format = GetNativeCompressedFormat(functions, features, format);
823 return result;
824 }
825
GetCopyTexImageImageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat,GLenum framebufferType)826 CopyTexImageImageFormat GetCopyTexImageImageFormat(const FunctionsGL *functions,
827 const angle::FeaturesGL &features,
828 GLenum internalFormat,
829 GLenum framebufferType)
830 {
831 CopyTexImageImageFormat result;
832 result.internalFormat = GetNativeInternalFormat(
833 functions, features, gl::GetInternalFormatInfo(internalFormat, framebufferType));
834 return result;
835 }
836
GetTexStorageFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)837 TexStorageFormat GetTexStorageFormat(const FunctionsGL *functions,
838 const angle::FeaturesGL &features,
839 GLenum internalFormat)
840 {
841 TexStorageFormat result;
842 // TexStorage entrypoints accept both compressed and uncompressed formats.
843 // All compressed formats are sized.
844 gl::InternalFormat sizedFormatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
845 if (sizedFormatInfo.compressed)
846 {
847 result.internalFormat = GetNativeCompressedFormat(functions, features, internalFormat);
848 }
849 else
850 {
851 result.internalFormat = GetNativeInternalFormat(functions, features, sizedFormatInfo);
852 }
853
854 return result;
855 }
856
GetRenderbufferFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum internalFormat)857 RenderbufferFormat GetRenderbufferFormat(const FunctionsGL *functions,
858 const angle::FeaturesGL &features,
859 GLenum internalFormat)
860 {
861 RenderbufferFormat result;
862 result.internalFormat = GetNativeInternalFormat(functions, features,
863 gl::GetSizedInternalFormatInfo(internalFormat));
864 return result;
865 }
GetReadPixelsFormat(const FunctionsGL * functions,const angle::FeaturesGL & features,GLenum attachmentReadFormat,GLenum format,GLenum type)866 ReadPixelsFormat GetReadPixelsFormat(const FunctionsGL *functions,
867 const angle::FeaturesGL &features,
868 GLenum attachmentReadFormat,
869 GLenum format,
870 GLenum type)
871 {
872 ReadPixelsFormat result;
873 result.format = GetNativeReadFormat(functions, features, attachmentReadFormat, format, type);
874 result.type = GetNativeReadType(functions, features, type);
875 return result;
876 }
877 } // namespace nativegl
878
879 } // namespace rx
880