blob: 374ea8657f7b1a631953fd8fa80c253bdc845261 [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 Madillacf2f3a2017-11-21 19:22:44 -0500304InternalFormat::InternalFormat(const InternalFormat &other) = default;
305
Jamie Madilla3944d42016-07-22 22:13:26 -0400306bool InternalFormat::isLUMA() const
307{
308 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
309 (luminanceBits + alphaBits) > 0);
310}
311
Geoff Langf607c602016-09-21 11:46:48 -0400312GLenum InternalFormat::getReadPixelsFormat() const
313{
314 return format;
315}
316
Geoff Langc71ea662017-09-26 17:06:02 -0400317GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400318{
319 switch (type)
320 {
321 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400322 case GL_HALF_FLOAT_OES:
323 if (version < Version(3, 0))
324 {
325 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
326 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
327 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
328 // as an IMPLEMENTATION_READ_TYPE.
329 return GL_HALF_FLOAT_OES;
330 }
331 else
332 {
333 return GL_HALF_FLOAT;
334 }
Geoff Langf607c602016-09-21 11:46:48 -0400335
336 default:
337 return type;
338 }
339}
340
Olli Etuaho50c562d2017-06-06 14:43:30 +0300341bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
342{
343 // GLES 3.0.5 section 4.4.2.2:
344 // "Implementations are required to support the same internal formats for renderbuffers as the
345 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
346 // formats labelled "texture-only"."
347 if (!sized || compressed)
348 {
349 return false;
350 }
351
352 // Luma formats.
353 if (isLUMA())
354 {
355 return false;
356 }
357
358 // Depth/stencil formats.
359 if (depthBits > 0 || stencilBits > 0)
360 {
361 // GLES 2.0.25 table 4.5.
362 // GLES 3.0.5 section 3.8.3.1.
363 // GLES 3.1 table 8.14.
364
365 // Required formats in all versions.
366 switch (internalFormat)
367 {
368 case GL_DEPTH_COMPONENT16:
369 case GL_STENCIL_INDEX8:
370 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
371 // is in section 4.4.2.2.
372 return true;
373 default:
374 break;
375 }
376 if (version.major < 3)
377 {
378 return false;
379 }
380 // Required formats in GLES 3.0 and up.
381 switch (internalFormat)
382 {
383 case GL_DEPTH_COMPONENT32F:
384 case GL_DEPTH_COMPONENT24:
385 case GL_DEPTH32F_STENCIL8:
386 case GL_DEPTH24_STENCIL8:
387 return true;
388 default:
389 return false;
390 }
391 }
392
393 // RGBA formats.
394 // GLES 2.0.25 table 4.5.
395 // GLES 3.0.5 section 3.8.3.1.
396 // GLES 3.1 table 8.13.
397
398 // Required formats in all versions.
399 switch (internalFormat)
400 {
401 case GL_RGBA4:
402 case GL_RGB5_A1:
403 case GL_RGB565:
404 return true;
405 default:
406 break;
407 }
408 if (version.major < 3)
409 {
410 return false;
411 }
412
413 if (format == GL_BGRA_EXT)
414 {
415 return false;
416 }
417
418 switch (componentType)
419 {
420 case GL_SIGNED_NORMALIZED:
421 case GL_FLOAT:
422 return false;
423 case GL_UNSIGNED_INT:
424 case GL_INT:
425 // Integer RGB formats are not required renderbuffer formats.
426 if (alphaBits == 0 && blueBits != 0)
427 {
428 return false;
429 }
430 // All integer R and RG formats are required.
431 // Integer RGBA formats including RGB10_A2_UI are required.
432 return true;
433 case GL_UNSIGNED_NORMALIZED:
434 if (internalFormat == GL_SRGB8)
435 {
436 return false;
437 }
438 return true;
439 default:
440 UNREACHABLE();
441 return false;
442 }
443}
444
Geoff Langca271392017-04-05 12:30:00 -0400445Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400446{
447}
448
Geoff Langca271392017-04-05 12:30:00 -0400449Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400450{
Jamie Madilla3944d42016-07-22 22:13:26 -0400451}
452
Geoff Langca271392017-04-05 12:30:00 -0400453Format::Format(GLenum internalFormat, GLenum type)
454 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400455{
Jamie Madilla3944d42016-07-22 22:13:26 -0400456}
457
458Format::Format(const Format &other) = default;
459Format &Format::operator=(const Format &other) = default;
460
Jamie Madilla3944d42016-07-22 22:13:26 -0400461bool Format::valid() const
462{
Geoff Langca271392017-04-05 12:30:00 -0400463 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400464}
465
466// static
467bool Format::SameSized(const Format &a, const Format &b)
468{
Geoff Langca271392017-04-05 12:30:00 -0400469 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400470}
471
Kenneth Russell69382852017-07-21 16:38:44 -0400472static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
473{
474 // BlitFramebuffer works if the color channels are identically
475 // sized, even if there is a swizzle (for example, blitting from a
476 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
477 // be expanded and/or autogenerated if that is found necessary.
478 if (internalformat == GL_BGRA8_EXT)
479 return GL_RGBA8;
480 return internalformat;
481}
482
483// static
484bool Format::EquivalentForBlit(const Format &a, const Format &b)
485{
486 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
487 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
488}
489
Jamie Madilla3944d42016-07-22 22:13:26 -0400490// static
491Format Format::Invalid()
492{
Geoff Langca271392017-04-05 12:30:00 -0400493 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400494 return invalid;
495}
496
Yuly Novikovd73f8522017-01-13 17:48:57 -0500497std::ostream &operator<<(std::ostream &os, const Format &fmt)
498{
499 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400500 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500501}
502
Jamie Madilla3944d42016-07-22 22:13:26 -0400503bool InternalFormat::operator==(const InternalFormat &other) const
504{
Geoff Langca271392017-04-05 12:30:00 -0400505 // We assume all internal formats are unique if they have the same internal format and type
506 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400507}
508
509bool InternalFormat::operator!=(const InternalFormat &other) const
510{
Geoff Langca271392017-04-05 12:30:00 -0400511 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400512}
513
Geoff Langca271392017-04-05 12:30:00 -0400514void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400515{
Geoff Langca271392017-04-05 12:30:00 -0400516 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
517 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
518 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400519}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000520
Jamie Madilla3944d42016-07-22 22:13:26 -0400521void AddRGBAFormat(InternalFormatInfoMap *map,
522 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400523 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400524 GLuint red,
525 GLuint green,
526 GLuint blue,
527 GLuint alpha,
528 GLuint shared,
529 GLenum format,
530 GLenum type,
531 GLenum componentType,
532 bool srgb,
533 InternalFormat::SupportCheckFunction textureSupport,
534 InternalFormat::SupportCheckFunction renderSupport,
535 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400536{
537 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400538 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400539 formatInfo.sized = sized;
540 formatInfo.sizedInternalFormat =
541 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400542 formatInfo.redBits = red;
543 formatInfo.greenBits = green;
544 formatInfo.blueBits = blue;
545 formatInfo.alphaBits = alpha;
546 formatInfo.sharedBits = shared;
547 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400548 formatInfo.componentCount =
549 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400550 formatInfo.format = format;
551 formatInfo.type = type;
552 formatInfo.componentType = componentType;
553 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
554 formatInfo.textureSupport = textureSupport;
555 formatInfo.renderSupport = renderSupport;
556 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400557
558 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400559}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000560
Geoff Langca271392017-04-05 12:30:00 -0400561static void AddLUMAFormat(InternalFormatInfoMap *map,
562 GLenum internalFormat,
563 bool sized,
564 GLuint luminance,
565 GLuint alpha,
566 GLenum format,
567 GLenum type,
568 GLenum componentType,
569 InternalFormat::SupportCheckFunction textureSupport,
570 InternalFormat::SupportCheckFunction renderSupport,
571 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400572{
573 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400574 formatInfo.internalFormat = internalFormat;
575 formatInfo.sized = sized;
576 formatInfo.sizedInternalFormat =
577 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400578 formatInfo.luminanceBits = luminance;
579 formatInfo.alphaBits = alpha;
580 formatInfo.pixelBytes = (luminance + alpha) / 8;
581 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
582 formatInfo.format = format;
583 formatInfo.type = type;
584 formatInfo.componentType = componentType;
585 formatInfo.colorEncoding = GL_LINEAR;
586 formatInfo.textureSupport = textureSupport;
587 formatInfo.renderSupport = renderSupport;
588 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400589
590 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400591}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000592
Jamie Madilla3944d42016-07-22 22:13:26 -0400593void AddDepthStencilFormat(InternalFormatInfoMap *map,
594 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400595 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400596 GLuint depthBits,
597 GLuint stencilBits,
598 GLuint unusedBits,
599 GLenum format,
600 GLenum type,
601 GLenum componentType,
602 InternalFormat::SupportCheckFunction textureSupport,
603 InternalFormat::SupportCheckFunction renderSupport,
604 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400605{
606 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400607 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400608 formatInfo.sized = sized;
609 formatInfo.sizedInternalFormat =
610 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400611 formatInfo.depthBits = depthBits;
612 formatInfo.stencilBits = stencilBits;
613 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
614 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
615 formatInfo.format = format;
616 formatInfo.type = type;
617 formatInfo.componentType = componentType;
618 formatInfo.colorEncoding = GL_LINEAR;
619 formatInfo.textureSupport = textureSupport;
620 formatInfo.renderSupport = renderSupport;
621 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400622
623 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400624}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000625
Geoff Langca271392017-04-05 12:30:00 -0400626void AddCompressedFormat(InternalFormatInfoMap *map,
627 GLenum internalFormat,
628 GLuint compressedBlockWidth,
629 GLuint compressedBlockHeight,
630 GLuint compressedBlockSize,
631 GLuint componentCount,
632 GLenum format,
633 GLenum type,
634 bool srgb,
635 InternalFormat::SupportCheckFunction textureSupport,
636 InternalFormat::SupportCheckFunction renderSupport,
637 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400638{
639 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400640 formatInfo.internalFormat = internalFormat;
641 formatInfo.sized = true;
642 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400643 formatInfo.compressedBlockWidth = compressedBlockWidth;
644 formatInfo.compressedBlockHeight = compressedBlockHeight;
645 formatInfo.pixelBytes = compressedBlockSize / 8;
646 formatInfo.componentCount = componentCount;
647 formatInfo.format = format;
648 formatInfo.type = type;
649 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
650 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
651 formatInfo.compressed = true;
652 formatInfo.textureSupport = textureSupport;
653 formatInfo.renderSupport = renderSupport;
654 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400655
656 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400657}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000658
Geoff Lange4a492b2014-06-19 14:14:41 -0400659static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000660{
661 InternalFormatInfoMap map;
662
663 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400664 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000665
Jamie Madilla3944d42016-07-22 22:13:26 -0400666 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000667
Geoff Langca271392017-04-05 12:30:00 -0400668 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
669 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);
670 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
671 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);
672 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
673 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);
674 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
675 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);
676 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);
677 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);
678 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);
679 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
680 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);
681 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);
682 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);
683 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);
684 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);
685 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);
686 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);
687 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);
688 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);
689 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);
690 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);
691 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);
692 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);
693 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);
694 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);
695 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);
696 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);
697 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);
698 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
699 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);
700 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
701 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);
702 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
703 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);
704 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);
705 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);
706 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);
707 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);
708 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);
709 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 -0400710
Geoff Langca271392017-04-05 12:30:00 -0400711 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);
712 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);
713 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 +0000714
Olli Etuahoceffd202018-01-08 16:39:45 +0200715 // Special format that is used for D3D textures that are used within ANGLE via the
716 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
717 // this format, but textures in this format can be created from D3D textures, and filtering them
718 // and rendering to them is allowed.
719 AddRGBAFormat(&map, GL_BGRA8_SRGB_ANGLEX, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported);
720
Jamie Madillec0b5802016-07-04 13:11:59 -0400721 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400722 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 -0400723
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000724 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400725 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
726 // | | | | | | | type | | | | |
727 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>);
728 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>);
729 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>);
730 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>);
731 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
732 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
733 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
734 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 +0000735
736 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400737 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
738 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>);
739 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>);
740 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>);
741 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 );
742 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 );
743 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 -0800744 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000745
746 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400747 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
748 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
749 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
750 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
751 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>);
752 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>);
753 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>);
754 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
755 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
756 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 +0000757
758 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400759 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
760 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
761 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
762 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
763 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
764 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
765 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
766 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
767 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
768 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
769 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 +0000770
771 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400772 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
773 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
774 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 +0000775
776 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang86f81162017-10-30 15:10:45 -0400777 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 +0000778
779 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400780 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 -0400781
782 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400783 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 +0000784
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800785 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400786 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
787 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
788 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
789 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
790 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 -0800791
Geoff Lang60ad73d2015-10-23 10:08:44 -0400792 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400793 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
794 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);
795 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);
796 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);
797 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);
798 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);
799 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);
800 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);
801 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);
802 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);
803 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);
804 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);
805 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);
806 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);
807 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 -0400808
Geoff Langca271392017-04-05 12:30:00 -0400809 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);
810 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);
811 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);
812 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);
813 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);
814 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);
815 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);
816 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);
817 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);
818 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);
819 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);
820 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);
821 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);
822 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 -0400823
Corentin Walleze0902642014-11-04 12:32:15 -0800824 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
825 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
826 // - All other stencil formats (all depth-stencil) are either float or normalized
827 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400828 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
829 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 -0800830
831 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400832 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
833 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
834 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
835 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
836 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);
837 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 -0800838
Vincent Lang25ab4512016-05-13 18:13:59 +0200839 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400840 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
841 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);
842 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);
843 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);
844 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);
845 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);
846 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);
847 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);
848 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 +0200849
Geoff Langca271392017-04-05 12:30:00 -0400850 // Unsized formats
851 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400852 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 -0400853 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 -0400854 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 -0400855 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 -0400856 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 -0400857 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 -0400858 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 -0400859 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);
860 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);
861 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);
862 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 -0400863 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 -0400864 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
865 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);
866
867 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);
868
869 // Unsized integer formats
870 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
871 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
872 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);
873 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
874 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);
875 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
876 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);
877 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
878 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);
879 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
880 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);
881 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
882 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);
883 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
884 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);
885 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
886 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);
887 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
888 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);
889 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
890 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);
891 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
892 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);
893 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
894 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);
895 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);
896
897 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400898 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
899 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
900 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
901 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
902 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
903 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>);
904 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>);
905 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>);
906 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>);
907 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
908 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
909 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 -0400910 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 );
911 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 -0400912 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 -0400913
914 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400915 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
916 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
917 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
918 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
919 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
920 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
921 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
922 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
923 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
924 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 -0400925
926 // Unsized depth stencil formats
927 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
928 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);
929 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);
930 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
931 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);
932 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);
933 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 -0400934 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800935
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000936 return map;
937}
938
Geoff Lange4a492b2014-06-19 14:14:41 -0400939static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000940{
Geoff Lange4a492b2014-06-19 14:14:41 -0400941 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
942 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000943}
944
Geoff Lange4a492b2014-06-19 14:14:41 -0400945static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400946{
947 FormatSet result;
948
Geoff Langca271392017-04-05 12:30:00 -0400949 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400950 {
Geoff Langca271392017-04-05 12:30:00 -0400951 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400952 {
Geoff Langca271392017-04-05 12:30:00 -0400953 if (type.second.sized)
954 {
955 // TODO(jmadill): Fix this hack.
956 if (internalFormat.first == GL_BGR565_ANGLEX)
957 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400958
Geoff Langca271392017-04-05 12:30:00 -0400959 result.insert(internalFormat.first);
960 }
Geoff Langcec35902014-04-16 10:52:36 -0400961 }
962 }
963
964 return result;
965}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000966
Geoff Lang5d601382014-07-22 15:14:06 -0400967const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000968{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200969 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000970 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200971 case GL_UNSIGNED_BYTE:
972 case GL_BYTE:
973 {
974 static const Type info = GenTypeInfo(1, false);
975 return info;
976 }
977 case GL_UNSIGNED_SHORT:
978 case GL_SHORT:
979 case GL_HALF_FLOAT:
980 case GL_HALF_FLOAT_OES:
981 {
982 static const Type info = GenTypeInfo(2, false);
983 return info;
984 }
985 case GL_UNSIGNED_INT:
986 case GL_INT:
987 case GL_FLOAT:
988 {
989 static const Type info = GenTypeInfo(4, false);
990 return info;
991 }
992 case GL_UNSIGNED_SHORT_5_6_5:
993 case GL_UNSIGNED_SHORT_4_4_4_4:
994 case GL_UNSIGNED_SHORT_5_5_5_1:
995 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
996 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
997 {
998 static const Type info = GenTypeInfo(2, true);
999 return info;
1000 }
1001 case GL_UNSIGNED_INT_2_10_10_10_REV:
1002 case GL_UNSIGNED_INT_24_8:
1003 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1004 case GL_UNSIGNED_INT_5_9_9_9_REV:
1005 {
1006 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1007 static const Type info = GenTypeInfo(4, true);
1008 return info;
1009 }
1010 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1011 {
1012 static const Type info = GenTypeInfo(8, true);
1013 return info;
1014 }
1015 default:
1016 {
1017 static const Type defaultInfo;
1018 return defaultInfo;
1019 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001020 }
1021}
1022
Geoff Langca271392017-04-05 12:30:00 -04001023const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001024{
Geoff Langca271392017-04-05 12:30:00 -04001025 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001026 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001027 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001028
1029 // Sized internal formats only have one type per entry
1030 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001031 {
Geoff Lang5d601382014-07-22 15:14:06 -04001032 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001033 }
Geoff Langca271392017-04-05 12:30:00 -04001034
1035 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1036 if (!internalFormatInfo.sized)
1037 {
1038 return defaultInternalFormat;
1039 }
1040
1041 return internalFormatInfo;
1042}
1043
1044const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1045{
1046 static const InternalFormat defaultInternalFormat;
1047 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1048
1049 auto internalFormatIter = formatMap.find(internalFormat);
1050 if (internalFormatIter == formatMap.end())
1051 {
1052 return defaultInternalFormat;
1053 }
1054
1055 // If the internal format is sized, simply return it without the type check.
1056 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1057 {
1058 return internalFormatIter->second.begin()->second;
1059 }
1060
1061 auto typeIter = internalFormatIter->second.find(type);
1062 if (typeIter == internalFormatIter->second.end())
1063 {
1064 return defaultInternalFormat;
1065 }
1066
1067 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001068}
1069
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001070GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1071{
1072 const auto &typeInfo = GetTypeInfo(formatType);
1073 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1074 return components * typeInfo.bytes;
1075}
1076
Corentin Wallez886de362016-09-27 10:49:35 -04001077ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001078 GLsizei width,
1079 GLint alignment,
1080 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001081{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001082 // Compressed images do not use pack/unpack parameters.
1083 if (compressed)
1084 {
1085 ASSERT(rowLength == 0);
Jeff Gilbert48590352017-11-07 16:03:38 -08001086 return computeCompressedImageSize(Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001087 }
1088
Geoff Lang3f234062016-07-13 15:35:45 -04001089 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001090 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001091
1092 ASSERT(alignment > 0 && isPow2(alignment));
1093 CheckedNumeric<GLuint> checkedAlignment(alignment);
1094 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1095 ANGLE_TRY_CHECKED_MATH(aligned);
1096 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001097}
1098
Corentin Wallez0e487192016-10-03 16:30:38 -04001099ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1100 GLint imageHeight,
1101 GLuint rowPitch) const
1102{
1103 GLuint rows =
1104 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1105 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1106
1107 auto depthPitch = checkedRowPitch * rows;
1108 ANGLE_TRY_CHECKED_MATH(depthPitch);
1109 return depthPitch.ValueOrDie();
1110}
1111
Corentin Wallez886de362016-09-27 10:49:35 -04001112ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001113 GLsizei width,
1114 GLsizei height,
1115 GLint alignment,
1116 GLint rowLength,
1117 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001118{
Jamie Madille2e406c2016-06-02 13:04:10 -04001119 GLuint rowPitch = 0;
1120 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001121 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001122}
1123
Jeff Gilbert48590352017-11-07 16:03:38 -08001124ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001125{
Jamie Madill513558d2016-06-02 13:04:11 -04001126 CheckedNumeric<GLuint> checkedWidth(size.width);
1127 CheckedNumeric<GLuint> checkedHeight(size.height);
1128 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001129 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1130 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001131
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001132 ASSERT(compressed);
1133 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1134 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1135 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1136 ANGLE_TRY_CHECKED_MATH(bytes);
1137 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001138}
1139
Corentin Wallez886de362016-09-27 10:49:35 -04001140ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -07001141 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -04001142 const PixelStoreStateBase &state,
1143 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001144{
Olli Etuaho989cac32016-06-08 16:18:49 -07001145 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1146 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001147 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1148 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1149 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001150 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1151 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001152 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001153 {
1154 checkedSkipImagesBytes = 0;
1155 }
1156 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1157 checkedSkipPixels * checkedPixelBytes;
1158 ANGLE_TRY_CHECKED_MATH(skipBytes);
1159 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001160}
1161
Corentin Wallez886de362016-09-27 10:49:35 -04001162ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1163 GLenum formatType,
1164 const Extents &size,
1165 const PixelStoreStateBase &state,
1166 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001167{
Corentin Wallez886de362016-09-27 10:49:35 -04001168 GLuint rowPitch = 0;
1169 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001170 rowPitch);
1171
Corentin Wallez0e487192016-10-03 16:30:38 -04001172 GLuint depthPitch = 0;
1173 if (is3D)
1174 {
1175 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1176 }
1177
Corentin Wallez886de362016-09-27 10:49:35 -04001178 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001179 if (compressed)
1180 {
Jeff Gilbert48590352017-11-07 16:03:38 -08001181 ANGLE_TRY_RESULT(computeCompressedImageSize(size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001182 }
Corentin Wallez886de362016-09-27 10:49:35 -04001183 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001184 {
Corentin Wallez886de362016-09-27 10:49:35 -04001185 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1186 checkedCopyBytes += size.width * bytes;
1187
1188 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1189 checkedCopyBytes += heightMinusOne * rowPitch;
1190
1191 if (is3D)
1192 {
1193 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1194 checkedCopyBytes += depthMinusOne * depthPitch;
1195 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001196 }
1197
Corentin Wallez886de362016-09-27 10:49:35 -04001198 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1199 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001200
1201 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1202
1203 ANGLE_TRY_CHECKED_MATH(endByte);
1204 return endByte.ValueOrDie();
1205}
1206
Geoff Langca271392017-04-05 12:30:00 -04001207GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001208{
Geoff Langca271392017-04-05 12:30:00 -04001209 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1210 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001211 {
Geoff Langca271392017-04-05 12:30:00 -04001212 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001213 }
Geoff Langca271392017-04-05 12:30:00 -04001214
1215 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001216}
1217
Geoff Lange4a492b2014-06-19 14:14:41 -04001218const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001219{
Geoff Lange4a492b2014-06-19 14:14:41 -04001220 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001221 return formatSet;
1222}
1223
Jamie Madill09e2d932015-07-14 16:40:31 -04001224AttributeType GetAttributeType(GLenum enumValue)
1225{
1226 switch (enumValue)
1227 {
1228 case GL_FLOAT:
1229 return ATTRIBUTE_FLOAT;
1230 case GL_FLOAT_VEC2:
1231 return ATTRIBUTE_VEC2;
1232 case GL_FLOAT_VEC3:
1233 return ATTRIBUTE_VEC3;
1234 case GL_FLOAT_VEC4:
1235 return ATTRIBUTE_VEC4;
1236 case GL_INT:
1237 return ATTRIBUTE_INT;
1238 case GL_INT_VEC2:
1239 return ATTRIBUTE_IVEC2;
1240 case GL_INT_VEC3:
1241 return ATTRIBUTE_IVEC3;
1242 case GL_INT_VEC4:
1243 return ATTRIBUTE_IVEC4;
1244 case GL_UNSIGNED_INT:
1245 return ATTRIBUTE_UINT;
1246 case GL_UNSIGNED_INT_VEC2:
1247 return ATTRIBUTE_UVEC2;
1248 case GL_UNSIGNED_INT_VEC3:
1249 return ATTRIBUTE_UVEC3;
1250 case GL_UNSIGNED_INT_VEC4:
1251 return ATTRIBUTE_UVEC4;
1252 case GL_FLOAT_MAT2:
1253 return ATTRIBUTE_MAT2;
1254 case GL_FLOAT_MAT3:
1255 return ATTRIBUTE_MAT3;
1256 case GL_FLOAT_MAT4:
1257 return ATTRIBUTE_MAT4;
1258 case GL_FLOAT_MAT2x3:
1259 return ATTRIBUTE_MAT2x3;
1260 case GL_FLOAT_MAT2x4:
1261 return ATTRIBUTE_MAT2x4;
1262 case GL_FLOAT_MAT3x2:
1263 return ATTRIBUTE_MAT3x2;
1264 case GL_FLOAT_MAT3x4:
1265 return ATTRIBUTE_MAT3x4;
1266 case GL_FLOAT_MAT4x2:
1267 return ATTRIBUTE_MAT4x2;
1268 case GL_FLOAT_MAT4x3:
1269 return ATTRIBUTE_MAT4x3;
1270 default:
1271 UNREACHABLE();
1272 return ATTRIBUTE_FLOAT;
1273 }
1274}
1275
Jamie Madilld3dfda22015-07-06 08:28:49 -04001276VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1277{
1278 switch (type)
1279 {
1280 case GL_BYTE:
1281 switch (components)
1282 {
1283 case 1:
1284 if (pureInteger)
1285 return VERTEX_FORMAT_SBYTE1_INT;
1286 if (normalized)
1287 return VERTEX_FORMAT_SBYTE1_NORM;
1288 return VERTEX_FORMAT_SBYTE1;
1289 case 2:
1290 if (pureInteger)
1291 return VERTEX_FORMAT_SBYTE2_INT;
1292 if (normalized)
1293 return VERTEX_FORMAT_SBYTE2_NORM;
1294 return VERTEX_FORMAT_SBYTE2;
1295 case 3:
1296 if (pureInteger)
1297 return VERTEX_FORMAT_SBYTE3_INT;
1298 if (normalized)
1299 return VERTEX_FORMAT_SBYTE3_NORM;
1300 return VERTEX_FORMAT_SBYTE3;
1301 case 4:
1302 if (pureInteger)
1303 return VERTEX_FORMAT_SBYTE4_INT;
1304 if (normalized)
1305 return VERTEX_FORMAT_SBYTE4_NORM;
1306 return VERTEX_FORMAT_SBYTE4;
1307 default:
1308 UNREACHABLE();
1309 break;
1310 }
1311 case GL_UNSIGNED_BYTE:
1312 switch (components)
1313 {
1314 case 1:
1315 if (pureInteger)
1316 return VERTEX_FORMAT_UBYTE1_INT;
1317 if (normalized)
1318 return VERTEX_FORMAT_UBYTE1_NORM;
1319 return VERTEX_FORMAT_UBYTE1;
1320 case 2:
1321 if (pureInteger)
1322 return VERTEX_FORMAT_UBYTE2_INT;
1323 if (normalized)
1324 return VERTEX_FORMAT_UBYTE2_NORM;
1325 return VERTEX_FORMAT_UBYTE2;
1326 case 3:
1327 if (pureInteger)
1328 return VERTEX_FORMAT_UBYTE3_INT;
1329 if (normalized)
1330 return VERTEX_FORMAT_UBYTE3_NORM;
1331 return VERTEX_FORMAT_UBYTE3;
1332 case 4:
1333 if (pureInteger)
1334 return VERTEX_FORMAT_UBYTE4_INT;
1335 if (normalized)
1336 return VERTEX_FORMAT_UBYTE4_NORM;
1337 return VERTEX_FORMAT_UBYTE4;
1338 default:
1339 UNREACHABLE();
1340 break;
1341 }
1342 case GL_SHORT:
1343 switch (components)
1344 {
1345 case 1:
1346 if (pureInteger)
1347 return VERTEX_FORMAT_SSHORT1_INT;
1348 if (normalized)
1349 return VERTEX_FORMAT_SSHORT1_NORM;
1350 return VERTEX_FORMAT_SSHORT1;
1351 case 2:
1352 if (pureInteger)
1353 return VERTEX_FORMAT_SSHORT2_INT;
1354 if (normalized)
1355 return VERTEX_FORMAT_SSHORT2_NORM;
1356 return VERTEX_FORMAT_SSHORT2;
1357 case 3:
1358 if (pureInteger)
1359 return VERTEX_FORMAT_SSHORT3_INT;
1360 if (normalized)
1361 return VERTEX_FORMAT_SSHORT3_NORM;
1362 return VERTEX_FORMAT_SSHORT3;
1363 case 4:
1364 if (pureInteger)
1365 return VERTEX_FORMAT_SSHORT4_INT;
1366 if (normalized)
1367 return VERTEX_FORMAT_SSHORT4_NORM;
1368 return VERTEX_FORMAT_SSHORT4;
1369 default:
1370 UNREACHABLE();
1371 break;
1372 }
1373 case GL_UNSIGNED_SHORT:
1374 switch (components)
1375 {
1376 case 1:
1377 if (pureInteger)
1378 return VERTEX_FORMAT_USHORT1_INT;
1379 if (normalized)
1380 return VERTEX_FORMAT_USHORT1_NORM;
1381 return VERTEX_FORMAT_USHORT1;
1382 case 2:
1383 if (pureInteger)
1384 return VERTEX_FORMAT_USHORT2_INT;
1385 if (normalized)
1386 return VERTEX_FORMAT_USHORT2_NORM;
1387 return VERTEX_FORMAT_USHORT2;
1388 case 3:
1389 if (pureInteger)
1390 return VERTEX_FORMAT_USHORT3_INT;
1391 if (normalized)
1392 return VERTEX_FORMAT_USHORT3_NORM;
1393 return VERTEX_FORMAT_USHORT3;
1394 case 4:
1395 if (pureInteger)
1396 return VERTEX_FORMAT_USHORT4_INT;
1397 if (normalized)
1398 return VERTEX_FORMAT_USHORT4_NORM;
1399 return VERTEX_FORMAT_USHORT4;
1400 default:
1401 UNREACHABLE();
1402 break;
1403 }
1404 case GL_INT:
1405 switch (components)
1406 {
1407 case 1:
1408 if (pureInteger)
1409 return VERTEX_FORMAT_SINT1_INT;
1410 if (normalized)
1411 return VERTEX_FORMAT_SINT1_NORM;
1412 return VERTEX_FORMAT_SINT1;
1413 case 2:
1414 if (pureInteger)
1415 return VERTEX_FORMAT_SINT2_INT;
1416 if (normalized)
1417 return VERTEX_FORMAT_SINT2_NORM;
1418 return VERTEX_FORMAT_SINT2;
1419 case 3:
1420 if (pureInteger)
1421 return VERTEX_FORMAT_SINT3_INT;
1422 if (normalized)
1423 return VERTEX_FORMAT_SINT3_NORM;
1424 return VERTEX_FORMAT_SINT3;
1425 case 4:
1426 if (pureInteger)
1427 return VERTEX_FORMAT_SINT4_INT;
1428 if (normalized)
1429 return VERTEX_FORMAT_SINT4_NORM;
1430 return VERTEX_FORMAT_SINT4;
1431 default:
1432 UNREACHABLE();
1433 break;
1434 }
1435 case GL_UNSIGNED_INT:
1436 switch (components)
1437 {
1438 case 1:
1439 if (pureInteger)
1440 return VERTEX_FORMAT_UINT1_INT;
1441 if (normalized)
1442 return VERTEX_FORMAT_UINT1_NORM;
1443 return VERTEX_FORMAT_UINT1;
1444 case 2:
1445 if (pureInteger)
1446 return VERTEX_FORMAT_UINT2_INT;
1447 if (normalized)
1448 return VERTEX_FORMAT_UINT2_NORM;
1449 return VERTEX_FORMAT_UINT2;
1450 case 3:
1451 if (pureInteger)
1452 return VERTEX_FORMAT_UINT3_INT;
1453 if (normalized)
1454 return VERTEX_FORMAT_UINT3_NORM;
1455 return VERTEX_FORMAT_UINT3;
1456 case 4:
1457 if (pureInteger)
1458 return VERTEX_FORMAT_UINT4_INT;
1459 if (normalized)
1460 return VERTEX_FORMAT_UINT4_NORM;
1461 return VERTEX_FORMAT_UINT4;
1462 default:
1463 UNREACHABLE();
1464 break;
1465 }
1466 case GL_FLOAT:
1467 switch (components)
1468 {
1469 case 1:
1470 return VERTEX_FORMAT_FLOAT1;
1471 case 2:
1472 return VERTEX_FORMAT_FLOAT2;
1473 case 3:
1474 return VERTEX_FORMAT_FLOAT3;
1475 case 4:
1476 return VERTEX_FORMAT_FLOAT4;
1477 default:
1478 UNREACHABLE();
1479 break;
1480 }
1481 case GL_HALF_FLOAT:
1482 switch (components)
1483 {
1484 case 1:
1485 return VERTEX_FORMAT_HALF1;
1486 case 2:
1487 return VERTEX_FORMAT_HALF2;
1488 case 3:
1489 return VERTEX_FORMAT_HALF3;
1490 case 4:
1491 return VERTEX_FORMAT_HALF4;
1492 default:
1493 UNREACHABLE();
1494 break;
1495 }
1496 case GL_FIXED:
1497 switch (components)
1498 {
1499 case 1:
1500 return VERTEX_FORMAT_FIXED1;
1501 case 2:
1502 return VERTEX_FORMAT_FIXED2;
1503 case 3:
1504 return VERTEX_FORMAT_FIXED3;
1505 case 4:
1506 return VERTEX_FORMAT_FIXED4;
1507 default:
1508 UNREACHABLE();
1509 break;
1510 }
1511 case GL_INT_2_10_10_10_REV:
1512 if (pureInteger)
1513 return VERTEX_FORMAT_SINT210_INT;
1514 if (normalized)
1515 return VERTEX_FORMAT_SINT210_NORM;
1516 return VERTEX_FORMAT_SINT210;
1517 case GL_UNSIGNED_INT_2_10_10_10_REV:
1518 if (pureInteger)
1519 return VERTEX_FORMAT_UINT210_INT;
1520 if (normalized)
1521 return VERTEX_FORMAT_UINT210_NORM;
1522 return VERTEX_FORMAT_UINT210;
1523 default:
1524 UNREACHABLE();
1525 break;
1526 }
1527 return VERTEX_FORMAT_UBYTE1;
1528}
1529
1530VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1531{
1532 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1533}
1534
1535VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1536{
1537 if (!attrib.enabled)
1538 {
1539 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1540 }
1541 return GetVertexFormatType(attrib);
1542}
1543
1544const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1545{
1546 switch (vertexFormatType)
1547 {
1548 case VERTEX_FORMAT_SBYTE1:
1549 {
1550 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1551 return format;
1552 }
1553 case VERTEX_FORMAT_SBYTE1_NORM:
1554 {
1555 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1556 return format;
1557 }
1558 case VERTEX_FORMAT_SBYTE2:
1559 {
1560 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1561 return format;
1562 }
1563 case VERTEX_FORMAT_SBYTE2_NORM:
1564 {
1565 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1566 return format;
1567 }
1568 case VERTEX_FORMAT_SBYTE3:
1569 {
1570 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1571 return format;
1572 }
1573 case VERTEX_FORMAT_SBYTE3_NORM:
1574 {
1575 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1576 return format;
1577 }
1578 case VERTEX_FORMAT_SBYTE4:
1579 {
1580 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1581 return format;
1582 }
1583 case VERTEX_FORMAT_SBYTE4_NORM:
1584 {
1585 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1586 return format;
1587 }
1588 case VERTEX_FORMAT_UBYTE1:
1589 {
1590 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1591 return format;
1592 }
1593 case VERTEX_FORMAT_UBYTE1_NORM:
1594 {
1595 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1596 return format;
1597 }
1598 case VERTEX_FORMAT_UBYTE2:
1599 {
1600 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1601 return format;
1602 }
1603 case VERTEX_FORMAT_UBYTE2_NORM:
1604 {
1605 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1606 return format;
1607 }
1608 case VERTEX_FORMAT_UBYTE3:
1609 {
1610 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1611 return format;
1612 }
1613 case VERTEX_FORMAT_UBYTE3_NORM:
1614 {
1615 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1616 return format;
1617 }
1618 case VERTEX_FORMAT_UBYTE4:
1619 {
1620 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1621 return format;
1622 }
1623 case VERTEX_FORMAT_UBYTE4_NORM:
1624 {
1625 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1626 return format;
1627 }
1628 case VERTEX_FORMAT_SSHORT1:
1629 {
1630 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1631 return format;
1632 }
1633 case VERTEX_FORMAT_SSHORT1_NORM:
1634 {
1635 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1636 return format;
1637 }
1638 case VERTEX_FORMAT_SSHORT2:
1639 {
1640 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1641 return format;
1642 }
1643 case VERTEX_FORMAT_SSHORT2_NORM:
1644 {
1645 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1646 return format;
1647 }
1648 case VERTEX_FORMAT_SSHORT3:
1649 {
1650 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1651 return format;
1652 }
1653 case VERTEX_FORMAT_SSHORT3_NORM:
1654 {
1655 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1656 return format;
1657 }
1658 case VERTEX_FORMAT_SSHORT4:
1659 {
1660 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1661 return format;
1662 }
1663 case VERTEX_FORMAT_SSHORT4_NORM:
1664 {
1665 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1666 return format;
1667 }
1668 case VERTEX_FORMAT_USHORT1:
1669 {
1670 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1671 return format;
1672 }
1673 case VERTEX_FORMAT_USHORT1_NORM:
1674 {
1675 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1676 return format;
1677 }
1678 case VERTEX_FORMAT_USHORT2:
1679 {
1680 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1681 return format;
1682 }
1683 case VERTEX_FORMAT_USHORT2_NORM:
1684 {
1685 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1686 return format;
1687 }
1688 case VERTEX_FORMAT_USHORT3:
1689 {
1690 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1691 return format;
1692 }
1693 case VERTEX_FORMAT_USHORT3_NORM:
1694 {
1695 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1696 return format;
1697 }
1698 case VERTEX_FORMAT_USHORT4:
1699 {
1700 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1701 return format;
1702 }
1703 case VERTEX_FORMAT_USHORT4_NORM:
1704 {
1705 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1706 return format;
1707 }
1708 case VERTEX_FORMAT_SINT1:
1709 {
1710 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1711 return format;
1712 }
1713 case VERTEX_FORMAT_SINT1_NORM:
1714 {
1715 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1716 return format;
1717 }
1718 case VERTEX_FORMAT_SINT2:
1719 {
1720 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1721 return format;
1722 }
1723 case VERTEX_FORMAT_SINT2_NORM:
1724 {
1725 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1726 return format;
1727 }
1728 case VERTEX_FORMAT_SINT3:
1729 {
1730 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1731 return format;
1732 }
1733 case VERTEX_FORMAT_SINT3_NORM:
1734 {
1735 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1736 return format;
1737 }
1738 case VERTEX_FORMAT_SINT4:
1739 {
1740 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1741 return format;
1742 }
1743 case VERTEX_FORMAT_SINT4_NORM:
1744 {
1745 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1746 return format;
1747 }
1748 case VERTEX_FORMAT_UINT1:
1749 {
1750 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1751 return format;
1752 }
1753 case VERTEX_FORMAT_UINT1_NORM:
1754 {
1755 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1756 return format;
1757 }
1758 case VERTEX_FORMAT_UINT2:
1759 {
1760 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1761 return format;
1762 }
1763 case VERTEX_FORMAT_UINT2_NORM:
1764 {
1765 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1766 return format;
1767 }
1768 case VERTEX_FORMAT_UINT3:
1769 {
1770 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1771 return format;
1772 }
1773 case VERTEX_FORMAT_UINT3_NORM:
1774 {
1775 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1776 return format;
1777 }
1778 case VERTEX_FORMAT_UINT4:
1779 {
1780 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1781 return format;
1782 }
1783 case VERTEX_FORMAT_UINT4_NORM:
1784 {
1785 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1786 return format;
1787 }
1788 case VERTEX_FORMAT_SBYTE1_INT:
1789 {
1790 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1791 return format;
1792 }
1793 case VERTEX_FORMAT_SBYTE2_INT:
1794 {
1795 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1796 return format;
1797 }
1798 case VERTEX_FORMAT_SBYTE3_INT:
1799 {
1800 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1801 return format;
1802 }
1803 case VERTEX_FORMAT_SBYTE4_INT:
1804 {
1805 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1806 return format;
1807 }
1808 case VERTEX_FORMAT_UBYTE1_INT:
1809 {
1810 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1811 return format;
1812 }
1813 case VERTEX_FORMAT_UBYTE2_INT:
1814 {
1815 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1816 return format;
1817 }
1818 case VERTEX_FORMAT_UBYTE3_INT:
1819 {
1820 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1821 return format;
1822 }
1823 case VERTEX_FORMAT_UBYTE4_INT:
1824 {
1825 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1826 return format;
1827 }
1828 case VERTEX_FORMAT_SSHORT1_INT:
1829 {
1830 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1831 return format;
1832 }
1833 case VERTEX_FORMAT_SSHORT2_INT:
1834 {
1835 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1836 return format;
1837 }
1838 case VERTEX_FORMAT_SSHORT3_INT:
1839 {
1840 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1841 return format;
1842 }
1843 case VERTEX_FORMAT_SSHORT4_INT:
1844 {
1845 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1846 return format;
1847 }
1848 case VERTEX_FORMAT_USHORT1_INT:
1849 {
1850 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1851 return format;
1852 }
1853 case VERTEX_FORMAT_USHORT2_INT:
1854 {
1855 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1856 return format;
1857 }
1858 case VERTEX_FORMAT_USHORT3_INT:
1859 {
1860 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1861 return format;
1862 }
1863 case VERTEX_FORMAT_USHORT4_INT:
1864 {
1865 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1866 return format;
1867 }
1868 case VERTEX_FORMAT_SINT1_INT:
1869 {
1870 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1871 return format;
1872 }
1873 case VERTEX_FORMAT_SINT2_INT:
1874 {
1875 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1876 return format;
1877 }
1878 case VERTEX_FORMAT_SINT3_INT:
1879 {
1880 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1881 return format;
1882 }
1883 case VERTEX_FORMAT_SINT4_INT:
1884 {
1885 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1886 return format;
1887 }
1888 case VERTEX_FORMAT_UINT1_INT:
1889 {
1890 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1891 return format;
1892 }
1893 case VERTEX_FORMAT_UINT2_INT:
1894 {
1895 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1896 return format;
1897 }
1898 case VERTEX_FORMAT_UINT3_INT:
1899 {
1900 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1901 return format;
1902 }
1903 case VERTEX_FORMAT_UINT4_INT:
1904 {
1905 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1906 return format;
1907 }
1908 case VERTEX_FORMAT_FIXED1:
1909 {
1910 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1911 return format;
1912 }
1913 case VERTEX_FORMAT_FIXED2:
1914 {
1915 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1916 return format;
1917 }
1918 case VERTEX_FORMAT_FIXED3:
1919 {
1920 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1921 return format;
1922 }
1923 case VERTEX_FORMAT_FIXED4:
1924 {
1925 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1926 return format;
1927 }
1928 case VERTEX_FORMAT_HALF1:
1929 {
1930 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1931 return format;
1932 }
1933 case VERTEX_FORMAT_HALF2:
1934 {
1935 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1936 return format;
1937 }
1938 case VERTEX_FORMAT_HALF3:
1939 {
1940 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1941 return format;
1942 }
1943 case VERTEX_FORMAT_HALF4:
1944 {
1945 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1946 return format;
1947 }
1948 case VERTEX_FORMAT_FLOAT1:
1949 {
1950 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1951 return format;
1952 }
1953 case VERTEX_FORMAT_FLOAT2:
1954 {
1955 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1956 return format;
1957 }
1958 case VERTEX_FORMAT_FLOAT3:
1959 {
1960 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1961 return format;
1962 }
1963 case VERTEX_FORMAT_FLOAT4:
1964 {
1965 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1966 return format;
1967 }
1968 case VERTEX_FORMAT_SINT210:
1969 {
1970 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1971 return format;
1972 }
1973 case VERTEX_FORMAT_UINT210:
1974 {
1975 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1976 return format;
1977 }
1978 case VERTEX_FORMAT_SINT210_NORM:
1979 {
1980 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1981 return format;
1982 }
1983 case VERTEX_FORMAT_UINT210_NORM:
1984 {
1985 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1986 return format;
1987 }
1988 case VERTEX_FORMAT_SINT210_INT:
1989 {
1990 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1991 return format;
1992 }
1993 case VERTEX_FORMAT_UINT210_INT:
1994 {
1995 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1996 return format;
1997 }
1998 default:
1999 {
2000 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2001 return format;
2002 }
2003 }
2004}
2005
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002006size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2007{
2008 switch (vertexFormatType)
2009 {
2010 case VERTEX_FORMAT_SBYTE1:
2011 case VERTEX_FORMAT_SBYTE1_NORM:
2012 case VERTEX_FORMAT_UBYTE1:
2013 case VERTEX_FORMAT_UBYTE1_NORM:
2014 case VERTEX_FORMAT_SBYTE1_INT:
2015 case VERTEX_FORMAT_UBYTE1_INT:
2016 return 1;
2017
2018 case VERTEX_FORMAT_SBYTE2:
2019 case VERTEX_FORMAT_SBYTE2_NORM:
2020 case VERTEX_FORMAT_UBYTE2:
2021 case VERTEX_FORMAT_UBYTE2_NORM:
2022 case VERTEX_FORMAT_SBYTE2_INT:
2023 case VERTEX_FORMAT_UBYTE2_INT:
2024 case VERTEX_FORMAT_SSHORT1:
2025 case VERTEX_FORMAT_SSHORT1_NORM:
2026 case VERTEX_FORMAT_USHORT1:
2027 case VERTEX_FORMAT_USHORT1_NORM:
2028 case VERTEX_FORMAT_SSHORT1_INT:
2029 case VERTEX_FORMAT_USHORT1_INT:
2030 case VERTEX_FORMAT_HALF1:
2031 return 2;
2032
2033 case VERTEX_FORMAT_SBYTE3:
2034 case VERTEX_FORMAT_SBYTE3_NORM:
2035 case VERTEX_FORMAT_UBYTE3:
2036 case VERTEX_FORMAT_UBYTE3_NORM:
2037 case VERTEX_FORMAT_SBYTE3_INT:
2038 case VERTEX_FORMAT_UBYTE3_INT:
2039 return 3;
2040
2041 case VERTEX_FORMAT_SBYTE4:
2042 case VERTEX_FORMAT_SBYTE4_NORM:
2043 case VERTEX_FORMAT_UBYTE4:
2044 case VERTEX_FORMAT_UBYTE4_NORM:
2045 case VERTEX_FORMAT_SBYTE4_INT:
2046 case VERTEX_FORMAT_UBYTE4_INT:
2047 case VERTEX_FORMAT_SSHORT2:
2048 case VERTEX_FORMAT_SSHORT2_NORM:
2049 case VERTEX_FORMAT_USHORT2:
2050 case VERTEX_FORMAT_USHORT2_NORM:
2051 case VERTEX_FORMAT_SSHORT2_INT:
2052 case VERTEX_FORMAT_USHORT2_INT:
2053 case VERTEX_FORMAT_SINT1:
2054 case VERTEX_FORMAT_SINT1_NORM:
2055 case VERTEX_FORMAT_UINT1:
2056 case VERTEX_FORMAT_UINT1_NORM:
2057 case VERTEX_FORMAT_SINT1_INT:
2058 case VERTEX_FORMAT_UINT1_INT:
2059 case VERTEX_FORMAT_HALF2:
2060 case VERTEX_FORMAT_FIXED1:
2061 case VERTEX_FORMAT_FLOAT1:
2062 case VERTEX_FORMAT_SINT210:
2063 case VERTEX_FORMAT_UINT210:
2064 case VERTEX_FORMAT_SINT210_NORM:
2065 case VERTEX_FORMAT_UINT210_NORM:
2066 case VERTEX_FORMAT_SINT210_INT:
2067 case VERTEX_FORMAT_UINT210_INT:
2068 return 4;
2069
2070 case VERTEX_FORMAT_SSHORT3:
2071 case VERTEX_FORMAT_SSHORT3_NORM:
2072 case VERTEX_FORMAT_USHORT3:
2073 case VERTEX_FORMAT_USHORT3_NORM:
2074 case VERTEX_FORMAT_SSHORT3_INT:
2075 case VERTEX_FORMAT_USHORT3_INT:
2076 case VERTEX_FORMAT_HALF3:
2077 return 6;
2078
2079 case VERTEX_FORMAT_SSHORT4:
2080 case VERTEX_FORMAT_SSHORT4_NORM:
2081 case VERTEX_FORMAT_USHORT4:
2082 case VERTEX_FORMAT_USHORT4_NORM:
2083 case VERTEX_FORMAT_SSHORT4_INT:
2084 case VERTEX_FORMAT_USHORT4_INT:
2085 case VERTEX_FORMAT_SINT2:
2086 case VERTEX_FORMAT_SINT2_NORM:
2087 case VERTEX_FORMAT_UINT2:
2088 case VERTEX_FORMAT_UINT2_NORM:
2089 case VERTEX_FORMAT_SINT2_INT:
2090 case VERTEX_FORMAT_UINT2_INT:
2091 case VERTEX_FORMAT_HALF4:
2092 case VERTEX_FORMAT_FIXED2:
2093 case VERTEX_FORMAT_FLOAT2:
2094 return 8;
2095
2096 case VERTEX_FORMAT_SINT3:
2097 case VERTEX_FORMAT_SINT3_NORM:
2098 case VERTEX_FORMAT_UINT3:
2099 case VERTEX_FORMAT_UINT3_NORM:
2100 case VERTEX_FORMAT_SINT3_INT:
2101 case VERTEX_FORMAT_UINT3_INT:
2102 case VERTEX_FORMAT_FIXED3:
2103 case VERTEX_FORMAT_FLOAT3:
2104 return 12;
2105
2106 case VERTEX_FORMAT_SINT4:
2107 case VERTEX_FORMAT_SINT4_NORM:
2108 case VERTEX_FORMAT_UINT4:
2109 case VERTEX_FORMAT_UINT4_NORM:
2110 case VERTEX_FORMAT_SINT4_INT:
2111 case VERTEX_FORMAT_UINT4_INT:
2112 case VERTEX_FORMAT_FIXED4:
2113 case VERTEX_FORMAT_FLOAT4:
2114 return 16;
2115
2116 case VERTEX_FORMAT_INVALID:
2117 default:
2118 UNREACHABLE();
2119 return 0;
2120 }
2121}
2122
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002123bool ValidES3InternalFormat(GLenum internalFormat)
2124{
2125 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2126 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2127}
2128
Jamie Madilld3dfda22015-07-06 08:28:49 -04002129VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
2130 : type(typeIn),
2131 normalized(normalizedIn),
2132 components(componentsIn),
2133 pureInteger(pureIntegerIn)
2134{
2135 // float -> !normalized
2136 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
2137}
2138
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002139}