blob: 6fd1a9bd8d02fb54bf98fd34803544479f52c84e [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
Frank Henigman95fb2a12018-05-27 20:17:05 -040020// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the
21// implementation can decide the true, sized, internal format. The ES2FormatMap determines the
22// internal format for all valid format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Geoff Langca271392017-04-05 12:30:00 -040027using InternalFormatInfoMap =
28 std::unordered_map<GLenum, std::unordered_map<GLenum, InternalFormat>>;
Jamie Madilla3944d42016-07-22 22:13:26 -040029
Jamie Madillca2ff382018-07-11 09:01:17 -040030bool CheckedMathResult(const CheckedNumeric<GLuint> &value, GLuint *resultOut)
31{
32 if (!value.IsValid())
33 {
34 return false;
35 }
36 else
37 {
38 *resultOut = value.ValueOrDie();
39 return true;
40 }
41}
Markus Tavenrath0d665132018-11-18 15:47:02 +010042
43constexpr GLuint Log2(GLuint bytes)
44{
45 return bytes == 1 ? 0 : (1 + Log2(bytes / 2));
46}
47
48constexpr uint32_t PackTypeInfo(GLuint bytes, bool specialized)
49{
50 // static_assert within constexpr requires c++17
51 // static_assert(isPow2(bytes));
52 return bytes | (Log2(bytes) << 8) | (specialized << 16);
53}
54
Jamie Madilla3944d42016-07-22 22:13:26 -040055} // anonymous namespace
56
Markus Tavenrath0d665132018-11-18 15:47:02 +010057FormatType::FormatType() : format(GL_NONE), type(GL_NONE) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040058
Markus Tavenrath0d665132018-11-18 15:47:02 +010059FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_) {}
Jamie Madilla3944d42016-07-22 22:13:26 -040060
61bool FormatType::operator<(const FormatType &other) const
62{
63 if (format != other.format)
64 return format < other.format;
65 return type < other.type;
66}
67
Frank Henigman95fb2a12018-05-27 20:17:05 -040068bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040069{
70 return memcmp(&a, &b, sizeof(Type)) < 0;
71}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000072
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040074static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075{
Geoff Lang493daf52014-07-03 13:38:44 -040076 return true;
77}
78
Geoff Langeb66a6e2016-10-31 13:06:12 -040079static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000080{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081 return false;
82}
83
Geoff Langeb66a6e2016-10-31 13:06:12 -040084template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
85static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040086{
Geoff Langeb66a6e2016-10-31 13:06:12 -040087 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040088}
89
Geoff Langcec35902014-04-16 10:52:36 -040090// Pointer to a boolean memeber of the Extensions struct
91typedef bool(Extensions::*ExtensionBool);
92
93// Check support for a single extension
94template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040095static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040096{
Geoff Lange4a492b2014-06-19 14:14:41 -040097 return extensions.*bool1;
98}
99
100// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400101template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
102static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400103{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400104 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
105 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400106}
107
108// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400109template <GLuint minCoreGLMajorVersion,
110 GLuint minCoreGLMinorVersion,
111 ExtensionBool bool1,
112 ExtensionBool bool2>
113static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400114{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400115 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
116 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400117}
118
119// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400120template <GLuint minCoreGLMajorVersion,
121 GLuint minCoreGLMinorVersion,
122 ExtensionBool bool1,
123 ExtensionBool bool2>
124static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400125{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400126 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
127 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400128}
129
130// Check support for two extensions
131template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400132static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400133{
Geoff Langabce7622014-09-19 16:13:00 -0400134 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400135}
136
Geoff Lang60ad73d2015-10-23 10:08:44 -0400137// Check support for either of two extensions
138template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400139static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400140{
141 return extensions.*bool1 || extensions.*bool2;
142}
143
Yuly Novikovd0828192018-06-15 15:51:07 -0400144// R8, RG8
145static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500146{
Yuly Novikovd0828192018-06-15 15:51:07 -0400147 return clientVersion >= Version(3, 0) || (extensions.textureStorage && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500148}
149
Yuly Novikovd0828192018-06-15 15:51:07 -0400150// R16F, RG16F with HALF_FLOAT_OES type
151static bool SizedHalfFloatOESRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500152{
Yuly Novikovd0828192018-06-15 15:51:07 -0400153 return extensions.textureStorage && extensions.textureHalfFloat && extensions.textureRG;
Jamie Madillcd089732015-12-17 09:53:09 -0500154}
155
Yuly Novikovd0828192018-06-15 15:51:07 -0400156static bool SizedHalfFloatOESRGTextureAttachmentSupport(const Version &clientVersion,
157 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400158{
Yuly Novikovd0828192018-06-15 15:51:07 -0400159 return SizedHalfFloatOESRGSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400160}
161
Yuly Novikovd0828192018-06-15 15:51:07 -0400162// R16F, RG16F with either HALF_FLOAT_OES or HALF_FLOAT types
163static bool SizedHalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500164{
Yuly Novikovd0828192018-06-15 15:51:07 -0400165 // HALF_FLOAT
166 if (clientVersion >= Version(3, 0))
167 {
168 return true;
169 }
170 // HALF_FLOAT_OES
171 else
172 {
173 return SizedHalfFloatOESRGSupport(clientVersion, extensions);
174 }
Jamie Madillcd089732015-12-17 09:53:09 -0500175}
176
Yuly Novikovd0828192018-06-15 15:51:07 -0400177static bool SizedHalfFloatRGTextureAttachmentSupport(const Version &clientVersion,
178 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500179{
Yuly Novikovd0828192018-06-15 15:51:07 -0400180 // HALF_FLOAT
181 if (clientVersion >= Version(3, 0))
182 {
183 return extensions.colorBufferFloat;
184 }
185 // HALF_FLOAT_OES
186 else
187 {
188 return SizedHalfFloatOESRGTextureAttachmentSupport(clientVersion, extensions);
189 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400190}
191
Yuly Novikovd0828192018-06-15 15:51:07 -0400192static bool SizedHalfFloatRGRenderbufferSupport(const Version &clientVersion,
193 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400194{
Yuly Novikovd0828192018-06-15 15:51:07 -0400195 return (clientVersion >= Version(3, 0) ||
196 (extensions.textureHalfFloat && extensions.textureRG)) &&
197 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400198}
199
Yuly Novikovd0828192018-06-15 15:51:07 -0400200// RGB16F, RGBA16F with HALF_FLOAT_OES type
201static bool SizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400202{
Yuly Novikovd0828192018-06-15 15:51:07 -0400203 return extensions.textureStorage && extensions.textureHalfFloat;
204}
205
206static bool SizedHalfFloatOESTextureAttachmentSupport(const Version &clientVersion,
207 const Extensions &extensions)
208{
209 return SizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
210}
211
212// RGB16F, RGBA16F with either HALF_FLOAT_OES or HALF_FLOAT types
213static bool SizedHalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
214{
215 // HALF_FLOAT
216 if (clientVersion >= Version(3, 0))
217 {
218 return true;
219 }
220 // HALF_FLOAT_OES
221 else
222 {
223 return SizedHalfFloatOESSupport(clientVersion, extensions);
224 }
225}
226
227static bool SizedHalfFloatFilterSupport(const Version &clientVersion, const Extensions &extensions)
228{
229 // HALF_FLOAT
230 if (clientVersion >= Version(3, 0))
231 {
232 return true;
233 }
234 // HALF_FLOAT_OES
235 else
236 {
237 return extensions.textureHalfFloatLinear;
238 }
239}
240
241static bool SizedHalfFloatRGBTextureAttachmentSupport(const Version &clientVersion,
242 const Extensions &extensions)
243{
244 // HALF_FLOAT
245 if (clientVersion >= Version(3, 0))
246 {
247 // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
248 // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
249 // is possible, so assume that all GLES implementations support it.
250 return extensions.colorBufferHalfFloat;
251 }
252 // HALF_FLOAT_OES
253 else
254 {
255 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
256 }
257}
258
259static bool SizedHalfFloatRGBRenderbufferSupport(const Version &clientVersion,
260 const Extensions &extensions)
261{
262 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400263 extensions.colorBufferHalfFloat;
264}
265
Yuly Novikovd0828192018-06-15 15:51:07 -0400266static bool SizedHalfFloatRGBATextureAttachmentSupport(const Version &clientVersion,
267 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400268{
Yuly Novikovd0828192018-06-15 15:51:07 -0400269 // HALF_FLOAT
270 if (clientVersion >= Version(3, 0))
271 {
272 return extensions.colorBufferFloat;
273 }
274 // HALF_FLOAT_OES
275 else
276 {
277 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
278 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400279}
280
Yuly Novikovd0828192018-06-15 15:51:07 -0400281static bool SizedHalfFloatRGBARenderbufferSupport(const Version &clientVersion,
282 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400283{
Yuly Novikovd0828192018-06-15 15:51:07 -0400284 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
285 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500286}
287
Yuly Novikovd0828192018-06-15 15:51:07 -0400288// R32F, RG32F
289static bool SizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500290{
Yuly Novikovd0828192018-06-15 15:51:07 -0400291 return clientVersion >= Version(3, 0) ||
292 (extensions.textureStorage && extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500293}
294
Geoff Lang677bb6f2017-04-05 12:40:40 -0400295// RGB32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400296static bool SizedFloatRGBSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500297{
Yuly Novikovd0828192018-06-15 15:51:07 -0400298 return clientVersion >= Version(3, 0) ||
299 (extensions.textureStorage && extensions.textureFloat) || extensions.colorBufferFloatRGB;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400300}
301
302// RGBA32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400303static bool SizedFloatRGBASupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400304{
Yuly Novikovd0828192018-06-15 15:51:07 -0400305 return clientVersion >= Version(3, 0) ||
306 (extensions.textureStorage && extensions.textureFloat) ||
307 extensions.colorBufferFloatRGBA;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400308}
309
Yuly Novikovd0828192018-06-15 15:51:07 -0400310static bool SizedFloatRGBATextureAttachmentSupport(const Version &clientVersion,
311 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400312{
Yuly Novikovd0828192018-06-15 15:51:07 -0400313 return (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
Jamie Madillcd089732015-12-17 09:53:09 -0500314}
315
Geoff Lang5d601382014-07-22 15:14:06 -0400316InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400317 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400318 sized(false),
319 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400320 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400321 greenBits(0),
322 blueBits(0),
323 luminanceBits(0),
324 alphaBits(0),
325 sharedBits(0),
326 depthBits(0),
327 stencilBits(0),
328 pixelBytes(0),
329 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400330 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400331 compressedBlockWidth(0),
332 compressedBlockHeight(0),
333 format(GL_NONE),
334 type(GL_NONE),
335 componentType(GL_NONE),
336 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400337 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400338 filterSupport(NeverSupported),
339 textureAttachmentSupport(NeverSupported),
340 renderbufferSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000341{
Geoff Lang5d601382014-07-22 15:14:06 -0400342}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000343
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500344InternalFormat::InternalFormat(const InternalFormat &other) = default;
345
Jamie Madilla3944d42016-07-22 22:13:26 -0400346bool InternalFormat::isLUMA() const
347{
348 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
349 (luminanceBits + alphaBits) > 0);
350}
351
Geoff Langf607c602016-09-21 11:46:48 -0400352GLenum InternalFormat::getReadPixelsFormat() const
353{
354 return format;
355}
356
Geoff Langc71ea662017-09-26 17:06:02 -0400357GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400358{
359 switch (type)
360 {
361 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400362 case GL_HALF_FLOAT_OES:
363 if (version < Version(3, 0))
364 {
365 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
366 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
367 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
368 // as an IMPLEMENTATION_READ_TYPE.
369 return GL_HALF_FLOAT_OES;
370 }
371 else
372 {
373 return GL_HALF_FLOAT;
374 }
Geoff Langf607c602016-09-21 11:46:48 -0400375
376 default:
377 return type;
378 }
379}
380
Olli Etuaho50c562d2017-06-06 14:43:30 +0300381bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
382{
383 // GLES 3.0.5 section 4.4.2.2:
384 // "Implementations are required to support the same internal formats for renderbuffers as the
385 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
386 // formats labelled "texture-only"."
387 if (!sized || compressed)
388 {
389 return false;
390 }
391
392 // Luma formats.
393 if (isLUMA())
394 {
395 return false;
396 }
397
398 // Depth/stencil formats.
399 if (depthBits > 0 || stencilBits > 0)
400 {
401 // GLES 2.0.25 table 4.5.
402 // GLES 3.0.5 section 3.8.3.1.
403 // GLES 3.1 table 8.14.
404
405 // Required formats in all versions.
406 switch (internalFormat)
407 {
408 case GL_DEPTH_COMPONENT16:
409 case GL_STENCIL_INDEX8:
410 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
411 // is in section 4.4.2.2.
412 return true;
413 default:
414 break;
415 }
416 if (version.major < 3)
417 {
418 return false;
419 }
420 // Required formats in GLES 3.0 and up.
421 switch (internalFormat)
422 {
423 case GL_DEPTH_COMPONENT32F:
424 case GL_DEPTH_COMPONENT24:
425 case GL_DEPTH32F_STENCIL8:
426 case GL_DEPTH24_STENCIL8:
427 return true;
428 default:
429 return false;
430 }
431 }
432
433 // RGBA formats.
434 // GLES 2.0.25 table 4.5.
435 // GLES 3.0.5 section 3.8.3.1.
436 // GLES 3.1 table 8.13.
437
438 // Required formats in all versions.
439 switch (internalFormat)
440 {
441 case GL_RGBA4:
442 case GL_RGB5_A1:
443 case GL_RGB565:
444 return true;
445 default:
446 break;
447 }
448 if (version.major < 3)
449 {
450 return false;
451 }
452
453 if (format == GL_BGRA_EXT)
454 {
455 return false;
456 }
457
458 switch (componentType)
459 {
460 case GL_SIGNED_NORMALIZED:
461 case GL_FLOAT:
462 return false;
463 case GL_UNSIGNED_INT:
464 case GL_INT:
465 // Integer RGB formats are not required renderbuffer formats.
466 if (alphaBits == 0 && blueBits != 0)
467 {
468 return false;
469 }
470 // All integer R and RG formats are required.
471 // Integer RGBA formats including RGB10_A2_UI are required.
472 return true;
473 case GL_UNSIGNED_NORMALIZED:
474 if (internalFormat == GL_SRGB8)
475 {
476 return false;
477 }
478 return true;
479 default:
480 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500481#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300482 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500483#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300484 }
485}
486
Markus Tavenrath0d665132018-11-18 15:47:02 +0100487Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat)) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400488
Markus Tavenrath0d665132018-11-18 15:47:02 +0100489Format::Format(const InternalFormat &internalFormat) : info(&internalFormat) {}
Jamie Madilla3944d42016-07-22 22:13:26 -0400490
Geoff Langca271392017-04-05 12:30:00 -0400491Format::Format(GLenum internalFormat, GLenum type)
492 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400493{
Jamie Madilla3944d42016-07-22 22:13:26 -0400494}
495
496Format::Format(const Format &other) = default;
497Format &Format::operator=(const Format &other) = default;
498
Jamie Madilla3944d42016-07-22 22:13:26 -0400499bool Format::valid() const
500{
Geoff Langca271392017-04-05 12:30:00 -0400501 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400502}
503
504// static
505bool Format::SameSized(const Format &a, const Format &b)
506{
Geoff Langca271392017-04-05 12:30:00 -0400507 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400508}
509
Kenneth Russell69382852017-07-21 16:38:44 -0400510static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
511{
512 // BlitFramebuffer works if the color channels are identically
513 // sized, even if there is a swizzle (for example, blitting from a
514 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
515 // be expanded and/or autogenerated if that is found necessary.
516 if (internalformat == GL_BGRA8_EXT)
517 return GL_RGBA8;
518 return internalformat;
519}
520
521// static
522bool Format::EquivalentForBlit(const Format &a, const Format &b)
523{
524 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
525 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
526}
527
Jamie Madilla3944d42016-07-22 22:13:26 -0400528// static
529Format Format::Invalid()
530{
Geoff Langca271392017-04-05 12:30:00 -0400531 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400532 return invalid;
533}
534
Yuly Novikovd73f8522017-01-13 17:48:57 -0500535std::ostream &operator<<(std::ostream &os, const Format &fmt)
536{
537 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400538 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500539}
540
Jamie Madilla3944d42016-07-22 22:13:26 -0400541bool InternalFormat::operator==(const InternalFormat &other) const
542{
Geoff Langca271392017-04-05 12:30:00 -0400543 // We assume all internal formats are unique if they have the same internal format and type
544 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400545}
546
547bool InternalFormat::operator!=(const InternalFormat &other) const
548{
Geoff Langca271392017-04-05 12:30:00 -0400549 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400550}
551
Geoff Langca271392017-04-05 12:30:00 -0400552void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400553{
Geoff Langca271392017-04-05 12:30:00 -0400554 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
555 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
556 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400557}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000558
Jamie Madilla3944d42016-07-22 22:13:26 -0400559void AddRGBAFormat(InternalFormatInfoMap *map,
560 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400561 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400562 GLuint red,
563 GLuint green,
564 GLuint blue,
565 GLuint alpha,
566 GLuint shared,
567 GLenum format,
568 GLenum type,
569 GLenum componentType,
570 bool srgb,
571 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400572 InternalFormat::SupportCheckFunction filterSupport,
573 InternalFormat::SupportCheckFunction textureAttachmentSupport,
574 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400575{
576 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400577 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400578 formatInfo.sized = sized;
579 formatInfo.sizedInternalFormat =
580 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400581 formatInfo.redBits = red;
582 formatInfo.greenBits = green;
583 formatInfo.blueBits = blue;
584 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400585 formatInfo.sharedBits = shared;
586 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400587 formatInfo.componentCount =
588 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400589 formatInfo.format = format;
590 formatInfo.type = type;
591 formatInfo.componentType = componentType;
592 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
593 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400594 formatInfo.filterSupport = filterSupport;
595 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
596 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400597
598 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400599}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000600
Geoff Langca271392017-04-05 12:30:00 -0400601static void AddLUMAFormat(InternalFormatInfoMap *map,
602 GLenum internalFormat,
603 bool sized,
604 GLuint luminance,
605 GLuint alpha,
606 GLenum format,
607 GLenum type,
608 GLenum componentType,
609 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400610 InternalFormat::SupportCheckFunction filterSupport,
611 InternalFormat::SupportCheckFunction textureAttachmentSupport,
612 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400613{
614 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400615 formatInfo.internalFormat = internalFormat;
616 formatInfo.sized = sized;
617 formatInfo.sizedInternalFormat =
618 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400619 formatInfo.luminanceBits = luminance;
620 formatInfo.alphaBits = alpha;
621 formatInfo.pixelBytes = (luminance + alpha) / 8;
622 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
623 formatInfo.format = format;
624 formatInfo.type = type;
625 formatInfo.componentType = componentType;
626 formatInfo.colorEncoding = GL_LINEAR;
627 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400628 formatInfo.filterSupport = filterSupport;
629 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
630 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400631
632 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400633}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000634
Jamie Madilla3944d42016-07-22 22:13:26 -0400635void AddDepthStencilFormat(InternalFormatInfoMap *map,
636 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400637 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400638 GLuint depthBits,
639 GLuint stencilBits,
640 GLuint unusedBits,
641 GLenum format,
642 GLenum type,
643 GLenum componentType,
644 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400645 InternalFormat::SupportCheckFunction filterSupport,
646 InternalFormat::SupportCheckFunction textureAttachmentSupport,
647 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400648{
649 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400650 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400651 formatInfo.sized = sized;
652 formatInfo.sizedInternalFormat =
653 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400654 formatInfo.depthBits = depthBits;
655 formatInfo.stencilBits = stencilBits;
656 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
657 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
658 formatInfo.format = format;
659 formatInfo.type = type;
660 formatInfo.componentType = componentType;
661 formatInfo.colorEncoding = GL_LINEAR;
662 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400663 formatInfo.filterSupport = filterSupport;
664 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
665 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400666
667 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400668}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000669
Geoff Langca271392017-04-05 12:30:00 -0400670void AddCompressedFormat(InternalFormatInfoMap *map,
671 GLenum internalFormat,
672 GLuint compressedBlockWidth,
673 GLuint compressedBlockHeight,
674 GLuint compressedBlockSize,
675 GLuint componentCount,
676 GLenum format,
677 GLenum type,
678 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;
692 formatInfo.format = format;
693 formatInfo.type = type;
694 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 );
793 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBATextureAttachmentSupport, RequireExt<&Extensions::colorBufferFloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000794
795 // 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 |
797 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<1, 0>, RequireES<1, 0> );
798 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
799 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
800 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32> );
801 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextures>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>);
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
Geoff Lang836674c2018-11-19 11:45:18 -0500818 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
819 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
820 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACR11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
821 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
822 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedEACRG11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
823 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
824 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
825 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughARGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
826 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, AlwaysSupported, NeverSupported, NeverSupported);
827 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2RGBA8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
828 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireESOrExtOrExt<3, 0, &Extensions::compressedTextureETC, &Extensions::compressedETC2sRGB8Alpha8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000829
830 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400831 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
832 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
833 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000834
835 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400836 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT3>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000837
838 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400839 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400840
841 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400842 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800844 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400845 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
846 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
847 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
848 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
849 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800850
Geoff Lang60ad73d2015-10-23 10:08:44 -0400851 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400852 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
853 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
854 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
855 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
856 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
857 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
858 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
859 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
860 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
861 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
862 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
863 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
864 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
865 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
866 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400867
Yuly Novikovf15f8862018-06-04 18:59:41 -0400868 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
869 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
870 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
871 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
872 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
873 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
874 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
875 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
876 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
877 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
878 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
879 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
880 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
881 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400882
Olli Etuahof2ed2992018-10-04 13:54:42 +0300883 // From EXT_texture_compression_bptc
884 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
885 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
886 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
887 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
888 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
889
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
Yuly Novikovf15f8862018-06-04 18:59:41 -0400898 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
899 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
900 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
901 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
902 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
903 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -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
Yuly Novikovd0828192018-06-15 15:51:07 -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>, NeverSupported, 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>, RequireExtAndExt<&Extensions::textureHalfFloat, &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 Madillba365932018-07-18 17:23:46 -04001354angle::FormatID GetVertexFormatID(GLenum type,
1355 GLboolean normalized,
1356 GLuint components,
1357 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001358{
1359 switch (type)
1360 {
1361 case GL_BYTE:
1362 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 }
1394 case GL_UNSIGNED_BYTE:
1395 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 }
1427 case GL_SHORT:
1428 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 }
1460 case GL_UNSIGNED_SHORT:
1461 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 }
1493 case GL_INT:
1494 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 }
1526 case GL_UNSIGNED_INT:
1527 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 }
1559 case GL_FLOAT:
1560 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 }
1576 case GL_HALF_FLOAT:
1577 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 }
1593 case GL_FIXED:
1594 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 }
1610 case GL_INT_2_10_10_10_REV:
1611 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 Madilld3dfda22015-07-06 08:28:49 -04001616 case GL_UNSIGNED_INT_2_10_10_10_REV:
1617 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 Madillba365932018-07-18 17:23:46 -04001630angle::FormatID GetVertexFormatID(const VertexAttribute &attrib)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001631{
1632 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1633}
1634
Frank Henigmand633b152018-10-04 23:34:31 -04001635angle::FormatID GetVertexFormatID(const VertexAttribute &attrib, GLenum currentValueType)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001636{
1637 if (!attrib.enabled)
1638 {
Frank Henigmand633b152018-10-04 23:34:31 -04001639 return GetVertexFormatID(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
Jamie Madilld3dfda22015-07-06 08:28:49 -04001640 }
Frank Henigmand633b152018-10-04 23:34:31 -04001641 return GetVertexFormatID(attrib);
Jamie Madilld3dfda22015-07-06 08:28:49 -04001642}
1643
Frank Henigmand633b152018-10-04 23:34:31 -04001644const VertexFormat &GetVertexFormatFromID(angle::FormatID vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001645{
Frank Henigmand633b152018-10-04 23:34:31 -04001646 switch (vertexFormatID)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001647 {
Frank Henigmand633b152018-10-04 23:34:31 -04001648 case angle::FormatID::R8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001649 {
1650 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1651 return format;
1652 }
Frank Henigmand633b152018-10-04 23:34:31 -04001653 case angle::FormatID::R8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001654 {
1655 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1656 return format;
1657 }
Frank Henigmand633b152018-10-04 23:34:31 -04001658 case angle::FormatID::R8G8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001659 {
1660 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1661 return format;
1662 }
Frank Henigmand633b152018-10-04 23:34:31 -04001663 case angle::FormatID::R8G8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001664 {
1665 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1666 return format;
1667 }
Frank Henigmand633b152018-10-04 23:34:31 -04001668 case angle::FormatID::R8G8B8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001669 {
1670 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1671 return format;
1672 }
Frank Henigmand633b152018-10-04 23:34:31 -04001673 case angle::FormatID::R8G8B8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001674 {
1675 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1676 return format;
1677 }
Frank Henigmand633b152018-10-04 23:34:31 -04001678 case angle::FormatID::R8G8B8A8_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001679 {
1680 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1681 return format;
1682 }
Frank Henigmand633b152018-10-04 23:34:31 -04001683 case angle::FormatID::R8G8B8A8_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001684 {
1685 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1686 return format;
1687 }
Frank Henigmand633b152018-10-04 23:34:31 -04001688 case angle::FormatID::R8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001689 {
1690 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1691 return format;
1692 }
Frank Henigmand633b152018-10-04 23:34:31 -04001693 case angle::FormatID::R8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001694 {
1695 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1696 return format;
1697 }
Frank Henigmand633b152018-10-04 23:34:31 -04001698 case angle::FormatID::R8G8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001699 {
1700 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1701 return format;
1702 }
Frank Henigmand633b152018-10-04 23:34:31 -04001703 case angle::FormatID::R8G8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001704 {
1705 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1706 return format;
1707 }
Frank Henigmand633b152018-10-04 23:34:31 -04001708 case angle::FormatID::R8G8B8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001709 {
1710 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1711 return format;
1712 }
Frank Henigmand633b152018-10-04 23:34:31 -04001713 case angle::FormatID::R8G8B8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001714 {
1715 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1716 return format;
1717 }
Frank Henigmand633b152018-10-04 23:34:31 -04001718 case angle::FormatID::R8G8B8A8_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001719 {
1720 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1721 return format;
1722 }
Frank Henigmand633b152018-10-04 23:34:31 -04001723 case angle::FormatID::R8G8B8A8_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001724 {
1725 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1726 return format;
1727 }
Frank Henigmand633b152018-10-04 23:34:31 -04001728 case angle::FormatID::R16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001729 {
1730 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1731 return format;
1732 }
Frank Henigmand633b152018-10-04 23:34:31 -04001733 case angle::FormatID::R16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001734 {
1735 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1736 return format;
1737 }
Frank Henigmand633b152018-10-04 23:34:31 -04001738 case angle::FormatID::R16G16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001739 {
1740 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1741 return format;
1742 }
Frank Henigmand633b152018-10-04 23:34:31 -04001743 case angle::FormatID::R16G16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001744 {
1745 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1746 return format;
1747 }
Frank Henigmand633b152018-10-04 23:34:31 -04001748 case angle::FormatID::R16G16B16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001749 {
1750 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1751 return format;
1752 }
Frank Henigmand633b152018-10-04 23:34:31 -04001753 case angle::FormatID::R16G16B16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001754 {
1755 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1756 return format;
1757 }
Frank Henigmand633b152018-10-04 23:34:31 -04001758 case angle::FormatID::R16G16B16A16_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001759 {
1760 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1761 return format;
1762 }
Frank Henigmand633b152018-10-04 23:34:31 -04001763 case angle::FormatID::R16G16B16A16_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001764 {
1765 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1766 return format;
1767 }
Frank Henigmand633b152018-10-04 23:34:31 -04001768 case angle::FormatID::R16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001769 {
1770 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1771 return format;
1772 }
Frank Henigmand633b152018-10-04 23:34:31 -04001773 case angle::FormatID::R16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001774 {
1775 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1776 return format;
1777 }
Frank Henigmand633b152018-10-04 23:34:31 -04001778 case angle::FormatID::R16G16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001779 {
1780 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1781 return format;
1782 }
Frank Henigmand633b152018-10-04 23:34:31 -04001783 case angle::FormatID::R16G16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001784 {
1785 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1786 return format;
1787 }
Frank Henigmand633b152018-10-04 23:34:31 -04001788 case angle::FormatID::R16G16B16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001789 {
1790 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1791 return format;
1792 }
Frank Henigmand633b152018-10-04 23:34:31 -04001793 case angle::FormatID::R16G16B16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001794 {
1795 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1796 return format;
1797 }
Frank Henigmand633b152018-10-04 23:34:31 -04001798 case angle::FormatID::R16G16B16A16_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001799 {
1800 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1801 return format;
1802 }
Frank Henigmand633b152018-10-04 23:34:31 -04001803 case angle::FormatID::R16G16B16A16_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001804 {
1805 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1806 return format;
1807 }
Frank Henigmand633b152018-10-04 23:34:31 -04001808 case angle::FormatID::R32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001809 {
1810 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1811 return format;
1812 }
Frank Henigmand633b152018-10-04 23:34:31 -04001813 case angle::FormatID::R32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001814 {
1815 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1816 return format;
1817 }
Frank Henigmand633b152018-10-04 23:34:31 -04001818 case angle::FormatID::R32G32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001819 {
1820 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1821 return format;
1822 }
Frank Henigmand633b152018-10-04 23:34:31 -04001823 case angle::FormatID::R32G32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001824 {
1825 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1826 return format;
1827 }
Frank Henigmand633b152018-10-04 23:34:31 -04001828 case angle::FormatID::R32G32B32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001829 {
1830 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1831 return format;
1832 }
Frank Henigmand633b152018-10-04 23:34:31 -04001833 case angle::FormatID::R32G32B32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001834 {
1835 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1836 return format;
1837 }
Frank Henigmand633b152018-10-04 23:34:31 -04001838 case angle::FormatID::R32G32B32A32_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001839 {
1840 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1841 return format;
1842 }
Frank Henigmand633b152018-10-04 23:34:31 -04001843 case angle::FormatID::R32G32B32A32_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001844 {
1845 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1846 return format;
1847 }
Frank Henigmand633b152018-10-04 23:34:31 -04001848 case angle::FormatID::R32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001849 {
1850 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1851 return format;
1852 }
Frank Henigmand633b152018-10-04 23:34:31 -04001853 case angle::FormatID::R32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001854 {
1855 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1856 return format;
1857 }
Frank Henigmand633b152018-10-04 23:34:31 -04001858 case angle::FormatID::R32G32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001859 {
1860 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1861 return format;
1862 }
Frank Henigmand633b152018-10-04 23:34:31 -04001863 case angle::FormatID::R32G32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001864 {
1865 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1866 return format;
1867 }
Frank Henigmand633b152018-10-04 23:34:31 -04001868 case angle::FormatID::R32G32B32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001869 {
1870 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1871 return format;
1872 }
Frank Henigmand633b152018-10-04 23:34:31 -04001873 case angle::FormatID::R32G32B32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001874 {
1875 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1876 return format;
1877 }
Frank Henigmand633b152018-10-04 23:34:31 -04001878 case angle::FormatID::R32G32B32A32_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001879 {
1880 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1881 return format;
1882 }
Frank Henigmand633b152018-10-04 23:34:31 -04001883 case angle::FormatID::R32G32B32A32_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001884 {
1885 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1886 return format;
1887 }
Frank Henigmand633b152018-10-04 23:34:31 -04001888 case angle::FormatID::R8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001889 {
1890 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1891 return format;
1892 }
Frank Henigmand633b152018-10-04 23:34:31 -04001893 case angle::FormatID::R8G8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001894 {
1895 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1896 return format;
1897 }
Frank Henigmand633b152018-10-04 23:34:31 -04001898 case angle::FormatID::R8G8B8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001899 {
1900 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1901 return format;
1902 }
Frank Henigmand633b152018-10-04 23:34:31 -04001903 case angle::FormatID::R8G8B8A8_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001904 {
1905 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1906 return format;
1907 }
Frank Henigmand633b152018-10-04 23:34:31 -04001908 case angle::FormatID::R8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001909 {
1910 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1911 return format;
1912 }
Frank Henigmand633b152018-10-04 23:34:31 -04001913 case angle::FormatID::R8G8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001914 {
1915 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1916 return format;
1917 }
Frank Henigmand633b152018-10-04 23:34:31 -04001918 case angle::FormatID::R8G8B8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001919 {
1920 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1921 return format;
1922 }
Frank Henigmand633b152018-10-04 23:34:31 -04001923 case angle::FormatID::R8G8B8A8_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001924 {
1925 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1926 return format;
1927 }
Frank Henigmand633b152018-10-04 23:34:31 -04001928 case angle::FormatID::R16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001929 {
1930 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1931 return format;
1932 }
Frank Henigmand633b152018-10-04 23:34:31 -04001933 case angle::FormatID::R16G16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001934 {
1935 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1936 return format;
1937 }
Frank Henigmand633b152018-10-04 23:34:31 -04001938 case angle::FormatID::R16G16B16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001939 {
1940 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1941 return format;
1942 }
Frank Henigmand633b152018-10-04 23:34:31 -04001943 case angle::FormatID::R16G16B16A16_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001944 {
1945 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1946 return format;
1947 }
Frank Henigmand633b152018-10-04 23:34:31 -04001948 case angle::FormatID::R16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001949 {
1950 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1951 return format;
1952 }
Frank Henigmand633b152018-10-04 23:34:31 -04001953 case angle::FormatID::R16G16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001954 {
1955 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1956 return format;
1957 }
Frank Henigmand633b152018-10-04 23:34:31 -04001958 case angle::FormatID::R16G16B16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001959 {
1960 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1961 return format;
1962 }
Frank Henigmand633b152018-10-04 23:34:31 -04001963 case angle::FormatID::R16G16B16A16_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001964 {
1965 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1966 return format;
1967 }
Frank Henigmand633b152018-10-04 23:34:31 -04001968 case angle::FormatID::R32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001969 {
1970 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1971 return format;
1972 }
Frank Henigmand633b152018-10-04 23:34:31 -04001973 case angle::FormatID::R32G32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001974 {
1975 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1976 return format;
1977 }
Frank Henigmand633b152018-10-04 23:34:31 -04001978 case angle::FormatID::R32G32B32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001979 {
1980 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1981 return format;
1982 }
Frank Henigmand633b152018-10-04 23:34:31 -04001983 case angle::FormatID::R32G32B32A32_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001984 {
1985 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1986 return format;
1987 }
Frank Henigmand633b152018-10-04 23:34:31 -04001988 case angle::FormatID::R32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001989 {
1990 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1991 return format;
1992 }
Frank Henigmand633b152018-10-04 23:34:31 -04001993 case angle::FormatID::R32G32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001994 {
1995 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1996 return format;
1997 }
Frank Henigmand633b152018-10-04 23:34:31 -04001998 case angle::FormatID::R32G32B32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04001999 {
2000 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2001 return format;
2002 }
Frank Henigmand633b152018-10-04 23:34:31 -04002003 case angle::FormatID::R32G32B32A32_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002004 {
2005 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2006 return format;
2007 }
Frank Henigmand633b152018-10-04 23:34:31 -04002008 case angle::FormatID::R32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002009 {
2010 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2011 return format;
2012 }
Frank Henigmand633b152018-10-04 23:34:31 -04002013 case angle::FormatID::R32G32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002014 {
2015 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2016 return format;
2017 }
Frank Henigmand633b152018-10-04 23:34:31 -04002018 case angle::FormatID::R32G32B32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002019 {
2020 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2021 return format;
2022 }
Frank Henigmand633b152018-10-04 23:34:31 -04002023 case angle::FormatID::R32G32B32A32_FIXED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002024 {
2025 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2026 return format;
2027 }
Frank Henigmand633b152018-10-04 23:34:31 -04002028 case angle::FormatID::R16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002029 {
2030 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2031 return format;
2032 }
Frank Henigmand633b152018-10-04 23:34:31 -04002033 case angle::FormatID::R16G16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002034 {
2035 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2036 return format;
2037 }
Frank Henigmand633b152018-10-04 23:34:31 -04002038 case angle::FormatID::R16G16B16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002039 {
2040 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2041 return format;
2042 }
Frank Henigmand633b152018-10-04 23:34:31 -04002043 case angle::FormatID::R16G16B16A16_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002044 {
2045 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2046 return format;
2047 }
Frank Henigmand633b152018-10-04 23:34:31 -04002048 case angle::FormatID::R32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002049 {
2050 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2051 return format;
2052 }
Frank Henigmand633b152018-10-04 23:34:31 -04002053 case angle::FormatID::R32G32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002054 {
2055 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2056 return format;
2057 }
Frank Henigmand633b152018-10-04 23:34:31 -04002058 case angle::FormatID::R32G32B32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002059 {
2060 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2061 return format;
2062 }
Frank Henigmand633b152018-10-04 23:34:31 -04002063 case angle::FormatID::R32G32B32A32_FLOAT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002064 {
2065 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2066 return format;
2067 }
Frank Henigmand633b152018-10-04 23:34:31 -04002068 case angle::FormatID::R10G10B10A2_SSCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002069 {
2070 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2071 return format;
2072 }
Frank Henigmand633b152018-10-04 23:34:31 -04002073 case angle::FormatID::R10G10B10A2_USCALED:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002074 {
2075 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2076 return format;
2077 }
Frank Henigmand633b152018-10-04 23:34:31 -04002078 case angle::FormatID::R10G10B10A2_SNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002079 {
2080 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2081 return format;
2082 }
Frank Henigmand633b152018-10-04 23:34:31 -04002083 case angle::FormatID::R10G10B10A2_UNORM:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002084 {
2085 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2086 return format;
2087 }
Frank Henigmand633b152018-10-04 23:34:31 -04002088 case angle::FormatID::R10G10B10A2_SINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002089 {
2090 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2091 return format;
2092 }
Frank Henigmand633b152018-10-04 23:34:31 -04002093 case angle::FormatID::R10G10B10A2_UINT:
Jamie Madilld3dfda22015-07-06 08:28:49 -04002094 {
2095 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2096 return format;
2097 }
2098 default:
2099 {
2100 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2101 return format;
2102 }
2103 }
2104}
2105
Frank Henigmand633b152018-10-04 23:34:31 -04002106size_t GetVertexFormatSize(angle::FormatID vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002107{
Frank Henigmand633b152018-10-04 23:34:31 -04002108 switch (vertexFormatID)
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002109 {
Frank Henigmand633b152018-10-04 23:34:31 -04002110 case angle::FormatID::R8_SSCALED:
2111 case angle::FormatID::R8_SNORM:
2112 case angle::FormatID::R8_USCALED:
2113 case angle::FormatID::R8_UNORM:
2114 case angle::FormatID::R8_SINT:
2115 case angle::FormatID::R8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002116 return 1;
2117
Frank Henigmand633b152018-10-04 23:34:31 -04002118 case angle::FormatID::R8G8_SSCALED:
2119 case angle::FormatID::R8G8_SNORM:
2120 case angle::FormatID::R8G8_USCALED:
2121 case angle::FormatID::R8G8_UNORM:
2122 case angle::FormatID::R8G8_SINT:
2123 case angle::FormatID::R8G8_UINT:
2124 case angle::FormatID::R16_SSCALED:
2125 case angle::FormatID::R16_SNORM:
2126 case angle::FormatID::R16_USCALED:
2127 case angle::FormatID::R16_UNORM:
2128 case angle::FormatID::R16_SINT:
2129 case angle::FormatID::R16_UINT:
2130 case angle::FormatID::R16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002131 return 2;
2132
Frank Henigmand633b152018-10-04 23:34:31 -04002133 case angle::FormatID::R8G8B8_SSCALED:
2134 case angle::FormatID::R8G8B8_SNORM:
2135 case angle::FormatID::R8G8B8_USCALED:
2136 case angle::FormatID::R8G8B8_UNORM:
2137 case angle::FormatID::R8G8B8_SINT:
2138 case angle::FormatID::R8G8B8_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002139 return 3;
2140
Frank Henigmand633b152018-10-04 23:34:31 -04002141 case angle::FormatID::R8G8B8A8_SSCALED:
2142 case angle::FormatID::R8G8B8A8_SNORM:
2143 case angle::FormatID::R8G8B8A8_USCALED:
2144 case angle::FormatID::R8G8B8A8_UNORM:
2145 case angle::FormatID::R8G8B8A8_SINT:
2146 case angle::FormatID::R8G8B8A8_UINT:
2147 case angle::FormatID::R16G16_SSCALED:
2148 case angle::FormatID::R16G16_SNORM:
2149 case angle::FormatID::R16G16_USCALED:
2150 case angle::FormatID::R16G16_UNORM:
2151 case angle::FormatID::R16G16_SINT:
2152 case angle::FormatID::R16G16_UINT:
2153 case angle::FormatID::R32_SSCALED:
2154 case angle::FormatID::R32_SNORM:
2155 case angle::FormatID::R32_USCALED:
2156 case angle::FormatID::R32_UNORM:
2157 case angle::FormatID::R32_SINT:
2158 case angle::FormatID::R32_UINT:
2159 case angle::FormatID::R16G16_FLOAT:
2160 case angle::FormatID::R32_FIXED:
2161 case angle::FormatID::R32_FLOAT:
2162 case angle::FormatID::R10G10B10A2_SSCALED:
2163 case angle::FormatID::R10G10B10A2_USCALED:
2164 case angle::FormatID::R10G10B10A2_SNORM:
2165 case angle::FormatID::R10G10B10A2_UNORM:
2166 case angle::FormatID::R10G10B10A2_SINT:
2167 case angle::FormatID::R10G10B10A2_UINT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002168 return 4;
2169
Frank Henigmand633b152018-10-04 23:34:31 -04002170 case angle::FormatID::R16G16B16_SSCALED:
2171 case angle::FormatID::R16G16B16_SNORM:
2172 case angle::FormatID::R16G16B16_USCALED:
2173 case angle::FormatID::R16G16B16_UNORM:
2174 case angle::FormatID::R16G16B16_SINT:
2175 case angle::FormatID::R16G16B16_UINT:
2176 case angle::FormatID::R16G16B16_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002177 return 6;
2178
Frank Henigmand633b152018-10-04 23:34:31 -04002179 case angle::FormatID::R16G16B16A16_SSCALED:
2180 case angle::FormatID::R16G16B16A16_SNORM:
2181 case angle::FormatID::R16G16B16A16_USCALED:
2182 case angle::FormatID::R16G16B16A16_UNORM:
2183 case angle::FormatID::R16G16B16A16_SINT:
2184 case angle::FormatID::R16G16B16A16_UINT:
2185 case angle::FormatID::R32G32_SSCALED:
2186 case angle::FormatID::R32G32_SNORM:
2187 case angle::FormatID::R32G32_USCALED:
2188 case angle::FormatID::R32G32_UNORM:
2189 case angle::FormatID::R32G32_SINT:
2190 case angle::FormatID::R32G32_UINT:
2191 case angle::FormatID::R16G16B16A16_FLOAT:
2192 case angle::FormatID::R32G32_FIXED:
2193 case angle::FormatID::R32G32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002194 return 8;
2195
Frank Henigmand633b152018-10-04 23:34:31 -04002196 case angle::FormatID::R32G32B32_SSCALED:
2197 case angle::FormatID::R32G32B32_SNORM:
2198 case angle::FormatID::R32G32B32_USCALED:
2199 case angle::FormatID::R32G32B32_UNORM:
2200 case angle::FormatID::R32G32B32_SINT:
2201 case angle::FormatID::R32G32B32_UINT:
2202 case angle::FormatID::R32G32B32_FIXED:
2203 case angle::FormatID::R32G32B32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002204 return 12;
2205
Frank Henigmand633b152018-10-04 23:34:31 -04002206 case angle::FormatID::R32G32B32A32_SSCALED:
2207 case angle::FormatID::R32G32B32A32_SNORM:
2208 case angle::FormatID::R32G32B32A32_USCALED:
2209 case angle::FormatID::R32G32B32A32_UNORM:
2210 case angle::FormatID::R32G32B32A32_SINT:
2211 case angle::FormatID::R32G32B32A32_UINT:
2212 case angle::FormatID::R32G32B32A32_FIXED:
2213 case angle::FormatID::R32G32B32A32_FLOAT:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002214 return 16;
2215
Frank Henigmand633b152018-10-04 23:34:31 -04002216 case angle::FormatID::NONE:
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002217 default:
2218 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002219#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002220 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002221#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002222 }
2223}
2224
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002225bool ValidES3InternalFormat(GLenum internalFormat)
2226{
2227 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2228 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2229}
2230
Frank Henigman95fb2a12018-05-27 20:17:05 -04002231VertexFormat::VertexFormat(GLenum typeIn,
2232 GLboolean normalizedIn,
2233 GLuint componentsIn,
2234 bool pureIntegerIn)
2235 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002236{
2237 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002238 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2239 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002240}
Markus Tavenrath0d665132018-11-18 15:47:02 +01002241} // namespace gl