blob: 50df33fd82c2948be1ec12449eb75d845fe27bc6 [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
30} // anonymous namespace
31
32FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
33{
34}
35
36FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
37{
38}
39
40bool FormatType::operator<(const FormatType &other) const
41{
42 if (format != other.format)
43 return format < other.format;
44 return type < other.type;
45}
46
Frank Henigman95fb2a12018-05-27 20:17:05 -040047Type::Type() : bytes(0), bytesShift(0), specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040048{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000049}
50
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020051static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052{
Geoff Lang5d601382014-07-22 15:14:06 -040053 Type info;
54 info.bytes = bytes;
Frank Henigman95fb2a12018-05-27 20:17:05 -040055 GLuint i = 0;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020056 while ((1u << i) < bytes)
57 {
58 ++i;
59 }
60 info.bytesShift = i;
61 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040062 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020063 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040064}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000065
Frank Henigman95fb2a12018-05-27 20:17:05 -040066bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040067{
68 return memcmp(&a, &b, sizeof(Type)) < 0;
69}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000070
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000071// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040072static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073{
Geoff Lang493daf52014-07-03 13:38:44 -040074 return true;
75}
76
Geoff Langeb66a6e2016-10-31 13:06:12 -040077static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000078{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000079 return false;
80}
81
Geoff Langeb66a6e2016-10-31 13:06:12 -040082template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
83static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040084{
Geoff Langeb66a6e2016-10-31 13:06:12 -040085 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040086}
87
Geoff Langcec35902014-04-16 10:52:36 -040088// Pointer to a boolean memeber of the Extensions struct
89typedef bool(Extensions::*ExtensionBool);
90
91// Check support for a single extension
92template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040093static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040094{
Geoff Lange4a492b2014-06-19 14:14:41 -040095 return extensions.*bool1;
96}
97
98// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -040099template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
100static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400101{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400102 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
103 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400104}
105
106// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400107template <GLuint minCoreGLMajorVersion,
108 GLuint minCoreGLMinorVersion,
109 ExtensionBool bool1,
110 ExtensionBool bool2>
111static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400112{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400113 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
114 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400115}
116
117// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400118template <GLuint minCoreGLMajorVersion,
119 GLuint minCoreGLMinorVersion,
120 ExtensionBool bool1,
121 ExtensionBool bool2>
122static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400123{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400124 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
125 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400126}
127
128// Check support for two extensions
129template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400130static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400131{
Geoff Langabce7622014-09-19 16:13:00 -0400132 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400133}
134
Geoff Lang60ad73d2015-10-23 10:08:44 -0400135// Check support for either of two extensions
136template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400137static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400138{
139 return extensions.*bool1 || extensions.*bool2;
140}
141
Jamie Madillcd089732015-12-17 09:53:09 -0500142// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400143static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500144{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400145 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500146}
147
Geoff Lang677bb6f2017-04-05 12:40:40 -0400148static bool HalfFloatRGBRenderableSupport(const Version &clientVersion,
149 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500150{
151 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
152}
153
Geoff Lang677bb6f2017-04-05 12:40:40 -0400154static bool HalfFloatRGBARenderableSupport(const Version &clientVersion,
155 const Extensions &extensions)
156{
157 return HalfFloatSupport(clientVersion, extensions) &&
158 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
159}
160
Jamie Madillcd089732015-12-17 09:53:09 -0500161// Special function for half float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400162
163// R16F, RG16F
164static bool HalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500165{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400166 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500167}
168
Geoff Lang677bb6f2017-04-05 12:40:40 -0400169// R16F, RG16F
170static bool HalfFloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500171{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400172 // It's unclear if EXT_color_buffer_half_float gives renderability to non-OES half float
173 // textures
174 return HalfFloatRGSupport(clientVersion, extensions) &&
175 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
176}
177
178// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
179static bool UnsizedHalfFloatOESRGSupport(const Version &, const Extensions &extensions)
180{
181 return extensions.textureHalfFloat && extensions.textureRG;
182}
183
184// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
185static bool UnsizedHalfFloatOESRGRenderableSupport(const Version &clientVersion,
186 const Extensions &extensions)
187{
188 return UnsizedHalfFloatOESRGSupport(clientVersion, extensions) &&
189 extensions.colorBufferHalfFloat;
190}
191
192// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
193static bool UnsizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
194{
195 return extensions.textureHalfFloat;
196}
197
198// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
199static bool UnsizedHalfFloatOESRenderableSupport(const Version &clientVersion,
200 const Extensions &extensions)
201{
202 return UnsizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500203}
204
205// Special function for float formats with three or four channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400206
207// RGB32F, RGBA32F
Geoff Langeb66a6e2016-10-31 13:06:12 -0400208static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500209{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400210 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500211}
212
Geoff Lang677bb6f2017-04-05 12:40:40 -0400213// RGB32F
214static bool FloatRGBRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500215{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400216 return FloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
217}
218
219// RGBA32F
220static bool FloatRGBARenderableSupport(const Version &clientVersion, const Extensions &extensions)
221{
Jamie Madillcd089732015-12-17 09:53:09 -0500222 return FloatSupport(clientVersion, extensions) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400223 (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
224}
225
226// RGB + FLOAT, RGBA + FLOAT
227static bool UnsizedFloatSupport(const Version &clientVersion, const Extensions &extensions)
228{
229 return extensions.textureFloat;
230}
231
232// RGB + FLOAT
233static bool UnsizedFloatRGBRenderableSupport(const Version &clientVersion,
234 const Extensions &extensions)
235{
236 return UnsizedFloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
237}
238
239// RGBA + FLOAT
240static bool UnsizedFloatRGBARenderableSupport(const Version &clientVersion,
241 const Extensions &extensions)
242{
243 return UnsizedFloatSupport(clientVersion, extensions) &&
244 (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500245}
246
247// Special function for float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400248
249// R32F, RG32F
250static bool FloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500251{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400252 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500253}
254
Geoff Lang677bb6f2017-04-05 12:40:40 -0400255// R32F, RG32F
256static bool FloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500257{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400258 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
259}
260
261// RED + FLOAT, RG + FLOAT
262static bool UnsizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
263{
264 return extensions.textureFloat && extensions.textureRG;
265}
266
267// RED + FLOAT, RG + FLOAT
268static bool UnsizedFloatRGRenderableSupport(const Version &clientVersion,
269 const Extensions &extensions)
270{
271 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500272}
273
Geoff Lang5d601382014-07-22 15:14:06 -0400274InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400275 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400276 sized(false),
277 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400278 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400279 greenBits(0),
280 blueBits(0),
281 luminanceBits(0),
282 alphaBits(0),
283 sharedBits(0),
284 depthBits(0),
285 stencilBits(0),
286 pixelBytes(0),
287 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400288 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400289 compressedBlockWidth(0),
290 compressedBlockHeight(0),
291 format(GL_NONE),
292 type(GL_NONE),
293 componentType(GL_NONE),
294 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400295 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400296 filterSupport(NeverSupported),
297 textureAttachmentSupport(NeverSupported),
298 renderbufferSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000299{
Geoff Lang5d601382014-07-22 15:14:06 -0400300}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500302InternalFormat::InternalFormat(const InternalFormat &other) = default;
303
Jamie Madilla3944d42016-07-22 22:13:26 -0400304bool InternalFormat::isLUMA() const
305{
306 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
307 (luminanceBits + alphaBits) > 0);
308}
309
Geoff Langf607c602016-09-21 11:46:48 -0400310GLenum InternalFormat::getReadPixelsFormat() const
311{
312 return format;
313}
314
Geoff Langc71ea662017-09-26 17:06:02 -0400315GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400316{
317 switch (type)
318 {
319 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400320 case GL_HALF_FLOAT_OES:
321 if (version < Version(3, 0))
322 {
323 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
324 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
325 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
326 // as an IMPLEMENTATION_READ_TYPE.
327 return GL_HALF_FLOAT_OES;
328 }
329 else
330 {
331 return GL_HALF_FLOAT;
332 }
Geoff Langf607c602016-09-21 11:46:48 -0400333
334 default:
335 return type;
336 }
337}
338
Olli Etuaho50c562d2017-06-06 14:43:30 +0300339bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
340{
341 // GLES 3.0.5 section 4.4.2.2:
342 // "Implementations are required to support the same internal formats for renderbuffers as the
343 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
344 // formats labelled "texture-only"."
345 if (!sized || compressed)
346 {
347 return false;
348 }
349
350 // Luma formats.
351 if (isLUMA())
352 {
353 return false;
354 }
355
356 // Depth/stencil formats.
357 if (depthBits > 0 || stencilBits > 0)
358 {
359 // GLES 2.0.25 table 4.5.
360 // GLES 3.0.5 section 3.8.3.1.
361 // GLES 3.1 table 8.14.
362
363 // Required formats in all versions.
364 switch (internalFormat)
365 {
366 case GL_DEPTH_COMPONENT16:
367 case GL_STENCIL_INDEX8:
368 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
369 // is in section 4.4.2.2.
370 return true;
371 default:
372 break;
373 }
374 if (version.major < 3)
375 {
376 return false;
377 }
378 // Required formats in GLES 3.0 and up.
379 switch (internalFormat)
380 {
381 case GL_DEPTH_COMPONENT32F:
382 case GL_DEPTH_COMPONENT24:
383 case GL_DEPTH32F_STENCIL8:
384 case GL_DEPTH24_STENCIL8:
385 return true;
386 default:
387 return false;
388 }
389 }
390
391 // RGBA formats.
392 // GLES 2.0.25 table 4.5.
393 // GLES 3.0.5 section 3.8.3.1.
394 // GLES 3.1 table 8.13.
395
396 // Required formats in all versions.
397 switch (internalFormat)
398 {
399 case GL_RGBA4:
400 case GL_RGB5_A1:
401 case GL_RGB565:
402 return true;
403 default:
404 break;
405 }
406 if (version.major < 3)
407 {
408 return false;
409 }
410
411 if (format == GL_BGRA_EXT)
412 {
413 return false;
414 }
415
416 switch (componentType)
417 {
418 case GL_SIGNED_NORMALIZED:
419 case GL_FLOAT:
420 return false;
421 case GL_UNSIGNED_INT:
422 case GL_INT:
423 // Integer RGB formats are not required renderbuffer formats.
424 if (alphaBits == 0 && blueBits != 0)
425 {
426 return false;
427 }
428 // All integer R and RG formats are required.
429 // Integer RGBA formats including RGB10_A2_UI are required.
430 return true;
431 case GL_UNSIGNED_NORMALIZED:
432 if (internalFormat == GL_SRGB8)
433 {
434 return false;
435 }
436 return true;
437 default:
438 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500439#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300440 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500441#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300442 }
443}
444
Geoff Langca271392017-04-05 12:30:00 -0400445Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400446{
447}
448
Geoff Langca271392017-04-05 12:30:00 -0400449Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400450{
Jamie Madilla3944d42016-07-22 22:13:26 -0400451}
452
Geoff Langca271392017-04-05 12:30:00 -0400453Format::Format(GLenum internalFormat, GLenum type)
454 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400455{
Jamie Madilla3944d42016-07-22 22:13:26 -0400456}
457
458Format::Format(const Format &other) = default;
459Format &Format::operator=(const Format &other) = default;
460
Jamie Madilla3944d42016-07-22 22:13:26 -0400461bool Format::valid() const
462{
Geoff Langca271392017-04-05 12:30:00 -0400463 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400464}
465
466// static
467bool Format::SameSized(const Format &a, const Format &b)
468{
Geoff Langca271392017-04-05 12:30:00 -0400469 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400470}
471
Kenneth Russell69382852017-07-21 16:38:44 -0400472static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
473{
474 // BlitFramebuffer works if the color channels are identically
475 // sized, even if there is a swizzle (for example, blitting from a
476 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
477 // be expanded and/or autogenerated if that is found necessary.
478 if (internalformat == GL_BGRA8_EXT)
479 return GL_RGBA8;
480 return internalformat;
481}
482
483// static
484bool Format::EquivalentForBlit(const Format &a, const Format &b)
485{
486 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
487 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
488}
489
Jamie Madilla3944d42016-07-22 22:13:26 -0400490// static
491Format Format::Invalid()
492{
Geoff Langca271392017-04-05 12:30:00 -0400493 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400494 return invalid;
495}
496
Yuly Novikovd73f8522017-01-13 17:48:57 -0500497std::ostream &operator<<(std::ostream &os, const Format &fmt)
498{
499 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400500 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500501}
502
Jamie Madilla3944d42016-07-22 22:13:26 -0400503bool InternalFormat::operator==(const InternalFormat &other) const
504{
Geoff Langca271392017-04-05 12:30:00 -0400505 // We assume all internal formats are unique if they have the same internal format and type
506 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400507}
508
509bool InternalFormat::operator!=(const InternalFormat &other) const
510{
Geoff Langca271392017-04-05 12:30:00 -0400511 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400512}
513
Geoff Langca271392017-04-05 12:30:00 -0400514void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400515{
Geoff Langca271392017-04-05 12:30:00 -0400516 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
517 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
518 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400519}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000520
Jamie Madilla3944d42016-07-22 22:13:26 -0400521void AddRGBAFormat(InternalFormatInfoMap *map,
522 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400523 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400524 GLuint red,
525 GLuint green,
526 GLuint blue,
527 GLuint alpha,
528 GLuint shared,
529 GLenum format,
530 GLenum type,
531 GLenum componentType,
532 bool srgb,
533 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400534 InternalFormat::SupportCheckFunction filterSupport,
535 InternalFormat::SupportCheckFunction textureAttachmentSupport,
536 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400537{
538 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400539 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400540 formatInfo.sized = sized;
541 formatInfo.sizedInternalFormat =
542 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400543 formatInfo.redBits = red;
544 formatInfo.greenBits = green;
545 formatInfo.blueBits = blue;
546 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400547 formatInfo.sharedBits = shared;
548 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400549 formatInfo.componentCount =
550 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400551 formatInfo.format = format;
552 formatInfo.type = type;
553 formatInfo.componentType = componentType;
554 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
555 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400556 formatInfo.filterSupport = filterSupport;
557 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
558 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400559
560 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400561}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000562
Geoff Langca271392017-04-05 12:30:00 -0400563static void AddLUMAFormat(InternalFormatInfoMap *map,
564 GLenum internalFormat,
565 bool sized,
566 GLuint luminance,
567 GLuint alpha,
568 GLenum format,
569 GLenum type,
570 GLenum componentType,
571 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400572 InternalFormat::SupportCheckFunction filterSupport,
573 InternalFormat::SupportCheckFunction textureAttachmentSupport,
574 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400575{
576 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400577 formatInfo.internalFormat = internalFormat;
578 formatInfo.sized = sized;
579 formatInfo.sizedInternalFormat =
580 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400581 formatInfo.luminanceBits = luminance;
582 formatInfo.alphaBits = alpha;
583 formatInfo.pixelBytes = (luminance + alpha) / 8;
584 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
585 formatInfo.format = format;
586 formatInfo.type = type;
587 formatInfo.componentType = componentType;
588 formatInfo.colorEncoding = GL_LINEAR;
589 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400590 formatInfo.filterSupport = filterSupport;
591 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
592 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400593
594 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400595}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596
Jamie Madilla3944d42016-07-22 22:13:26 -0400597void AddDepthStencilFormat(InternalFormatInfoMap *map,
598 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400599 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400600 GLuint depthBits,
601 GLuint stencilBits,
602 GLuint unusedBits,
603 GLenum format,
604 GLenum type,
605 GLenum componentType,
606 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400607 InternalFormat::SupportCheckFunction filterSupport,
608 InternalFormat::SupportCheckFunction textureAttachmentSupport,
609 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400610{
611 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400612 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400613 formatInfo.sized = sized;
614 formatInfo.sizedInternalFormat =
615 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400616 formatInfo.depthBits = depthBits;
617 formatInfo.stencilBits = stencilBits;
618 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
619 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
620 formatInfo.format = format;
621 formatInfo.type = type;
622 formatInfo.componentType = componentType;
623 formatInfo.colorEncoding = GL_LINEAR;
624 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400625 formatInfo.filterSupport = filterSupport;
626 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
627 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400628
629 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400630}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631
Geoff Langca271392017-04-05 12:30:00 -0400632void AddCompressedFormat(InternalFormatInfoMap *map,
633 GLenum internalFormat,
634 GLuint compressedBlockWidth,
635 GLuint compressedBlockHeight,
636 GLuint compressedBlockSize,
637 GLuint componentCount,
638 GLenum format,
639 GLenum type,
640 bool srgb,
641 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400642 InternalFormat::SupportCheckFunction filterSupport,
643 InternalFormat::SupportCheckFunction textureAttachmentSupport,
644 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400645{
646 InternalFormat formatInfo;
Geoff Langcb8a9212018-06-28 12:30:36 -0400647 formatInfo.internalFormat = internalFormat;
648 formatInfo.sized = true;
649 formatInfo.sizedInternalFormat = internalFormat;
650 formatInfo.compressedBlockWidth = compressedBlockWidth;
651 formatInfo.compressedBlockHeight = compressedBlockHeight;
652 formatInfo.pixelBytes = compressedBlockSize / 8;
653 formatInfo.componentCount = componentCount;
654 formatInfo.format = format;
655 formatInfo.type = type;
656 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
657 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
658 formatInfo.compressed = true;
659 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400660 formatInfo.filterSupport = filterSupport;
661 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
662 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400663
664 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400665}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000666
Geoff Lange4a492b2014-06-19 14:14:41 -0400667static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000668{
669 InternalFormatInfoMap map;
670
671 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400672 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000673
Jamie Madilla3944d42016-07-22 22:13:26 -0400674 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000675
Yuly Novikovf15f8862018-06-04 18:59:41 -0400676 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
677 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> );
678 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 );
679 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> );
680 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 );
681 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> );
682 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 );
683 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> );
684 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> );
685 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> );
686 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> );
687 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 );
688 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> );
689 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> );
690 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 );
691 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> );
692 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 );
693 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> );
694 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> );
695 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> );
696 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> );
697 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> );
698 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> );
699 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> );
700 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> );
701 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> );
702 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> );
703 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> );
704 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> );
705 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> );
706 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
707 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 );
708 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
709 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 );
710 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
711 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 );
712 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> );
713 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> );
714 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> );
715 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> );
716 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> );
717 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 -0400718
Yuly Novikovf15f8862018-06-04 18:59:41 -0400719 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>);
720 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>);
721 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 +0000722
Olli Etuahoceffd202018-01-08 16:39:45 +0200723 // Special format that is used for D3D textures that are used within ANGLE via the
724 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
725 // this format, but textures in this format can be created from D3D textures, and filtering them
726 // and rendering to them is allowed.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400727 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 +0200728
Jamie Madillec0b5802016-07-04 13:11:59 -0400729 // Special format which is not really supported, so always false for all supports.
Geoff Langcb8a9212018-06-28 12:30:36 -0400730 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 -0400731 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 -0400732
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000733 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Yuly Novikovf15f8862018-06-04 18:59:41 -0400734 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
735 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 );
736 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 );
737 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 );
738 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);
739 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
740 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
741 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGBRenderableSupport, FloatRGBRenderableSupport );
742 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 +0000743
744 // Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400745 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
746 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> );
747 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> );
748 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> );
749 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> );
750 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>);
751 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 -0800752 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000753
754 // Luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400755 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
756 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
757 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
758 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
759 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);
760 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);
761 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);
762 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
763 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
764 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 +0000765
766 // Compressed formats, From ES 3.0.1 spec, table 3.16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400767 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
768 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
769 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);
770 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
771 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);
772 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
773 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
774 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);
775 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);
776 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);
777 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 +0000778
779 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400780 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
781 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
782 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 +0000783
784 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400785 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 +0000786
787 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400788 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 -0400789
790 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400791 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 +0000792
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800793 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400794 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
795 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
796 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);
797 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);
798 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 -0800799
Geoff Lang60ad73d2015-10-23 10:08:44 -0400800 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400801 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
802 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);
803 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);
804 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);
805 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);
806 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);
807 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);
808 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);
809 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);
810 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);
811 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);
812 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);
813 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);
814 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);
815 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 -0400816
Yuly Novikovf15f8862018-06-04 18:59:41 -0400817 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);
818 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);
819 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);
820 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);
821 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);
822 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);
823 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);
824 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);
825 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);
826 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);
827 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);
828 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);
829 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);
830 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 -0400831
Corentin Walleze0902642014-11-04 12:32:15 -0800832 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
833 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
834 // - All other stencil formats (all depth-stencil) are either float or normalized
835 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400836 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
837 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 -0800838
839 // From GL_ANGLE_lossy_etc_decode
Yuly Novikovf15f8862018-06-04 18:59:41 -0400840 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
841 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
842 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);
843 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);
844 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);
845 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 -0800846
Vincent Lang25ab4512016-05-13 18:13:59 +0200847 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400848 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
849 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>);
850 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 );
851 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>);
852 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 );
853 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 );
854 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 );
855 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>);
856 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 +0200857
Geoff Langca271392017-04-05 12:30:00 -0400858 // Unsized formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400859 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
860 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 );
861 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
862 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 );
863 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
864 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 );
865 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> );
866 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
867 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> );
868 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> );
869 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> );
870 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> );
871 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
872 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 );
873 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> );
874 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 -0400875
876 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400877 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
878 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);
879 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);
880 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);
881 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);
882 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);
883 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);
884 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);
885 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);
886 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);
887 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);
888 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);
889 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);
890 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);
891 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);
892 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);
893 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);
894 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);
895 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);
896 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);
897 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);
898 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);
899 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);
900 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);
901 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);
902 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 -0400903
904 // Unsized floating point formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400905 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
906 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
907 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
908 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
909 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
910 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);
911 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);
912 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 );
913 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 );
914 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
915 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
916 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGBRenderableSupport, UnsizedFloatRGBRenderableSupport );
917 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 );
918 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 );
919 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 -0400920
921 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400922 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
923 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
924 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
925 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
926 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
927 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
928 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);
929 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
930 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
931 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 -0400932
933 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400934 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
935 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> );
936 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> );
937 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> );
938 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>);
939 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>);
940 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 -0400941 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800942
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000943 return map;
944}
945
Geoff Lange4a492b2014-06-19 14:14:41 -0400946static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000947{
Geoff Lange4a492b2014-06-19 14:14:41 -0400948 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
949 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000950}
951
Geoff Lange4a492b2014-06-19 14:14:41 -0400952static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400953{
954 FormatSet result;
955
Geoff Langca271392017-04-05 12:30:00 -0400956 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400957 {
Geoff Langca271392017-04-05 12:30:00 -0400958 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400959 {
Geoff Langca271392017-04-05 12:30:00 -0400960 if (type.second.sized)
961 {
962 // TODO(jmadill): Fix this hack.
963 if (internalFormat.first == GL_BGR565_ANGLEX)
964 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400965
Geoff Langca271392017-04-05 12:30:00 -0400966 result.insert(internalFormat.first);
967 }
Geoff Langcec35902014-04-16 10:52:36 -0400968 }
969 }
970
971 return result;
972}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000973
Geoff Lang5d601382014-07-22 15:14:06 -0400974const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000975{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200976 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000977 {
Frank Henigman95fb2a12018-05-27 20:17:05 -0400978 case GL_UNSIGNED_BYTE:
979 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200980 {
981 static const Type info = GenTypeInfo(1, false);
982 return info;
983 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400984 case GL_UNSIGNED_SHORT:
985 case GL_SHORT:
986 case GL_HALF_FLOAT:
987 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200988 {
989 static const Type info = GenTypeInfo(2, false);
990 return info;
991 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400992 case GL_UNSIGNED_INT:
993 case GL_INT:
994 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200995 {
996 static const Type info = GenTypeInfo(4, false);
997 return info;
998 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400999 case GL_UNSIGNED_SHORT_5_6_5:
1000 case GL_UNSIGNED_SHORT_4_4_4_4:
1001 case GL_UNSIGNED_SHORT_5_5_5_1:
1002 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1003 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001004 {
1005 static const Type info = GenTypeInfo(2, true);
1006 return info;
1007 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001008 case GL_UNSIGNED_INT_2_10_10_10_REV:
1009 case GL_UNSIGNED_INT_24_8:
1010 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1011 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001012 {
1013 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1014 static const Type info = GenTypeInfo(4, true);
1015 return info;
1016 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001017 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001018 {
1019 static const Type info = GenTypeInfo(8, true);
1020 return info;
1021 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001022 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001023 {
1024 static const Type defaultInfo;
1025 return defaultInfo;
1026 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001027 }
1028}
1029
Geoff Langca271392017-04-05 12:30:00 -04001030const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001031{
Geoff Langca271392017-04-05 12:30:00 -04001032 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001033 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001034 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001035
1036 // Sized internal formats only have one type per entry
1037 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001038 {
Geoff Lang5d601382014-07-22 15:14:06 -04001039 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001040 }
Geoff Langca271392017-04-05 12:30:00 -04001041
1042 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1043 if (!internalFormatInfo.sized)
1044 {
1045 return defaultInternalFormat;
1046 }
1047
1048 return internalFormatInfo;
1049}
1050
1051const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1052{
1053 static const InternalFormat defaultInternalFormat;
1054 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1055
1056 auto internalFormatIter = formatMap.find(internalFormat);
1057 if (internalFormatIter == formatMap.end())
1058 {
1059 return defaultInternalFormat;
1060 }
1061
1062 // If the internal format is sized, simply return it without the type check.
1063 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1064 {
1065 return internalFormatIter->second.begin()->second;
1066 }
1067
1068 auto typeIter = internalFormatIter->second.find(type);
1069 if (typeIter == internalFormatIter->second.end())
1070 {
1071 return defaultInternalFormat;
1072 }
1073
1074 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001075}
1076
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001077GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1078{
1079 const auto &typeInfo = GetTypeInfo(formatType);
1080 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1081 return components * typeInfo.bytes;
1082}
1083
Corentin Wallez886de362016-09-27 10:49:35 -04001084ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001085 GLsizei width,
1086 GLint alignment,
1087 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001088{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001089 // Compressed images do not use pack/unpack parameters.
1090 if (compressed)
1091 {
1092 ASSERT(rowLength == 0);
Jeff Gilbert48590352017-11-07 16:03:38 -08001093 return computeCompressedImageSize(Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001094 }
1095
Geoff Lang3f234062016-07-13 15:35:45 -04001096 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001097 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001098
1099 ASSERT(alignment > 0 && isPow2(alignment));
1100 CheckedNumeric<GLuint> checkedAlignment(alignment);
1101 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1102 ANGLE_TRY_CHECKED_MATH(aligned);
1103 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001104}
1105
Corentin Wallez0e487192016-10-03 16:30:38 -04001106ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1107 GLint imageHeight,
1108 GLuint rowPitch) const
1109{
1110 GLuint rows =
1111 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1112 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1113
1114 auto depthPitch = checkedRowPitch * rows;
1115 ANGLE_TRY_CHECKED_MATH(depthPitch);
1116 return depthPitch.ValueOrDie();
1117}
1118
Corentin Wallez886de362016-09-27 10:49:35 -04001119ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001120 GLsizei width,
1121 GLsizei height,
1122 GLint alignment,
1123 GLint rowLength,
1124 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001125{
Jamie Madille2e406c2016-06-02 13:04:10 -04001126 GLuint rowPitch = 0;
1127 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001128 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001129}
1130
Jeff Gilbert48590352017-11-07 16:03:38 -08001131ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001132{
Jamie Madill513558d2016-06-02 13:04:11 -04001133 CheckedNumeric<GLuint> checkedWidth(size.width);
1134 CheckedNumeric<GLuint> checkedHeight(size.height);
1135 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001136 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1137 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001138
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001139 ASSERT(compressed);
1140 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1141 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1142 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1143 ANGLE_TRY_CHECKED_MATH(bytes);
1144 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001145}
1146
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001147ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLenum formatType,
1148 GLuint rowPitch,
1149 GLuint depthPitch,
1150 const PixelStoreStateBase &state,
1151 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001152{
Olli Etuaho989cac32016-06-08 16:18:49 -07001153 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1154 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001155 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1156 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1157 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001158 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001159 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001160 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001161 {
1162 checkedSkipImagesBytes = 0;
1163 }
1164 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1165 checkedSkipPixels * checkedPixelBytes;
1166 ANGLE_TRY_CHECKED_MATH(skipBytes);
1167 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001168}
1169
Frank Henigman95fb2a12018-05-27 20:17:05 -04001170ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(GLenum formatType,
1171 const Extents &size,
1172 const PixelStoreStateBase &state,
1173 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001174{
Corentin Wallez886de362016-09-27 10:49:35 -04001175 GLuint rowPitch = 0;
1176 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001177 rowPitch);
1178
Corentin Wallez0e487192016-10-03 16:30:38 -04001179 GLuint depthPitch = 0;
1180 if (is3D)
1181 {
1182 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1183 }
1184
Corentin Wallez886de362016-09-27 10:49:35 -04001185 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001186 if (compressed)
1187 {
Jeff Gilbert48590352017-11-07 16:03:38 -08001188 ANGLE_TRY_RESULT(computeCompressedImageSize(size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001189 }
Corentin Wallez886de362016-09-27 10:49:35 -04001190 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001191 {
Corentin Wallez886de362016-09-27 10:49:35 -04001192 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1193 checkedCopyBytes += size.width * bytes;
1194
1195 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1196 checkedCopyBytes += heightMinusOne * rowPitch;
1197
1198 if (is3D)
1199 {
1200 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1201 checkedCopyBytes += depthMinusOne * depthPitch;
1202 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001203 }
1204
Corentin Wallez886de362016-09-27 10:49:35 -04001205 CheckedNumeric<GLuint> checkedSkipBytes = 0;
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001206 ANGLE_TRY_RESULT(computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D),
1207 checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001208
1209 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1210
1211 ANGLE_TRY_CHECKED_MATH(endByte);
1212 return endByte.ValueOrDie();
1213}
1214
Geoff Langca271392017-04-05 12:30:00 -04001215GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001216{
Geoff Langca271392017-04-05 12:30:00 -04001217 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1218 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001219 {
Geoff Langca271392017-04-05 12:30:00 -04001220 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001221 }
Geoff Langca271392017-04-05 12:30:00 -04001222
1223 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001224}
1225
Geoff Lange4a492b2014-06-19 14:14:41 -04001226const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001227{
Geoff Lange4a492b2014-06-19 14:14:41 -04001228 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001229 return formatSet;
1230}
1231
Jamie Madill09e2d932015-07-14 16:40:31 -04001232AttributeType GetAttributeType(GLenum enumValue)
1233{
1234 switch (enumValue)
1235 {
1236 case GL_FLOAT:
1237 return ATTRIBUTE_FLOAT;
1238 case GL_FLOAT_VEC2:
1239 return ATTRIBUTE_VEC2;
1240 case GL_FLOAT_VEC3:
1241 return ATTRIBUTE_VEC3;
1242 case GL_FLOAT_VEC4:
1243 return ATTRIBUTE_VEC4;
1244 case GL_INT:
1245 return ATTRIBUTE_INT;
1246 case GL_INT_VEC2:
1247 return ATTRIBUTE_IVEC2;
1248 case GL_INT_VEC3:
1249 return ATTRIBUTE_IVEC3;
1250 case GL_INT_VEC4:
1251 return ATTRIBUTE_IVEC4;
1252 case GL_UNSIGNED_INT:
1253 return ATTRIBUTE_UINT;
1254 case GL_UNSIGNED_INT_VEC2:
1255 return ATTRIBUTE_UVEC2;
1256 case GL_UNSIGNED_INT_VEC3:
1257 return ATTRIBUTE_UVEC3;
1258 case GL_UNSIGNED_INT_VEC4:
1259 return ATTRIBUTE_UVEC4;
1260 case GL_FLOAT_MAT2:
1261 return ATTRIBUTE_MAT2;
1262 case GL_FLOAT_MAT3:
1263 return ATTRIBUTE_MAT3;
1264 case GL_FLOAT_MAT4:
1265 return ATTRIBUTE_MAT4;
1266 case GL_FLOAT_MAT2x3:
1267 return ATTRIBUTE_MAT2x3;
1268 case GL_FLOAT_MAT2x4:
1269 return ATTRIBUTE_MAT2x4;
1270 case GL_FLOAT_MAT3x2:
1271 return ATTRIBUTE_MAT3x2;
1272 case GL_FLOAT_MAT3x4:
1273 return ATTRIBUTE_MAT3x4;
1274 case GL_FLOAT_MAT4x2:
1275 return ATTRIBUTE_MAT4x2;
1276 case GL_FLOAT_MAT4x3:
1277 return ATTRIBUTE_MAT4x3;
1278 default:
1279 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001280#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001281 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001282#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001283 }
1284}
1285
Frank Henigman95fb2a12018-05-27 20:17:05 -04001286angle::Format::ID GetVertexFormatID(GLenum type,
1287 GLboolean normalized,
1288 GLuint components,
1289 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001290{
1291 switch (type)
1292 {
1293 case GL_BYTE:
1294 switch (components)
1295 {
1296 case 1:
1297 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001298 return angle::Format::ID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001299 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001300 return angle::Format::ID::R8_SNORM;
1301 return angle::Format::ID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001302 case 2:
1303 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001304 return angle::Format::ID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001305 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001306 return angle::Format::ID::R8G8_SNORM;
1307 return angle::Format::ID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001308 case 3:
1309 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001310 return angle::Format::ID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001311 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001312 return angle::Format::ID::R8G8B8_SNORM;
1313 return angle::Format::ID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001314 case 4:
1315 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001316 return angle::Format::ID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001317 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001318 return angle::Format::ID::R8G8B8A8_SNORM;
1319 return angle::Format::ID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001320 default:
1321 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001322#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001323 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001324#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001325 }
1326 case GL_UNSIGNED_BYTE:
1327 switch (components)
1328 {
1329 case 1:
1330 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001331 return angle::Format::ID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001332 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001333 return angle::Format::ID::R8_UNORM;
1334 return angle::Format::ID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001335 case 2:
1336 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001337 return angle::Format::ID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001338 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001339 return angle::Format::ID::R8G8_UNORM;
1340 return angle::Format::ID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001341 case 3:
1342 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001343 return angle::Format::ID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001344 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001345 return angle::Format::ID::R8G8B8_UNORM;
1346 return angle::Format::ID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001347 case 4:
1348 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001349 return angle::Format::ID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001350 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001351 return angle::Format::ID::R8G8B8A8_UNORM;
1352 return angle::Format::ID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001353 default:
1354 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001355#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001356 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001357#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001358 }
1359 case GL_SHORT:
1360 switch (components)
1361 {
1362 case 1:
1363 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001364 return angle::Format::ID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001365 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001366 return angle::Format::ID::R16_SNORM;
1367 return angle::Format::ID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001368 case 2:
1369 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001370 return angle::Format::ID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001371 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001372 return angle::Format::ID::R16G16_SNORM;
1373 return angle::Format::ID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001374 case 3:
1375 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001376 return angle::Format::ID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001377 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001378 return angle::Format::ID::R16G16B16_SNORM;
1379 return angle::Format::ID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001380 case 4:
1381 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001382 return angle::Format::ID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001383 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001384 return angle::Format::ID::R16G16B16A16_SNORM;
1385 return angle::Format::ID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001386 default:
1387 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001388#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001389 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001390#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001391 }
1392 case GL_UNSIGNED_SHORT:
1393 switch (components)
1394 {
1395 case 1:
1396 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001397 return angle::Format::ID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001398 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001399 return angle::Format::ID::R16_UNORM;
1400 return angle::Format::ID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001401 case 2:
1402 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001403 return angle::Format::ID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001404 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001405 return angle::Format::ID::R16G16_UNORM;
1406 return angle::Format::ID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001407 case 3:
1408 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001409 return angle::Format::ID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001410 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001411 return angle::Format::ID::R16G16B16_UNORM;
1412 return angle::Format::ID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001413 case 4:
1414 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001415 return angle::Format::ID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001416 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001417 return angle::Format::ID::R16G16B16A16_UNORM;
1418 return angle::Format::ID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001419 default:
1420 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001421#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001422 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001423#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001424 }
1425 case GL_INT:
1426 switch (components)
1427 {
1428 case 1:
1429 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001430 return angle::Format::ID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001431 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001432 return angle::Format::ID::R32_SNORM;
1433 return angle::Format::ID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001434 case 2:
1435 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001436 return angle::Format::ID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001437 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001438 return angle::Format::ID::R32G32_SNORM;
1439 return angle::Format::ID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001440 case 3:
1441 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001442 return angle::Format::ID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001443 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001444 return angle::Format::ID::R32G32B32_SNORM;
1445 return angle::Format::ID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001446 case 4:
1447 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001448 return angle::Format::ID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001449 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001450 return angle::Format::ID::R32G32B32A32_SNORM;
1451 return angle::Format::ID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001452 default:
1453 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001454#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001455 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001456#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001457 }
1458 case GL_UNSIGNED_INT:
1459 switch (components)
1460 {
1461 case 1:
1462 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001463 return angle::Format::ID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001464 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001465 return angle::Format::ID::R32_UNORM;
1466 return angle::Format::ID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001467 case 2:
1468 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001469 return angle::Format::ID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001470 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001471 return angle::Format::ID::R32G32_UNORM;
1472 return angle::Format::ID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001473 case 3:
1474 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001475 return angle::Format::ID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001476 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001477 return angle::Format::ID::R32G32B32_UNORM;
1478 return angle::Format::ID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001479 case 4:
1480 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001481 return angle::Format::ID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001482 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001483 return angle::Format::ID::R32G32B32A32_UNORM;
1484 return angle::Format::ID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001485 default:
1486 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001487#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001488 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001489#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001490 }
1491 case GL_FLOAT:
1492 switch (components)
1493 {
1494 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001495 return angle::Format::ID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001496 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001497 return angle::Format::ID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001498 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001499 return angle::Format::ID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001500 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001501 return angle::Format::ID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001502 default:
1503 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001504#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001505 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001506#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001507 }
1508 case GL_HALF_FLOAT:
1509 switch (components)
1510 {
1511 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001512 return angle::Format::ID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001513 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001514 return angle::Format::ID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001515 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001516 return angle::Format::ID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001517 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001518 return angle::Format::ID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001519 default:
1520 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001521#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001522 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001523#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001524 }
1525 case GL_FIXED:
1526 switch (components)
1527 {
1528 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001529 return angle::Format::ID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001530 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001531 return angle::Format::ID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001532 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001533 return angle::Format::ID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001534 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001535 return angle::Format::ID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001536 default:
1537 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001538#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001539 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001540#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001541 }
1542 case GL_INT_2_10_10_10_REV:
1543 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001544 return angle::Format::ID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001545 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001546 return angle::Format::ID::R10G10B10A2_SNORM;
1547 return angle::Format::ID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001548 case GL_UNSIGNED_INT_2_10_10_10_REV:
1549 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001550 return angle::Format::ID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001551 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001552 return angle::Format::ID::R10G10B10A2_UNORM;
1553 return angle::Format::ID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001554 default:
1555 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001556#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001557 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001558#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001559 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001560}
1561
Frank Henigman95fb2a12018-05-27 20:17:05 -04001562angle::Format::ID GetVertexFormatID(const VertexAttribute &attrib)
1563{
1564 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1565}
1566
1567// TODO(fjhenigman): Do away with VertexFormatType; use angle::Format::ID instead. anglebug.com/2531
1568VertexFormatType GetVertexFormatType(GLenum type,
1569 GLboolean normalized,
1570 GLuint components,
1571 bool pureInteger)
1572{
1573 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1574 {
1575 case angle::Format::ID::R8_SINT:
1576 return VERTEX_FORMAT_SBYTE1_INT;
1577 case angle::Format::ID::R8_SNORM:
1578 return VERTEX_FORMAT_SBYTE1_NORM;
1579 case angle::Format::ID::R8_SSCALED:
1580 return VERTEX_FORMAT_SBYTE1;
1581 case angle::Format::ID::R8G8_SINT:
1582 return VERTEX_FORMAT_SBYTE2_INT;
1583 case angle::Format::ID::R8G8_SNORM:
1584 return VERTEX_FORMAT_SBYTE2_NORM;
1585 case angle::Format::ID::R8G8_SSCALED:
1586 return VERTEX_FORMAT_SBYTE2;
1587 case angle::Format::ID::R8G8B8_SINT:
1588 return VERTEX_FORMAT_SBYTE3_INT;
1589 case angle::Format::ID::R8G8B8_SNORM:
1590 return VERTEX_FORMAT_SBYTE3_NORM;
1591 case angle::Format::ID::R8G8B8_SSCALED:
1592 return VERTEX_FORMAT_SBYTE3;
1593 case angle::Format::ID::R8G8B8A8_SINT:
1594 return VERTEX_FORMAT_SBYTE4_INT;
1595 case angle::Format::ID::R8G8B8A8_SNORM:
1596 return VERTEX_FORMAT_SBYTE4_NORM;
1597 case angle::Format::ID::R8G8B8A8_SSCALED:
1598 return VERTEX_FORMAT_SBYTE4;
1599 case angle::Format::ID::R8_UINT:
1600 return VERTEX_FORMAT_UBYTE1_INT;
1601 case angle::Format::ID::R8_UNORM:
1602 return VERTEX_FORMAT_UBYTE1_NORM;
1603 case angle::Format::ID::R8_USCALED:
1604 return VERTEX_FORMAT_UBYTE1;
1605 case angle::Format::ID::R8G8_UINT:
1606 return VERTEX_FORMAT_UBYTE2_INT;
1607 case angle::Format::ID::R8G8_UNORM:
1608 return VERTEX_FORMAT_UBYTE2_NORM;
1609 case angle::Format::ID::R8G8_USCALED:
1610 return VERTEX_FORMAT_UBYTE2;
1611 case angle::Format::ID::R8G8B8_UINT:
1612 return VERTEX_FORMAT_UBYTE3_INT;
1613 case angle::Format::ID::R8G8B8_UNORM:
1614 return VERTEX_FORMAT_UBYTE3_NORM;
1615 case angle::Format::ID::R8G8B8_USCALED:
1616 return VERTEX_FORMAT_UBYTE3;
1617 case angle::Format::ID::R8G8B8A8_UINT:
1618 return VERTEX_FORMAT_UBYTE4_INT;
1619 case angle::Format::ID::R8G8B8A8_UNORM:
1620 return VERTEX_FORMAT_UBYTE4_NORM;
1621 case angle::Format::ID::R8G8B8A8_USCALED:
1622 return VERTEX_FORMAT_UBYTE4;
1623 case angle::Format::ID::R16_SINT:
1624 return VERTEX_FORMAT_SSHORT1_INT;
1625 case angle::Format::ID::R16_SNORM:
1626 return VERTEX_FORMAT_SSHORT1_NORM;
1627 case angle::Format::ID::R16_SSCALED:
1628 return VERTEX_FORMAT_SSHORT1;
1629 case angle::Format::ID::R16G16_SINT:
1630 return VERTEX_FORMAT_SSHORT2_INT;
1631 case angle::Format::ID::R16G16_SNORM:
1632 return VERTEX_FORMAT_SSHORT2_NORM;
1633 case angle::Format::ID::R16G16_SSCALED:
1634 return VERTEX_FORMAT_SSHORT2;
1635 case angle::Format::ID::R16G16B16_SINT:
1636 return VERTEX_FORMAT_SSHORT3_INT;
1637 case angle::Format::ID::R16G16B16_SNORM:
1638 return VERTEX_FORMAT_SSHORT3_NORM;
1639 case angle::Format::ID::R16G16B16_SSCALED:
1640 return VERTEX_FORMAT_SSHORT3;
1641 case angle::Format::ID::R16G16B16A16_SINT:
1642 return VERTEX_FORMAT_SSHORT4_INT;
1643 case angle::Format::ID::R16G16B16A16_SNORM:
1644 return VERTEX_FORMAT_SSHORT4_NORM;
1645 case angle::Format::ID::R16G16B16A16_SSCALED:
1646 return VERTEX_FORMAT_SSHORT4;
1647 case angle::Format::ID::R16_UINT:
1648 return VERTEX_FORMAT_USHORT1_INT;
1649 case angle::Format::ID::R16_UNORM:
1650 return VERTEX_FORMAT_USHORT1_NORM;
1651 case angle::Format::ID::R16_USCALED:
1652 return VERTEX_FORMAT_USHORT1;
1653 case angle::Format::ID::R16G16_UINT:
1654 return VERTEX_FORMAT_USHORT2_INT;
1655 case angle::Format::ID::R16G16_UNORM:
1656 return VERTEX_FORMAT_USHORT2_NORM;
1657 case angle::Format::ID::R16G16_USCALED:
1658 return VERTEX_FORMAT_USHORT2;
1659 case angle::Format::ID::R16G16B16_UINT:
1660 return VERTEX_FORMAT_USHORT3_INT;
1661 case angle::Format::ID::R16G16B16_UNORM:
1662 return VERTEX_FORMAT_USHORT3_NORM;
1663 case angle::Format::ID::R16G16B16_USCALED:
1664 return VERTEX_FORMAT_USHORT3;
1665 case angle::Format::ID::R16G16B16A16_UINT:
1666 return VERTEX_FORMAT_USHORT4_INT;
1667 case angle::Format::ID::R16G16B16A16_UNORM:
1668 return VERTEX_FORMAT_USHORT4_NORM;
1669 case angle::Format::ID::R16G16B16A16_USCALED:
1670 return VERTEX_FORMAT_USHORT4;
1671 case angle::Format::ID::R32_SINT:
1672 return VERTEX_FORMAT_SINT1_INT;
1673 case angle::Format::ID::R32_SNORM:
1674 return VERTEX_FORMAT_SINT1_NORM;
1675 case angle::Format::ID::R32_SSCALED:
1676 return VERTEX_FORMAT_SINT1;
1677 case angle::Format::ID::R32G32_SINT:
1678 return VERTEX_FORMAT_SINT2_INT;
1679 case angle::Format::ID::R32G32_SNORM:
1680 return VERTEX_FORMAT_SINT2_NORM;
1681 case angle::Format::ID::R32G32_SSCALED:
1682 return VERTEX_FORMAT_SINT2;
1683 case angle::Format::ID::R32G32B32_SINT:
1684 return VERTEX_FORMAT_SINT3_INT;
1685 case angle::Format::ID::R32G32B32_SNORM:
1686 return VERTEX_FORMAT_SINT3_NORM;
1687 case angle::Format::ID::R32G32B32_SSCALED:
1688 return VERTEX_FORMAT_SINT3;
1689 case angle::Format::ID::R32G32B32A32_SINT:
1690 return VERTEX_FORMAT_SINT4_INT;
1691 case angle::Format::ID::R32G32B32A32_SNORM:
1692 return VERTEX_FORMAT_SINT4_NORM;
1693 case angle::Format::ID::R32G32B32A32_SSCALED:
1694 return VERTEX_FORMAT_SINT4;
1695 case angle::Format::ID::R32_UINT:
1696 return VERTEX_FORMAT_UINT1_INT;
1697 case angle::Format::ID::R32_UNORM:
1698 return VERTEX_FORMAT_UINT1_NORM;
1699 case angle::Format::ID::R32_USCALED:
1700 return VERTEX_FORMAT_UINT1;
1701 case angle::Format::ID::R32G32_UINT:
1702 return VERTEX_FORMAT_UINT2_INT;
1703 case angle::Format::ID::R32G32_UNORM:
1704 return VERTEX_FORMAT_UINT2_NORM;
1705 case angle::Format::ID::R32G32_USCALED:
1706 return VERTEX_FORMAT_UINT2;
1707 case angle::Format::ID::R32G32B32_UINT:
1708 return VERTEX_FORMAT_UINT3_INT;
1709 case angle::Format::ID::R32G32B32_UNORM:
1710 return VERTEX_FORMAT_UINT3_NORM;
1711 case angle::Format::ID::R32G32B32_USCALED:
1712 return VERTEX_FORMAT_UINT3;
1713 case angle::Format::ID::R32G32B32A32_UINT:
1714 return VERTEX_FORMAT_UINT4_INT;
1715 case angle::Format::ID::R32G32B32A32_UNORM:
1716 return VERTEX_FORMAT_UINT4_NORM;
1717 case angle::Format::ID::R32G32B32A32_USCALED:
1718 return VERTEX_FORMAT_UINT4;
1719 case angle::Format::ID::R32_FLOAT:
1720 return VERTEX_FORMAT_FLOAT1;
1721 case angle::Format::ID::R32G32_FLOAT:
1722 return VERTEX_FORMAT_FLOAT2;
1723 case angle::Format::ID::R32G32B32_FLOAT:
1724 return VERTEX_FORMAT_FLOAT3;
1725 case angle::Format::ID::R32G32B32A32_FLOAT:
1726 return VERTEX_FORMAT_FLOAT4;
1727 case angle::Format::ID::R16_FLOAT:
1728 return VERTEX_FORMAT_HALF1;
1729 case angle::Format::ID::R16G16_FLOAT:
1730 return VERTEX_FORMAT_HALF2;
1731 case angle::Format::ID::R16G16B16_FLOAT:
1732 return VERTEX_FORMAT_HALF3;
1733 case angle::Format::ID::R16G16B16A16_FLOAT:
1734 return VERTEX_FORMAT_HALF4;
1735 case angle::Format::ID::R32_FIXED:
1736 return VERTEX_FORMAT_FIXED1;
1737 case angle::Format::ID::R32G32_FIXED:
1738 return VERTEX_FORMAT_FIXED2;
1739 case angle::Format::ID::R32G32B32_FIXED:
1740 return VERTEX_FORMAT_FIXED3;
1741 case angle::Format::ID::R32G32B32A32_FIXED:
1742 return VERTEX_FORMAT_FIXED4;
1743 case angle::Format::ID::R10G10B10A2_SINT:
1744 return VERTEX_FORMAT_SINT210_INT;
1745 case angle::Format::ID::R10G10B10A2_SNORM:
1746 return VERTEX_FORMAT_SINT210_NORM;
1747 case angle::Format::ID::R10G10B10A2_SSCALED:
1748 return VERTEX_FORMAT_SINT210;
1749 case angle::Format::ID::R10G10B10A2_UINT:
1750 return VERTEX_FORMAT_UINT210_INT;
1751 case angle::Format::ID::R10G10B10A2_UNORM:
1752 return VERTEX_FORMAT_UINT210_NORM;
1753 case angle::Format::ID::R10G10B10A2_USCALED:
1754 return VERTEX_FORMAT_UINT210;
1755 default:
1756 return VERTEX_FORMAT_INVALID;
1757 }
1758}
1759
Jamie Madilld3dfda22015-07-06 08:28:49 -04001760VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1761{
1762 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1763}
1764
1765VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1766{
1767 if (!attrib.enabled)
1768 {
1769 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1770 }
1771 return GetVertexFormatType(attrib);
1772}
1773
1774const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1775{
1776 switch (vertexFormatType)
1777 {
1778 case VERTEX_FORMAT_SBYTE1:
1779 {
1780 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1781 return format;
1782 }
1783 case VERTEX_FORMAT_SBYTE1_NORM:
1784 {
1785 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1786 return format;
1787 }
1788 case VERTEX_FORMAT_SBYTE2:
1789 {
1790 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1791 return format;
1792 }
1793 case VERTEX_FORMAT_SBYTE2_NORM:
1794 {
1795 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1796 return format;
1797 }
1798 case VERTEX_FORMAT_SBYTE3:
1799 {
1800 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1801 return format;
1802 }
1803 case VERTEX_FORMAT_SBYTE3_NORM:
1804 {
1805 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1806 return format;
1807 }
1808 case VERTEX_FORMAT_SBYTE4:
1809 {
1810 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1811 return format;
1812 }
1813 case VERTEX_FORMAT_SBYTE4_NORM:
1814 {
1815 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1816 return format;
1817 }
1818 case VERTEX_FORMAT_UBYTE1:
1819 {
1820 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1821 return format;
1822 }
1823 case VERTEX_FORMAT_UBYTE1_NORM:
1824 {
1825 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1826 return format;
1827 }
1828 case VERTEX_FORMAT_UBYTE2:
1829 {
1830 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1831 return format;
1832 }
1833 case VERTEX_FORMAT_UBYTE2_NORM:
1834 {
1835 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1836 return format;
1837 }
1838 case VERTEX_FORMAT_UBYTE3:
1839 {
1840 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1841 return format;
1842 }
1843 case VERTEX_FORMAT_UBYTE3_NORM:
1844 {
1845 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1846 return format;
1847 }
1848 case VERTEX_FORMAT_UBYTE4:
1849 {
1850 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1851 return format;
1852 }
1853 case VERTEX_FORMAT_UBYTE4_NORM:
1854 {
1855 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1856 return format;
1857 }
1858 case VERTEX_FORMAT_SSHORT1:
1859 {
1860 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1861 return format;
1862 }
1863 case VERTEX_FORMAT_SSHORT1_NORM:
1864 {
1865 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1866 return format;
1867 }
1868 case VERTEX_FORMAT_SSHORT2:
1869 {
1870 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1871 return format;
1872 }
1873 case VERTEX_FORMAT_SSHORT2_NORM:
1874 {
1875 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1876 return format;
1877 }
1878 case VERTEX_FORMAT_SSHORT3:
1879 {
1880 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1881 return format;
1882 }
1883 case VERTEX_FORMAT_SSHORT3_NORM:
1884 {
1885 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1886 return format;
1887 }
1888 case VERTEX_FORMAT_SSHORT4:
1889 {
1890 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1891 return format;
1892 }
1893 case VERTEX_FORMAT_SSHORT4_NORM:
1894 {
1895 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1896 return format;
1897 }
1898 case VERTEX_FORMAT_USHORT1:
1899 {
1900 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1901 return format;
1902 }
1903 case VERTEX_FORMAT_USHORT1_NORM:
1904 {
1905 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1906 return format;
1907 }
1908 case VERTEX_FORMAT_USHORT2:
1909 {
1910 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1911 return format;
1912 }
1913 case VERTEX_FORMAT_USHORT2_NORM:
1914 {
1915 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1916 return format;
1917 }
1918 case VERTEX_FORMAT_USHORT3:
1919 {
1920 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1921 return format;
1922 }
1923 case VERTEX_FORMAT_USHORT3_NORM:
1924 {
1925 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1926 return format;
1927 }
1928 case VERTEX_FORMAT_USHORT4:
1929 {
1930 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1931 return format;
1932 }
1933 case VERTEX_FORMAT_USHORT4_NORM:
1934 {
1935 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1936 return format;
1937 }
1938 case VERTEX_FORMAT_SINT1:
1939 {
1940 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1941 return format;
1942 }
1943 case VERTEX_FORMAT_SINT1_NORM:
1944 {
1945 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1946 return format;
1947 }
1948 case VERTEX_FORMAT_SINT2:
1949 {
1950 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1951 return format;
1952 }
1953 case VERTEX_FORMAT_SINT2_NORM:
1954 {
1955 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1956 return format;
1957 }
1958 case VERTEX_FORMAT_SINT3:
1959 {
1960 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1961 return format;
1962 }
1963 case VERTEX_FORMAT_SINT3_NORM:
1964 {
1965 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1966 return format;
1967 }
1968 case VERTEX_FORMAT_SINT4:
1969 {
1970 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1971 return format;
1972 }
1973 case VERTEX_FORMAT_SINT4_NORM:
1974 {
1975 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1976 return format;
1977 }
1978 case VERTEX_FORMAT_UINT1:
1979 {
1980 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1981 return format;
1982 }
1983 case VERTEX_FORMAT_UINT1_NORM:
1984 {
1985 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1986 return format;
1987 }
1988 case VERTEX_FORMAT_UINT2:
1989 {
1990 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1991 return format;
1992 }
1993 case VERTEX_FORMAT_UINT2_NORM:
1994 {
1995 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1996 return format;
1997 }
1998 case VERTEX_FORMAT_UINT3:
1999 {
2000 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2001 return format;
2002 }
2003 case VERTEX_FORMAT_UINT3_NORM:
2004 {
2005 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2006 return format;
2007 }
2008 case VERTEX_FORMAT_UINT4:
2009 {
2010 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2011 return format;
2012 }
2013 case VERTEX_FORMAT_UINT4_NORM:
2014 {
2015 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2016 return format;
2017 }
2018 case VERTEX_FORMAT_SBYTE1_INT:
2019 {
2020 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2021 return format;
2022 }
2023 case VERTEX_FORMAT_SBYTE2_INT:
2024 {
2025 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2026 return format;
2027 }
2028 case VERTEX_FORMAT_SBYTE3_INT:
2029 {
2030 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2031 return format;
2032 }
2033 case VERTEX_FORMAT_SBYTE4_INT:
2034 {
2035 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2036 return format;
2037 }
2038 case VERTEX_FORMAT_UBYTE1_INT:
2039 {
2040 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2041 return format;
2042 }
2043 case VERTEX_FORMAT_UBYTE2_INT:
2044 {
2045 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2046 return format;
2047 }
2048 case VERTEX_FORMAT_UBYTE3_INT:
2049 {
2050 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2051 return format;
2052 }
2053 case VERTEX_FORMAT_UBYTE4_INT:
2054 {
2055 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2056 return format;
2057 }
2058 case VERTEX_FORMAT_SSHORT1_INT:
2059 {
2060 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2061 return format;
2062 }
2063 case VERTEX_FORMAT_SSHORT2_INT:
2064 {
2065 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2066 return format;
2067 }
2068 case VERTEX_FORMAT_SSHORT3_INT:
2069 {
2070 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2071 return format;
2072 }
2073 case VERTEX_FORMAT_SSHORT4_INT:
2074 {
2075 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2076 return format;
2077 }
2078 case VERTEX_FORMAT_USHORT1_INT:
2079 {
2080 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2081 return format;
2082 }
2083 case VERTEX_FORMAT_USHORT2_INT:
2084 {
2085 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2086 return format;
2087 }
2088 case VERTEX_FORMAT_USHORT3_INT:
2089 {
2090 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2091 return format;
2092 }
2093 case VERTEX_FORMAT_USHORT4_INT:
2094 {
2095 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2096 return format;
2097 }
2098 case VERTEX_FORMAT_SINT1_INT:
2099 {
2100 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2101 return format;
2102 }
2103 case VERTEX_FORMAT_SINT2_INT:
2104 {
2105 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2106 return format;
2107 }
2108 case VERTEX_FORMAT_SINT3_INT:
2109 {
2110 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2111 return format;
2112 }
2113 case VERTEX_FORMAT_SINT4_INT:
2114 {
2115 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2116 return format;
2117 }
2118 case VERTEX_FORMAT_UINT1_INT:
2119 {
2120 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2121 return format;
2122 }
2123 case VERTEX_FORMAT_UINT2_INT:
2124 {
2125 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2126 return format;
2127 }
2128 case VERTEX_FORMAT_UINT3_INT:
2129 {
2130 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2131 return format;
2132 }
2133 case VERTEX_FORMAT_UINT4_INT:
2134 {
2135 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2136 return format;
2137 }
2138 case VERTEX_FORMAT_FIXED1:
2139 {
2140 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2141 return format;
2142 }
2143 case VERTEX_FORMAT_FIXED2:
2144 {
2145 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2146 return format;
2147 }
2148 case VERTEX_FORMAT_FIXED3:
2149 {
2150 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2151 return format;
2152 }
2153 case VERTEX_FORMAT_FIXED4:
2154 {
2155 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2156 return format;
2157 }
2158 case VERTEX_FORMAT_HALF1:
2159 {
2160 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2161 return format;
2162 }
2163 case VERTEX_FORMAT_HALF2:
2164 {
2165 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2166 return format;
2167 }
2168 case VERTEX_FORMAT_HALF3:
2169 {
2170 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2171 return format;
2172 }
2173 case VERTEX_FORMAT_HALF4:
2174 {
2175 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2176 return format;
2177 }
2178 case VERTEX_FORMAT_FLOAT1:
2179 {
2180 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2181 return format;
2182 }
2183 case VERTEX_FORMAT_FLOAT2:
2184 {
2185 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2186 return format;
2187 }
2188 case VERTEX_FORMAT_FLOAT3:
2189 {
2190 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2191 return format;
2192 }
2193 case VERTEX_FORMAT_FLOAT4:
2194 {
2195 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2196 return format;
2197 }
2198 case VERTEX_FORMAT_SINT210:
2199 {
2200 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2201 return format;
2202 }
2203 case VERTEX_FORMAT_UINT210:
2204 {
2205 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2206 return format;
2207 }
2208 case VERTEX_FORMAT_SINT210_NORM:
2209 {
2210 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2211 return format;
2212 }
2213 case VERTEX_FORMAT_UINT210_NORM:
2214 {
2215 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2216 return format;
2217 }
2218 case VERTEX_FORMAT_SINT210_INT:
2219 {
2220 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2221 return format;
2222 }
2223 case VERTEX_FORMAT_UINT210_INT:
2224 {
2225 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2226 return format;
2227 }
2228 default:
2229 {
2230 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2231 return format;
2232 }
2233 }
2234}
2235
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002236size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2237{
2238 switch (vertexFormatType)
2239 {
2240 case VERTEX_FORMAT_SBYTE1:
2241 case VERTEX_FORMAT_SBYTE1_NORM:
2242 case VERTEX_FORMAT_UBYTE1:
2243 case VERTEX_FORMAT_UBYTE1_NORM:
2244 case VERTEX_FORMAT_SBYTE1_INT:
2245 case VERTEX_FORMAT_UBYTE1_INT:
2246 return 1;
2247
2248 case VERTEX_FORMAT_SBYTE2:
2249 case VERTEX_FORMAT_SBYTE2_NORM:
2250 case VERTEX_FORMAT_UBYTE2:
2251 case VERTEX_FORMAT_UBYTE2_NORM:
2252 case VERTEX_FORMAT_SBYTE2_INT:
2253 case VERTEX_FORMAT_UBYTE2_INT:
2254 case VERTEX_FORMAT_SSHORT1:
2255 case VERTEX_FORMAT_SSHORT1_NORM:
2256 case VERTEX_FORMAT_USHORT1:
2257 case VERTEX_FORMAT_USHORT1_NORM:
2258 case VERTEX_FORMAT_SSHORT1_INT:
2259 case VERTEX_FORMAT_USHORT1_INT:
2260 case VERTEX_FORMAT_HALF1:
2261 return 2;
2262
2263 case VERTEX_FORMAT_SBYTE3:
2264 case VERTEX_FORMAT_SBYTE3_NORM:
2265 case VERTEX_FORMAT_UBYTE3:
2266 case VERTEX_FORMAT_UBYTE3_NORM:
2267 case VERTEX_FORMAT_SBYTE3_INT:
2268 case VERTEX_FORMAT_UBYTE3_INT:
2269 return 3;
2270
2271 case VERTEX_FORMAT_SBYTE4:
2272 case VERTEX_FORMAT_SBYTE4_NORM:
2273 case VERTEX_FORMAT_UBYTE4:
2274 case VERTEX_FORMAT_UBYTE4_NORM:
2275 case VERTEX_FORMAT_SBYTE4_INT:
2276 case VERTEX_FORMAT_UBYTE4_INT:
2277 case VERTEX_FORMAT_SSHORT2:
2278 case VERTEX_FORMAT_SSHORT2_NORM:
2279 case VERTEX_FORMAT_USHORT2:
2280 case VERTEX_FORMAT_USHORT2_NORM:
2281 case VERTEX_FORMAT_SSHORT2_INT:
2282 case VERTEX_FORMAT_USHORT2_INT:
2283 case VERTEX_FORMAT_SINT1:
2284 case VERTEX_FORMAT_SINT1_NORM:
2285 case VERTEX_FORMAT_UINT1:
2286 case VERTEX_FORMAT_UINT1_NORM:
2287 case VERTEX_FORMAT_SINT1_INT:
2288 case VERTEX_FORMAT_UINT1_INT:
2289 case VERTEX_FORMAT_HALF2:
2290 case VERTEX_FORMAT_FIXED1:
2291 case VERTEX_FORMAT_FLOAT1:
2292 case VERTEX_FORMAT_SINT210:
2293 case VERTEX_FORMAT_UINT210:
2294 case VERTEX_FORMAT_SINT210_NORM:
2295 case VERTEX_FORMAT_UINT210_NORM:
2296 case VERTEX_FORMAT_SINT210_INT:
2297 case VERTEX_FORMAT_UINT210_INT:
2298 return 4;
2299
2300 case VERTEX_FORMAT_SSHORT3:
2301 case VERTEX_FORMAT_SSHORT3_NORM:
2302 case VERTEX_FORMAT_USHORT3:
2303 case VERTEX_FORMAT_USHORT3_NORM:
2304 case VERTEX_FORMAT_SSHORT3_INT:
2305 case VERTEX_FORMAT_USHORT3_INT:
2306 case VERTEX_FORMAT_HALF3:
2307 return 6;
2308
2309 case VERTEX_FORMAT_SSHORT4:
2310 case VERTEX_FORMAT_SSHORT4_NORM:
2311 case VERTEX_FORMAT_USHORT4:
2312 case VERTEX_FORMAT_USHORT4_NORM:
2313 case VERTEX_FORMAT_SSHORT4_INT:
2314 case VERTEX_FORMAT_USHORT4_INT:
2315 case VERTEX_FORMAT_SINT2:
2316 case VERTEX_FORMAT_SINT2_NORM:
2317 case VERTEX_FORMAT_UINT2:
2318 case VERTEX_FORMAT_UINT2_NORM:
2319 case VERTEX_FORMAT_SINT2_INT:
2320 case VERTEX_FORMAT_UINT2_INT:
2321 case VERTEX_FORMAT_HALF4:
2322 case VERTEX_FORMAT_FIXED2:
2323 case VERTEX_FORMAT_FLOAT2:
2324 return 8;
2325
2326 case VERTEX_FORMAT_SINT3:
2327 case VERTEX_FORMAT_SINT3_NORM:
2328 case VERTEX_FORMAT_UINT3:
2329 case VERTEX_FORMAT_UINT3_NORM:
2330 case VERTEX_FORMAT_SINT3_INT:
2331 case VERTEX_FORMAT_UINT3_INT:
2332 case VERTEX_FORMAT_FIXED3:
2333 case VERTEX_FORMAT_FLOAT3:
2334 return 12;
2335
2336 case VERTEX_FORMAT_SINT4:
2337 case VERTEX_FORMAT_SINT4_NORM:
2338 case VERTEX_FORMAT_UINT4:
2339 case VERTEX_FORMAT_UINT4_NORM:
2340 case VERTEX_FORMAT_SINT4_INT:
2341 case VERTEX_FORMAT_UINT4_INT:
2342 case VERTEX_FORMAT_FIXED4:
2343 case VERTEX_FORMAT_FLOAT4:
2344 return 16;
2345
2346 case VERTEX_FORMAT_INVALID:
2347 default:
2348 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002349#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002350 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002351#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002352 }
2353}
2354
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002355bool ValidES3InternalFormat(GLenum internalFormat)
2356{
2357 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2358 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2359}
2360
Frank Henigman95fb2a12018-05-27 20:17:05 -04002361VertexFormat::VertexFormat(GLenum typeIn,
2362 GLboolean normalizedIn,
2363 GLuint componentsIn,
2364 bool pureIntegerIn)
2365 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002366{
2367 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002368 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2369 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002370}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002371}