blob: 8c67dbee22f609c054a3b50b964c4ba2ceb639ec [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),
296 renderSupport(NeverSupported),
297 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000298{
Geoff Lang5d601382014-07-22 15:14:06 -0400299}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000300
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500301InternalFormat::InternalFormat(const InternalFormat &other) = default;
302
Jamie Madilla3944d42016-07-22 22:13:26 -0400303bool InternalFormat::isLUMA() const
304{
305 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
306 (luminanceBits + alphaBits) > 0);
307}
308
Geoff Langf607c602016-09-21 11:46:48 -0400309GLenum InternalFormat::getReadPixelsFormat() const
310{
311 return format;
312}
313
Geoff Langc71ea662017-09-26 17:06:02 -0400314GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400315{
316 switch (type)
317 {
318 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400319 case GL_HALF_FLOAT_OES:
320 if (version < Version(3, 0))
321 {
322 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
323 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
324 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
325 // as an IMPLEMENTATION_READ_TYPE.
326 return GL_HALF_FLOAT_OES;
327 }
328 else
329 {
330 return GL_HALF_FLOAT;
331 }
Geoff Langf607c602016-09-21 11:46:48 -0400332
333 default:
334 return type;
335 }
336}
337
Olli Etuaho50c562d2017-06-06 14:43:30 +0300338bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
339{
340 // GLES 3.0.5 section 4.4.2.2:
341 // "Implementations are required to support the same internal formats for renderbuffers as the
342 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
343 // formats labelled "texture-only"."
344 if (!sized || compressed)
345 {
346 return false;
347 }
348
349 // Luma formats.
350 if (isLUMA())
351 {
352 return false;
353 }
354
355 // Depth/stencil formats.
356 if (depthBits > 0 || stencilBits > 0)
357 {
358 // GLES 2.0.25 table 4.5.
359 // GLES 3.0.5 section 3.8.3.1.
360 // GLES 3.1 table 8.14.
361
362 // Required formats in all versions.
363 switch (internalFormat)
364 {
365 case GL_DEPTH_COMPONENT16:
366 case GL_STENCIL_INDEX8:
367 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
368 // is in section 4.4.2.2.
369 return true;
370 default:
371 break;
372 }
373 if (version.major < 3)
374 {
375 return false;
376 }
377 // Required formats in GLES 3.0 and up.
378 switch (internalFormat)
379 {
380 case GL_DEPTH_COMPONENT32F:
381 case GL_DEPTH_COMPONENT24:
382 case GL_DEPTH32F_STENCIL8:
383 case GL_DEPTH24_STENCIL8:
384 return true;
385 default:
386 return false;
387 }
388 }
389
390 // RGBA formats.
391 // GLES 2.0.25 table 4.5.
392 // GLES 3.0.5 section 3.8.3.1.
393 // GLES 3.1 table 8.13.
394
395 // Required formats in all versions.
396 switch (internalFormat)
397 {
398 case GL_RGBA4:
399 case GL_RGB5_A1:
400 case GL_RGB565:
401 return true;
402 default:
403 break;
404 }
405 if (version.major < 3)
406 {
407 return false;
408 }
409
410 if (format == GL_BGRA_EXT)
411 {
412 return false;
413 }
414
415 switch (componentType)
416 {
417 case GL_SIGNED_NORMALIZED:
418 case GL_FLOAT:
419 return false;
420 case GL_UNSIGNED_INT:
421 case GL_INT:
422 // Integer RGB formats are not required renderbuffer formats.
423 if (alphaBits == 0 && blueBits != 0)
424 {
425 return false;
426 }
427 // All integer R and RG formats are required.
428 // Integer RGBA formats including RGB10_A2_UI are required.
429 return true;
430 case GL_UNSIGNED_NORMALIZED:
431 if (internalFormat == GL_SRGB8)
432 {
433 return false;
434 }
435 return true;
436 default:
437 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500438#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300439 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500440#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300441 }
442}
443
Geoff Langca271392017-04-05 12:30:00 -0400444Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400445{
446}
447
Geoff Langca271392017-04-05 12:30:00 -0400448Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400449{
Jamie Madilla3944d42016-07-22 22:13:26 -0400450}
451
Geoff Langca271392017-04-05 12:30:00 -0400452Format::Format(GLenum internalFormat, GLenum type)
453 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400454{
Jamie Madilla3944d42016-07-22 22:13:26 -0400455}
456
457Format::Format(const Format &other) = default;
458Format &Format::operator=(const Format &other) = default;
459
Jamie Madilla3944d42016-07-22 22:13:26 -0400460bool Format::valid() const
461{
Geoff Langca271392017-04-05 12:30:00 -0400462 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400463}
464
465// static
466bool Format::SameSized(const Format &a, const Format &b)
467{
Geoff Langca271392017-04-05 12:30:00 -0400468 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400469}
470
Kenneth Russell69382852017-07-21 16:38:44 -0400471static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
472{
473 // BlitFramebuffer works if the color channels are identically
474 // sized, even if there is a swizzle (for example, blitting from a
475 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
476 // be expanded and/or autogenerated if that is found necessary.
477 if (internalformat == GL_BGRA8_EXT)
478 return GL_RGBA8;
479 return internalformat;
480}
481
482// static
483bool Format::EquivalentForBlit(const Format &a, const Format &b)
484{
485 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
486 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
487}
488
Jamie Madilla3944d42016-07-22 22:13:26 -0400489// static
490Format Format::Invalid()
491{
Geoff Langca271392017-04-05 12:30:00 -0400492 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400493 return invalid;
494}
495
Yuly Novikovd73f8522017-01-13 17:48:57 -0500496std::ostream &operator<<(std::ostream &os, const Format &fmt)
497{
498 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400499 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500500}
501
Jamie Madilla3944d42016-07-22 22:13:26 -0400502bool InternalFormat::operator==(const InternalFormat &other) const
503{
Geoff Langca271392017-04-05 12:30:00 -0400504 // We assume all internal formats are unique if they have the same internal format and type
505 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400506}
507
508bool InternalFormat::operator!=(const InternalFormat &other) const
509{
Geoff Langca271392017-04-05 12:30:00 -0400510 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400511}
512
Geoff Langca271392017-04-05 12:30:00 -0400513void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400514{
Geoff Langca271392017-04-05 12:30:00 -0400515 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
516 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
517 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400518}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000519
Jamie Madilla3944d42016-07-22 22:13:26 -0400520void AddRGBAFormat(InternalFormatInfoMap *map,
521 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400522 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400523 GLuint red,
524 GLuint green,
525 GLuint blue,
526 GLuint alpha,
527 GLuint shared,
528 GLenum format,
529 GLenum type,
530 GLenum componentType,
531 bool srgb,
532 InternalFormat::SupportCheckFunction textureSupport,
533 InternalFormat::SupportCheckFunction renderSupport,
534 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400535{
536 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400537 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400538 formatInfo.sized = sized;
539 formatInfo.sizedInternalFormat =
540 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400541 formatInfo.redBits = red;
542 formatInfo.greenBits = green;
543 formatInfo.blueBits = blue;
544 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400545 formatInfo.sharedBits = shared;
546 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400547 formatInfo.componentCount =
548 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400549 formatInfo.format = format;
550 formatInfo.type = type;
551 formatInfo.componentType = componentType;
552 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
Geoff Lang5d601382014-07-22 15:14:06 -0400553 formatInfo.textureSupport = textureSupport;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400554 formatInfo.renderSupport = renderSupport;
555 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400556
557 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400558}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000559
Geoff Langca271392017-04-05 12:30:00 -0400560static void AddLUMAFormat(InternalFormatInfoMap *map,
561 GLenum internalFormat,
562 bool sized,
563 GLuint luminance,
564 GLuint alpha,
565 GLenum format,
566 GLenum type,
567 GLenum componentType,
568 InternalFormat::SupportCheckFunction textureSupport,
569 InternalFormat::SupportCheckFunction renderSupport,
570 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400571{
572 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400573 formatInfo.internalFormat = internalFormat;
574 formatInfo.sized = sized;
575 formatInfo.sizedInternalFormat =
576 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400577 formatInfo.luminanceBits = luminance;
578 formatInfo.alphaBits = alpha;
579 formatInfo.pixelBytes = (luminance + alpha) / 8;
Geoff Lang5d601382014-07-22 15:14:06 -0400580 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400581 formatInfo.format = format;
582 formatInfo.type = type;
583 formatInfo.componentType = componentType;
584 formatInfo.colorEncoding = GL_LINEAR;
Geoff Lang5d601382014-07-22 15:14:06 -0400585 formatInfo.textureSupport = textureSupport;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400586 formatInfo.renderSupport = renderSupport;
587 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400588
589 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400590}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000591
Jamie Madilla3944d42016-07-22 22:13:26 -0400592void AddDepthStencilFormat(InternalFormatInfoMap *map,
593 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400594 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400595 GLuint depthBits,
596 GLuint stencilBits,
597 GLuint unusedBits,
598 GLenum format,
599 GLenum type,
600 GLenum componentType,
601 InternalFormat::SupportCheckFunction textureSupport,
602 InternalFormat::SupportCheckFunction renderSupport,
603 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400604{
605 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400606 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400607 formatInfo.sized = sized;
608 formatInfo.sizedInternalFormat =
609 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400610 formatInfo.depthBits = depthBits;
611 formatInfo.stencilBits = stencilBits;
612 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
Geoff Lang5d601382014-07-22 15:14:06 -0400613 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400614 formatInfo.format = format;
615 formatInfo.type = type;
616 formatInfo.componentType = componentType;
617 formatInfo.colorEncoding = GL_LINEAR;
Geoff Lang5d601382014-07-22 15:14:06 -0400618 formatInfo.textureSupport = textureSupport;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400619 formatInfo.renderSupport = renderSupport;
620 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400621
622 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400623}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624
Geoff Langca271392017-04-05 12:30:00 -0400625void AddCompressedFormat(InternalFormatInfoMap *map,
626 GLenum internalFormat,
627 GLuint compressedBlockWidth,
628 GLuint compressedBlockHeight,
629 GLuint compressedBlockSize,
630 GLuint componentCount,
631 GLenum format,
632 GLenum type,
633 bool srgb,
634 InternalFormat::SupportCheckFunction textureSupport,
635 InternalFormat::SupportCheckFunction renderSupport,
636 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400637{
638 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400639 formatInfo.internalFormat = internalFormat;
640 formatInfo.sized = true;
641 formatInfo.sizedInternalFormat = internalFormat;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400642 formatInfo.compressedBlockWidth = compressedBlockWidth;
Geoff Lang5d601382014-07-22 15:14:06 -0400643 formatInfo.compressedBlockHeight = compressedBlockHeight;
Frank Henigman95fb2a12018-05-27 20:17:05 -0400644 formatInfo.pixelBytes = compressedBlockSize / 8;
645 formatInfo.componentCount = componentCount;
646 formatInfo.format = format;
647 formatInfo.type = type;
648 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
649 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
650 formatInfo.compressed = true;
651 formatInfo.textureSupport = textureSupport;
652 formatInfo.renderSupport = renderSupport;
653 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400654
655 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400656}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000657
Geoff Lange4a492b2014-06-19 14:14:41 -0400658static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000659{
660 InternalFormatInfoMap map;
661
662 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400663 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000664
Jamie Madilla3944d42016-07-22 22:13:26 -0400665 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000666
Geoff Langca271392017-04-05 12:30:00 -0400667 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
668 AddRGBAFormat(&map, GL_R8, true, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
669 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
670 AddRGBAFormat(&map, GL_RG8, true, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
671 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
672 AddRGBAFormat(&map, GL_RGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
673 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
Lingfeng Yang56e95402018-02-19 16:45:26 -0800674 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>, RequireES<1, 0>, AlwaysSupported);
675 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>, RequireES<1, 0>, AlwaysSupported);
676 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>, RequireES<1, 0>, AlwaysSupported);
Geoff Langca271392017-04-05 12:30:00 -0400677 AddRGBAFormat(&map, GL_RGBA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
678 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
679 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>, RequireES<3, 0>, AlwaysSupported);
680 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>, RequireES<3, 0>, NeverSupported);
681 AddRGBAFormat(&map, GL_SRGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
682 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>, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported);
683 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>, NeverSupported, AlwaysSupported);
684 AddRGBAFormat(&map, GL_R8I, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
685 AddRGBAFormat(&map, GL_R8UI, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
686 AddRGBAFormat(&map, GL_R16I, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
687 AddRGBAFormat(&map, GL_R16UI, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
688 AddRGBAFormat(&map, GL_R32I, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
689 AddRGBAFormat(&map, GL_R32UI, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
690 AddRGBAFormat(&map, GL_RG8I, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
691 AddRGBAFormat(&map, GL_RG8UI, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
692 AddRGBAFormat(&map, GL_RG16I, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
693 AddRGBAFormat(&map, GL_RG16UI, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
694 AddRGBAFormat(&map, GL_RG32I, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
695 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>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported);
696 AddRGBAFormat(&map, GL_RG32UI, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
697 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
698 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);
699 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
700 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);
701 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
702 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);
703 AddRGBAFormat(&map, GL_RGBA8I, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
704 AddRGBAFormat(&map, GL_RGBA8UI, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
705 AddRGBAFormat(&map, GL_RGBA16I, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
706 AddRGBAFormat(&map, GL_RGBA16UI, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
707 AddRGBAFormat(&map, GL_RGBA32I, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
708 AddRGBAFormat(&map, GL_RGBA32UI, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
Jamie Madilla3944d42016-07-22 22:13:26 -0400709
Geoff Langca271392017-04-05 12:30:00 -0400710 AddRGBAFormat(&map, GL_BGRA8_EXT, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
711 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>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
712 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>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000713
Olli Etuahoceffd202018-01-08 16:39:45 +0200714 // Special format that is used for D3D textures that are used within ANGLE via the
715 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
716 // this format, but textures in this format can be created from D3D textures, and filtering them
717 // and rendering to them is allowed.
718 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);
719
Jamie Madillec0b5802016-07-04 13:11:59 -0400720 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400721 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);
Jamie Madillec0b5802016-07-04 13:11:59 -0400722
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000723 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400724 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
725 // | | | | | | | type | | | | |
726 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, HalfFloatRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
727 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, HalfFloatRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
728 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRGBRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
729 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRGBARenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
730 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
731 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
732 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
733 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000734
735 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400736 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
Lingfeng Yang56e95402018-02-19 16:45:26 -0800737 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireES<1, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
Geoff Langca271392017-04-05 12:30:00 -0400738 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
739 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
740 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported );
741 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>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, AlwaysSupported );
742 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>, RequireES<3, 0>, AlwaysSupported );
Corentin Walleze0902642014-11-04 12:32:15 -0800743 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000744
745 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400746 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
747 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
748 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
749 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
750 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
751 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
752 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
753 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
754 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
755 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000756
757 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lange88e4542018-05-03 15:05:57 -0400758 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
759 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11UnsignedTexture>, NeverSupported, AlwaysSupported);
760 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11SignedTexture>, NeverSupported, AlwaysSupported);
761 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11UnsignedTexture>, NeverSupported, AlwaysSupported);
762 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11SignedTexture>, NeverSupported, AlwaysSupported);
763 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGB8Texture>, NeverSupported, AlwaysSupported);
764 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Texture>, NeverSupported, AlwaysSupported);
765 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughARGB8Texture>, NeverSupported, AlwaysSupported);
766 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, NeverSupported, AlwaysSupported);
767 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGBA8Texture>, NeverSupported, AlwaysSupported);
768 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Alpha8Texture>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000769
770 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400771 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
772 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
773 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000774
775 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang86f81162017-10-30 15:10:45 -0400776 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT3>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000777
778 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400779 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400780
781 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400782 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000783
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800784 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400785 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
786 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
787 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
788 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
789 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800790
Geoff Lang60ad73d2015-10-23 10:08:44 -0400791 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400792 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
793 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
794 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
795 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
796 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
797 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
798 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
799 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
800 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
801 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
802 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
803 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
804 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
805 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
806 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400807
Geoff Langca271392017-04-05 12:30:00 -0400808 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
809 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
810 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
811 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
812 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
813 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
814 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
815 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
816 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
817 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
818 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
819 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
820 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
821 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400822
Corentin Walleze0902642014-11-04 12:32:15 -0800823 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
824 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
825 // - All other stencil formats (all depth-stencil) are either float or normalized
826 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400827 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
Lingfeng Yang56e95402018-02-19 16:45:26 -0800828 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireES<1, 0>, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800829
830 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400831 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
832 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
833 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
834 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
835 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
836 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800837
Vincent Lang25ab4512016-05-13 18:13:59 +0200838 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400839 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
840 AddRGBAFormat(&map, GL_R16_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
841 AddRGBAFormat(&map, GL_R16_SNORM_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
842 AddRGBAFormat(&map, GL_RG16_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
843 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
844 AddRGBAFormat(&map, GL_RGB16_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
845 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
846 AddRGBAFormat(&map, GL_RGBA16_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
847 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
Vincent Lang25ab4512016-05-13 18:13:59 +0200848
Geoff Langca271392017-04-05 12:30:00 -0400849 // Unsized formats
Geoff Lange24032a2018-03-28 15:41:46 -0400850 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
851 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
852 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
853 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
854 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
855 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, AlwaysSupported, AlwaysSupported);
856 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>, RequireES<1, 0>, AlwaysSupported);
857 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
858 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>, RequireES<1, 0>, AlwaysSupported);
859 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>, RequireES<1, 0>, AlwaysSupported);
860 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<1, 0>, RequireES<1, 0>, AlwaysSupported);
861 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>, RequireES<1, 0>, AlwaysSupported);
862 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
863 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_SRGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
864 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>, RequireExt<&Extensions::sRGB>, AlwaysSupported);
Geoff Langca271392017-04-05 12:30:00 -0400865
Geoff Lange24032a2018-03-28 15:41:46 -0400866 AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
Geoff Langca271392017-04-05 12:30:00 -0400867
868 // Unsized integer formats
869 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
870 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
871 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);
872 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
873 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);
874 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
875 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);
876 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
877 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);
878 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
879 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);
880 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
881 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);
882 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
883 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);
884 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
885 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);
886 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
887 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);
888 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
889 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);
890 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
891 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);
892 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
893 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);
894 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);
895
896 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400897 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
898 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
899 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
900 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
901 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
902 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, UnsizedHalfFloatOESRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
903 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, UnsizedHalfFloatOESRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
904 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, UnsizedHalfFloatOESRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
905 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, UnsizedHalfFloatOESRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
906 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
907 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
908 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langdbcced82017-06-06 15:55:54 -0400909 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 );
910 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 );
Geoff Lang677bb6f2017-04-05 12:40:40 -0400911 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langca271392017-04-05 12:30:00 -0400912
913 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400914 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Lingfeng Yang56e95402018-02-19 16:45:26 -0800915 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported, AlwaysSupported );
916 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported, AlwaysSupported );
917 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported, AlwaysSupported );
Geoff Lang677bb6f2017-04-05 12:40:40 -0400918 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
919 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
920 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
921 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
922 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
923 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langca271392017-04-05 12:30:00 -0400924
925 // Unsized depth stencil formats
926 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
Lingfeng Yang56e95402018-02-19 16:45:26 -0800927 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireES<1, 0>, AlwaysSupported);
928 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireES<1, 0>, AlwaysSupported);
929 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<1, 0>, RequireES<1, 0>, AlwaysSupported);
Geoff Langca271392017-04-05 12:30:00 -0400930 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>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
931 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>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
Lingfeng Yang56e95402018-02-19 16:45:26 -0800932 AddDepthStencilFormat(&map, GL_STENCIL, false, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireES<1, 0>, NeverSupported);
Geoff Lang9bbad182015-09-04 11:07:29 -0400933 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800934
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000935 return map;
936}
937
Geoff Lange4a492b2014-06-19 14:14:41 -0400938static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000939{
Geoff Lange4a492b2014-06-19 14:14:41 -0400940 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
941 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000942}
943
Geoff Lange4a492b2014-06-19 14:14:41 -0400944static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400945{
946 FormatSet result;
947
Geoff Langca271392017-04-05 12:30:00 -0400948 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400949 {
Geoff Langca271392017-04-05 12:30:00 -0400950 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400951 {
Geoff Langca271392017-04-05 12:30:00 -0400952 if (type.second.sized)
953 {
954 // TODO(jmadill): Fix this hack.
955 if (internalFormat.first == GL_BGR565_ANGLEX)
956 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400957
Geoff Langca271392017-04-05 12:30:00 -0400958 result.insert(internalFormat.first);
959 }
Geoff Langcec35902014-04-16 10:52:36 -0400960 }
961 }
962
963 return result;
964}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000965
Geoff Lang5d601382014-07-22 15:14:06 -0400966const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000967{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200968 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000969 {
Frank Henigman95fb2a12018-05-27 20:17:05 -0400970 case GL_UNSIGNED_BYTE:
971 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200972 {
973 static const Type info = GenTypeInfo(1, false);
974 return info;
975 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400976 case GL_UNSIGNED_SHORT:
977 case GL_SHORT:
978 case GL_HALF_FLOAT:
979 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200980 {
981 static const Type info = GenTypeInfo(2, false);
982 return info;
983 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400984 case GL_UNSIGNED_INT:
985 case GL_INT:
986 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200987 {
988 static const Type info = GenTypeInfo(4, false);
989 return info;
990 }
Frank Henigman95fb2a12018-05-27 20:17:05 -0400991 case GL_UNSIGNED_SHORT_5_6_5:
992 case GL_UNSIGNED_SHORT_4_4_4_4:
993 case GL_UNSIGNED_SHORT_5_5_5_1:
994 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
995 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200996 {
997 static const Type info = GenTypeInfo(2, true);
998 return info;
999 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001000 case GL_UNSIGNED_INT_2_10_10_10_REV:
1001 case GL_UNSIGNED_INT_24_8:
1002 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1003 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001004 {
1005 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1006 static const Type info = GenTypeInfo(4, true);
1007 return info;
1008 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001009 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001010 {
1011 static const Type info = GenTypeInfo(8, true);
1012 return info;
1013 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001014 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001015 {
1016 static const Type defaultInfo;
1017 return defaultInfo;
1018 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001019 }
1020}
1021
Geoff Langca271392017-04-05 12:30:00 -04001022const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001023{
Geoff Langca271392017-04-05 12:30:00 -04001024 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001025 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001026 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001027
1028 // Sized internal formats only have one type per entry
1029 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001030 {
Geoff Lang5d601382014-07-22 15:14:06 -04001031 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001032 }
Geoff Langca271392017-04-05 12:30:00 -04001033
1034 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1035 if (!internalFormatInfo.sized)
1036 {
1037 return defaultInternalFormat;
1038 }
1039
1040 return internalFormatInfo;
1041}
1042
1043const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1044{
1045 static const InternalFormat defaultInternalFormat;
1046 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1047
1048 auto internalFormatIter = formatMap.find(internalFormat);
1049 if (internalFormatIter == formatMap.end())
1050 {
1051 return defaultInternalFormat;
1052 }
1053
1054 // If the internal format is sized, simply return it without the type check.
1055 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1056 {
1057 return internalFormatIter->second.begin()->second;
1058 }
1059
1060 auto typeIter = internalFormatIter->second.find(type);
1061 if (typeIter == internalFormatIter->second.end())
1062 {
1063 return defaultInternalFormat;
1064 }
1065
1066 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001067}
1068
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001069GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1070{
1071 const auto &typeInfo = GetTypeInfo(formatType);
1072 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1073 return components * typeInfo.bytes;
1074}
1075
Corentin Wallez886de362016-09-27 10:49:35 -04001076ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001077 GLsizei width,
1078 GLint alignment,
1079 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001080{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001081 // Compressed images do not use pack/unpack parameters.
1082 if (compressed)
1083 {
1084 ASSERT(rowLength == 0);
Jeff Gilbert48590352017-11-07 16:03:38 -08001085 return computeCompressedImageSize(Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001086 }
1087
Geoff Lang3f234062016-07-13 15:35:45 -04001088 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001089 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001090
1091 ASSERT(alignment > 0 && isPow2(alignment));
1092 CheckedNumeric<GLuint> checkedAlignment(alignment);
1093 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1094 ANGLE_TRY_CHECKED_MATH(aligned);
1095 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001096}
1097
Corentin Wallez0e487192016-10-03 16:30:38 -04001098ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1099 GLint imageHeight,
1100 GLuint rowPitch) const
1101{
1102 GLuint rows =
1103 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1104 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1105
1106 auto depthPitch = checkedRowPitch * rows;
1107 ANGLE_TRY_CHECKED_MATH(depthPitch);
1108 return depthPitch.ValueOrDie();
1109}
1110
Corentin Wallez886de362016-09-27 10:49:35 -04001111ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Frank Henigman95fb2a12018-05-27 20:17:05 -04001112 GLsizei width,
1113 GLsizei height,
1114 GLint alignment,
1115 GLint rowLength,
1116 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001117{
Jamie Madille2e406c2016-06-02 13:04:10 -04001118 GLuint rowPitch = 0;
1119 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001120 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001121}
1122
Jeff Gilbert48590352017-11-07 16:03:38 -08001123ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001124{
Jamie Madill513558d2016-06-02 13:04:11 -04001125 CheckedNumeric<GLuint> checkedWidth(size.width);
1126 CheckedNumeric<GLuint> checkedHeight(size.height);
1127 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001128 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1129 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001130
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001131 ASSERT(compressed);
1132 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1133 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1134 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1135 ANGLE_TRY_CHECKED_MATH(bytes);
1136 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001137}
1138
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001139ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLenum formatType,
1140 GLuint rowPitch,
1141 GLuint depthPitch,
1142 const PixelStoreStateBase &state,
1143 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001144{
Olli Etuaho989cac32016-06-08 16:18:49 -07001145 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1146 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001147 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1148 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1149 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001150 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001151 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001152 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001153 {
1154 checkedSkipImagesBytes = 0;
1155 }
1156 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1157 checkedSkipPixels * checkedPixelBytes;
1158 ANGLE_TRY_CHECKED_MATH(skipBytes);
1159 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001160}
1161
Frank Henigman95fb2a12018-05-27 20:17:05 -04001162ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(GLenum formatType,
1163 const Extents &size,
1164 const PixelStoreStateBase &state,
1165 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001166{
Corentin Wallez886de362016-09-27 10:49:35 -04001167 GLuint rowPitch = 0;
1168 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001169 rowPitch);
1170
Corentin Wallez0e487192016-10-03 16:30:38 -04001171 GLuint depthPitch = 0;
1172 if (is3D)
1173 {
1174 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1175 }
1176
Corentin Wallez886de362016-09-27 10:49:35 -04001177 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001178 if (compressed)
1179 {
Jeff Gilbert48590352017-11-07 16:03:38 -08001180 ANGLE_TRY_RESULT(computeCompressedImageSize(size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001181 }
Corentin Wallez886de362016-09-27 10:49:35 -04001182 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001183 {
Corentin Wallez886de362016-09-27 10:49:35 -04001184 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1185 checkedCopyBytes += size.width * bytes;
1186
1187 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1188 checkedCopyBytes += heightMinusOne * rowPitch;
1189
1190 if (is3D)
1191 {
1192 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1193 checkedCopyBytes += depthMinusOne * depthPitch;
1194 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001195 }
1196
Corentin Wallez886de362016-09-27 10:49:35 -04001197 CheckedNumeric<GLuint> checkedSkipBytes = 0;
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001198 ANGLE_TRY_RESULT(computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D),
1199 checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001200
1201 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1202
1203 ANGLE_TRY_CHECKED_MATH(endByte);
1204 return endByte.ValueOrDie();
1205}
1206
Geoff Langca271392017-04-05 12:30:00 -04001207GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001208{
Geoff Langca271392017-04-05 12:30:00 -04001209 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1210 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001211 {
Geoff Langca271392017-04-05 12:30:00 -04001212 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001213 }
Geoff Langca271392017-04-05 12:30:00 -04001214
1215 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001216}
1217
Geoff Lange4a492b2014-06-19 14:14:41 -04001218const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001219{
Geoff Lange4a492b2014-06-19 14:14:41 -04001220 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001221 return formatSet;
1222}
1223
Jamie Madill09e2d932015-07-14 16:40:31 -04001224AttributeType GetAttributeType(GLenum enumValue)
1225{
1226 switch (enumValue)
1227 {
1228 case GL_FLOAT:
1229 return ATTRIBUTE_FLOAT;
1230 case GL_FLOAT_VEC2:
1231 return ATTRIBUTE_VEC2;
1232 case GL_FLOAT_VEC3:
1233 return ATTRIBUTE_VEC3;
1234 case GL_FLOAT_VEC4:
1235 return ATTRIBUTE_VEC4;
1236 case GL_INT:
1237 return ATTRIBUTE_INT;
1238 case GL_INT_VEC2:
1239 return ATTRIBUTE_IVEC2;
1240 case GL_INT_VEC3:
1241 return ATTRIBUTE_IVEC3;
1242 case GL_INT_VEC4:
1243 return ATTRIBUTE_IVEC4;
1244 case GL_UNSIGNED_INT:
1245 return ATTRIBUTE_UINT;
1246 case GL_UNSIGNED_INT_VEC2:
1247 return ATTRIBUTE_UVEC2;
1248 case GL_UNSIGNED_INT_VEC3:
1249 return ATTRIBUTE_UVEC3;
1250 case GL_UNSIGNED_INT_VEC4:
1251 return ATTRIBUTE_UVEC4;
1252 case GL_FLOAT_MAT2:
1253 return ATTRIBUTE_MAT2;
1254 case GL_FLOAT_MAT3:
1255 return ATTRIBUTE_MAT3;
1256 case GL_FLOAT_MAT4:
1257 return ATTRIBUTE_MAT4;
1258 case GL_FLOAT_MAT2x3:
1259 return ATTRIBUTE_MAT2x3;
1260 case GL_FLOAT_MAT2x4:
1261 return ATTRIBUTE_MAT2x4;
1262 case GL_FLOAT_MAT3x2:
1263 return ATTRIBUTE_MAT3x2;
1264 case GL_FLOAT_MAT3x4:
1265 return ATTRIBUTE_MAT3x4;
1266 case GL_FLOAT_MAT4x2:
1267 return ATTRIBUTE_MAT4x2;
1268 case GL_FLOAT_MAT4x3:
1269 return ATTRIBUTE_MAT4x3;
1270 default:
1271 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001272#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001273 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001274#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001275 }
1276}
1277
Frank Henigman95fb2a12018-05-27 20:17:05 -04001278angle::Format::ID GetVertexFormatID(GLenum type,
1279 GLboolean normalized,
1280 GLuint components,
1281 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001282{
1283 switch (type)
1284 {
1285 case GL_BYTE:
1286 switch (components)
1287 {
1288 case 1:
1289 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001290 return angle::Format::ID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001291 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001292 return angle::Format::ID::R8_SNORM;
1293 return angle::Format::ID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001294 case 2:
1295 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001296 return angle::Format::ID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001297 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001298 return angle::Format::ID::R8G8_SNORM;
1299 return angle::Format::ID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001300 case 3:
1301 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001302 return angle::Format::ID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001303 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001304 return angle::Format::ID::R8G8B8_SNORM;
1305 return angle::Format::ID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001306 case 4:
1307 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001308 return angle::Format::ID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001309 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001310 return angle::Format::ID::R8G8B8A8_SNORM;
1311 return angle::Format::ID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001312 default:
1313 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001314#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001315 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001316#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001317 }
1318 case GL_UNSIGNED_BYTE:
1319 switch (components)
1320 {
1321 case 1:
1322 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001323 return angle::Format::ID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001324 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001325 return angle::Format::ID::R8_UNORM;
1326 return angle::Format::ID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001327 case 2:
1328 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001329 return angle::Format::ID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001330 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001331 return angle::Format::ID::R8G8_UNORM;
1332 return angle::Format::ID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001333 case 3:
1334 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001335 return angle::Format::ID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001336 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001337 return angle::Format::ID::R8G8B8_UNORM;
1338 return angle::Format::ID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001339 case 4:
1340 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001341 return angle::Format::ID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001342 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001343 return angle::Format::ID::R8G8B8A8_UNORM;
1344 return angle::Format::ID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001345 default:
1346 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001347#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001348 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001349#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001350 }
1351 case GL_SHORT:
1352 switch (components)
1353 {
1354 case 1:
1355 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001356 return angle::Format::ID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001357 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001358 return angle::Format::ID::R16_SNORM;
1359 return angle::Format::ID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001360 case 2:
1361 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001362 return angle::Format::ID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001363 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001364 return angle::Format::ID::R16G16_SNORM;
1365 return angle::Format::ID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001366 case 3:
1367 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001368 return angle::Format::ID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001369 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001370 return angle::Format::ID::R16G16B16_SNORM;
1371 return angle::Format::ID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001372 case 4:
1373 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001374 return angle::Format::ID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001375 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001376 return angle::Format::ID::R16G16B16A16_SNORM;
1377 return angle::Format::ID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001378 default:
1379 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001380#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001381 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001382#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001383 }
1384 case GL_UNSIGNED_SHORT:
1385 switch (components)
1386 {
1387 case 1:
1388 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001389 return angle::Format::ID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001390 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001391 return angle::Format::ID::R16_UNORM;
1392 return angle::Format::ID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001393 case 2:
1394 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001395 return angle::Format::ID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001396 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001397 return angle::Format::ID::R16G16_UNORM;
1398 return angle::Format::ID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001399 case 3:
1400 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001401 return angle::Format::ID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001402 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001403 return angle::Format::ID::R16G16B16_UNORM;
1404 return angle::Format::ID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001405 case 4:
1406 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001407 return angle::Format::ID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001408 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001409 return angle::Format::ID::R16G16B16A16_UNORM;
1410 return angle::Format::ID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001411 default:
1412 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001413#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001414 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001415#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001416 }
1417 case GL_INT:
1418 switch (components)
1419 {
1420 case 1:
1421 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001422 return angle::Format::ID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001423 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001424 return angle::Format::ID::R32_SNORM;
1425 return angle::Format::ID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001426 case 2:
1427 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001428 return angle::Format::ID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001429 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001430 return angle::Format::ID::R32G32_SNORM;
1431 return angle::Format::ID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001432 case 3:
1433 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001434 return angle::Format::ID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001435 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001436 return angle::Format::ID::R32G32B32_SNORM;
1437 return angle::Format::ID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001438 case 4:
1439 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001440 return angle::Format::ID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001441 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001442 return angle::Format::ID::R32G32B32A32_SNORM;
1443 return angle::Format::ID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001444 default:
1445 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001446#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001447 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001448#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001449 }
1450 case GL_UNSIGNED_INT:
1451 switch (components)
1452 {
1453 case 1:
1454 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001455 return angle::Format::ID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001456 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001457 return angle::Format::ID::R32_UNORM;
1458 return angle::Format::ID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001459 case 2:
1460 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001461 return angle::Format::ID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001462 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001463 return angle::Format::ID::R32G32_UNORM;
1464 return angle::Format::ID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001465 case 3:
1466 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001467 return angle::Format::ID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001468 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001469 return angle::Format::ID::R32G32B32_UNORM;
1470 return angle::Format::ID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001471 case 4:
1472 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001473 return angle::Format::ID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001474 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001475 return angle::Format::ID::R32G32B32A32_UNORM;
1476 return angle::Format::ID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001477 default:
1478 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001479#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001480 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001481#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001482 }
1483 case GL_FLOAT:
1484 switch (components)
1485 {
1486 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001487 return angle::Format::ID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001488 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001489 return angle::Format::ID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001490 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001491 return angle::Format::ID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001492 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001493 return angle::Format::ID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001494 default:
1495 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001496#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001497 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001498#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001499 }
1500 case GL_HALF_FLOAT:
1501 switch (components)
1502 {
1503 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001504 return angle::Format::ID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001505 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001506 return angle::Format::ID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001507 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001508 return angle::Format::ID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001509 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001510 return angle::Format::ID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001511 default:
1512 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001513#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001514 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001515#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001516 }
1517 case GL_FIXED:
1518 switch (components)
1519 {
1520 case 1:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001521 return angle::Format::ID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001522 case 2:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001523 return angle::Format::ID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001524 case 3:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001525 return angle::Format::ID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001526 case 4:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001527 return angle::Format::ID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001528 default:
1529 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001530#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001531 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001532#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001533 }
1534 case GL_INT_2_10_10_10_REV:
1535 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001536 return angle::Format::ID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001537 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001538 return angle::Format::ID::R10G10B10A2_SNORM;
1539 return angle::Format::ID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001540 case GL_UNSIGNED_INT_2_10_10_10_REV:
1541 if (pureInteger)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001542 return angle::Format::ID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001543 if (normalized)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001544 return angle::Format::ID::R10G10B10A2_UNORM;
1545 return angle::Format::ID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001546 default:
1547 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001548#if !UNREACHABLE_IS_NORETURN
Frank Henigman95fb2a12018-05-27 20:17:05 -04001549 return angle::Format::ID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001550#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001551 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001552}
1553
Frank Henigman95fb2a12018-05-27 20:17:05 -04001554angle::Format::ID GetVertexFormatID(const VertexAttribute &attrib)
1555{
1556 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1557}
1558
1559// TODO(fjhenigman): Do away with VertexFormatType; use angle::Format::ID instead. anglebug.com/2531
1560VertexFormatType GetVertexFormatType(GLenum type,
1561 GLboolean normalized,
1562 GLuint components,
1563 bool pureInteger)
1564{
1565 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1566 {
1567 case angle::Format::ID::R8_SINT:
1568 return VERTEX_FORMAT_SBYTE1_INT;
1569 case angle::Format::ID::R8_SNORM:
1570 return VERTEX_FORMAT_SBYTE1_NORM;
1571 case angle::Format::ID::R8_SSCALED:
1572 return VERTEX_FORMAT_SBYTE1;
1573 case angle::Format::ID::R8G8_SINT:
1574 return VERTEX_FORMAT_SBYTE2_INT;
1575 case angle::Format::ID::R8G8_SNORM:
1576 return VERTEX_FORMAT_SBYTE2_NORM;
1577 case angle::Format::ID::R8G8_SSCALED:
1578 return VERTEX_FORMAT_SBYTE2;
1579 case angle::Format::ID::R8G8B8_SINT:
1580 return VERTEX_FORMAT_SBYTE3_INT;
1581 case angle::Format::ID::R8G8B8_SNORM:
1582 return VERTEX_FORMAT_SBYTE3_NORM;
1583 case angle::Format::ID::R8G8B8_SSCALED:
1584 return VERTEX_FORMAT_SBYTE3;
1585 case angle::Format::ID::R8G8B8A8_SINT:
1586 return VERTEX_FORMAT_SBYTE4_INT;
1587 case angle::Format::ID::R8G8B8A8_SNORM:
1588 return VERTEX_FORMAT_SBYTE4_NORM;
1589 case angle::Format::ID::R8G8B8A8_SSCALED:
1590 return VERTEX_FORMAT_SBYTE4;
1591 case angle::Format::ID::R8_UINT:
1592 return VERTEX_FORMAT_UBYTE1_INT;
1593 case angle::Format::ID::R8_UNORM:
1594 return VERTEX_FORMAT_UBYTE1_NORM;
1595 case angle::Format::ID::R8_USCALED:
1596 return VERTEX_FORMAT_UBYTE1;
1597 case angle::Format::ID::R8G8_UINT:
1598 return VERTEX_FORMAT_UBYTE2_INT;
1599 case angle::Format::ID::R8G8_UNORM:
1600 return VERTEX_FORMAT_UBYTE2_NORM;
1601 case angle::Format::ID::R8G8_USCALED:
1602 return VERTEX_FORMAT_UBYTE2;
1603 case angle::Format::ID::R8G8B8_UINT:
1604 return VERTEX_FORMAT_UBYTE3_INT;
1605 case angle::Format::ID::R8G8B8_UNORM:
1606 return VERTEX_FORMAT_UBYTE3_NORM;
1607 case angle::Format::ID::R8G8B8_USCALED:
1608 return VERTEX_FORMAT_UBYTE3;
1609 case angle::Format::ID::R8G8B8A8_UINT:
1610 return VERTEX_FORMAT_UBYTE4_INT;
1611 case angle::Format::ID::R8G8B8A8_UNORM:
1612 return VERTEX_FORMAT_UBYTE4_NORM;
1613 case angle::Format::ID::R8G8B8A8_USCALED:
1614 return VERTEX_FORMAT_UBYTE4;
1615 case angle::Format::ID::R16_SINT:
1616 return VERTEX_FORMAT_SSHORT1_INT;
1617 case angle::Format::ID::R16_SNORM:
1618 return VERTEX_FORMAT_SSHORT1_NORM;
1619 case angle::Format::ID::R16_SSCALED:
1620 return VERTEX_FORMAT_SSHORT1;
1621 case angle::Format::ID::R16G16_SINT:
1622 return VERTEX_FORMAT_SSHORT2_INT;
1623 case angle::Format::ID::R16G16_SNORM:
1624 return VERTEX_FORMAT_SSHORT2_NORM;
1625 case angle::Format::ID::R16G16_SSCALED:
1626 return VERTEX_FORMAT_SSHORT2;
1627 case angle::Format::ID::R16G16B16_SINT:
1628 return VERTEX_FORMAT_SSHORT3_INT;
1629 case angle::Format::ID::R16G16B16_SNORM:
1630 return VERTEX_FORMAT_SSHORT3_NORM;
1631 case angle::Format::ID::R16G16B16_SSCALED:
1632 return VERTEX_FORMAT_SSHORT3;
1633 case angle::Format::ID::R16G16B16A16_SINT:
1634 return VERTEX_FORMAT_SSHORT4_INT;
1635 case angle::Format::ID::R16G16B16A16_SNORM:
1636 return VERTEX_FORMAT_SSHORT4_NORM;
1637 case angle::Format::ID::R16G16B16A16_SSCALED:
1638 return VERTEX_FORMAT_SSHORT4;
1639 case angle::Format::ID::R16_UINT:
1640 return VERTEX_FORMAT_USHORT1_INT;
1641 case angle::Format::ID::R16_UNORM:
1642 return VERTEX_FORMAT_USHORT1_NORM;
1643 case angle::Format::ID::R16_USCALED:
1644 return VERTEX_FORMAT_USHORT1;
1645 case angle::Format::ID::R16G16_UINT:
1646 return VERTEX_FORMAT_USHORT2_INT;
1647 case angle::Format::ID::R16G16_UNORM:
1648 return VERTEX_FORMAT_USHORT2_NORM;
1649 case angle::Format::ID::R16G16_USCALED:
1650 return VERTEX_FORMAT_USHORT2;
1651 case angle::Format::ID::R16G16B16_UINT:
1652 return VERTEX_FORMAT_USHORT3_INT;
1653 case angle::Format::ID::R16G16B16_UNORM:
1654 return VERTEX_FORMAT_USHORT3_NORM;
1655 case angle::Format::ID::R16G16B16_USCALED:
1656 return VERTEX_FORMAT_USHORT3;
1657 case angle::Format::ID::R16G16B16A16_UINT:
1658 return VERTEX_FORMAT_USHORT4_INT;
1659 case angle::Format::ID::R16G16B16A16_UNORM:
1660 return VERTEX_FORMAT_USHORT4_NORM;
1661 case angle::Format::ID::R16G16B16A16_USCALED:
1662 return VERTEX_FORMAT_USHORT4;
1663 case angle::Format::ID::R32_SINT:
1664 return VERTEX_FORMAT_SINT1_INT;
1665 case angle::Format::ID::R32_SNORM:
1666 return VERTEX_FORMAT_SINT1_NORM;
1667 case angle::Format::ID::R32_SSCALED:
1668 return VERTEX_FORMAT_SINT1;
1669 case angle::Format::ID::R32G32_SINT:
1670 return VERTEX_FORMAT_SINT2_INT;
1671 case angle::Format::ID::R32G32_SNORM:
1672 return VERTEX_FORMAT_SINT2_NORM;
1673 case angle::Format::ID::R32G32_SSCALED:
1674 return VERTEX_FORMAT_SINT2;
1675 case angle::Format::ID::R32G32B32_SINT:
1676 return VERTEX_FORMAT_SINT3_INT;
1677 case angle::Format::ID::R32G32B32_SNORM:
1678 return VERTEX_FORMAT_SINT3_NORM;
1679 case angle::Format::ID::R32G32B32_SSCALED:
1680 return VERTEX_FORMAT_SINT3;
1681 case angle::Format::ID::R32G32B32A32_SINT:
1682 return VERTEX_FORMAT_SINT4_INT;
1683 case angle::Format::ID::R32G32B32A32_SNORM:
1684 return VERTEX_FORMAT_SINT4_NORM;
1685 case angle::Format::ID::R32G32B32A32_SSCALED:
1686 return VERTEX_FORMAT_SINT4;
1687 case angle::Format::ID::R32_UINT:
1688 return VERTEX_FORMAT_UINT1_INT;
1689 case angle::Format::ID::R32_UNORM:
1690 return VERTEX_FORMAT_UINT1_NORM;
1691 case angle::Format::ID::R32_USCALED:
1692 return VERTEX_FORMAT_UINT1;
1693 case angle::Format::ID::R32G32_UINT:
1694 return VERTEX_FORMAT_UINT2_INT;
1695 case angle::Format::ID::R32G32_UNORM:
1696 return VERTEX_FORMAT_UINT2_NORM;
1697 case angle::Format::ID::R32G32_USCALED:
1698 return VERTEX_FORMAT_UINT2;
1699 case angle::Format::ID::R32G32B32_UINT:
1700 return VERTEX_FORMAT_UINT3_INT;
1701 case angle::Format::ID::R32G32B32_UNORM:
1702 return VERTEX_FORMAT_UINT3_NORM;
1703 case angle::Format::ID::R32G32B32_USCALED:
1704 return VERTEX_FORMAT_UINT3;
1705 case angle::Format::ID::R32G32B32A32_UINT:
1706 return VERTEX_FORMAT_UINT4_INT;
1707 case angle::Format::ID::R32G32B32A32_UNORM:
1708 return VERTEX_FORMAT_UINT4_NORM;
1709 case angle::Format::ID::R32G32B32A32_USCALED:
1710 return VERTEX_FORMAT_UINT4;
1711 case angle::Format::ID::R32_FLOAT:
1712 return VERTEX_FORMAT_FLOAT1;
1713 case angle::Format::ID::R32G32_FLOAT:
1714 return VERTEX_FORMAT_FLOAT2;
1715 case angle::Format::ID::R32G32B32_FLOAT:
1716 return VERTEX_FORMAT_FLOAT3;
1717 case angle::Format::ID::R32G32B32A32_FLOAT:
1718 return VERTEX_FORMAT_FLOAT4;
1719 case angle::Format::ID::R16_FLOAT:
1720 return VERTEX_FORMAT_HALF1;
1721 case angle::Format::ID::R16G16_FLOAT:
1722 return VERTEX_FORMAT_HALF2;
1723 case angle::Format::ID::R16G16B16_FLOAT:
1724 return VERTEX_FORMAT_HALF3;
1725 case angle::Format::ID::R16G16B16A16_FLOAT:
1726 return VERTEX_FORMAT_HALF4;
1727 case angle::Format::ID::R32_FIXED:
1728 return VERTEX_FORMAT_FIXED1;
1729 case angle::Format::ID::R32G32_FIXED:
1730 return VERTEX_FORMAT_FIXED2;
1731 case angle::Format::ID::R32G32B32_FIXED:
1732 return VERTEX_FORMAT_FIXED3;
1733 case angle::Format::ID::R32G32B32A32_FIXED:
1734 return VERTEX_FORMAT_FIXED4;
1735 case angle::Format::ID::R10G10B10A2_SINT:
1736 return VERTEX_FORMAT_SINT210_INT;
1737 case angle::Format::ID::R10G10B10A2_SNORM:
1738 return VERTEX_FORMAT_SINT210_NORM;
1739 case angle::Format::ID::R10G10B10A2_SSCALED:
1740 return VERTEX_FORMAT_SINT210;
1741 case angle::Format::ID::R10G10B10A2_UINT:
1742 return VERTEX_FORMAT_UINT210_INT;
1743 case angle::Format::ID::R10G10B10A2_UNORM:
1744 return VERTEX_FORMAT_UINT210_NORM;
1745 case angle::Format::ID::R10G10B10A2_USCALED:
1746 return VERTEX_FORMAT_UINT210;
1747 default:
1748 return VERTEX_FORMAT_INVALID;
1749 }
1750}
1751
Jamie Madilld3dfda22015-07-06 08:28:49 -04001752VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1753{
1754 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1755}
1756
1757VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1758{
1759 if (!attrib.enabled)
1760 {
1761 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1762 }
1763 return GetVertexFormatType(attrib);
1764}
1765
1766const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1767{
1768 switch (vertexFormatType)
1769 {
1770 case VERTEX_FORMAT_SBYTE1:
1771 {
1772 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1773 return format;
1774 }
1775 case VERTEX_FORMAT_SBYTE1_NORM:
1776 {
1777 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1778 return format;
1779 }
1780 case VERTEX_FORMAT_SBYTE2:
1781 {
1782 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1783 return format;
1784 }
1785 case VERTEX_FORMAT_SBYTE2_NORM:
1786 {
1787 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1788 return format;
1789 }
1790 case VERTEX_FORMAT_SBYTE3:
1791 {
1792 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1793 return format;
1794 }
1795 case VERTEX_FORMAT_SBYTE3_NORM:
1796 {
1797 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1798 return format;
1799 }
1800 case VERTEX_FORMAT_SBYTE4:
1801 {
1802 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1803 return format;
1804 }
1805 case VERTEX_FORMAT_SBYTE4_NORM:
1806 {
1807 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1808 return format;
1809 }
1810 case VERTEX_FORMAT_UBYTE1:
1811 {
1812 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1813 return format;
1814 }
1815 case VERTEX_FORMAT_UBYTE1_NORM:
1816 {
1817 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1818 return format;
1819 }
1820 case VERTEX_FORMAT_UBYTE2:
1821 {
1822 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1823 return format;
1824 }
1825 case VERTEX_FORMAT_UBYTE2_NORM:
1826 {
1827 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1828 return format;
1829 }
1830 case VERTEX_FORMAT_UBYTE3:
1831 {
1832 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1833 return format;
1834 }
1835 case VERTEX_FORMAT_UBYTE3_NORM:
1836 {
1837 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1838 return format;
1839 }
1840 case VERTEX_FORMAT_UBYTE4:
1841 {
1842 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1843 return format;
1844 }
1845 case VERTEX_FORMAT_UBYTE4_NORM:
1846 {
1847 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1848 return format;
1849 }
1850 case VERTEX_FORMAT_SSHORT1:
1851 {
1852 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1853 return format;
1854 }
1855 case VERTEX_FORMAT_SSHORT1_NORM:
1856 {
1857 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1858 return format;
1859 }
1860 case VERTEX_FORMAT_SSHORT2:
1861 {
1862 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1863 return format;
1864 }
1865 case VERTEX_FORMAT_SSHORT2_NORM:
1866 {
1867 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1868 return format;
1869 }
1870 case VERTEX_FORMAT_SSHORT3:
1871 {
1872 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1873 return format;
1874 }
1875 case VERTEX_FORMAT_SSHORT3_NORM:
1876 {
1877 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1878 return format;
1879 }
1880 case VERTEX_FORMAT_SSHORT4:
1881 {
1882 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1883 return format;
1884 }
1885 case VERTEX_FORMAT_SSHORT4_NORM:
1886 {
1887 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1888 return format;
1889 }
1890 case VERTEX_FORMAT_USHORT1:
1891 {
1892 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1893 return format;
1894 }
1895 case VERTEX_FORMAT_USHORT1_NORM:
1896 {
1897 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1898 return format;
1899 }
1900 case VERTEX_FORMAT_USHORT2:
1901 {
1902 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1903 return format;
1904 }
1905 case VERTEX_FORMAT_USHORT2_NORM:
1906 {
1907 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1908 return format;
1909 }
1910 case VERTEX_FORMAT_USHORT3:
1911 {
1912 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1913 return format;
1914 }
1915 case VERTEX_FORMAT_USHORT3_NORM:
1916 {
1917 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1918 return format;
1919 }
1920 case VERTEX_FORMAT_USHORT4:
1921 {
1922 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1923 return format;
1924 }
1925 case VERTEX_FORMAT_USHORT4_NORM:
1926 {
1927 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1928 return format;
1929 }
1930 case VERTEX_FORMAT_SINT1:
1931 {
1932 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1933 return format;
1934 }
1935 case VERTEX_FORMAT_SINT1_NORM:
1936 {
1937 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1938 return format;
1939 }
1940 case VERTEX_FORMAT_SINT2:
1941 {
1942 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1943 return format;
1944 }
1945 case VERTEX_FORMAT_SINT2_NORM:
1946 {
1947 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1948 return format;
1949 }
1950 case VERTEX_FORMAT_SINT3:
1951 {
1952 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1953 return format;
1954 }
1955 case VERTEX_FORMAT_SINT3_NORM:
1956 {
1957 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1958 return format;
1959 }
1960 case VERTEX_FORMAT_SINT4:
1961 {
1962 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1963 return format;
1964 }
1965 case VERTEX_FORMAT_SINT4_NORM:
1966 {
1967 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1968 return format;
1969 }
1970 case VERTEX_FORMAT_UINT1:
1971 {
1972 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1973 return format;
1974 }
1975 case VERTEX_FORMAT_UINT1_NORM:
1976 {
1977 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1978 return format;
1979 }
1980 case VERTEX_FORMAT_UINT2:
1981 {
1982 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1983 return format;
1984 }
1985 case VERTEX_FORMAT_UINT2_NORM:
1986 {
1987 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1988 return format;
1989 }
1990 case VERTEX_FORMAT_UINT3:
1991 {
1992 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1993 return format;
1994 }
1995 case VERTEX_FORMAT_UINT3_NORM:
1996 {
1997 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1998 return format;
1999 }
2000 case VERTEX_FORMAT_UINT4:
2001 {
2002 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2003 return format;
2004 }
2005 case VERTEX_FORMAT_UINT4_NORM:
2006 {
2007 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2008 return format;
2009 }
2010 case VERTEX_FORMAT_SBYTE1_INT:
2011 {
2012 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2013 return format;
2014 }
2015 case VERTEX_FORMAT_SBYTE2_INT:
2016 {
2017 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2018 return format;
2019 }
2020 case VERTEX_FORMAT_SBYTE3_INT:
2021 {
2022 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2023 return format;
2024 }
2025 case VERTEX_FORMAT_SBYTE4_INT:
2026 {
2027 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2028 return format;
2029 }
2030 case VERTEX_FORMAT_UBYTE1_INT:
2031 {
2032 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2033 return format;
2034 }
2035 case VERTEX_FORMAT_UBYTE2_INT:
2036 {
2037 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2038 return format;
2039 }
2040 case VERTEX_FORMAT_UBYTE3_INT:
2041 {
2042 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2043 return format;
2044 }
2045 case VERTEX_FORMAT_UBYTE4_INT:
2046 {
2047 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2048 return format;
2049 }
2050 case VERTEX_FORMAT_SSHORT1_INT:
2051 {
2052 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2053 return format;
2054 }
2055 case VERTEX_FORMAT_SSHORT2_INT:
2056 {
2057 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2058 return format;
2059 }
2060 case VERTEX_FORMAT_SSHORT3_INT:
2061 {
2062 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2063 return format;
2064 }
2065 case VERTEX_FORMAT_SSHORT4_INT:
2066 {
2067 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2068 return format;
2069 }
2070 case VERTEX_FORMAT_USHORT1_INT:
2071 {
2072 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2073 return format;
2074 }
2075 case VERTEX_FORMAT_USHORT2_INT:
2076 {
2077 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2078 return format;
2079 }
2080 case VERTEX_FORMAT_USHORT3_INT:
2081 {
2082 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2083 return format;
2084 }
2085 case VERTEX_FORMAT_USHORT4_INT:
2086 {
2087 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2088 return format;
2089 }
2090 case VERTEX_FORMAT_SINT1_INT:
2091 {
2092 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2093 return format;
2094 }
2095 case VERTEX_FORMAT_SINT2_INT:
2096 {
2097 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2098 return format;
2099 }
2100 case VERTEX_FORMAT_SINT3_INT:
2101 {
2102 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2103 return format;
2104 }
2105 case VERTEX_FORMAT_SINT4_INT:
2106 {
2107 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2108 return format;
2109 }
2110 case VERTEX_FORMAT_UINT1_INT:
2111 {
2112 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2113 return format;
2114 }
2115 case VERTEX_FORMAT_UINT2_INT:
2116 {
2117 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2118 return format;
2119 }
2120 case VERTEX_FORMAT_UINT3_INT:
2121 {
2122 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2123 return format;
2124 }
2125 case VERTEX_FORMAT_UINT4_INT:
2126 {
2127 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2128 return format;
2129 }
2130 case VERTEX_FORMAT_FIXED1:
2131 {
2132 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2133 return format;
2134 }
2135 case VERTEX_FORMAT_FIXED2:
2136 {
2137 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2138 return format;
2139 }
2140 case VERTEX_FORMAT_FIXED3:
2141 {
2142 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2143 return format;
2144 }
2145 case VERTEX_FORMAT_FIXED4:
2146 {
2147 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2148 return format;
2149 }
2150 case VERTEX_FORMAT_HALF1:
2151 {
2152 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2153 return format;
2154 }
2155 case VERTEX_FORMAT_HALF2:
2156 {
2157 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2158 return format;
2159 }
2160 case VERTEX_FORMAT_HALF3:
2161 {
2162 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2163 return format;
2164 }
2165 case VERTEX_FORMAT_HALF4:
2166 {
2167 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2168 return format;
2169 }
2170 case VERTEX_FORMAT_FLOAT1:
2171 {
2172 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2173 return format;
2174 }
2175 case VERTEX_FORMAT_FLOAT2:
2176 {
2177 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2178 return format;
2179 }
2180 case VERTEX_FORMAT_FLOAT3:
2181 {
2182 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2183 return format;
2184 }
2185 case VERTEX_FORMAT_FLOAT4:
2186 {
2187 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2188 return format;
2189 }
2190 case VERTEX_FORMAT_SINT210:
2191 {
2192 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2193 return format;
2194 }
2195 case VERTEX_FORMAT_UINT210:
2196 {
2197 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2198 return format;
2199 }
2200 case VERTEX_FORMAT_SINT210_NORM:
2201 {
2202 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2203 return format;
2204 }
2205 case VERTEX_FORMAT_UINT210_NORM:
2206 {
2207 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2208 return format;
2209 }
2210 case VERTEX_FORMAT_SINT210_INT:
2211 {
2212 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2213 return format;
2214 }
2215 case VERTEX_FORMAT_UINT210_INT:
2216 {
2217 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2218 return format;
2219 }
2220 default:
2221 {
2222 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2223 return format;
2224 }
2225 }
2226}
2227
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002228size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2229{
2230 switch (vertexFormatType)
2231 {
2232 case VERTEX_FORMAT_SBYTE1:
2233 case VERTEX_FORMAT_SBYTE1_NORM:
2234 case VERTEX_FORMAT_UBYTE1:
2235 case VERTEX_FORMAT_UBYTE1_NORM:
2236 case VERTEX_FORMAT_SBYTE1_INT:
2237 case VERTEX_FORMAT_UBYTE1_INT:
2238 return 1;
2239
2240 case VERTEX_FORMAT_SBYTE2:
2241 case VERTEX_FORMAT_SBYTE2_NORM:
2242 case VERTEX_FORMAT_UBYTE2:
2243 case VERTEX_FORMAT_UBYTE2_NORM:
2244 case VERTEX_FORMAT_SBYTE2_INT:
2245 case VERTEX_FORMAT_UBYTE2_INT:
2246 case VERTEX_FORMAT_SSHORT1:
2247 case VERTEX_FORMAT_SSHORT1_NORM:
2248 case VERTEX_FORMAT_USHORT1:
2249 case VERTEX_FORMAT_USHORT1_NORM:
2250 case VERTEX_FORMAT_SSHORT1_INT:
2251 case VERTEX_FORMAT_USHORT1_INT:
2252 case VERTEX_FORMAT_HALF1:
2253 return 2;
2254
2255 case VERTEX_FORMAT_SBYTE3:
2256 case VERTEX_FORMAT_SBYTE3_NORM:
2257 case VERTEX_FORMAT_UBYTE3:
2258 case VERTEX_FORMAT_UBYTE3_NORM:
2259 case VERTEX_FORMAT_SBYTE3_INT:
2260 case VERTEX_FORMAT_UBYTE3_INT:
2261 return 3;
2262
2263 case VERTEX_FORMAT_SBYTE4:
2264 case VERTEX_FORMAT_SBYTE4_NORM:
2265 case VERTEX_FORMAT_UBYTE4:
2266 case VERTEX_FORMAT_UBYTE4_NORM:
2267 case VERTEX_FORMAT_SBYTE4_INT:
2268 case VERTEX_FORMAT_UBYTE4_INT:
2269 case VERTEX_FORMAT_SSHORT2:
2270 case VERTEX_FORMAT_SSHORT2_NORM:
2271 case VERTEX_FORMAT_USHORT2:
2272 case VERTEX_FORMAT_USHORT2_NORM:
2273 case VERTEX_FORMAT_SSHORT2_INT:
2274 case VERTEX_FORMAT_USHORT2_INT:
2275 case VERTEX_FORMAT_SINT1:
2276 case VERTEX_FORMAT_SINT1_NORM:
2277 case VERTEX_FORMAT_UINT1:
2278 case VERTEX_FORMAT_UINT1_NORM:
2279 case VERTEX_FORMAT_SINT1_INT:
2280 case VERTEX_FORMAT_UINT1_INT:
2281 case VERTEX_FORMAT_HALF2:
2282 case VERTEX_FORMAT_FIXED1:
2283 case VERTEX_FORMAT_FLOAT1:
2284 case VERTEX_FORMAT_SINT210:
2285 case VERTEX_FORMAT_UINT210:
2286 case VERTEX_FORMAT_SINT210_NORM:
2287 case VERTEX_FORMAT_UINT210_NORM:
2288 case VERTEX_FORMAT_SINT210_INT:
2289 case VERTEX_FORMAT_UINT210_INT:
2290 return 4;
2291
2292 case VERTEX_FORMAT_SSHORT3:
2293 case VERTEX_FORMAT_SSHORT3_NORM:
2294 case VERTEX_FORMAT_USHORT3:
2295 case VERTEX_FORMAT_USHORT3_NORM:
2296 case VERTEX_FORMAT_SSHORT3_INT:
2297 case VERTEX_FORMAT_USHORT3_INT:
2298 case VERTEX_FORMAT_HALF3:
2299 return 6;
2300
2301 case VERTEX_FORMAT_SSHORT4:
2302 case VERTEX_FORMAT_SSHORT4_NORM:
2303 case VERTEX_FORMAT_USHORT4:
2304 case VERTEX_FORMAT_USHORT4_NORM:
2305 case VERTEX_FORMAT_SSHORT4_INT:
2306 case VERTEX_FORMAT_USHORT4_INT:
2307 case VERTEX_FORMAT_SINT2:
2308 case VERTEX_FORMAT_SINT2_NORM:
2309 case VERTEX_FORMAT_UINT2:
2310 case VERTEX_FORMAT_UINT2_NORM:
2311 case VERTEX_FORMAT_SINT2_INT:
2312 case VERTEX_FORMAT_UINT2_INT:
2313 case VERTEX_FORMAT_HALF4:
2314 case VERTEX_FORMAT_FIXED2:
2315 case VERTEX_FORMAT_FLOAT2:
2316 return 8;
2317
2318 case VERTEX_FORMAT_SINT3:
2319 case VERTEX_FORMAT_SINT3_NORM:
2320 case VERTEX_FORMAT_UINT3:
2321 case VERTEX_FORMAT_UINT3_NORM:
2322 case VERTEX_FORMAT_SINT3_INT:
2323 case VERTEX_FORMAT_UINT3_INT:
2324 case VERTEX_FORMAT_FIXED3:
2325 case VERTEX_FORMAT_FLOAT3:
2326 return 12;
2327
2328 case VERTEX_FORMAT_SINT4:
2329 case VERTEX_FORMAT_SINT4_NORM:
2330 case VERTEX_FORMAT_UINT4:
2331 case VERTEX_FORMAT_UINT4_NORM:
2332 case VERTEX_FORMAT_SINT4_INT:
2333 case VERTEX_FORMAT_UINT4_INT:
2334 case VERTEX_FORMAT_FIXED4:
2335 case VERTEX_FORMAT_FLOAT4:
2336 return 16;
2337
2338 case VERTEX_FORMAT_INVALID:
2339 default:
2340 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002341#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002342 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002343#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002344 }
2345}
2346
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002347bool ValidES3InternalFormat(GLenum internalFormat)
2348{
2349 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2350 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2351}
2352
Frank Henigman95fb2a12018-05-27 20:17:05 -04002353VertexFormat::VertexFormat(GLenum typeIn,
2354 GLboolean normalizedIn,
2355 GLuint componentsIn,
2356 bool pureIntegerIn)
2357 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002358{
2359 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002360 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2361 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002362}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002363}