blob: 7c1d6af4e0c061501e94ebf17893640e2ecbb6cb [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);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400551 formatInfo.format = format;
552 formatInfo.type = type;
553 formatInfo.componentType = componentType;
554 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
Geoff Lang5d601382014-07-22 15:14:06 -0400555 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);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400581 formatInfo.luminanceBits = luminance;
582 formatInfo.alphaBits = alpha;
583 formatInfo.pixelBytes = (luminance + alpha) / 8;
Geoff Lang5d601382014-07-22 15:14:06 -0400584 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400585 formatInfo.format = format;
586 formatInfo.type = type;
587 formatInfo.componentType = componentType;
588 formatInfo.colorEncoding = GL_LINEAR;
Geoff Lang5d601382014-07-22 15:14:06 -0400589 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);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400616 formatInfo.depthBits = depthBits;
617 formatInfo.stencilBits = stencilBits;
618 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
Geoff Lang5d601382014-07-22 15:14:06 -0400619 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400620 formatInfo.format = format;
621 formatInfo.type = type;
622 formatInfo.componentType = componentType;
623 formatInfo.colorEncoding = GL_LINEAR;
Geoff Lang5d601382014-07-22 15:14:06 -0400624 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 Langca271392017-04-05 12:30:00 -0400647 formatInfo.internalFormat = internalFormat;
648 formatInfo.sized = true;
649 formatInfo.sizedInternalFormat = internalFormat;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400650 formatInfo.compressedBlockWidth = compressedBlockWidth;
Geoff Lang5d601382014-07-22 15:14:06 -0400651 formatInfo.compressedBlockHeight = compressedBlockHeight;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400652 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.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400730 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 -0400731
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000732 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Yuly Novikovf15f8862018-06-04 18:59:41 -0400733 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
734 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 );
735 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 );
736 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 );
737 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);
738 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
739 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGRenderableSupport, FloatRGRenderableSupport );
740 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, RequireExt<&Extensions::textureFloatLinear>, FloatRGBRenderableSupport, FloatRGBRenderableSupport );
741 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 +0000742
743 // Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400744 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
745 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> );
746 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> );
747 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> );
748 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> );
749 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>);
750 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 -0800751 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000752
753 // Luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400754 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
755 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
756 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
757 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
758 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);
759 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);
760 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);
761 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
762 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
763 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 +0000764
765 // Compressed formats, From ES 3.0.1 spec, table 3.16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400766 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
767 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
768 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);
769 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
770 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);
771 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
772 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
773 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);
774 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);
775 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);
776 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 +0000777
778 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400779 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
780 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
781 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 +0000782
783 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400784 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 +0000785
786 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400787 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 -0400788
789 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400790 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 +0000791
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800792 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400793 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
794 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
795 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);
796 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);
797 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 -0800798
Geoff Lang60ad73d2015-10-23 10:08:44 -0400799 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400800 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
801 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);
802 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);
803 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);
804 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);
805 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);
806 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);
807 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);
808 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);
809 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);
810 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);
811 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);
812 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);
813 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);
814 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 -0400815
Yuly Novikovf15f8862018-06-04 18:59:41 -0400816 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);
817 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);
818 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);
819 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);
820 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);
821 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);
822 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);
823 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);
824 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);
825 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);
826 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);
827 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);
828 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);
829 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 -0400830
Corentin Walleze0902642014-11-04 12:32:15 -0800831 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
832 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
833 // - All other stencil formats (all depth-stencil) are either float or normalized
834 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400835 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
836 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 -0800837
838 // From GL_ANGLE_lossy_etc_decode
Yuly Novikovf15f8862018-06-04 18:59:41 -0400839 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
840 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
841 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);
842 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);
843 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);
844 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 -0800845
Vincent Lang25ab4512016-05-13 18:13:59 +0200846 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400847 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
848 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>);
849 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 );
850 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>);
851 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 );
852 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 );
853 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 );
854 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>);
855 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 +0200856
Geoff Langca271392017-04-05 12:30:00 -0400857 // Unsized formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400858 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
859 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 );
860 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
861 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 );
862 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
863 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 );
864 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> );
865 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
866 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> );
867 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> );
868 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> );
869 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> );
870 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
871 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 );
872 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> );
873 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 -0400874
875 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400876 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
877 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);
878 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);
879 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);
880 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);
881 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);
882 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);
883 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);
884 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);
885 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);
886 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);
887 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);
888 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);
889 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);
890 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);
891 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);
892 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);
893 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);
894 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);
895 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);
896 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);
897 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);
898 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);
899 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);
900 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);
901 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 -0400902
903 // Unsized floating point formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400904 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
905 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
906 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
907 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
908 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
909 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);
910 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);
911 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 );
912 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 );
913 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
914 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGRenderableSupport, UnsizedFloatRGRenderableSupport );
915 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, RequireExt<&Extensions::textureFloatLinear>, UnsizedFloatRGBRenderableSupport, UnsizedFloatRGBRenderableSupport );
916 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 );
917 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 );
918 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 -0400919
920 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400921 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
922 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
923 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
924 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, NeverSupported, NeverSupported);
925 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
926 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
927 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);
928 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
929 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
930 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 -0400931
932 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400933 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
934 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> );
935 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> );
936 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> );
937 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>);
938 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>);
939 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 -0400940 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800941
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000942 return map;
943}
944
Geoff Lange4a492b2014-06-19 14:14:41 -0400945static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000946{
Geoff Lange4a492b2014-06-19 14:14:41 -0400947 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
948 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000949}
950
Geoff Lange4a492b2014-06-19 14:14:41 -0400951static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400952{
953 FormatSet result;
954
Geoff Langca271392017-04-05 12:30:00 -0400955 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400956 {
Geoff Langca271392017-04-05 12:30:00 -0400957 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400958 {
Geoff Langca271392017-04-05 12:30:00 -0400959 if (type.second.sized)
960 {
961 // TODO(jmadill): Fix this hack.
962 if (internalFormat.first == GL_BGR565_ANGLEX)
963 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400964
Geoff Langca271392017-04-05 12:30:00 -0400965 result.insert(internalFormat.first);
966 }
Geoff Langcec35902014-04-16 10:52:36 -0400967 }
968 }
969
970 return result;
971}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000972
Geoff Lang5d601382014-07-22 15:14:06 -0400973const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000974{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200975 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000976 {
Frank Henigman95fb2a12018-05-27 20:17:05 -0400977 case GL_UNSIGNED_BYTE:
978 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200979 {
980 static const Type info = GenTypeInfo(1, false);
981 return info;
982 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400983 case GL_UNSIGNED_SHORT:
984 case GL_SHORT:
985 case GL_HALF_FLOAT:
986 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200987 {
988 static const Type info = GenTypeInfo(2, false);
989 return info;
990 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400991 case GL_UNSIGNED_INT:
992 case GL_INT:
993 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200994 {
995 static const Type info = GenTypeInfo(4, false);
996 return info;
997 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400998 case GL_UNSIGNED_SHORT_5_6_5:
999 case GL_UNSIGNED_SHORT_4_4_4_4:
1000 case GL_UNSIGNED_SHORT_5_5_5_1:
1001 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1002 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001003 {
1004 static const Type info = GenTypeInfo(2, true);
1005 return info;
1006 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001007 case GL_UNSIGNED_INT_2_10_10_10_REV:
1008 case GL_UNSIGNED_INT_24_8:
1009 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1010 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001011 {
1012 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1013 static const Type info = GenTypeInfo(4, true);
1014 return info;
1015 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001016 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001017 {
1018 static const Type info = GenTypeInfo(8, true);
1019 return info;
1020 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001021 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001022 {
1023 static const Type defaultInfo;
1024 return defaultInfo;
1025 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001026 }
1027}
1028
Geoff Langca271392017-04-05 12:30:00 -04001029const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001030{
Geoff Langca271392017-04-05 12:30:00 -04001031 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001032 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001033 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001034
1035 // Sized internal formats only have one type per entry
1036 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001037 {
Geoff Lang5d601382014-07-22 15:14:06 -04001038 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001039 }
Geoff Langca271392017-04-05 12:30:00 -04001040
1041 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1042 if (!internalFormatInfo.sized)
1043 {
1044 return defaultInternalFormat;
1045 }
1046
1047 return internalFormatInfo;
1048}
1049
1050const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1051{
1052 static const InternalFormat defaultInternalFormat;
1053 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1054
1055 auto internalFormatIter = formatMap.find(internalFormat);
1056 if (internalFormatIter == formatMap.end())
1057 {
1058 return defaultInternalFormat;
1059 }
1060
1061 // If the internal format is sized, simply return it without the type check.
1062 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1063 {
1064 return internalFormatIter->second.begin()->second;
1065 }
1066
1067 auto typeIter = internalFormatIter->second.find(type);
1068 if (typeIter == internalFormatIter->second.end())
1069 {
1070 return defaultInternalFormat;
1071 }
1072
1073 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001074}
1075
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001076GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1077{
1078 const auto &typeInfo = GetTypeInfo(formatType);
1079 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1080 return components * typeInfo.bytes;
1081}
1082
Corentin Wallez886de362016-09-27 10:49:35 -04001083ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001084 GLsizei width,
1085 GLint alignment,
1086 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001087{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001088 // Compressed images do not use pack/unpack parameters.
1089 if (compressed)
1090 {
1091 ASSERT(rowLength == 0);
Jeff Gilbert48590352017-11-07 16:03:38 -08001092 return computeCompressedImageSize(Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001093 }
1094
Geoff Lang3f234062016-07-13 15:35:45 -04001095 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001096 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001097
1098 ASSERT(alignment > 0 && isPow2(alignment));
1099 CheckedNumeric<GLuint> checkedAlignment(alignment);
1100 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1101 ANGLE_TRY_CHECKED_MATH(aligned);
1102 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001103}
1104
Corentin Wallez0e487192016-10-03 16:30:38 -04001105ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1106 GLint imageHeight,
1107 GLuint rowPitch) const
1108{
1109 GLuint rows =
1110 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1111 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1112
1113 auto depthPitch = checkedRowPitch * rows;
1114 ANGLE_TRY_CHECKED_MATH(depthPitch);
1115 return depthPitch.ValueOrDie();
1116}
1117
Corentin Wallez886de362016-09-27 10:49:35 -04001118ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001119 GLsizei width,
1120 GLsizei height,
1121 GLint alignment,
1122 GLint rowLength,
1123 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001124{
Jamie Madille2e406c2016-06-02 13:04:10 -04001125 GLuint rowPitch = 0;
1126 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001127 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001128}
1129
Jeff Gilbert48590352017-11-07 16:03:38 -08001130ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001131{
Jamie Madill513558d2016-06-02 13:04:11 -04001132 CheckedNumeric<GLuint> checkedWidth(size.width);
1133 CheckedNumeric<GLuint> checkedHeight(size.height);
1134 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001135 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1136 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001137
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001138 ASSERT(compressed);
1139 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1140 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1141 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1142 ANGLE_TRY_CHECKED_MATH(bytes);
1143 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001144}
1145
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001146ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLenum formatType,
1147 GLuint rowPitch,
1148 GLuint depthPitch,
1149 const PixelStoreStateBase &state,
1150 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001151{
Olli Etuaho989cac32016-06-08 16:18:49 -07001152 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1153 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001154 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1155 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1156 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001157 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001158 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001159 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001160 {
1161 checkedSkipImagesBytes = 0;
1162 }
1163 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1164 checkedSkipPixels * checkedPixelBytes;
1165 ANGLE_TRY_CHECKED_MATH(skipBytes);
1166 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001167}
1168
Frank Henigman95fb2a12018-05-27 20:17:05 -04001169ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(GLenum formatType,
1170 const Extents &size,
1171 const PixelStoreStateBase &state,
1172 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001173{
Corentin Wallez886de362016-09-27 10:49:35 -04001174 GLuint rowPitch = 0;
1175 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001176 rowPitch);
1177
Corentin Wallez0e487192016-10-03 16:30:38 -04001178 GLuint depthPitch = 0;
1179 if (is3D)
1180 {
1181 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1182 }
1183
Corentin Wallez886de362016-09-27 10:49:35 -04001184 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001185 if (compressed)
1186 {
Jeff Gilbert48590352017-11-07 16:03:38 -08001187 ANGLE_TRY_RESULT(computeCompressedImageSize(size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001188 }
Corentin Wallez886de362016-09-27 10:49:35 -04001189 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001190 {
Corentin Wallez886de362016-09-27 10:49:35 -04001191 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1192 checkedCopyBytes += size.width * bytes;
1193
1194 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1195 checkedCopyBytes += heightMinusOne * rowPitch;
1196
1197 if (is3D)
1198 {
1199 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1200 checkedCopyBytes += depthMinusOne * depthPitch;
1201 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001202 }
1203
Corentin Wallez886de362016-09-27 10:49:35 -04001204 CheckedNumeric<GLuint> checkedSkipBytes = 0;
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001205 ANGLE_TRY_RESULT(computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D),
1206 checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001207
1208 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1209
1210 ANGLE_TRY_CHECKED_MATH(endByte);
1211 return endByte.ValueOrDie();
1212}
1213
Geoff Langca271392017-04-05 12:30:00 -04001214GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001215{
Geoff Langca271392017-04-05 12:30:00 -04001216 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1217 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001218 {
Geoff Langca271392017-04-05 12:30:00 -04001219 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001220 }
Geoff Langca271392017-04-05 12:30:00 -04001221
1222 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001223}
1224
Geoff Lange4a492b2014-06-19 14:14:41 -04001225const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001226{
Geoff Lange4a492b2014-06-19 14:14:41 -04001227 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001228 return formatSet;
1229}
1230
Jamie Madill09e2d932015-07-14 16:40:31 -04001231AttributeType GetAttributeType(GLenum enumValue)
1232{
1233 switch (enumValue)
1234 {
1235 case GL_FLOAT:
1236 return ATTRIBUTE_FLOAT;
1237 case GL_FLOAT_VEC2:
1238 return ATTRIBUTE_VEC2;
1239 case GL_FLOAT_VEC3:
1240 return ATTRIBUTE_VEC3;
1241 case GL_FLOAT_VEC4:
1242 return ATTRIBUTE_VEC4;
1243 case GL_INT:
1244 return ATTRIBUTE_INT;
1245 case GL_INT_VEC2:
1246 return ATTRIBUTE_IVEC2;
1247 case GL_INT_VEC3:
1248 return ATTRIBUTE_IVEC3;
1249 case GL_INT_VEC4:
1250 return ATTRIBUTE_IVEC4;
1251 case GL_UNSIGNED_INT:
1252 return ATTRIBUTE_UINT;
1253 case GL_UNSIGNED_INT_VEC2:
1254 return ATTRIBUTE_UVEC2;
1255 case GL_UNSIGNED_INT_VEC3:
1256 return ATTRIBUTE_UVEC3;
1257 case GL_UNSIGNED_INT_VEC4:
1258 return ATTRIBUTE_UVEC4;
1259 case GL_FLOAT_MAT2:
1260 return ATTRIBUTE_MAT2;
1261 case GL_FLOAT_MAT3:
1262 return ATTRIBUTE_MAT3;
1263 case GL_FLOAT_MAT4:
1264 return ATTRIBUTE_MAT4;
1265 case GL_FLOAT_MAT2x3:
1266 return ATTRIBUTE_MAT2x3;
1267 case GL_FLOAT_MAT2x4:
1268 return ATTRIBUTE_MAT2x4;
1269 case GL_FLOAT_MAT3x2:
1270 return ATTRIBUTE_MAT3x2;
1271 case GL_FLOAT_MAT3x4:
1272 return ATTRIBUTE_MAT3x4;
1273 case GL_FLOAT_MAT4x2:
1274 return ATTRIBUTE_MAT4x2;
1275 case GL_FLOAT_MAT4x3:
1276 return ATTRIBUTE_MAT4x3;
1277 default:
1278 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001279#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001280 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001281#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001282 }
1283}
1284
Frank Henigman95fb2a12018-05-27 20:17:05 -04001285angle::Format::ID GetVertexFormatID(GLenum type,
1286 GLboolean normalized,
1287 GLuint components,
1288 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001289{
1290 switch (type)
1291 {
1292 case GL_BYTE:
1293 switch (components)
1294 {
1295 case 1:
1296 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001297 return angle::Format::ID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001298 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001299 return angle::Format::ID::R8_SNORM;
1300 return angle::Format::ID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001301 case 2:
1302 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001303 return angle::Format::ID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001304 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001305 return angle::Format::ID::R8G8_SNORM;
1306 return angle::Format::ID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001307 case 3:
1308 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001309 return angle::Format::ID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001310 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001311 return angle::Format::ID::R8G8B8_SNORM;
1312 return angle::Format::ID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001313 case 4:
1314 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001315 return angle::Format::ID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001316 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001317 return angle::Format::ID::R8G8B8A8_SNORM;
1318 return angle::Format::ID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001319 default:
1320 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001321#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001322 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001323#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001324 }
1325 case GL_UNSIGNED_BYTE:
1326 switch (components)
1327 {
1328 case 1:
1329 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001330 return angle::Format::ID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001331 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001332 return angle::Format::ID::R8_UNORM;
1333 return angle::Format::ID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001334 case 2:
1335 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001336 return angle::Format::ID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001337 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001338 return angle::Format::ID::R8G8_UNORM;
1339 return angle::Format::ID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001340 case 3:
1341 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001342 return angle::Format::ID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001343 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001344 return angle::Format::ID::R8G8B8_UNORM;
1345 return angle::Format::ID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001346 case 4:
1347 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001348 return angle::Format::ID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001349 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001350 return angle::Format::ID::R8G8B8A8_UNORM;
1351 return angle::Format::ID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001352 default:
1353 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001354#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001355 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001356#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001357 }
1358 case GL_SHORT:
1359 switch (components)
1360 {
1361 case 1:
1362 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001363 return angle::Format::ID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001364 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001365 return angle::Format::ID::R16_SNORM;
1366 return angle::Format::ID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001367 case 2:
1368 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001369 return angle::Format::ID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001370 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001371 return angle::Format::ID::R16G16_SNORM;
1372 return angle::Format::ID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001373 case 3:
1374 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001375 return angle::Format::ID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001376 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001377 return angle::Format::ID::R16G16B16_SNORM;
1378 return angle::Format::ID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001379 case 4:
1380 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001381 return angle::Format::ID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001382 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001383 return angle::Format::ID::R16G16B16A16_SNORM;
1384 return angle::Format::ID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001385 default:
1386 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001387#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001388 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001389#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001390 }
1391 case GL_UNSIGNED_SHORT:
1392 switch (components)
1393 {
1394 case 1:
1395 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001396 return angle::Format::ID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001397 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001398 return angle::Format::ID::R16_UNORM;
1399 return angle::Format::ID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001400 case 2:
1401 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001402 return angle::Format::ID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001403 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001404 return angle::Format::ID::R16G16_UNORM;
1405 return angle::Format::ID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001406 case 3:
1407 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001408 return angle::Format::ID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001409 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001410 return angle::Format::ID::R16G16B16_UNORM;
1411 return angle::Format::ID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001412 case 4:
1413 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001414 return angle::Format::ID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001415 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001416 return angle::Format::ID::R16G16B16A16_UNORM;
1417 return angle::Format::ID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001418 default:
1419 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001420#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001421 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001422#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001423 }
1424 case GL_INT:
1425 switch (components)
1426 {
1427 case 1:
1428 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001429 return angle::Format::ID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001430 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001431 return angle::Format::ID::R32_SNORM;
1432 return angle::Format::ID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001433 case 2:
1434 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001435 return angle::Format::ID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001436 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001437 return angle::Format::ID::R32G32_SNORM;
1438 return angle::Format::ID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001439 case 3:
1440 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001441 return angle::Format::ID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001442 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001443 return angle::Format::ID::R32G32B32_SNORM;
1444 return angle::Format::ID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001445 case 4:
1446 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001447 return angle::Format::ID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001448 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001449 return angle::Format::ID::R32G32B32A32_SNORM;
1450 return angle::Format::ID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001451 default:
1452 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001453#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001454 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001455#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001456 }
1457 case GL_UNSIGNED_INT:
1458 switch (components)
1459 {
1460 case 1:
1461 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001462 return angle::Format::ID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001463 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001464 return angle::Format::ID::R32_UNORM;
1465 return angle::Format::ID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001466 case 2:
1467 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001468 return angle::Format::ID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001469 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001470 return angle::Format::ID::R32G32_UNORM;
1471 return angle::Format::ID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001472 case 3:
1473 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001474 return angle::Format::ID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001475 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001476 return angle::Format::ID::R32G32B32_UNORM;
1477 return angle::Format::ID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001478 case 4:
1479 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001480 return angle::Format::ID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001481 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001482 return angle::Format::ID::R32G32B32A32_UNORM;
1483 return angle::Format::ID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001484 default:
1485 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001486#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001487 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001488#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001489 }
1490 case GL_FLOAT:
1491 switch (components)
1492 {
1493 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001494 return angle::Format::ID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001495 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001496 return angle::Format::ID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001497 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001498 return angle::Format::ID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001499 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001500 return angle::Format::ID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001501 default:
1502 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001503#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001504 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001505#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001506 }
1507 case GL_HALF_FLOAT:
1508 switch (components)
1509 {
1510 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001511 return angle::Format::ID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001512 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001513 return angle::Format::ID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001514 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001515 return angle::Format::ID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001516 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001517 return angle::Format::ID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001518 default:
1519 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001520#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001521 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001522#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001523 }
1524 case GL_FIXED:
1525 switch (components)
1526 {
1527 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001528 return angle::Format::ID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001529 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001530 return angle::Format::ID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001531 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001532 return angle::Format::ID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001533 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001534 return angle::Format::ID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001535 default:
1536 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001537#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001538 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001539#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001540 }
1541 case GL_INT_2_10_10_10_REV:
1542 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001543 return angle::Format::ID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001544 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001545 return angle::Format::ID::R10G10B10A2_SNORM;
1546 return angle::Format::ID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001547 case GL_UNSIGNED_INT_2_10_10_10_REV:
1548 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001549 return angle::Format::ID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001550 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001551 return angle::Format::ID::R10G10B10A2_UNORM;
1552 return angle::Format::ID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001553 default:
1554 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001555#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001556 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001557#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001558 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001559}
1560
Frank Henigman95fb2a12018-05-27 20:17:05 -04001561angle::Format::ID GetVertexFormatID(const VertexAttribute &attrib)
1562{
1563 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1564}
1565
1566// TODO(fjhenigman): Do away with VertexFormatType; use angle::Format::ID instead. anglebug.com/2531
1567VertexFormatType GetVertexFormatType(GLenum type,
1568 GLboolean normalized,
1569 GLuint components,
1570 bool pureInteger)
1571{
1572 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1573 {
1574 case angle::Format::ID::R8_SINT:
1575 return VERTEX_FORMAT_SBYTE1_INT;
1576 case angle::Format::ID::R8_SNORM:
1577 return VERTEX_FORMAT_SBYTE1_NORM;
1578 case angle::Format::ID::R8_SSCALED:
1579 return VERTEX_FORMAT_SBYTE1;
1580 case angle::Format::ID::R8G8_SINT:
1581 return VERTEX_FORMAT_SBYTE2_INT;
1582 case angle::Format::ID::R8G8_SNORM:
1583 return VERTEX_FORMAT_SBYTE2_NORM;
1584 case angle::Format::ID::R8G8_SSCALED:
1585 return VERTEX_FORMAT_SBYTE2;
1586 case angle::Format::ID::R8G8B8_SINT:
1587 return VERTEX_FORMAT_SBYTE3_INT;
1588 case angle::Format::ID::R8G8B8_SNORM:
1589 return VERTEX_FORMAT_SBYTE3_NORM;
1590 case angle::Format::ID::R8G8B8_SSCALED:
1591 return VERTEX_FORMAT_SBYTE3;
1592 case angle::Format::ID::R8G8B8A8_SINT:
1593 return VERTEX_FORMAT_SBYTE4_INT;
1594 case angle::Format::ID::R8G8B8A8_SNORM:
1595 return VERTEX_FORMAT_SBYTE4_NORM;
1596 case angle::Format::ID::R8G8B8A8_SSCALED:
1597 return VERTEX_FORMAT_SBYTE4;
1598 case angle::Format::ID::R8_UINT:
1599 return VERTEX_FORMAT_UBYTE1_INT;
1600 case angle::Format::ID::R8_UNORM:
1601 return VERTEX_FORMAT_UBYTE1_NORM;
1602 case angle::Format::ID::R8_USCALED:
1603 return VERTEX_FORMAT_UBYTE1;
1604 case angle::Format::ID::R8G8_UINT:
1605 return VERTEX_FORMAT_UBYTE2_INT;
1606 case angle::Format::ID::R8G8_UNORM:
1607 return VERTEX_FORMAT_UBYTE2_NORM;
1608 case angle::Format::ID::R8G8_USCALED:
1609 return VERTEX_FORMAT_UBYTE2;
1610 case angle::Format::ID::R8G8B8_UINT:
1611 return VERTEX_FORMAT_UBYTE3_INT;
1612 case angle::Format::ID::R8G8B8_UNORM:
1613 return VERTEX_FORMAT_UBYTE3_NORM;
1614 case angle::Format::ID::R8G8B8_USCALED:
1615 return VERTEX_FORMAT_UBYTE3;
1616 case angle::Format::ID::R8G8B8A8_UINT:
1617 return VERTEX_FORMAT_UBYTE4_INT;
1618 case angle::Format::ID::R8G8B8A8_UNORM:
1619 return VERTEX_FORMAT_UBYTE4_NORM;
1620 case angle::Format::ID::R8G8B8A8_USCALED:
1621 return VERTEX_FORMAT_UBYTE4;
1622 case angle::Format::ID::R16_SINT:
1623 return VERTEX_FORMAT_SSHORT1_INT;
1624 case angle::Format::ID::R16_SNORM:
1625 return VERTEX_FORMAT_SSHORT1_NORM;
1626 case angle::Format::ID::R16_SSCALED:
1627 return VERTEX_FORMAT_SSHORT1;
1628 case angle::Format::ID::R16G16_SINT:
1629 return VERTEX_FORMAT_SSHORT2_INT;
1630 case angle::Format::ID::R16G16_SNORM:
1631 return VERTEX_FORMAT_SSHORT2_NORM;
1632 case angle::Format::ID::R16G16_SSCALED:
1633 return VERTEX_FORMAT_SSHORT2;
1634 case angle::Format::ID::R16G16B16_SINT:
1635 return VERTEX_FORMAT_SSHORT3_INT;
1636 case angle::Format::ID::R16G16B16_SNORM:
1637 return VERTEX_FORMAT_SSHORT3_NORM;
1638 case angle::Format::ID::R16G16B16_SSCALED:
1639 return VERTEX_FORMAT_SSHORT3;
1640 case angle::Format::ID::R16G16B16A16_SINT:
1641 return VERTEX_FORMAT_SSHORT4_INT;
1642 case angle::Format::ID::R16G16B16A16_SNORM:
1643 return VERTEX_FORMAT_SSHORT4_NORM;
1644 case angle::Format::ID::R16G16B16A16_SSCALED:
1645 return VERTEX_FORMAT_SSHORT4;
1646 case angle::Format::ID::R16_UINT:
1647 return VERTEX_FORMAT_USHORT1_INT;
1648 case angle::Format::ID::R16_UNORM:
1649 return VERTEX_FORMAT_USHORT1_NORM;
1650 case angle::Format::ID::R16_USCALED:
1651 return VERTEX_FORMAT_USHORT1;
1652 case angle::Format::ID::R16G16_UINT:
1653 return VERTEX_FORMAT_USHORT2_INT;
1654 case angle::Format::ID::R16G16_UNORM:
1655 return VERTEX_FORMAT_USHORT2_NORM;
1656 case angle::Format::ID::R16G16_USCALED:
1657 return VERTEX_FORMAT_USHORT2;
1658 case angle::Format::ID::R16G16B16_UINT:
1659 return VERTEX_FORMAT_USHORT3_INT;
1660 case angle::Format::ID::R16G16B16_UNORM:
1661 return VERTEX_FORMAT_USHORT3_NORM;
1662 case angle::Format::ID::R16G16B16_USCALED:
1663 return VERTEX_FORMAT_USHORT3;
1664 case angle::Format::ID::R16G16B16A16_UINT:
1665 return VERTEX_FORMAT_USHORT4_INT;
1666 case angle::Format::ID::R16G16B16A16_UNORM:
1667 return VERTEX_FORMAT_USHORT4_NORM;
1668 case angle::Format::ID::R16G16B16A16_USCALED:
1669 return VERTEX_FORMAT_USHORT4;
1670 case angle::Format::ID::R32_SINT:
1671 return VERTEX_FORMAT_SINT1_INT;
1672 case angle::Format::ID::R32_SNORM:
1673 return VERTEX_FORMAT_SINT1_NORM;
1674 case angle::Format::ID::R32_SSCALED:
1675 return VERTEX_FORMAT_SINT1;
1676 case angle::Format::ID::R32G32_SINT:
1677 return VERTEX_FORMAT_SINT2_INT;
1678 case angle::Format::ID::R32G32_SNORM:
1679 return VERTEX_FORMAT_SINT2_NORM;
1680 case angle::Format::ID::R32G32_SSCALED:
1681 return VERTEX_FORMAT_SINT2;
1682 case angle::Format::ID::R32G32B32_SINT:
1683 return VERTEX_FORMAT_SINT3_INT;
1684 case angle::Format::ID::R32G32B32_SNORM:
1685 return VERTEX_FORMAT_SINT3_NORM;
1686 case angle::Format::ID::R32G32B32_SSCALED:
1687 return VERTEX_FORMAT_SINT3;
1688 case angle::Format::ID::R32G32B32A32_SINT:
1689 return VERTEX_FORMAT_SINT4_INT;
1690 case angle::Format::ID::R32G32B32A32_SNORM:
1691 return VERTEX_FORMAT_SINT4_NORM;
1692 case angle::Format::ID::R32G32B32A32_SSCALED:
1693 return VERTEX_FORMAT_SINT4;
1694 case angle::Format::ID::R32_UINT:
1695 return VERTEX_FORMAT_UINT1_INT;
1696 case angle::Format::ID::R32_UNORM:
1697 return VERTEX_FORMAT_UINT1_NORM;
1698 case angle::Format::ID::R32_USCALED:
1699 return VERTEX_FORMAT_UINT1;
1700 case angle::Format::ID::R32G32_UINT:
1701 return VERTEX_FORMAT_UINT2_INT;
1702 case angle::Format::ID::R32G32_UNORM:
1703 return VERTEX_FORMAT_UINT2_NORM;
1704 case angle::Format::ID::R32G32_USCALED:
1705 return VERTEX_FORMAT_UINT2;
1706 case angle::Format::ID::R32G32B32_UINT:
1707 return VERTEX_FORMAT_UINT3_INT;
1708 case angle::Format::ID::R32G32B32_UNORM:
1709 return VERTEX_FORMAT_UINT3_NORM;
1710 case angle::Format::ID::R32G32B32_USCALED:
1711 return VERTEX_FORMAT_UINT3;
1712 case angle::Format::ID::R32G32B32A32_UINT:
1713 return VERTEX_FORMAT_UINT4_INT;
1714 case angle::Format::ID::R32G32B32A32_UNORM:
1715 return VERTEX_FORMAT_UINT4_NORM;
1716 case angle::Format::ID::R32G32B32A32_USCALED:
1717 return VERTEX_FORMAT_UINT4;
1718 case angle::Format::ID::R32_FLOAT:
1719 return VERTEX_FORMAT_FLOAT1;
1720 case angle::Format::ID::R32G32_FLOAT:
1721 return VERTEX_FORMAT_FLOAT2;
1722 case angle::Format::ID::R32G32B32_FLOAT:
1723 return VERTEX_FORMAT_FLOAT3;
1724 case angle::Format::ID::R32G32B32A32_FLOAT:
1725 return VERTEX_FORMAT_FLOAT4;
1726 case angle::Format::ID::R16_FLOAT:
1727 return VERTEX_FORMAT_HALF1;
1728 case angle::Format::ID::R16G16_FLOAT:
1729 return VERTEX_FORMAT_HALF2;
1730 case angle::Format::ID::R16G16B16_FLOAT:
1731 return VERTEX_FORMAT_HALF3;
1732 case angle::Format::ID::R16G16B16A16_FLOAT:
1733 return VERTEX_FORMAT_HALF4;
1734 case angle::Format::ID::R32_FIXED:
1735 return VERTEX_FORMAT_FIXED1;
1736 case angle::Format::ID::R32G32_FIXED:
1737 return VERTEX_FORMAT_FIXED2;
1738 case angle::Format::ID::R32G32B32_FIXED:
1739 return VERTEX_FORMAT_FIXED3;
1740 case angle::Format::ID::R32G32B32A32_FIXED:
1741 return VERTEX_FORMAT_FIXED4;
1742 case angle::Format::ID::R10G10B10A2_SINT:
1743 return VERTEX_FORMAT_SINT210_INT;
1744 case angle::Format::ID::R10G10B10A2_SNORM:
1745 return VERTEX_FORMAT_SINT210_NORM;
1746 case angle::Format::ID::R10G10B10A2_SSCALED:
1747 return VERTEX_FORMAT_SINT210;
1748 case angle::Format::ID::R10G10B10A2_UINT:
1749 return VERTEX_FORMAT_UINT210_INT;
1750 case angle::Format::ID::R10G10B10A2_UNORM:
1751 return VERTEX_FORMAT_UINT210_NORM;
1752 case angle::Format::ID::R10G10B10A2_USCALED:
1753 return VERTEX_FORMAT_UINT210;
1754 default:
1755 return VERTEX_FORMAT_INVALID;
1756 }
1757}
1758
Jamie Madilld3dfda22015-07-06 08:28:49 -04001759VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1760{
1761 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1762}
1763
1764VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1765{
1766 if (!attrib.enabled)
1767 {
1768 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1769 }
1770 return GetVertexFormatType(attrib);
1771}
1772
1773const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1774{
1775 switch (vertexFormatType)
1776 {
1777 case VERTEX_FORMAT_SBYTE1:
1778 {
1779 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1780 return format;
1781 }
1782 case VERTEX_FORMAT_SBYTE1_NORM:
1783 {
1784 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1785 return format;
1786 }
1787 case VERTEX_FORMAT_SBYTE2:
1788 {
1789 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1790 return format;
1791 }
1792 case VERTEX_FORMAT_SBYTE2_NORM:
1793 {
1794 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1795 return format;
1796 }
1797 case VERTEX_FORMAT_SBYTE3:
1798 {
1799 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1800 return format;
1801 }
1802 case VERTEX_FORMAT_SBYTE3_NORM:
1803 {
1804 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1805 return format;
1806 }
1807 case VERTEX_FORMAT_SBYTE4:
1808 {
1809 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1810 return format;
1811 }
1812 case VERTEX_FORMAT_SBYTE4_NORM:
1813 {
1814 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1815 return format;
1816 }
1817 case VERTEX_FORMAT_UBYTE1:
1818 {
1819 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1820 return format;
1821 }
1822 case VERTEX_FORMAT_UBYTE1_NORM:
1823 {
1824 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1825 return format;
1826 }
1827 case VERTEX_FORMAT_UBYTE2:
1828 {
1829 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1830 return format;
1831 }
1832 case VERTEX_FORMAT_UBYTE2_NORM:
1833 {
1834 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1835 return format;
1836 }
1837 case VERTEX_FORMAT_UBYTE3:
1838 {
1839 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1840 return format;
1841 }
1842 case VERTEX_FORMAT_UBYTE3_NORM:
1843 {
1844 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1845 return format;
1846 }
1847 case VERTEX_FORMAT_UBYTE4:
1848 {
1849 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1850 return format;
1851 }
1852 case VERTEX_FORMAT_UBYTE4_NORM:
1853 {
1854 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1855 return format;
1856 }
1857 case VERTEX_FORMAT_SSHORT1:
1858 {
1859 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1860 return format;
1861 }
1862 case VERTEX_FORMAT_SSHORT1_NORM:
1863 {
1864 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1865 return format;
1866 }
1867 case VERTEX_FORMAT_SSHORT2:
1868 {
1869 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1870 return format;
1871 }
1872 case VERTEX_FORMAT_SSHORT2_NORM:
1873 {
1874 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1875 return format;
1876 }
1877 case VERTEX_FORMAT_SSHORT3:
1878 {
1879 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1880 return format;
1881 }
1882 case VERTEX_FORMAT_SSHORT3_NORM:
1883 {
1884 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1885 return format;
1886 }
1887 case VERTEX_FORMAT_SSHORT4:
1888 {
1889 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1890 return format;
1891 }
1892 case VERTEX_FORMAT_SSHORT4_NORM:
1893 {
1894 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1895 return format;
1896 }
1897 case VERTEX_FORMAT_USHORT1:
1898 {
1899 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1900 return format;
1901 }
1902 case VERTEX_FORMAT_USHORT1_NORM:
1903 {
1904 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1905 return format;
1906 }
1907 case VERTEX_FORMAT_USHORT2:
1908 {
1909 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1910 return format;
1911 }
1912 case VERTEX_FORMAT_USHORT2_NORM:
1913 {
1914 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1915 return format;
1916 }
1917 case VERTEX_FORMAT_USHORT3:
1918 {
1919 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1920 return format;
1921 }
1922 case VERTEX_FORMAT_USHORT3_NORM:
1923 {
1924 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1925 return format;
1926 }
1927 case VERTEX_FORMAT_USHORT4:
1928 {
1929 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1930 return format;
1931 }
1932 case VERTEX_FORMAT_USHORT4_NORM:
1933 {
1934 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1935 return format;
1936 }
1937 case VERTEX_FORMAT_SINT1:
1938 {
1939 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1940 return format;
1941 }
1942 case VERTEX_FORMAT_SINT1_NORM:
1943 {
1944 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1945 return format;
1946 }
1947 case VERTEX_FORMAT_SINT2:
1948 {
1949 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1950 return format;
1951 }
1952 case VERTEX_FORMAT_SINT2_NORM:
1953 {
1954 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1955 return format;
1956 }
1957 case VERTEX_FORMAT_SINT3:
1958 {
1959 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1960 return format;
1961 }
1962 case VERTEX_FORMAT_SINT3_NORM:
1963 {
1964 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1965 return format;
1966 }
1967 case VERTEX_FORMAT_SINT4:
1968 {
1969 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1970 return format;
1971 }
1972 case VERTEX_FORMAT_SINT4_NORM:
1973 {
1974 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1975 return format;
1976 }
1977 case VERTEX_FORMAT_UINT1:
1978 {
1979 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1980 return format;
1981 }
1982 case VERTEX_FORMAT_UINT1_NORM:
1983 {
1984 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1985 return format;
1986 }
1987 case VERTEX_FORMAT_UINT2:
1988 {
1989 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1990 return format;
1991 }
1992 case VERTEX_FORMAT_UINT2_NORM:
1993 {
1994 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1995 return format;
1996 }
1997 case VERTEX_FORMAT_UINT3:
1998 {
1999 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2000 return format;
2001 }
2002 case VERTEX_FORMAT_UINT3_NORM:
2003 {
2004 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2005 return format;
2006 }
2007 case VERTEX_FORMAT_UINT4:
2008 {
2009 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2010 return format;
2011 }
2012 case VERTEX_FORMAT_UINT4_NORM:
2013 {
2014 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2015 return format;
2016 }
2017 case VERTEX_FORMAT_SBYTE1_INT:
2018 {
2019 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2020 return format;
2021 }
2022 case VERTEX_FORMAT_SBYTE2_INT:
2023 {
2024 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2025 return format;
2026 }
2027 case VERTEX_FORMAT_SBYTE3_INT:
2028 {
2029 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2030 return format;
2031 }
2032 case VERTEX_FORMAT_SBYTE4_INT:
2033 {
2034 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2035 return format;
2036 }
2037 case VERTEX_FORMAT_UBYTE1_INT:
2038 {
2039 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2040 return format;
2041 }
2042 case VERTEX_FORMAT_UBYTE2_INT:
2043 {
2044 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2045 return format;
2046 }
2047 case VERTEX_FORMAT_UBYTE3_INT:
2048 {
2049 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2050 return format;
2051 }
2052 case VERTEX_FORMAT_UBYTE4_INT:
2053 {
2054 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2055 return format;
2056 }
2057 case VERTEX_FORMAT_SSHORT1_INT:
2058 {
2059 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2060 return format;
2061 }
2062 case VERTEX_FORMAT_SSHORT2_INT:
2063 {
2064 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2065 return format;
2066 }
2067 case VERTEX_FORMAT_SSHORT3_INT:
2068 {
2069 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2070 return format;
2071 }
2072 case VERTEX_FORMAT_SSHORT4_INT:
2073 {
2074 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2075 return format;
2076 }
2077 case VERTEX_FORMAT_USHORT1_INT:
2078 {
2079 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2080 return format;
2081 }
2082 case VERTEX_FORMAT_USHORT2_INT:
2083 {
2084 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2085 return format;
2086 }
2087 case VERTEX_FORMAT_USHORT3_INT:
2088 {
2089 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2090 return format;
2091 }
2092 case VERTEX_FORMAT_USHORT4_INT:
2093 {
2094 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2095 return format;
2096 }
2097 case VERTEX_FORMAT_SINT1_INT:
2098 {
2099 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2100 return format;
2101 }
2102 case VERTEX_FORMAT_SINT2_INT:
2103 {
2104 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2105 return format;
2106 }
2107 case VERTEX_FORMAT_SINT3_INT:
2108 {
2109 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2110 return format;
2111 }
2112 case VERTEX_FORMAT_SINT4_INT:
2113 {
2114 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2115 return format;
2116 }
2117 case VERTEX_FORMAT_UINT1_INT:
2118 {
2119 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2120 return format;
2121 }
2122 case VERTEX_FORMAT_UINT2_INT:
2123 {
2124 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2125 return format;
2126 }
2127 case VERTEX_FORMAT_UINT3_INT:
2128 {
2129 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2130 return format;
2131 }
2132 case VERTEX_FORMAT_UINT4_INT:
2133 {
2134 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2135 return format;
2136 }
2137 case VERTEX_FORMAT_FIXED1:
2138 {
2139 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2140 return format;
2141 }
2142 case VERTEX_FORMAT_FIXED2:
2143 {
2144 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2145 return format;
2146 }
2147 case VERTEX_FORMAT_FIXED3:
2148 {
2149 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2150 return format;
2151 }
2152 case VERTEX_FORMAT_FIXED4:
2153 {
2154 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2155 return format;
2156 }
2157 case VERTEX_FORMAT_HALF1:
2158 {
2159 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2160 return format;
2161 }
2162 case VERTEX_FORMAT_HALF2:
2163 {
2164 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2165 return format;
2166 }
2167 case VERTEX_FORMAT_HALF3:
2168 {
2169 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2170 return format;
2171 }
2172 case VERTEX_FORMAT_HALF4:
2173 {
2174 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2175 return format;
2176 }
2177 case VERTEX_FORMAT_FLOAT1:
2178 {
2179 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2180 return format;
2181 }
2182 case VERTEX_FORMAT_FLOAT2:
2183 {
2184 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2185 return format;
2186 }
2187 case VERTEX_FORMAT_FLOAT3:
2188 {
2189 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2190 return format;
2191 }
2192 case VERTEX_FORMAT_FLOAT4:
2193 {
2194 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2195 return format;
2196 }
2197 case VERTEX_FORMAT_SINT210:
2198 {
2199 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2200 return format;
2201 }
2202 case VERTEX_FORMAT_UINT210:
2203 {
2204 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2205 return format;
2206 }
2207 case VERTEX_FORMAT_SINT210_NORM:
2208 {
2209 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2210 return format;
2211 }
2212 case VERTEX_FORMAT_UINT210_NORM:
2213 {
2214 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2215 return format;
2216 }
2217 case VERTEX_FORMAT_SINT210_INT:
2218 {
2219 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2220 return format;
2221 }
2222 case VERTEX_FORMAT_UINT210_INT:
2223 {
2224 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2225 return format;
2226 }
2227 default:
2228 {
2229 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2230 return format;
2231 }
2232 }
2233}
2234
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002235size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2236{
2237 switch (vertexFormatType)
2238 {
2239 case VERTEX_FORMAT_SBYTE1:
2240 case VERTEX_FORMAT_SBYTE1_NORM:
2241 case VERTEX_FORMAT_UBYTE1:
2242 case VERTEX_FORMAT_UBYTE1_NORM:
2243 case VERTEX_FORMAT_SBYTE1_INT:
2244 case VERTEX_FORMAT_UBYTE1_INT:
2245 return 1;
2246
2247 case VERTEX_FORMAT_SBYTE2:
2248 case VERTEX_FORMAT_SBYTE2_NORM:
2249 case VERTEX_FORMAT_UBYTE2:
2250 case VERTEX_FORMAT_UBYTE2_NORM:
2251 case VERTEX_FORMAT_SBYTE2_INT:
2252 case VERTEX_FORMAT_UBYTE2_INT:
2253 case VERTEX_FORMAT_SSHORT1:
2254 case VERTEX_FORMAT_SSHORT1_NORM:
2255 case VERTEX_FORMAT_USHORT1:
2256 case VERTEX_FORMAT_USHORT1_NORM:
2257 case VERTEX_FORMAT_SSHORT1_INT:
2258 case VERTEX_FORMAT_USHORT1_INT:
2259 case VERTEX_FORMAT_HALF1:
2260 return 2;
2261
2262 case VERTEX_FORMAT_SBYTE3:
2263 case VERTEX_FORMAT_SBYTE3_NORM:
2264 case VERTEX_FORMAT_UBYTE3:
2265 case VERTEX_FORMAT_UBYTE3_NORM:
2266 case VERTEX_FORMAT_SBYTE3_INT:
2267 case VERTEX_FORMAT_UBYTE3_INT:
2268 return 3;
2269
2270 case VERTEX_FORMAT_SBYTE4:
2271 case VERTEX_FORMAT_SBYTE4_NORM:
2272 case VERTEX_FORMAT_UBYTE4:
2273 case VERTEX_FORMAT_UBYTE4_NORM:
2274 case VERTEX_FORMAT_SBYTE4_INT:
2275 case VERTEX_FORMAT_UBYTE4_INT:
2276 case VERTEX_FORMAT_SSHORT2:
2277 case VERTEX_FORMAT_SSHORT2_NORM:
2278 case VERTEX_FORMAT_USHORT2:
2279 case VERTEX_FORMAT_USHORT2_NORM:
2280 case VERTEX_FORMAT_SSHORT2_INT:
2281 case VERTEX_FORMAT_USHORT2_INT:
2282 case VERTEX_FORMAT_SINT1:
2283 case VERTEX_FORMAT_SINT1_NORM:
2284 case VERTEX_FORMAT_UINT1:
2285 case VERTEX_FORMAT_UINT1_NORM:
2286 case VERTEX_FORMAT_SINT1_INT:
2287 case VERTEX_FORMAT_UINT1_INT:
2288 case VERTEX_FORMAT_HALF2:
2289 case VERTEX_FORMAT_FIXED1:
2290 case VERTEX_FORMAT_FLOAT1:
2291 case VERTEX_FORMAT_SINT210:
2292 case VERTEX_FORMAT_UINT210:
2293 case VERTEX_FORMAT_SINT210_NORM:
2294 case VERTEX_FORMAT_UINT210_NORM:
2295 case VERTEX_FORMAT_SINT210_INT:
2296 case VERTEX_FORMAT_UINT210_INT:
2297 return 4;
2298
2299 case VERTEX_FORMAT_SSHORT3:
2300 case VERTEX_FORMAT_SSHORT3_NORM:
2301 case VERTEX_FORMAT_USHORT3:
2302 case VERTEX_FORMAT_USHORT3_NORM:
2303 case VERTEX_FORMAT_SSHORT3_INT:
2304 case VERTEX_FORMAT_USHORT3_INT:
2305 case VERTEX_FORMAT_HALF3:
2306 return 6;
2307
2308 case VERTEX_FORMAT_SSHORT4:
2309 case VERTEX_FORMAT_SSHORT4_NORM:
2310 case VERTEX_FORMAT_USHORT4:
2311 case VERTEX_FORMAT_USHORT4_NORM:
2312 case VERTEX_FORMAT_SSHORT4_INT:
2313 case VERTEX_FORMAT_USHORT4_INT:
2314 case VERTEX_FORMAT_SINT2:
2315 case VERTEX_FORMAT_SINT2_NORM:
2316 case VERTEX_FORMAT_UINT2:
2317 case VERTEX_FORMAT_UINT2_NORM:
2318 case VERTEX_FORMAT_SINT2_INT:
2319 case VERTEX_FORMAT_UINT2_INT:
2320 case VERTEX_FORMAT_HALF4:
2321 case VERTEX_FORMAT_FIXED2:
2322 case VERTEX_FORMAT_FLOAT2:
2323 return 8;
2324
2325 case VERTEX_FORMAT_SINT3:
2326 case VERTEX_FORMAT_SINT3_NORM:
2327 case VERTEX_FORMAT_UINT3:
2328 case VERTEX_FORMAT_UINT3_NORM:
2329 case VERTEX_FORMAT_SINT3_INT:
2330 case VERTEX_FORMAT_UINT3_INT:
2331 case VERTEX_FORMAT_FIXED3:
2332 case VERTEX_FORMAT_FLOAT3:
2333 return 12;
2334
2335 case VERTEX_FORMAT_SINT4:
2336 case VERTEX_FORMAT_SINT4_NORM:
2337 case VERTEX_FORMAT_UINT4:
2338 case VERTEX_FORMAT_UINT4_NORM:
2339 case VERTEX_FORMAT_SINT4_INT:
2340 case VERTEX_FORMAT_UINT4_INT:
2341 case VERTEX_FORMAT_FIXED4:
2342 case VERTEX_FORMAT_FLOAT4:
2343 return 16;
2344
2345 case VERTEX_FORMAT_INVALID:
2346 default:
2347 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002348#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002349 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002350#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002351 }
2352}
2353
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002354bool ValidES3InternalFormat(GLenum internalFormat)
2355{
2356 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2357 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2358}
2359
Frank Henigman95fb2a12018-05-27 20:17:05 -04002360VertexFormat::VertexFormat(GLenum typeIn,
2361 GLboolean normalizedIn,
2362 GLuint componentsIn,
2363 bool pureIntegerIn)
2364 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002365{
2366 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002367 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2368 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002369}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002370}