blob: 3fef699d31ef19f52f02a3e0e852136378790d21 [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}
Jamie Madilla3944d42016-07-22 22:13:26 -040042} // anonymous namespace
43
44FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
45{
46}
47
48FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
49{
50}
51
52bool FormatType::operator<(const FormatType &other) const
53{
54 if (format != other.format)
55 return format < other.format;
56 return type < other.type;
57}
58
Frank Henigman95fb2a12018-05-27 20:17:05 -040059Type::Type() : bytes(0), bytesShift(0), specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040060{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000061}
62
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020063static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000064{
Geoff Lang5d601382014-07-22 15:14:06 -040065 Type info;
66 info.bytes = bytes;
Frank Henigman95fb2a12018-05-27 20:17:05 -040067 GLuint i = 0;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020068 while ((1u << i) < bytes)
69 {
70 ++i;
71 }
72 info.bytesShift = i;
73 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040074 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020075 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040076}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000077
Frank Henigman95fb2a12018-05-27 20:17:05 -040078bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040079{
80 return memcmp(&a, &b, sizeof(Type)) < 0;
81}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000083// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040084static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000085{
Geoff Lang493daf52014-07-03 13:38:44 -040086 return true;
87}
88
Geoff Langeb66a6e2016-10-31 13:06:12 -040089static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000090{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000091 return false;
92}
93
Geoff Langeb66a6e2016-10-31 13:06:12 -040094template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
95static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040096{
Geoff Langeb66a6e2016-10-31 13:06:12 -040097 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040098}
99
Geoff Langcec35902014-04-16 10:52:36 -0400100// Pointer to a boolean memeber of the Extensions struct
101typedef bool(Extensions::*ExtensionBool);
102
103// Check support for a single extension
104template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400106{
Geoff Lange4a492b2014-06-19 14:14:41 -0400107 return extensions.*bool1;
108}
109
110// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400111template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
112static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400113{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400114 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
115 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400116}
117
118// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400119template <GLuint minCoreGLMajorVersion,
120 GLuint minCoreGLMinorVersion,
121 ExtensionBool bool1,
122 ExtensionBool bool2>
123static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400124{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400125 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
126 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400127}
128
129// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400130template <GLuint minCoreGLMajorVersion,
131 GLuint minCoreGLMinorVersion,
132 ExtensionBool bool1,
133 ExtensionBool bool2>
134static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400135{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400136 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
137 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400138}
139
140// Check support for two extensions
141template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400142static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400143{
Geoff Langabce7622014-09-19 16:13:00 -0400144 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400145}
146
Geoff Lang60ad73d2015-10-23 10:08:44 -0400147// Check support for either of two extensions
148template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400149static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400150{
151 return extensions.*bool1 || extensions.*bool2;
152}
153
Jamie Madillcd089732015-12-17 09:53:09 -0500154// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400155static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500156{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400157 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500158}
159
Geoff Lang677bb6f2017-04-05 12:40:40 -0400160static bool HalfFloatRGBRenderableSupport(const Version &clientVersion,
161 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500162{
163 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
164}
165
Geoff Lang677bb6f2017-04-05 12:40:40 -0400166static bool HalfFloatRGBARenderableSupport(const Version &clientVersion,
167 const Extensions &extensions)
168{
169 return HalfFloatSupport(clientVersion, extensions) &&
170 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
171}
172
Jamie Madillcd089732015-12-17 09:53:09 -0500173// Special function for half float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400174
175// R16F, RG16F
176static bool HalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500177{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400178 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500179}
180
Geoff Lang677bb6f2017-04-05 12:40:40 -0400181// R16F, RG16F
182static bool HalfFloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500183{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400184 // It's unclear if EXT_color_buffer_half_float gives renderability to non-OES half float
185 // textures
186 return HalfFloatRGSupport(clientVersion, extensions) &&
187 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
188}
189
190// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
191static bool UnsizedHalfFloatOESRGSupport(const Version &, const Extensions &extensions)
192{
193 return extensions.textureHalfFloat && extensions.textureRG;
194}
195
196// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
197static bool UnsizedHalfFloatOESRGRenderableSupport(const Version &clientVersion,
198 const Extensions &extensions)
199{
200 return UnsizedHalfFloatOESRGSupport(clientVersion, extensions) &&
201 extensions.colorBufferHalfFloat;
202}
203
204// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
205static bool UnsizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
206{
207 return extensions.textureHalfFloat;
208}
209
210// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
211static bool UnsizedHalfFloatOESRenderableSupport(const Version &clientVersion,
212 const Extensions &extensions)
213{
214 return UnsizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500215}
216
217// Special function for float formats with three or four channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400218
219// RGB32F, RGBA32F
Geoff Langeb66a6e2016-10-31 13:06:12 -0400220static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500221{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400222 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500223}
224
Geoff Lang677bb6f2017-04-05 12:40:40 -0400225// RGB32F
226static bool FloatRGBRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500227{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400228 return FloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
229}
230
231// RGBA32F
232static bool FloatRGBARenderableSupport(const Version &clientVersion, const Extensions &extensions)
233{
Jamie Madillcd089732015-12-17 09:53:09 -0500234 return FloatSupport(clientVersion, extensions) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400235 (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
236}
237
238// RGB + FLOAT, RGBA + FLOAT
239static bool UnsizedFloatSupport(const Version &clientVersion, const Extensions &extensions)
240{
241 return extensions.textureFloat;
242}
243
244// RGB + FLOAT
245static bool UnsizedFloatRGBRenderableSupport(const Version &clientVersion,
246 const Extensions &extensions)
247{
248 return UnsizedFloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
249}
250
251// RGBA + FLOAT
252static bool UnsizedFloatRGBARenderableSupport(const Version &clientVersion,
253 const Extensions &extensions)
254{
255 return UnsizedFloatSupport(clientVersion, extensions) &&
256 (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500257}
258
259// Special function for float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400260
261// R32F, RG32F
262static bool FloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500263{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400264 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500265}
266
Geoff Lang677bb6f2017-04-05 12:40:40 -0400267// R32F, RG32F
268static bool FloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500269{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400270 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
271}
272
273// RED + FLOAT, RG + FLOAT
274static bool UnsizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
275{
276 return extensions.textureFloat && extensions.textureRG;
277}
278
279// RED + FLOAT, RG + FLOAT
280static bool UnsizedFloatRGRenderableSupport(const Version &clientVersion,
281 const Extensions &extensions)
282{
283 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500284}
285
Geoff Lang5d601382014-07-22 15:14:06 -0400286InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400287 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400288 sized(false),
289 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400290 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400291 greenBits(0),
292 blueBits(0),
293 luminanceBits(0),
294 alphaBits(0),
295 sharedBits(0),
296 depthBits(0),
297 stencilBits(0),
298 pixelBytes(0),
299 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400300 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400301 compressedBlockWidth(0),
302 compressedBlockHeight(0),
303 format(GL_NONE),
304 type(GL_NONE),
305 componentType(GL_NONE),
306 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400307 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400308 filterSupport(NeverSupported),
309 textureAttachmentSupport(NeverSupported),
310 renderbufferSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000311{
Geoff Lang5d601382014-07-22 15:14:06 -0400312}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000313
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500314InternalFormat::InternalFormat(const InternalFormat &other) = default;
315
Jamie Madilla3944d42016-07-22 22:13:26 -0400316bool InternalFormat::isLUMA() const
317{
318 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
319 (luminanceBits + alphaBits) > 0);
320}
321
Geoff Langf607c602016-09-21 11:46:48 -0400322GLenum InternalFormat::getReadPixelsFormat() const
323{
324 return format;
325}
326
Geoff Langc71ea662017-09-26 17:06:02 -0400327GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400328{
329 switch (type)
330 {
331 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400332 case GL_HALF_FLOAT_OES:
333 if (version < Version(3, 0))
334 {
335 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
336 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
337 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
338 // as an IMPLEMENTATION_READ_TYPE.
339 return GL_HALF_FLOAT_OES;
340 }
341 else
342 {
343 return GL_HALF_FLOAT;
344 }
Geoff Langf607c602016-09-21 11:46:48 -0400345
346 default:
347 return type;
348 }
349}
350
Olli Etuaho50c562d2017-06-06 14:43:30 +0300351bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
352{
353 // GLES 3.0.5 section 4.4.2.2:
354 // "Implementations are required to support the same internal formats for renderbuffers as the
355 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
356 // formats labelled "texture-only"."
357 if (!sized || compressed)
358 {
359 return false;
360 }
361
362 // Luma formats.
363 if (isLUMA())
364 {
365 return false;
366 }
367
368 // Depth/stencil formats.
369 if (depthBits > 0 || stencilBits > 0)
370 {
371 // GLES 2.0.25 table 4.5.
372 // GLES 3.0.5 section 3.8.3.1.
373 // GLES 3.1 table 8.14.
374
375 // Required formats in all versions.
376 switch (internalFormat)
377 {
378 case GL_DEPTH_COMPONENT16:
379 case GL_STENCIL_INDEX8:
380 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
381 // is in section 4.4.2.2.
382 return true;
383 default:
384 break;
385 }
386 if (version.major < 3)
387 {
388 return false;
389 }
390 // Required formats in GLES 3.0 and up.
391 switch (internalFormat)
392 {
393 case GL_DEPTH_COMPONENT32F:
394 case GL_DEPTH_COMPONENT24:
395 case GL_DEPTH32F_STENCIL8:
396 case GL_DEPTH24_STENCIL8:
397 return true;
398 default:
399 return false;
400 }
401 }
402
403 // RGBA formats.
404 // GLES 2.0.25 table 4.5.
405 // GLES 3.0.5 section 3.8.3.1.
406 // GLES 3.1 table 8.13.
407
408 // Required formats in all versions.
409 switch (internalFormat)
410 {
411 case GL_RGBA4:
412 case GL_RGB5_A1:
413 case GL_RGB565:
414 return true;
415 default:
416 break;
417 }
418 if (version.major < 3)
419 {
420 return false;
421 }
422
423 if (format == GL_BGRA_EXT)
424 {
425 return false;
426 }
427
428 switch (componentType)
429 {
430 case GL_SIGNED_NORMALIZED:
431 case GL_FLOAT:
432 return false;
433 case GL_UNSIGNED_INT:
434 case GL_INT:
435 // Integer RGB formats are not required renderbuffer formats.
436 if (alphaBits == 0 && blueBits != 0)
437 {
438 return false;
439 }
440 // All integer R and RG formats are required.
441 // Integer RGBA formats including RGB10_A2_UI are required.
442 return true;
443 case GL_UNSIGNED_NORMALIZED:
444 if (internalFormat == GL_SRGB8)
445 {
446 return false;
447 }
448 return true;
449 default:
450 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500451#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300452 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500453#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300454 }
455}
456
Geoff Langca271392017-04-05 12:30:00 -0400457Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400458{
459}
460
Geoff Langca271392017-04-05 12:30:00 -0400461Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400462{
Jamie Madilla3944d42016-07-22 22:13:26 -0400463}
464
Geoff Langca271392017-04-05 12:30:00 -0400465Format::Format(GLenum internalFormat, GLenum type)
466 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400467{
Jamie Madilla3944d42016-07-22 22:13:26 -0400468}
469
470Format::Format(const Format &other) = default;
471Format &Format::operator=(const Format &other) = default;
472
Jamie Madilla3944d42016-07-22 22:13:26 -0400473bool Format::valid() const
474{
Geoff Langca271392017-04-05 12:30:00 -0400475 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400476}
477
478// static
479bool Format::SameSized(const Format &a, const Format &b)
480{
Geoff Langca271392017-04-05 12:30:00 -0400481 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400482}
483
Kenneth Russell69382852017-07-21 16:38:44 -0400484static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
485{
486 // BlitFramebuffer works if the color channels are identically
487 // sized, even if there is a swizzle (for example, blitting from a
488 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
489 // be expanded and/or autogenerated if that is found necessary.
490 if (internalformat == GL_BGRA8_EXT)
491 return GL_RGBA8;
492 return internalformat;
493}
494
495// static
496bool Format::EquivalentForBlit(const Format &a, const Format &b)
497{
498 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
499 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
500}
501
Jamie Madilla3944d42016-07-22 22:13:26 -0400502// static
503Format Format::Invalid()
504{
Geoff Langca271392017-04-05 12:30:00 -0400505 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400506 return invalid;
507}
508
Yuly Novikovd73f8522017-01-13 17:48:57 -0500509std::ostream &operator<<(std::ostream &os, const Format &fmt)
510{
511 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400512 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500513}
514
Jamie Madilla3944d42016-07-22 22:13:26 -0400515bool InternalFormat::operator==(const InternalFormat &other) const
516{
Geoff Langca271392017-04-05 12:30:00 -0400517 // We assume all internal formats are unique if they have the same internal format and type
518 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400519}
520
521bool InternalFormat::operator!=(const InternalFormat &other) const
522{
Geoff Langca271392017-04-05 12:30:00 -0400523 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400524}
525
Geoff Langca271392017-04-05 12:30:00 -0400526void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400527{
Geoff Langca271392017-04-05 12:30:00 -0400528 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
529 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
530 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400531}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000532
Jamie Madilla3944d42016-07-22 22:13:26 -0400533void AddRGBAFormat(InternalFormatInfoMap *map,
534 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400535 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400536 GLuint red,
537 GLuint green,
538 GLuint blue,
539 GLuint alpha,
540 GLuint shared,
541 GLenum format,
542 GLenum type,
543 GLenum componentType,
544 bool srgb,
545 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400546 InternalFormat::SupportCheckFunction filterSupport,
547 InternalFormat::SupportCheckFunction textureAttachmentSupport,
548 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400549{
550 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400551 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400552 formatInfo.sized = sized;
553 formatInfo.sizedInternalFormat =
554 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400555 formatInfo.redBits = red;
556 formatInfo.greenBits = green;
557 formatInfo.blueBits = blue;
558 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400559 formatInfo.sharedBits = shared;
560 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400561 formatInfo.componentCount =
562 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400563 formatInfo.format = format;
564 formatInfo.type = type;
565 formatInfo.componentType = componentType;
566 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
567 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400568 formatInfo.filterSupport = filterSupport;
569 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
570 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400571
572 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400573}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000574
Geoff Langca271392017-04-05 12:30:00 -0400575static void AddLUMAFormat(InternalFormatInfoMap *map,
576 GLenum internalFormat,
577 bool sized,
578 GLuint luminance,
579 GLuint alpha,
580 GLenum format,
581 GLenum type,
582 GLenum componentType,
583 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400584 InternalFormat::SupportCheckFunction filterSupport,
585 InternalFormat::SupportCheckFunction textureAttachmentSupport,
586 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400587{
588 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400589 formatInfo.internalFormat = internalFormat;
590 formatInfo.sized = sized;
591 formatInfo.sizedInternalFormat =
592 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400593 formatInfo.luminanceBits = luminance;
594 formatInfo.alphaBits = alpha;
595 formatInfo.pixelBytes = (luminance + alpha) / 8;
596 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
597 formatInfo.format = format;
598 formatInfo.type = type;
599 formatInfo.componentType = componentType;
600 formatInfo.colorEncoding = GL_LINEAR;
601 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400602 formatInfo.filterSupport = filterSupport;
603 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
604 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400605
606 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400607}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000608
Jamie Madilla3944d42016-07-22 22:13:26 -0400609void AddDepthStencilFormat(InternalFormatInfoMap *map,
610 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400611 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400612 GLuint depthBits,
613 GLuint stencilBits,
614 GLuint unusedBits,
615 GLenum format,
616 GLenum type,
617 GLenum componentType,
618 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400619 InternalFormat::SupportCheckFunction filterSupport,
620 InternalFormat::SupportCheckFunction textureAttachmentSupport,
621 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400622{
623 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400624 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400625 formatInfo.sized = sized;
626 formatInfo.sizedInternalFormat =
627 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400628 formatInfo.depthBits = depthBits;
629 formatInfo.stencilBits = stencilBits;
630 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
631 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
632 formatInfo.format = format;
633 formatInfo.type = type;
634 formatInfo.componentType = componentType;
635 formatInfo.colorEncoding = GL_LINEAR;
636 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400637 formatInfo.filterSupport = filterSupport;
638 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
639 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400640
641 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400642}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000643
Geoff Langca271392017-04-05 12:30:00 -0400644void AddCompressedFormat(InternalFormatInfoMap *map,
645 GLenum internalFormat,
646 GLuint compressedBlockWidth,
647 GLuint compressedBlockHeight,
648 GLuint compressedBlockSize,
649 GLuint componentCount,
650 GLenum format,
651 GLenum type,
652 bool srgb,
653 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400654 InternalFormat::SupportCheckFunction filterSupport,
655 InternalFormat::SupportCheckFunction textureAttachmentSupport,
656 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400657{
658 InternalFormat formatInfo;
Geoff Langcb8a9212018-06-28 12:30:36 -0400659 formatInfo.internalFormat = internalFormat;
660 formatInfo.sized = true;
661 formatInfo.sizedInternalFormat = internalFormat;
662 formatInfo.compressedBlockWidth = compressedBlockWidth;
663 formatInfo.compressedBlockHeight = compressedBlockHeight;
664 formatInfo.pixelBytes = compressedBlockSize / 8;
665 formatInfo.componentCount = componentCount;
666 formatInfo.format = format;
667 formatInfo.type = type;
668 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
669 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
670 formatInfo.compressed = true;
671 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400672 formatInfo.filterSupport = filterSupport;
673 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
674 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400675
676 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400677}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000678
Geoff Lange4a492b2014-06-19 14:14:41 -0400679static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000680{
681 InternalFormatInfoMap map;
682
683 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400684 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000685
Jamie Madilla3944d42016-07-22 22:13:26 -0400686 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000687
Yuly Novikovf15f8862018-06-04 18:59:41 -0400688 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
689 AddRGBAFormat(&map, GL_R8, true, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG> );
690 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 );
691 AddRGBAFormat(&map, GL_RG8, true, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG> );
692 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 );
693 AddRGBAFormat(&map, GL_RGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
694 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 );
695 AddRGBAFormat(&map, GL_RGB565, true, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
696 AddRGBAFormat(&map, GL_RGBA4, true, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
697 AddRGBAFormat(&map, GL_RGB5_A1, true, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
698 AddRGBAFormat(&map, GL_RGBA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
699 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 );
700 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> );
701 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> );
702 AddRGBAFormat(&map, GL_SRGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported, NeverSupported, NeverSupported );
703 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::sRGB>, RequireESOrExt<3, 0, &Extensions::sRGB> );
704 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 );
705 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> );
706 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> );
707 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> );
708 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> );
709 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> );
710 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> );
711 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> );
712 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> );
713 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> );
714 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> );
715 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> );
716 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> );
717 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> );
718 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
719 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 );
720 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
721 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 );
722 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
723 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 );
724 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> );
725 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> );
726 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> );
727 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> );
728 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> );
729 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 -0400730
Yuly Novikovf15f8862018-06-04 18:59:41 -0400731 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>);
732 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>);
733 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 +0000734
Olli Etuahoceffd202018-01-08 16:39:45 +0200735 // Special format that is used for D3D textures that are used within ANGLE via the
736 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
737 // this format, but textures in this format can be created from D3D textures, and filtering them
738 // and rendering to them is allowed.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400739 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 +0200740
Jamie Madillec0b5802016-07-04 13:11:59 -0400741 // Special format which is not really supported, so always false for all supports.
Geoff Langcb8a9212018-06-28 12:30:36 -0400742 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 );
Yuly Novikovf15f8862018-06-04 18:59:41 -0400743 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 -0400744
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000745 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Yuly Novikovf15f8862018-06-04 18:59:41 -0400746 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
747 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, HalfFloatRGRenderableSupport, HalfFloatRGRenderableSupport );
748 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, HalfFloatRGRenderableSupport, HalfFloatRGRenderableSupport );
749 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, HalfFloatRGBRenderableSupport, HalfFloatRGBRenderableSupport );
750 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, HalfFloatRGBARenderableSupport, HalfFloatRGBARenderableSupport);
751 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
752 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
753 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGBRenderableSupport, FloatRGBRenderableSupport );
754 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGBARenderableSupport, FloatRGBARenderableSupport );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000755
756 // Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400757 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
758 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> );
759 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> );
760 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> );
761 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> );
762 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>);
763 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 -0800764 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000765
766 // Luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400767 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
768 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
769 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
770 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
771 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
772 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
773 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
774 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
775 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
776 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 +0000777
778 // Compressed formats, From ES 3.0.1 spec, table 3.16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400779 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
780 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
781 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
782 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
783 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
784 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
785 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
786 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughARGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
787 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, AlwaysSupported, NeverSupported, NeverSupported);
788 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGBA8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
789 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Alpha8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000790
791 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400792 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
793 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
794 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 +0000795
796 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400797 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 +0000798
799 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400800 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 -0400801
802 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400803 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 +0000804
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800805 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400806 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
807 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
808 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);
809 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);
810 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 -0800811
Geoff Lang60ad73d2015-10-23 10:08:44 -0400812 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400813 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
814 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);
815 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);
816 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);
817 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);
818 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);
819 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);
820 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);
821 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);
822 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);
823 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);
824 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);
825 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);
826 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);
827 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 -0400828
Yuly Novikovf15f8862018-06-04 18:59:41 -0400829 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);
830 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);
831 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);
832 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);
833 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);
834 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);
835 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);
836 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);
837 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);
838 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);
839 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);
840 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);
841 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);
842 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 -0400843
Corentin Walleze0902642014-11-04 12:32:15 -0800844 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
845 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
846 // - All other stencil formats (all depth-stencil) are either float or normalized
847 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400848 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
849 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 -0800850
851 // From GL_ANGLE_lossy_etc_decode
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_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
854 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);
855 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);
856 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);
857 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 -0800858
Vincent Lang25ab4512016-05-13 18:13:59 +0200859 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400860 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
861 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>);
862 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 );
863 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>);
864 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 );
865 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 );
866 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 );
867 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>);
868 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 +0200869
Geoff Langca271392017-04-05 12:30:00 -0400870 // Unsized formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400871 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
872 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported, AlwaysSupported );
873 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
874 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported, AlwaysSupported );
875 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
876 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, AlwaysSupported, AlwaysSupported );
877 AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
878 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
879 AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
880 AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
881 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
882 AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
883 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
884 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 );
885 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>, RequireExt<&Extensions::sRGB> );
886 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>, RequireExt<&Extensions::textureFormatBGRA8888>);
Geoff Langca271392017-04-05 12:30:00 -0400887
888 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400889 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
890 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);
891 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);
892 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);
893 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);
894 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);
895 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);
896 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);
897 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);
898 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);
899 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);
900 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);
901 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);
902 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);
903 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);
904 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);
905 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);
906 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);
907 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);
908 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);
909 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);
910 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);
911 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);
912 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);
913 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);
914 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 -0400915
916 // Unsized floating point formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400917 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
918 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
919 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
920 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
921 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
922 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, UnsizedHalfFloatOESRGRenderableSupport, UnsizedHalfFloatOESRGRenderableSupport);
923 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, UnsizedHalfFloatOESRGRenderableSupport, UnsizedHalfFloatOESRGRenderableSupport);
924 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, UnsizedHalfFloatOESRenderableSupport, UnsizedHalfFloatOESRenderableSupport );
925 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>, UnsizedHalfFloatOESRenderableSupport, UnsizedHalfFloatOESRenderableSupport );
926 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
927 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
928 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGBRenderableSupport, UnsizedFloatRGBRenderableSupport );
929 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 );
930 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 );
931 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGBARenderableSupport, UnsizedFloatRGBARenderableSupport );
Geoff Langca271392017-04-05 12:30:00 -0400932
933 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400934 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
935 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
936 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
937 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
938 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
939 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
940 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);
941 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
942 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
943 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 -0400944
945 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400946 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
947 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> );
948 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> );
949 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> );
950 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>);
951 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>);
952 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 -0400953 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800954
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000955 return map;
956}
957
Geoff Lange4a492b2014-06-19 14:14:41 -0400958static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000959{
Geoff Lange4a492b2014-06-19 14:14:41 -0400960 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
961 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000962}
963
Geoff Lange4a492b2014-06-19 14:14:41 -0400964static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400965{
966 FormatSet result;
967
Geoff Langca271392017-04-05 12:30:00 -0400968 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400969 {
Geoff Langca271392017-04-05 12:30:00 -0400970 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400971 {
Geoff Langca271392017-04-05 12:30:00 -0400972 if (type.second.sized)
973 {
974 // TODO(jmadill): Fix this hack.
975 if (internalFormat.first == GL_BGR565_ANGLEX)
976 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400977
Geoff Langca271392017-04-05 12:30:00 -0400978 result.insert(internalFormat.first);
979 }
Geoff Langcec35902014-04-16 10:52:36 -0400980 }
981 }
982
983 return result;
984}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000985
Geoff Lang5d601382014-07-22 15:14:06 -0400986const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000987{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200988 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000989 {
Frank Henigman95fb2a12018-05-27 20:17:05 -0400990 case GL_UNSIGNED_BYTE:
991 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200992 {
993 static const Type info = GenTypeInfo(1, false);
994 return info;
995 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400996 case GL_UNSIGNED_SHORT:
997 case GL_SHORT:
998 case GL_HALF_FLOAT:
999 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001000 {
1001 static const Type info = GenTypeInfo(2, false);
1002 return info;
1003 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001004 case GL_UNSIGNED_INT:
1005 case GL_INT:
1006 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001007 {
1008 static const Type info = GenTypeInfo(4, false);
1009 return info;
1010 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001011 case GL_UNSIGNED_SHORT_5_6_5:
1012 case GL_UNSIGNED_SHORT_4_4_4_4:
1013 case GL_UNSIGNED_SHORT_5_5_5_1:
1014 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1015 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001016 {
1017 static const Type info = GenTypeInfo(2, true);
1018 return info;
1019 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001020 case GL_UNSIGNED_INT_2_10_10_10_REV:
1021 case GL_UNSIGNED_INT_24_8:
1022 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1023 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001024 {
1025 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1026 static const Type info = GenTypeInfo(4, true);
1027 return info;
1028 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001029 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001030 {
1031 static const Type info = GenTypeInfo(8, true);
1032 return info;
1033 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001034 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001035 {
1036 static const Type defaultInfo;
1037 return defaultInfo;
1038 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001039 }
1040}
1041
Geoff Langca271392017-04-05 12:30:00 -04001042const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001043{
Geoff Langca271392017-04-05 12:30:00 -04001044 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001045 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001046 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001047
1048 // Sized internal formats only have one type per entry
1049 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001050 {
Geoff Lang5d601382014-07-22 15:14:06 -04001051 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001052 }
Geoff Langca271392017-04-05 12:30:00 -04001053
1054 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1055 if (!internalFormatInfo.sized)
1056 {
1057 return defaultInternalFormat;
1058 }
1059
1060 return internalFormatInfo;
1061}
1062
1063const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1064{
1065 static const InternalFormat defaultInternalFormat;
1066 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1067
1068 auto internalFormatIter = formatMap.find(internalFormat);
1069 if (internalFormatIter == formatMap.end())
1070 {
1071 return defaultInternalFormat;
1072 }
1073
1074 // If the internal format is sized, simply return it without the type check.
1075 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1076 {
1077 return internalFormatIter->second.begin()->second;
1078 }
1079
1080 auto typeIter = internalFormatIter->second.find(type);
1081 if (typeIter == internalFormatIter->second.end())
1082 {
1083 return defaultInternalFormat;
1084 }
1085
1086 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001087}
1088
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001089GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1090{
1091 const auto &typeInfo = GetTypeInfo(formatType);
1092 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1093 return components * typeInfo.bytes;
1094}
1095
Jamie Madillca2ff382018-07-11 09:01:17 -04001096bool InternalFormat::computeRowPitch(GLenum formatType,
1097 GLsizei width,
1098 GLint alignment,
1099 GLint rowLength,
1100 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001101{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001102 // Compressed images do not use pack/unpack parameters.
1103 if (compressed)
1104 {
1105 ASSERT(rowLength == 0);
Jamie Madillca2ff382018-07-11 09:01:17 -04001106 return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001107 }
1108
Geoff Lang3f234062016-07-13 15:35:45 -04001109 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001110 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001111
1112 ASSERT(alignment > 0 && isPow2(alignment));
1113 CheckedNumeric<GLuint> checkedAlignment(alignment);
1114 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
Jamie Madillca2ff382018-07-11 09:01:17 -04001115 return CheckedMathResult(aligned, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001116}
1117
Jamie Madillca2ff382018-07-11 09:01:17 -04001118bool InternalFormat::computeDepthPitch(GLsizei height,
1119 GLint imageHeight,
1120 GLuint rowPitch,
1121 GLuint *resultOut) const
Corentin Wallez0e487192016-10-03 16:30:38 -04001122{
1123 GLuint rows =
1124 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1125 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1126
Jamie Madillca2ff382018-07-11 09:01:17 -04001127 return CheckedMathResult(checkedRowPitch * rows, resultOut);
Corentin Wallez0e487192016-10-03 16:30:38 -04001128}
1129
Jamie Madillca2ff382018-07-11 09:01:17 -04001130bool InternalFormat::computeDepthPitch(GLenum formatType,
1131 GLsizei width,
1132 GLsizei height,
1133 GLint alignment,
1134 GLint rowLength,
1135 GLint imageHeight,
1136 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001137{
Jamie Madille2e406c2016-06-02 13:04:10 -04001138 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001139 if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1140 {
1141 return false;
1142 }
1143 return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144}
1145
Jamie Madillca2ff382018-07-11 09:01:17 -04001146bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001147{
Jamie Madill513558d2016-06-02 13:04:11 -04001148 CheckedNumeric<GLuint> checkedWidth(size.width);
1149 CheckedNumeric<GLuint> checkedHeight(size.height);
1150 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001151 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1152 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001153
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001154 ASSERT(compressed);
1155 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1156 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1157 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
Jamie Madillca2ff382018-07-11 09:01:17 -04001158 return CheckedMathResult(bytes, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001159}
1160
Jamie Madillca2ff382018-07-11 09:01:17 -04001161bool InternalFormat::computeSkipBytes(GLenum formatType,
1162 GLuint rowPitch,
1163 GLuint depthPitch,
1164 const PixelStoreStateBase &state,
1165 bool is3D,
1166 GLuint *resultOut) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001167{
Olli Etuaho989cac32016-06-08 16:18:49 -07001168 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1169 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001170 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1171 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1172 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001173 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001174 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001175 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001176 {
1177 checkedSkipImagesBytes = 0;
1178 }
1179 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1180 checkedSkipPixels * checkedPixelBytes;
Jamie Madillca2ff382018-07-11 09:01:17 -04001181 return CheckedMathResult(skipBytes, resultOut);
Minmin Gongadff67b2015-10-14 10:34:45 -04001182}
1183
Jamie Madillca2ff382018-07-11 09:01:17 -04001184bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1185 const Extents &size,
1186 const PixelStoreStateBase &state,
1187 bool is3D,
1188 GLuint *resultOut) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001189{
Corentin Wallez886de362016-09-27 10:49:35 -04001190 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001191 if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
Corentin Wallez0e487192016-10-03 16:30:38 -04001192 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001193 return false;
Corentin Wallez0e487192016-10-03 16:30:38 -04001194 }
1195
Jamie Madillca2ff382018-07-11 09:01:17 -04001196 GLuint depthPitch = 0;
1197 if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1198 {
1199 return false;
1200 }
1201
1202 CheckedNumeric<GLuint> checkedCopyBytes(0);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001203 if (compressed)
1204 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001205 GLuint copyBytes = 0;
1206 if (!computeCompressedImageSize(size, &copyBytes))
1207 {
1208 return false;
1209 }
1210 checkedCopyBytes = copyBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001211 }
Corentin Wallez886de362016-09-27 10:49:35 -04001212 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001213 {
Corentin Wallez886de362016-09-27 10:49:35 -04001214 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1215 checkedCopyBytes += size.width * bytes;
1216
1217 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1218 checkedCopyBytes += heightMinusOne * rowPitch;
1219
1220 if (is3D)
1221 {
1222 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1223 checkedCopyBytes += depthMinusOne * depthPitch;
1224 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001225 }
1226
Jamie Madillca2ff382018-07-11 09:01:17 -04001227 GLuint skipBytes = 0;
1228 if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1229 {
1230 return false;
1231 }
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001232
Jamie Madillca2ff382018-07-11 09:01:17 -04001233 CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001234
Jamie Madillca2ff382018-07-11 09:01:17 -04001235 return CheckedMathResult(endByte, resultOut);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001236}
1237
Geoff Langca271392017-04-05 12:30:00 -04001238GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001239{
Geoff Langca271392017-04-05 12:30:00 -04001240 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1241 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001242 {
Geoff Langca271392017-04-05 12:30:00 -04001243 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001244 }
Geoff Langca271392017-04-05 12:30:00 -04001245
1246 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001247}
1248
Geoff Lange4a492b2014-06-19 14:14:41 -04001249const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001250{
Geoff Lange4a492b2014-06-19 14:14:41 -04001251 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001252 return formatSet;
1253}
1254
Jamie Madill09e2d932015-07-14 16:40:31 -04001255AttributeType GetAttributeType(GLenum enumValue)
1256{
1257 switch (enumValue)
1258 {
1259 case GL_FLOAT:
1260 return ATTRIBUTE_FLOAT;
1261 case GL_FLOAT_VEC2:
1262 return ATTRIBUTE_VEC2;
1263 case GL_FLOAT_VEC3:
1264 return ATTRIBUTE_VEC3;
1265 case GL_FLOAT_VEC4:
1266 return ATTRIBUTE_VEC4;
1267 case GL_INT:
1268 return ATTRIBUTE_INT;
1269 case GL_INT_VEC2:
1270 return ATTRIBUTE_IVEC2;
1271 case GL_INT_VEC3:
1272 return ATTRIBUTE_IVEC3;
1273 case GL_INT_VEC4:
1274 return ATTRIBUTE_IVEC4;
1275 case GL_UNSIGNED_INT:
1276 return ATTRIBUTE_UINT;
1277 case GL_UNSIGNED_INT_VEC2:
1278 return ATTRIBUTE_UVEC2;
1279 case GL_UNSIGNED_INT_VEC3:
1280 return ATTRIBUTE_UVEC3;
1281 case GL_UNSIGNED_INT_VEC4:
1282 return ATTRIBUTE_UVEC4;
1283 case GL_FLOAT_MAT2:
1284 return ATTRIBUTE_MAT2;
1285 case GL_FLOAT_MAT3:
1286 return ATTRIBUTE_MAT3;
1287 case GL_FLOAT_MAT4:
1288 return ATTRIBUTE_MAT4;
1289 case GL_FLOAT_MAT2x3:
1290 return ATTRIBUTE_MAT2x3;
1291 case GL_FLOAT_MAT2x4:
1292 return ATTRIBUTE_MAT2x4;
1293 case GL_FLOAT_MAT3x2:
1294 return ATTRIBUTE_MAT3x2;
1295 case GL_FLOAT_MAT3x4:
1296 return ATTRIBUTE_MAT3x4;
1297 case GL_FLOAT_MAT4x2:
1298 return ATTRIBUTE_MAT4x2;
1299 case GL_FLOAT_MAT4x3:
1300 return ATTRIBUTE_MAT4x3;
1301 default:
1302 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001303#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001304 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001305#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001306 }
1307}
1308
Frank Henigman95fb2a12018-05-27 20:17:05 -04001309angle::Format::ID GetVertexFormatID(GLenum type,
1310 GLboolean normalized,
1311 GLuint components,
1312 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001313{
1314 switch (type)
1315 {
1316 case GL_BYTE:
1317 switch (components)
1318 {
1319 case 1:
1320 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001321 return angle::Format::ID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001322 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001323 return angle::Format::ID::R8_SNORM;
1324 return angle::Format::ID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001325 case 2:
1326 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001327 return angle::Format::ID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001328 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001329 return angle::Format::ID::R8G8_SNORM;
1330 return angle::Format::ID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001331 case 3:
1332 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001333 return angle::Format::ID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001334 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001335 return angle::Format::ID::R8G8B8_SNORM;
1336 return angle::Format::ID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001337 case 4:
1338 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001339 return angle::Format::ID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001340 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001341 return angle::Format::ID::R8G8B8A8_SNORM;
1342 return angle::Format::ID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001343 default:
1344 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001345#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001346 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001347#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001348 }
1349 case GL_UNSIGNED_BYTE:
1350 switch (components)
1351 {
1352 case 1:
1353 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001354 return angle::Format::ID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001355 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001356 return angle::Format::ID::R8_UNORM;
1357 return angle::Format::ID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001358 case 2:
1359 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001360 return angle::Format::ID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001361 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001362 return angle::Format::ID::R8G8_UNORM;
1363 return angle::Format::ID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001364 case 3:
1365 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001366 return angle::Format::ID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001367 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001368 return angle::Format::ID::R8G8B8_UNORM;
1369 return angle::Format::ID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001370 case 4:
1371 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001372 return angle::Format::ID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001373 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001374 return angle::Format::ID::R8G8B8A8_UNORM;
1375 return angle::Format::ID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001376 default:
1377 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001378#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001379 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001380#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001381 }
1382 case GL_SHORT:
1383 switch (components)
1384 {
1385 case 1:
1386 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001387 return angle::Format::ID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001388 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001389 return angle::Format::ID::R16_SNORM;
1390 return angle::Format::ID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001391 case 2:
1392 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001393 return angle::Format::ID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001394 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001395 return angle::Format::ID::R16G16_SNORM;
1396 return angle::Format::ID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001397 case 3:
1398 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001399 return angle::Format::ID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001400 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001401 return angle::Format::ID::R16G16B16_SNORM;
1402 return angle::Format::ID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001403 case 4:
1404 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001405 return angle::Format::ID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001406 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001407 return angle::Format::ID::R16G16B16A16_SNORM;
1408 return angle::Format::ID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001409 default:
1410 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001411#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001412 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001413#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001414 }
1415 case GL_UNSIGNED_SHORT:
1416 switch (components)
1417 {
1418 case 1:
1419 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001420 return angle::Format::ID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001421 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001422 return angle::Format::ID::R16_UNORM;
1423 return angle::Format::ID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001424 case 2:
1425 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001426 return angle::Format::ID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001427 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001428 return angle::Format::ID::R16G16_UNORM;
1429 return angle::Format::ID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001430 case 3:
1431 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001432 return angle::Format::ID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001433 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001434 return angle::Format::ID::R16G16B16_UNORM;
1435 return angle::Format::ID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001436 case 4:
1437 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001438 return angle::Format::ID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001439 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001440 return angle::Format::ID::R16G16B16A16_UNORM;
1441 return angle::Format::ID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001442 default:
1443 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001444#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001445 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001446#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001447 }
1448 case GL_INT:
1449 switch (components)
1450 {
1451 case 1:
1452 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001453 return angle::Format::ID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001454 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001455 return angle::Format::ID::R32_SNORM;
1456 return angle::Format::ID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001457 case 2:
1458 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001459 return angle::Format::ID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001460 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001461 return angle::Format::ID::R32G32_SNORM;
1462 return angle::Format::ID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001463 case 3:
1464 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001465 return angle::Format::ID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001466 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001467 return angle::Format::ID::R32G32B32_SNORM;
1468 return angle::Format::ID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001469 case 4:
1470 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001471 return angle::Format::ID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001472 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001473 return angle::Format::ID::R32G32B32A32_SNORM;
1474 return angle::Format::ID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001475 default:
1476 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001477#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001478 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001479#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001480 }
1481 case GL_UNSIGNED_INT:
1482 switch (components)
1483 {
1484 case 1:
1485 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001486 return angle::Format::ID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001487 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001488 return angle::Format::ID::R32_UNORM;
1489 return angle::Format::ID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001490 case 2:
1491 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001492 return angle::Format::ID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001493 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001494 return angle::Format::ID::R32G32_UNORM;
1495 return angle::Format::ID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001496 case 3:
1497 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001498 return angle::Format::ID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001499 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001500 return angle::Format::ID::R32G32B32_UNORM;
1501 return angle::Format::ID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001502 case 4:
1503 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001504 return angle::Format::ID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001505 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001506 return angle::Format::ID::R32G32B32A32_UNORM;
1507 return angle::Format::ID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001508 default:
1509 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001510#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001511 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001512#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001513 }
1514 case GL_FLOAT:
1515 switch (components)
1516 {
1517 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001518 return angle::Format::ID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001519 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001520 return angle::Format::ID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001521 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001522 return angle::Format::ID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001523 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001524 return angle::Format::ID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001525 default:
1526 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001527#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001528 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001529#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001530 }
1531 case GL_HALF_FLOAT:
1532 switch (components)
1533 {
1534 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001535 return angle::Format::ID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001536 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001537 return angle::Format::ID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001538 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001539 return angle::Format::ID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001540 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001541 return angle::Format::ID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001542 default:
1543 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001544#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001545 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001546#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001547 }
1548 case GL_FIXED:
1549 switch (components)
1550 {
1551 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001552 return angle::Format::ID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001553 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001554 return angle::Format::ID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001555 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001556 return angle::Format::ID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001557 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001558 return angle::Format::ID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001559 default:
1560 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001561#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001562 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001563#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001564 }
1565 case GL_INT_2_10_10_10_REV:
1566 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001567 return angle::Format::ID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001568 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001569 return angle::Format::ID::R10G10B10A2_SNORM;
1570 return angle::Format::ID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001571 case GL_UNSIGNED_INT_2_10_10_10_REV:
1572 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001573 return angle::Format::ID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001574 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001575 return angle::Format::ID::R10G10B10A2_UNORM;
1576 return angle::Format::ID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001577 default:
1578 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001579#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001580 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001581#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001582 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001583}
1584
Frank Henigman95fb2a12018-05-27 20:17:05 -04001585angle::Format::ID GetVertexFormatID(const VertexAttribute &attrib)
1586{
1587 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1588}
1589
1590// TODO(fjhenigman): Do away with VertexFormatType; use angle::Format::ID instead. anglebug.com/2531
1591VertexFormatType GetVertexFormatType(GLenum type,
1592 GLboolean normalized,
1593 GLuint components,
1594 bool pureInteger)
1595{
1596 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1597 {
1598 case angle::Format::ID::R8_SINT:
1599 return VERTEX_FORMAT_SBYTE1_INT;
1600 case angle::Format::ID::R8_SNORM:
1601 return VERTEX_FORMAT_SBYTE1_NORM;
1602 case angle::Format::ID::R8_SSCALED:
1603 return VERTEX_FORMAT_SBYTE1;
1604 case angle::Format::ID::R8G8_SINT:
1605 return VERTEX_FORMAT_SBYTE2_INT;
1606 case angle::Format::ID::R8G8_SNORM:
1607 return VERTEX_FORMAT_SBYTE2_NORM;
1608 case angle::Format::ID::R8G8_SSCALED:
1609 return VERTEX_FORMAT_SBYTE2;
1610 case angle::Format::ID::R8G8B8_SINT:
1611 return VERTEX_FORMAT_SBYTE3_INT;
1612 case angle::Format::ID::R8G8B8_SNORM:
1613 return VERTEX_FORMAT_SBYTE3_NORM;
1614 case angle::Format::ID::R8G8B8_SSCALED:
1615 return VERTEX_FORMAT_SBYTE3;
1616 case angle::Format::ID::R8G8B8A8_SINT:
1617 return VERTEX_FORMAT_SBYTE4_INT;
1618 case angle::Format::ID::R8G8B8A8_SNORM:
1619 return VERTEX_FORMAT_SBYTE4_NORM;
1620 case angle::Format::ID::R8G8B8A8_SSCALED:
1621 return VERTEX_FORMAT_SBYTE4;
1622 case angle::Format::ID::R8_UINT:
1623 return VERTEX_FORMAT_UBYTE1_INT;
1624 case angle::Format::ID::R8_UNORM:
1625 return VERTEX_FORMAT_UBYTE1_NORM;
1626 case angle::Format::ID::R8_USCALED:
1627 return VERTEX_FORMAT_UBYTE1;
1628 case angle::Format::ID::R8G8_UINT:
1629 return VERTEX_FORMAT_UBYTE2_INT;
1630 case angle::Format::ID::R8G8_UNORM:
1631 return VERTEX_FORMAT_UBYTE2_NORM;
1632 case angle::Format::ID::R8G8_USCALED:
1633 return VERTEX_FORMAT_UBYTE2;
1634 case angle::Format::ID::R8G8B8_UINT:
1635 return VERTEX_FORMAT_UBYTE3_INT;
1636 case angle::Format::ID::R8G8B8_UNORM:
1637 return VERTEX_FORMAT_UBYTE3_NORM;
1638 case angle::Format::ID::R8G8B8_USCALED:
1639 return VERTEX_FORMAT_UBYTE3;
1640 case angle::Format::ID::R8G8B8A8_UINT:
1641 return VERTEX_FORMAT_UBYTE4_INT;
1642 case angle::Format::ID::R8G8B8A8_UNORM:
1643 return VERTEX_FORMAT_UBYTE4_NORM;
1644 case angle::Format::ID::R8G8B8A8_USCALED:
1645 return VERTEX_FORMAT_UBYTE4;
1646 case angle::Format::ID::R16_SINT:
1647 return VERTEX_FORMAT_SSHORT1_INT;
1648 case angle::Format::ID::R16_SNORM:
1649 return VERTEX_FORMAT_SSHORT1_NORM;
1650 case angle::Format::ID::R16_SSCALED:
1651 return VERTEX_FORMAT_SSHORT1;
1652 case angle::Format::ID::R16G16_SINT:
1653 return VERTEX_FORMAT_SSHORT2_INT;
1654 case angle::Format::ID::R16G16_SNORM:
1655 return VERTEX_FORMAT_SSHORT2_NORM;
1656 case angle::Format::ID::R16G16_SSCALED:
1657 return VERTEX_FORMAT_SSHORT2;
1658 case angle::Format::ID::R16G16B16_SINT:
1659 return VERTEX_FORMAT_SSHORT3_INT;
1660 case angle::Format::ID::R16G16B16_SNORM:
1661 return VERTEX_FORMAT_SSHORT3_NORM;
1662 case angle::Format::ID::R16G16B16_SSCALED:
1663 return VERTEX_FORMAT_SSHORT3;
1664 case angle::Format::ID::R16G16B16A16_SINT:
1665 return VERTEX_FORMAT_SSHORT4_INT;
1666 case angle::Format::ID::R16G16B16A16_SNORM:
1667 return VERTEX_FORMAT_SSHORT4_NORM;
1668 case angle::Format::ID::R16G16B16A16_SSCALED:
1669 return VERTEX_FORMAT_SSHORT4;
1670 case angle::Format::ID::R16_UINT:
1671 return VERTEX_FORMAT_USHORT1_INT;
1672 case angle::Format::ID::R16_UNORM:
1673 return VERTEX_FORMAT_USHORT1_NORM;
1674 case angle::Format::ID::R16_USCALED:
1675 return VERTEX_FORMAT_USHORT1;
1676 case angle::Format::ID::R16G16_UINT:
1677 return VERTEX_FORMAT_USHORT2_INT;
1678 case angle::Format::ID::R16G16_UNORM:
1679 return VERTEX_FORMAT_USHORT2_NORM;
1680 case angle::Format::ID::R16G16_USCALED:
1681 return VERTEX_FORMAT_USHORT2;
1682 case angle::Format::ID::R16G16B16_UINT:
1683 return VERTEX_FORMAT_USHORT3_INT;
1684 case angle::Format::ID::R16G16B16_UNORM:
1685 return VERTEX_FORMAT_USHORT3_NORM;
1686 case angle::Format::ID::R16G16B16_USCALED:
1687 return VERTEX_FORMAT_USHORT3;
1688 case angle::Format::ID::R16G16B16A16_UINT:
1689 return VERTEX_FORMAT_USHORT4_INT;
1690 case angle::Format::ID::R16G16B16A16_UNORM:
1691 return VERTEX_FORMAT_USHORT4_NORM;
1692 case angle::Format::ID::R16G16B16A16_USCALED:
1693 return VERTEX_FORMAT_USHORT4;
1694 case angle::Format::ID::R32_SINT:
1695 return VERTEX_FORMAT_SINT1_INT;
1696 case angle::Format::ID::R32_SNORM:
1697 return VERTEX_FORMAT_SINT1_NORM;
1698 case angle::Format::ID::R32_SSCALED:
1699 return VERTEX_FORMAT_SINT1;
1700 case angle::Format::ID::R32G32_SINT:
1701 return VERTEX_FORMAT_SINT2_INT;
1702 case angle::Format::ID::R32G32_SNORM:
1703 return VERTEX_FORMAT_SINT2_NORM;
1704 case angle::Format::ID::R32G32_SSCALED:
1705 return VERTEX_FORMAT_SINT2;
1706 case angle::Format::ID::R32G32B32_SINT:
1707 return VERTEX_FORMAT_SINT3_INT;
1708 case angle::Format::ID::R32G32B32_SNORM:
1709 return VERTEX_FORMAT_SINT3_NORM;
1710 case angle::Format::ID::R32G32B32_SSCALED:
1711 return VERTEX_FORMAT_SINT3;
1712 case angle::Format::ID::R32G32B32A32_SINT:
1713 return VERTEX_FORMAT_SINT4_INT;
1714 case angle::Format::ID::R32G32B32A32_SNORM:
1715 return VERTEX_FORMAT_SINT4_NORM;
1716 case angle::Format::ID::R32G32B32A32_SSCALED:
1717 return VERTEX_FORMAT_SINT4;
1718 case angle::Format::ID::R32_UINT:
1719 return VERTEX_FORMAT_UINT1_INT;
1720 case angle::Format::ID::R32_UNORM:
1721 return VERTEX_FORMAT_UINT1_NORM;
1722 case angle::Format::ID::R32_USCALED:
1723 return VERTEX_FORMAT_UINT1;
1724 case angle::Format::ID::R32G32_UINT:
1725 return VERTEX_FORMAT_UINT2_INT;
1726 case angle::Format::ID::R32G32_UNORM:
1727 return VERTEX_FORMAT_UINT2_NORM;
1728 case angle::Format::ID::R32G32_USCALED:
1729 return VERTEX_FORMAT_UINT2;
1730 case angle::Format::ID::R32G32B32_UINT:
1731 return VERTEX_FORMAT_UINT3_INT;
1732 case angle::Format::ID::R32G32B32_UNORM:
1733 return VERTEX_FORMAT_UINT3_NORM;
1734 case angle::Format::ID::R32G32B32_USCALED:
1735 return VERTEX_FORMAT_UINT3;
1736 case angle::Format::ID::R32G32B32A32_UINT:
1737 return VERTEX_FORMAT_UINT4_INT;
1738 case angle::Format::ID::R32G32B32A32_UNORM:
1739 return VERTEX_FORMAT_UINT4_NORM;
1740 case angle::Format::ID::R32G32B32A32_USCALED:
1741 return VERTEX_FORMAT_UINT4;
1742 case angle::Format::ID::R32_FLOAT:
1743 return VERTEX_FORMAT_FLOAT1;
1744 case angle::Format::ID::R32G32_FLOAT:
1745 return VERTEX_FORMAT_FLOAT2;
1746 case angle::Format::ID::R32G32B32_FLOAT:
1747 return VERTEX_FORMAT_FLOAT3;
1748 case angle::Format::ID::R32G32B32A32_FLOAT:
1749 return VERTEX_FORMAT_FLOAT4;
1750 case angle::Format::ID::R16_FLOAT:
1751 return VERTEX_FORMAT_HALF1;
1752 case angle::Format::ID::R16G16_FLOAT:
1753 return VERTEX_FORMAT_HALF2;
1754 case angle::Format::ID::R16G16B16_FLOAT:
1755 return VERTEX_FORMAT_HALF3;
1756 case angle::Format::ID::R16G16B16A16_FLOAT:
1757 return VERTEX_FORMAT_HALF4;
1758 case angle::Format::ID::R32_FIXED:
1759 return VERTEX_FORMAT_FIXED1;
1760 case angle::Format::ID::R32G32_FIXED:
1761 return VERTEX_FORMAT_FIXED2;
1762 case angle::Format::ID::R32G32B32_FIXED:
1763 return VERTEX_FORMAT_FIXED3;
1764 case angle::Format::ID::R32G32B32A32_FIXED:
1765 return VERTEX_FORMAT_FIXED4;
1766 case angle::Format::ID::R10G10B10A2_SINT:
1767 return VERTEX_FORMAT_SINT210_INT;
1768 case angle::Format::ID::R10G10B10A2_SNORM:
1769 return VERTEX_FORMAT_SINT210_NORM;
1770 case angle::Format::ID::R10G10B10A2_SSCALED:
1771 return VERTEX_FORMAT_SINT210;
1772 case angle::Format::ID::R10G10B10A2_UINT:
1773 return VERTEX_FORMAT_UINT210_INT;
1774 case angle::Format::ID::R10G10B10A2_UNORM:
1775 return VERTEX_FORMAT_UINT210_NORM;
1776 case angle::Format::ID::R10G10B10A2_USCALED:
1777 return VERTEX_FORMAT_UINT210;
1778 default:
1779 return VERTEX_FORMAT_INVALID;
1780 }
1781}
1782
Jamie Madilld3dfda22015-07-06 08:28:49 -04001783VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1784{
1785 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1786}
1787
1788VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1789{
1790 if (!attrib.enabled)
1791 {
1792 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1793 }
1794 return GetVertexFormatType(attrib);
1795}
1796
1797const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1798{
1799 switch (vertexFormatType)
1800 {
1801 case VERTEX_FORMAT_SBYTE1:
1802 {
1803 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1804 return format;
1805 }
1806 case VERTEX_FORMAT_SBYTE1_NORM:
1807 {
1808 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1809 return format;
1810 }
1811 case VERTEX_FORMAT_SBYTE2:
1812 {
1813 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1814 return format;
1815 }
1816 case VERTEX_FORMAT_SBYTE2_NORM:
1817 {
1818 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1819 return format;
1820 }
1821 case VERTEX_FORMAT_SBYTE3:
1822 {
1823 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1824 return format;
1825 }
1826 case VERTEX_FORMAT_SBYTE3_NORM:
1827 {
1828 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1829 return format;
1830 }
1831 case VERTEX_FORMAT_SBYTE4:
1832 {
1833 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1834 return format;
1835 }
1836 case VERTEX_FORMAT_SBYTE4_NORM:
1837 {
1838 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1839 return format;
1840 }
1841 case VERTEX_FORMAT_UBYTE1:
1842 {
1843 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1844 return format;
1845 }
1846 case VERTEX_FORMAT_UBYTE1_NORM:
1847 {
1848 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1849 return format;
1850 }
1851 case VERTEX_FORMAT_UBYTE2:
1852 {
1853 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1854 return format;
1855 }
1856 case VERTEX_FORMAT_UBYTE2_NORM:
1857 {
1858 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1859 return format;
1860 }
1861 case VERTEX_FORMAT_UBYTE3:
1862 {
1863 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1864 return format;
1865 }
1866 case VERTEX_FORMAT_UBYTE3_NORM:
1867 {
1868 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1869 return format;
1870 }
1871 case VERTEX_FORMAT_UBYTE4:
1872 {
1873 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1874 return format;
1875 }
1876 case VERTEX_FORMAT_UBYTE4_NORM:
1877 {
1878 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1879 return format;
1880 }
1881 case VERTEX_FORMAT_SSHORT1:
1882 {
1883 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1884 return format;
1885 }
1886 case VERTEX_FORMAT_SSHORT1_NORM:
1887 {
1888 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1889 return format;
1890 }
1891 case VERTEX_FORMAT_SSHORT2:
1892 {
1893 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1894 return format;
1895 }
1896 case VERTEX_FORMAT_SSHORT2_NORM:
1897 {
1898 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1899 return format;
1900 }
1901 case VERTEX_FORMAT_SSHORT3:
1902 {
1903 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1904 return format;
1905 }
1906 case VERTEX_FORMAT_SSHORT3_NORM:
1907 {
1908 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1909 return format;
1910 }
1911 case VERTEX_FORMAT_SSHORT4:
1912 {
1913 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1914 return format;
1915 }
1916 case VERTEX_FORMAT_SSHORT4_NORM:
1917 {
1918 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1919 return format;
1920 }
1921 case VERTEX_FORMAT_USHORT1:
1922 {
1923 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1924 return format;
1925 }
1926 case VERTEX_FORMAT_USHORT1_NORM:
1927 {
1928 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1929 return format;
1930 }
1931 case VERTEX_FORMAT_USHORT2:
1932 {
1933 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1934 return format;
1935 }
1936 case VERTEX_FORMAT_USHORT2_NORM:
1937 {
1938 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1939 return format;
1940 }
1941 case VERTEX_FORMAT_USHORT3:
1942 {
1943 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1944 return format;
1945 }
1946 case VERTEX_FORMAT_USHORT3_NORM:
1947 {
1948 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1949 return format;
1950 }
1951 case VERTEX_FORMAT_USHORT4:
1952 {
1953 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1954 return format;
1955 }
1956 case VERTEX_FORMAT_USHORT4_NORM:
1957 {
1958 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1959 return format;
1960 }
1961 case VERTEX_FORMAT_SINT1:
1962 {
1963 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1964 return format;
1965 }
1966 case VERTEX_FORMAT_SINT1_NORM:
1967 {
1968 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1969 return format;
1970 }
1971 case VERTEX_FORMAT_SINT2:
1972 {
1973 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1974 return format;
1975 }
1976 case VERTEX_FORMAT_SINT2_NORM:
1977 {
1978 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1979 return format;
1980 }
1981 case VERTEX_FORMAT_SINT3:
1982 {
1983 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1984 return format;
1985 }
1986 case VERTEX_FORMAT_SINT3_NORM:
1987 {
1988 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1989 return format;
1990 }
1991 case VERTEX_FORMAT_SINT4:
1992 {
1993 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1994 return format;
1995 }
1996 case VERTEX_FORMAT_SINT4_NORM:
1997 {
1998 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1999 return format;
2000 }
2001 case VERTEX_FORMAT_UINT1:
2002 {
2003 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2004 return format;
2005 }
2006 case VERTEX_FORMAT_UINT1_NORM:
2007 {
2008 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2009 return format;
2010 }
2011 case VERTEX_FORMAT_UINT2:
2012 {
2013 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2014 return format;
2015 }
2016 case VERTEX_FORMAT_UINT2_NORM:
2017 {
2018 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2019 return format;
2020 }
2021 case VERTEX_FORMAT_UINT3:
2022 {
2023 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2024 return format;
2025 }
2026 case VERTEX_FORMAT_UINT3_NORM:
2027 {
2028 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2029 return format;
2030 }
2031 case VERTEX_FORMAT_UINT4:
2032 {
2033 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2034 return format;
2035 }
2036 case VERTEX_FORMAT_UINT4_NORM:
2037 {
2038 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2039 return format;
2040 }
2041 case VERTEX_FORMAT_SBYTE1_INT:
2042 {
2043 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2044 return format;
2045 }
2046 case VERTEX_FORMAT_SBYTE2_INT:
2047 {
2048 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2049 return format;
2050 }
2051 case VERTEX_FORMAT_SBYTE3_INT:
2052 {
2053 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2054 return format;
2055 }
2056 case VERTEX_FORMAT_SBYTE4_INT:
2057 {
2058 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2059 return format;
2060 }
2061 case VERTEX_FORMAT_UBYTE1_INT:
2062 {
2063 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2064 return format;
2065 }
2066 case VERTEX_FORMAT_UBYTE2_INT:
2067 {
2068 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2069 return format;
2070 }
2071 case VERTEX_FORMAT_UBYTE3_INT:
2072 {
2073 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2074 return format;
2075 }
2076 case VERTEX_FORMAT_UBYTE4_INT:
2077 {
2078 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2079 return format;
2080 }
2081 case VERTEX_FORMAT_SSHORT1_INT:
2082 {
2083 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2084 return format;
2085 }
2086 case VERTEX_FORMAT_SSHORT2_INT:
2087 {
2088 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2089 return format;
2090 }
2091 case VERTEX_FORMAT_SSHORT3_INT:
2092 {
2093 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2094 return format;
2095 }
2096 case VERTEX_FORMAT_SSHORT4_INT:
2097 {
2098 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2099 return format;
2100 }
2101 case VERTEX_FORMAT_USHORT1_INT:
2102 {
2103 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2104 return format;
2105 }
2106 case VERTEX_FORMAT_USHORT2_INT:
2107 {
2108 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2109 return format;
2110 }
2111 case VERTEX_FORMAT_USHORT3_INT:
2112 {
2113 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2114 return format;
2115 }
2116 case VERTEX_FORMAT_USHORT4_INT:
2117 {
2118 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2119 return format;
2120 }
2121 case VERTEX_FORMAT_SINT1_INT:
2122 {
2123 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2124 return format;
2125 }
2126 case VERTEX_FORMAT_SINT2_INT:
2127 {
2128 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2129 return format;
2130 }
2131 case VERTEX_FORMAT_SINT3_INT:
2132 {
2133 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2134 return format;
2135 }
2136 case VERTEX_FORMAT_SINT4_INT:
2137 {
2138 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2139 return format;
2140 }
2141 case VERTEX_FORMAT_UINT1_INT:
2142 {
2143 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2144 return format;
2145 }
2146 case VERTEX_FORMAT_UINT2_INT:
2147 {
2148 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2149 return format;
2150 }
2151 case VERTEX_FORMAT_UINT3_INT:
2152 {
2153 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2154 return format;
2155 }
2156 case VERTEX_FORMAT_UINT4_INT:
2157 {
2158 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2159 return format;
2160 }
2161 case VERTEX_FORMAT_FIXED1:
2162 {
2163 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2164 return format;
2165 }
2166 case VERTEX_FORMAT_FIXED2:
2167 {
2168 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2169 return format;
2170 }
2171 case VERTEX_FORMAT_FIXED3:
2172 {
2173 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2174 return format;
2175 }
2176 case VERTEX_FORMAT_FIXED4:
2177 {
2178 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2179 return format;
2180 }
2181 case VERTEX_FORMAT_HALF1:
2182 {
2183 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2184 return format;
2185 }
2186 case VERTEX_FORMAT_HALF2:
2187 {
2188 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2189 return format;
2190 }
2191 case VERTEX_FORMAT_HALF3:
2192 {
2193 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2194 return format;
2195 }
2196 case VERTEX_FORMAT_HALF4:
2197 {
2198 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2199 return format;
2200 }
2201 case VERTEX_FORMAT_FLOAT1:
2202 {
2203 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2204 return format;
2205 }
2206 case VERTEX_FORMAT_FLOAT2:
2207 {
2208 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2209 return format;
2210 }
2211 case VERTEX_FORMAT_FLOAT3:
2212 {
2213 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2214 return format;
2215 }
2216 case VERTEX_FORMAT_FLOAT4:
2217 {
2218 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2219 return format;
2220 }
2221 case VERTEX_FORMAT_SINT210:
2222 {
2223 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2224 return format;
2225 }
2226 case VERTEX_FORMAT_UINT210:
2227 {
2228 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2229 return format;
2230 }
2231 case VERTEX_FORMAT_SINT210_NORM:
2232 {
2233 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2234 return format;
2235 }
2236 case VERTEX_FORMAT_UINT210_NORM:
2237 {
2238 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2239 return format;
2240 }
2241 case VERTEX_FORMAT_SINT210_INT:
2242 {
2243 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2244 return format;
2245 }
2246 case VERTEX_FORMAT_UINT210_INT:
2247 {
2248 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2249 return format;
2250 }
2251 default:
2252 {
2253 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2254 return format;
2255 }
2256 }
2257}
2258
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002259size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2260{
2261 switch (vertexFormatType)
2262 {
2263 case VERTEX_FORMAT_SBYTE1:
2264 case VERTEX_FORMAT_SBYTE1_NORM:
2265 case VERTEX_FORMAT_UBYTE1:
2266 case VERTEX_FORMAT_UBYTE1_NORM:
2267 case VERTEX_FORMAT_SBYTE1_INT:
2268 case VERTEX_FORMAT_UBYTE1_INT:
2269 return 1;
2270
2271 case VERTEX_FORMAT_SBYTE2:
2272 case VERTEX_FORMAT_SBYTE2_NORM:
2273 case VERTEX_FORMAT_UBYTE2:
2274 case VERTEX_FORMAT_UBYTE2_NORM:
2275 case VERTEX_FORMAT_SBYTE2_INT:
2276 case VERTEX_FORMAT_UBYTE2_INT:
2277 case VERTEX_FORMAT_SSHORT1:
2278 case VERTEX_FORMAT_SSHORT1_NORM:
2279 case VERTEX_FORMAT_USHORT1:
2280 case VERTEX_FORMAT_USHORT1_NORM:
2281 case VERTEX_FORMAT_SSHORT1_INT:
2282 case VERTEX_FORMAT_USHORT1_INT:
2283 case VERTEX_FORMAT_HALF1:
2284 return 2;
2285
2286 case VERTEX_FORMAT_SBYTE3:
2287 case VERTEX_FORMAT_SBYTE3_NORM:
2288 case VERTEX_FORMAT_UBYTE3:
2289 case VERTEX_FORMAT_UBYTE3_NORM:
2290 case VERTEX_FORMAT_SBYTE3_INT:
2291 case VERTEX_FORMAT_UBYTE3_INT:
2292 return 3;
2293
2294 case VERTEX_FORMAT_SBYTE4:
2295 case VERTEX_FORMAT_SBYTE4_NORM:
2296 case VERTEX_FORMAT_UBYTE4:
2297 case VERTEX_FORMAT_UBYTE4_NORM:
2298 case VERTEX_FORMAT_SBYTE4_INT:
2299 case VERTEX_FORMAT_UBYTE4_INT:
2300 case VERTEX_FORMAT_SSHORT2:
2301 case VERTEX_FORMAT_SSHORT2_NORM:
2302 case VERTEX_FORMAT_USHORT2:
2303 case VERTEX_FORMAT_USHORT2_NORM:
2304 case VERTEX_FORMAT_SSHORT2_INT:
2305 case VERTEX_FORMAT_USHORT2_INT:
2306 case VERTEX_FORMAT_SINT1:
2307 case VERTEX_FORMAT_SINT1_NORM:
2308 case VERTEX_FORMAT_UINT1:
2309 case VERTEX_FORMAT_UINT1_NORM:
2310 case VERTEX_FORMAT_SINT1_INT:
2311 case VERTEX_FORMAT_UINT1_INT:
2312 case VERTEX_FORMAT_HALF2:
2313 case VERTEX_FORMAT_FIXED1:
2314 case VERTEX_FORMAT_FLOAT1:
2315 case VERTEX_FORMAT_SINT210:
2316 case VERTEX_FORMAT_UINT210:
2317 case VERTEX_FORMAT_SINT210_NORM:
2318 case VERTEX_FORMAT_UINT210_NORM:
2319 case VERTEX_FORMAT_SINT210_INT:
2320 case VERTEX_FORMAT_UINT210_INT:
2321 return 4;
2322
2323 case VERTEX_FORMAT_SSHORT3:
2324 case VERTEX_FORMAT_SSHORT3_NORM:
2325 case VERTEX_FORMAT_USHORT3:
2326 case VERTEX_FORMAT_USHORT3_NORM:
2327 case VERTEX_FORMAT_SSHORT3_INT:
2328 case VERTEX_FORMAT_USHORT3_INT:
2329 case VERTEX_FORMAT_HALF3:
2330 return 6;
2331
2332 case VERTEX_FORMAT_SSHORT4:
2333 case VERTEX_FORMAT_SSHORT4_NORM:
2334 case VERTEX_FORMAT_USHORT4:
2335 case VERTEX_FORMAT_USHORT4_NORM:
2336 case VERTEX_FORMAT_SSHORT4_INT:
2337 case VERTEX_FORMAT_USHORT4_INT:
2338 case VERTEX_FORMAT_SINT2:
2339 case VERTEX_FORMAT_SINT2_NORM:
2340 case VERTEX_FORMAT_UINT2:
2341 case VERTEX_FORMAT_UINT2_NORM:
2342 case VERTEX_FORMAT_SINT2_INT:
2343 case VERTEX_FORMAT_UINT2_INT:
2344 case VERTEX_FORMAT_HALF4:
2345 case VERTEX_FORMAT_FIXED2:
2346 case VERTEX_FORMAT_FLOAT2:
2347 return 8;
2348
2349 case VERTEX_FORMAT_SINT3:
2350 case VERTEX_FORMAT_SINT3_NORM:
2351 case VERTEX_FORMAT_UINT3:
2352 case VERTEX_FORMAT_UINT3_NORM:
2353 case VERTEX_FORMAT_SINT3_INT:
2354 case VERTEX_FORMAT_UINT3_INT:
2355 case VERTEX_FORMAT_FIXED3:
2356 case VERTEX_FORMAT_FLOAT3:
2357 return 12;
2358
2359 case VERTEX_FORMAT_SINT4:
2360 case VERTEX_FORMAT_SINT4_NORM:
2361 case VERTEX_FORMAT_UINT4:
2362 case VERTEX_FORMAT_UINT4_NORM:
2363 case VERTEX_FORMAT_SINT4_INT:
2364 case VERTEX_FORMAT_UINT4_INT:
2365 case VERTEX_FORMAT_FIXED4:
2366 case VERTEX_FORMAT_FLOAT4:
2367 return 16;
2368
2369 case VERTEX_FORMAT_INVALID:
2370 default:
2371 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002372#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002373 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002374#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002375 }
2376}
2377
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002378bool ValidES3InternalFormat(GLenum internalFormat)
2379{
2380 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2381 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2382}
2383
Frank Henigman95fb2a12018-05-27 20:17:05 -04002384VertexFormat::VertexFormat(GLenum typeIn,
2385 GLboolean normalizedIn,
2386 GLuint componentsIn,
2387 bool pureIntegerIn)
2388 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002389{
2390 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002391 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2392 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002393}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002394}