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