blob: 53eabe48292b8b6638f3c11a65a36ed21e4f4dde [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Geoff Langca271392017-04-05 12:30:00 -040027using InternalFormatInfoMap =
28 std::unordered_map<GLenum, std::unordered_map<GLenum, InternalFormat>>;
Jamie Madilla3944d42016-07-22 22:13:26 -040029
30} // anonymous namespace
31
32FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
33{
34}
35
36FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
37{
38}
39
40bool FormatType::operator<(const FormatType &other) const
41{
42 if (format != other.format)
43 return format < other.format;
44 return type < other.type;
45}
46
Geoff Lang5d601382014-07-22 15:14:06 -040047Type::Type()
48 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020049 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -040050 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040051{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052}
53
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020054static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055{
Geoff Lang5d601382014-07-22 15:14:06 -040056 Type info;
57 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020058 GLuint i = 0;
59 while ((1u << i) < bytes)
60 {
61 ++i;
62 }
63 info.bytesShift = i;
64 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040065 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020066 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040067}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang5d601382014-07-22 15:14:06 -040069bool operator<(const Type& a, const Type& b)
70{
71 return memcmp(&a, &b, sizeof(Type)) < 0;
72}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000074// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040075static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076{
Geoff Lang493daf52014-07-03 13:38:44 -040077 return true;
78}
79
Geoff Langeb66a6e2016-10-31 13:06:12 -040080static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082 return false;
83}
84
Geoff Langeb66a6e2016-10-31 13:06:12 -040085template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
86static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040087{
Geoff Langeb66a6e2016-10-31 13:06:12 -040088 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040089}
90
Geoff Langcec35902014-04-16 10:52:36 -040091// Pointer to a boolean memeber of the Extensions struct
92typedef bool(Extensions::*ExtensionBool);
93
94// Check support for a single extension
95template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040096static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040097{
Geoff Lange4a492b2014-06-19 14:14:41 -040098 return extensions.*bool1;
99}
100
101// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400102template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
103static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400104{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
106 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400107}
108
109// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400110template <GLuint minCoreGLMajorVersion,
111 GLuint minCoreGLMinorVersion,
112 ExtensionBool bool1,
113 ExtensionBool bool2>
114static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400115{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400116 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
117 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400118}
119
120// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400121template <GLuint minCoreGLMajorVersion,
122 GLuint minCoreGLMinorVersion,
123 ExtensionBool bool1,
124 ExtensionBool bool2>
125static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400126{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400127 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
128 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400129}
130
131// Check support for two extensions
132template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400133static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400134{
Geoff Langabce7622014-09-19 16:13:00 -0400135 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400136}
137
Geoff Lang60ad73d2015-10-23 10:08:44 -0400138// Check support for either of two extensions
139template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400140static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400141{
142 return extensions.*bool1 || extensions.*bool2;
143}
144
Jamie Madillcd089732015-12-17 09:53:09 -0500145// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400146static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500147{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400148 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500149}
150
Geoff Lang677bb6f2017-04-05 12:40:40 -0400151static bool HalfFloatRGBRenderableSupport(const Version &clientVersion,
152 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500153{
154 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
155}
156
Geoff Lang677bb6f2017-04-05 12:40:40 -0400157static bool HalfFloatRGBARenderableSupport(const Version &clientVersion,
158 const Extensions &extensions)
159{
160 return HalfFloatSupport(clientVersion, extensions) &&
161 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
162}
163
Jamie Madillcd089732015-12-17 09:53:09 -0500164// Special function for half float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400165
166// R16F, RG16F
167static bool HalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500168{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400169 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500170}
171
Geoff Lang677bb6f2017-04-05 12:40:40 -0400172// R16F, RG16F
173static bool HalfFloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400175 // It's unclear if EXT_color_buffer_half_float gives renderability to non-OES half float
176 // textures
177 return HalfFloatRGSupport(clientVersion, extensions) &&
178 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
179}
180
181// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
182static bool UnsizedHalfFloatOESRGSupport(const Version &, const Extensions &extensions)
183{
184 return extensions.textureHalfFloat && extensions.textureRG;
185}
186
187// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
188static bool UnsizedHalfFloatOESRGRenderableSupport(const Version &clientVersion,
189 const Extensions &extensions)
190{
191 return UnsizedHalfFloatOESRGSupport(clientVersion, extensions) &&
192 extensions.colorBufferHalfFloat;
193}
194
195// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
196static bool UnsizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
197{
198 return extensions.textureHalfFloat;
199}
200
201// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
202static bool UnsizedHalfFloatOESRenderableSupport(const Version &clientVersion,
203 const Extensions &extensions)
204{
205 return UnsizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500206}
207
208// Special function for float formats with three or four channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400209
210// RGB32F, RGBA32F
Geoff Langeb66a6e2016-10-31 13:06:12 -0400211static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500212{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400213 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500214}
215
Geoff Lang677bb6f2017-04-05 12:40:40 -0400216// RGB32F
217static bool FloatRGBRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500218{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400219 return FloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
220}
221
222// RGBA32F
223static bool FloatRGBARenderableSupport(const Version &clientVersion, const Extensions &extensions)
224{
Jamie Madillcd089732015-12-17 09:53:09 -0500225 return FloatSupport(clientVersion, extensions) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400226 (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
227}
228
229// RGB + FLOAT, RGBA + FLOAT
230static bool UnsizedFloatSupport(const Version &clientVersion, const Extensions &extensions)
231{
232 return extensions.textureFloat;
233}
234
235// RGB + FLOAT
236static bool UnsizedFloatRGBRenderableSupport(const Version &clientVersion,
237 const Extensions &extensions)
238{
239 return UnsizedFloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
240}
241
242// RGBA + FLOAT
243static bool UnsizedFloatRGBARenderableSupport(const Version &clientVersion,
244 const Extensions &extensions)
245{
246 return UnsizedFloatSupport(clientVersion, extensions) &&
247 (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500248}
249
250// Special function for float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400251
252// R32F, RG32F
253static bool FloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500254{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400255 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500256}
257
Geoff Lang677bb6f2017-04-05 12:40:40 -0400258// R32F, RG32F
259static bool FloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500260{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400261 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
262}
263
264// RED + FLOAT, RG + FLOAT
265static bool UnsizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
266{
267 return extensions.textureFloat && extensions.textureRG;
268}
269
270// RED + FLOAT, RG + FLOAT
271static bool UnsizedFloatRGRenderableSupport(const Version &clientVersion,
272 const Extensions &extensions)
273{
274 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500275}
276
Geoff Lang5d601382014-07-22 15:14:06 -0400277InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400278 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400279 sized(false),
280 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400281 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400282 greenBits(0),
283 blueBits(0),
284 luminanceBits(0),
285 alphaBits(0),
286 sharedBits(0),
287 depthBits(0),
288 stencilBits(0),
289 pixelBytes(0),
290 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400291 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400292 compressedBlockWidth(0),
293 compressedBlockHeight(0),
294 format(GL_NONE),
295 type(GL_NONE),
296 componentType(GL_NONE),
297 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400298 textureSupport(NeverSupported),
299 renderSupport(NeverSupported),
300 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301{
Geoff Lang5d601382014-07-22 15:14:06 -0400302}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303
Jamie Madilla3944d42016-07-22 22:13:26 -0400304bool InternalFormat::isLUMA() const
305{
306 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
307 (luminanceBits + alphaBits) > 0);
308}
309
Geoff Langf607c602016-09-21 11:46:48 -0400310GLenum InternalFormat::getReadPixelsFormat() const
311{
312 return format;
313}
314
315GLenum InternalFormat::getReadPixelsType() const
316{
317 switch (type)
318 {
319 case GL_HALF_FLOAT:
320 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
321 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
322 // OES_texture_half_float
323 return GL_HALF_FLOAT_OES;
324
325 default:
326 return type;
327 }
328}
329
Olli Etuaho50c562d2017-06-06 14:43:30 +0300330bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
331{
332 // GLES 3.0.5 section 4.4.2.2:
333 // "Implementations are required to support the same internal formats for renderbuffers as the
334 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
335 // formats labelled "texture-only"."
336 if (!sized || compressed)
337 {
338 return false;
339 }
340
341 // Luma formats.
342 if (isLUMA())
343 {
344 return false;
345 }
346
347 // Depth/stencil formats.
348 if (depthBits > 0 || stencilBits > 0)
349 {
350 // GLES 2.0.25 table 4.5.
351 // GLES 3.0.5 section 3.8.3.1.
352 // GLES 3.1 table 8.14.
353
354 // Required formats in all versions.
355 switch (internalFormat)
356 {
357 case GL_DEPTH_COMPONENT16:
358 case GL_STENCIL_INDEX8:
359 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
360 // is in section 4.4.2.2.
361 return true;
362 default:
363 break;
364 }
365 if (version.major < 3)
366 {
367 return false;
368 }
369 // Required formats in GLES 3.0 and up.
370 switch (internalFormat)
371 {
372 case GL_DEPTH_COMPONENT32F:
373 case GL_DEPTH_COMPONENT24:
374 case GL_DEPTH32F_STENCIL8:
375 case GL_DEPTH24_STENCIL8:
376 return true;
377 default:
378 return false;
379 }
380 }
381
382 // RGBA formats.
383 // GLES 2.0.25 table 4.5.
384 // GLES 3.0.5 section 3.8.3.1.
385 // GLES 3.1 table 8.13.
386
387 // Required formats in all versions.
388 switch (internalFormat)
389 {
390 case GL_RGBA4:
391 case GL_RGB5_A1:
392 case GL_RGB565:
393 return true;
394 default:
395 break;
396 }
397 if (version.major < 3)
398 {
399 return false;
400 }
401
402 if (format == GL_BGRA_EXT)
403 {
404 return false;
405 }
406
407 switch (componentType)
408 {
409 case GL_SIGNED_NORMALIZED:
410 case GL_FLOAT:
411 return false;
412 case GL_UNSIGNED_INT:
413 case GL_INT:
414 // Integer RGB formats are not required renderbuffer formats.
415 if (alphaBits == 0 && blueBits != 0)
416 {
417 return false;
418 }
419 // All integer R and RG formats are required.
420 // Integer RGBA formats including RGB10_A2_UI are required.
421 return true;
422 case GL_UNSIGNED_NORMALIZED:
423 if (internalFormat == GL_SRGB8)
424 {
425 return false;
426 }
427 return true;
428 default:
429 UNREACHABLE();
430 return false;
431 }
432}
433
Geoff Langca271392017-04-05 12:30:00 -0400434Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400435{
436}
437
Geoff Langca271392017-04-05 12:30:00 -0400438Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400439{
Jamie Madilla3944d42016-07-22 22:13:26 -0400440}
441
Geoff Langca271392017-04-05 12:30:00 -0400442Format::Format(GLenum internalFormat, GLenum type)
443 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400444{
Jamie Madilla3944d42016-07-22 22:13:26 -0400445}
446
447Format::Format(const Format &other) = default;
448Format &Format::operator=(const Format &other) = default;
449
Jamie Madilla3944d42016-07-22 22:13:26 -0400450bool Format::valid() const
451{
Geoff Langca271392017-04-05 12:30:00 -0400452 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400453}
454
455// static
456bool Format::SameSized(const Format &a, const Format &b)
457{
Geoff Langca271392017-04-05 12:30:00 -0400458 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400459}
460
461// static
462Format Format::Invalid()
463{
Geoff Langca271392017-04-05 12:30:00 -0400464 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400465 return invalid;
466}
467
Yuly Novikovd73f8522017-01-13 17:48:57 -0500468std::ostream &operator<<(std::ostream &os, const Format &fmt)
469{
470 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400471 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500472}
473
Jamie Madilla3944d42016-07-22 22:13:26 -0400474bool InternalFormat::operator==(const InternalFormat &other) const
475{
Geoff Langca271392017-04-05 12:30:00 -0400476 // We assume all internal formats are unique if they have the same internal format and type
477 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400478}
479
480bool InternalFormat::operator!=(const InternalFormat &other) const
481{
Geoff Langca271392017-04-05 12:30:00 -0400482 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400483}
484
Geoff Langca271392017-04-05 12:30:00 -0400485void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400486{
Geoff Langca271392017-04-05 12:30:00 -0400487 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
488 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
489 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400490}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000491
Jamie Madilla3944d42016-07-22 22:13:26 -0400492void AddRGBAFormat(InternalFormatInfoMap *map,
493 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400494 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400495 GLuint red,
496 GLuint green,
497 GLuint blue,
498 GLuint alpha,
499 GLuint shared,
500 GLenum format,
501 GLenum type,
502 GLenum componentType,
503 bool srgb,
504 InternalFormat::SupportCheckFunction textureSupport,
505 InternalFormat::SupportCheckFunction renderSupport,
506 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400507{
508 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400509 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400510 formatInfo.sized = sized;
511 formatInfo.sizedInternalFormat =
512 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400513 formatInfo.redBits = red;
514 formatInfo.greenBits = green;
515 formatInfo.blueBits = blue;
516 formatInfo.alphaBits = alpha;
517 formatInfo.sharedBits = shared;
518 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400519 formatInfo.componentCount =
520 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400521 formatInfo.format = format;
522 formatInfo.type = type;
523 formatInfo.componentType = componentType;
524 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
525 formatInfo.textureSupport = textureSupport;
526 formatInfo.renderSupport = renderSupport;
527 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400528
529 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400530}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000531
Geoff Langca271392017-04-05 12:30:00 -0400532static void AddLUMAFormat(InternalFormatInfoMap *map,
533 GLenum internalFormat,
534 bool sized,
535 GLuint luminance,
536 GLuint alpha,
537 GLenum format,
538 GLenum type,
539 GLenum componentType,
540 InternalFormat::SupportCheckFunction textureSupport,
541 InternalFormat::SupportCheckFunction renderSupport,
542 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400543{
544 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400545 formatInfo.internalFormat = internalFormat;
546 formatInfo.sized = sized;
547 formatInfo.sizedInternalFormat =
548 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400549 formatInfo.luminanceBits = luminance;
550 formatInfo.alphaBits = alpha;
551 formatInfo.pixelBytes = (luminance + alpha) / 8;
552 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
553 formatInfo.format = format;
554 formatInfo.type = type;
555 formatInfo.componentType = componentType;
556 formatInfo.colorEncoding = GL_LINEAR;
557 formatInfo.textureSupport = textureSupport;
558 formatInfo.renderSupport = renderSupport;
559 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400560
561 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400562}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000563
Jamie Madilla3944d42016-07-22 22:13:26 -0400564void AddDepthStencilFormat(InternalFormatInfoMap *map,
565 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400566 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400567 GLuint depthBits,
568 GLuint stencilBits,
569 GLuint unusedBits,
570 GLenum format,
571 GLenum type,
572 GLenum componentType,
573 InternalFormat::SupportCheckFunction textureSupport,
574 InternalFormat::SupportCheckFunction renderSupport,
575 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400576{
577 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400578 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400579 formatInfo.sized = sized;
580 formatInfo.sizedInternalFormat =
581 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400582 formatInfo.depthBits = depthBits;
583 formatInfo.stencilBits = stencilBits;
584 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
585 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
586 formatInfo.format = format;
587 formatInfo.type = type;
588 formatInfo.componentType = componentType;
589 formatInfo.colorEncoding = GL_LINEAR;
590 formatInfo.textureSupport = textureSupport;
591 formatInfo.renderSupport = renderSupport;
592 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400593
594 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400595}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596
Geoff Langca271392017-04-05 12:30:00 -0400597void AddCompressedFormat(InternalFormatInfoMap *map,
598 GLenum internalFormat,
599 GLuint compressedBlockWidth,
600 GLuint compressedBlockHeight,
601 GLuint compressedBlockSize,
602 GLuint componentCount,
603 GLenum format,
604 GLenum type,
605 bool srgb,
606 InternalFormat::SupportCheckFunction textureSupport,
607 InternalFormat::SupportCheckFunction renderSupport,
608 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400609{
610 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400611 formatInfo.internalFormat = internalFormat;
612 formatInfo.sized = true;
613 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400614 formatInfo.compressedBlockWidth = compressedBlockWidth;
615 formatInfo.compressedBlockHeight = compressedBlockHeight;
616 formatInfo.pixelBytes = compressedBlockSize / 8;
617 formatInfo.componentCount = componentCount;
618 formatInfo.format = format;
619 formatInfo.type = type;
620 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
621 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
622 formatInfo.compressed = true;
623 formatInfo.textureSupport = textureSupport;
624 formatInfo.renderSupport = renderSupport;
625 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400626
627 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400628}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000629
Geoff Lange4a492b2014-06-19 14:14:41 -0400630static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631{
632 InternalFormatInfoMap map;
633
634 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400635 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636
Jamie Madilla3944d42016-07-22 22:13:26 -0400637 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000638
Geoff Langca271392017-04-05 12:30:00 -0400639 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
640 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);
641 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
642 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);
643 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
644 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);
645 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
646 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);
647 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);
648 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);
649 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);
650 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
651 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);
652 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);
653 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);
654 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);
655 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);
656 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);
657 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);
658 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);
659 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);
660 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);
661 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);
662 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);
663 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);
664 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);
665 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);
666 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);
667 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);
668 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);
669 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
670 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);
671 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
672 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);
673 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
674 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);
675 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);
676 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);
677 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);
678 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);
679 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);
680 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 -0400681
Geoff Langca271392017-04-05 12:30:00 -0400682 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);
683 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);
684 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 +0000685
Jamie Madillec0b5802016-07-04 13:11:59 -0400686 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400687 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 -0400688
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000689 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400690 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
691 // | | | | | | | type | | | | |
692 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>);
693 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>);
694 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>);
695 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>);
696 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
697 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
698 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
699 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 +0000700
701 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400702 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
703 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>);
704 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>);
705 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>);
706 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 );
707 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 );
708 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 -0800709 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000710
711 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400712 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
713 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
714 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
715 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
716 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>);
717 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>);
718 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>);
719 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
720 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
721 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 +0000722
723 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400724 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
725 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
726 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
727 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
728 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
729 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
730 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
731 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
732 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
733 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
734 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 +0000735
736 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400737 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
738 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
739 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 +0000740
741 // From GL_ANGLE_texture_compression_dxt3
Geoff Langca271392017-04-05 12:30:00 -0400742 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000743
744 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400745 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 -0400746
747 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400748 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 +0000749
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800750 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400751 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
752 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
753 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
754 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
755 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 -0800756
Geoff Lang60ad73d2015-10-23 10:08:44 -0400757 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400758 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
759 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);
760 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);
761 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);
762 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);
763 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);
764 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);
765 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);
766 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);
767 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);
768 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);
769 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);
770 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);
771 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);
772 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 -0400773
Geoff Langca271392017-04-05 12:30:00 -0400774 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);
775 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);
776 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);
777 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);
778 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);
779 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);
780 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);
781 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);
782 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);
783 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);
784 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);
785 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);
786 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);
787 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 -0400788
Corentin Walleze0902642014-11-04 12:32:15 -0800789 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
790 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
791 // - All other stencil formats (all depth-stencil) are either float or normalized
792 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400793 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
794 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 -0800795
796 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400797 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
798 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
799 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
800 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
801 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);
802 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 -0800803
Vincent Lang25ab4512016-05-13 18:13:59 +0200804 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400805 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
806 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);
807 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);
808 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);
809 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);
810 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);
811 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);
812 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);
813 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 +0200814
Geoff Langca271392017-04-05 12:30:00 -0400815 // Unsized formats
816 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400817 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 -0400818 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 -0400819 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 -0400820 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400821 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
822 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 -0400823 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 -0400824 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);
825 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);
826 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);
827 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 -0400828 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 -0400829 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
830 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);
831
832 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);
833
834 // Unsized integer formats
835 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
836 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
837 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);
838 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
839 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);
840 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
841 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);
842 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
843 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);
844 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
845 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);
846 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
847 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);
848 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
849 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);
850 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
851 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);
852 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
853 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);
854 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
855 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);
856 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
857 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);
858 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
859 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);
860 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);
861
862 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400863 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
864 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
865 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
866 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
867 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
868 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>);
869 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>);
870 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>);
871 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>);
872 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
873 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
874 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 -0400875 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 );
876 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 -0400877 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 -0400878
879 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400880 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
881 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
882 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
883 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
884 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
885 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
886 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
887 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
888 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
889 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 -0400890
891 // Unsized depth stencil formats
892 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
893 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);
894 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);
895 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
896 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);
897 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);
898 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 -0400899 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800900
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000901 return map;
902}
903
Geoff Lange4a492b2014-06-19 14:14:41 -0400904static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000905{
Geoff Lange4a492b2014-06-19 14:14:41 -0400906 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
907 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000908}
909
Geoff Lange4a492b2014-06-19 14:14:41 -0400910static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400911{
912 FormatSet result;
913
Geoff Langca271392017-04-05 12:30:00 -0400914 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400915 {
Geoff Langca271392017-04-05 12:30:00 -0400916 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400917 {
Geoff Langca271392017-04-05 12:30:00 -0400918 if (type.second.sized)
919 {
920 // TODO(jmadill): Fix this hack.
921 if (internalFormat.first == GL_BGR565_ANGLEX)
922 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400923
Geoff Langca271392017-04-05 12:30:00 -0400924 result.insert(internalFormat.first);
925 }
Geoff Langcec35902014-04-16 10:52:36 -0400926 }
927 }
928
929 return result;
930}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000931
Geoff Lang5d601382014-07-22 15:14:06 -0400932const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000933{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200934 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000935 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200936 case GL_UNSIGNED_BYTE:
937 case GL_BYTE:
938 {
939 static const Type info = GenTypeInfo(1, false);
940 return info;
941 }
942 case GL_UNSIGNED_SHORT:
943 case GL_SHORT:
944 case GL_HALF_FLOAT:
945 case GL_HALF_FLOAT_OES:
946 {
947 static const Type info = GenTypeInfo(2, false);
948 return info;
949 }
950 case GL_UNSIGNED_INT:
951 case GL_INT:
952 case GL_FLOAT:
953 {
954 static const Type info = GenTypeInfo(4, false);
955 return info;
956 }
957 case GL_UNSIGNED_SHORT_5_6_5:
958 case GL_UNSIGNED_SHORT_4_4_4_4:
959 case GL_UNSIGNED_SHORT_5_5_5_1:
960 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
961 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
962 {
963 static const Type info = GenTypeInfo(2, true);
964 return info;
965 }
966 case GL_UNSIGNED_INT_2_10_10_10_REV:
967 case GL_UNSIGNED_INT_24_8:
968 case GL_UNSIGNED_INT_10F_11F_11F_REV:
969 case GL_UNSIGNED_INT_5_9_9_9_REV:
970 {
971 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
972 static const Type info = GenTypeInfo(4, true);
973 return info;
974 }
975 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
976 {
977 static const Type info = GenTypeInfo(8, true);
978 return info;
979 }
980 default:
981 {
982 static const Type defaultInfo;
983 return defaultInfo;
984 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000985 }
986}
987
Geoff Langca271392017-04-05 12:30:00 -0400988const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000989{
Geoff Langca271392017-04-05 12:30:00 -0400990 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400991 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400992 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -0400993
994 // Sized internal formats only have one type per entry
995 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000996 {
Geoff Lang5d601382014-07-22 15:14:06 -0400997 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000998 }
Geoff Langca271392017-04-05 12:30:00 -0400999
1000 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1001 if (!internalFormatInfo.sized)
1002 {
1003 return defaultInternalFormat;
1004 }
1005
1006 return internalFormatInfo;
1007}
1008
1009const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1010{
1011 static const InternalFormat defaultInternalFormat;
1012 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1013
1014 auto internalFormatIter = formatMap.find(internalFormat);
1015 if (internalFormatIter == formatMap.end())
1016 {
1017 return defaultInternalFormat;
1018 }
1019
1020 // If the internal format is sized, simply return it without the type check.
1021 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1022 {
1023 return internalFormatIter->second.begin()->second;
1024 }
1025
1026 auto typeIter = internalFormatIter->second.find(type);
1027 if (typeIter == internalFormatIter->second.end())
1028 {
1029 return defaultInternalFormat;
1030 }
1031
1032 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001033}
1034
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001035GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1036{
1037 const auto &typeInfo = GetTypeInfo(formatType);
1038 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1039 return components * typeInfo.bytes;
1040}
1041
Corentin Wallez886de362016-09-27 10:49:35 -04001042ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001043 GLsizei width,
1044 GLint alignment,
1045 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001046{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001047 // Compressed images do not use pack/unpack parameters.
1048 if (compressed)
1049 {
1050 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -04001051 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001052 }
1053
Geoff Lang3f234062016-07-13 15:35:45 -04001054 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001055 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001056
1057 ASSERT(alignment > 0 && isPow2(alignment));
1058 CheckedNumeric<GLuint> checkedAlignment(alignment);
1059 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
1060 ANGLE_TRY_CHECKED_MATH(aligned);
1061 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001062}
1063
Corentin Wallez0e487192016-10-03 16:30:38 -04001064ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
1065 GLint imageHeight,
1066 GLuint rowPitch) const
1067{
1068 GLuint rows =
1069 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1070 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1071
1072 auto depthPitch = checkedRowPitch * rows;
1073 ANGLE_TRY_CHECKED_MATH(depthPitch);
1074 return depthPitch.ValueOrDie();
1075}
1076
Corentin Wallez886de362016-09-27 10:49:35 -04001077ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -04001078 GLsizei width,
1079 GLsizei height,
1080 GLint alignment,
1081 GLint rowLength,
1082 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001083{
Jamie Madille2e406c2016-06-02 13:04:10 -04001084 GLuint rowPitch = 0;
1085 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -04001086 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001087}
1088
Corentin Wallez886de362016-09-27 10:49:35 -04001089ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
1090 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001091{
Jamie Madill513558d2016-06-02 13:04:11 -04001092 CheckedNumeric<GLuint> checkedWidth(size.width);
1093 CheckedNumeric<GLuint> checkedHeight(size.height);
1094 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001095 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1096 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001097
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001098 ASSERT(compressed);
1099 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1100 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1101 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
1102 ANGLE_TRY_CHECKED_MATH(bytes);
1103 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001104}
1105
Corentin Wallez886de362016-09-27 10:49:35 -04001106ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -07001107 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -04001108 const PixelStoreStateBase &state,
1109 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001110{
Olli Etuaho989cac32016-06-08 16:18:49 -07001111 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1112 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001113 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1114 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1115 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001116 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1117 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001118 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001119 {
1120 checkedSkipImagesBytes = 0;
1121 }
1122 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1123 checkedSkipPixels * checkedPixelBytes;
1124 ANGLE_TRY_CHECKED_MATH(skipBytes);
1125 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001126}
1127
Corentin Wallez886de362016-09-27 10:49:35 -04001128ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1129 GLenum formatType,
1130 const Extents &size,
1131 const PixelStoreStateBase &state,
1132 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001133{
Corentin Wallez886de362016-09-27 10:49:35 -04001134 GLuint rowPitch = 0;
1135 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001136 rowPitch);
1137
Corentin Wallez0e487192016-10-03 16:30:38 -04001138 GLuint depthPitch = 0;
1139 if (is3D)
1140 {
1141 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1142 }
1143
Corentin Wallez886de362016-09-27 10:49:35 -04001144 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001145 if (compressed)
1146 {
Corentin Wallez886de362016-09-27 10:49:35 -04001147 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001148 }
Corentin Wallez886de362016-09-27 10:49:35 -04001149 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001150 {
Corentin Wallez886de362016-09-27 10:49:35 -04001151 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1152 checkedCopyBytes += size.width * bytes;
1153
1154 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1155 checkedCopyBytes += heightMinusOne * rowPitch;
1156
1157 if (is3D)
1158 {
1159 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1160 checkedCopyBytes += depthMinusOne * depthPitch;
1161 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001162 }
1163
Corentin Wallez886de362016-09-27 10:49:35 -04001164 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1165 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001166
1167 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1168
1169 ANGLE_TRY_CHECKED_MATH(endByte);
1170 return endByte.ValueOrDie();
1171}
1172
Geoff Langca271392017-04-05 12:30:00 -04001173GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001174{
Geoff Langca271392017-04-05 12:30:00 -04001175 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1176 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001177 {
Geoff Langca271392017-04-05 12:30:00 -04001178 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001179 }
Geoff Langca271392017-04-05 12:30:00 -04001180
1181 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001182}
1183
Geoff Lange4a492b2014-06-19 14:14:41 -04001184const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001185{
Geoff Lange4a492b2014-06-19 14:14:41 -04001186 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001187 return formatSet;
1188}
1189
Jamie Madill09e2d932015-07-14 16:40:31 -04001190AttributeType GetAttributeType(GLenum enumValue)
1191{
1192 switch (enumValue)
1193 {
1194 case GL_FLOAT:
1195 return ATTRIBUTE_FLOAT;
1196 case GL_FLOAT_VEC2:
1197 return ATTRIBUTE_VEC2;
1198 case GL_FLOAT_VEC3:
1199 return ATTRIBUTE_VEC3;
1200 case GL_FLOAT_VEC4:
1201 return ATTRIBUTE_VEC4;
1202 case GL_INT:
1203 return ATTRIBUTE_INT;
1204 case GL_INT_VEC2:
1205 return ATTRIBUTE_IVEC2;
1206 case GL_INT_VEC3:
1207 return ATTRIBUTE_IVEC3;
1208 case GL_INT_VEC4:
1209 return ATTRIBUTE_IVEC4;
1210 case GL_UNSIGNED_INT:
1211 return ATTRIBUTE_UINT;
1212 case GL_UNSIGNED_INT_VEC2:
1213 return ATTRIBUTE_UVEC2;
1214 case GL_UNSIGNED_INT_VEC3:
1215 return ATTRIBUTE_UVEC3;
1216 case GL_UNSIGNED_INT_VEC4:
1217 return ATTRIBUTE_UVEC4;
1218 case GL_FLOAT_MAT2:
1219 return ATTRIBUTE_MAT2;
1220 case GL_FLOAT_MAT3:
1221 return ATTRIBUTE_MAT3;
1222 case GL_FLOAT_MAT4:
1223 return ATTRIBUTE_MAT4;
1224 case GL_FLOAT_MAT2x3:
1225 return ATTRIBUTE_MAT2x3;
1226 case GL_FLOAT_MAT2x4:
1227 return ATTRIBUTE_MAT2x4;
1228 case GL_FLOAT_MAT3x2:
1229 return ATTRIBUTE_MAT3x2;
1230 case GL_FLOAT_MAT3x4:
1231 return ATTRIBUTE_MAT3x4;
1232 case GL_FLOAT_MAT4x2:
1233 return ATTRIBUTE_MAT4x2;
1234 case GL_FLOAT_MAT4x3:
1235 return ATTRIBUTE_MAT4x3;
1236 default:
1237 UNREACHABLE();
1238 return ATTRIBUTE_FLOAT;
1239 }
1240}
1241
Jamie Madilld3dfda22015-07-06 08:28:49 -04001242VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1243{
1244 switch (type)
1245 {
1246 case GL_BYTE:
1247 switch (components)
1248 {
1249 case 1:
1250 if (pureInteger)
1251 return VERTEX_FORMAT_SBYTE1_INT;
1252 if (normalized)
1253 return VERTEX_FORMAT_SBYTE1_NORM;
1254 return VERTEX_FORMAT_SBYTE1;
1255 case 2:
1256 if (pureInteger)
1257 return VERTEX_FORMAT_SBYTE2_INT;
1258 if (normalized)
1259 return VERTEX_FORMAT_SBYTE2_NORM;
1260 return VERTEX_FORMAT_SBYTE2;
1261 case 3:
1262 if (pureInteger)
1263 return VERTEX_FORMAT_SBYTE3_INT;
1264 if (normalized)
1265 return VERTEX_FORMAT_SBYTE3_NORM;
1266 return VERTEX_FORMAT_SBYTE3;
1267 case 4:
1268 if (pureInteger)
1269 return VERTEX_FORMAT_SBYTE4_INT;
1270 if (normalized)
1271 return VERTEX_FORMAT_SBYTE4_NORM;
1272 return VERTEX_FORMAT_SBYTE4;
1273 default:
1274 UNREACHABLE();
1275 break;
1276 }
1277 case GL_UNSIGNED_BYTE:
1278 switch (components)
1279 {
1280 case 1:
1281 if (pureInteger)
1282 return VERTEX_FORMAT_UBYTE1_INT;
1283 if (normalized)
1284 return VERTEX_FORMAT_UBYTE1_NORM;
1285 return VERTEX_FORMAT_UBYTE1;
1286 case 2:
1287 if (pureInteger)
1288 return VERTEX_FORMAT_UBYTE2_INT;
1289 if (normalized)
1290 return VERTEX_FORMAT_UBYTE2_NORM;
1291 return VERTEX_FORMAT_UBYTE2;
1292 case 3:
1293 if (pureInteger)
1294 return VERTEX_FORMAT_UBYTE3_INT;
1295 if (normalized)
1296 return VERTEX_FORMAT_UBYTE3_NORM;
1297 return VERTEX_FORMAT_UBYTE3;
1298 case 4:
1299 if (pureInteger)
1300 return VERTEX_FORMAT_UBYTE4_INT;
1301 if (normalized)
1302 return VERTEX_FORMAT_UBYTE4_NORM;
1303 return VERTEX_FORMAT_UBYTE4;
1304 default:
1305 UNREACHABLE();
1306 break;
1307 }
1308 case GL_SHORT:
1309 switch (components)
1310 {
1311 case 1:
1312 if (pureInteger)
1313 return VERTEX_FORMAT_SSHORT1_INT;
1314 if (normalized)
1315 return VERTEX_FORMAT_SSHORT1_NORM;
1316 return VERTEX_FORMAT_SSHORT1;
1317 case 2:
1318 if (pureInteger)
1319 return VERTEX_FORMAT_SSHORT2_INT;
1320 if (normalized)
1321 return VERTEX_FORMAT_SSHORT2_NORM;
1322 return VERTEX_FORMAT_SSHORT2;
1323 case 3:
1324 if (pureInteger)
1325 return VERTEX_FORMAT_SSHORT3_INT;
1326 if (normalized)
1327 return VERTEX_FORMAT_SSHORT3_NORM;
1328 return VERTEX_FORMAT_SSHORT3;
1329 case 4:
1330 if (pureInteger)
1331 return VERTEX_FORMAT_SSHORT4_INT;
1332 if (normalized)
1333 return VERTEX_FORMAT_SSHORT4_NORM;
1334 return VERTEX_FORMAT_SSHORT4;
1335 default:
1336 UNREACHABLE();
1337 break;
1338 }
1339 case GL_UNSIGNED_SHORT:
1340 switch (components)
1341 {
1342 case 1:
1343 if (pureInteger)
1344 return VERTEX_FORMAT_USHORT1_INT;
1345 if (normalized)
1346 return VERTEX_FORMAT_USHORT1_NORM;
1347 return VERTEX_FORMAT_USHORT1;
1348 case 2:
1349 if (pureInteger)
1350 return VERTEX_FORMAT_USHORT2_INT;
1351 if (normalized)
1352 return VERTEX_FORMAT_USHORT2_NORM;
1353 return VERTEX_FORMAT_USHORT2;
1354 case 3:
1355 if (pureInteger)
1356 return VERTEX_FORMAT_USHORT3_INT;
1357 if (normalized)
1358 return VERTEX_FORMAT_USHORT3_NORM;
1359 return VERTEX_FORMAT_USHORT3;
1360 case 4:
1361 if (pureInteger)
1362 return VERTEX_FORMAT_USHORT4_INT;
1363 if (normalized)
1364 return VERTEX_FORMAT_USHORT4_NORM;
1365 return VERTEX_FORMAT_USHORT4;
1366 default:
1367 UNREACHABLE();
1368 break;
1369 }
1370 case GL_INT:
1371 switch (components)
1372 {
1373 case 1:
1374 if (pureInteger)
1375 return VERTEX_FORMAT_SINT1_INT;
1376 if (normalized)
1377 return VERTEX_FORMAT_SINT1_NORM;
1378 return VERTEX_FORMAT_SINT1;
1379 case 2:
1380 if (pureInteger)
1381 return VERTEX_FORMAT_SINT2_INT;
1382 if (normalized)
1383 return VERTEX_FORMAT_SINT2_NORM;
1384 return VERTEX_FORMAT_SINT2;
1385 case 3:
1386 if (pureInteger)
1387 return VERTEX_FORMAT_SINT3_INT;
1388 if (normalized)
1389 return VERTEX_FORMAT_SINT3_NORM;
1390 return VERTEX_FORMAT_SINT3;
1391 case 4:
1392 if (pureInteger)
1393 return VERTEX_FORMAT_SINT4_INT;
1394 if (normalized)
1395 return VERTEX_FORMAT_SINT4_NORM;
1396 return VERTEX_FORMAT_SINT4;
1397 default:
1398 UNREACHABLE();
1399 break;
1400 }
1401 case GL_UNSIGNED_INT:
1402 switch (components)
1403 {
1404 case 1:
1405 if (pureInteger)
1406 return VERTEX_FORMAT_UINT1_INT;
1407 if (normalized)
1408 return VERTEX_FORMAT_UINT1_NORM;
1409 return VERTEX_FORMAT_UINT1;
1410 case 2:
1411 if (pureInteger)
1412 return VERTEX_FORMAT_UINT2_INT;
1413 if (normalized)
1414 return VERTEX_FORMAT_UINT2_NORM;
1415 return VERTEX_FORMAT_UINT2;
1416 case 3:
1417 if (pureInteger)
1418 return VERTEX_FORMAT_UINT3_INT;
1419 if (normalized)
1420 return VERTEX_FORMAT_UINT3_NORM;
1421 return VERTEX_FORMAT_UINT3;
1422 case 4:
1423 if (pureInteger)
1424 return VERTEX_FORMAT_UINT4_INT;
1425 if (normalized)
1426 return VERTEX_FORMAT_UINT4_NORM;
1427 return VERTEX_FORMAT_UINT4;
1428 default:
1429 UNREACHABLE();
1430 break;
1431 }
1432 case GL_FLOAT:
1433 switch (components)
1434 {
1435 case 1:
1436 return VERTEX_FORMAT_FLOAT1;
1437 case 2:
1438 return VERTEX_FORMAT_FLOAT2;
1439 case 3:
1440 return VERTEX_FORMAT_FLOAT3;
1441 case 4:
1442 return VERTEX_FORMAT_FLOAT4;
1443 default:
1444 UNREACHABLE();
1445 break;
1446 }
1447 case GL_HALF_FLOAT:
1448 switch (components)
1449 {
1450 case 1:
1451 return VERTEX_FORMAT_HALF1;
1452 case 2:
1453 return VERTEX_FORMAT_HALF2;
1454 case 3:
1455 return VERTEX_FORMAT_HALF3;
1456 case 4:
1457 return VERTEX_FORMAT_HALF4;
1458 default:
1459 UNREACHABLE();
1460 break;
1461 }
1462 case GL_FIXED:
1463 switch (components)
1464 {
1465 case 1:
1466 return VERTEX_FORMAT_FIXED1;
1467 case 2:
1468 return VERTEX_FORMAT_FIXED2;
1469 case 3:
1470 return VERTEX_FORMAT_FIXED3;
1471 case 4:
1472 return VERTEX_FORMAT_FIXED4;
1473 default:
1474 UNREACHABLE();
1475 break;
1476 }
1477 case GL_INT_2_10_10_10_REV:
1478 if (pureInteger)
1479 return VERTEX_FORMAT_SINT210_INT;
1480 if (normalized)
1481 return VERTEX_FORMAT_SINT210_NORM;
1482 return VERTEX_FORMAT_SINT210;
1483 case GL_UNSIGNED_INT_2_10_10_10_REV:
1484 if (pureInteger)
1485 return VERTEX_FORMAT_UINT210_INT;
1486 if (normalized)
1487 return VERTEX_FORMAT_UINT210_NORM;
1488 return VERTEX_FORMAT_UINT210;
1489 default:
1490 UNREACHABLE();
1491 break;
1492 }
1493 return VERTEX_FORMAT_UBYTE1;
1494}
1495
1496VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1497{
1498 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1499}
1500
1501VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1502{
1503 if (!attrib.enabled)
1504 {
1505 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1506 }
1507 return GetVertexFormatType(attrib);
1508}
1509
1510const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1511{
1512 switch (vertexFormatType)
1513 {
1514 case VERTEX_FORMAT_SBYTE1:
1515 {
1516 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1517 return format;
1518 }
1519 case VERTEX_FORMAT_SBYTE1_NORM:
1520 {
1521 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1522 return format;
1523 }
1524 case VERTEX_FORMAT_SBYTE2:
1525 {
1526 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1527 return format;
1528 }
1529 case VERTEX_FORMAT_SBYTE2_NORM:
1530 {
1531 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1532 return format;
1533 }
1534 case VERTEX_FORMAT_SBYTE3:
1535 {
1536 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1537 return format;
1538 }
1539 case VERTEX_FORMAT_SBYTE3_NORM:
1540 {
1541 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1542 return format;
1543 }
1544 case VERTEX_FORMAT_SBYTE4:
1545 {
1546 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1547 return format;
1548 }
1549 case VERTEX_FORMAT_SBYTE4_NORM:
1550 {
1551 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1552 return format;
1553 }
1554 case VERTEX_FORMAT_UBYTE1:
1555 {
1556 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1557 return format;
1558 }
1559 case VERTEX_FORMAT_UBYTE1_NORM:
1560 {
1561 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1562 return format;
1563 }
1564 case VERTEX_FORMAT_UBYTE2:
1565 {
1566 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1567 return format;
1568 }
1569 case VERTEX_FORMAT_UBYTE2_NORM:
1570 {
1571 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1572 return format;
1573 }
1574 case VERTEX_FORMAT_UBYTE3:
1575 {
1576 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1577 return format;
1578 }
1579 case VERTEX_FORMAT_UBYTE3_NORM:
1580 {
1581 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1582 return format;
1583 }
1584 case VERTEX_FORMAT_UBYTE4:
1585 {
1586 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1587 return format;
1588 }
1589 case VERTEX_FORMAT_UBYTE4_NORM:
1590 {
1591 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1592 return format;
1593 }
1594 case VERTEX_FORMAT_SSHORT1:
1595 {
1596 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1597 return format;
1598 }
1599 case VERTEX_FORMAT_SSHORT1_NORM:
1600 {
1601 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1602 return format;
1603 }
1604 case VERTEX_FORMAT_SSHORT2:
1605 {
1606 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1607 return format;
1608 }
1609 case VERTEX_FORMAT_SSHORT2_NORM:
1610 {
1611 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1612 return format;
1613 }
1614 case VERTEX_FORMAT_SSHORT3:
1615 {
1616 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1617 return format;
1618 }
1619 case VERTEX_FORMAT_SSHORT3_NORM:
1620 {
1621 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1622 return format;
1623 }
1624 case VERTEX_FORMAT_SSHORT4:
1625 {
1626 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1627 return format;
1628 }
1629 case VERTEX_FORMAT_SSHORT4_NORM:
1630 {
1631 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1632 return format;
1633 }
1634 case VERTEX_FORMAT_USHORT1:
1635 {
1636 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1637 return format;
1638 }
1639 case VERTEX_FORMAT_USHORT1_NORM:
1640 {
1641 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1642 return format;
1643 }
1644 case VERTEX_FORMAT_USHORT2:
1645 {
1646 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1647 return format;
1648 }
1649 case VERTEX_FORMAT_USHORT2_NORM:
1650 {
1651 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1652 return format;
1653 }
1654 case VERTEX_FORMAT_USHORT3:
1655 {
1656 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1657 return format;
1658 }
1659 case VERTEX_FORMAT_USHORT3_NORM:
1660 {
1661 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1662 return format;
1663 }
1664 case VERTEX_FORMAT_USHORT4:
1665 {
1666 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1667 return format;
1668 }
1669 case VERTEX_FORMAT_USHORT4_NORM:
1670 {
1671 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1672 return format;
1673 }
1674 case VERTEX_FORMAT_SINT1:
1675 {
1676 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1677 return format;
1678 }
1679 case VERTEX_FORMAT_SINT1_NORM:
1680 {
1681 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1682 return format;
1683 }
1684 case VERTEX_FORMAT_SINT2:
1685 {
1686 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1687 return format;
1688 }
1689 case VERTEX_FORMAT_SINT2_NORM:
1690 {
1691 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1692 return format;
1693 }
1694 case VERTEX_FORMAT_SINT3:
1695 {
1696 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1697 return format;
1698 }
1699 case VERTEX_FORMAT_SINT3_NORM:
1700 {
1701 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1702 return format;
1703 }
1704 case VERTEX_FORMAT_SINT4:
1705 {
1706 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1707 return format;
1708 }
1709 case VERTEX_FORMAT_SINT4_NORM:
1710 {
1711 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1712 return format;
1713 }
1714 case VERTEX_FORMAT_UINT1:
1715 {
1716 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1717 return format;
1718 }
1719 case VERTEX_FORMAT_UINT1_NORM:
1720 {
1721 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1722 return format;
1723 }
1724 case VERTEX_FORMAT_UINT2:
1725 {
1726 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1727 return format;
1728 }
1729 case VERTEX_FORMAT_UINT2_NORM:
1730 {
1731 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1732 return format;
1733 }
1734 case VERTEX_FORMAT_UINT3:
1735 {
1736 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1737 return format;
1738 }
1739 case VERTEX_FORMAT_UINT3_NORM:
1740 {
1741 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1742 return format;
1743 }
1744 case VERTEX_FORMAT_UINT4:
1745 {
1746 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1747 return format;
1748 }
1749 case VERTEX_FORMAT_UINT4_NORM:
1750 {
1751 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1752 return format;
1753 }
1754 case VERTEX_FORMAT_SBYTE1_INT:
1755 {
1756 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1757 return format;
1758 }
1759 case VERTEX_FORMAT_SBYTE2_INT:
1760 {
1761 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1762 return format;
1763 }
1764 case VERTEX_FORMAT_SBYTE3_INT:
1765 {
1766 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1767 return format;
1768 }
1769 case VERTEX_FORMAT_SBYTE4_INT:
1770 {
1771 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1772 return format;
1773 }
1774 case VERTEX_FORMAT_UBYTE1_INT:
1775 {
1776 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1777 return format;
1778 }
1779 case VERTEX_FORMAT_UBYTE2_INT:
1780 {
1781 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1782 return format;
1783 }
1784 case VERTEX_FORMAT_UBYTE3_INT:
1785 {
1786 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1787 return format;
1788 }
1789 case VERTEX_FORMAT_UBYTE4_INT:
1790 {
1791 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1792 return format;
1793 }
1794 case VERTEX_FORMAT_SSHORT1_INT:
1795 {
1796 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1797 return format;
1798 }
1799 case VERTEX_FORMAT_SSHORT2_INT:
1800 {
1801 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1802 return format;
1803 }
1804 case VERTEX_FORMAT_SSHORT3_INT:
1805 {
1806 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1807 return format;
1808 }
1809 case VERTEX_FORMAT_SSHORT4_INT:
1810 {
1811 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1812 return format;
1813 }
1814 case VERTEX_FORMAT_USHORT1_INT:
1815 {
1816 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1817 return format;
1818 }
1819 case VERTEX_FORMAT_USHORT2_INT:
1820 {
1821 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1822 return format;
1823 }
1824 case VERTEX_FORMAT_USHORT3_INT:
1825 {
1826 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1827 return format;
1828 }
1829 case VERTEX_FORMAT_USHORT4_INT:
1830 {
1831 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1832 return format;
1833 }
1834 case VERTEX_FORMAT_SINT1_INT:
1835 {
1836 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1837 return format;
1838 }
1839 case VERTEX_FORMAT_SINT2_INT:
1840 {
1841 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1842 return format;
1843 }
1844 case VERTEX_FORMAT_SINT3_INT:
1845 {
1846 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1847 return format;
1848 }
1849 case VERTEX_FORMAT_SINT4_INT:
1850 {
1851 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1852 return format;
1853 }
1854 case VERTEX_FORMAT_UINT1_INT:
1855 {
1856 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1857 return format;
1858 }
1859 case VERTEX_FORMAT_UINT2_INT:
1860 {
1861 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1862 return format;
1863 }
1864 case VERTEX_FORMAT_UINT3_INT:
1865 {
1866 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1867 return format;
1868 }
1869 case VERTEX_FORMAT_UINT4_INT:
1870 {
1871 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1872 return format;
1873 }
1874 case VERTEX_FORMAT_FIXED1:
1875 {
1876 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1877 return format;
1878 }
1879 case VERTEX_FORMAT_FIXED2:
1880 {
1881 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1882 return format;
1883 }
1884 case VERTEX_FORMAT_FIXED3:
1885 {
1886 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1887 return format;
1888 }
1889 case VERTEX_FORMAT_FIXED4:
1890 {
1891 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1892 return format;
1893 }
1894 case VERTEX_FORMAT_HALF1:
1895 {
1896 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1897 return format;
1898 }
1899 case VERTEX_FORMAT_HALF2:
1900 {
1901 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1902 return format;
1903 }
1904 case VERTEX_FORMAT_HALF3:
1905 {
1906 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1907 return format;
1908 }
1909 case VERTEX_FORMAT_HALF4:
1910 {
1911 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1912 return format;
1913 }
1914 case VERTEX_FORMAT_FLOAT1:
1915 {
1916 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1917 return format;
1918 }
1919 case VERTEX_FORMAT_FLOAT2:
1920 {
1921 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1922 return format;
1923 }
1924 case VERTEX_FORMAT_FLOAT3:
1925 {
1926 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1927 return format;
1928 }
1929 case VERTEX_FORMAT_FLOAT4:
1930 {
1931 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1932 return format;
1933 }
1934 case VERTEX_FORMAT_SINT210:
1935 {
1936 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1937 return format;
1938 }
1939 case VERTEX_FORMAT_UINT210:
1940 {
1941 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1942 return format;
1943 }
1944 case VERTEX_FORMAT_SINT210_NORM:
1945 {
1946 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1947 return format;
1948 }
1949 case VERTEX_FORMAT_UINT210_NORM:
1950 {
1951 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1952 return format;
1953 }
1954 case VERTEX_FORMAT_SINT210_INT:
1955 {
1956 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1957 return format;
1958 }
1959 case VERTEX_FORMAT_UINT210_INT:
1960 {
1961 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1962 return format;
1963 }
1964 default:
1965 {
1966 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1967 return format;
1968 }
1969 }
1970}
1971
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001972size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1973{
1974 switch (vertexFormatType)
1975 {
1976 case VERTEX_FORMAT_SBYTE1:
1977 case VERTEX_FORMAT_SBYTE1_NORM:
1978 case VERTEX_FORMAT_UBYTE1:
1979 case VERTEX_FORMAT_UBYTE1_NORM:
1980 case VERTEX_FORMAT_SBYTE1_INT:
1981 case VERTEX_FORMAT_UBYTE1_INT:
1982 return 1;
1983
1984 case VERTEX_FORMAT_SBYTE2:
1985 case VERTEX_FORMAT_SBYTE2_NORM:
1986 case VERTEX_FORMAT_UBYTE2:
1987 case VERTEX_FORMAT_UBYTE2_NORM:
1988 case VERTEX_FORMAT_SBYTE2_INT:
1989 case VERTEX_FORMAT_UBYTE2_INT:
1990 case VERTEX_FORMAT_SSHORT1:
1991 case VERTEX_FORMAT_SSHORT1_NORM:
1992 case VERTEX_FORMAT_USHORT1:
1993 case VERTEX_FORMAT_USHORT1_NORM:
1994 case VERTEX_FORMAT_SSHORT1_INT:
1995 case VERTEX_FORMAT_USHORT1_INT:
1996 case VERTEX_FORMAT_HALF1:
1997 return 2;
1998
1999 case VERTEX_FORMAT_SBYTE3:
2000 case VERTEX_FORMAT_SBYTE3_NORM:
2001 case VERTEX_FORMAT_UBYTE3:
2002 case VERTEX_FORMAT_UBYTE3_NORM:
2003 case VERTEX_FORMAT_SBYTE3_INT:
2004 case VERTEX_FORMAT_UBYTE3_INT:
2005 return 3;
2006
2007 case VERTEX_FORMAT_SBYTE4:
2008 case VERTEX_FORMAT_SBYTE4_NORM:
2009 case VERTEX_FORMAT_UBYTE4:
2010 case VERTEX_FORMAT_UBYTE4_NORM:
2011 case VERTEX_FORMAT_SBYTE4_INT:
2012 case VERTEX_FORMAT_UBYTE4_INT:
2013 case VERTEX_FORMAT_SSHORT2:
2014 case VERTEX_FORMAT_SSHORT2_NORM:
2015 case VERTEX_FORMAT_USHORT2:
2016 case VERTEX_FORMAT_USHORT2_NORM:
2017 case VERTEX_FORMAT_SSHORT2_INT:
2018 case VERTEX_FORMAT_USHORT2_INT:
2019 case VERTEX_FORMAT_SINT1:
2020 case VERTEX_FORMAT_SINT1_NORM:
2021 case VERTEX_FORMAT_UINT1:
2022 case VERTEX_FORMAT_UINT1_NORM:
2023 case VERTEX_FORMAT_SINT1_INT:
2024 case VERTEX_FORMAT_UINT1_INT:
2025 case VERTEX_FORMAT_HALF2:
2026 case VERTEX_FORMAT_FIXED1:
2027 case VERTEX_FORMAT_FLOAT1:
2028 case VERTEX_FORMAT_SINT210:
2029 case VERTEX_FORMAT_UINT210:
2030 case VERTEX_FORMAT_SINT210_NORM:
2031 case VERTEX_FORMAT_UINT210_NORM:
2032 case VERTEX_FORMAT_SINT210_INT:
2033 case VERTEX_FORMAT_UINT210_INT:
2034 return 4;
2035
2036 case VERTEX_FORMAT_SSHORT3:
2037 case VERTEX_FORMAT_SSHORT3_NORM:
2038 case VERTEX_FORMAT_USHORT3:
2039 case VERTEX_FORMAT_USHORT3_NORM:
2040 case VERTEX_FORMAT_SSHORT3_INT:
2041 case VERTEX_FORMAT_USHORT3_INT:
2042 case VERTEX_FORMAT_HALF3:
2043 return 6;
2044
2045 case VERTEX_FORMAT_SSHORT4:
2046 case VERTEX_FORMAT_SSHORT4_NORM:
2047 case VERTEX_FORMAT_USHORT4:
2048 case VERTEX_FORMAT_USHORT4_NORM:
2049 case VERTEX_FORMAT_SSHORT4_INT:
2050 case VERTEX_FORMAT_USHORT4_INT:
2051 case VERTEX_FORMAT_SINT2:
2052 case VERTEX_FORMAT_SINT2_NORM:
2053 case VERTEX_FORMAT_UINT2:
2054 case VERTEX_FORMAT_UINT2_NORM:
2055 case VERTEX_FORMAT_SINT2_INT:
2056 case VERTEX_FORMAT_UINT2_INT:
2057 case VERTEX_FORMAT_HALF4:
2058 case VERTEX_FORMAT_FIXED2:
2059 case VERTEX_FORMAT_FLOAT2:
2060 return 8;
2061
2062 case VERTEX_FORMAT_SINT3:
2063 case VERTEX_FORMAT_SINT3_NORM:
2064 case VERTEX_FORMAT_UINT3:
2065 case VERTEX_FORMAT_UINT3_NORM:
2066 case VERTEX_FORMAT_SINT3_INT:
2067 case VERTEX_FORMAT_UINT3_INT:
2068 case VERTEX_FORMAT_FIXED3:
2069 case VERTEX_FORMAT_FLOAT3:
2070 return 12;
2071
2072 case VERTEX_FORMAT_SINT4:
2073 case VERTEX_FORMAT_SINT4_NORM:
2074 case VERTEX_FORMAT_UINT4:
2075 case VERTEX_FORMAT_UINT4_NORM:
2076 case VERTEX_FORMAT_SINT4_INT:
2077 case VERTEX_FORMAT_UINT4_INT:
2078 case VERTEX_FORMAT_FIXED4:
2079 case VERTEX_FORMAT_FLOAT4:
2080 return 16;
2081
2082 case VERTEX_FORMAT_INVALID:
2083 default:
2084 UNREACHABLE();
2085 return 0;
2086 }
2087}
2088
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002089bool ValidES3InternalFormat(GLenum internalFormat)
2090{
2091 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2092 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2093}
2094
Jamie Madilld3dfda22015-07-06 08:28:49 -04002095VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
2096 : type(typeIn),
2097 normalized(normalizedIn),
2098 components(componentsIn),
2099 pureInteger(pureIntegerIn)
2100{
2101 // float -> !normalized
2102 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
2103}
2104
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002105}