blob: 00eac8ac9f22cd8f2491925fbf014eb7dda24b85 [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
Geoff Langc71ea662017-09-26 17:06:02 -0400315GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400316{
317 switch (type)
318 {
319 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400320 case GL_HALF_FLOAT_OES:
321 if (version < Version(3, 0))
322 {
323 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
324 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
325 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
326 // as an IMPLEMENTATION_READ_TYPE.
327 return GL_HALF_FLOAT_OES;
328 }
329 else
330 {
331 return GL_HALF_FLOAT;
332 }
Geoff Langf607c602016-09-21 11:46:48 -0400333
334 default:
335 return type;
336 }
337}
338
Olli Etuaho50c562d2017-06-06 14:43:30 +0300339bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
340{
341 // GLES 3.0.5 section 4.4.2.2:
342 // "Implementations are required to support the same internal formats for renderbuffers as the
343 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
344 // formats labelled "texture-only"."
345 if (!sized || compressed)
346 {
347 return false;
348 }
349
350 // Luma formats.
351 if (isLUMA())
352 {
353 return false;
354 }
355
356 // Depth/stencil formats.
357 if (depthBits > 0 || stencilBits > 0)
358 {
359 // GLES 2.0.25 table 4.5.
360 // GLES 3.0.5 section 3.8.3.1.
361 // GLES 3.1 table 8.14.
362
363 // Required formats in all versions.
364 switch (internalFormat)
365 {
366 case GL_DEPTH_COMPONENT16:
367 case GL_STENCIL_INDEX8:
368 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
369 // is in section 4.4.2.2.
370 return true;
371 default:
372 break;
373 }
374 if (version.major < 3)
375 {
376 return false;
377 }
378 // Required formats in GLES 3.0 and up.
379 switch (internalFormat)
380 {
381 case GL_DEPTH_COMPONENT32F:
382 case GL_DEPTH_COMPONENT24:
383 case GL_DEPTH32F_STENCIL8:
384 case GL_DEPTH24_STENCIL8:
385 return true;
386 default:
387 return false;
388 }
389 }
390
391 // RGBA formats.
392 // GLES 2.0.25 table 4.5.
393 // GLES 3.0.5 section 3.8.3.1.
394 // GLES 3.1 table 8.13.
395
396 // Required formats in all versions.
397 switch (internalFormat)
398 {
399 case GL_RGBA4:
400 case GL_RGB5_A1:
401 case GL_RGB565:
402 return true;
403 default:
404 break;
405 }
406 if (version.major < 3)
407 {
408 return false;
409 }
410
411 if (format == GL_BGRA_EXT)
412 {
413 return false;
414 }
415
416 switch (componentType)
417 {
418 case GL_SIGNED_NORMALIZED:
419 case GL_FLOAT:
420 return false;
421 case GL_UNSIGNED_INT:
422 case GL_INT:
423 // Integer RGB formats are not required renderbuffer formats.
424 if (alphaBits == 0 && blueBits != 0)
425 {
426 return false;
427 }
428 // All integer R and RG formats are required.
429 // Integer RGBA formats including RGB10_A2_UI are required.
430 return true;
431 case GL_UNSIGNED_NORMALIZED:
432 if (internalFormat == GL_SRGB8)
433 {
434 return false;
435 }
436 return true;
437 default:
438 UNREACHABLE();
439 return false;
440 }
441}
442
Geoff Langca271392017-04-05 12:30:00 -0400443Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400444{
445}
446
Geoff Langca271392017-04-05 12:30:00 -0400447Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400448{
Jamie Madilla3944d42016-07-22 22:13:26 -0400449}
450
Geoff Langca271392017-04-05 12:30:00 -0400451Format::Format(GLenum internalFormat, GLenum type)
452 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400453{
Jamie Madilla3944d42016-07-22 22:13:26 -0400454}
455
456Format::Format(const Format &other) = default;
457Format &Format::operator=(const Format &other) = default;
458
Jamie Madilla3944d42016-07-22 22:13:26 -0400459bool Format::valid() const
460{
Geoff Langca271392017-04-05 12:30:00 -0400461 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400462}
463
464// static
465bool Format::SameSized(const Format &a, const Format &b)
466{
Geoff Langca271392017-04-05 12:30:00 -0400467 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400468}
469
Kenneth Russell69382852017-07-21 16:38:44 -0400470static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
471{
472 // BlitFramebuffer works if the color channels are identically
473 // sized, even if there is a swizzle (for example, blitting from a
474 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
475 // be expanded and/or autogenerated if that is found necessary.
476 if (internalformat == GL_BGRA8_EXT)
477 return GL_RGBA8;
478 return internalformat;
479}
480
481// static
482bool Format::EquivalentForBlit(const Format &a, const Format &b)
483{
484 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
485 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
486}
487
Jamie Madilla3944d42016-07-22 22:13:26 -0400488// static
489Format Format::Invalid()
490{
Geoff Langca271392017-04-05 12:30:00 -0400491 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400492 return invalid;
493}
494
Yuly Novikovd73f8522017-01-13 17:48:57 -0500495std::ostream &operator<<(std::ostream &os, const Format &fmt)
496{
497 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400498 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500499}
500
Jamie Madilla3944d42016-07-22 22:13:26 -0400501bool InternalFormat::operator==(const InternalFormat &other) const
502{
Geoff Langca271392017-04-05 12:30:00 -0400503 // We assume all internal formats are unique if they have the same internal format and type
504 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400505}
506
507bool InternalFormat::operator!=(const InternalFormat &other) const
508{
Geoff Langca271392017-04-05 12:30:00 -0400509 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400510}
511
Geoff Langca271392017-04-05 12:30:00 -0400512void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400513{
Geoff Langca271392017-04-05 12:30:00 -0400514 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
515 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
516 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400517}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000518
Jamie Madilla3944d42016-07-22 22:13:26 -0400519void AddRGBAFormat(InternalFormatInfoMap *map,
520 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400521 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400522 GLuint red,
523 GLuint green,
524 GLuint blue,
525 GLuint alpha,
526 GLuint shared,
527 GLenum format,
528 GLenum type,
529 GLenum componentType,
530 bool srgb,
531 InternalFormat::SupportCheckFunction textureSupport,
532 InternalFormat::SupportCheckFunction renderSupport,
533 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400534{
535 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400536 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400537 formatInfo.sized = sized;
538 formatInfo.sizedInternalFormat =
539 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400540 formatInfo.redBits = red;
541 formatInfo.greenBits = green;
542 formatInfo.blueBits = blue;
543 formatInfo.alphaBits = alpha;
544 formatInfo.sharedBits = shared;
545 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400546 formatInfo.componentCount =
547 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400548 formatInfo.format = format;
549 formatInfo.type = type;
550 formatInfo.componentType = componentType;
551 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
552 formatInfo.textureSupport = textureSupport;
553 formatInfo.renderSupport = renderSupport;
554 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400555
556 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400557}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000558
Geoff Langca271392017-04-05 12:30:00 -0400559static void AddLUMAFormat(InternalFormatInfoMap *map,
560 GLenum internalFormat,
561 bool sized,
562 GLuint luminance,
563 GLuint alpha,
564 GLenum format,
565 GLenum type,
566 GLenum componentType,
567 InternalFormat::SupportCheckFunction textureSupport,
568 InternalFormat::SupportCheckFunction renderSupport,
569 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400570{
571 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400572 formatInfo.internalFormat = internalFormat;
573 formatInfo.sized = sized;
574 formatInfo.sizedInternalFormat =
575 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400576 formatInfo.luminanceBits = luminance;
577 formatInfo.alphaBits = alpha;
578 formatInfo.pixelBytes = (luminance + alpha) / 8;
579 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
580 formatInfo.format = format;
581 formatInfo.type = type;
582 formatInfo.componentType = componentType;
583 formatInfo.colorEncoding = GL_LINEAR;
584 formatInfo.textureSupport = textureSupport;
585 formatInfo.renderSupport = renderSupport;
586 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400587
588 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400589}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000590
Jamie Madilla3944d42016-07-22 22:13:26 -0400591void AddDepthStencilFormat(InternalFormatInfoMap *map,
592 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400593 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400594 GLuint depthBits,
595 GLuint stencilBits,
596 GLuint unusedBits,
597 GLenum format,
598 GLenum type,
599 GLenum componentType,
600 InternalFormat::SupportCheckFunction textureSupport,
601 InternalFormat::SupportCheckFunction renderSupport,
602 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400603{
604 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400605 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400606 formatInfo.sized = sized;
607 formatInfo.sizedInternalFormat =
608 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400609 formatInfo.depthBits = depthBits;
610 formatInfo.stencilBits = stencilBits;
611 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
612 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
613 formatInfo.format = format;
614 formatInfo.type = type;
615 formatInfo.componentType = componentType;
616 formatInfo.colorEncoding = GL_LINEAR;
617 formatInfo.textureSupport = textureSupport;
618 formatInfo.renderSupport = renderSupport;
619 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400620
621 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400622}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000623
Geoff Langca271392017-04-05 12:30:00 -0400624void AddCompressedFormat(InternalFormatInfoMap *map,
625 GLenum internalFormat,
626 GLuint compressedBlockWidth,
627 GLuint compressedBlockHeight,
628 GLuint compressedBlockSize,
629 GLuint componentCount,
630 GLenum format,
631 GLenum type,
632 bool srgb,
633 InternalFormat::SupportCheckFunction textureSupport,
634 InternalFormat::SupportCheckFunction renderSupport,
635 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400636{
637 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400638 formatInfo.internalFormat = internalFormat;
639 formatInfo.sized = true;
640 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400641 formatInfo.compressedBlockWidth = compressedBlockWidth;
642 formatInfo.compressedBlockHeight = compressedBlockHeight;
643 formatInfo.pixelBytes = compressedBlockSize / 8;
644 formatInfo.componentCount = componentCount;
645 formatInfo.format = format;
646 formatInfo.type = type;
647 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
648 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
649 formatInfo.compressed = true;
650 formatInfo.textureSupport = textureSupport;
651 formatInfo.renderSupport = renderSupport;
652 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400653
654 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400655}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656
Geoff Lange4a492b2014-06-19 14:14:41 -0400657static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000658{
659 InternalFormatInfoMap map;
660
661 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400662 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000663
Jamie Madilla3944d42016-07-22 22:13:26 -0400664 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000665
Geoff Langca271392017-04-05 12:30:00 -0400666 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
667 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);
668 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
669 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);
670 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
671 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);
672 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
673 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);
674 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);
675 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);
676 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);
677 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
678 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);
679 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);
680 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);
681 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);
682 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);
683 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);
684 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);
685 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);
686 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);
687 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);
688 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);
689 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);
690 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);
691 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);
692 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);
693 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);
694 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);
695 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);
696 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
697 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);
698 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
699 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);
700 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
701 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);
702 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);
703 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);
704 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);
705 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);
706 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);
707 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 -0400708
Geoff Langca271392017-04-05 12:30:00 -0400709 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);
710 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);
711 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 +0000712
Jamie Madillec0b5802016-07-04 13:11:59 -0400713 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400714 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 -0400715
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000716 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400717 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
718 // | | | | | | | type | | | | |
719 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>);
720 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>);
721 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>);
722 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>);
723 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
724 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
725 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
726 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 +0000727
728 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400729 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
730 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>);
731 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>);
732 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>);
733 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 );
734 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 );
735 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 -0800736 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737
738 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400739 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
740 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
741 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
742 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
743 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>);
744 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>);
745 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>);
746 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
747 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
748 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 +0000749
750 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400751 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
752 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
753 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
754 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
755 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
756 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
757 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
758 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
759 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
760 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
761 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 +0000762
763 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400764 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
765 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
766 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 +0000767
768 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang86f81162017-10-30 15:10:45 -0400769 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT3>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000770
771 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400772 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 -0400773
774 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400775 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 +0000776
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800777 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400778 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
779 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
780 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
781 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
782 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 -0800783
Geoff Lang60ad73d2015-10-23 10:08:44 -0400784 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400785 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
786 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
787 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);
788 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);
789 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);
790 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);
791 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);
792 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);
793 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);
794 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);
795 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);
796 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);
797 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);
798 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);
799 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 -0400800
Geoff Langca271392017-04-05 12:30:00 -0400801 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);
802 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);
803 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);
804 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);
805 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);
806 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);
807 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);
808 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);
809 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);
810 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);
811 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);
812 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);
813 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);
814 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 -0400815
Corentin Walleze0902642014-11-04 12:32:15 -0800816 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
817 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
818 // - All other stencil formats (all depth-stencil) are either float or normalized
819 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400820 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
821 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 -0800822
823 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400824 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
825 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
826 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
827 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
828 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);
829 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 -0800830
Vincent Lang25ab4512016-05-13 18:13:59 +0200831 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400832 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
833 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);
834 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);
835 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);
836 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);
837 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);
838 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);
839 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);
840 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 +0200841
Geoff Langca271392017-04-05 12:30:00 -0400842 // Unsized formats
843 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400844 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 -0400845 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 -0400846 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 -0400847 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langd84a00b2017-10-27 17:27:26 -0400848 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, AlwaysSupported, AlwaysSupported);
Geoff Langca271392017-04-05 12:30:00 -0400849 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 -0400850 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 -0400851 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);
852 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);
853 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);
854 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 -0400855 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 -0400856 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
857 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);
858
859 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);
860
861 // Unsized integer formats
862 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
863 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
864 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);
865 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
866 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);
867 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
868 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);
869 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
870 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);
871 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
872 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);
873 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
874 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);
875 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
876 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);
877 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
878 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);
879 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
880 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);
881 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
882 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);
883 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
884 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);
885 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
886 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);
887 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);
888
889 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400890 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
891 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
892 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
893 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
894 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
895 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>);
896 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>);
897 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>);
898 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>);
899 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
900 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
901 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 -0400902 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 );
903 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 -0400904 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 -0400905
906 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400907 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
908 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
909 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
910 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
911 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
912 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
913 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
914 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
915 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
916 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 -0400917
918 // Unsized depth stencil formats
919 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
920 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);
921 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);
922 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
923 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);
924 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);
925 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 -0400926 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800927
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000928 return map;
929}
930
Geoff Lange4a492b2014-06-19 14:14:41 -0400931static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000932{
Geoff Lange4a492b2014-06-19 14:14:41 -0400933 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
934 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000935}
936
Geoff Lange4a492b2014-06-19 14:14:41 -0400937static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400938{
939 FormatSet result;
940
Geoff Langca271392017-04-05 12:30:00 -0400941 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400942 {
Geoff Langca271392017-04-05 12:30:00 -0400943 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400944 {
Geoff Langca271392017-04-05 12:30:00 -0400945 if (type.second.sized)
946 {
947 // TODO(jmadill): Fix this hack.
948 if (internalFormat.first == GL_BGR565_ANGLEX)
949 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400950
Geoff Langca271392017-04-05 12:30:00 -0400951 result.insert(internalFormat.first);
952 }
Geoff Langcec35902014-04-16 10:52:36 -0400953 }
954 }
955
956 return result;
957}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000958
Geoff Lang5d601382014-07-22 15:14:06 -0400959const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000960{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200961 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000962 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200963 case GL_UNSIGNED_BYTE:
964 case GL_BYTE:
965 {
966 static const Type info = GenTypeInfo(1, false);
967 return info;
968 }
969 case GL_UNSIGNED_SHORT:
970 case GL_SHORT:
971 case GL_HALF_FLOAT:
972 case GL_HALF_FLOAT_OES:
973 {
974 static const Type info = GenTypeInfo(2, false);
975 return info;
976 }
977 case GL_UNSIGNED_INT:
978 case GL_INT:
979 case GL_FLOAT:
980 {
981 static const Type info = GenTypeInfo(4, false);
982 return info;
983 }
984 case GL_UNSIGNED_SHORT_5_6_5:
985 case GL_UNSIGNED_SHORT_4_4_4_4:
986 case GL_UNSIGNED_SHORT_5_5_5_1:
987 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
988 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
989 {
990 static const Type info = GenTypeInfo(2, true);
991 return info;
992 }
993 case GL_UNSIGNED_INT_2_10_10_10_REV:
994 case GL_UNSIGNED_INT_24_8:
995 case GL_UNSIGNED_INT_10F_11F_11F_REV:
996 case GL_UNSIGNED_INT_5_9_9_9_REV:
997 {
998 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
999 static const Type info = GenTypeInfo(4, true);
1000 return info;
1001 }
1002 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1003 {
1004 static const Type info = GenTypeInfo(8, true);
1005 return info;
1006 }
1007 default:
1008 {
1009 static const Type defaultInfo;
1010 return defaultInfo;
1011 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001012 }
1013}
1014
Geoff Langca271392017-04-05 12:30:00 -04001015const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001016{
Geoff Langca271392017-04-05 12:30:00 -04001017 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001018 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001019 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001020
1021 // Sized internal formats only have one type per entry
1022 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001023 {
Geoff Lang5d601382014-07-22 15:14:06 -04001024 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001025 }
Geoff Langca271392017-04-05 12:30:00 -04001026
1027 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1028 if (!internalFormatInfo.sized)
1029 {
1030 return defaultInternalFormat;
1031 }
1032
1033 return internalFormatInfo;
1034}
1035
1036const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1037{
1038 static const InternalFormat defaultInternalFormat;
1039 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1040
1041 auto internalFormatIter = formatMap.find(internalFormat);
1042 if (internalFormatIter == formatMap.end())
1043 {
1044 return defaultInternalFormat;
1045 }
1046
1047 // If the internal format is sized, simply return it without the type check.
1048 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1049 {
1050 return internalFormatIter->second.begin()->second;
1051 }
1052
1053 auto typeIter = internalFormatIter->second.find(type);
1054 if (typeIter == internalFormatIter->second.end())
1055 {
1056 return defaultInternalFormat;
1057 }
1058
1059 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001060}
1061
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001062GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1063{
1064 const auto &typeInfo = GetTypeInfo(formatType);
1065 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1066 return components * typeInfo.bytes;
1067}
1068
Corentin Wallez886de362016-09-27 10:49:35 -04001069ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001070 GLsizei width,
1071 GLint alignment,
1072 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001073{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001074 // Compressed images do not use pack/unpack parameters.
1075 if (compressed)
1076 {
1077 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -04001078 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001079 }
1080
Geoff Lang3f234062016-07-13 15:35:45 -04001081 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001082 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001083
1084 ASSERT(alignment > 0 && isPow2(alignment));
1085 CheckedNumeric<GLuint> checkedAlignment(alignment);
1086 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1087 ANGLE_TRY_CHECKED_MATH(aligned);
1088 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001089}
1090
Corentin Wallez0e487192016-10-03 16:30:38 -04001091ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1092 GLint imageHeight,
1093 GLuint rowPitch) const
1094{
1095 GLuint rows =
1096 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1097 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1098
1099 auto depthPitch = checkedRowPitch * rows;
1100 ANGLE_TRY_CHECKED_MATH(depthPitch);
1101 return depthPitch.ValueOrDie();
1102}
1103
Corentin Wallez886de362016-09-27 10:49:35 -04001104ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001105 GLsizei width,
1106 GLsizei height,
1107 GLint alignment,
1108 GLint rowLength,
1109 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001110{
Jamie Madille2e406c2016-06-02 13:04:10 -04001111 GLuint rowPitch = 0;
1112 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001113 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001114}
1115
Corentin Wallez886de362016-09-27 10:49:35 -04001116ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
1117 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001118{
Jamie Madill513558d2016-06-02 13:04:11 -04001119 CheckedNumeric<GLuint> checkedWidth(size.width);
1120 CheckedNumeric<GLuint> checkedHeight(size.height);
1121 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001122 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1123 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001124
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001125 ASSERT(compressed);
1126 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1127 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1128 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1129 ANGLE_TRY_CHECKED_MATH(bytes);
1130 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001131}
1132
Corentin Wallez886de362016-09-27 10:49:35 -04001133ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -07001134 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -04001135 const PixelStoreStateBase &state,
1136 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001137{
Olli Etuaho989cac32016-06-08 16:18:49 -07001138 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1139 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001140 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1141 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1142 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001143 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1144 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001145 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001146 {
1147 checkedSkipImagesBytes = 0;
1148 }
1149 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1150 checkedSkipPixels * checkedPixelBytes;
1151 ANGLE_TRY_CHECKED_MATH(skipBytes);
1152 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001153}
1154
Corentin Wallez886de362016-09-27 10:49:35 -04001155ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1156 GLenum formatType,
1157 const Extents &size,
1158 const PixelStoreStateBase &state,
1159 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001160{
Corentin Wallez886de362016-09-27 10:49:35 -04001161 GLuint rowPitch = 0;
1162 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001163 rowPitch);
1164
Corentin Wallez0e487192016-10-03 16:30:38 -04001165 GLuint depthPitch = 0;
1166 if (is3D)
1167 {
1168 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1169 }
1170
Corentin Wallez886de362016-09-27 10:49:35 -04001171 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001172 if (compressed)
1173 {
Corentin Wallez886de362016-09-27 10:49:35 -04001174 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001175 }
Corentin Wallez886de362016-09-27 10:49:35 -04001176 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001177 {
Corentin Wallez886de362016-09-27 10:49:35 -04001178 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1179 checkedCopyBytes += size.width * bytes;
1180
1181 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1182 checkedCopyBytes += heightMinusOne * rowPitch;
1183
1184 if (is3D)
1185 {
1186 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1187 checkedCopyBytes += depthMinusOne * depthPitch;
1188 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001189 }
1190
Corentin Wallez886de362016-09-27 10:49:35 -04001191 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1192 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001193
1194 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1195
1196 ANGLE_TRY_CHECKED_MATH(endByte);
1197 return endByte.ValueOrDie();
1198}
1199
Geoff Langca271392017-04-05 12:30:00 -04001200GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001201{
Geoff Langca271392017-04-05 12:30:00 -04001202 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1203 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001204 {
Geoff Langca271392017-04-05 12:30:00 -04001205 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001206 }
Geoff Langca271392017-04-05 12:30:00 -04001207
1208 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001209}
1210
Geoff Lange4a492b2014-06-19 14:14:41 -04001211const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001212{
Geoff Lange4a492b2014-06-19 14:14:41 -04001213 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001214 return formatSet;
1215}
1216
Jamie Madill09e2d932015-07-14 16:40:31 -04001217AttributeType GetAttributeType(GLenum enumValue)
1218{
1219 switch (enumValue)
1220 {
1221 case GL_FLOAT:
1222 return ATTRIBUTE_FLOAT;
1223 case GL_FLOAT_VEC2:
1224 return ATTRIBUTE_VEC2;
1225 case GL_FLOAT_VEC3:
1226 return ATTRIBUTE_VEC3;
1227 case GL_FLOAT_VEC4:
1228 return ATTRIBUTE_VEC4;
1229 case GL_INT:
1230 return ATTRIBUTE_INT;
1231 case GL_INT_VEC2:
1232 return ATTRIBUTE_IVEC2;
1233 case GL_INT_VEC3:
1234 return ATTRIBUTE_IVEC3;
1235 case GL_INT_VEC4:
1236 return ATTRIBUTE_IVEC4;
1237 case GL_UNSIGNED_INT:
1238 return ATTRIBUTE_UINT;
1239 case GL_UNSIGNED_INT_VEC2:
1240 return ATTRIBUTE_UVEC2;
1241 case GL_UNSIGNED_INT_VEC3:
1242 return ATTRIBUTE_UVEC3;
1243 case GL_UNSIGNED_INT_VEC4:
1244 return ATTRIBUTE_UVEC4;
1245 case GL_FLOAT_MAT2:
1246 return ATTRIBUTE_MAT2;
1247 case GL_FLOAT_MAT3:
1248 return ATTRIBUTE_MAT3;
1249 case GL_FLOAT_MAT4:
1250 return ATTRIBUTE_MAT4;
1251 case GL_FLOAT_MAT2x3:
1252 return ATTRIBUTE_MAT2x3;
1253 case GL_FLOAT_MAT2x4:
1254 return ATTRIBUTE_MAT2x4;
1255 case GL_FLOAT_MAT3x2:
1256 return ATTRIBUTE_MAT3x2;
1257 case GL_FLOAT_MAT3x4:
1258 return ATTRIBUTE_MAT3x4;
1259 case GL_FLOAT_MAT4x2:
1260 return ATTRIBUTE_MAT4x2;
1261 case GL_FLOAT_MAT4x3:
1262 return ATTRIBUTE_MAT4x3;
1263 default:
1264 UNREACHABLE();
1265 return ATTRIBUTE_FLOAT;
1266 }
1267}
1268
Jamie Madilld3dfda22015-07-06 08:28:49 -04001269VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1270{
1271 switch (type)
1272 {
1273 case GL_BYTE:
1274 switch (components)
1275 {
1276 case 1:
1277 if (pureInteger)
1278 return VERTEX_FORMAT_SBYTE1_INT;
1279 if (normalized)
1280 return VERTEX_FORMAT_SBYTE1_NORM;
1281 return VERTEX_FORMAT_SBYTE1;
1282 case 2:
1283 if (pureInteger)
1284 return VERTEX_FORMAT_SBYTE2_INT;
1285 if (normalized)
1286 return VERTEX_FORMAT_SBYTE2_NORM;
1287 return VERTEX_FORMAT_SBYTE2;
1288 case 3:
1289 if (pureInteger)
1290 return VERTEX_FORMAT_SBYTE3_INT;
1291 if (normalized)
1292 return VERTEX_FORMAT_SBYTE3_NORM;
1293 return VERTEX_FORMAT_SBYTE3;
1294 case 4:
1295 if (pureInteger)
1296 return VERTEX_FORMAT_SBYTE4_INT;
1297 if (normalized)
1298 return VERTEX_FORMAT_SBYTE4_NORM;
1299 return VERTEX_FORMAT_SBYTE4;
1300 default:
1301 UNREACHABLE();
1302 break;
1303 }
1304 case GL_UNSIGNED_BYTE:
1305 switch (components)
1306 {
1307 case 1:
1308 if (pureInteger)
1309 return VERTEX_FORMAT_UBYTE1_INT;
1310 if (normalized)
1311 return VERTEX_FORMAT_UBYTE1_NORM;
1312 return VERTEX_FORMAT_UBYTE1;
1313 case 2:
1314 if (pureInteger)
1315 return VERTEX_FORMAT_UBYTE2_INT;
1316 if (normalized)
1317 return VERTEX_FORMAT_UBYTE2_NORM;
1318 return VERTEX_FORMAT_UBYTE2;
1319 case 3:
1320 if (pureInteger)
1321 return VERTEX_FORMAT_UBYTE3_INT;
1322 if (normalized)
1323 return VERTEX_FORMAT_UBYTE3_NORM;
1324 return VERTEX_FORMAT_UBYTE3;
1325 case 4:
1326 if (pureInteger)
1327 return VERTEX_FORMAT_UBYTE4_INT;
1328 if (normalized)
1329 return VERTEX_FORMAT_UBYTE4_NORM;
1330 return VERTEX_FORMAT_UBYTE4;
1331 default:
1332 UNREACHABLE();
1333 break;
1334 }
1335 case GL_SHORT:
1336 switch (components)
1337 {
1338 case 1:
1339 if (pureInteger)
1340 return VERTEX_FORMAT_SSHORT1_INT;
1341 if (normalized)
1342 return VERTEX_FORMAT_SSHORT1_NORM;
1343 return VERTEX_FORMAT_SSHORT1;
1344 case 2:
1345 if (pureInteger)
1346 return VERTEX_FORMAT_SSHORT2_INT;
1347 if (normalized)
1348 return VERTEX_FORMAT_SSHORT2_NORM;
1349 return VERTEX_FORMAT_SSHORT2;
1350 case 3:
1351 if (pureInteger)
1352 return VERTEX_FORMAT_SSHORT3_INT;
1353 if (normalized)
1354 return VERTEX_FORMAT_SSHORT3_NORM;
1355 return VERTEX_FORMAT_SSHORT3;
1356 case 4:
1357 if (pureInteger)
1358 return VERTEX_FORMAT_SSHORT4_INT;
1359 if (normalized)
1360 return VERTEX_FORMAT_SSHORT4_NORM;
1361 return VERTEX_FORMAT_SSHORT4;
1362 default:
1363 UNREACHABLE();
1364 break;
1365 }
1366 case GL_UNSIGNED_SHORT:
1367 switch (components)
1368 {
1369 case 1:
1370 if (pureInteger)
1371 return VERTEX_FORMAT_USHORT1_INT;
1372 if (normalized)
1373 return VERTEX_FORMAT_USHORT1_NORM;
1374 return VERTEX_FORMAT_USHORT1;
1375 case 2:
1376 if (pureInteger)
1377 return VERTEX_FORMAT_USHORT2_INT;
1378 if (normalized)
1379 return VERTEX_FORMAT_USHORT2_NORM;
1380 return VERTEX_FORMAT_USHORT2;
1381 case 3:
1382 if (pureInteger)
1383 return VERTEX_FORMAT_USHORT3_INT;
1384 if (normalized)
1385 return VERTEX_FORMAT_USHORT3_NORM;
1386 return VERTEX_FORMAT_USHORT3;
1387 case 4:
1388 if (pureInteger)
1389 return VERTEX_FORMAT_USHORT4_INT;
1390 if (normalized)
1391 return VERTEX_FORMAT_USHORT4_NORM;
1392 return VERTEX_FORMAT_USHORT4;
1393 default:
1394 UNREACHABLE();
1395 break;
1396 }
1397 case GL_INT:
1398 switch (components)
1399 {
1400 case 1:
1401 if (pureInteger)
1402 return VERTEX_FORMAT_SINT1_INT;
1403 if (normalized)
1404 return VERTEX_FORMAT_SINT1_NORM;
1405 return VERTEX_FORMAT_SINT1;
1406 case 2:
1407 if (pureInteger)
1408 return VERTEX_FORMAT_SINT2_INT;
1409 if (normalized)
1410 return VERTEX_FORMAT_SINT2_NORM;
1411 return VERTEX_FORMAT_SINT2;
1412 case 3:
1413 if (pureInteger)
1414 return VERTEX_FORMAT_SINT3_INT;
1415 if (normalized)
1416 return VERTEX_FORMAT_SINT3_NORM;
1417 return VERTEX_FORMAT_SINT3;
1418 case 4:
1419 if (pureInteger)
1420 return VERTEX_FORMAT_SINT4_INT;
1421 if (normalized)
1422 return VERTEX_FORMAT_SINT4_NORM;
1423 return VERTEX_FORMAT_SINT4;
1424 default:
1425 UNREACHABLE();
1426 break;
1427 }
1428 case GL_UNSIGNED_INT:
1429 switch (components)
1430 {
1431 case 1:
1432 if (pureInteger)
1433 return VERTEX_FORMAT_UINT1_INT;
1434 if (normalized)
1435 return VERTEX_FORMAT_UINT1_NORM;
1436 return VERTEX_FORMAT_UINT1;
1437 case 2:
1438 if (pureInteger)
1439 return VERTEX_FORMAT_UINT2_INT;
1440 if (normalized)
1441 return VERTEX_FORMAT_UINT2_NORM;
1442 return VERTEX_FORMAT_UINT2;
1443 case 3:
1444 if (pureInteger)
1445 return VERTEX_FORMAT_UINT3_INT;
1446 if (normalized)
1447 return VERTEX_FORMAT_UINT3_NORM;
1448 return VERTEX_FORMAT_UINT3;
1449 case 4:
1450 if (pureInteger)
1451 return VERTEX_FORMAT_UINT4_INT;
1452 if (normalized)
1453 return VERTEX_FORMAT_UINT4_NORM;
1454 return VERTEX_FORMAT_UINT4;
1455 default:
1456 UNREACHABLE();
1457 break;
1458 }
1459 case GL_FLOAT:
1460 switch (components)
1461 {
1462 case 1:
1463 return VERTEX_FORMAT_FLOAT1;
1464 case 2:
1465 return VERTEX_FORMAT_FLOAT2;
1466 case 3:
1467 return VERTEX_FORMAT_FLOAT3;
1468 case 4:
1469 return VERTEX_FORMAT_FLOAT4;
1470 default:
1471 UNREACHABLE();
1472 break;
1473 }
1474 case GL_HALF_FLOAT:
1475 switch (components)
1476 {
1477 case 1:
1478 return VERTEX_FORMAT_HALF1;
1479 case 2:
1480 return VERTEX_FORMAT_HALF2;
1481 case 3:
1482 return VERTEX_FORMAT_HALF3;
1483 case 4:
1484 return VERTEX_FORMAT_HALF4;
1485 default:
1486 UNREACHABLE();
1487 break;
1488 }
1489 case GL_FIXED:
1490 switch (components)
1491 {
1492 case 1:
1493 return VERTEX_FORMAT_FIXED1;
1494 case 2:
1495 return VERTEX_FORMAT_FIXED2;
1496 case 3:
1497 return VERTEX_FORMAT_FIXED3;
1498 case 4:
1499 return VERTEX_FORMAT_FIXED4;
1500 default:
1501 UNREACHABLE();
1502 break;
1503 }
1504 case GL_INT_2_10_10_10_REV:
1505 if (pureInteger)
1506 return VERTEX_FORMAT_SINT210_INT;
1507 if (normalized)
1508 return VERTEX_FORMAT_SINT210_NORM;
1509 return VERTEX_FORMAT_SINT210;
1510 case GL_UNSIGNED_INT_2_10_10_10_REV:
1511 if (pureInteger)
1512 return VERTEX_FORMAT_UINT210_INT;
1513 if (normalized)
1514 return VERTEX_FORMAT_UINT210_NORM;
1515 return VERTEX_FORMAT_UINT210;
1516 default:
1517 UNREACHABLE();
1518 break;
1519 }
1520 return VERTEX_FORMAT_UBYTE1;
1521}
1522
1523VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1524{
1525 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1526}
1527
1528VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1529{
1530 if (!attrib.enabled)
1531 {
1532 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1533 }
1534 return GetVertexFormatType(attrib);
1535}
1536
1537const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1538{
1539 switch (vertexFormatType)
1540 {
1541 case VERTEX_FORMAT_SBYTE1:
1542 {
1543 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1544 return format;
1545 }
1546 case VERTEX_FORMAT_SBYTE1_NORM:
1547 {
1548 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1549 return format;
1550 }
1551 case VERTEX_FORMAT_SBYTE2:
1552 {
1553 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1554 return format;
1555 }
1556 case VERTEX_FORMAT_SBYTE2_NORM:
1557 {
1558 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1559 return format;
1560 }
1561 case VERTEX_FORMAT_SBYTE3:
1562 {
1563 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1564 return format;
1565 }
1566 case VERTEX_FORMAT_SBYTE3_NORM:
1567 {
1568 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1569 return format;
1570 }
1571 case VERTEX_FORMAT_SBYTE4:
1572 {
1573 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1574 return format;
1575 }
1576 case VERTEX_FORMAT_SBYTE4_NORM:
1577 {
1578 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1579 return format;
1580 }
1581 case VERTEX_FORMAT_UBYTE1:
1582 {
1583 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1584 return format;
1585 }
1586 case VERTEX_FORMAT_UBYTE1_NORM:
1587 {
1588 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1589 return format;
1590 }
1591 case VERTEX_FORMAT_UBYTE2:
1592 {
1593 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1594 return format;
1595 }
1596 case VERTEX_FORMAT_UBYTE2_NORM:
1597 {
1598 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1599 return format;
1600 }
1601 case VERTEX_FORMAT_UBYTE3:
1602 {
1603 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1604 return format;
1605 }
1606 case VERTEX_FORMAT_UBYTE3_NORM:
1607 {
1608 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1609 return format;
1610 }
1611 case VERTEX_FORMAT_UBYTE4:
1612 {
1613 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1614 return format;
1615 }
1616 case VERTEX_FORMAT_UBYTE4_NORM:
1617 {
1618 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1619 return format;
1620 }
1621 case VERTEX_FORMAT_SSHORT1:
1622 {
1623 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1624 return format;
1625 }
1626 case VERTEX_FORMAT_SSHORT1_NORM:
1627 {
1628 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1629 return format;
1630 }
1631 case VERTEX_FORMAT_SSHORT2:
1632 {
1633 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1634 return format;
1635 }
1636 case VERTEX_FORMAT_SSHORT2_NORM:
1637 {
1638 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1639 return format;
1640 }
1641 case VERTEX_FORMAT_SSHORT3:
1642 {
1643 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1644 return format;
1645 }
1646 case VERTEX_FORMAT_SSHORT3_NORM:
1647 {
1648 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1649 return format;
1650 }
1651 case VERTEX_FORMAT_SSHORT4:
1652 {
1653 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1654 return format;
1655 }
1656 case VERTEX_FORMAT_SSHORT4_NORM:
1657 {
1658 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1659 return format;
1660 }
1661 case VERTEX_FORMAT_USHORT1:
1662 {
1663 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1664 return format;
1665 }
1666 case VERTEX_FORMAT_USHORT1_NORM:
1667 {
1668 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1669 return format;
1670 }
1671 case VERTEX_FORMAT_USHORT2:
1672 {
1673 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1674 return format;
1675 }
1676 case VERTEX_FORMAT_USHORT2_NORM:
1677 {
1678 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1679 return format;
1680 }
1681 case VERTEX_FORMAT_USHORT3:
1682 {
1683 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1684 return format;
1685 }
1686 case VERTEX_FORMAT_USHORT3_NORM:
1687 {
1688 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1689 return format;
1690 }
1691 case VERTEX_FORMAT_USHORT4:
1692 {
1693 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1694 return format;
1695 }
1696 case VERTEX_FORMAT_USHORT4_NORM:
1697 {
1698 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1699 return format;
1700 }
1701 case VERTEX_FORMAT_SINT1:
1702 {
1703 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1704 return format;
1705 }
1706 case VERTEX_FORMAT_SINT1_NORM:
1707 {
1708 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1709 return format;
1710 }
1711 case VERTEX_FORMAT_SINT2:
1712 {
1713 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1714 return format;
1715 }
1716 case VERTEX_FORMAT_SINT2_NORM:
1717 {
1718 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1719 return format;
1720 }
1721 case VERTEX_FORMAT_SINT3:
1722 {
1723 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1724 return format;
1725 }
1726 case VERTEX_FORMAT_SINT3_NORM:
1727 {
1728 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1729 return format;
1730 }
1731 case VERTEX_FORMAT_SINT4:
1732 {
1733 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1734 return format;
1735 }
1736 case VERTEX_FORMAT_SINT4_NORM:
1737 {
1738 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1739 return format;
1740 }
1741 case VERTEX_FORMAT_UINT1:
1742 {
1743 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1744 return format;
1745 }
1746 case VERTEX_FORMAT_UINT1_NORM:
1747 {
1748 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1749 return format;
1750 }
1751 case VERTEX_FORMAT_UINT2:
1752 {
1753 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1754 return format;
1755 }
1756 case VERTEX_FORMAT_UINT2_NORM:
1757 {
1758 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1759 return format;
1760 }
1761 case VERTEX_FORMAT_UINT3:
1762 {
1763 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1764 return format;
1765 }
1766 case VERTEX_FORMAT_UINT3_NORM:
1767 {
1768 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1769 return format;
1770 }
1771 case VERTEX_FORMAT_UINT4:
1772 {
1773 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1774 return format;
1775 }
1776 case VERTEX_FORMAT_UINT4_NORM:
1777 {
1778 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1779 return format;
1780 }
1781 case VERTEX_FORMAT_SBYTE1_INT:
1782 {
1783 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1784 return format;
1785 }
1786 case VERTEX_FORMAT_SBYTE2_INT:
1787 {
1788 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1789 return format;
1790 }
1791 case VERTEX_FORMAT_SBYTE3_INT:
1792 {
1793 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1794 return format;
1795 }
1796 case VERTEX_FORMAT_SBYTE4_INT:
1797 {
1798 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1799 return format;
1800 }
1801 case VERTEX_FORMAT_UBYTE1_INT:
1802 {
1803 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1804 return format;
1805 }
1806 case VERTEX_FORMAT_UBYTE2_INT:
1807 {
1808 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1809 return format;
1810 }
1811 case VERTEX_FORMAT_UBYTE3_INT:
1812 {
1813 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1814 return format;
1815 }
1816 case VERTEX_FORMAT_UBYTE4_INT:
1817 {
1818 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1819 return format;
1820 }
1821 case VERTEX_FORMAT_SSHORT1_INT:
1822 {
1823 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1824 return format;
1825 }
1826 case VERTEX_FORMAT_SSHORT2_INT:
1827 {
1828 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1829 return format;
1830 }
1831 case VERTEX_FORMAT_SSHORT3_INT:
1832 {
1833 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1834 return format;
1835 }
1836 case VERTEX_FORMAT_SSHORT4_INT:
1837 {
1838 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1839 return format;
1840 }
1841 case VERTEX_FORMAT_USHORT1_INT:
1842 {
1843 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1844 return format;
1845 }
1846 case VERTEX_FORMAT_USHORT2_INT:
1847 {
1848 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1849 return format;
1850 }
1851 case VERTEX_FORMAT_USHORT3_INT:
1852 {
1853 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1854 return format;
1855 }
1856 case VERTEX_FORMAT_USHORT4_INT:
1857 {
1858 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1859 return format;
1860 }
1861 case VERTEX_FORMAT_SINT1_INT:
1862 {
1863 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1864 return format;
1865 }
1866 case VERTEX_FORMAT_SINT2_INT:
1867 {
1868 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1869 return format;
1870 }
1871 case VERTEX_FORMAT_SINT3_INT:
1872 {
1873 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1874 return format;
1875 }
1876 case VERTEX_FORMAT_SINT4_INT:
1877 {
1878 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1879 return format;
1880 }
1881 case VERTEX_FORMAT_UINT1_INT:
1882 {
1883 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1884 return format;
1885 }
1886 case VERTEX_FORMAT_UINT2_INT:
1887 {
1888 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1889 return format;
1890 }
1891 case VERTEX_FORMAT_UINT3_INT:
1892 {
1893 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1894 return format;
1895 }
1896 case VERTEX_FORMAT_UINT4_INT:
1897 {
1898 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1899 return format;
1900 }
1901 case VERTEX_FORMAT_FIXED1:
1902 {
1903 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1904 return format;
1905 }
1906 case VERTEX_FORMAT_FIXED2:
1907 {
1908 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1909 return format;
1910 }
1911 case VERTEX_FORMAT_FIXED3:
1912 {
1913 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1914 return format;
1915 }
1916 case VERTEX_FORMAT_FIXED4:
1917 {
1918 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1919 return format;
1920 }
1921 case VERTEX_FORMAT_HALF1:
1922 {
1923 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1924 return format;
1925 }
1926 case VERTEX_FORMAT_HALF2:
1927 {
1928 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1929 return format;
1930 }
1931 case VERTEX_FORMAT_HALF3:
1932 {
1933 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1934 return format;
1935 }
1936 case VERTEX_FORMAT_HALF4:
1937 {
1938 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1939 return format;
1940 }
1941 case VERTEX_FORMAT_FLOAT1:
1942 {
1943 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1944 return format;
1945 }
1946 case VERTEX_FORMAT_FLOAT2:
1947 {
1948 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1949 return format;
1950 }
1951 case VERTEX_FORMAT_FLOAT3:
1952 {
1953 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1954 return format;
1955 }
1956 case VERTEX_FORMAT_FLOAT4:
1957 {
1958 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1959 return format;
1960 }
1961 case VERTEX_FORMAT_SINT210:
1962 {
1963 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1964 return format;
1965 }
1966 case VERTEX_FORMAT_UINT210:
1967 {
1968 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1969 return format;
1970 }
1971 case VERTEX_FORMAT_SINT210_NORM:
1972 {
1973 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1974 return format;
1975 }
1976 case VERTEX_FORMAT_UINT210_NORM:
1977 {
1978 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1979 return format;
1980 }
1981 case VERTEX_FORMAT_SINT210_INT:
1982 {
1983 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1984 return format;
1985 }
1986 case VERTEX_FORMAT_UINT210_INT:
1987 {
1988 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1989 return format;
1990 }
1991 default:
1992 {
1993 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1994 return format;
1995 }
1996 }
1997}
1998
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001999size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2000{
2001 switch (vertexFormatType)
2002 {
2003 case VERTEX_FORMAT_SBYTE1:
2004 case VERTEX_FORMAT_SBYTE1_NORM:
2005 case VERTEX_FORMAT_UBYTE1:
2006 case VERTEX_FORMAT_UBYTE1_NORM:
2007 case VERTEX_FORMAT_SBYTE1_INT:
2008 case VERTEX_FORMAT_UBYTE1_INT:
2009 return 1;
2010
2011 case VERTEX_FORMAT_SBYTE2:
2012 case VERTEX_FORMAT_SBYTE2_NORM:
2013 case VERTEX_FORMAT_UBYTE2:
2014 case VERTEX_FORMAT_UBYTE2_NORM:
2015 case VERTEX_FORMAT_SBYTE2_INT:
2016 case VERTEX_FORMAT_UBYTE2_INT:
2017 case VERTEX_FORMAT_SSHORT1:
2018 case VERTEX_FORMAT_SSHORT1_NORM:
2019 case VERTEX_FORMAT_USHORT1:
2020 case VERTEX_FORMAT_USHORT1_NORM:
2021 case VERTEX_FORMAT_SSHORT1_INT:
2022 case VERTEX_FORMAT_USHORT1_INT:
2023 case VERTEX_FORMAT_HALF1:
2024 return 2;
2025
2026 case VERTEX_FORMAT_SBYTE3:
2027 case VERTEX_FORMAT_SBYTE3_NORM:
2028 case VERTEX_FORMAT_UBYTE3:
2029 case VERTEX_FORMAT_UBYTE3_NORM:
2030 case VERTEX_FORMAT_SBYTE3_INT:
2031 case VERTEX_FORMAT_UBYTE3_INT:
2032 return 3;
2033
2034 case VERTEX_FORMAT_SBYTE4:
2035 case VERTEX_FORMAT_SBYTE4_NORM:
2036 case VERTEX_FORMAT_UBYTE4:
2037 case VERTEX_FORMAT_UBYTE4_NORM:
2038 case VERTEX_FORMAT_SBYTE4_INT:
2039 case VERTEX_FORMAT_UBYTE4_INT:
2040 case VERTEX_FORMAT_SSHORT2:
2041 case VERTEX_FORMAT_SSHORT2_NORM:
2042 case VERTEX_FORMAT_USHORT2:
2043 case VERTEX_FORMAT_USHORT2_NORM:
2044 case VERTEX_FORMAT_SSHORT2_INT:
2045 case VERTEX_FORMAT_USHORT2_INT:
2046 case VERTEX_FORMAT_SINT1:
2047 case VERTEX_FORMAT_SINT1_NORM:
2048 case VERTEX_FORMAT_UINT1:
2049 case VERTEX_FORMAT_UINT1_NORM:
2050 case VERTEX_FORMAT_SINT1_INT:
2051 case VERTEX_FORMAT_UINT1_INT:
2052 case VERTEX_FORMAT_HALF2:
2053 case VERTEX_FORMAT_FIXED1:
2054 case VERTEX_FORMAT_FLOAT1:
2055 case VERTEX_FORMAT_SINT210:
2056 case VERTEX_FORMAT_UINT210:
2057 case VERTEX_FORMAT_SINT210_NORM:
2058 case VERTEX_FORMAT_UINT210_NORM:
2059 case VERTEX_FORMAT_SINT210_INT:
2060 case VERTEX_FORMAT_UINT210_INT:
2061 return 4;
2062
2063 case VERTEX_FORMAT_SSHORT3:
2064 case VERTEX_FORMAT_SSHORT3_NORM:
2065 case VERTEX_FORMAT_USHORT3:
2066 case VERTEX_FORMAT_USHORT3_NORM:
2067 case VERTEX_FORMAT_SSHORT3_INT:
2068 case VERTEX_FORMAT_USHORT3_INT:
2069 case VERTEX_FORMAT_HALF3:
2070 return 6;
2071
2072 case VERTEX_FORMAT_SSHORT4:
2073 case VERTEX_FORMAT_SSHORT4_NORM:
2074 case VERTEX_FORMAT_USHORT4:
2075 case VERTEX_FORMAT_USHORT4_NORM:
2076 case VERTEX_FORMAT_SSHORT4_INT:
2077 case VERTEX_FORMAT_USHORT4_INT:
2078 case VERTEX_FORMAT_SINT2:
2079 case VERTEX_FORMAT_SINT2_NORM:
2080 case VERTEX_FORMAT_UINT2:
2081 case VERTEX_FORMAT_UINT2_NORM:
2082 case VERTEX_FORMAT_SINT2_INT:
2083 case VERTEX_FORMAT_UINT2_INT:
2084 case VERTEX_FORMAT_HALF4:
2085 case VERTEX_FORMAT_FIXED2:
2086 case VERTEX_FORMAT_FLOAT2:
2087 return 8;
2088
2089 case VERTEX_FORMAT_SINT3:
2090 case VERTEX_FORMAT_SINT3_NORM:
2091 case VERTEX_FORMAT_UINT3:
2092 case VERTEX_FORMAT_UINT3_NORM:
2093 case VERTEX_FORMAT_SINT3_INT:
2094 case VERTEX_FORMAT_UINT3_INT:
2095 case VERTEX_FORMAT_FIXED3:
2096 case VERTEX_FORMAT_FLOAT3:
2097 return 12;
2098
2099 case VERTEX_FORMAT_SINT4:
2100 case VERTEX_FORMAT_SINT4_NORM:
2101 case VERTEX_FORMAT_UINT4:
2102 case VERTEX_FORMAT_UINT4_NORM:
2103 case VERTEX_FORMAT_SINT4_INT:
2104 case VERTEX_FORMAT_UINT4_INT:
2105 case VERTEX_FORMAT_FIXED4:
2106 case VERTEX_FORMAT_FLOAT4:
2107 return 16;
2108
2109 case VERTEX_FORMAT_INVALID:
2110 default:
2111 UNREACHABLE();
2112 return 0;
2113 }
2114}
2115
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002116bool ValidES3InternalFormat(GLenum internalFormat)
2117{
2118 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2119 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2120}
2121
Jamie Madilld3dfda22015-07-06 08:28:49 -04002122VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
2123 : type(typeIn),
2124 normalized(normalizedIn),
2125 components(componentsIn),
2126 pureInteger(pureIntegerIn)
2127{
2128 // float -> !normalized
2129 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
2130}
2131
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002132}