blob: 9ab99d9dcf64b451c81da98b6bf02803409e003b [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
Markus Tavenrath0d665132018-11-18 15:47:02 +010043constexpr uint32_t PackTypeInfo(GLuint bytes, bool specialized)
44{
45 // static_assert within constexpr requires c++17
46 // static_assert(isPow2(bytes));
Jamie Madill3f0c4a52019-01-10 10:20:35 -050047 return bytes | (rx::Log2(bytes) << 8) | (specialized << 16);
Markus Tavenrath0d665132018-11-18 15:47:02 +010048}
49
Jamie Madilla3944d42016-07-22 22:13:26 -040050} // anonymous namespace
51
Markus Tavenrath0d665132018-11-18 15:47:02 +010052FormatType::FormatType() : format(GL_NONE), type(GL_NONE) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040053
Markus Tavenrath0d665132018-11-18 15:47:02 +010054FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040055
56bool FormatType::operator<(const FormatType &other) const
57{
58 if (format != other.format)
59 return format < other.format;
60 return type < other.type;
61}
62
Frank Henigman95fb2a12018-05-27 20:17:05 -040063bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040064{
65 return memcmp(&a, &b, sizeof(Type)) < 0;
66}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000067
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040069static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000070{
Geoff Lang493daf52014-07-03 13:38:44 -040071 return true;
72}
73
Geoff Langeb66a6e2016-10-31 13:06:12 -040074static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076 return false;
77}
78
Geoff Langeb66a6e2016-10-31 13:06:12 -040079template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
80static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040081{
Geoff Langeb66a6e2016-10-31 13:06:12 -040082 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040083}
84
Geoff Langcec35902014-04-16 10:52:36 -040085// Pointer to a boolean memeber of the Extensions struct
86typedef bool(Extensions::*ExtensionBool);
87
88// Check support for a single extension
89template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040090static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040091{
Geoff Lange4a492b2014-06-19 14:14:41 -040092 return extensions.*bool1;
93}
94
95// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -040096template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
97static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -040098{
Geoff Langeb66a6e2016-10-31 13:06:12 -040099 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
100 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400101}
102
103// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400104template <GLuint minCoreGLMajorVersion,
105 GLuint minCoreGLMinorVersion,
106 ExtensionBool bool1,
107 ExtensionBool bool2>
108static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400109{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400110 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
111 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400112}
113
114// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400115template <GLuint minCoreGLMajorVersion,
116 GLuint minCoreGLMinorVersion,
117 ExtensionBool bool1,
118 ExtensionBool bool2>
119static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400120{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400121 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
122 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400123}
124
125// Check support for two extensions
126template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400127static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400128{
Geoff Langabce7622014-09-19 16:13:00 -0400129 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400130}
131
Geoff Lang60ad73d2015-10-23 10:08:44 -0400132// Check support for either of two extensions
133template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400134static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400135{
136 return extensions.*bool1 || extensions.*bool2;
137}
138
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600139// Check support for any of three extensions
140template <ExtensionBool bool1, ExtensionBool bool2, ExtensionBool bool3>
141static bool RequireExtOrExtOrExt(const Version &, const Extensions &extensions)
142{
143 return extensions.*bool1 || extensions.*bool2 || extensions.*bool3;
144}
145
Yuly Novikovd0828192018-06-15 15:51:07 -0400146// R8, RG8
147static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500148{
Yuly Novikovd0828192018-06-15 15:51:07 -0400149 return clientVersion >= Version(3, 0) || (extensions.textureStorage && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500150}
151
Yuly Novikovd0828192018-06-15 15:51:07 -0400152// R16F, RG16F with HALF_FLOAT_OES type
153static bool SizedHalfFloatOESRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500154{
Yuly Novikovd0828192018-06-15 15:51:07 -0400155 return extensions.textureStorage && extensions.textureHalfFloat && extensions.textureRG;
Jamie Madillcd089732015-12-17 09:53:09 -0500156}
157
Yuly Novikovd0828192018-06-15 15:51:07 -0400158static bool SizedHalfFloatOESRGTextureAttachmentSupport(const Version &clientVersion,
159 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400160{
Yuly Novikovd0828192018-06-15 15:51:07 -0400161 return SizedHalfFloatOESRGSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400162}
163
Yuly Novikovd0828192018-06-15 15:51:07 -0400164// R16F, RG16F with either HALF_FLOAT_OES or HALF_FLOAT types
165static bool SizedHalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500166{
Yuly Novikovd0828192018-06-15 15:51:07 -0400167 // HALF_FLOAT
168 if (clientVersion >= Version(3, 0))
169 {
170 return true;
171 }
172 // HALF_FLOAT_OES
173 else
174 {
175 return SizedHalfFloatOESRGSupport(clientVersion, extensions);
176 }
Jamie Madillcd089732015-12-17 09:53:09 -0500177}
178
Yuly Novikovd0828192018-06-15 15:51:07 -0400179static bool SizedHalfFloatRGTextureAttachmentSupport(const Version &clientVersion,
180 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500181{
Yuly Novikovd0828192018-06-15 15:51:07 -0400182 // HALF_FLOAT
183 if (clientVersion >= Version(3, 0))
184 {
185 return extensions.colorBufferFloat;
186 }
187 // HALF_FLOAT_OES
188 else
189 {
190 return SizedHalfFloatOESRGTextureAttachmentSupport(clientVersion, extensions);
191 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400192}
193
Yuly Novikovd0828192018-06-15 15:51:07 -0400194static bool SizedHalfFloatRGRenderbufferSupport(const Version &clientVersion,
195 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400196{
Yuly Novikovd0828192018-06-15 15:51:07 -0400197 return (clientVersion >= Version(3, 0) ||
198 (extensions.textureHalfFloat && extensions.textureRG)) &&
199 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400200}
201
Yuly Novikovd0828192018-06-15 15:51:07 -0400202// RGB16F, RGBA16F with HALF_FLOAT_OES type
203static bool SizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400204{
Yuly Novikovd0828192018-06-15 15:51:07 -0400205 return extensions.textureStorage && extensions.textureHalfFloat;
206}
207
208static bool SizedHalfFloatOESTextureAttachmentSupport(const Version &clientVersion,
209 const Extensions &extensions)
210{
211 return SizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
212}
213
214// RGB16F, RGBA16F with either HALF_FLOAT_OES or HALF_FLOAT types
215static bool SizedHalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
216{
217 // HALF_FLOAT
218 if (clientVersion >= Version(3, 0))
219 {
220 return true;
221 }
222 // HALF_FLOAT_OES
223 else
224 {
225 return SizedHalfFloatOESSupport(clientVersion, extensions);
226 }
227}
228
229static bool SizedHalfFloatFilterSupport(const Version &clientVersion, const Extensions &extensions)
230{
231 // HALF_FLOAT
232 if (clientVersion >= Version(3, 0))
233 {
234 return true;
235 }
236 // HALF_FLOAT_OES
237 else
238 {
239 return extensions.textureHalfFloatLinear;
240 }
241}
242
243static bool SizedHalfFloatRGBTextureAttachmentSupport(const Version &clientVersion,
244 const Extensions &extensions)
245{
246 // HALF_FLOAT
247 if (clientVersion >= Version(3, 0))
248 {
249 // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
250 // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
251 // is possible, so assume that all GLES implementations support it.
252 return extensions.colorBufferHalfFloat;
253 }
254 // HALF_FLOAT_OES
255 else
256 {
257 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
258 }
259}
260
261static bool SizedHalfFloatRGBRenderbufferSupport(const Version &clientVersion,
262 const Extensions &extensions)
263{
264 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400265 extensions.colorBufferHalfFloat;
266}
267
Yuly Novikovd0828192018-06-15 15:51:07 -0400268static bool SizedHalfFloatRGBATextureAttachmentSupport(const Version &clientVersion,
269 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400270{
Yuly Novikovd0828192018-06-15 15:51:07 -0400271 // HALF_FLOAT
272 if (clientVersion >= Version(3, 0))
273 {
274 return extensions.colorBufferFloat;
275 }
276 // HALF_FLOAT_OES
277 else
278 {
279 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
280 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400281}
282
Yuly Novikovd0828192018-06-15 15:51:07 -0400283static bool SizedHalfFloatRGBARenderbufferSupport(const Version &clientVersion,
284 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400285{
Yuly Novikovd0828192018-06-15 15:51:07 -0400286 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
287 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500288}
289
Yuly Novikovd0828192018-06-15 15:51:07 -0400290// R32F, RG32F
291static bool SizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500292{
Yuly Novikovd0828192018-06-15 15:51:07 -0400293 return clientVersion >= Version(3, 0) ||
294 (extensions.textureStorage && extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500295}
296
Geoff Lang677bb6f2017-04-05 12:40:40 -0400297// RGB32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400298static bool SizedFloatRGBSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500299{
Yuly Novikovd0828192018-06-15 15:51:07 -0400300 return clientVersion >= Version(3, 0) ||
301 (extensions.textureStorage && extensions.textureFloat) || extensions.colorBufferFloatRGB;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400302}
303
304// RGBA32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400305static bool SizedFloatRGBASupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400306{
Yuly Novikovd0828192018-06-15 15:51:07 -0400307 return clientVersion >= Version(3, 0) ||
308 (extensions.textureStorage && extensions.textureFloat) ||
309 extensions.colorBufferFloatRGBA;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400310}
311
Jeff Gilbert6446c882019-03-28 17:49:38 -0700312static bool SizedFloatRGBARenderableSupport(const Version &clientVersion,
313 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400314{
Jeff Gilbert6446c882019-03-28 17:49:38 -0700315 // This logic is the same for both Renderbuffers and TextureAttachment.
316 return extensions.colorBufferFloatRGBA || // ES2
317 extensions.colorBufferFloat; // ES3
Jamie Madillcd089732015-12-17 09:53:09 -0500318}
319
Geoff Lang5d601382014-07-22 15:14:06 -0400320InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400321 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400322 sized(false),
323 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400324 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400325 greenBits(0),
326 blueBits(0),
327 luminanceBits(0),
328 alphaBits(0),
329 sharedBits(0),
330 depthBits(0),
331 stencilBits(0),
332 pixelBytes(0),
333 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400334 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400335 compressedBlockWidth(0),
336 compressedBlockHeight(0),
337 format(GL_NONE),
338 type(GL_NONE),
339 componentType(GL_NONE),
340 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400341 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400342 filterSupport(NeverSupported),
343 textureAttachmentSupport(NeverSupported),
344 renderbufferSupport(NeverSupported)
Jamie Madillb980c562018-11-27 11:34:27 -0500345{}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000346
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500347InternalFormat::InternalFormat(const InternalFormat &other) = default;
348
Jamie Madilla3944d42016-07-22 22:13:26 -0400349bool InternalFormat::isLUMA() const
350{
351 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
352 (luminanceBits + alphaBits) > 0);
353}
354
Geoff Langf607c602016-09-21 11:46:48 -0400355GLenum InternalFormat::getReadPixelsFormat() const
356{
357 return format;
358}
359
Geoff Langc71ea662017-09-26 17:06:02 -0400360GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400361{
362 switch (type)
363 {
364 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400365 case GL_HALF_FLOAT_OES:
366 if (version < Version(3, 0))
367 {
368 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
369 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
370 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
371 // as an IMPLEMENTATION_READ_TYPE.
372 return GL_HALF_FLOAT_OES;
373 }
374 else
375 {
376 return GL_HALF_FLOAT;
377 }
Geoff Langf607c602016-09-21 11:46:48 -0400378
379 default:
380 return type;
381 }
382}
383
Olli Etuaho50c562d2017-06-06 14:43:30 +0300384bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
385{
386 // GLES 3.0.5 section 4.4.2.2:
387 // "Implementations are required to support the same internal formats for renderbuffers as the
388 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
389 // formats labelled "texture-only"."
390 if (!sized || compressed)
391 {
392 return false;
393 }
394
395 // Luma formats.
396 if (isLUMA())
397 {
398 return false;
399 }
400
401 // Depth/stencil formats.
402 if (depthBits > 0 || stencilBits > 0)
403 {
404 // GLES 2.0.25 table 4.5.
405 // GLES 3.0.5 section 3.8.3.1.
406 // GLES 3.1 table 8.14.
407
408 // Required formats in all versions.
409 switch (internalFormat)
410 {
411 case GL_DEPTH_COMPONENT16:
412 case GL_STENCIL_INDEX8:
413 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
414 // is in section 4.4.2.2.
415 return true;
416 default:
417 break;
418 }
419 if (version.major < 3)
420 {
421 return false;
422 }
423 // Required formats in GLES 3.0 and up.
424 switch (internalFormat)
425 {
426 case GL_DEPTH_COMPONENT32F:
427 case GL_DEPTH_COMPONENT24:
428 case GL_DEPTH32F_STENCIL8:
429 case GL_DEPTH24_STENCIL8:
430 return true;
431 default:
432 return false;
433 }
434 }
435
436 // RGBA formats.
437 // GLES 2.0.25 table 4.5.
438 // GLES 3.0.5 section 3.8.3.1.
439 // GLES 3.1 table 8.13.
440
441 // Required formats in all versions.
442 switch (internalFormat)
443 {
444 case GL_RGBA4:
445 case GL_RGB5_A1:
446 case GL_RGB565:
447 return true;
448 default:
449 break;
450 }
451 if (version.major < 3)
452 {
453 return false;
454 }
455
456 if (format == GL_BGRA_EXT)
457 {
458 return false;
459 }
460
461 switch (componentType)
462 {
463 case GL_SIGNED_NORMALIZED:
464 case GL_FLOAT:
465 return false;
466 case GL_UNSIGNED_INT:
467 case GL_INT:
468 // Integer RGB formats are not required renderbuffer formats.
469 if (alphaBits == 0 && blueBits != 0)
470 {
471 return false;
472 }
473 // All integer R and RG formats are required.
474 // Integer RGBA formats including RGB10_A2_UI are required.
475 return true;
476 case GL_UNSIGNED_NORMALIZED:
477 if (internalFormat == GL_SRGB8)
478 {
479 return false;
480 }
481 return true;
482 default:
483 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500484#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300485 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500486#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300487 }
488}
489
Markus Tavenrath0d665132018-11-18 15:47:02 +0100490Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat)) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400491
Markus Tavenrath0d665132018-11-18 15:47:02 +0100492Format::Format(const InternalFormat &internalFormat) : info(&internalFormat) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400493
Geoff Langca271392017-04-05 12:30:00 -0400494Format::Format(GLenum internalFormat, GLenum type)
495 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madillb980c562018-11-27 11:34:27 -0500496{}
Jamie Madilla3944d42016-07-22 22:13:26 -0400497
498Format::Format(const Format &other) = default;
499Format &Format::operator=(const Format &other) = default;
500
Jamie Madilla3944d42016-07-22 22:13:26 -0400501bool Format::valid() const
502{
Geoff Langca271392017-04-05 12:30:00 -0400503 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400504}
505
506// static
507bool Format::SameSized(const Format &a, const Format &b)
508{
Geoff Langca271392017-04-05 12:30:00 -0400509 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400510}
511
Kenneth Russell69382852017-07-21 16:38:44 -0400512static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
513{
514 // BlitFramebuffer works if the color channels are identically
515 // sized, even if there is a swizzle (for example, blitting from a
516 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
517 // be expanded and/or autogenerated if that is found necessary.
518 if (internalformat == GL_BGRA8_EXT)
519 return GL_RGBA8;
520 return internalformat;
521}
522
523// static
524bool Format::EquivalentForBlit(const Format &a, const Format &b)
525{
526 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
527 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
528}
529
Jamie Madilla3944d42016-07-22 22:13:26 -0400530// static
531Format Format::Invalid()
532{
Geoff Langca271392017-04-05 12:30:00 -0400533 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400534 return invalid;
535}
536
Yuly Novikovd73f8522017-01-13 17:48:57 -0500537std::ostream &operator<<(std::ostream &os, const Format &fmt)
538{
539 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400540 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500541}
542
Jamie Madilla3944d42016-07-22 22:13:26 -0400543bool InternalFormat::operator==(const InternalFormat &other) const
544{
Geoff Langca271392017-04-05 12:30:00 -0400545 // We assume all internal formats are unique if they have the same internal format and type
546 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400547}
548
549bool InternalFormat::operator!=(const InternalFormat &other) const
550{
Geoff Langca271392017-04-05 12:30:00 -0400551 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400552}
553
Geoff Langca271392017-04-05 12:30:00 -0400554void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400555{
Geoff Langca271392017-04-05 12:30:00 -0400556 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
557 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
558 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400559}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000560
Jamie Madilla3944d42016-07-22 22:13:26 -0400561void AddRGBAFormat(InternalFormatInfoMap *map,
562 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400563 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400564 GLuint red,
565 GLuint green,
566 GLuint blue,
567 GLuint alpha,
568 GLuint shared,
569 GLenum format,
570 GLenum type,
571 GLenum componentType,
572 bool srgb,
573 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400574 InternalFormat::SupportCheckFunction filterSupport,
575 InternalFormat::SupportCheckFunction textureAttachmentSupport,
576 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400577{
578 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400579 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400580 formatInfo.sized = sized;
581 formatInfo.sizedInternalFormat =
582 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400583 formatInfo.redBits = red;
584 formatInfo.greenBits = green;
585 formatInfo.blueBits = blue;
586 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400587 formatInfo.sharedBits = shared;
588 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400589 formatInfo.componentCount =
590 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400591 formatInfo.format = format;
592 formatInfo.type = type;
593 formatInfo.componentType = componentType;
594 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
595 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400596 formatInfo.filterSupport = filterSupport;
597 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
598 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400599
600 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400601}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000602
Geoff Langca271392017-04-05 12:30:00 -0400603static void AddLUMAFormat(InternalFormatInfoMap *map,
604 GLenum internalFormat,
605 bool sized,
606 GLuint luminance,
607 GLuint alpha,
608 GLenum format,
609 GLenum type,
610 GLenum componentType,
611 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400612 InternalFormat::SupportCheckFunction filterSupport,
613 InternalFormat::SupportCheckFunction textureAttachmentSupport,
614 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400615{
616 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400617 formatInfo.internalFormat = internalFormat;
618 formatInfo.sized = sized;
619 formatInfo.sizedInternalFormat =
620 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400621 formatInfo.luminanceBits = luminance;
622 formatInfo.alphaBits = alpha;
623 formatInfo.pixelBytes = (luminance + alpha) / 8;
624 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
625 formatInfo.format = format;
626 formatInfo.type = type;
627 formatInfo.componentType = componentType;
628 formatInfo.colorEncoding = GL_LINEAR;
629 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400630 formatInfo.filterSupport = filterSupport;
631 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
632 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400633
634 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400635}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636
Jamie Madilla3944d42016-07-22 22:13:26 -0400637void AddDepthStencilFormat(InternalFormatInfoMap *map,
638 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400639 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400640 GLuint depthBits,
641 GLuint stencilBits,
642 GLuint unusedBits,
643 GLenum format,
644 GLenum type,
645 GLenum componentType,
646 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400647 InternalFormat::SupportCheckFunction filterSupport,
648 InternalFormat::SupportCheckFunction textureAttachmentSupport,
649 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400650{
651 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400652 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400653 formatInfo.sized = sized;
654 formatInfo.sizedInternalFormat =
655 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400656 formatInfo.depthBits = depthBits;
657 formatInfo.stencilBits = stencilBits;
658 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
659 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
660 formatInfo.format = format;
661 formatInfo.type = type;
662 formatInfo.componentType = componentType;
663 formatInfo.colorEncoding = GL_LINEAR;
664 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400665 formatInfo.filterSupport = filterSupport;
666 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
667 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400668
669 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400670}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000671
Geoff Langca271392017-04-05 12:30:00 -0400672void AddCompressedFormat(InternalFormatInfoMap *map,
673 GLenum internalFormat,
674 GLuint compressedBlockWidth,
675 GLuint compressedBlockHeight,
676 GLuint compressedBlockSize,
677 GLuint componentCount,
Geoff Langca271392017-04-05 12:30:00 -0400678 bool srgb,
679 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400680 InternalFormat::SupportCheckFunction filterSupport,
681 InternalFormat::SupportCheckFunction textureAttachmentSupport,
682 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400683{
684 InternalFormat formatInfo;
Geoff Langcb8a9212018-06-28 12:30:36 -0400685 formatInfo.internalFormat = internalFormat;
686 formatInfo.sized = true;
687 formatInfo.sizedInternalFormat = internalFormat;
688 formatInfo.compressedBlockWidth = compressedBlockWidth;
689 formatInfo.compressedBlockHeight = compressedBlockHeight;
690 formatInfo.pixelBytes = compressedBlockSize / 8;
691 formatInfo.componentCount = componentCount;
Jamie Madill896e7de2019-04-04 10:59:55 -0400692 formatInfo.format = internalFormat;
693 formatInfo.type = GL_UNSIGNED_BYTE;
Geoff Langcb8a9212018-06-28 12:30:36 -0400694 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
695 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
696 formatInfo.compressed = true;
697 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400698 formatInfo.filterSupport = filterSupport;
699 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
700 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400701
702 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400703}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000704
Yuly Novikovd0828192018-06-15 15:51:07 -0400705// Notes:
706// 1. "Texture supported" includes all the means by which texture can be created, however,
707// GL_EXT_texture_storage in ES2 is a special case, when only glTexStorage* is allowed.
708// The assumption is that ES2 validation will not check textureSupport for sized formats.
709//
710// 2. Sized half float types are a combination of GL_HALF_FLOAT and GL_HALF_FLOAT_OES support,
711// due to a limitation that only one type for sized formats is allowed.
712//
713// TODO(ynovikov): http://anglebug.com/2846 Verify support fields of BGRA, depth, stencil
714// and compressed formats. Perform texturable check as part of filterable and attachment checks.
Geoff Lange4a492b2014-06-19 14:14:41 -0400715static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000716{
717 InternalFormatInfoMap map;
718
719 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400720 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000721
Jamie Madilla3944d42016-07-22 22:13:26 -0400722 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000723
Yuly Novikovd0828192018-06-15 15:51:07 -0400724 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
725 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> );
726 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 );
727 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> );
728 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 );
729 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> );
730 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 );
731 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> );
732 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> );
733 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> );
734 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> );
735 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 );
736 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> );
737 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> );
738 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 );
739 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> );
740 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> );
741 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 );
742 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> );
743 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> );
744 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> );
745 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> );
746 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> );
747 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> );
748 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> );
749 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> );
750 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> );
751 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> );
752 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> );
753 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> );
754 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
755 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 );
756 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
757 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 );
758 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
759 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 );
760 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> );
761 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> );
762 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> );
763 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> );
764 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> );
765 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 -0400766
Yuly Novikovd0828192018-06-15 15:51:07 -0400767 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>);
768 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>);
769 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 +0000770
Olli Etuahoceffd202018-01-08 16:39:45 +0200771 // Special format that is used for D3D textures that are used within ANGLE via the
772 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
773 // this format, but textures in this format can be created from D3D textures, and filtering them
774 // and rendering to them is allowed.
Yuly Novikovd0828192018-06-15 15:51:07 -0400775 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 +0200776
Jamie Madillec0b5802016-07-04 13:11:59 -0400777 // Special format which is not really supported, so always false for all supports.
Yuly Novikovd0828192018-06-15 15:51:07 -0400778 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 );
779 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 -0400780
Yuly Novikovd0828192018-06-15 15:51:07 -0400781 // Floating point formats
782 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
783 // It's not possible to have two entries per sized format.
784 // E.g. for GL_RG16F, one with GL_HALF_FLOAT type and the other with GL_HALF_FLOAT_OES type.
785 // So, GL_HALF_FLOAT type formats conditions are merged with GL_HALF_FLOAT_OES type conditions.
786 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
787 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
788 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBTextureAttachmentSupport, SizedHalfFloatRGBRenderbufferSupport );
789 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBATextureAttachmentSupport, SizedHalfFloatRGBARenderbufferSupport );
790 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>);
791 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>);
792 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 );
Jeff Gilbert6446c882019-03-28 17:49:38 -0700793 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBARenderableSupport, SizedFloatRGBARenderableSupport );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000794
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600795 // ANGLE Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400796 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600797 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::depthTextureOES>, RequireES<1, 0>, RequireES<1, 0> );
Courtney Goeltzenleuchterb76bf1b2019-04-18 16:00:22 -0600798 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::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> );
799 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, RequireES<3, 0>, RequireES<3, 0> );
Courtney Goeltzenleuchtereaf2d922019-04-18 16:31:25 -0600800 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>, AlwaysSupported, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>, RequireExtOrExtOrExt<&Extensions::depthTextureANGLE, &Extensions::depthTextureOES, &Extensions::depth32>);
Courtney Goeltzenleuchterb76bf1b2019-04-18 16:00:22 -0600801 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextureANGLE>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextureANGLE, &Extensions::packedDepthStencil>);
802 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 -0800803 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000804
805 // Luminance alpha formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400806 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
807 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
808 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
809 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
810 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);
811 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);
812 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);
813 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
814 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
815 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 +0000816
817 // Compressed formats, From ES 3.0.1 spec, table 3.16
Jamie Madill896e7de2019-04-04 10:59:55 -0400818 // | Internal format |W |H | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
819 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
820 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
821 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
822 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
823 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
824 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
825 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughARGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
826 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, AlwaysSupported, NeverSupported, NeverSupported);
827 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGBA8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
828 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Alpha8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000829
830 // From GL_EXT_texture_compression_dxt1
Jamie Madill896e7de2019-04-04 10:59:55 -0400831 // | Internal format |W |H | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
832 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
833 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000834
835 // From GL_ANGLE_texture_compression_dxt3
Jamie Madill896e7de2019-04-04 10:59:55 -0400836 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionDXT3>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000837
838 // From GL_ANGLE_texture_compression_dxt5
Jamie Madill896e7de2019-04-04 10:59:55 -0400839 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionDXT5>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400840
841 // From GL_OES_compressed_ETC1_RGB8_texture
Jamie Madill896e7de2019-04-04 10:59:55 -0400842 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800844 // From GL_EXT_texture_compression_s3tc_srgb
Jamie Madill896e7de2019-04-04 10:59:55 -0400845 // | Internal format |W |H | BS |CC|SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
846 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
847 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
848 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
849 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800850
Geoff Lang60ad73d2015-10-23 10:08:44 -0400851 // From KHR_texture_compression_astc_hdr
Jamie Madill896e7de2019-04-04 10:59:55 -0400852 // | Internal format | W | H | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
853 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
854 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
855 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
856 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
857 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
858 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
859 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
860 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
861 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
862 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
863 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
864 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
865 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
866 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400867
Jamie Madill896e7de2019-04-04 10:59:55 -0400868 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
869 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
870 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
871 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
872 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
873 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
874 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
875 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
876 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
877 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
878 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
879 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
880 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
881 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400882
Olli Etuahof2ed2992018-10-04 13:54:42 +0300883 // From EXT_texture_compression_bptc
Jamie Madill896e7de2019-04-04 10:59:55 -0400884 // | Internal format | W | H | BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
885 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
886 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 128, 4, true, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
887 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
888 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 128, 4, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
Olli Etuahof2ed2992018-10-04 13:54:42 +0300889
Corentin Walleze0902642014-11-04 12:32:15 -0800890 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
891 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
892 // - All other stencil formats (all depth-stencil) are either float or normalized
893 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400894 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
895 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 -0800896
897 // From GL_ANGLE_lossy_etc_decode
Jamie Madill896e7de2019-04-04 10:59:55 -0400898 // | Internal format |W |H |BS |CC| SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
899 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
900 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
901 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
902 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
903 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800904
Vincent Lang25ab4512016-05-13 18:13:59 +0200905 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400906 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
907 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>);
908 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 );
909 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>);
910 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 );
911 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 );
912 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 );
913 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>);
914 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 +0200915
Geoff Langca271392017-04-05 12:30:00 -0400916 // Unsized formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400917 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
918 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);
919 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
920 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);
921 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
922 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);
923 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);
924 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
925 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);
926 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);
927 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);
928 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);
929 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
930 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);
931 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);
932 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 -0400933
934 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400935 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
936 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);
937 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);
938 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);
939 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);
940 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);
941 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);
942 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);
943 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);
944 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);
945 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);
946 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);
947 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);
948 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);
949 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);
950 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);
951 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);
952 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);
953 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);
954 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);
955 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);
956 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);
957 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);
958 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);
959 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);
960 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 -0400961
962 // Unsized floating point formats
Geoff Lang979f3bb2019-03-14 10:23:29 -0400963 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
964 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
965 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
966 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
967 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
968 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);
969 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);
970 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>, RequireExtAndExt<&Extensions::colorBufferHalfFloat, &Extensions::webglCompatibility>, NeverSupported);
971 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>, RequireExt<&Extensions::colorBufferHalfFloat>, NeverSupported);
972 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);
973 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);
974 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);
975 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);
976 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);
977 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 -0400978
979 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400980 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
Yuly Novikovd0828192018-06-15 15:51:07 -0400981 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
982 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
983 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 -0400984 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
985 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
986 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);
987 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
988 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
989 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 -0400990
991 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400992 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
993 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> );
994 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> );
995 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> );
996 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>);
997 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>);
998 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 -0400999 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -08001000
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001001 return map;
1002}
1003
Geoff Lange4a492b2014-06-19 14:14:41 -04001004static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001005{
Geoff Lange4a492b2014-06-19 14:14:41 -04001006 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
1007 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001008}
1009
Geoff Lange4a492b2014-06-19 14:14:41 -04001010static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -04001011{
1012 FormatSet result;
1013
Geoff Langca271392017-04-05 12:30:00 -04001014 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -04001015 {
Geoff Langca271392017-04-05 12:30:00 -04001016 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -04001017 {
Geoff Langca271392017-04-05 12:30:00 -04001018 if (type.second.sized)
1019 {
1020 // TODO(jmadill): Fix this hack.
1021 if (internalFormat.first == GL_BGR565_ANGLEX)
1022 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -04001023
Geoff Langca271392017-04-05 12:30:00 -04001024 result.insert(internalFormat.first);
1025 }
Geoff Langcec35902014-04-16 10:52:36 -04001026 }
1027 }
1028
1029 return result;
1030}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001031
Markus Tavenrath0d665132018-11-18 15:47:02 +01001032uint32_t GetPackedTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001033{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001034 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001035 {
Frank Henigman95fb2a12018-05-27 20:17:05 -04001036 case GL_UNSIGNED_BYTE:
1037 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001038 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001039 static constexpr uint32_t kPacked = PackTypeInfo(1, false);
1040 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001041 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001042 case GL_UNSIGNED_SHORT:
1043 case GL_SHORT:
1044 case GL_HALF_FLOAT:
1045 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001046 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001047 static constexpr uint32_t kPacked = PackTypeInfo(2, false);
1048 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001049 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001050 case GL_UNSIGNED_INT:
1051 case GL_INT:
1052 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001053 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001054 static constexpr uint32_t kPacked = PackTypeInfo(4, false);
1055 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001056 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001057 case GL_UNSIGNED_SHORT_5_6_5:
1058 case GL_UNSIGNED_SHORT_4_4_4_4:
1059 case GL_UNSIGNED_SHORT_5_5_5_1:
1060 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1061 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001062 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001063 static constexpr uint32_t kPacked = PackTypeInfo(2, true);
1064 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001065 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001066 case GL_UNSIGNED_INT_2_10_10_10_REV:
1067 case GL_UNSIGNED_INT_24_8:
1068 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1069 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001070 {
1071 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
Markus Tavenrath0d665132018-11-18 15:47:02 +01001072 static constexpr uint32_t kPacked = PackTypeInfo(4, true);
1073 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001074 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001075 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001076 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001077 static constexpr uint32_t kPacked = PackTypeInfo(8, true);
1078 return kPacked;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001079 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001080 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001081 {
Markus Tavenrath0d665132018-11-18 15:47:02 +01001082 return 0;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001083 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001084 }
1085}
1086
Geoff Langca271392017-04-05 12:30:00 -04001087const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001088{
Geoff Langca271392017-04-05 12:30:00 -04001089 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001090 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001091 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001092
1093 // Sized internal formats only have one type per entry
1094 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001095 {
Geoff Lang5d601382014-07-22 15:14:06 -04001096 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001097 }
Geoff Langca271392017-04-05 12:30:00 -04001098
1099 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1100 if (!internalFormatInfo.sized)
1101 {
1102 return defaultInternalFormat;
1103 }
1104
1105 return internalFormatInfo;
1106}
1107
1108const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1109{
1110 static const InternalFormat defaultInternalFormat;
1111 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1112
1113 auto internalFormatIter = formatMap.find(internalFormat);
1114 if (internalFormatIter == formatMap.end())
1115 {
1116 return defaultInternalFormat;
1117 }
1118
1119 // If the internal format is sized, simply return it without the type check.
1120 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1121 {
1122 return internalFormatIter->second.begin()->second;
1123 }
1124
1125 auto typeIter = internalFormatIter->second.find(type);
1126 if (typeIter == internalFormatIter->second.end())
1127 {
1128 return defaultInternalFormat;
1129 }
1130
1131 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001132}
1133
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001134GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1135{
1136 const auto &typeInfo = GetTypeInfo(formatType);
1137 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1138 return components * typeInfo.bytes;
1139}
1140
Jamie Madillca2ff382018-07-11 09:01:17 -04001141bool InternalFormat::computeRowPitch(GLenum formatType,
1142 GLsizei width,
1143 GLint alignment,
1144 GLint rowLength,
1145 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001146{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001147 // Compressed images do not use pack/unpack parameters.
1148 if (compressed)
1149 {
1150 ASSERT(rowLength == 0);
Jamie Madillca2ff382018-07-11 09:01:17 -04001151 return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001152 }
1153
Geoff Lang3f234062016-07-13 15:35:45 -04001154 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001155 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001156
1157 ASSERT(alignment > 0 && isPow2(alignment));
1158 CheckedNumeric<GLuint> checkedAlignment(alignment);
1159 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
Jamie Madillca2ff382018-07-11 09:01:17 -04001160 return CheckedMathResult(aligned, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001161}
1162
Jamie Madillca2ff382018-07-11 09:01:17 -04001163bool InternalFormat::computeDepthPitch(GLsizei height,
1164 GLint imageHeight,
1165 GLuint rowPitch,
1166 GLuint *resultOut) const
Corentin Wallez0e487192016-10-03 16:30:38 -04001167{
1168 GLuint rows =
1169 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1170 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1171
Jamie Madillca2ff382018-07-11 09:01:17 -04001172 return CheckedMathResult(checkedRowPitch * rows, resultOut);
Corentin Wallez0e487192016-10-03 16:30:38 -04001173}
1174
Jamie Madillca2ff382018-07-11 09:01:17 -04001175bool InternalFormat::computeDepthPitch(GLenum formatType,
1176 GLsizei width,
1177 GLsizei height,
1178 GLint alignment,
1179 GLint rowLength,
1180 GLint imageHeight,
1181 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001182{
Jamie Madille2e406c2016-06-02 13:04:10 -04001183 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001184 if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1185 {
1186 return false;
1187 }
1188 return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001189}
1190
Jamie Madillca2ff382018-07-11 09:01:17 -04001191bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001192{
Jamie Madill513558d2016-06-02 13:04:11 -04001193 CheckedNumeric<GLuint> checkedWidth(size.width);
1194 CheckedNumeric<GLuint> checkedHeight(size.height);
1195 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001196 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1197 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001198
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001199 ASSERT(compressed);
1200 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1201 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1202 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
Jamie Madillca2ff382018-07-11 09:01:17 -04001203 return CheckedMathResult(bytes, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001204}
1205
Jamie Madillca2ff382018-07-11 09:01:17 -04001206bool InternalFormat::computeSkipBytes(GLenum formatType,
1207 GLuint rowPitch,
1208 GLuint depthPitch,
1209 const PixelStoreStateBase &state,
1210 bool is3D,
1211 GLuint *resultOut) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001212{
Olli Etuaho989cac32016-06-08 16:18:49 -07001213 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1214 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001215 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1216 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1217 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001218 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001219 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001220 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001221 {
1222 checkedSkipImagesBytes = 0;
1223 }
1224 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1225 checkedSkipPixels * checkedPixelBytes;
Jamie Madillca2ff382018-07-11 09:01:17 -04001226 return CheckedMathResult(skipBytes, resultOut);
Minmin Gongadff67b2015-10-14 10:34:45 -04001227}
1228
Jamie Madillca2ff382018-07-11 09:01:17 -04001229bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1230 const Extents &size,
1231 const PixelStoreStateBase &state,
1232 bool is3D,
1233 GLuint *resultOut) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001234{
Corentin Wallez886de362016-09-27 10:49:35 -04001235 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001236 if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
Corentin Wallez0e487192016-10-03 16:30:38 -04001237 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001238 return false;
Corentin Wallez0e487192016-10-03 16:30:38 -04001239 }
1240
Jamie Madillca2ff382018-07-11 09:01:17 -04001241 GLuint depthPitch = 0;
1242 if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1243 {
1244 return false;
1245 }
1246
1247 CheckedNumeric<GLuint> checkedCopyBytes(0);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001248 if (compressed)
1249 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001250 GLuint copyBytes = 0;
1251 if (!computeCompressedImageSize(size, &copyBytes))
1252 {
1253 return false;
1254 }
1255 checkedCopyBytes = copyBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001256 }
Corentin Wallez886de362016-09-27 10:49:35 -04001257 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001258 {
Corentin Wallez886de362016-09-27 10:49:35 -04001259 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1260 checkedCopyBytes += size.width * bytes;
1261
1262 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1263 checkedCopyBytes += heightMinusOne * rowPitch;
1264
1265 if (is3D)
1266 {
1267 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1268 checkedCopyBytes += depthMinusOne * depthPitch;
1269 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001270 }
1271
Jamie Madillca2ff382018-07-11 09:01:17 -04001272 GLuint skipBytes = 0;
1273 if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1274 {
1275 return false;
1276 }
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001277
Jamie Madillca2ff382018-07-11 09:01:17 -04001278 CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001279
Jamie Madillca2ff382018-07-11 09:01:17 -04001280 return CheckedMathResult(endByte, resultOut);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001281}
1282
Geoff Langca271392017-04-05 12:30:00 -04001283GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001284{
Geoff Langca271392017-04-05 12:30:00 -04001285 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1286 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001287 {
Geoff Langca271392017-04-05 12:30:00 -04001288 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001289 }
Geoff Langca271392017-04-05 12:30:00 -04001290
1291 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001292}
1293
Geoff Lange4a492b2014-06-19 14:14:41 -04001294const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001295{
Geoff Lange4a492b2014-06-19 14:14:41 -04001296 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001297 return formatSet;
1298}
1299
Jamie Madill09e2d932015-07-14 16:40:31 -04001300AttributeType GetAttributeType(GLenum enumValue)
1301{
1302 switch (enumValue)
1303 {
1304 case GL_FLOAT:
1305 return ATTRIBUTE_FLOAT;
1306 case GL_FLOAT_VEC2:
1307 return ATTRIBUTE_VEC2;
1308 case GL_FLOAT_VEC3:
1309 return ATTRIBUTE_VEC3;
1310 case GL_FLOAT_VEC4:
1311 return ATTRIBUTE_VEC4;
1312 case GL_INT:
1313 return ATTRIBUTE_INT;
1314 case GL_INT_VEC2:
1315 return ATTRIBUTE_IVEC2;
1316 case GL_INT_VEC3:
1317 return ATTRIBUTE_IVEC3;
1318 case GL_INT_VEC4:
1319 return ATTRIBUTE_IVEC4;
1320 case GL_UNSIGNED_INT:
1321 return ATTRIBUTE_UINT;
1322 case GL_UNSIGNED_INT_VEC2:
1323 return ATTRIBUTE_UVEC2;
1324 case GL_UNSIGNED_INT_VEC3:
1325 return ATTRIBUTE_UVEC3;
1326 case GL_UNSIGNED_INT_VEC4:
1327 return ATTRIBUTE_UVEC4;
1328 case GL_FLOAT_MAT2:
1329 return ATTRIBUTE_MAT2;
1330 case GL_FLOAT_MAT3:
1331 return ATTRIBUTE_MAT3;
1332 case GL_FLOAT_MAT4:
1333 return ATTRIBUTE_MAT4;
1334 case GL_FLOAT_MAT2x3:
1335 return ATTRIBUTE_MAT2x3;
1336 case GL_FLOAT_MAT2x4:
1337 return ATTRIBUTE_MAT2x4;
1338 case GL_FLOAT_MAT3x2:
1339 return ATTRIBUTE_MAT3x2;
1340 case GL_FLOAT_MAT3x4:
1341 return ATTRIBUTE_MAT3x4;
1342 case GL_FLOAT_MAT4x2:
1343 return ATTRIBUTE_MAT4x2;
1344 case GL_FLOAT_MAT4x3:
1345 return ATTRIBUTE_MAT4x3;
1346 default:
1347 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001348#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001349 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001350#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001351 }
1352}
1353
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001354angle::FormatID GetVertexFormatID(VertexAttribType type,
Jamie Madillba365932018-07-18 17:23:46 -04001355 GLboolean normalized,
1356 GLuint components,
1357 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001358{
1359 switch (type)
1360 {
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001361 case VertexAttribType::Byte:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001362 switch (components)
1363 {
1364 case 1:
1365 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001366 return angle::FormatID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001367 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001368 return angle::FormatID::R8_SNORM;
1369 return angle::FormatID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001370 case 2:
1371 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001372 return angle::FormatID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001373 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001374 return angle::FormatID::R8G8_SNORM;
1375 return angle::FormatID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001376 case 3:
1377 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001378 return angle::FormatID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001379 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001380 return angle::FormatID::R8G8B8_SNORM;
1381 return angle::FormatID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001382 case 4:
1383 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001384 return angle::FormatID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001385 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001386 return angle::FormatID::R8G8B8A8_SNORM;
1387 return angle::FormatID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001388 default:
1389 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001390#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001391 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001392#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001393 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001394 case VertexAttribType::UnsignedByte:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001395 switch (components)
1396 {
1397 case 1:
1398 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001399 return angle::FormatID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001400 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001401 return angle::FormatID::R8_UNORM;
1402 return angle::FormatID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001403 case 2:
1404 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001405 return angle::FormatID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001406 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001407 return angle::FormatID::R8G8_UNORM;
1408 return angle::FormatID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001409 case 3:
1410 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001411 return angle::FormatID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001412 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001413 return angle::FormatID::R8G8B8_UNORM;
1414 return angle::FormatID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001415 case 4:
1416 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001417 return angle::FormatID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001418 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001419 return angle::FormatID::R8G8B8A8_UNORM;
1420 return angle::FormatID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001421 default:
1422 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001423#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001424 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001425#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001426 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001427 case VertexAttribType::Short:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001428 switch (components)
1429 {
1430 case 1:
1431 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001432 return angle::FormatID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001433 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001434 return angle::FormatID::R16_SNORM;
1435 return angle::FormatID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001436 case 2:
1437 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001438 return angle::FormatID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001439 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001440 return angle::FormatID::R16G16_SNORM;
1441 return angle::FormatID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001442 case 3:
1443 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001444 return angle::FormatID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001445 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001446 return angle::FormatID::R16G16B16_SNORM;
1447 return angle::FormatID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001448 case 4:
1449 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001450 return angle::FormatID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001451 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001452 return angle::FormatID::R16G16B16A16_SNORM;
1453 return angle::FormatID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001454 default:
1455 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001456#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001457 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001458#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001459 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001460 case VertexAttribType::UnsignedShort:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001461 switch (components)
1462 {
1463 case 1:
1464 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001465 return angle::FormatID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001466 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001467 return angle::FormatID::R16_UNORM;
1468 return angle::FormatID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001469 case 2:
1470 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001471 return angle::FormatID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001472 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001473 return angle::FormatID::R16G16_UNORM;
1474 return angle::FormatID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001475 case 3:
1476 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001477 return angle::FormatID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001478 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001479 return angle::FormatID::R16G16B16_UNORM;
1480 return angle::FormatID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001481 case 4:
1482 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001483 return angle::FormatID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001484 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001485 return angle::FormatID::R16G16B16A16_UNORM;
1486 return angle::FormatID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001487 default:
1488 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001489#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001490 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001491#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001492 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001493 case VertexAttribType::Int:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001494 switch (components)
1495 {
1496 case 1:
1497 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001498 return angle::FormatID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001499 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001500 return angle::FormatID::R32_SNORM;
1501 return angle::FormatID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001502 case 2:
1503 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001504 return angle::FormatID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001505 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001506 return angle::FormatID::R32G32_SNORM;
1507 return angle::FormatID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001508 case 3:
1509 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001510 return angle::FormatID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001511 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001512 return angle::FormatID::R32G32B32_SNORM;
1513 return angle::FormatID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001514 case 4:
1515 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001516 return angle::FormatID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001517 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001518 return angle::FormatID::R32G32B32A32_SNORM;
1519 return angle::FormatID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001520 default:
1521 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001522#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001523 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001524#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001525 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001526 case VertexAttribType::UnsignedInt:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001527 switch (components)
1528 {
1529 case 1:
1530 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001531 return angle::FormatID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001532 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001533 return angle::FormatID::R32_UNORM;
1534 return angle::FormatID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001535 case 2:
1536 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001537 return angle::FormatID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001538 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001539 return angle::FormatID::R32G32_UNORM;
1540 return angle::FormatID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001541 case 3:
1542 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001543 return angle::FormatID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001544 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001545 return angle::FormatID::R32G32B32_UNORM;
1546 return angle::FormatID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001547 case 4:
1548 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001549 return angle::FormatID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001550 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001551 return angle::FormatID::R32G32B32A32_UNORM;
1552 return angle::FormatID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001553 default:
1554 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001555#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001556 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001557#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001558 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001559 case VertexAttribType::Float:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001560 switch (components)
1561 {
1562 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001563 return angle::FormatID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001564 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001565 return angle::FormatID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001566 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001567 return angle::FormatID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001568 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001569 return angle::FormatID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001570 default:
1571 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001572#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001573 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001574#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001575 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001576 case VertexAttribType::HalfFloat:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001577 switch (components)
1578 {
1579 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001580 return angle::FormatID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001581 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001582 return angle::FormatID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001583 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001584 return angle::FormatID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001585 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001586 return angle::FormatID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001587 default:
1588 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001589#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001590 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001591#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001592 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001593 case VertexAttribType::Fixed:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001594 switch (components)
1595 {
1596 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001597 return angle::FormatID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001598 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001599 return angle::FormatID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001600 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001601 return angle::FormatID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001602 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001603 return angle::FormatID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001604 default:
1605 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001606#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001607 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001608#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001609 }
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001610 case VertexAttribType::Int2101010:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001611 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001612 return angle::FormatID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001613 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001614 return angle::FormatID::R10G10B10A2_SNORM;
1615 return angle::FormatID::R10G10B10A2_SSCALED;
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001616 case VertexAttribType::UnsignedInt2101010:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001617 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001618 return angle::FormatID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001619 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001620 return angle::FormatID::R10G10B10A2_UNORM;
1621 return angle::FormatID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001622 default:
1623 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001624#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001625 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001626#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001627 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001628}
1629
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001630angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, VertexAttribType currentValueType)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001631{
1632 if (!attrib.enabled)
1633 {
Jamie Madilldd34b3b2019-01-16 09:59:54 -05001634 return GetVertexFormatID(currentValueType, GL_FALSE, 4,
1635 (currentValueType != VertexAttribType::Float));
Jamie Madilld3dfda22015-07-06 08:28:49 -04001636 }
Frank Henigmand633b152018-10-04 23:34:31 -04001637 return GetVertexFormatID(attrib);
Jamie Madilld3dfda22015-07-06 08:28:49 -04001638}
1639
Frank Henigmand633b152018-10-04 23:34:31 -04001640const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001641{
Frank Henigmand633b152018-10-04 23:34:31 -04001642 switch (vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001643 {
Frank Henigmand633b152018-10-04 23:34:31 -04001644 case angle::FormatID::R8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001645 {
1646 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1647 return format;
1648 }
Frank Henigmand633b152018-10-04 23:34:31 -04001649 case angle::FormatID::R8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001650 {
1651 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1652 return format;
1653 }
Frank Henigmand633b152018-10-04 23:34:31 -04001654 case angle::FormatID::R8G8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001655 {
1656 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1657 return format;
1658 }
Frank Henigmand633b152018-10-04 23:34:31 -04001659 case angle::FormatID::R8G8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001660 {
1661 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1662 return format;
1663 }
Frank Henigmand633b152018-10-04 23:34:31 -04001664 case angle::FormatID::R8G8B8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001665 {
1666 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1667 return format;
1668 }
Frank Henigmand633b152018-10-04 23:34:31 -04001669 case angle::FormatID::R8G8B8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001670 {
1671 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1672 return format;
1673 }
Frank Henigmand633b152018-10-04 23:34:31 -04001674 case angle::FormatID::R8G8B8A8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001675 {
1676 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1677 return format;
1678 }
Frank Henigmand633b152018-10-04 23:34:31 -04001679 case angle::FormatID::R8G8B8A8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001680 {
1681 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1682 return format;
1683 }
Frank Henigmand633b152018-10-04 23:34:31 -04001684 case angle::FormatID::R8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001685 {
1686 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1687 return format;
1688 }
Frank Henigmand633b152018-10-04 23:34:31 -04001689 case angle::FormatID::R8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001690 {
1691 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1692 return format;
1693 }
Frank Henigmand633b152018-10-04 23:34:31 -04001694 case angle::FormatID::R8G8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001695 {
1696 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1697 return format;
1698 }
Frank Henigmand633b152018-10-04 23:34:31 -04001699 case angle::FormatID::R8G8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001700 {
1701 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1702 return format;
1703 }
Frank Henigmand633b152018-10-04 23:34:31 -04001704 case angle::FormatID::R8G8B8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001705 {
1706 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1707 return format;
1708 }
Frank Henigmand633b152018-10-04 23:34:31 -04001709 case angle::FormatID::R8G8B8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001710 {
1711 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1712 return format;
1713 }
Frank Henigmand633b152018-10-04 23:34:31 -04001714 case angle::FormatID::R8G8B8A8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001715 {
1716 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1717 return format;
1718 }
Frank Henigmand633b152018-10-04 23:34:31 -04001719 case angle::FormatID::R8G8B8A8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001720 {
1721 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1722 return format;
1723 }
Frank Henigmand633b152018-10-04 23:34:31 -04001724 case angle::FormatID::R16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001725 {
1726 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1727 return format;
1728 }
Frank Henigmand633b152018-10-04 23:34:31 -04001729 case angle::FormatID::R16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001730 {
1731 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1732 return format;
1733 }
Frank Henigmand633b152018-10-04 23:34:31 -04001734 case angle::FormatID::R16G16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001735 {
1736 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1737 return format;
1738 }
Frank Henigmand633b152018-10-04 23:34:31 -04001739 case angle::FormatID::R16G16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001740 {
1741 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1742 return format;
1743 }
Frank Henigmand633b152018-10-04 23:34:31 -04001744 case angle::FormatID::R16G16B16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001745 {
1746 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1747 return format;
1748 }
Frank Henigmand633b152018-10-04 23:34:31 -04001749 case angle::FormatID::R16G16B16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001750 {
1751 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1752 return format;
1753 }
Frank Henigmand633b152018-10-04 23:34:31 -04001754 case angle::FormatID::R16G16B16A16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001755 {
1756 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1757 return format;
1758 }
Frank Henigmand633b152018-10-04 23:34:31 -04001759 case angle::FormatID::R16G16B16A16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001760 {
1761 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1762 return format;
1763 }
Frank Henigmand633b152018-10-04 23:34:31 -04001764 case angle::FormatID::R16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001765 {
1766 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1767 return format;
1768 }
Frank Henigmand633b152018-10-04 23:34:31 -04001769 case angle::FormatID::R16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001770 {
1771 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1772 return format;
1773 }
Frank Henigmand633b152018-10-04 23:34:31 -04001774 case angle::FormatID::R16G16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001775 {
1776 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1777 return format;
1778 }
Frank Henigmand633b152018-10-04 23:34:31 -04001779 case angle::FormatID::R16G16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001780 {
1781 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1782 return format;
1783 }
Frank Henigmand633b152018-10-04 23:34:31 -04001784 case angle::FormatID::R16G16B16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001785 {
1786 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1787 return format;
1788 }
Frank Henigmand633b152018-10-04 23:34:31 -04001789 case angle::FormatID::R16G16B16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001790 {
1791 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1792 return format;
1793 }
Frank Henigmand633b152018-10-04 23:34:31 -04001794 case angle::FormatID::R16G16B16A16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001795 {
1796 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1797 return format;
1798 }
Frank Henigmand633b152018-10-04 23:34:31 -04001799 case angle::FormatID::R16G16B16A16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001800 {
1801 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1802 return format;
1803 }
Frank Henigmand633b152018-10-04 23:34:31 -04001804 case angle::FormatID::R32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001805 {
1806 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1807 return format;
1808 }
Frank Henigmand633b152018-10-04 23:34:31 -04001809 case angle::FormatID::R32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001810 {
1811 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1812 return format;
1813 }
Frank Henigmand633b152018-10-04 23:34:31 -04001814 case angle::FormatID::R32G32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001815 {
1816 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1817 return format;
1818 }
Frank Henigmand633b152018-10-04 23:34:31 -04001819 case angle::FormatID::R32G32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001820 {
1821 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1822 return format;
1823 }
Frank Henigmand633b152018-10-04 23:34:31 -04001824 case angle::FormatID::R32G32B32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001825 {
1826 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1827 return format;
1828 }
Frank Henigmand633b152018-10-04 23:34:31 -04001829 case angle::FormatID::R32G32B32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001830 {
1831 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1832 return format;
1833 }
Frank Henigmand633b152018-10-04 23:34:31 -04001834 case angle::FormatID::R32G32B32A32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001835 {
1836 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1837 return format;
1838 }
Frank Henigmand633b152018-10-04 23:34:31 -04001839 case angle::FormatID::R32G32B32A32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001840 {
1841 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1842 return format;
1843 }
Frank Henigmand633b152018-10-04 23:34:31 -04001844 case angle::FormatID::R32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001845 {
1846 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1847 return format;
1848 }
Frank Henigmand633b152018-10-04 23:34:31 -04001849 case angle::FormatID::R32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001850 {
1851 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1852 return format;
1853 }
Frank Henigmand633b152018-10-04 23:34:31 -04001854 case angle::FormatID::R32G32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001855 {
1856 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1857 return format;
1858 }
Frank Henigmand633b152018-10-04 23:34:31 -04001859 case angle::FormatID::R32G32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001860 {
1861 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1862 return format;
1863 }
Frank Henigmand633b152018-10-04 23:34:31 -04001864 case angle::FormatID::R32G32B32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001865 {
1866 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1867 return format;
1868 }
Frank Henigmand633b152018-10-04 23:34:31 -04001869 case angle::FormatID::R32G32B32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001870 {
1871 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1872 return format;
1873 }
Frank Henigmand633b152018-10-04 23:34:31 -04001874 case angle::FormatID::R32G32B32A32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001875 {
1876 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1877 return format;
1878 }
Frank Henigmand633b152018-10-04 23:34:31 -04001879 case angle::FormatID::R32G32B32A32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001880 {
1881 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1882 return format;
1883 }
Frank Henigmand633b152018-10-04 23:34:31 -04001884 case angle::FormatID::R8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001885 {
1886 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1887 return format;
1888 }
Frank Henigmand633b152018-10-04 23:34:31 -04001889 case angle::FormatID::R8G8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001890 {
1891 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1892 return format;
1893 }
Frank Henigmand633b152018-10-04 23:34:31 -04001894 case angle::FormatID::R8G8B8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001895 {
1896 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1897 return format;
1898 }
Frank Henigmand633b152018-10-04 23:34:31 -04001899 case angle::FormatID::R8G8B8A8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001900 {
1901 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1902 return format;
1903 }
Frank Henigmand633b152018-10-04 23:34:31 -04001904 case angle::FormatID::R8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001905 {
1906 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1907 return format;
1908 }
Frank Henigmand633b152018-10-04 23:34:31 -04001909 case angle::FormatID::R8G8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001910 {
1911 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1912 return format;
1913 }
Frank Henigmand633b152018-10-04 23:34:31 -04001914 case angle::FormatID::R8G8B8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001915 {
1916 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1917 return format;
1918 }
Frank Henigmand633b152018-10-04 23:34:31 -04001919 case angle::FormatID::R8G8B8A8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001920 {
1921 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1922 return format;
1923 }
Frank Henigmand633b152018-10-04 23:34:31 -04001924 case angle::FormatID::R16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001925 {
1926 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1927 return format;
1928 }
Frank Henigmand633b152018-10-04 23:34:31 -04001929 case angle::FormatID::R16G16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001930 {
1931 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1932 return format;
1933 }
Frank Henigmand633b152018-10-04 23:34:31 -04001934 case angle::FormatID::R16G16B16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001935 {
1936 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1937 return format;
1938 }
Frank Henigmand633b152018-10-04 23:34:31 -04001939 case angle::FormatID::R16G16B16A16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001940 {
1941 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1942 return format;
1943 }
Frank Henigmand633b152018-10-04 23:34:31 -04001944 case angle::FormatID::R16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001945 {
1946 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1947 return format;
1948 }
Frank Henigmand633b152018-10-04 23:34:31 -04001949 case angle::FormatID::R16G16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001950 {
1951 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1952 return format;
1953 }
Frank Henigmand633b152018-10-04 23:34:31 -04001954 case angle::FormatID::R16G16B16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001955 {
1956 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1957 return format;
1958 }
Frank Henigmand633b152018-10-04 23:34:31 -04001959 case angle::FormatID::R16G16B16A16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001960 {
1961 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1962 return format;
1963 }
Frank Henigmand633b152018-10-04 23:34:31 -04001964 case angle::FormatID::R32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001965 {
1966 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1967 return format;
1968 }
Frank Henigmand633b152018-10-04 23:34:31 -04001969 case angle::FormatID::R32G32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001970 {
1971 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1972 return format;
1973 }
Frank Henigmand633b152018-10-04 23:34:31 -04001974 case angle::FormatID::R32G32B32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001975 {
1976 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1977 return format;
1978 }
Frank Henigmand633b152018-10-04 23:34:31 -04001979 case angle::FormatID::R32G32B32A32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001980 {
1981 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1982 return format;
1983 }
Frank Henigmand633b152018-10-04 23:34:31 -04001984 case angle::FormatID::R32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001985 {
1986 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1987 return format;
1988 }
Frank Henigmand633b152018-10-04 23:34:31 -04001989 case angle::FormatID::R32G32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001990 {
1991 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1992 return format;
1993 }
Frank Henigmand633b152018-10-04 23:34:31 -04001994 case angle::FormatID::R32G32B32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001995 {
1996 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1997 return format;
1998 }
Frank Henigmand633b152018-10-04 23:34:31 -04001999 case angle::FormatID::R32G32B32A32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002000 {
2001 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2002 return format;
2003 }
Frank Henigmand633b152018-10-04 23:34:31 -04002004 case angle::FormatID::R32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002005 {
2006 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2007 return format;
2008 }
Frank Henigmand633b152018-10-04 23:34:31 -04002009 case angle::FormatID::R32G32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002010 {
2011 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2012 return format;
2013 }
Frank Henigmand633b152018-10-04 23:34:31 -04002014 case angle::FormatID::R32G32B32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002015 {
2016 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2017 return format;
2018 }
Frank Henigmand633b152018-10-04 23:34:31 -04002019 case angle::FormatID::R32G32B32A32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002020 {
2021 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2022 return format;
2023 }
Frank Henigmand633b152018-10-04 23:34:31 -04002024 case angle::FormatID::R16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002025 {
2026 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2027 return format;
2028 }
Frank Henigmand633b152018-10-04 23:34:31 -04002029 case angle::FormatID::R16G16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002030 {
2031 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2032 return format;
2033 }
Frank Henigmand633b152018-10-04 23:34:31 -04002034 case angle::FormatID::R16G16B16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002035 {
2036 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2037 return format;
2038 }
Frank Henigmand633b152018-10-04 23:34:31 -04002039 case angle::FormatID::R16G16B16A16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002040 {
2041 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2042 return format;
2043 }
Frank Henigmand633b152018-10-04 23:34:31 -04002044 case angle::FormatID::R32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002045 {
2046 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2047 return format;
2048 }
Frank Henigmand633b152018-10-04 23:34:31 -04002049 case angle::FormatID::R32G32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002050 {
2051 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2052 return format;
2053 }
Frank Henigmand633b152018-10-04 23:34:31 -04002054 case angle::FormatID::R32G32B32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002055 {
2056 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2057 return format;
2058 }
Frank Henigmand633b152018-10-04 23:34:31 -04002059 case angle::FormatID::R32G32B32A32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002060 {
2061 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2062 return format;
2063 }
Frank Henigmand633b152018-10-04 23:34:31 -04002064 case angle::FormatID::R10G10B10A2_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002065 {
2066 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2067 return format;
2068 }
Frank Henigmand633b152018-10-04 23:34:31 -04002069 case angle::FormatID::R10G10B10A2_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002070 {
2071 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2072 return format;
2073 }
Frank Henigmand633b152018-10-04 23:34:31 -04002074 case angle::FormatID::R10G10B10A2_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002075 {
2076 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2077 return format;
2078 }
Frank Henigmand633b152018-10-04 23:34:31 -04002079 case angle::FormatID::R10G10B10A2_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002080 {
2081 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2082 return format;
2083 }
Frank Henigmand633b152018-10-04 23:34:31 -04002084 case angle::FormatID::R10G10B10A2_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002085 {
2086 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2087 return format;
2088 }
Frank Henigmand633b152018-10-04 23:34:31 -04002089 case angle::FormatID::R10G10B10A2_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002090 {
2091 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2092 return format;
2093 }
2094 default:
2095 {
2096 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2097 return format;
2098 }
2099 }
2100}
2101
Frank Henigmand633b152018-10-04 23:34:31 -04002102size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002103{
Frank Henigmand633b152018-10-04 23:34:31 -04002104 switch (vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002105 {
Frank Henigmand633b152018-10-04 23:34:31 -04002106 case angle::FormatID::R8_SSCALED:
2107 case angle::FormatID::R8_SNORM:
2108 case angle::FormatID::R8_USCALED:
2109 case angle::FormatID::R8_UNORM:
2110 case angle::FormatID::R8_SINT:
2111 case angle::FormatID::R8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002112 return 1;
2113
Frank Henigmand633b152018-10-04 23:34:31 -04002114 case angle::FormatID::R8G8_SSCALED:
2115 case angle::FormatID::R8G8_SNORM:
2116 case angle::FormatID::R8G8_USCALED:
2117 case angle::FormatID::R8G8_UNORM:
2118 case angle::FormatID::R8G8_SINT:
2119 case angle::FormatID::R8G8_UINT:
2120 case angle::FormatID::R16_SSCALED:
2121 case angle::FormatID::R16_SNORM:
2122 case angle::FormatID::R16_USCALED:
2123 case angle::FormatID::R16_UNORM:
2124 case angle::FormatID::R16_SINT:
2125 case angle::FormatID::R16_UINT:
2126 case angle::FormatID::R16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002127 return 2;
2128
Frank Henigmand633b152018-10-04 23:34:31 -04002129 case angle::FormatID::R8G8B8_SSCALED:
2130 case angle::FormatID::R8G8B8_SNORM:
2131 case angle::FormatID::R8G8B8_USCALED:
2132 case angle::FormatID::R8G8B8_UNORM:
2133 case angle::FormatID::R8G8B8_SINT:
2134 case angle::FormatID::R8G8B8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002135 return 3;
2136
Frank Henigmand633b152018-10-04 23:34:31 -04002137 case angle::FormatID::R8G8B8A8_SSCALED:
2138 case angle::FormatID::R8G8B8A8_SNORM:
2139 case angle::FormatID::R8G8B8A8_USCALED:
2140 case angle::FormatID::R8G8B8A8_UNORM:
2141 case angle::FormatID::R8G8B8A8_SINT:
2142 case angle::FormatID::R8G8B8A8_UINT:
2143 case angle::FormatID::R16G16_SSCALED:
2144 case angle::FormatID::R16G16_SNORM:
2145 case angle::FormatID::R16G16_USCALED:
2146 case angle::FormatID::R16G16_UNORM:
2147 case angle::FormatID::R16G16_SINT:
2148 case angle::FormatID::R16G16_UINT:
2149 case angle::FormatID::R32_SSCALED:
2150 case angle::FormatID::R32_SNORM:
2151 case angle::FormatID::R32_USCALED:
2152 case angle::FormatID::R32_UNORM:
2153 case angle::FormatID::R32_SINT:
2154 case angle::FormatID::R32_UINT:
2155 case angle::FormatID::R16G16_FLOAT:
2156 case angle::FormatID::R32_FIXED:
2157 case angle::FormatID::R32_FLOAT:
2158 case angle::FormatID::R10G10B10A2_SSCALED:
2159 case angle::FormatID::R10G10B10A2_USCALED:
2160 case angle::FormatID::R10G10B10A2_SNORM:
2161 case angle::FormatID::R10G10B10A2_UNORM:
2162 case angle::FormatID::R10G10B10A2_SINT:
2163 case angle::FormatID::R10G10B10A2_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002164 return 4;
2165
Frank Henigmand633b152018-10-04 23:34:31 -04002166 case angle::FormatID::R16G16B16_SSCALED:
2167 case angle::FormatID::R16G16B16_SNORM:
2168 case angle::FormatID::R16G16B16_USCALED:
2169 case angle::FormatID::R16G16B16_UNORM:
2170 case angle::FormatID::R16G16B16_SINT:
2171 case angle::FormatID::R16G16B16_UINT:
2172 case angle::FormatID::R16G16B16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002173 return 6;
2174
Frank Henigmand633b152018-10-04 23:34:31 -04002175 case angle::FormatID::R16G16B16A16_SSCALED:
2176 case angle::FormatID::R16G16B16A16_SNORM:
2177 case angle::FormatID::R16G16B16A16_USCALED:
2178 case angle::FormatID::R16G16B16A16_UNORM:
2179 case angle::FormatID::R16G16B16A16_SINT:
2180 case angle::FormatID::R16G16B16A16_UINT:
2181 case angle::FormatID::R32G32_SSCALED:
2182 case angle::FormatID::R32G32_SNORM:
2183 case angle::FormatID::R32G32_USCALED:
2184 case angle::FormatID::R32G32_UNORM:
2185 case angle::FormatID::R32G32_SINT:
2186 case angle::FormatID::R32G32_UINT:
2187 case angle::FormatID::R16G16B16A16_FLOAT:
2188 case angle::FormatID::R32G32_FIXED:
2189 case angle::FormatID::R32G32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002190 return 8;
2191
Frank Henigmand633b152018-10-04 23:34:31 -04002192 case angle::FormatID::R32G32B32_SSCALED:
2193 case angle::FormatID::R32G32B32_SNORM:
2194 case angle::FormatID::R32G32B32_USCALED:
2195 case angle::FormatID::R32G32B32_UNORM:
2196 case angle::FormatID::R32G32B32_SINT:
2197 case angle::FormatID::R32G32B32_UINT:
2198 case angle::FormatID::R32G32B32_FIXED:
2199 case angle::FormatID::R32G32B32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002200 return 12;
2201
Frank Henigmand633b152018-10-04 23:34:31 -04002202 case angle::FormatID::R32G32B32A32_SSCALED:
2203 case angle::FormatID::R32G32B32A32_SNORM:
2204 case angle::FormatID::R32G32B32A32_USCALED:
2205 case angle::FormatID::R32G32B32A32_UNORM:
2206 case angle::FormatID::R32G32B32A32_SINT:
2207 case angle::FormatID::R32G32B32A32_UINT:
2208 case angle::FormatID::R32G32B32A32_FIXED:
2209 case angle::FormatID::R32G32B32A32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002210 return 16;
2211
Frank Henigmand633b152018-10-04 23:34:31 -04002212 case angle::FormatID::NONE:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002213 default:
2214 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002215#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002216 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002217#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002218 }
2219}
2220
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002221bool ValidES3InternalFormat(GLenum internalFormat)
2222{
2223 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2224 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2225}
2226
Frank Henigman95fb2a12018-05-27 20:17:05 -04002227VertexFormat::VertexFormat(GLenum typeIn,
2228 GLboolean normalizedIn,
2229 GLuint componentsIn,
2230 bool pureIntegerIn)
2231 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002232{
2233 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002234 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2235 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002236}
Markus Tavenrath0d665132018-11-18 15:47:02 +01002237} // namespace gl