blob: faf985cdc6102532e12ba78ebf6e46ecb53b259f [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
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// 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
Geoff Lang5d601382014-07-22 15:14:06 -040047Type::Type()
48 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020049 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -040050 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040051{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052}
53
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020054static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055{
Geoff Lang5d601382014-07-22 15:14:06 -040056 Type info;
57 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020058 GLuint i = 0;
59 while ((1u << i) < bytes)
60 {
61 ++i;
62 }
63 info.bytesShift = i;
64 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040065 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020066 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040067}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang5d601382014-07-22 15:14:06 -040069bool operator<(const Type& a, const Type& b)
70{
71 return memcmp(&a, &b, sizeof(Type)) < 0;
72}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000074// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040075static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076{
Geoff Lang493daf52014-07-03 13:38:44 -040077 return true;
78}
79
Geoff Langeb66a6e2016-10-31 13:06:12 -040080static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082 return false;
83}
84
Geoff Langeb66a6e2016-10-31 13:06:12 -040085template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
86static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040087{
Geoff Langeb66a6e2016-10-31 13:06:12 -040088 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040089}
90
Geoff Langcec35902014-04-16 10:52:36 -040091// Pointer to a boolean memeber of the Extensions struct
92typedef bool(Extensions::*ExtensionBool);
93
94// Check support for a single extension
95template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040096static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040097{
Geoff Lange4a492b2014-06-19 14:14:41 -040098 return extensions.*bool1;
99}
100
101// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400102template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
103static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400104{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
106 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400107}
108
109// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400110template <GLuint minCoreGLMajorVersion,
111 GLuint minCoreGLMinorVersion,
112 ExtensionBool bool1,
113 ExtensionBool bool2>
114static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400115{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400116 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
117 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400118}
119
120// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400121template <GLuint minCoreGLMajorVersion,
122 GLuint minCoreGLMinorVersion,
123 ExtensionBool bool1,
124 ExtensionBool bool2>
125static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400126{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400127 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
128 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400129}
130
131// Check support for two extensions
132template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400133static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400134{
Geoff Langabce7622014-09-19 16:13:00 -0400135 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400136}
137
Geoff Lang60ad73d2015-10-23 10:08:44 -0400138// Check support for either of two extensions
139template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400140static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400141{
142 return extensions.*bool1 || extensions.*bool2;
143}
144
Jamie Madillcd089732015-12-17 09:53:09 -0500145// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400146static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500147{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400148 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500149}
150
Geoff Lang677bb6f2017-04-05 12:40:40 -0400151static bool HalfFloatRGBRenderableSupport(const Version &clientVersion,
152 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500153{
154 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
155}
156
Geoff Lang677bb6f2017-04-05 12:40:40 -0400157static bool HalfFloatRGBARenderableSupport(const Version &clientVersion,
158 const Extensions &extensions)
159{
160 return HalfFloatSupport(clientVersion, extensions) &&
161 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
162}
163
Jamie Madillcd089732015-12-17 09:53:09 -0500164// Special function for half float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400165
166// R16F, RG16F
167static bool HalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500168{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400169 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500170}
171
Geoff Lang677bb6f2017-04-05 12:40:40 -0400172// R16F, RG16F
173static bool HalfFloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400175 // It's unclear if EXT_color_buffer_half_float gives renderability to non-OES half float
176 // textures
177 return HalfFloatRGSupport(clientVersion, extensions) &&
178 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
179}
180
181// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
182static bool UnsizedHalfFloatOESRGSupport(const Version &, const Extensions &extensions)
183{
184 return extensions.textureHalfFloat && extensions.textureRG;
185}
186
187// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
188static bool UnsizedHalfFloatOESRGRenderableSupport(const Version &clientVersion,
189 const Extensions &extensions)
190{
191 return UnsizedHalfFloatOESRGSupport(clientVersion, extensions) &&
192 extensions.colorBufferHalfFloat;
193}
194
195// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
196static bool UnsizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
197{
198 return extensions.textureHalfFloat;
199}
200
201// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
202static bool UnsizedHalfFloatOESRenderableSupport(const Version &clientVersion,
203 const Extensions &extensions)
204{
205 return UnsizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500206}
207
208// Special function for float formats with three or four channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400209
210// RGB32F, RGBA32F
Geoff Langeb66a6e2016-10-31 13:06:12 -0400211static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500212{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400213 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500214}
215
Geoff Lang677bb6f2017-04-05 12:40:40 -0400216// RGB32F
217static bool FloatRGBRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500218{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400219 return FloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
220}
221
222// RGBA32F
223static bool FloatRGBARenderableSupport(const Version &clientVersion, const Extensions &extensions)
224{
Jamie Madillcd089732015-12-17 09:53:09 -0500225 return FloatSupport(clientVersion, extensions) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400226 (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
227}
228
229// RGB + FLOAT, RGBA + FLOAT
230static bool UnsizedFloatSupport(const Version &clientVersion, const Extensions &extensions)
231{
232 return extensions.textureFloat;
233}
234
235// RGB + FLOAT
236static bool UnsizedFloatRGBRenderableSupport(const Version &clientVersion,
237 const Extensions &extensions)
238{
239 return UnsizedFloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
240}
241
242// RGBA + FLOAT
243static bool UnsizedFloatRGBARenderableSupport(const Version &clientVersion,
244 const Extensions &extensions)
245{
246 return UnsizedFloatSupport(clientVersion, extensions) &&
247 (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500248}
249
250// Special function for float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400251
252// R32F, RG32F
253static bool FloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500254{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400255 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500256}
257
Geoff Lang677bb6f2017-04-05 12:40:40 -0400258// R32F, RG32F
259static bool FloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500260{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400261 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
262}
263
264// RED + FLOAT, RG + FLOAT
265static bool UnsizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
266{
267 return extensions.textureFloat && extensions.textureRG;
268}
269
270// RED + FLOAT, RG + FLOAT
271static bool UnsizedFloatRGRenderableSupport(const Version &clientVersion,
272 const Extensions &extensions)
273{
274 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500275}
276
Geoff Lang5d601382014-07-22 15:14:06 -0400277InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400278 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400279 sized(false),
280 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400281 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400282 greenBits(0),
283 blueBits(0),
284 luminanceBits(0),
285 alphaBits(0),
286 sharedBits(0),
287 depthBits(0),
288 stencilBits(0),
289 pixelBytes(0),
290 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400291 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400292 compressedBlockWidth(0),
293 compressedBlockHeight(0),
294 format(GL_NONE),
295 type(GL_NONE),
296 componentType(GL_NONE),
297 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400298 textureSupport(NeverSupported),
299 renderSupport(NeverSupported),
300 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301{
Geoff Lang5d601382014-07-22 15:14:06 -0400302}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303
Jamie Madilla3944d42016-07-22 22:13:26 -0400304bool InternalFormat::isLUMA() const
305{
306 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
307 (luminanceBits + alphaBits) > 0);
308}
309
Geoff Langf607c602016-09-21 11:46:48 -0400310GLenum InternalFormat::getReadPixelsFormat() const
311{
312 return format;
313}
314
315GLenum InternalFormat::getReadPixelsType() const
316{
317 switch (type)
318 {
319 case GL_HALF_FLOAT:
320 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
321 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
322 // OES_texture_half_float
323 return GL_HALF_FLOAT_OES;
324
325 default:
326 return type;
327 }
328}
329
Olli Etuaho50c562d2017-06-06 14:43:30 +0300330bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
331{
332 // GLES 3.0.5 section 4.4.2.2:
333 // "Implementations are required to support the same internal formats for renderbuffers as the
334 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
335 // formats labelled "texture-only"."
336 if (!sized || compressed)
337 {
338 return false;
339 }
340
341 // Luma formats.
342 if (isLUMA())
343 {
344 return false;
345 }
346
347 // Depth/stencil formats.
348 if (depthBits > 0 || stencilBits > 0)
349 {
350 // GLES 2.0.25 table 4.5.
351 // GLES 3.0.5 section 3.8.3.1.
352 // GLES 3.1 table 8.14.
353
354 // Required formats in all versions.
355 switch (internalFormat)
356 {
357 case GL_DEPTH_COMPONENT16:
358 case GL_STENCIL_INDEX8:
359 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
360 // is in section 4.4.2.2.
361 return true;
362 default:
363 break;
364 }
365 if (version.major < 3)
366 {
367 return false;
368 }
369 // Required formats in GLES 3.0 and up.
370 switch (internalFormat)
371 {
372 case GL_DEPTH_COMPONENT32F:
373 case GL_DEPTH_COMPONENT24:
374 case GL_DEPTH32F_STENCIL8:
375 case GL_DEPTH24_STENCIL8:
376 return true;
377 default:
378 return false;
379 }
380 }
381
382 // RGBA formats.
383 // GLES 2.0.25 table 4.5.
384 // GLES 3.0.5 section 3.8.3.1.
385 // GLES 3.1 table 8.13.
386
387 // Required formats in all versions.
388 switch (internalFormat)
389 {
390 case GL_RGBA4:
391 case GL_RGB5_A1:
392 case GL_RGB565:
393 return true;
394 default:
395 break;
396 }
397 if (version.major < 3)
398 {
399 return false;
400 }
401
402 if (format == GL_BGRA_EXT)
403 {
404 return false;
405 }
406
407 switch (componentType)
408 {
409 case GL_SIGNED_NORMALIZED:
410 case GL_FLOAT:
411 return false;
412 case GL_UNSIGNED_INT:
413 case GL_INT:
414 // Integer RGB formats are not required renderbuffer formats.
415 if (alphaBits == 0 && blueBits != 0)
416 {
417 return false;
418 }
419 // All integer R and RG formats are required.
420 // Integer RGBA formats including RGB10_A2_UI are required.
421 return true;
422 case GL_UNSIGNED_NORMALIZED:
423 if (internalFormat == GL_SRGB8)
424 {
425 return false;
426 }
427 return true;
428 default:
429 UNREACHABLE();
430 return false;
431 }
432}
433
Geoff Langca271392017-04-05 12:30:00 -0400434Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400435{
436}
437
Geoff Langca271392017-04-05 12:30:00 -0400438Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400439{
Jamie Madilla3944d42016-07-22 22:13:26 -0400440}
441
Geoff Langca271392017-04-05 12:30:00 -0400442Format::Format(GLenum internalFormat, GLenum type)
443 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400444{
Jamie Madilla3944d42016-07-22 22:13:26 -0400445}
446
447Format::Format(const Format &other) = default;
448Format &Format::operator=(const Format &other) = default;
449
Jamie Madilla3944d42016-07-22 22:13:26 -0400450bool Format::valid() const
451{
Geoff Langca271392017-04-05 12:30:00 -0400452 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400453}
454
455// static
456bool Format::SameSized(const Format &a, const Format &b)
457{
Geoff Langca271392017-04-05 12:30:00 -0400458 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400459}
460
Kenneth Russell69382852017-07-21 16:38:44 -0400461static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
462{
463 // BlitFramebuffer works if the color channels are identically
464 // sized, even if there is a swizzle (for example, blitting from a
465 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
466 // be expanded and/or autogenerated if that is found necessary.
467 if (internalformat == GL_BGRA8_EXT)
468 return GL_RGBA8;
469 return internalformat;
470}
471
472// static
473bool Format::EquivalentForBlit(const Format &a, const Format &b)
474{
475 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
476 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
477}
478
Jamie Madilla3944d42016-07-22 22:13:26 -0400479// static
480Format Format::Invalid()
481{
Geoff Langca271392017-04-05 12:30:00 -0400482 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400483 return invalid;
484}
485
Yuly Novikovd73f8522017-01-13 17:48:57 -0500486std::ostream &operator<<(std::ostream &os, const Format &fmt)
487{
488 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400489 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500490}
491
Jamie Madilla3944d42016-07-22 22:13:26 -0400492bool InternalFormat::operator==(const InternalFormat &other) const
493{
Geoff Langca271392017-04-05 12:30:00 -0400494 // We assume all internal formats are unique if they have the same internal format and type
495 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400496}
497
498bool InternalFormat::operator!=(const InternalFormat &other) const
499{
Geoff Langca271392017-04-05 12:30:00 -0400500 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400501}
502
Geoff Langca271392017-04-05 12:30:00 -0400503void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400504{
Geoff Langca271392017-04-05 12:30:00 -0400505 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
506 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
507 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400508}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000509
Jamie Madilla3944d42016-07-22 22:13:26 -0400510void AddRGBAFormat(InternalFormatInfoMap *map,
511 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400512 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400513 GLuint red,
514 GLuint green,
515 GLuint blue,
516 GLuint alpha,
517 GLuint shared,
518 GLenum format,
519 GLenum type,
520 GLenum componentType,
521 bool srgb,
522 InternalFormat::SupportCheckFunction textureSupport,
523 InternalFormat::SupportCheckFunction renderSupport,
524 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400525{
526 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400527 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400528 formatInfo.sized = sized;
529 formatInfo.sizedInternalFormat =
530 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400531 formatInfo.redBits = red;
532 formatInfo.greenBits = green;
533 formatInfo.blueBits = blue;
534 formatInfo.alphaBits = alpha;
535 formatInfo.sharedBits = shared;
536 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400537 formatInfo.componentCount =
538 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400539 formatInfo.format = format;
540 formatInfo.type = type;
541 formatInfo.componentType = componentType;
542 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
543 formatInfo.textureSupport = textureSupport;
544 formatInfo.renderSupport = renderSupport;
545 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400546
547 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400548}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000549
Geoff Langca271392017-04-05 12:30:00 -0400550static void AddLUMAFormat(InternalFormatInfoMap *map,
551 GLenum internalFormat,
552 bool sized,
553 GLuint luminance,
554 GLuint alpha,
555 GLenum format,
556 GLenum type,
557 GLenum componentType,
558 InternalFormat::SupportCheckFunction textureSupport,
559 InternalFormat::SupportCheckFunction renderSupport,
560 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400561{
562 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400563 formatInfo.internalFormat = internalFormat;
564 formatInfo.sized = sized;
565 formatInfo.sizedInternalFormat =
566 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400567 formatInfo.luminanceBits = luminance;
568 formatInfo.alphaBits = alpha;
569 formatInfo.pixelBytes = (luminance + alpha) / 8;
570 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
571 formatInfo.format = format;
572 formatInfo.type = type;
573 formatInfo.componentType = componentType;
574 formatInfo.colorEncoding = GL_LINEAR;
575 formatInfo.textureSupport = textureSupport;
576 formatInfo.renderSupport = renderSupport;
577 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400578
579 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400580}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000581
Jamie Madilla3944d42016-07-22 22:13:26 -0400582void AddDepthStencilFormat(InternalFormatInfoMap *map,
583 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400584 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400585 GLuint depthBits,
586 GLuint stencilBits,
587 GLuint unusedBits,
588 GLenum format,
589 GLenum type,
590 GLenum componentType,
591 InternalFormat::SupportCheckFunction textureSupport,
592 InternalFormat::SupportCheckFunction renderSupport,
593 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400594{
595 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400596 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400597 formatInfo.sized = sized;
598 formatInfo.sizedInternalFormat =
599 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400600 formatInfo.depthBits = depthBits;
601 formatInfo.stencilBits = stencilBits;
602 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
603 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
604 formatInfo.format = format;
605 formatInfo.type = type;
606 formatInfo.componentType = componentType;
607 formatInfo.colorEncoding = GL_LINEAR;
608 formatInfo.textureSupport = textureSupport;
609 formatInfo.renderSupport = renderSupport;
610 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400611
612 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400613}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614
Geoff Langca271392017-04-05 12:30:00 -0400615void AddCompressedFormat(InternalFormatInfoMap *map,
616 GLenum internalFormat,
617 GLuint compressedBlockWidth,
618 GLuint compressedBlockHeight,
619 GLuint compressedBlockSize,
620 GLuint componentCount,
621 GLenum format,
622 GLenum type,
623 bool srgb,
624 InternalFormat::SupportCheckFunction textureSupport,
625 InternalFormat::SupportCheckFunction renderSupport,
626 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400627{
628 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400629 formatInfo.internalFormat = internalFormat;
630 formatInfo.sized = true;
631 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400632 formatInfo.compressedBlockWidth = compressedBlockWidth;
633 formatInfo.compressedBlockHeight = compressedBlockHeight;
634 formatInfo.pixelBytes = compressedBlockSize / 8;
635 formatInfo.componentCount = componentCount;
636 formatInfo.format = format;
637 formatInfo.type = type;
638 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
639 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
640 formatInfo.compressed = true;
641 formatInfo.textureSupport = textureSupport;
642 formatInfo.renderSupport = renderSupport;
643 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400644
645 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400646}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000647
Geoff Lange4a492b2014-06-19 14:14:41 -0400648static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000649{
650 InternalFormatInfoMap map;
651
652 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400653 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000654
Jamie Madilla3944d42016-07-22 22:13:26 -0400655 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656
Geoff Langca271392017-04-05 12:30:00 -0400657 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
658 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);
659 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
660 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);
661 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
662 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);
663 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
664 AddRGBAFormat(&map, GL_RGB565, true, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
665 AddRGBAFormat(&map, GL_RGBA4, true, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
666 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<2, 0>, RequireES<2, 0>, AlwaysSupported);
667 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);
668 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
669 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);
670 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);
671 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);
672 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);
673 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);
674 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);
675 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);
676 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);
677 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);
678 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);
679 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);
680 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);
681 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);
682 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);
683 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);
684 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);
685 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);
686 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);
687 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
688 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);
689 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
690 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);
691 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
692 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);
693 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);
694 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);
695 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);
696 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);
697 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);
698 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 -0400699
Geoff Langca271392017-04-05 12:30:00 -0400700 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);
701 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);
702 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 +0000703
Jamie Madillec0b5802016-07-04 13:11:59 -0400704 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400705 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 -0400706
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400708 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
709 // | | | | | | | type | | | | |
710 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>);
711 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>);
712 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>);
713 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>);
714 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
715 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
716 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
717 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 +0000718
719 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400720 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
721 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
722 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>);
723 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>);
724 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 );
725 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 );
726 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 -0800727 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000728
729 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400730 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
731 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
732 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
733 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
734 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>);
735 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>);
736 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>);
737 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
738 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
739 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 +0000740
741 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400742 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
743 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
744 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
745 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
746 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
747 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
748 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
749 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
750 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
751 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
752 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000753
754 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400755 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
756 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
757 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 +0000758
759 // From GL_ANGLE_texture_compression_dxt3
Geoff Langca271392017-04-05 12:30:00 -0400760 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000761
762 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400763 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 -0400764
765 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400766 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 +0000767
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800768 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400769 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
770 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
771 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
772 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
773 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 -0800774
Geoff Lang60ad73d2015-10-23 10:08:44 -0400775 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400776 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
777 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);
778 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);
779 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);
780 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);
781 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);
782 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);
783 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);
784 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);
785 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);
786 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);
787 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);
788 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);
789 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);
790 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 -0400791
Geoff Langca271392017-04-05 12:30:00 -0400792 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);
793 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);
794 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);
795 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);
796 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);
797 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);
798 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);
799 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);
800 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);
801 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);
802 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);
803 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);
804 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);
805 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 -0400806
Corentin Walleze0902642014-11-04 12:32:15 -0800807 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
808 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
809 // - All other stencil formats (all depth-stencil) are either float or normalized
810 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400811 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
812 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800813
814 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400815 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
816 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
817 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
818 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
819 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);
820 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 -0800821
Vincent Lang25ab4512016-05-13 18:13:59 +0200822 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400823 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
824 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);
825 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);
826 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);
827 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);
828 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);
829 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);
830 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);
831 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 +0200832
Geoff Langca271392017-04-05 12:30:00 -0400833 // Unsized formats
834 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400835 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400836 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400837 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400838 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400839 AddRGBAFormat(&map, GL_RGB, false, 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);
840 AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400841 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400842 AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
843 AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
844 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
845 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<2, 0>, RequireES<2, 0>, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400846 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400847 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
848 AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, RequireExt<&Extensions::sRGB>, AlwaysSupported);
849
850 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);
851
852 // Unsized integer formats
853 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
854 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
855 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);
856 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
857 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);
858 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
859 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);
860 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
861 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);
862 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
863 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);
864 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
865 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);
866 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
867 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);
868 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
869 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);
870 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
871 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);
872 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
873 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);
874 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
875 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);
876 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
877 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);
878 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);
879
880 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400881 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
882 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
883 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
884 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
885 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
886 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>);
887 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>);
888 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>);
889 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>);
890 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
891 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
892 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 -0400893 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 );
894 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 -0400895 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 -0400896
897 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400898 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
899 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
900 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
901 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
902 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
903 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
904 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
905 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
906 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
907 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 -0400908
909 // Unsized depth stencil formats
910 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
911 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
912 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
913 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
914 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);
915 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);
916 AddDepthStencilFormat(&map, GL_STENCIL, false, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, NeverSupported);
Geoff Lang9bbad182015-09-04 11:07:29 -0400917 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800918
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000919 return map;
920}
921
Geoff Lange4a492b2014-06-19 14:14:41 -0400922static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923{
Geoff Lange4a492b2014-06-19 14:14:41 -0400924 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
925 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000926}
927
Geoff Lange4a492b2014-06-19 14:14:41 -0400928static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400929{
930 FormatSet result;
931
Geoff Langca271392017-04-05 12:30:00 -0400932 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400933 {
Geoff Langca271392017-04-05 12:30:00 -0400934 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400935 {
Geoff Langca271392017-04-05 12:30:00 -0400936 if (type.second.sized)
937 {
938 // TODO(jmadill): Fix this hack.
939 if (internalFormat.first == GL_BGR565_ANGLEX)
940 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400941
Geoff Langca271392017-04-05 12:30:00 -0400942 result.insert(internalFormat.first);
943 }
Geoff Langcec35902014-04-16 10:52:36 -0400944 }
945 }
946
947 return result;
948}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000949
Geoff Lang5d601382014-07-22 15:14:06 -0400950const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000951{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200952 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000953 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200954 case GL_UNSIGNED_BYTE:
955 case GL_BYTE:
956 {
957 static const Type info = GenTypeInfo(1, false);
958 return info;
959 }
960 case GL_UNSIGNED_SHORT:
961 case GL_SHORT:
962 case GL_HALF_FLOAT:
963 case GL_HALF_FLOAT_OES:
964 {
965 static const Type info = GenTypeInfo(2, false);
966 return info;
967 }
968 case GL_UNSIGNED_INT:
969 case GL_INT:
970 case GL_FLOAT:
971 {
972 static const Type info = GenTypeInfo(4, false);
973 return info;
974 }
975 case GL_UNSIGNED_SHORT_5_6_5:
976 case GL_UNSIGNED_SHORT_4_4_4_4:
977 case GL_UNSIGNED_SHORT_5_5_5_1:
978 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
979 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
980 {
981 static const Type info = GenTypeInfo(2, true);
982 return info;
983 }
984 case GL_UNSIGNED_INT_2_10_10_10_REV:
985 case GL_UNSIGNED_INT_24_8:
986 case GL_UNSIGNED_INT_10F_11F_11F_REV:
987 case GL_UNSIGNED_INT_5_9_9_9_REV:
988 {
989 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
990 static const Type info = GenTypeInfo(4, true);
991 return info;
992 }
993 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
994 {
995 static const Type info = GenTypeInfo(8, true);
996 return info;
997 }
998 default:
999 {
1000 static const Type defaultInfo;
1001 return defaultInfo;
1002 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001003 }
1004}
1005
Geoff Langca271392017-04-05 12:30:00 -04001006const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001007{
Geoff Langca271392017-04-05 12:30:00 -04001008 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001009 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001010 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001011
1012 // Sized internal formats only have one type per entry
1013 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001014 {
Geoff Lang5d601382014-07-22 15:14:06 -04001015 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001016 }
Geoff Langca271392017-04-05 12:30:00 -04001017
1018 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1019 if (!internalFormatInfo.sized)
1020 {
1021 return defaultInternalFormat;
1022 }
1023
1024 return internalFormatInfo;
1025}
1026
1027const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1028{
1029 static const InternalFormat defaultInternalFormat;
1030 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1031
1032 auto internalFormatIter = formatMap.find(internalFormat);
1033 if (internalFormatIter == formatMap.end())
1034 {
1035 return defaultInternalFormat;
1036 }
1037
1038 // If the internal format is sized, simply return it without the type check.
1039 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1040 {
1041 return internalFormatIter->second.begin()->second;
1042 }
1043
1044 auto typeIter = internalFormatIter->second.find(type);
1045 if (typeIter == internalFormatIter->second.end())
1046 {
1047 return defaultInternalFormat;
1048 }
1049
1050 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001051}
1052
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001053GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1054{
1055 const auto &typeInfo = GetTypeInfo(formatType);
1056 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1057 return components * typeInfo.bytes;
1058}
1059
Corentin Wallez886de362016-09-27 10:49:35 -04001060ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001061 GLsizei width,
1062 GLint alignment,
1063 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001064{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001065 // Compressed images do not use pack/unpack parameters.
1066 if (compressed)
1067 {
1068 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -04001069 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001070 }
1071
Geoff Lang3f234062016-07-13 15:35:45 -04001072 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001073 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001074
1075 ASSERT(alignment > 0 && isPow2(alignment));
1076 CheckedNumeric<GLuint> checkedAlignment(alignment);
1077 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1078 ANGLE_TRY_CHECKED_MATH(aligned);
1079 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001080}
1081
Corentin Wallez0e487192016-10-03 16:30:38 -04001082ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1083 GLint imageHeight,
1084 GLuint rowPitch) const
1085{
1086 GLuint rows =
1087 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1088 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1089
1090 auto depthPitch = checkedRowPitch * rows;
1091 ANGLE_TRY_CHECKED_MATH(depthPitch);
1092 return depthPitch.ValueOrDie();
1093}
1094
Corentin Wallez886de362016-09-27 10:49:35 -04001095ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001096 GLsizei width,
1097 GLsizei height,
1098 GLint alignment,
1099 GLint rowLength,
1100 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001101{
Jamie Madille2e406c2016-06-02 13:04:10 -04001102 GLuint rowPitch = 0;
1103 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001104 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001105}
1106
Corentin Wallez886de362016-09-27 10:49:35 -04001107ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
1108 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001109{
Jamie Madill513558d2016-06-02 13:04:11 -04001110 CheckedNumeric<GLuint> checkedWidth(size.width);
1111 CheckedNumeric<GLuint> checkedHeight(size.height);
1112 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001113 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1114 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001115
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001116 ASSERT(compressed);
1117 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1118 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1119 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1120 ANGLE_TRY_CHECKED_MATH(bytes);
1121 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001122}
1123
Corentin Wallez886de362016-09-27 10:49:35 -04001124ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -07001125 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -04001126 const PixelStoreStateBase &state,
1127 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001128{
Olli Etuaho989cac32016-06-08 16:18:49 -07001129 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1130 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001131 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1132 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1133 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001134 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1135 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001136 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001137 {
1138 checkedSkipImagesBytes = 0;
1139 }
1140 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1141 checkedSkipPixels * checkedPixelBytes;
1142 ANGLE_TRY_CHECKED_MATH(skipBytes);
1143 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001144}
1145
Corentin Wallez886de362016-09-27 10:49:35 -04001146ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1147 GLenum formatType,
1148 const Extents &size,
1149 const PixelStoreStateBase &state,
1150 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001151{
Corentin Wallez886de362016-09-27 10:49:35 -04001152 GLuint rowPitch = 0;
1153 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001154 rowPitch);
1155
Corentin Wallez0e487192016-10-03 16:30:38 -04001156 GLuint depthPitch = 0;
1157 if (is3D)
1158 {
1159 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1160 }
1161
Corentin Wallez886de362016-09-27 10:49:35 -04001162 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001163 if (compressed)
1164 {
Corentin Wallez886de362016-09-27 10:49:35 -04001165 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001166 }
Corentin Wallez886de362016-09-27 10:49:35 -04001167 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001168 {
Corentin Wallez886de362016-09-27 10:49:35 -04001169 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1170 checkedCopyBytes += size.width * bytes;
1171
1172 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1173 checkedCopyBytes += heightMinusOne * rowPitch;
1174
1175 if (is3D)
1176 {
1177 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1178 checkedCopyBytes += depthMinusOne * depthPitch;
1179 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001180 }
1181
Corentin Wallez886de362016-09-27 10:49:35 -04001182 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1183 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001184
1185 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1186
1187 ANGLE_TRY_CHECKED_MATH(endByte);
1188 return endByte.ValueOrDie();
1189}
1190
Geoff Langca271392017-04-05 12:30:00 -04001191GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001192{
Geoff Langca271392017-04-05 12:30:00 -04001193 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1194 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001195 {
Geoff Langca271392017-04-05 12:30:00 -04001196 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001197 }
Geoff Langca271392017-04-05 12:30:00 -04001198
1199 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001200}
1201
Geoff Lange4a492b2014-06-19 14:14:41 -04001202const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001203{
Geoff Lange4a492b2014-06-19 14:14:41 -04001204 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001205 return formatSet;
1206}
1207
Jamie Madill09e2d932015-07-14 16:40:31 -04001208AttributeType GetAttributeType(GLenum enumValue)
1209{
1210 switch (enumValue)
1211 {
1212 case GL_FLOAT:
1213 return ATTRIBUTE_FLOAT;
1214 case GL_FLOAT_VEC2:
1215 return ATTRIBUTE_VEC2;
1216 case GL_FLOAT_VEC3:
1217 return ATTRIBUTE_VEC3;
1218 case GL_FLOAT_VEC4:
1219 return ATTRIBUTE_VEC4;
1220 case GL_INT:
1221 return ATTRIBUTE_INT;
1222 case GL_INT_VEC2:
1223 return ATTRIBUTE_IVEC2;
1224 case GL_INT_VEC3:
1225 return ATTRIBUTE_IVEC3;
1226 case GL_INT_VEC4:
1227 return ATTRIBUTE_IVEC4;
1228 case GL_UNSIGNED_INT:
1229 return ATTRIBUTE_UINT;
1230 case GL_UNSIGNED_INT_VEC2:
1231 return ATTRIBUTE_UVEC2;
1232 case GL_UNSIGNED_INT_VEC3:
1233 return ATTRIBUTE_UVEC3;
1234 case GL_UNSIGNED_INT_VEC4:
1235 return ATTRIBUTE_UVEC4;
1236 case GL_FLOAT_MAT2:
1237 return ATTRIBUTE_MAT2;
1238 case GL_FLOAT_MAT3:
1239 return ATTRIBUTE_MAT3;
1240 case GL_FLOAT_MAT4:
1241 return ATTRIBUTE_MAT4;
1242 case GL_FLOAT_MAT2x3:
1243 return ATTRIBUTE_MAT2x3;
1244 case GL_FLOAT_MAT2x4:
1245 return ATTRIBUTE_MAT2x4;
1246 case GL_FLOAT_MAT3x2:
1247 return ATTRIBUTE_MAT3x2;
1248 case GL_FLOAT_MAT3x4:
1249 return ATTRIBUTE_MAT3x4;
1250 case GL_FLOAT_MAT4x2:
1251 return ATTRIBUTE_MAT4x2;
1252 case GL_FLOAT_MAT4x3:
1253 return ATTRIBUTE_MAT4x3;
1254 default:
1255 UNREACHABLE();
1256 return ATTRIBUTE_FLOAT;
1257 }
1258}
1259
Jamie Madilld3dfda22015-07-06 08:28:49 -04001260VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1261{
1262 switch (type)
1263 {
1264 case GL_BYTE:
1265 switch (components)
1266 {
1267 case 1:
1268 if (pureInteger)
1269 return VERTEX_FORMAT_SBYTE1_INT;
1270 if (normalized)
1271 return VERTEX_FORMAT_SBYTE1_NORM;
1272 return VERTEX_FORMAT_SBYTE1;
1273 case 2:
1274 if (pureInteger)
1275 return VERTEX_FORMAT_SBYTE2_INT;
1276 if (normalized)
1277 return VERTEX_FORMAT_SBYTE2_NORM;
1278 return VERTEX_FORMAT_SBYTE2;
1279 case 3:
1280 if (pureInteger)
1281 return VERTEX_FORMAT_SBYTE3_INT;
1282 if (normalized)
1283 return VERTEX_FORMAT_SBYTE3_NORM;
1284 return VERTEX_FORMAT_SBYTE3;
1285 case 4:
1286 if (pureInteger)
1287 return VERTEX_FORMAT_SBYTE4_INT;
1288 if (normalized)
1289 return VERTEX_FORMAT_SBYTE4_NORM;
1290 return VERTEX_FORMAT_SBYTE4;
1291 default:
1292 UNREACHABLE();
1293 break;
1294 }
1295 case GL_UNSIGNED_BYTE:
1296 switch (components)
1297 {
1298 case 1:
1299 if (pureInteger)
1300 return VERTEX_FORMAT_UBYTE1_INT;
1301 if (normalized)
1302 return VERTEX_FORMAT_UBYTE1_NORM;
1303 return VERTEX_FORMAT_UBYTE1;
1304 case 2:
1305 if (pureInteger)
1306 return VERTEX_FORMAT_UBYTE2_INT;
1307 if (normalized)
1308 return VERTEX_FORMAT_UBYTE2_NORM;
1309 return VERTEX_FORMAT_UBYTE2;
1310 case 3:
1311 if (pureInteger)
1312 return VERTEX_FORMAT_UBYTE3_INT;
1313 if (normalized)
1314 return VERTEX_FORMAT_UBYTE3_NORM;
1315 return VERTEX_FORMAT_UBYTE3;
1316 case 4:
1317 if (pureInteger)
1318 return VERTEX_FORMAT_UBYTE4_INT;
1319 if (normalized)
1320 return VERTEX_FORMAT_UBYTE4_NORM;
1321 return VERTEX_FORMAT_UBYTE4;
1322 default:
1323 UNREACHABLE();
1324 break;
1325 }
1326 case GL_SHORT:
1327 switch (components)
1328 {
1329 case 1:
1330 if (pureInteger)
1331 return VERTEX_FORMAT_SSHORT1_INT;
1332 if (normalized)
1333 return VERTEX_FORMAT_SSHORT1_NORM;
1334 return VERTEX_FORMAT_SSHORT1;
1335 case 2:
1336 if (pureInteger)
1337 return VERTEX_FORMAT_SSHORT2_INT;
1338 if (normalized)
1339 return VERTEX_FORMAT_SSHORT2_NORM;
1340 return VERTEX_FORMAT_SSHORT2;
1341 case 3:
1342 if (pureInteger)
1343 return VERTEX_FORMAT_SSHORT3_INT;
1344 if (normalized)
1345 return VERTEX_FORMAT_SSHORT3_NORM;
1346 return VERTEX_FORMAT_SSHORT3;
1347 case 4:
1348 if (pureInteger)
1349 return VERTEX_FORMAT_SSHORT4_INT;
1350 if (normalized)
1351 return VERTEX_FORMAT_SSHORT4_NORM;
1352 return VERTEX_FORMAT_SSHORT4;
1353 default:
1354 UNREACHABLE();
1355 break;
1356 }
1357 case GL_UNSIGNED_SHORT:
1358 switch (components)
1359 {
1360 case 1:
1361 if (pureInteger)
1362 return VERTEX_FORMAT_USHORT1_INT;
1363 if (normalized)
1364 return VERTEX_FORMAT_USHORT1_NORM;
1365 return VERTEX_FORMAT_USHORT1;
1366 case 2:
1367 if (pureInteger)
1368 return VERTEX_FORMAT_USHORT2_INT;
1369 if (normalized)
1370 return VERTEX_FORMAT_USHORT2_NORM;
1371 return VERTEX_FORMAT_USHORT2;
1372 case 3:
1373 if (pureInteger)
1374 return VERTEX_FORMAT_USHORT3_INT;
1375 if (normalized)
1376 return VERTEX_FORMAT_USHORT3_NORM;
1377 return VERTEX_FORMAT_USHORT3;
1378 case 4:
1379 if (pureInteger)
1380 return VERTEX_FORMAT_USHORT4_INT;
1381 if (normalized)
1382 return VERTEX_FORMAT_USHORT4_NORM;
1383 return VERTEX_FORMAT_USHORT4;
1384 default:
1385 UNREACHABLE();
1386 break;
1387 }
1388 case GL_INT:
1389 switch (components)
1390 {
1391 case 1:
1392 if (pureInteger)
1393 return VERTEX_FORMAT_SINT1_INT;
1394 if (normalized)
1395 return VERTEX_FORMAT_SINT1_NORM;
1396 return VERTEX_FORMAT_SINT1;
1397 case 2:
1398 if (pureInteger)
1399 return VERTEX_FORMAT_SINT2_INT;
1400 if (normalized)
1401 return VERTEX_FORMAT_SINT2_NORM;
1402 return VERTEX_FORMAT_SINT2;
1403 case 3:
1404 if (pureInteger)
1405 return VERTEX_FORMAT_SINT3_INT;
1406 if (normalized)
1407 return VERTEX_FORMAT_SINT3_NORM;
1408 return VERTEX_FORMAT_SINT3;
1409 case 4:
1410 if (pureInteger)
1411 return VERTEX_FORMAT_SINT4_INT;
1412 if (normalized)
1413 return VERTEX_FORMAT_SINT4_NORM;
1414 return VERTEX_FORMAT_SINT4;
1415 default:
1416 UNREACHABLE();
1417 break;
1418 }
1419 case GL_UNSIGNED_INT:
1420 switch (components)
1421 {
1422 case 1:
1423 if (pureInteger)
1424 return VERTEX_FORMAT_UINT1_INT;
1425 if (normalized)
1426 return VERTEX_FORMAT_UINT1_NORM;
1427 return VERTEX_FORMAT_UINT1;
1428 case 2:
1429 if (pureInteger)
1430 return VERTEX_FORMAT_UINT2_INT;
1431 if (normalized)
1432 return VERTEX_FORMAT_UINT2_NORM;
1433 return VERTEX_FORMAT_UINT2;
1434 case 3:
1435 if (pureInteger)
1436 return VERTEX_FORMAT_UINT3_INT;
1437 if (normalized)
1438 return VERTEX_FORMAT_UINT3_NORM;
1439 return VERTEX_FORMAT_UINT3;
1440 case 4:
1441 if (pureInteger)
1442 return VERTEX_FORMAT_UINT4_INT;
1443 if (normalized)
1444 return VERTEX_FORMAT_UINT4_NORM;
1445 return VERTEX_FORMAT_UINT4;
1446 default:
1447 UNREACHABLE();
1448 break;
1449 }
1450 case GL_FLOAT:
1451 switch (components)
1452 {
1453 case 1:
1454 return VERTEX_FORMAT_FLOAT1;
1455 case 2:
1456 return VERTEX_FORMAT_FLOAT2;
1457 case 3:
1458 return VERTEX_FORMAT_FLOAT3;
1459 case 4:
1460 return VERTEX_FORMAT_FLOAT4;
1461 default:
1462 UNREACHABLE();
1463 break;
1464 }
1465 case GL_HALF_FLOAT:
1466 switch (components)
1467 {
1468 case 1:
1469 return VERTEX_FORMAT_HALF1;
1470 case 2:
1471 return VERTEX_FORMAT_HALF2;
1472 case 3:
1473 return VERTEX_FORMAT_HALF3;
1474 case 4:
1475 return VERTEX_FORMAT_HALF4;
1476 default:
1477 UNREACHABLE();
1478 break;
1479 }
1480 case GL_FIXED:
1481 switch (components)
1482 {
1483 case 1:
1484 return VERTEX_FORMAT_FIXED1;
1485 case 2:
1486 return VERTEX_FORMAT_FIXED2;
1487 case 3:
1488 return VERTEX_FORMAT_FIXED3;
1489 case 4:
1490 return VERTEX_FORMAT_FIXED4;
1491 default:
1492 UNREACHABLE();
1493 break;
1494 }
1495 case GL_INT_2_10_10_10_REV:
1496 if (pureInteger)
1497 return VERTEX_FORMAT_SINT210_INT;
1498 if (normalized)
1499 return VERTEX_FORMAT_SINT210_NORM;
1500 return VERTEX_FORMAT_SINT210;
1501 case GL_UNSIGNED_INT_2_10_10_10_REV:
1502 if (pureInteger)
1503 return VERTEX_FORMAT_UINT210_INT;
1504 if (normalized)
1505 return VERTEX_FORMAT_UINT210_NORM;
1506 return VERTEX_FORMAT_UINT210;
1507 default:
1508 UNREACHABLE();
1509 break;
1510 }
1511 return VERTEX_FORMAT_UBYTE1;
1512}
1513
1514VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1515{
1516 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1517}
1518
1519VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1520{
1521 if (!attrib.enabled)
1522 {
1523 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1524 }
1525 return GetVertexFormatType(attrib);
1526}
1527
1528const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1529{
1530 switch (vertexFormatType)
1531 {
1532 case VERTEX_FORMAT_SBYTE1:
1533 {
1534 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1535 return format;
1536 }
1537 case VERTEX_FORMAT_SBYTE1_NORM:
1538 {
1539 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1540 return format;
1541 }
1542 case VERTEX_FORMAT_SBYTE2:
1543 {
1544 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1545 return format;
1546 }
1547 case VERTEX_FORMAT_SBYTE2_NORM:
1548 {
1549 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1550 return format;
1551 }
1552 case VERTEX_FORMAT_SBYTE3:
1553 {
1554 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1555 return format;
1556 }
1557 case VERTEX_FORMAT_SBYTE3_NORM:
1558 {
1559 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1560 return format;
1561 }
1562 case VERTEX_FORMAT_SBYTE4:
1563 {
1564 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1565 return format;
1566 }
1567 case VERTEX_FORMAT_SBYTE4_NORM:
1568 {
1569 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1570 return format;
1571 }
1572 case VERTEX_FORMAT_UBYTE1:
1573 {
1574 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1575 return format;
1576 }
1577 case VERTEX_FORMAT_UBYTE1_NORM:
1578 {
1579 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1580 return format;
1581 }
1582 case VERTEX_FORMAT_UBYTE2:
1583 {
1584 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1585 return format;
1586 }
1587 case VERTEX_FORMAT_UBYTE2_NORM:
1588 {
1589 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1590 return format;
1591 }
1592 case VERTEX_FORMAT_UBYTE3:
1593 {
1594 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1595 return format;
1596 }
1597 case VERTEX_FORMAT_UBYTE3_NORM:
1598 {
1599 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1600 return format;
1601 }
1602 case VERTEX_FORMAT_UBYTE4:
1603 {
1604 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1605 return format;
1606 }
1607 case VERTEX_FORMAT_UBYTE4_NORM:
1608 {
1609 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1610 return format;
1611 }
1612 case VERTEX_FORMAT_SSHORT1:
1613 {
1614 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1615 return format;
1616 }
1617 case VERTEX_FORMAT_SSHORT1_NORM:
1618 {
1619 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1620 return format;
1621 }
1622 case VERTEX_FORMAT_SSHORT2:
1623 {
1624 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1625 return format;
1626 }
1627 case VERTEX_FORMAT_SSHORT2_NORM:
1628 {
1629 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1630 return format;
1631 }
1632 case VERTEX_FORMAT_SSHORT3:
1633 {
1634 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1635 return format;
1636 }
1637 case VERTEX_FORMAT_SSHORT3_NORM:
1638 {
1639 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1640 return format;
1641 }
1642 case VERTEX_FORMAT_SSHORT4:
1643 {
1644 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1645 return format;
1646 }
1647 case VERTEX_FORMAT_SSHORT4_NORM:
1648 {
1649 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1650 return format;
1651 }
1652 case VERTEX_FORMAT_USHORT1:
1653 {
1654 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1655 return format;
1656 }
1657 case VERTEX_FORMAT_USHORT1_NORM:
1658 {
1659 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1660 return format;
1661 }
1662 case VERTEX_FORMAT_USHORT2:
1663 {
1664 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1665 return format;
1666 }
1667 case VERTEX_FORMAT_USHORT2_NORM:
1668 {
1669 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1670 return format;
1671 }
1672 case VERTEX_FORMAT_USHORT3:
1673 {
1674 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1675 return format;
1676 }
1677 case VERTEX_FORMAT_USHORT3_NORM:
1678 {
1679 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1680 return format;
1681 }
1682 case VERTEX_FORMAT_USHORT4:
1683 {
1684 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1685 return format;
1686 }
1687 case VERTEX_FORMAT_USHORT4_NORM:
1688 {
1689 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1690 return format;
1691 }
1692 case VERTEX_FORMAT_SINT1:
1693 {
1694 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1695 return format;
1696 }
1697 case VERTEX_FORMAT_SINT1_NORM:
1698 {
1699 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1700 return format;
1701 }
1702 case VERTEX_FORMAT_SINT2:
1703 {
1704 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1705 return format;
1706 }
1707 case VERTEX_FORMAT_SINT2_NORM:
1708 {
1709 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1710 return format;
1711 }
1712 case VERTEX_FORMAT_SINT3:
1713 {
1714 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1715 return format;
1716 }
1717 case VERTEX_FORMAT_SINT3_NORM:
1718 {
1719 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1720 return format;
1721 }
1722 case VERTEX_FORMAT_SINT4:
1723 {
1724 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1725 return format;
1726 }
1727 case VERTEX_FORMAT_SINT4_NORM:
1728 {
1729 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1730 return format;
1731 }
1732 case VERTEX_FORMAT_UINT1:
1733 {
1734 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1735 return format;
1736 }
1737 case VERTEX_FORMAT_UINT1_NORM:
1738 {
1739 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1740 return format;
1741 }
1742 case VERTEX_FORMAT_UINT2:
1743 {
1744 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1745 return format;
1746 }
1747 case VERTEX_FORMAT_UINT2_NORM:
1748 {
1749 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1750 return format;
1751 }
1752 case VERTEX_FORMAT_UINT3:
1753 {
1754 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1755 return format;
1756 }
1757 case VERTEX_FORMAT_UINT3_NORM:
1758 {
1759 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1760 return format;
1761 }
1762 case VERTEX_FORMAT_UINT4:
1763 {
1764 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1765 return format;
1766 }
1767 case VERTEX_FORMAT_UINT4_NORM:
1768 {
1769 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1770 return format;
1771 }
1772 case VERTEX_FORMAT_SBYTE1_INT:
1773 {
1774 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1775 return format;
1776 }
1777 case VERTEX_FORMAT_SBYTE2_INT:
1778 {
1779 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1780 return format;
1781 }
1782 case VERTEX_FORMAT_SBYTE3_INT:
1783 {
1784 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1785 return format;
1786 }
1787 case VERTEX_FORMAT_SBYTE4_INT:
1788 {
1789 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1790 return format;
1791 }
1792 case VERTEX_FORMAT_UBYTE1_INT:
1793 {
1794 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1795 return format;
1796 }
1797 case VERTEX_FORMAT_UBYTE2_INT:
1798 {
1799 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1800 return format;
1801 }
1802 case VERTEX_FORMAT_UBYTE3_INT:
1803 {
1804 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1805 return format;
1806 }
1807 case VERTEX_FORMAT_UBYTE4_INT:
1808 {
1809 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1810 return format;
1811 }
1812 case VERTEX_FORMAT_SSHORT1_INT:
1813 {
1814 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1815 return format;
1816 }
1817 case VERTEX_FORMAT_SSHORT2_INT:
1818 {
1819 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1820 return format;
1821 }
1822 case VERTEX_FORMAT_SSHORT3_INT:
1823 {
1824 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1825 return format;
1826 }
1827 case VERTEX_FORMAT_SSHORT4_INT:
1828 {
1829 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1830 return format;
1831 }
1832 case VERTEX_FORMAT_USHORT1_INT:
1833 {
1834 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1835 return format;
1836 }
1837 case VERTEX_FORMAT_USHORT2_INT:
1838 {
1839 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1840 return format;
1841 }
1842 case VERTEX_FORMAT_USHORT3_INT:
1843 {
1844 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1845 return format;
1846 }
1847 case VERTEX_FORMAT_USHORT4_INT:
1848 {
1849 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1850 return format;
1851 }
1852 case VERTEX_FORMAT_SINT1_INT:
1853 {
1854 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1855 return format;
1856 }
1857 case VERTEX_FORMAT_SINT2_INT:
1858 {
1859 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1860 return format;
1861 }
1862 case VERTEX_FORMAT_SINT3_INT:
1863 {
1864 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1865 return format;
1866 }
1867 case VERTEX_FORMAT_SINT4_INT:
1868 {
1869 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1870 return format;
1871 }
1872 case VERTEX_FORMAT_UINT1_INT:
1873 {
1874 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1875 return format;
1876 }
1877 case VERTEX_FORMAT_UINT2_INT:
1878 {
1879 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1880 return format;
1881 }
1882 case VERTEX_FORMAT_UINT3_INT:
1883 {
1884 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1885 return format;
1886 }
1887 case VERTEX_FORMAT_UINT4_INT:
1888 {
1889 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1890 return format;
1891 }
1892 case VERTEX_FORMAT_FIXED1:
1893 {
1894 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1895 return format;
1896 }
1897 case VERTEX_FORMAT_FIXED2:
1898 {
1899 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1900 return format;
1901 }
1902 case VERTEX_FORMAT_FIXED3:
1903 {
1904 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1905 return format;
1906 }
1907 case VERTEX_FORMAT_FIXED4:
1908 {
1909 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1910 return format;
1911 }
1912 case VERTEX_FORMAT_HALF1:
1913 {
1914 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1915 return format;
1916 }
1917 case VERTEX_FORMAT_HALF2:
1918 {
1919 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1920 return format;
1921 }
1922 case VERTEX_FORMAT_HALF3:
1923 {
1924 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1925 return format;
1926 }
1927 case VERTEX_FORMAT_HALF4:
1928 {
1929 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1930 return format;
1931 }
1932 case VERTEX_FORMAT_FLOAT1:
1933 {
1934 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1935 return format;
1936 }
1937 case VERTEX_FORMAT_FLOAT2:
1938 {
1939 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1940 return format;
1941 }
1942 case VERTEX_FORMAT_FLOAT3:
1943 {
1944 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1945 return format;
1946 }
1947 case VERTEX_FORMAT_FLOAT4:
1948 {
1949 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1950 return format;
1951 }
1952 case VERTEX_FORMAT_SINT210:
1953 {
1954 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1955 return format;
1956 }
1957 case VERTEX_FORMAT_UINT210:
1958 {
1959 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1960 return format;
1961 }
1962 case VERTEX_FORMAT_SINT210_NORM:
1963 {
1964 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1965 return format;
1966 }
1967 case VERTEX_FORMAT_UINT210_NORM:
1968 {
1969 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1970 return format;
1971 }
1972 case VERTEX_FORMAT_SINT210_INT:
1973 {
1974 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1975 return format;
1976 }
1977 case VERTEX_FORMAT_UINT210_INT:
1978 {
1979 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1980 return format;
1981 }
1982 default:
1983 {
1984 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1985 return format;
1986 }
1987 }
1988}
1989
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001990size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1991{
1992 switch (vertexFormatType)
1993 {
1994 case VERTEX_FORMAT_SBYTE1:
1995 case VERTEX_FORMAT_SBYTE1_NORM:
1996 case VERTEX_FORMAT_UBYTE1:
1997 case VERTEX_FORMAT_UBYTE1_NORM:
1998 case VERTEX_FORMAT_SBYTE1_INT:
1999 case VERTEX_FORMAT_UBYTE1_INT:
2000 return 1;
2001
2002 case VERTEX_FORMAT_SBYTE2:
2003 case VERTEX_FORMAT_SBYTE2_NORM:
2004 case VERTEX_FORMAT_UBYTE2:
2005 case VERTEX_FORMAT_UBYTE2_NORM:
2006 case VERTEX_FORMAT_SBYTE2_INT:
2007 case VERTEX_FORMAT_UBYTE2_INT:
2008 case VERTEX_FORMAT_SSHORT1:
2009 case VERTEX_FORMAT_SSHORT1_NORM:
2010 case VERTEX_FORMAT_USHORT1:
2011 case VERTEX_FORMAT_USHORT1_NORM:
2012 case VERTEX_FORMAT_SSHORT1_INT:
2013 case VERTEX_FORMAT_USHORT1_INT:
2014 case VERTEX_FORMAT_HALF1:
2015 return 2;
2016
2017 case VERTEX_FORMAT_SBYTE3:
2018 case VERTEX_FORMAT_SBYTE3_NORM:
2019 case VERTEX_FORMAT_UBYTE3:
2020 case VERTEX_FORMAT_UBYTE3_NORM:
2021 case VERTEX_FORMAT_SBYTE3_INT:
2022 case VERTEX_FORMAT_UBYTE3_INT:
2023 return 3;
2024
2025 case VERTEX_FORMAT_SBYTE4:
2026 case VERTEX_FORMAT_SBYTE4_NORM:
2027 case VERTEX_FORMAT_UBYTE4:
2028 case VERTEX_FORMAT_UBYTE4_NORM:
2029 case VERTEX_FORMAT_SBYTE4_INT:
2030 case VERTEX_FORMAT_UBYTE4_INT:
2031 case VERTEX_FORMAT_SSHORT2:
2032 case VERTEX_FORMAT_SSHORT2_NORM:
2033 case VERTEX_FORMAT_USHORT2:
2034 case VERTEX_FORMAT_USHORT2_NORM:
2035 case VERTEX_FORMAT_SSHORT2_INT:
2036 case VERTEX_FORMAT_USHORT2_INT:
2037 case VERTEX_FORMAT_SINT1:
2038 case VERTEX_FORMAT_SINT1_NORM:
2039 case VERTEX_FORMAT_UINT1:
2040 case VERTEX_FORMAT_UINT1_NORM:
2041 case VERTEX_FORMAT_SINT1_INT:
2042 case VERTEX_FORMAT_UINT1_INT:
2043 case VERTEX_FORMAT_HALF2:
2044 case VERTEX_FORMAT_FIXED1:
2045 case VERTEX_FORMAT_FLOAT1:
2046 case VERTEX_FORMAT_SINT210:
2047 case VERTEX_FORMAT_UINT210:
2048 case VERTEX_FORMAT_SINT210_NORM:
2049 case VERTEX_FORMAT_UINT210_NORM:
2050 case VERTEX_FORMAT_SINT210_INT:
2051 case VERTEX_FORMAT_UINT210_INT:
2052 return 4;
2053
2054 case VERTEX_FORMAT_SSHORT3:
2055 case VERTEX_FORMAT_SSHORT3_NORM:
2056 case VERTEX_FORMAT_USHORT3:
2057 case VERTEX_FORMAT_USHORT3_NORM:
2058 case VERTEX_FORMAT_SSHORT3_INT:
2059 case VERTEX_FORMAT_USHORT3_INT:
2060 case VERTEX_FORMAT_HALF3:
2061 return 6;
2062
2063 case VERTEX_FORMAT_SSHORT4:
2064 case VERTEX_FORMAT_SSHORT4_NORM:
2065 case VERTEX_FORMAT_USHORT4:
2066 case VERTEX_FORMAT_USHORT4_NORM:
2067 case VERTEX_FORMAT_SSHORT4_INT:
2068 case VERTEX_FORMAT_USHORT4_INT:
2069 case VERTEX_FORMAT_SINT2:
2070 case VERTEX_FORMAT_SINT2_NORM:
2071 case VERTEX_FORMAT_UINT2:
2072 case VERTEX_FORMAT_UINT2_NORM:
2073 case VERTEX_FORMAT_SINT2_INT:
2074 case VERTEX_FORMAT_UINT2_INT:
2075 case VERTEX_FORMAT_HALF4:
2076 case VERTEX_FORMAT_FIXED2:
2077 case VERTEX_FORMAT_FLOAT2:
2078 return 8;
2079
2080 case VERTEX_FORMAT_SINT3:
2081 case VERTEX_FORMAT_SINT3_NORM:
2082 case VERTEX_FORMAT_UINT3:
2083 case VERTEX_FORMAT_UINT3_NORM:
2084 case VERTEX_FORMAT_SINT3_INT:
2085 case VERTEX_FORMAT_UINT3_INT:
2086 case VERTEX_FORMAT_FIXED3:
2087 case VERTEX_FORMAT_FLOAT3:
2088 return 12;
2089
2090 case VERTEX_FORMAT_SINT4:
2091 case VERTEX_FORMAT_SINT4_NORM:
2092 case VERTEX_FORMAT_UINT4:
2093 case VERTEX_FORMAT_UINT4_NORM:
2094 case VERTEX_FORMAT_SINT4_INT:
2095 case VERTEX_FORMAT_UINT4_INT:
2096 case VERTEX_FORMAT_FIXED4:
2097 case VERTEX_FORMAT_FLOAT4:
2098 return 16;
2099
2100 case VERTEX_FORMAT_INVALID:
2101 default:
2102 UNREACHABLE();
2103 return 0;
2104 }
2105}
2106
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002107bool ValidES3InternalFormat(GLenum internalFormat)
2108{
2109 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2110 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2111}
2112
Jamie Madilld3dfda22015-07-06 08:28:49 -04002113VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
2114 : type(typeIn),
2115 normalized(normalizedIn),
2116 components(componentsIn),
2117 pureInteger(pureIntegerIn)
2118{
2119 // float -> !normalized
2120 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
2121}
2122
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002123}