blob: 806adda05aa4e78c4abd733f5e0f72c68c89fb46 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
Frank Henigman95fb2a12018-05-27 20:17:05 -040020// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the
21// implementation can decide the true, sized, internal format. The ES2FormatMap determines the
22// internal format for all valid format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Geoff Langca271392017-04-05 12:30:00 -040027using InternalFormatInfoMap =
28 std::unordered_map<GLenum, std::unordered_map<GLenum, InternalFormat>>;
Jamie Madilla3944d42016-07-22 22:13:26 -040029
Jamie Madillca2ff382018-07-11 09:01:17 -040030bool CheckedMathResult(const CheckedNumeric<GLuint> &value, GLuint *resultOut)
31{
32 if (!value.IsValid())
33 {
34 return false;
35 }
36 else
37 {
38 *resultOut = value.ValueOrDie();
39 return true;
40 }
41}
Markus Tavenrath0d665132018-11-18 15:47:02 +010042
43constexpr GLuint Log2(GLuint bytes)
44{
45 return bytes == 1 ? 0 : (1 + Log2(bytes / 2));
46}
47
48constexpr uint32_t PackTypeInfo(GLuint bytes, bool specialized)
49{
50 // static_assert within constexpr requires c++17
51 // static_assert(isPow2(bytes));
52 return bytes | (Log2(bytes) << 8) | (specialized << 16);
53}
54
Jamie Madilla3944d42016-07-22 22:13:26 -040055} // anonymous namespace
56
Markus Tavenrath0d665132018-11-18 15:47:02 +010057FormatType::FormatType() : format(GL_NONE), type(GL_NONE) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040058
Markus Tavenrath0d665132018-11-18 15:47:02 +010059FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040060
61bool FormatType::operator<(const FormatType &other) const
62{
63 if (format != other.format)
64 return format < other.format;
65 return type < other.type;
66}
67
Frank Henigman95fb2a12018-05-27 20:17:05 -040068bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040069{
70 return memcmp(&a, &b, sizeof(Type)) < 0;
71}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000072
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040074static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075{
Geoff Lang493daf52014-07-03 13:38:44 -040076 return true;
77}
78
Geoff Langeb66a6e2016-10-31 13:06:12 -040079static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000080{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081 return false;
82}
83
Geoff Langeb66a6e2016-10-31 13:06:12 -040084template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
85static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040086{
Geoff Langeb66a6e2016-10-31 13:06:12 -040087 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040088}
89
Geoff Langcec35902014-04-16 10:52:36 -040090// Pointer to a boolean memeber of the Extensions struct
91typedef bool(Extensions::*ExtensionBool);
92
93// Check support for a single extension
94template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040095static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040096{
Geoff Lange4a492b2014-06-19 14:14:41 -040097 return extensions.*bool1;
98}
99
100// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400101template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
102static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400103{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400104 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
105 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400106}
107
108// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400109template <GLuint minCoreGLMajorVersion,
110 GLuint minCoreGLMinorVersion,
111 ExtensionBool bool1,
112 ExtensionBool bool2>
113static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400114{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400115 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
116 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400117}
118
119// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400120template <GLuint minCoreGLMajorVersion,
121 GLuint minCoreGLMinorVersion,
122 ExtensionBool bool1,
123 ExtensionBool bool2>
124static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400125{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400126 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
127 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400128}
129
130// Check support for two extensions
131template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400132static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400133{
Geoff Langabce7622014-09-19 16:13:00 -0400134 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400135}
136
Geoff Lang60ad73d2015-10-23 10:08:44 -0400137// Check support for either of two extensions
138template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400139static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400140{
141 return extensions.*bool1 || extensions.*bool2;
142}
143
Yuly Novikovd0828192018-06-15 15:51:07 -0400144// R8, RG8
145static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500146{
Yuly Novikovd0828192018-06-15 15:51:07 -0400147 return clientVersion >= Version(3, 0) || (extensions.textureStorage && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500148}
149
Yuly Novikovd0828192018-06-15 15:51:07 -0400150// R16F, RG16F with HALF_FLOAT_OES type
151static bool SizedHalfFloatOESRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500152{
Yuly Novikovd0828192018-06-15 15:51:07 -0400153 return extensions.textureStorage && extensions.textureHalfFloat && extensions.textureRG;
Jamie Madillcd089732015-12-17 09:53:09 -0500154}
155
Yuly Novikovd0828192018-06-15 15:51:07 -0400156static bool SizedHalfFloatOESRGTextureAttachmentSupport(const Version &clientVersion,
157 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400158{
Yuly Novikovd0828192018-06-15 15:51:07 -0400159 return SizedHalfFloatOESRGSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400160}
161
Yuly Novikovd0828192018-06-15 15:51:07 -0400162// R16F, RG16F with either HALF_FLOAT_OES or HALF_FLOAT types
163static bool SizedHalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500164{
Yuly Novikovd0828192018-06-15 15:51:07 -0400165 // HALF_FLOAT
166 if (clientVersion >= Version(3, 0))
167 {
168 return true;
169 }
170 // HALF_FLOAT_OES
171 else
172 {
173 return SizedHalfFloatOESRGSupport(clientVersion, extensions);
174 }
Jamie Madillcd089732015-12-17 09:53:09 -0500175}
176
Yuly Novikovd0828192018-06-15 15:51:07 -0400177static bool SizedHalfFloatRGTextureAttachmentSupport(const Version &clientVersion,
178 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500179{
Yuly Novikovd0828192018-06-15 15:51:07 -0400180 // HALF_FLOAT
181 if (clientVersion >= Version(3, 0))
182 {
183 return extensions.colorBufferFloat;
184 }
185 // HALF_FLOAT_OES
186 else
187 {
188 return SizedHalfFloatOESRGTextureAttachmentSupport(clientVersion, extensions);
189 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190}
191
Yuly Novikovd0828192018-06-15 15:51:07 -0400192static bool SizedHalfFloatRGRenderbufferSupport(const Version &clientVersion,
193 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194{
Yuly Novikovd0828192018-06-15 15:51:07 -0400195 return (clientVersion >= Version(3, 0) ||
196 (extensions.textureHalfFloat && extensions.textureRG)) &&
197 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198}
199
Yuly Novikovd0828192018-06-15 15:51:07 -0400200// RGB16F, RGBA16F with HALF_FLOAT_OES type
201static bool SizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400202{
Yuly Novikovd0828192018-06-15 15:51:07 -0400203 return extensions.textureStorage && extensions.textureHalfFloat;
204}
205
206static bool SizedHalfFloatOESTextureAttachmentSupport(const Version &clientVersion,
207 const Extensions &extensions)
208{
209 return SizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
210}
211
212// RGB16F, RGBA16F with either HALF_FLOAT_OES or HALF_FLOAT types
213static bool SizedHalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
214{
215 // HALF_FLOAT
216 if (clientVersion >= Version(3, 0))
217 {
218 return true;
219 }
220 // HALF_FLOAT_OES
221 else
222 {
223 return SizedHalfFloatOESSupport(clientVersion, extensions);
224 }
225}
226
227static bool SizedHalfFloatFilterSupport(const Version &clientVersion, const Extensions &extensions)
228{
229 // HALF_FLOAT
230 if (clientVersion >= Version(3, 0))
231 {
232 return true;
233 }
234 // HALF_FLOAT_OES
235 else
236 {
237 return extensions.textureHalfFloatLinear;
238 }
239}
240
241static bool SizedHalfFloatRGBTextureAttachmentSupport(const Version &clientVersion,
242 const Extensions &extensions)
243{
244 // HALF_FLOAT
245 if (clientVersion >= Version(3, 0))
246 {
247 // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
248 // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
249 // is possible, so assume that all GLES implementations support it.
250 return extensions.colorBufferHalfFloat;
251 }
252 // HALF_FLOAT_OES
253 else
254 {
255 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
256 }
257}
258
259static bool SizedHalfFloatRGBRenderbufferSupport(const Version &clientVersion,
260 const Extensions &extensions)
261{
262 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400263 extensions.colorBufferHalfFloat;
264}
265
Yuly Novikovd0828192018-06-15 15:51:07 -0400266static bool SizedHalfFloatRGBATextureAttachmentSupport(const Version &clientVersion,
267 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400268{
Yuly Novikovd0828192018-06-15 15:51:07 -0400269 // HALF_FLOAT
270 if (clientVersion >= Version(3, 0))
271 {
272 return extensions.colorBufferFloat;
273 }
274 // HALF_FLOAT_OES
275 else
276 {
277 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
278 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400279}
280
Yuly Novikovd0828192018-06-15 15:51:07 -0400281static bool SizedHalfFloatRGBARenderbufferSupport(const Version &clientVersion,
282 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400283{
Yuly Novikovd0828192018-06-15 15:51:07 -0400284 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
285 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500286}
287
Yuly Novikovd0828192018-06-15 15:51:07 -0400288// R32F, RG32F
289static bool SizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500290{
Yuly Novikovd0828192018-06-15 15:51:07 -0400291 return clientVersion >= Version(3, 0) ||
292 (extensions.textureStorage && extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500293}
294
Geoff Lang677bb6f2017-04-05 12:40:40 -0400295// RGB32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400296static bool SizedFloatRGBSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500297{
Yuly Novikovd0828192018-06-15 15:51:07 -0400298 return clientVersion >= Version(3, 0) ||
299 (extensions.textureStorage && extensions.textureFloat) || extensions.colorBufferFloatRGB;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400300}
301
302// RGBA32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400303static bool SizedFloatRGBASupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400304{
Yuly Novikovd0828192018-06-15 15:51:07 -0400305 return clientVersion >= Version(3, 0) ||
306 (extensions.textureStorage && extensions.textureFloat) ||
307 extensions.colorBufferFloatRGBA;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400308}
309
Yuly Novikovd0828192018-06-15 15:51:07 -0400310static bool SizedFloatRGBATextureAttachmentSupport(const Version &clientVersion,
311 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400312{
Yuly Novikovd0828192018-06-15 15:51:07 -0400313 return (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
Jamie Madillcd089732015-12-17 09:53:09 -0500314}
315
Geoff Lang5d601382014-07-22 15:14:06 -0400316InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400317 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400318 sized(false),
319 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400320 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400321 greenBits(0),
322 blueBits(0),
323 luminanceBits(0),
324 alphaBits(0),
325 sharedBits(0),
326 depthBits(0),
327 stencilBits(0),
328 pixelBytes(0),
329 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400330 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400331 compressedBlockWidth(0),
332 compressedBlockHeight(0),
333 format(GL_NONE),
334 type(GL_NONE),
335 componentType(GL_NONE),
336 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400337 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400338 filterSupport(NeverSupported),
339 textureAttachmentSupport(NeverSupported),
340 renderbufferSupport(NeverSupported)
Jamie Madillb980c562018-11-27 11:34:27 -0500341{}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000342
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500343InternalFormat::InternalFormat(const InternalFormat &other) = default;
344
Jamie Madilla3944d42016-07-22 22:13:26 -0400345bool InternalFormat::isLUMA() const
346{
347 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
348 (luminanceBits + alphaBits) > 0);
349}
350
Geoff Langf607c602016-09-21 11:46:48 -0400351GLenum InternalFormat::getReadPixelsFormat() const
352{
353 return format;
354}
355
Geoff Langc71ea662017-09-26 17:06:02 -0400356GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400357{
358 switch (type)
359 {
360 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400361 case GL_HALF_FLOAT_OES:
362 if (version < Version(3, 0))
363 {
364 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
365 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
366 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
367 // as an IMPLEMENTATION_READ_TYPE.
368 return GL_HALF_FLOAT_OES;
369 }
370 else
371 {
372 return GL_HALF_FLOAT;
373 }
Geoff Langf607c602016-09-21 11:46:48 -0400374
375 default:
376 return type;
377 }
378}
379
Olli Etuaho50c562d2017-06-06 14:43:30 +0300380bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
381{
382 // GLES 3.0.5 section 4.4.2.2:
383 // "Implementations are required to support the same internal formats for renderbuffers as the
384 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
385 // formats labelled "texture-only"."
386 if (!sized || compressed)
387 {
388 return false;
389 }
390
391 // Luma formats.
392 if (isLUMA())
393 {
394 return false;
395 }
396
397 // Depth/stencil formats.
398 if (depthBits > 0 || stencilBits > 0)
399 {
400 // GLES 2.0.25 table 4.5.
401 // GLES 3.0.5 section 3.8.3.1.
402 // GLES 3.1 table 8.14.
403
404 // Required formats in all versions.
405 switch (internalFormat)
406 {
407 case GL_DEPTH_COMPONENT16:
408 case GL_STENCIL_INDEX8:
409 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
410 // is in section 4.4.2.2.
411 return true;
412 default:
413 break;
414 }
415 if (version.major < 3)
416 {
417 return false;
418 }
419 // Required formats in GLES 3.0 and up.
420 switch (internalFormat)
421 {
422 case GL_DEPTH_COMPONENT32F:
423 case GL_DEPTH_COMPONENT24:
424 case GL_DEPTH32F_STENCIL8:
425 case GL_DEPTH24_STENCIL8:
426 return true;
427 default:
428 return false;
429 }
430 }
431
432 // RGBA formats.
433 // GLES 2.0.25 table 4.5.
434 // GLES 3.0.5 section 3.8.3.1.
435 // GLES 3.1 table 8.13.
436
437 // Required formats in all versions.
438 switch (internalFormat)
439 {
440 case GL_RGBA4:
441 case GL_RGB5_A1:
442 case GL_RGB565:
443 return true;
444 default:
445 break;
446 }
447 if (version.major < 3)
448 {
449 return false;
450 }
451
452 if (format == GL_BGRA_EXT)
453 {
454 return false;
455 }
456
457 switch (componentType)
458 {
459 case GL_SIGNED_NORMALIZED:
460 case GL_FLOAT:
461 return false;
462 case GL_UNSIGNED_INT:
463 case GL_INT:
464 // Integer RGB formats are not required renderbuffer formats.
465 if (alphaBits == 0 && blueBits != 0)
466 {
467 return false;
468 }
469 // All integer R and RG formats are required.
470 // Integer RGBA formats including RGB10_A2_UI are required.
471 return true;
472 case GL_UNSIGNED_NORMALIZED:
473 if (internalFormat == GL_SRGB8)
474 {
475 return false;
476 }
477 return true;
478 default:
479 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500480#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300481 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500482#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300483 }
484}
485
Markus Tavenrath0d665132018-11-18 15:47:02 +0100486Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat)) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400487
Markus Tavenrath0d665132018-11-18 15:47:02 +0100488Format::Format(const InternalFormat &internalFormat) : info(&internalFormat) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400489
Geoff Langca271392017-04-05 12:30:00 -0400490Format::Format(GLenum internalFormat, GLenum type)
491 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madillb980c562018-11-27 11:34:27 -0500492{}
Jamie Madilla3944d42016-07-22 22:13:26 -0400493
494Format::Format(const Format &other) = default;
495Format &Format::operator=(const Format &other) = default;
496
Jamie Madilla3944d42016-07-22 22:13:26 -0400497bool Format::valid() const
498{
Geoff Langca271392017-04-05 12:30:00 -0400499 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400500}
501
502// static
503bool Format::SameSized(const Format &a, const Format &b)
504{
Geoff Langca271392017-04-05 12:30:00 -0400505 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400506}
507
Kenneth Russell69382852017-07-21 16:38:44 -0400508static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
509{
510 // BlitFramebuffer works if the color channels are identically
511 // sized, even if there is a swizzle (for example, blitting from a
512 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
513 // be expanded and/or autogenerated if that is found necessary.
514 if (internalformat == GL_BGRA8_EXT)
515 return GL_RGBA8;
516 return internalformat;
517}
518
519// static
520bool Format::EquivalentForBlit(const Format &a, const Format &b)
521{
522 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
523 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
524}
525
Jamie Madilla3944d42016-07-22 22:13:26 -0400526// static
527Format Format::Invalid()
528{
Geoff Langca271392017-04-05 12:30:00 -0400529 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400530 return invalid;
531}
532
Yuly Novikovd73f8522017-01-13 17:48:57 -0500533std::ostream &operator<<(std::ostream &os, const Format &fmt)
534{
535 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400536 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500537}
538
Jamie Madilla3944d42016-07-22 22:13:26 -0400539bool InternalFormat::operator==(const InternalFormat &other) const
540{
Geoff Langca271392017-04-05 12:30:00 -0400541 // We assume all internal formats are unique if they have the same internal format and type
542 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400543}
544
545bool InternalFormat::operator!=(const InternalFormat &other) const
546{
Geoff Langca271392017-04-05 12:30:00 -0400547 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400548}
549
Geoff Langca271392017-04-05 12:30:00 -0400550void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400551{
Geoff Langca271392017-04-05 12:30:00 -0400552 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
553 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
554 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400555}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000556
Jamie Madilla3944d42016-07-22 22:13:26 -0400557void AddRGBAFormat(InternalFormatInfoMap *map,
558 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400559 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400560 GLuint red,
561 GLuint green,
562 GLuint blue,
563 GLuint alpha,
564 GLuint shared,
565 GLenum format,
566 GLenum type,
567 GLenum componentType,
568 bool srgb,
569 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400570 InternalFormat::SupportCheckFunction filterSupport,
571 InternalFormat::SupportCheckFunction textureAttachmentSupport,
572 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400573{
574 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400575 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400576 formatInfo.sized = sized;
577 formatInfo.sizedInternalFormat =
578 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400579 formatInfo.redBits = red;
580 formatInfo.greenBits = green;
581 formatInfo.blueBits = blue;
582 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400583 formatInfo.sharedBits = shared;
584 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400585 formatInfo.componentCount =
586 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400587 formatInfo.format = format;
588 formatInfo.type = type;
589 formatInfo.componentType = componentType;
590 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
591 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400592 formatInfo.filterSupport = filterSupport;
593 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
594 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400595
596 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400597}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000598
Geoff Langca271392017-04-05 12:30:00 -0400599static void AddLUMAFormat(InternalFormatInfoMap *map,
600 GLenum internalFormat,
601 bool sized,
602 GLuint luminance,
603 GLuint alpha,
604 GLenum format,
605 GLenum type,
606 GLenum componentType,
607 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400608 InternalFormat::SupportCheckFunction filterSupport,
609 InternalFormat::SupportCheckFunction textureAttachmentSupport,
610 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400611{
612 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400613 formatInfo.internalFormat = internalFormat;
614 formatInfo.sized = sized;
615 formatInfo.sizedInternalFormat =
616 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400617 formatInfo.luminanceBits = luminance;
618 formatInfo.alphaBits = alpha;
619 formatInfo.pixelBytes = (luminance + alpha) / 8;
620 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
621 formatInfo.format = format;
622 formatInfo.type = type;
623 formatInfo.componentType = componentType;
624 formatInfo.colorEncoding = GL_LINEAR;
625 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400626 formatInfo.filterSupport = filterSupport;
627 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
628 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400629
630 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400631}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000632
Jamie Madilla3944d42016-07-22 22:13:26 -0400633void AddDepthStencilFormat(InternalFormatInfoMap *map,
634 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400635 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400636 GLuint depthBits,
637 GLuint stencilBits,
638 GLuint unusedBits,
639 GLenum format,
640 GLenum type,
641 GLenum componentType,
642 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400643 InternalFormat::SupportCheckFunction filterSupport,
644 InternalFormat::SupportCheckFunction textureAttachmentSupport,
645 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400646{
647 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400648 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400649 formatInfo.sized = sized;
650 formatInfo.sizedInternalFormat =
651 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400652 formatInfo.depthBits = depthBits;
653 formatInfo.stencilBits = stencilBits;
654 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
655 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
656 formatInfo.format = format;
657 formatInfo.type = type;
658 formatInfo.componentType = componentType;
659 formatInfo.colorEncoding = GL_LINEAR;
660 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400661 formatInfo.filterSupport = filterSupport;
662 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
663 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400664
665 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400666}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000667
Geoff Langca271392017-04-05 12:30:00 -0400668void AddCompressedFormat(InternalFormatInfoMap *map,
669 GLenum internalFormat,
670 GLuint compressedBlockWidth,
671 GLuint compressedBlockHeight,
672 GLuint compressedBlockSize,
673 GLuint componentCount,
674 GLenum format,
675 GLenum type,
676 bool srgb,
677 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400678 InternalFormat::SupportCheckFunction filterSupport,
679 InternalFormat::SupportCheckFunction textureAttachmentSupport,
680 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400681{
682 InternalFormat formatInfo;
Geoff Langcb8a9212018-06-28 12:30:36 -0400683 formatInfo.internalFormat = internalFormat;
684 formatInfo.sized = true;
685 formatInfo.sizedInternalFormat = internalFormat;
686 formatInfo.compressedBlockWidth = compressedBlockWidth;
687 formatInfo.compressedBlockHeight = compressedBlockHeight;
688 formatInfo.pixelBytes = compressedBlockSize / 8;
689 formatInfo.componentCount = componentCount;
690 formatInfo.format = format;
691 formatInfo.type = type;
692 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
693 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
694 formatInfo.compressed = true;
695 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400696 formatInfo.filterSupport = filterSupport;
697 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
698 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400699
700 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400701}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000702
Yuly Novikovd0828192018-06-15 15:51:07 -0400703// Notes:
704// 1. "Texture supported" includes all the means by which texture can be created, however,
705// GL_EXT_texture_storage in ES2 is a special case, when only glTexStorage* is allowed.
706// The assumption is that ES2 validation will not check textureSupport for sized formats.
707//
708// 2. Sized half float types are a combination of GL_HALF_FLOAT and GL_HALF_FLOAT_OES support,
709// due to a limitation that only one type for sized formats is allowed.
710//
711// TODO(ynovikov): http://anglebug.com/2846 Verify support fields of BGRA, depth, stencil
712// and compressed formats. Perform texturable check as part of filterable and attachment checks.
Geoff Lange4a492b2014-06-19 14:14:41 -0400713static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000714{
715 InternalFormatInfoMap map;
716
717 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400718 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000719
Jamie Madilla3944d42016-07-22 22:13:26 -0400720 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000721
Yuly Novikovd0828192018-06-15 15:51:07 -0400722 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
723 AddRGBAFormat(&map, GL_R8, true, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, SizedRGSupport, AlwaysSupported, SizedRGSupport, RequireESOrExt<3, 0, &Extensions::textureRG> );
724 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
725 AddRGBAFormat(&map, GL_RG8, true, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, SizedRGSupport, AlwaysSupported, SizedRGSupport, RequireESOrExt<3, 0, &Extensions::textureRG> );
726 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
727 AddRGBAFormat(&map, GL_RGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
728 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
729 AddRGBAFormat(&map, GL_RGB565, true, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
730 AddRGBAFormat(&map, GL_RGBA4, true, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
731 AddRGBAFormat(&map, GL_RGB5_A1, true, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
732 AddRGBAFormat(&map, GL_RGBA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
733 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
734 AddRGBAFormat(&map, GL_RGB10_A2, true, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> );
735 AddRGBAFormat(&map, GL_RGB10_A2UI, true, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
736 AddRGBAFormat(&map, GL_SRGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
737 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::sRGB> );
738 AddRGBAFormat(&map, GL_R11F_G11F_B10F, true, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3, 0>, AlwaysSupported, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat> );
739 AddRGBAFormat(&map, GL_RGB9_E5, true, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
740 AddRGBAFormat(&map, GL_R8I, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
741 AddRGBAFormat(&map, GL_R8UI, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
742 AddRGBAFormat(&map, GL_R16I, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
743 AddRGBAFormat(&map, GL_R16UI, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
744 AddRGBAFormat(&map, GL_R32I, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
745 AddRGBAFormat(&map, GL_R32UI, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
746 AddRGBAFormat(&map, GL_RG8I, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
747 AddRGBAFormat(&map, GL_RG8UI, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
748 AddRGBAFormat(&map, GL_RG16I, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
749 AddRGBAFormat(&map, GL_RG16UI, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
750 AddRGBAFormat(&map, GL_RG32I, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
751 AddRGBAFormat(&map, GL_RG32UI, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
752 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
753 AddRGBAFormat(&map, GL_RGB8UI, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
754 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
755 AddRGBAFormat(&map, GL_RGB16UI, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
756 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
757 AddRGBAFormat(&map, GL_RGB32UI, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
758 AddRGBAFormat(&map, GL_RGBA8I, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
759 AddRGBAFormat(&map, GL_RGBA8UI, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
760 AddRGBAFormat(&map, GL_RGBA16I, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
761 AddRGBAFormat(&map, GL_RGBA16UI, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
762 AddRGBAFormat(&map, GL_RGBA32I, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
763 AddRGBAFormat(&map, GL_RGBA32UI, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
Jamie Madilla3944d42016-07-22 22:13:26 -0400764
Yuly Novikovd0828192018-06-15 15:51:07 -0400765 AddRGBAFormat(&map, GL_BGRA8_EXT, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
766 AddRGBAFormat(&map, GL_BGRA4_ANGLEX, true, 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
767 AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX, true, 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000768
Olli Etuahoceffd202018-01-08 16:39:45 +0200769 // Special format that is used for D3D textures that are used within ANGLE via the
770 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
771 // this format, but textures in this format can be created from D3D textures, and filtering them
772 // and rendering to them is allowed.
Yuly Novikovd0828192018-06-15 15:51:07 -0400773 AddRGBAFormat(&map, GL_BGRA8_SRGB_ANGLEX, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported, AlwaysSupported );
Olli Etuahoceffd202018-01-08 16:39:45 +0200774
Jamie Madillec0b5802016-07-04 13:11:59 -0400775 // Special format which is not really supported, so always false for all supports.
Yuly Novikovd0828192018-06-15 15:51:07 -0400776 AddRGBAFormat(&map, GL_BGRX8_ANGLEX, true, 8, 8, 8, 0, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
777 AddRGBAFormat(&map, GL_BGR565_ANGLEX, true, 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
Jamie Madillec0b5802016-07-04 13:11:59 -0400778
Yuly Novikovd0828192018-06-15 15:51:07 -0400779 // Floating point formats
780 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
781 // It's not possible to have two entries per sized format.
782 // E.g. for GL_RG16F, one with GL_HALF_FLOAT type and the other with GL_HALF_FLOAT_OES type.
783 // So, GL_HALF_FLOAT type formats conditions are merged with GL_HALF_FLOAT_OES type conditions.
784 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
785 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
786 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBTextureAttachmentSupport, SizedHalfFloatRGBRenderbufferSupport );
787 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBATextureAttachmentSupport, SizedHalfFloatRGBARenderbufferSupport );
788 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, SizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat>);
789 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, SizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat>);
790 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloatRGB>, NeverSupported );
791 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBATextureAttachmentSupport, RequireExt<&Extensions::colorBufferFloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000792
793 // Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400794 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
795 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<1, 0>, RequireES<1, 0> );
796 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
797 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
798 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32> );
799 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextures>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>);
800 AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, true, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> );
Corentin Walleze0902642014-11-04 12:32:15 -0800801 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000802
803 // Luminance alpha formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400804 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
805 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
806 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
807 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
808 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
809 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
810 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
811 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
812 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
813 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000814
815 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang836674c2018-11-19 11:45:18 -0500816 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
817 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
818 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
819 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
820 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
821 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
822 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
823 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughARGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
824 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, AlwaysSupported, NeverSupported, NeverSupported);
825 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGBA8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
826 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Alpha8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000827
828 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400829 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
830 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
831 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000832
833 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400834 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT3>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000835
836 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400837 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400838
839 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400840 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000841
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800842 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400843 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
844 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
845 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
846 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
847 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800848
Geoff Lang60ad73d2015-10-23 10:08:44 -0400849 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400850 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
851 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
852 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
853 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
854 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
855 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
856 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
857 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
858 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
859 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
860 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
861 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
862 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
863 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
864 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400865
Yuly Novikovf15f8862018-06-04 18:59:41 -0400866 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
867 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
868 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
869 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
870 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
871 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
872 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
873 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
874 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
875 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
876 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
877 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
878 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
879 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400880
Olli Etuahof2ed2992018-10-04 13:54:42 +0300881 // From EXT_texture_compression_bptc
882 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
883 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
884 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
885 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
886 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
887
Corentin Walleze0902642014-11-04 12:32:15 -0800888 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
889 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
890 // - All other stencil formats (all depth-stencil) are either float or normalized
891 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400892 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
893 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported, RequireES<1, 0>, RequireES<1, 0>);
Minmin Gonge3939b92015-12-01 15:36:51 -0800894
895 // From GL_ANGLE_lossy_etc_decode
Yuly Novikovf15f8862018-06-04 18:59:41 -0400896 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
897 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
898 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
899 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
900 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
901 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800902
Vincent Lang25ab4512016-05-13 18:13:59 +0200903 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400904 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
905 AddRGBAFormat(&map, GL_R16_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
906 AddRGBAFormat(&map, GL_R16_SNORM_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
907 AddRGBAFormat(&map, GL_RG16_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
908 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
909 AddRGBAFormat(&map, GL_RGB16_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
910 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
911 AddRGBAFormat(&map, GL_RGBA16_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
912 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
Vincent Lang25ab4512016-05-13 18:13:59 +0200913
Geoff Langca271392017-04-05 12:30:00 -0400914 // Unsized formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400915 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
916 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, RequireExt<&Extensions::textureRG>, NeverSupported);
917 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
918 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, RequireExt<&Extensions::textureRG>, NeverSupported);
919 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
920 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
921 AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
922 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
923 AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
924 AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
925 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
926 AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
927 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
928 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_SRGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, NeverSupported, NeverSupported);
929 AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, RequireExt<&Extensions::sRGB>, NeverSupported);
930 AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400931
932 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400933 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
934 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
935 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
936 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
937 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
938 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
939 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
940 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
941 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
942 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
943 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
944 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
945 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
946 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
947 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
948 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
949 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
950 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
951 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
952 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
953 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
954 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
955 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
956 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
957 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
958 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400959
960 // Unsized floating point formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400961 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
962 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
963 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
964 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
965 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
966 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
967 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
968 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
969 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::colorBufferHalfFloat>, NeverSupported);
970 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
971 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
972 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
973 AddRGBAFormat(&map, GL_RGB, false, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
974 AddRGBAFormat(&map, GL_RGB, false, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
975 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400976
977 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400978 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
Yuly Novikovd0828192018-06-15 15:51:07 -0400979 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
980 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
981 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
Yuly Novikovf15f8862018-06-04 18:59:41 -0400982 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
983 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
984 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
985 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
986 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
987 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400988
989 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400990 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
991 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
992 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
993 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
994 AddDepthStencilFormat(&map, GL_DEPTH_STENCIL, false, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>);
995 AddDepthStencilFormat(&map, GL_DEPTH_STENCIL, false, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>);
996 AddDepthStencilFormat(&map, GL_STENCIL, false, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported , RequireES<1, 0>, RequireES<1, 0> );
Geoff Lang9bbad182015-09-04 11:07:29 -0400997 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800998
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000999 return map;
1000}
1001
Geoff Lange4a492b2014-06-19 14:14:41 -04001002static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001003{
Geoff Lange4a492b2014-06-19 14:14:41 -04001004 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
1005 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001006}
1007
Geoff Lange4a492b2014-06-19 14:14:41 -04001008static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -04001009{
1010 FormatSet result;
1011
Geoff Langca271392017-04-05 12:30:00 -04001012 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -04001013 {
Geoff Langca271392017-04-05 12:30:00 -04001014 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -04001015 {
Geoff Langca271392017-04-05 12:30:00 -04001016 if (type.second.sized)
1017 {
1018 // TODO(jmadill): Fix this hack.
1019 if (internalFormat.first == GL_BGR565_ANGLEX)
1020 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -04001021
Geoff Langca271392017-04-05 12:30:00 -04001022 result.insert(internalFormat.first);
1023 }
Geoff Langcec35902014-04-16 10:52:36 -04001024 }
1025 }
1026
1027 return result;
1028}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001029
Markus Tavenrath0d665132018-11-18 15:47:02 +01001030uint32_t GetPackedTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001031{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001032 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001033 {
Frank Henigman95fb2a12018-05-27 20:17:05 -04001034 case GL_UNSIGNED_BYTE:
1035 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001036 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001037 static constexpr uint32_t kPacked = PackTypeInfo(1, false);
1038 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001039 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001040 case GL_UNSIGNED_SHORT:
1041 case GL_SHORT:
1042 case GL_HALF_FLOAT:
1043 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001044 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001045 static constexpr uint32_t kPacked = PackTypeInfo(2, false);
1046 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001047 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001048 case GL_UNSIGNED_INT:
1049 case GL_INT:
1050 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001051 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001052 static constexpr uint32_t kPacked = PackTypeInfo(4, false);
1053 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001054 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001055 case GL_UNSIGNED_SHORT_5_6_5:
1056 case GL_UNSIGNED_SHORT_4_4_4_4:
1057 case GL_UNSIGNED_SHORT_5_5_5_1:
1058 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1059 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001060 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001061 static constexpr uint32_t kPacked = PackTypeInfo(2, true);
1062 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001063 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001064 case GL_UNSIGNED_INT_2_10_10_10_REV:
1065 case GL_UNSIGNED_INT_24_8:
1066 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1067 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001068 {
1069 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
Markus Tavenrath0d665132018-11-18 15:47:02 +01001070 static constexpr uint32_t kPacked = PackTypeInfo(4, true);
1071 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001072 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001073 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001074 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001075 static constexpr uint32_t kPacked = PackTypeInfo(8, true);
1076 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001077 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001078 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001079 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001080 return 0;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001081 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001082 }
1083}
1084
Geoff Langca271392017-04-05 12:30:00 -04001085const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001086{
Geoff Langca271392017-04-05 12:30:00 -04001087 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001088 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001089 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001090
1091 // Sized internal formats only have one type per entry
1092 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001093 {
Geoff Lang5d601382014-07-22 15:14:06 -04001094 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001095 }
Geoff Langca271392017-04-05 12:30:00 -04001096
1097 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1098 if (!internalFormatInfo.sized)
1099 {
1100 return defaultInternalFormat;
1101 }
1102
1103 return internalFormatInfo;
1104}
1105
1106const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1107{
1108 static const InternalFormat defaultInternalFormat;
1109 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1110
1111 auto internalFormatIter = formatMap.find(internalFormat);
1112 if (internalFormatIter == formatMap.end())
1113 {
1114 return defaultInternalFormat;
1115 }
1116
1117 // If the internal format is sized, simply return it without the type check.
1118 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1119 {
1120 return internalFormatIter->second.begin()->second;
1121 }
1122
1123 auto typeIter = internalFormatIter->second.find(type);
1124 if (typeIter == internalFormatIter->second.end())
1125 {
1126 return defaultInternalFormat;
1127 }
1128
1129 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001130}
1131
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001132GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1133{
1134 const auto &typeInfo = GetTypeInfo(formatType);
1135 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1136 return components * typeInfo.bytes;
1137}
1138
Jamie Madillca2ff382018-07-11 09:01:17 -04001139bool InternalFormat::computeRowPitch(GLenum formatType,
1140 GLsizei width,
1141 GLint alignment,
1142 GLint rowLength,
1143 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001145 // Compressed images do not use pack/unpack parameters.
1146 if (compressed)
1147 {
1148 ASSERT(rowLength == 0);
Jamie Madillca2ff382018-07-11 09:01:17 -04001149 return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001150 }
1151
Geoff Lang3f234062016-07-13 15:35:45 -04001152 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001153 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001154
1155 ASSERT(alignment > 0 && isPow2(alignment));
1156 CheckedNumeric<GLuint> checkedAlignment(alignment);
1157 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
Jamie Madillca2ff382018-07-11 09:01:17 -04001158 return CheckedMathResult(aligned, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001159}
1160
Jamie Madillca2ff382018-07-11 09:01:17 -04001161bool InternalFormat::computeDepthPitch(GLsizei height,
1162 GLint imageHeight,
1163 GLuint rowPitch,
1164 GLuint *resultOut) const
Corentin Wallez0e487192016-10-03 16:30:38 -04001165{
1166 GLuint rows =
1167 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1168 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1169
Jamie Madillca2ff382018-07-11 09:01:17 -04001170 return CheckedMathResult(checkedRowPitch * rows, resultOut);
Corentin Wallez0e487192016-10-03 16:30:38 -04001171}
1172
Jamie Madillca2ff382018-07-11 09:01:17 -04001173bool InternalFormat::computeDepthPitch(GLenum formatType,
1174 GLsizei width,
1175 GLsizei height,
1176 GLint alignment,
1177 GLint rowLength,
1178 GLint imageHeight,
1179 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001180{
Jamie Madille2e406c2016-06-02 13:04:10 -04001181 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001182 if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1183 {
1184 return false;
1185 }
1186 return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001187}
1188
Jamie Madillca2ff382018-07-11 09:01:17 -04001189bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001190{
Jamie Madill513558d2016-06-02 13:04:11 -04001191 CheckedNumeric<GLuint> checkedWidth(size.width);
1192 CheckedNumeric<GLuint> checkedHeight(size.height);
1193 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001194 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1195 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001196
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001197 ASSERT(compressed);
1198 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1199 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1200 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
Jamie Madillca2ff382018-07-11 09:01:17 -04001201 return CheckedMathResult(bytes, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001202}
1203
Jamie Madillca2ff382018-07-11 09:01:17 -04001204bool InternalFormat::computeSkipBytes(GLenum formatType,
1205 GLuint rowPitch,
1206 GLuint depthPitch,
1207 const PixelStoreStateBase &state,
1208 bool is3D,
1209 GLuint *resultOut) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001210{
Olli Etuaho989cac32016-06-08 16:18:49 -07001211 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1212 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001213 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1214 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1215 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001216 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001217 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001218 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001219 {
1220 checkedSkipImagesBytes = 0;
1221 }
1222 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1223 checkedSkipPixels * checkedPixelBytes;
Jamie Madillca2ff382018-07-11 09:01:17 -04001224 return CheckedMathResult(skipBytes, resultOut);
Minmin Gongadff67b2015-10-14 10:34:45 -04001225}
1226
Jamie Madillca2ff382018-07-11 09:01:17 -04001227bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1228 const Extents &size,
1229 const PixelStoreStateBase &state,
1230 bool is3D,
1231 GLuint *resultOut) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001232{
Corentin Wallez886de362016-09-27 10:49:35 -04001233 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001234 if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
Corentin Wallez0e487192016-10-03 16:30:38 -04001235 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001236 return false;
Corentin Wallez0e487192016-10-03 16:30:38 -04001237 }
1238
Jamie Madillca2ff382018-07-11 09:01:17 -04001239 GLuint depthPitch = 0;
1240 if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1241 {
1242 return false;
1243 }
1244
1245 CheckedNumeric<GLuint> checkedCopyBytes(0);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001246 if (compressed)
1247 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001248 GLuint copyBytes = 0;
1249 if (!computeCompressedImageSize(size, &copyBytes))
1250 {
1251 return false;
1252 }
1253 checkedCopyBytes = copyBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001254 }
Corentin Wallez886de362016-09-27 10:49:35 -04001255 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001256 {
Corentin Wallez886de362016-09-27 10:49:35 -04001257 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1258 checkedCopyBytes += size.width * bytes;
1259
1260 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1261 checkedCopyBytes += heightMinusOne * rowPitch;
1262
1263 if (is3D)
1264 {
1265 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1266 checkedCopyBytes += depthMinusOne * depthPitch;
1267 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001268 }
1269
Jamie Madillca2ff382018-07-11 09:01:17 -04001270 GLuint skipBytes = 0;
1271 if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1272 {
1273 return false;
1274 }
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001275
Jamie Madillca2ff382018-07-11 09:01:17 -04001276 CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001277
Jamie Madillca2ff382018-07-11 09:01:17 -04001278 return CheckedMathResult(endByte, resultOut);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001279}
1280
Geoff Langca271392017-04-05 12:30:00 -04001281GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001282{
Geoff Langca271392017-04-05 12:30:00 -04001283 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1284 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001285 {
Geoff Langca271392017-04-05 12:30:00 -04001286 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001287 }
Geoff Langca271392017-04-05 12:30:00 -04001288
1289 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001290}
1291
Geoff Lange4a492b2014-06-19 14:14:41 -04001292const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001293{
Geoff Lange4a492b2014-06-19 14:14:41 -04001294 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001295 return formatSet;
1296}
1297
Jamie Madill09e2d932015-07-14 16:40:31 -04001298AttributeType GetAttributeType(GLenum enumValue)
1299{
1300 switch (enumValue)
1301 {
1302 case GL_FLOAT:
1303 return ATTRIBUTE_FLOAT;
1304 case GL_FLOAT_VEC2:
1305 return ATTRIBUTE_VEC2;
1306 case GL_FLOAT_VEC3:
1307 return ATTRIBUTE_VEC3;
1308 case GL_FLOAT_VEC4:
1309 return ATTRIBUTE_VEC4;
1310 case GL_INT:
1311 return ATTRIBUTE_INT;
1312 case GL_INT_VEC2:
1313 return ATTRIBUTE_IVEC2;
1314 case GL_INT_VEC3:
1315 return ATTRIBUTE_IVEC3;
1316 case GL_INT_VEC4:
1317 return ATTRIBUTE_IVEC4;
1318 case GL_UNSIGNED_INT:
1319 return ATTRIBUTE_UINT;
1320 case GL_UNSIGNED_INT_VEC2:
1321 return ATTRIBUTE_UVEC2;
1322 case GL_UNSIGNED_INT_VEC3:
1323 return ATTRIBUTE_UVEC3;
1324 case GL_UNSIGNED_INT_VEC4:
1325 return ATTRIBUTE_UVEC4;
1326 case GL_FLOAT_MAT2:
1327 return ATTRIBUTE_MAT2;
1328 case GL_FLOAT_MAT3:
1329 return ATTRIBUTE_MAT3;
1330 case GL_FLOAT_MAT4:
1331 return ATTRIBUTE_MAT4;
1332 case GL_FLOAT_MAT2x3:
1333 return ATTRIBUTE_MAT2x3;
1334 case GL_FLOAT_MAT2x4:
1335 return ATTRIBUTE_MAT2x4;
1336 case GL_FLOAT_MAT3x2:
1337 return ATTRIBUTE_MAT3x2;
1338 case GL_FLOAT_MAT3x4:
1339 return ATTRIBUTE_MAT3x4;
1340 case GL_FLOAT_MAT4x2:
1341 return ATTRIBUTE_MAT4x2;
1342 case GL_FLOAT_MAT4x3:
1343 return ATTRIBUTE_MAT4x3;
1344 default:
1345 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001346#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001347 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001348#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001349 }
1350}
1351
Jamie Madillba365932018-07-18 17:23:46 -04001352angle::FormatID GetVertexFormatID(GLenum type,
1353 GLboolean normalized,
1354 GLuint components,
1355 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001356{
1357 switch (type)
1358 {
1359 case GL_BYTE:
1360 switch (components)
1361 {
1362 case 1:
1363 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001364 return angle::FormatID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001365 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001366 return angle::FormatID::R8_SNORM;
1367 return angle::FormatID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001368 case 2:
1369 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001370 return angle::FormatID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001371 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001372 return angle::FormatID::R8G8_SNORM;
1373 return angle::FormatID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001374 case 3:
1375 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001376 return angle::FormatID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001377 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001378 return angle::FormatID::R8G8B8_SNORM;
1379 return angle::FormatID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001380 case 4:
1381 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001382 return angle::FormatID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001383 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001384 return angle::FormatID::R8G8B8A8_SNORM;
1385 return angle::FormatID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001386 default:
1387 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001388#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001389 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001390#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001391 }
1392 case GL_UNSIGNED_BYTE:
1393 switch (components)
1394 {
1395 case 1:
1396 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001397 return angle::FormatID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001398 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001399 return angle::FormatID::R8_UNORM;
1400 return angle::FormatID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001401 case 2:
1402 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001403 return angle::FormatID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001404 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001405 return angle::FormatID::R8G8_UNORM;
1406 return angle::FormatID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001407 case 3:
1408 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001409 return angle::FormatID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001410 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001411 return angle::FormatID::R8G8B8_UNORM;
1412 return angle::FormatID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001413 case 4:
1414 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001415 return angle::FormatID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001416 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001417 return angle::FormatID::R8G8B8A8_UNORM;
1418 return angle::FormatID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001419 default:
1420 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001421#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001422 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001423#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001424 }
1425 case GL_SHORT:
1426 switch (components)
1427 {
1428 case 1:
1429 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001430 return angle::FormatID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001431 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001432 return angle::FormatID::R16_SNORM;
1433 return angle::FormatID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001434 case 2:
1435 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001436 return angle::FormatID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001437 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001438 return angle::FormatID::R16G16_SNORM;
1439 return angle::FormatID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001440 case 3:
1441 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001442 return angle::FormatID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001443 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001444 return angle::FormatID::R16G16B16_SNORM;
1445 return angle::FormatID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001446 case 4:
1447 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001448 return angle::FormatID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001449 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001450 return angle::FormatID::R16G16B16A16_SNORM;
1451 return angle::FormatID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001452 default:
1453 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001454#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001455 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001456#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001457 }
1458 case GL_UNSIGNED_SHORT:
1459 switch (components)
1460 {
1461 case 1:
1462 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001463 return angle::FormatID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001464 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001465 return angle::FormatID::R16_UNORM;
1466 return angle::FormatID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001467 case 2:
1468 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001469 return angle::FormatID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001470 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001471 return angle::FormatID::R16G16_UNORM;
1472 return angle::FormatID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001473 case 3:
1474 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001475 return angle::FormatID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001476 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001477 return angle::FormatID::R16G16B16_UNORM;
1478 return angle::FormatID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001479 case 4:
1480 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001481 return angle::FormatID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001482 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001483 return angle::FormatID::R16G16B16A16_UNORM;
1484 return angle::FormatID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001485 default:
1486 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001487#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001488 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001489#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001490 }
1491 case GL_INT:
1492 switch (components)
1493 {
1494 case 1:
1495 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001496 return angle::FormatID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001497 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001498 return angle::FormatID::R32_SNORM;
1499 return angle::FormatID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001500 case 2:
1501 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001502 return angle::FormatID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001503 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001504 return angle::FormatID::R32G32_SNORM;
1505 return angle::FormatID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001506 case 3:
1507 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001508 return angle::FormatID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001509 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001510 return angle::FormatID::R32G32B32_SNORM;
1511 return angle::FormatID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001512 case 4:
1513 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001514 return angle::FormatID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001515 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001516 return angle::FormatID::R32G32B32A32_SNORM;
1517 return angle::FormatID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001518 default:
1519 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001520#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001521 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001522#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001523 }
1524 case GL_UNSIGNED_INT:
1525 switch (components)
1526 {
1527 case 1:
1528 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001529 return angle::FormatID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001530 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001531 return angle::FormatID::R32_UNORM;
1532 return angle::FormatID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001533 case 2:
1534 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001535 return angle::FormatID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001536 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001537 return angle::FormatID::R32G32_UNORM;
1538 return angle::FormatID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001539 case 3:
1540 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001541 return angle::FormatID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001542 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001543 return angle::FormatID::R32G32B32_UNORM;
1544 return angle::FormatID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001545 case 4:
1546 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001547 return angle::FormatID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001548 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001549 return angle::FormatID::R32G32B32A32_UNORM;
1550 return angle::FormatID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001551 default:
1552 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001553#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001554 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001555#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001556 }
1557 case GL_FLOAT:
1558 switch (components)
1559 {
1560 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001561 return angle::FormatID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001562 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001563 return angle::FormatID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001564 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001565 return angle::FormatID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001566 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001567 return angle::FormatID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001568 default:
1569 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001570#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001571 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001572#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001573 }
1574 case GL_HALF_FLOAT:
1575 switch (components)
1576 {
1577 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001578 return angle::FormatID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001579 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001580 return angle::FormatID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001581 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001582 return angle::FormatID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001583 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001584 return angle::FormatID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001585 default:
1586 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001587#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001588 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001589#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001590 }
1591 case GL_FIXED:
1592 switch (components)
1593 {
1594 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001595 return angle::FormatID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001596 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001597 return angle::FormatID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001598 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001599 return angle::FormatID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001600 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001601 return angle::FormatID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001602 default:
1603 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001604#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001605 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001606#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001607 }
1608 case GL_INT_2_10_10_10_REV:
1609 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001610 return angle::FormatID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001611 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001612 return angle::FormatID::R10G10B10A2_SNORM;
1613 return angle::FormatID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001614 case GL_UNSIGNED_INT_2_10_10_10_REV:
1615 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001616 return angle::FormatID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001617 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001618 return angle::FormatID::R10G10B10A2_UNORM;
1619 return angle::FormatID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001620 default:
1621 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001622#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001623 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001624#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001625 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001626}
1627
Jamie Madillba365932018-07-18 17:23:46 -04001628angle::FormatID GetVertexFormatID(const VertexAttribute &attrib)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001629{
1630 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1631}
1632
Frank Henigmand633b152018-10-04 23:34:31 -04001633angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, GLenum currentValueType)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001634{
1635 if (!attrib.enabled)
1636 {
Frank Henigmand633b152018-10-04 23:34:31 -04001637 return GetVertexFormatID(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
Jamie Madilld3dfda22015-07-06 08:28:49 -04001638 }
Frank Henigmand633b152018-10-04 23:34:31 -04001639 return GetVertexFormatID(attrib);
Jamie Madilld3dfda22015-07-06 08:28:49 -04001640}
1641
Frank Henigmand633b152018-10-04 23:34:31 -04001642const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001643{
Frank Henigmand633b152018-10-04 23:34:31 -04001644 switch (vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001645 {
Frank Henigmand633b152018-10-04 23:34:31 -04001646 case angle::FormatID::R8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001647 {
1648 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1649 return format;
1650 }
Frank Henigmand633b152018-10-04 23:34:31 -04001651 case angle::FormatID::R8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001652 {
1653 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1654 return format;
1655 }
Frank Henigmand633b152018-10-04 23:34:31 -04001656 case angle::FormatID::R8G8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001657 {
1658 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1659 return format;
1660 }
Frank Henigmand633b152018-10-04 23:34:31 -04001661 case angle::FormatID::R8G8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001662 {
1663 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1664 return format;
1665 }
Frank Henigmand633b152018-10-04 23:34:31 -04001666 case angle::FormatID::R8G8B8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001667 {
1668 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1669 return format;
1670 }
Frank Henigmand633b152018-10-04 23:34:31 -04001671 case angle::FormatID::R8G8B8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001672 {
1673 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1674 return format;
1675 }
Frank Henigmand633b152018-10-04 23:34:31 -04001676 case angle::FormatID::R8G8B8A8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001677 {
1678 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1679 return format;
1680 }
Frank Henigmand633b152018-10-04 23:34:31 -04001681 case angle::FormatID::R8G8B8A8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001682 {
1683 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1684 return format;
1685 }
Frank Henigmand633b152018-10-04 23:34:31 -04001686 case angle::FormatID::R8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001687 {
1688 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1689 return format;
1690 }
Frank Henigmand633b152018-10-04 23:34:31 -04001691 case angle::FormatID::R8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001692 {
1693 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1694 return format;
1695 }
Frank Henigmand633b152018-10-04 23:34:31 -04001696 case angle::FormatID::R8G8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001697 {
1698 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1699 return format;
1700 }
Frank Henigmand633b152018-10-04 23:34:31 -04001701 case angle::FormatID::R8G8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001702 {
1703 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1704 return format;
1705 }
Frank Henigmand633b152018-10-04 23:34:31 -04001706 case angle::FormatID::R8G8B8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001707 {
1708 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1709 return format;
1710 }
Frank Henigmand633b152018-10-04 23:34:31 -04001711 case angle::FormatID::R8G8B8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001712 {
1713 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1714 return format;
1715 }
Frank Henigmand633b152018-10-04 23:34:31 -04001716 case angle::FormatID::R8G8B8A8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001717 {
1718 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1719 return format;
1720 }
Frank Henigmand633b152018-10-04 23:34:31 -04001721 case angle::FormatID::R8G8B8A8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001722 {
1723 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1724 return format;
1725 }
Frank Henigmand633b152018-10-04 23:34:31 -04001726 case angle::FormatID::R16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001727 {
1728 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1729 return format;
1730 }
Frank Henigmand633b152018-10-04 23:34:31 -04001731 case angle::FormatID::R16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001732 {
1733 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1734 return format;
1735 }
Frank Henigmand633b152018-10-04 23:34:31 -04001736 case angle::FormatID::R16G16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001737 {
1738 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1739 return format;
1740 }
Frank Henigmand633b152018-10-04 23:34:31 -04001741 case angle::FormatID::R16G16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001742 {
1743 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1744 return format;
1745 }
Frank Henigmand633b152018-10-04 23:34:31 -04001746 case angle::FormatID::R16G16B16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001747 {
1748 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1749 return format;
1750 }
Frank Henigmand633b152018-10-04 23:34:31 -04001751 case angle::FormatID::R16G16B16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001752 {
1753 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1754 return format;
1755 }
Frank Henigmand633b152018-10-04 23:34:31 -04001756 case angle::FormatID::R16G16B16A16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001757 {
1758 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1759 return format;
1760 }
Frank Henigmand633b152018-10-04 23:34:31 -04001761 case angle::FormatID::R16G16B16A16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001762 {
1763 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1764 return format;
1765 }
Frank Henigmand633b152018-10-04 23:34:31 -04001766 case angle::FormatID::R16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001767 {
1768 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1769 return format;
1770 }
Frank Henigmand633b152018-10-04 23:34:31 -04001771 case angle::FormatID::R16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001772 {
1773 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1774 return format;
1775 }
Frank Henigmand633b152018-10-04 23:34:31 -04001776 case angle::FormatID::R16G16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001777 {
1778 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1779 return format;
1780 }
Frank Henigmand633b152018-10-04 23:34:31 -04001781 case angle::FormatID::R16G16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001782 {
1783 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1784 return format;
1785 }
Frank Henigmand633b152018-10-04 23:34:31 -04001786 case angle::FormatID::R16G16B16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001787 {
1788 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1789 return format;
1790 }
Frank Henigmand633b152018-10-04 23:34:31 -04001791 case angle::FormatID::R16G16B16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001792 {
1793 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1794 return format;
1795 }
Frank Henigmand633b152018-10-04 23:34:31 -04001796 case angle::FormatID::R16G16B16A16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001797 {
1798 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1799 return format;
1800 }
Frank Henigmand633b152018-10-04 23:34:31 -04001801 case angle::FormatID::R16G16B16A16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001802 {
1803 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1804 return format;
1805 }
Frank Henigmand633b152018-10-04 23:34:31 -04001806 case angle::FormatID::R32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001807 {
1808 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1809 return format;
1810 }
Frank Henigmand633b152018-10-04 23:34:31 -04001811 case angle::FormatID::R32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001812 {
1813 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1814 return format;
1815 }
Frank Henigmand633b152018-10-04 23:34:31 -04001816 case angle::FormatID::R32G32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001817 {
1818 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1819 return format;
1820 }
Frank Henigmand633b152018-10-04 23:34:31 -04001821 case angle::FormatID::R32G32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001822 {
1823 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1824 return format;
1825 }
Frank Henigmand633b152018-10-04 23:34:31 -04001826 case angle::FormatID::R32G32B32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001827 {
1828 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1829 return format;
1830 }
Frank Henigmand633b152018-10-04 23:34:31 -04001831 case angle::FormatID::R32G32B32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001832 {
1833 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1834 return format;
1835 }
Frank Henigmand633b152018-10-04 23:34:31 -04001836 case angle::FormatID::R32G32B32A32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001837 {
1838 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1839 return format;
1840 }
Frank Henigmand633b152018-10-04 23:34:31 -04001841 case angle::FormatID::R32G32B32A32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001842 {
1843 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1844 return format;
1845 }
Frank Henigmand633b152018-10-04 23:34:31 -04001846 case angle::FormatID::R32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001847 {
1848 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1849 return format;
1850 }
Frank Henigmand633b152018-10-04 23:34:31 -04001851 case angle::FormatID::R32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001852 {
1853 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1854 return format;
1855 }
Frank Henigmand633b152018-10-04 23:34:31 -04001856 case angle::FormatID::R32G32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001857 {
1858 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1859 return format;
1860 }
Frank Henigmand633b152018-10-04 23:34:31 -04001861 case angle::FormatID::R32G32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001862 {
1863 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1864 return format;
1865 }
Frank Henigmand633b152018-10-04 23:34:31 -04001866 case angle::FormatID::R32G32B32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001867 {
1868 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1869 return format;
1870 }
Frank Henigmand633b152018-10-04 23:34:31 -04001871 case angle::FormatID::R32G32B32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001872 {
1873 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1874 return format;
1875 }
Frank Henigmand633b152018-10-04 23:34:31 -04001876 case angle::FormatID::R32G32B32A32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001877 {
1878 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1879 return format;
1880 }
Frank Henigmand633b152018-10-04 23:34:31 -04001881 case angle::FormatID::R32G32B32A32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001882 {
1883 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1884 return format;
1885 }
Frank Henigmand633b152018-10-04 23:34:31 -04001886 case angle::FormatID::R8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001887 {
1888 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1889 return format;
1890 }
Frank Henigmand633b152018-10-04 23:34:31 -04001891 case angle::FormatID::R8G8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001892 {
1893 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1894 return format;
1895 }
Frank Henigmand633b152018-10-04 23:34:31 -04001896 case angle::FormatID::R8G8B8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001897 {
1898 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1899 return format;
1900 }
Frank Henigmand633b152018-10-04 23:34:31 -04001901 case angle::FormatID::R8G8B8A8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001902 {
1903 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1904 return format;
1905 }
Frank Henigmand633b152018-10-04 23:34:31 -04001906 case angle::FormatID::R8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001907 {
1908 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1909 return format;
1910 }
Frank Henigmand633b152018-10-04 23:34:31 -04001911 case angle::FormatID::R8G8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001912 {
1913 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1914 return format;
1915 }
Frank Henigmand633b152018-10-04 23:34:31 -04001916 case angle::FormatID::R8G8B8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001917 {
1918 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1919 return format;
1920 }
Frank Henigmand633b152018-10-04 23:34:31 -04001921 case angle::FormatID::R8G8B8A8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001922 {
1923 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1924 return format;
1925 }
Frank Henigmand633b152018-10-04 23:34:31 -04001926 case angle::FormatID::R16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001927 {
1928 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1929 return format;
1930 }
Frank Henigmand633b152018-10-04 23:34:31 -04001931 case angle::FormatID::R16G16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001932 {
1933 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1934 return format;
1935 }
Frank Henigmand633b152018-10-04 23:34:31 -04001936 case angle::FormatID::R16G16B16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001937 {
1938 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1939 return format;
1940 }
Frank Henigmand633b152018-10-04 23:34:31 -04001941 case angle::FormatID::R16G16B16A16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001942 {
1943 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1944 return format;
1945 }
Frank Henigmand633b152018-10-04 23:34:31 -04001946 case angle::FormatID::R16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001947 {
1948 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1949 return format;
1950 }
Frank Henigmand633b152018-10-04 23:34:31 -04001951 case angle::FormatID::R16G16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001952 {
1953 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1954 return format;
1955 }
Frank Henigmand633b152018-10-04 23:34:31 -04001956 case angle::FormatID::R16G16B16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001957 {
1958 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1959 return format;
1960 }
Frank Henigmand633b152018-10-04 23:34:31 -04001961 case angle::FormatID::R16G16B16A16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001962 {
1963 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1964 return format;
1965 }
Frank Henigmand633b152018-10-04 23:34:31 -04001966 case angle::FormatID::R32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001967 {
1968 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1969 return format;
1970 }
Frank Henigmand633b152018-10-04 23:34:31 -04001971 case angle::FormatID::R32G32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001972 {
1973 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1974 return format;
1975 }
Frank Henigmand633b152018-10-04 23:34:31 -04001976 case angle::FormatID::R32G32B32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001977 {
1978 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1979 return format;
1980 }
Frank Henigmand633b152018-10-04 23:34:31 -04001981 case angle::FormatID::R32G32B32A32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001982 {
1983 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1984 return format;
1985 }
Frank Henigmand633b152018-10-04 23:34:31 -04001986 case angle::FormatID::R32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001987 {
1988 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1989 return format;
1990 }
Frank Henigmand633b152018-10-04 23:34:31 -04001991 case angle::FormatID::R32G32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001992 {
1993 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1994 return format;
1995 }
Frank Henigmand633b152018-10-04 23:34:31 -04001996 case angle::FormatID::R32G32B32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001997 {
1998 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1999 return format;
2000 }
Frank Henigmand633b152018-10-04 23:34:31 -04002001 case angle::FormatID::R32G32B32A32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002002 {
2003 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2004 return format;
2005 }
Frank Henigmand633b152018-10-04 23:34:31 -04002006 case angle::FormatID::R32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002007 {
2008 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2009 return format;
2010 }
Frank Henigmand633b152018-10-04 23:34:31 -04002011 case angle::FormatID::R32G32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002012 {
2013 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2014 return format;
2015 }
Frank Henigmand633b152018-10-04 23:34:31 -04002016 case angle::FormatID::R32G32B32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002017 {
2018 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2019 return format;
2020 }
Frank Henigmand633b152018-10-04 23:34:31 -04002021 case angle::FormatID::R32G32B32A32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002022 {
2023 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2024 return format;
2025 }
Frank Henigmand633b152018-10-04 23:34:31 -04002026 case angle::FormatID::R16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002027 {
2028 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2029 return format;
2030 }
Frank Henigmand633b152018-10-04 23:34:31 -04002031 case angle::FormatID::R16G16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002032 {
2033 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2034 return format;
2035 }
Frank Henigmand633b152018-10-04 23:34:31 -04002036 case angle::FormatID::R16G16B16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002037 {
2038 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2039 return format;
2040 }
Frank Henigmand633b152018-10-04 23:34:31 -04002041 case angle::FormatID::R16G16B16A16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002042 {
2043 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2044 return format;
2045 }
Frank Henigmand633b152018-10-04 23:34:31 -04002046 case angle::FormatID::R32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002047 {
2048 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2049 return format;
2050 }
Frank Henigmand633b152018-10-04 23:34:31 -04002051 case angle::FormatID::R32G32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002052 {
2053 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2054 return format;
2055 }
Frank Henigmand633b152018-10-04 23:34:31 -04002056 case angle::FormatID::R32G32B32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002057 {
2058 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2059 return format;
2060 }
Frank Henigmand633b152018-10-04 23:34:31 -04002061 case angle::FormatID::R32G32B32A32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002062 {
2063 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2064 return format;
2065 }
Frank Henigmand633b152018-10-04 23:34:31 -04002066 case angle::FormatID::R10G10B10A2_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002067 {
2068 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2069 return format;
2070 }
Frank Henigmand633b152018-10-04 23:34:31 -04002071 case angle::FormatID::R10G10B10A2_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002072 {
2073 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2074 return format;
2075 }
Frank Henigmand633b152018-10-04 23:34:31 -04002076 case angle::FormatID::R10G10B10A2_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002077 {
2078 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2079 return format;
2080 }
Frank Henigmand633b152018-10-04 23:34:31 -04002081 case angle::FormatID::R10G10B10A2_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002082 {
2083 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2084 return format;
2085 }
Frank Henigmand633b152018-10-04 23:34:31 -04002086 case angle::FormatID::R10G10B10A2_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002087 {
2088 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2089 return format;
2090 }
Frank Henigmand633b152018-10-04 23:34:31 -04002091 case angle::FormatID::R10G10B10A2_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002092 {
2093 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2094 return format;
2095 }
2096 default:
2097 {
2098 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2099 return format;
2100 }
2101 }
2102}
2103
Frank Henigmand633b152018-10-04 23:34:31 -04002104size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002105{
Frank Henigmand633b152018-10-04 23:34:31 -04002106 switch (vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002107 {
Frank Henigmand633b152018-10-04 23:34:31 -04002108 case angle::FormatID::R8_SSCALED:
2109 case angle::FormatID::R8_SNORM:
2110 case angle::FormatID::R8_USCALED:
2111 case angle::FormatID::R8_UNORM:
2112 case angle::FormatID::R8_SINT:
2113 case angle::FormatID::R8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002114 return 1;
2115
Frank Henigmand633b152018-10-04 23:34:31 -04002116 case angle::FormatID::R8G8_SSCALED:
2117 case angle::FormatID::R8G8_SNORM:
2118 case angle::FormatID::R8G8_USCALED:
2119 case angle::FormatID::R8G8_UNORM:
2120 case angle::FormatID::R8G8_SINT:
2121 case angle::FormatID::R8G8_UINT:
2122 case angle::FormatID::R16_SSCALED:
2123 case angle::FormatID::R16_SNORM:
2124 case angle::FormatID::R16_USCALED:
2125 case angle::FormatID::R16_UNORM:
2126 case angle::FormatID::R16_SINT:
2127 case angle::FormatID::R16_UINT:
2128 case angle::FormatID::R16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002129 return 2;
2130
Frank Henigmand633b152018-10-04 23:34:31 -04002131 case angle::FormatID::R8G8B8_SSCALED:
2132 case angle::FormatID::R8G8B8_SNORM:
2133 case angle::FormatID::R8G8B8_USCALED:
2134 case angle::FormatID::R8G8B8_UNORM:
2135 case angle::FormatID::R8G8B8_SINT:
2136 case angle::FormatID::R8G8B8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002137 return 3;
2138
Frank Henigmand633b152018-10-04 23:34:31 -04002139 case angle::FormatID::R8G8B8A8_SSCALED:
2140 case angle::FormatID::R8G8B8A8_SNORM:
2141 case angle::FormatID::R8G8B8A8_USCALED:
2142 case angle::FormatID::R8G8B8A8_UNORM:
2143 case angle::FormatID::R8G8B8A8_SINT:
2144 case angle::FormatID::R8G8B8A8_UINT:
2145 case angle::FormatID::R16G16_SSCALED:
2146 case angle::FormatID::R16G16_SNORM:
2147 case angle::FormatID::R16G16_USCALED:
2148 case angle::FormatID::R16G16_UNORM:
2149 case angle::FormatID::R16G16_SINT:
2150 case angle::FormatID::R16G16_UINT:
2151 case angle::FormatID::R32_SSCALED:
2152 case angle::FormatID::R32_SNORM:
2153 case angle::FormatID::R32_USCALED:
2154 case angle::FormatID::R32_UNORM:
2155 case angle::FormatID::R32_SINT:
2156 case angle::FormatID::R32_UINT:
2157 case angle::FormatID::R16G16_FLOAT:
2158 case angle::FormatID::R32_FIXED:
2159 case angle::FormatID::R32_FLOAT:
2160 case angle::FormatID::R10G10B10A2_SSCALED:
2161 case angle::FormatID::R10G10B10A2_USCALED:
2162 case angle::FormatID::R10G10B10A2_SNORM:
2163 case angle::FormatID::R10G10B10A2_UNORM:
2164 case angle::FormatID::R10G10B10A2_SINT:
2165 case angle::FormatID::R10G10B10A2_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002166 return 4;
2167
Frank Henigmand633b152018-10-04 23:34:31 -04002168 case angle::FormatID::R16G16B16_SSCALED:
2169 case angle::FormatID::R16G16B16_SNORM:
2170 case angle::FormatID::R16G16B16_USCALED:
2171 case angle::FormatID::R16G16B16_UNORM:
2172 case angle::FormatID::R16G16B16_SINT:
2173 case angle::FormatID::R16G16B16_UINT:
2174 case angle::FormatID::R16G16B16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002175 return 6;
2176
Frank Henigmand633b152018-10-04 23:34:31 -04002177 case angle::FormatID::R16G16B16A16_SSCALED:
2178 case angle::FormatID::R16G16B16A16_SNORM:
2179 case angle::FormatID::R16G16B16A16_USCALED:
2180 case angle::FormatID::R16G16B16A16_UNORM:
2181 case angle::FormatID::R16G16B16A16_SINT:
2182 case angle::FormatID::R16G16B16A16_UINT:
2183 case angle::FormatID::R32G32_SSCALED:
2184 case angle::FormatID::R32G32_SNORM:
2185 case angle::FormatID::R32G32_USCALED:
2186 case angle::FormatID::R32G32_UNORM:
2187 case angle::FormatID::R32G32_SINT:
2188 case angle::FormatID::R32G32_UINT:
2189 case angle::FormatID::R16G16B16A16_FLOAT:
2190 case angle::FormatID::R32G32_FIXED:
2191 case angle::FormatID::R32G32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002192 return 8;
2193
Frank Henigmand633b152018-10-04 23:34:31 -04002194 case angle::FormatID::R32G32B32_SSCALED:
2195 case angle::FormatID::R32G32B32_SNORM:
2196 case angle::FormatID::R32G32B32_USCALED:
2197 case angle::FormatID::R32G32B32_UNORM:
2198 case angle::FormatID::R32G32B32_SINT:
2199 case angle::FormatID::R32G32B32_UINT:
2200 case angle::FormatID::R32G32B32_FIXED:
2201 case angle::FormatID::R32G32B32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002202 return 12;
2203
Frank Henigmand633b152018-10-04 23:34:31 -04002204 case angle::FormatID::R32G32B32A32_SSCALED:
2205 case angle::FormatID::R32G32B32A32_SNORM:
2206 case angle::FormatID::R32G32B32A32_USCALED:
2207 case angle::FormatID::R32G32B32A32_UNORM:
2208 case angle::FormatID::R32G32B32A32_SINT:
2209 case angle::FormatID::R32G32B32A32_UINT:
2210 case angle::FormatID::R32G32B32A32_FIXED:
2211 case angle::FormatID::R32G32B32A32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002212 return 16;
2213
Frank Henigmand633b152018-10-04 23:34:31 -04002214 case angle::FormatID::NONE:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002215 default:
2216 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002217#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002218 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002219#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002220 }
2221}
2222
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002223bool ValidES3InternalFormat(GLenum internalFormat)
2224{
2225 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2226 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2227}
2228
Frank Henigman95fb2a12018-05-27 20:17:05 -04002229VertexFormat::VertexFormat(GLenum typeIn,
2230 GLboolean normalizedIn,
2231 GLuint componentsIn,
2232 bool pureIntegerIn)
2233 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002234{
2235 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002236 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2237 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002238}
Markus Tavenrath0d665132018-11-18 15:47:02 +01002239} // namespace gl