blob: 83c271604e0d770e7fcb6a8d0006eca31e3ceb92 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
Frank Henigman95fb2a12018-05-27 20:17:05 -040020// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the
21// implementation can decide the true, sized, internal format. The ES2FormatMap determines the
22// internal format for all valid format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Geoff Langca271392017-04-05 12:30:00 -040027using InternalFormatInfoMap =
28 std::unordered_map<GLenum, std::unordered_map<GLenum, InternalFormat>>;
Jamie Madilla3944d42016-07-22 22:13:26 -040029
Jamie Madillca2ff382018-07-11 09:01:17 -040030bool CheckedMathResult(const CheckedNumeric<GLuint> &value, GLuint *resultOut)
31{
32 if (!value.IsValid())
33 {
34 return false;
35 }
36 else
37 {
38 *resultOut = value.ValueOrDie();
39 return true;
40 }
41}
Jamie Madilla3944d42016-07-22 22:13:26 -040042} // anonymous namespace
43
44FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
45{
46}
47
48FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
49{
50}
51
52bool FormatType::operator<(const FormatType &other) const
53{
54 if (format != other.format)
55 return format < other.format;
56 return type < other.type;
57}
58
Frank Henigman95fb2a12018-05-27 20:17:05 -040059Type::Type() : bytes(0), bytesShift(0), specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040060{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000061}
62
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020063static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000064{
Geoff Lang5d601382014-07-22 15:14:06 -040065 Type info;
66 info.bytes = bytes;
Frank Henigman95fb2a12018-05-27 20:17:05 -040067 GLuint i = 0;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020068 while ((1u << i) < bytes)
69 {
70 ++i;
71 }
72 info.bytesShift = i;
73 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040074 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020075 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040076}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000077
Frank Henigman95fb2a12018-05-27 20:17:05 -040078bool operator<(const Type &a, const Type &b)
Geoff Lang5d601382014-07-22 15:14:06 -040079{
80 return memcmp(&a, &b, sizeof(Type)) < 0;
81}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000083// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040084static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000085{
Geoff Lang493daf52014-07-03 13:38:44 -040086 return true;
87}
88
Geoff Langeb66a6e2016-10-31 13:06:12 -040089static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000090{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000091 return false;
92}
93
Geoff Langeb66a6e2016-10-31 13:06:12 -040094template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
95static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040096{
Geoff Langeb66a6e2016-10-31 13:06:12 -040097 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040098}
99
Geoff Langcec35902014-04-16 10:52:36 -0400100// Pointer to a boolean memeber of the Extensions struct
101typedef bool(Extensions::*ExtensionBool);
102
103// Check support for a single extension
104template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400106{
Geoff Lange4a492b2014-06-19 14:14:41 -0400107 return extensions.*bool1;
108}
109
110// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400111template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
112static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400113{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400114 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
115 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400116}
117
118// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400119template <GLuint minCoreGLMajorVersion,
120 GLuint minCoreGLMinorVersion,
121 ExtensionBool bool1,
122 ExtensionBool bool2>
123static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400124{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400125 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
126 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400127}
128
129// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400130template <GLuint minCoreGLMajorVersion,
131 GLuint minCoreGLMinorVersion,
132 ExtensionBool bool1,
133 ExtensionBool bool2>
134static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400135{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400136 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
137 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400138}
139
140// Check support for two extensions
141template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400142static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400143{
Geoff Langabce7622014-09-19 16:13:00 -0400144 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400145}
146
Geoff Lang60ad73d2015-10-23 10:08:44 -0400147// Check support for either of two extensions
148template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400149static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400150{
151 return extensions.*bool1 || extensions.*bool2;
152}
153
Yuly Novikovd0828192018-06-15 15:51:07 -0400154// R8, RG8
155static bool SizedRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500156{
Yuly Novikovd0828192018-06-15 15:51:07 -0400157 return clientVersion >= Version(3, 0) || (extensions.textureStorage && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500158}
159
Yuly Novikovd0828192018-06-15 15:51:07 -0400160// R16F, RG16F with HALF_FLOAT_OES type
161static bool SizedHalfFloatOESRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500162{
Yuly Novikovd0828192018-06-15 15:51:07 -0400163 return extensions.textureStorage && extensions.textureHalfFloat && extensions.textureRG;
Jamie Madillcd089732015-12-17 09:53:09 -0500164}
165
Yuly Novikovd0828192018-06-15 15:51:07 -0400166static bool SizedHalfFloatOESRGTextureAttachmentSupport(const Version &clientVersion,
167 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400168{
Yuly Novikovd0828192018-06-15 15:51:07 -0400169 return SizedHalfFloatOESRGSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400170}
171
Yuly Novikovd0828192018-06-15 15:51:07 -0400172// R16F, RG16F with either HALF_FLOAT_OES or HALF_FLOAT types
173static bool SizedHalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
Yuly Novikovd0828192018-06-15 15:51:07 -0400175 // HALF_FLOAT
176 if (clientVersion >= Version(3, 0))
177 {
178 return true;
179 }
180 // HALF_FLOAT_OES
181 else
182 {
183 return SizedHalfFloatOESRGSupport(clientVersion, extensions);
184 }
Jamie Madillcd089732015-12-17 09:53:09 -0500185}
186
Yuly Novikovd0828192018-06-15 15:51:07 -0400187static bool SizedHalfFloatRGTextureAttachmentSupport(const Version &clientVersion,
188 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500189{
Yuly Novikovd0828192018-06-15 15:51:07 -0400190 // HALF_FLOAT
191 if (clientVersion >= Version(3, 0))
192 {
193 return extensions.colorBufferFloat;
194 }
195 // HALF_FLOAT_OES
196 else
197 {
198 return SizedHalfFloatOESRGTextureAttachmentSupport(clientVersion, extensions);
199 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400200}
201
Yuly Novikovd0828192018-06-15 15:51:07 -0400202static bool SizedHalfFloatRGRenderbufferSupport(const Version &clientVersion,
203 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400204{
Yuly Novikovd0828192018-06-15 15:51:07 -0400205 return (clientVersion >= Version(3, 0) ||
206 (extensions.textureHalfFloat && extensions.textureRG)) &&
207 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Geoff Lang677bb6f2017-04-05 12:40:40 -0400208}
209
Yuly Novikovd0828192018-06-15 15:51:07 -0400210// RGB16F, RGBA16F with HALF_FLOAT_OES type
211static bool SizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400212{
Yuly Novikovd0828192018-06-15 15:51:07 -0400213 return extensions.textureStorage && extensions.textureHalfFloat;
214}
215
216static bool SizedHalfFloatOESTextureAttachmentSupport(const Version &clientVersion,
217 const Extensions &extensions)
218{
219 return SizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
220}
221
222// RGB16F, RGBA16F with either HALF_FLOAT_OES or HALF_FLOAT types
223static bool SizedHalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
224{
225 // HALF_FLOAT
226 if (clientVersion >= Version(3, 0))
227 {
228 return true;
229 }
230 // HALF_FLOAT_OES
231 else
232 {
233 return SizedHalfFloatOESSupport(clientVersion, extensions);
234 }
235}
236
237static bool SizedHalfFloatFilterSupport(const Version &clientVersion, const Extensions &extensions)
238{
239 // HALF_FLOAT
240 if (clientVersion >= Version(3, 0))
241 {
242 return true;
243 }
244 // HALF_FLOAT_OES
245 else
246 {
247 return extensions.textureHalfFloatLinear;
248 }
249}
250
251static bool SizedHalfFloatRGBTextureAttachmentSupport(const Version &clientVersion,
252 const Extensions &extensions)
253{
254 // HALF_FLOAT
255 if (clientVersion >= Version(3, 0))
256 {
257 // It is unclear how EXT_color_buffer_half_float applies to ES3.0 and above, however,
258 // dEQP GLES3 es3fFboColorbufferTests.cpp verifies that texture attachment of GL_RGB16F
259 // is possible, so assume that all GLES implementations support it.
260 return extensions.colorBufferHalfFloat;
261 }
262 // HALF_FLOAT_OES
263 else
264 {
265 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
266 }
267}
268
269static bool SizedHalfFloatRGBRenderbufferSupport(const Version &clientVersion,
270 const Extensions &extensions)
271{
272 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400273 extensions.colorBufferHalfFloat;
274}
275
Yuly Novikovd0828192018-06-15 15:51:07 -0400276static bool SizedHalfFloatRGBATextureAttachmentSupport(const Version &clientVersion,
277 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400278{
Yuly Novikovd0828192018-06-15 15:51:07 -0400279 // HALF_FLOAT
280 if (clientVersion >= Version(3, 0))
281 {
282 return extensions.colorBufferFloat;
283 }
284 // HALF_FLOAT_OES
285 else
286 {
287 return SizedHalfFloatOESTextureAttachmentSupport(clientVersion, extensions);
288 }
Geoff Lang677bb6f2017-04-05 12:40:40 -0400289}
290
Yuly Novikovd0828192018-06-15 15:51:07 -0400291static bool SizedHalfFloatRGBARenderbufferSupport(const Version &clientVersion,
292 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400293{
Yuly Novikovd0828192018-06-15 15:51:07 -0400294 return (clientVersion >= Version(3, 0) || extensions.textureHalfFloat) &&
295 (extensions.colorBufferFloat || extensions.colorBufferHalfFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500296}
297
Yuly Novikovd0828192018-06-15 15:51:07 -0400298// R32F, RG32F
299static bool SizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500300{
Yuly Novikovd0828192018-06-15 15:51:07 -0400301 return clientVersion >= Version(3, 0) ||
302 (extensions.textureStorage && extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500303}
304
Geoff Lang677bb6f2017-04-05 12:40:40 -0400305// RGB32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400306static bool SizedFloatRGBSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500307{
Yuly Novikovd0828192018-06-15 15:51:07 -0400308 return clientVersion >= Version(3, 0) ||
309 (extensions.textureStorage && extensions.textureFloat) || extensions.colorBufferFloatRGB;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400310}
311
312// RGBA32F
Yuly Novikovd0828192018-06-15 15:51:07 -0400313static bool SizedFloatRGBASupport(const Version &clientVersion, const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400314{
Yuly Novikovd0828192018-06-15 15:51:07 -0400315 return clientVersion >= Version(3, 0) ||
316 (extensions.textureStorage && extensions.textureFloat) ||
317 extensions.colorBufferFloatRGBA;
Geoff Lang677bb6f2017-04-05 12:40:40 -0400318}
319
Yuly Novikovd0828192018-06-15 15:51:07 -0400320static bool SizedFloatRGBATextureAttachmentSupport(const Version &clientVersion,
321 const Extensions &extensions)
Geoff Lang677bb6f2017-04-05 12:40:40 -0400322{
Yuly Novikovd0828192018-06-15 15:51:07 -0400323 return (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
Jamie Madillcd089732015-12-17 09:53:09 -0500324}
325
Geoff Lang5d601382014-07-22 15:14:06 -0400326InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400327 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400328 sized(false),
329 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400330 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400331 greenBits(0),
332 blueBits(0),
333 luminanceBits(0),
334 alphaBits(0),
335 sharedBits(0),
336 depthBits(0),
337 stencilBits(0),
338 pixelBytes(0),
339 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400340 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400341 compressedBlockWidth(0),
342 compressedBlockHeight(0),
343 format(GL_NONE),
344 type(GL_NONE),
345 componentType(GL_NONE),
346 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400347 textureSupport(NeverSupported),
Yuly Novikovf15f8862018-06-04 18:59:41 -0400348 filterSupport(NeverSupported),
349 textureAttachmentSupport(NeverSupported),
350 renderbufferSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000351{
Geoff Lang5d601382014-07-22 15:14:06 -0400352}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000353
Jamie Madillacf2f3a2017-11-21 19:22:44 -0500354InternalFormat::InternalFormat(const InternalFormat &other) = default;
355
Jamie Madilla3944d42016-07-22 22:13:26 -0400356bool InternalFormat::isLUMA() const
357{
358 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
359 (luminanceBits + alphaBits) > 0);
360}
361
Geoff Langf607c602016-09-21 11:46:48 -0400362GLenum InternalFormat::getReadPixelsFormat() const
363{
364 return format;
365}
366
Geoff Langc71ea662017-09-26 17:06:02 -0400367GLenum InternalFormat::getReadPixelsType(const Version &version) const
Geoff Langf607c602016-09-21 11:46:48 -0400368{
369 switch (type)
370 {
371 case GL_HALF_FLOAT:
Geoff Langc71ea662017-09-26 17:06:02 -0400372 case GL_HALF_FLOAT_OES:
373 if (version < Version(3, 0))
374 {
375 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type
376 // as the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
377 // OES_texture_half_float. HALF_FLOAT becomes core in ES3 and is acceptable to use
378 // as an IMPLEMENTATION_READ_TYPE.
379 return GL_HALF_FLOAT_OES;
380 }
381 else
382 {
383 return GL_HALF_FLOAT;
384 }
Geoff Langf607c602016-09-21 11:46:48 -0400385
386 default:
387 return type;
388 }
389}
390
Olli Etuaho50c562d2017-06-06 14:43:30 +0300391bool InternalFormat::isRequiredRenderbufferFormat(const Version &version) const
392{
393 // GLES 3.0.5 section 4.4.2.2:
394 // "Implementations are required to support the same internal formats for renderbuffers as the
395 // required formats for textures enumerated in section 3.8.3.1, with the exception of the color
396 // formats labelled "texture-only"."
397 if (!sized || compressed)
398 {
399 return false;
400 }
401
402 // Luma formats.
403 if (isLUMA())
404 {
405 return false;
406 }
407
408 // Depth/stencil formats.
409 if (depthBits > 0 || stencilBits > 0)
410 {
411 // GLES 2.0.25 table 4.5.
412 // GLES 3.0.5 section 3.8.3.1.
413 // GLES 3.1 table 8.14.
414
415 // Required formats in all versions.
416 switch (internalFormat)
417 {
418 case GL_DEPTH_COMPONENT16:
419 case GL_STENCIL_INDEX8:
420 // Note that STENCIL_INDEX8 is not mentioned in GLES 3.0.5 section 3.8.3.1, but it
421 // is in section 4.4.2.2.
422 return true;
423 default:
424 break;
425 }
426 if (version.major < 3)
427 {
428 return false;
429 }
430 // Required formats in GLES 3.0 and up.
431 switch (internalFormat)
432 {
433 case GL_DEPTH_COMPONENT32F:
434 case GL_DEPTH_COMPONENT24:
435 case GL_DEPTH32F_STENCIL8:
436 case GL_DEPTH24_STENCIL8:
437 return true;
438 default:
439 return false;
440 }
441 }
442
443 // RGBA formats.
444 // GLES 2.0.25 table 4.5.
445 // GLES 3.0.5 section 3.8.3.1.
446 // GLES 3.1 table 8.13.
447
448 // Required formats in all versions.
449 switch (internalFormat)
450 {
451 case GL_RGBA4:
452 case GL_RGB5_A1:
453 case GL_RGB565:
454 return true;
455 default:
456 break;
457 }
458 if (version.major < 3)
459 {
460 return false;
461 }
462
463 if (format == GL_BGRA_EXT)
464 {
465 return false;
466 }
467
468 switch (componentType)
469 {
470 case GL_SIGNED_NORMALIZED:
471 case GL_FLOAT:
472 return false;
473 case GL_UNSIGNED_INT:
474 case GL_INT:
475 // Integer RGB formats are not required renderbuffer formats.
476 if (alphaBits == 0 && blueBits != 0)
477 {
478 return false;
479 }
480 // All integer R and RG formats are required.
481 // Integer RGBA formats including RGB10_A2_UI are required.
482 return true;
483 case GL_UNSIGNED_NORMALIZED:
484 if (internalFormat == GL_SRGB8)
485 {
486 return false;
487 }
488 return true;
489 default:
490 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -0500491#if !UNREACHABLE_IS_NORETURN
Olli Etuaho50c562d2017-06-06 14:43:30 +0300492 return false;
Nico Weberb5db2b42018-02-12 15:31:56 -0500493#endif
Olli Etuaho50c562d2017-06-06 14:43:30 +0300494 }
495}
496
Geoff Langca271392017-04-05 12:30:00 -0400497Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400498{
499}
500
Geoff Langca271392017-04-05 12:30:00 -0400501Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400502{
Jamie Madilla3944d42016-07-22 22:13:26 -0400503}
504
Geoff Langca271392017-04-05 12:30:00 -0400505Format::Format(GLenum internalFormat, GLenum type)
506 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400507{
Jamie Madilla3944d42016-07-22 22:13:26 -0400508}
509
510Format::Format(const Format &other) = default;
511Format &Format::operator=(const Format &other) = default;
512
Jamie Madilla3944d42016-07-22 22:13:26 -0400513bool Format::valid() const
514{
Geoff Langca271392017-04-05 12:30:00 -0400515 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400516}
517
518// static
519bool Format::SameSized(const Format &a, const Format &b)
520{
Geoff Langca271392017-04-05 12:30:00 -0400521 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400522}
523
Kenneth Russell69382852017-07-21 16:38:44 -0400524static GLenum EquivalentBlitInternalFormat(GLenum internalformat)
525{
526 // BlitFramebuffer works if the color channels are identically
527 // sized, even if there is a swizzle (for example, blitting from a
528 // multisampled RGBA8 renderbuffer to a BGRA8 texture). This could
529 // be expanded and/or autogenerated if that is found necessary.
530 if (internalformat == GL_BGRA8_EXT)
531 return GL_RGBA8;
532 return internalformat;
533}
534
535// static
536bool Format::EquivalentForBlit(const Format &a, const Format &b)
537{
538 return (EquivalentBlitInternalFormat(a.info->sizedInternalFormat) ==
539 EquivalentBlitInternalFormat(b.info->sizedInternalFormat));
540}
541
Jamie Madilla3944d42016-07-22 22:13:26 -0400542// static
543Format Format::Invalid()
544{
Geoff Langca271392017-04-05 12:30:00 -0400545 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400546 return invalid;
547}
548
Yuly Novikovd73f8522017-01-13 17:48:57 -0500549std::ostream &operator<<(std::ostream &os, const Format &fmt)
550{
551 // TODO(ynovikov): return string representation when available
Geoff Langb0e9ddb2018-05-23 11:30:04 -0400552 return FmtHex(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500553}
554
Jamie Madilla3944d42016-07-22 22:13:26 -0400555bool InternalFormat::operator==(const InternalFormat &other) const
556{
Geoff Langca271392017-04-05 12:30:00 -0400557 // We assume all internal formats are unique if they have the same internal format and type
558 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400559}
560
561bool InternalFormat::operator!=(const InternalFormat &other) const
562{
Geoff Langca271392017-04-05 12:30:00 -0400563 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400564}
565
Geoff Langca271392017-04-05 12:30:00 -0400566void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400567{
Geoff Langca271392017-04-05 12:30:00 -0400568 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
569 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
570 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400571}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000572
Jamie Madilla3944d42016-07-22 22:13:26 -0400573void AddRGBAFormat(InternalFormatInfoMap *map,
574 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400575 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400576 GLuint red,
577 GLuint green,
578 GLuint blue,
579 GLuint alpha,
580 GLuint shared,
581 GLenum format,
582 GLenum type,
583 GLenum componentType,
584 bool srgb,
585 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400586 InternalFormat::SupportCheckFunction filterSupport,
587 InternalFormat::SupportCheckFunction textureAttachmentSupport,
588 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400589{
590 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400591 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400592 formatInfo.sized = sized;
593 formatInfo.sizedInternalFormat =
594 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Frank Henigman95fb2a12018-05-27 20:17:05 -0400595 formatInfo.redBits = red;
596 formatInfo.greenBits = green;
597 formatInfo.blueBits = blue;
598 formatInfo.alphaBits = alpha;
Geoff Lang5d601382014-07-22 15:14:06 -0400599 formatInfo.sharedBits = shared;
600 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400601 formatInfo.componentCount =
602 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Langcb8a9212018-06-28 12:30:36 -0400603 formatInfo.format = format;
604 formatInfo.type = type;
605 formatInfo.componentType = componentType;
606 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
607 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400608 formatInfo.filterSupport = filterSupport;
609 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
610 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400611
612 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400613}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614
Geoff Langca271392017-04-05 12:30:00 -0400615static void AddLUMAFormat(InternalFormatInfoMap *map,
616 GLenum internalFormat,
617 bool sized,
618 GLuint luminance,
619 GLuint alpha,
620 GLenum format,
621 GLenum type,
622 GLenum componentType,
623 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400624 InternalFormat::SupportCheckFunction filterSupport,
625 InternalFormat::SupportCheckFunction textureAttachmentSupport,
626 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400627{
628 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400629 formatInfo.internalFormat = internalFormat;
630 formatInfo.sized = sized;
631 formatInfo.sizedInternalFormat =
632 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400633 formatInfo.luminanceBits = luminance;
634 formatInfo.alphaBits = alpha;
635 formatInfo.pixelBytes = (luminance + alpha) / 8;
636 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
637 formatInfo.format = format;
638 formatInfo.type = type;
639 formatInfo.componentType = componentType;
640 formatInfo.colorEncoding = GL_LINEAR;
641 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400642 formatInfo.filterSupport = filterSupport;
643 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
644 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400645
646 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400647}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648
Jamie Madilla3944d42016-07-22 22:13:26 -0400649void AddDepthStencilFormat(InternalFormatInfoMap *map,
650 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400651 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400652 GLuint depthBits,
653 GLuint stencilBits,
654 GLuint unusedBits,
655 GLenum format,
656 GLenum type,
657 GLenum componentType,
658 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400659 InternalFormat::SupportCheckFunction filterSupport,
660 InternalFormat::SupportCheckFunction textureAttachmentSupport,
661 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400662{
663 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400664 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400665 formatInfo.sized = sized;
666 formatInfo.sizedInternalFormat =
667 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Langcb8a9212018-06-28 12:30:36 -0400668 formatInfo.depthBits = depthBits;
669 formatInfo.stencilBits = stencilBits;
670 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
671 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
672 formatInfo.format = format;
673 formatInfo.type = type;
674 formatInfo.componentType = componentType;
675 formatInfo.colorEncoding = GL_LINEAR;
676 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400677 formatInfo.filterSupport = filterSupport;
678 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
679 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400680
681 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400682}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000683
Geoff Langca271392017-04-05 12:30:00 -0400684void AddCompressedFormat(InternalFormatInfoMap *map,
685 GLenum internalFormat,
686 GLuint compressedBlockWidth,
687 GLuint compressedBlockHeight,
688 GLuint compressedBlockSize,
689 GLuint componentCount,
690 GLenum format,
691 GLenum type,
692 bool srgb,
693 InternalFormat::SupportCheckFunction textureSupport,
Yuly Novikovf15f8862018-06-04 18:59:41 -0400694 InternalFormat::SupportCheckFunction filterSupport,
695 InternalFormat::SupportCheckFunction textureAttachmentSupport,
696 InternalFormat::SupportCheckFunction renderbufferSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400697{
698 InternalFormat formatInfo;
Geoff Langcb8a9212018-06-28 12:30:36 -0400699 formatInfo.internalFormat = internalFormat;
700 formatInfo.sized = true;
701 formatInfo.sizedInternalFormat = internalFormat;
702 formatInfo.compressedBlockWidth = compressedBlockWidth;
703 formatInfo.compressedBlockHeight = compressedBlockHeight;
704 formatInfo.pixelBytes = compressedBlockSize / 8;
705 formatInfo.componentCount = componentCount;
706 formatInfo.format = format;
707 formatInfo.type = type;
708 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
709 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
710 formatInfo.compressed = true;
711 formatInfo.textureSupport = textureSupport;
Yuly Novikovf15f8862018-06-04 18:59:41 -0400712 formatInfo.filterSupport = filterSupport;
713 formatInfo.textureAttachmentSupport = textureAttachmentSupport;
714 formatInfo.renderbufferSupport = renderbufferSupport;
Geoff Langca271392017-04-05 12:30:00 -0400715
716 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400717}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000718
Yuly Novikovd0828192018-06-15 15:51:07 -0400719// Notes:
720// 1. "Texture supported" includes all the means by which texture can be created, however,
721// GL_EXT_texture_storage in ES2 is a special case, when only glTexStorage* is allowed.
722// The assumption is that ES2 validation will not check textureSupport for sized formats.
723//
724// 2. Sized half float types are a combination of GL_HALF_FLOAT and GL_HALF_FLOAT_OES support,
725// due to a limitation that only one type for sized formats is allowed.
726//
727// TODO(ynovikov): http://anglebug.com/2846 Verify support fields of BGRA, depth, stencil
728// and compressed formats. Perform texturable check as part of filterable and attachment checks.
Geoff Lange4a492b2014-06-19 14:14:41 -0400729static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000730{
731 InternalFormatInfoMap map;
732
733 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400734 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000735
Jamie Madilla3944d42016-07-22 22:13:26 -0400736 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737
Yuly Novikovd0828192018-06-15 15:51:07 -0400738 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
739 AddRGBAFormat(&map, GL_R8, true, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, SizedRGSupport, AlwaysSupported, SizedRGSupport, RequireESOrExt<3, 0, &Extensions::textureRG> );
740 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
741 AddRGBAFormat(&map, GL_RG8, true, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, SizedRGSupport, AlwaysSupported, SizedRGSupport, RequireESOrExt<3, 0, &Extensions::textureRG> );
742 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
743 AddRGBAFormat(&map, GL_RGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
744 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
745 AddRGBAFormat(&map, GL_RGB565, true, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
746 AddRGBAFormat(&map, GL_RGBA4, true, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
747 AddRGBAFormat(&map, GL_RGB5_A1, true, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireES<2, 0> );
748 AddRGBAFormat(&map, GL_RGBA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureStorage>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::textureStorage>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8> );
749 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
750 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>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> );
751 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>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
752 AddRGBAFormat(&map, GL_SRGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireES<3, 0>, AlwaysSupported, NeverSupported, NeverSupported );
753 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireES<3, 0>, AlwaysSupported, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::sRGB> );
754 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>, AlwaysSupported, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat> );
755 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>, AlwaysSupported, NeverSupported, NeverSupported );
756 AddRGBAFormat(&map, GL_R8I, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
757 AddRGBAFormat(&map, GL_R8UI, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
758 AddRGBAFormat(&map, GL_R16I, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
759 AddRGBAFormat(&map, GL_R16UI, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
760 AddRGBAFormat(&map, GL_R32I, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
761 AddRGBAFormat(&map, GL_R32UI, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
762 AddRGBAFormat(&map, GL_RG8I, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
763 AddRGBAFormat(&map, GL_RG8UI, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
764 AddRGBAFormat(&map, GL_RG16I, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
765 AddRGBAFormat(&map, GL_RG16UI, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
766 AddRGBAFormat(&map, GL_RG32I, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
767 AddRGBAFormat(&map, GL_RG32UI, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
768 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
769 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, NeverSupported );
770 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
771 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, NeverSupported );
772 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported );
773 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, NeverSupported );
774 AddRGBAFormat(&map, GL_RGBA8I, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
775 AddRGBAFormat(&map, GL_RGBA8UI, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
776 AddRGBAFormat(&map, GL_RGBA16I, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
777 AddRGBAFormat(&map, GL_RGBA16UI, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
778 AddRGBAFormat(&map, GL_RGBA32I, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
779 AddRGBAFormat(&map, GL_RGBA32UI, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, RequireES<3, 0>, RequireES<3, 0> );
Jamie Madilla3944d42016-07-22 22:13:26 -0400780
Yuly Novikovd0828192018-06-15 15:51:07 -0400781 AddRGBAFormat(&map, GL_BGRA8_EXT, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
782 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>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
783 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>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000784
Olli Etuahoceffd202018-01-08 16:39:45 +0200785 // Special format that is used for D3D textures that are used within ANGLE via the
786 // EGL_ANGLE_d3d_texture_client_buffer extension. We don't allow uploading texture images with
787 // this format, but textures in this format can be created from D3D textures, and filtering them
788 // and rendering to them is allowed.
Yuly Novikovd0828192018-06-15 15:51:07 -0400789 AddRGBAFormat(&map, GL_BGRA8_SRGB_ANGLEX, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, NeverSupported, AlwaysSupported, AlwaysSupported, AlwaysSupported );
Olli Etuahoceffd202018-01-08 16:39:45 +0200790
Jamie Madillec0b5802016-07-04 13:11:59 -0400791 // Special format which is not really supported, so always false for all supports.
Yuly Novikovd0828192018-06-15 15:51:07 -0400792 AddRGBAFormat(&map, GL_BGRX8_ANGLEX, true, 8, 8, 8, 0, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported );
793 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, NeverSupported );
Jamie Madillec0b5802016-07-04 13:11:59 -0400794
Yuly Novikovd0828192018-06-15 15:51:07 -0400795 // Floating point formats
796 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
797 // It's not possible to have two entries per sized format.
798 // E.g. for GL_RG16F, one with GL_HALF_FLOAT type and the other with GL_HALF_FLOAT_OES type.
799 // So, GL_HALF_FLOAT type formats conditions are merged with GL_HALF_FLOAT_OES type conditions.
800 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
801 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatRGSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGTextureAttachmentSupport, SizedHalfFloatRGRenderbufferSupport );
802 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBTextureAttachmentSupport, SizedHalfFloatRGBRenderbufferSupport );
803 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, SizedHalfFloatSupport, SizedHalfFloatFilterSupport, SizedHalfFloatRGBATextureAttachmentSupport, SizedHalfFloatRGBARenderbufferSupport );
804 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, SizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat>);
805 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, SizedFloatRGSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloat>, RequireExt<&Extensions::colorBufferFloat>);
806 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBSupport, RequireExt<&Extensions::textureFloatLinear>, RequireExt<&Extensions::colorBufferFloatRGB>, NeverSupported );
807 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, SizedFloatRGBASupport, RequireExt<&Extensions::textureFloatLinear>, SizedFloatRGBATextureAttachmentSupport, RequireExt<&Extensions::colorBufferFloat>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000808
809 // Depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400810 // | Internal format |sized| D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
811 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<1, 0>, RequireES<1, 0> );
812 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
813 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireES<3, 0>, RequireES<3, 0> );
814 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32> );
815 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>, AlwaysSupported, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>);
816 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>, AlwaysSupported, RequireES<3, 0>, RequireES<3, 0> );
Corentin Walleze0902642014-11-04 12:32:15 -0800817 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000818
819 // Luminance alpha formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400820 // | Internal format |sized| L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
821 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
822 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
823 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, AlwaysSupported, NeverSupported, NeverSupported);
824 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
825 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
826 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
827 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
828 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
829 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000830
831 // Compressed formats, From ES 3.0.1 spec, table 3.16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400832 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
833 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
834 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACR11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
835 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11UnsignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
836 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedEACRG11SignedTexture>, AlwaysSupported, NeverSupported, NeverSupported);
837 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
838 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
839 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughARGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
840 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2PunchthroughAsRGB8AlphaTexture>, AlwaysSupported, NeverSupported, NeverSupported);
841 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireESOrExt<3, 0, &Extensions::compressedETC2RGBA8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
842 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireESOrExt<3, 0, &Extensions::compressedETC2sRGB8Alpha8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843
844 // From GL_EXT_texture_compression_dxt1
Yuly Novikovf15f8862018-06-04 18:59:41 -0400845 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
846 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
847 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000848
849 // From GL_ANGLE_texture_compression_dxt3
Yuly Novikovf15f8862018-06-04 18:59:41 -0400850 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT3>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000851
852 // From GL_ANGLE_texture_compression_dxt5
Yuly Novikovf15f8862018-06-04 18:59:41 -0400853 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400854
855 // From GL_OES_compressed_ETC1_RGB8_texture
Yuly Novikovf15f8862018-06-04 18:59:41 -0400856 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, AlwaysSupported, NeverSupported, NeverSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000857
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800858 // From GL_EXT_texture_compression_s3tc_srgb
Yuly Novikovf15f8862018-06-04 18:59:41 -0400859 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
860 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
861 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
862 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
863 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, AlwaysSupported, NeverSupported, NeverSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800864
Geoff Lang60ad73d2015-10-23 10:08:44 -0400865 // From KHR_texture_compression_astc_hdr
Yuly Novikovf15f8862018-06-04 18:59:41 -0400866 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
867 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
868 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
869 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
870 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
871 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
872 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
873 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
874 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
875 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
876 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
877 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
878 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
879 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
880 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400881
Yuly Novikovf15f8862018-06-04 18:59:41 -0400882 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
883 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
884 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
885 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
886 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
887 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
888 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
889 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
890 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
891 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
892 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
893 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
894 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
895 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, AlwaysSupported, NeverSupported, NeverSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400896
Olli Etuahof2ed2992018-10-04 13:54:42 +0300897 // From EXT_texture_compression_bptc
898 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
899 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
900 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
901 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
902 AddCompressedFormat(&map, GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT, 4, 4, 128, 4, GL_RGB, GL_FLOAT, false, RequireExt<&Extensions::textureCompressionBPTC>, AlwaysSupported, NeverSupported, NeverSupported);
903
Corentin Walleze0902642014-11-04 12:32:15 -0800904 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
905 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
906 // - All other stencil formats (all depth-stencil) are either float or normalized
907 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400908 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
909 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported, RequireES<1, 0>, RequireES<1, 0>);
Minmin Gonge3939b92015-12-01 15:36:51 -0800910
911 // From GL_ANGLE_lossy_etc_decode
Yuly Novikovf15f8862018-06-04 18:59:41 -0400912 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
913 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
914 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
915 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
916 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
917 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800918
Vincent Lang25ab4512016-05-13 18:13:59 +0200919 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400920 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
921 AddRGBAFormat(&map, GL_R16_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
922 AddRGBAFormat(&map, GL_R16_SNORM_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
923 AddRGBAFormat(&map, GL_RG16_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
924 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
925 AddRGBAFormat(&map, GL_RGB16_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
926 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
927 AddRGBAFormat(&map, GL_RGBA16_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>);
928 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, AlwaysSupported, NeverSupported, NeverSupported );
Vincent Lang25ab4512016-05-13 18:13:59 +0200929
Geoff Langca271392017-04-05 12:30:00 -0400930 // Unsized formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400931 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
932 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, RequireExt<&Extensions::textureRG>, NeverSupported);
933 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
934 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, RequireExt<&Extensions::textureRG>, NeverSupported);
935 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
936 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
937 AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
938 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
939 AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
940 AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
941 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, AlwaysSupported, AlwaysSupported, RequireES<2, 0>, NeverSupported);
942 AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
943 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
944 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_SRGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, NeverSupported, NeverSupported);
945 AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, AlwaysSupported, RequireExt<&Extensions::sRGB>, NeverSupported);
946 AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported, RequireExt<&Extensions::textureFormatBGRA8888>, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400947
948 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400949 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
950 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
951 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, NeverSupported);
952 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
953 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, NeverSupported);
954 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
955 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, NeverSupported);
956 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
957 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, NeverSupported);
958 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
959 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, NeverSupported);
960 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
961 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, NeverSupported);
962 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
963 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, NeverSupported);
964 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
965 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, NeverSupported);
966 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
967 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, NeverSupported);
968 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
969 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, NeverSupported);
970 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
971 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, NeverSupported);
972 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported, NeverSupported);
973 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, NeverSupported);
974 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, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400975
976 // Unsized floating point formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400977 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
978 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
979 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
980 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
981 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
982 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
983 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
984 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
985 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, RequireExtAndExt<&Extensions::textureHalfFloat, &Extensions::colorBufferHalfFloat>, NeverSupported);
986 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
987 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, RequireExtAndExt<&Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
988 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
989 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, NeverSupported);
990 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, NeverSupported);
991 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -0400992
993 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400994 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
Yuly Novikovd0828192018-06-15 15:51:07 -0400995 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
996 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
997 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
Yuly Novikovf15f8862018-06-04 18:59:41 -0400998 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
999 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
1000 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
1001 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
1002 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
1003 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
Geoff Langca271392017-04-05 12:30:00 -04001004
1005 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -04001006 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
1007 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
1008 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
1009 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<1, 0>, AlwaysSupported, RequireES<1, 0>, RequireES<1, 0> );
1010 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>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>);
1011 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>, AlwaysSupported, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>);
1012 AddDepthStencilFormat(&map, GL_STENCIL, false, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<1, 0>, NeverSupported , RequireES<1, 0>, RequireES<1, 0> );
Geoff Lang9bbad182015-09-04 11:07:29 -04001013 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -08001014
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001015 return map;
1016}
1017
Geoff Lange4a492b2014-06-19 14:14:41 -04001018static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001019{
Geoff Lange4a492b2014-06-19 14:14:41 -04001020 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
1021 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001022}
1023
Geoff Lange4a492b2014-06-19 14:14:41 -04001024static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -04001025{
1026 FormatSet result;
1027
Geoff Langca271392017-04-05 12:30:00 -04001028 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -04001029 {
Geoff Langca271392017-04-05 12:30:00 -04001030 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -04001031 {
Geoff Langca271392017-04-05 12:30:00 -04001032 if (type.second.sized)
1033 {
1034 // TODO(jmadill): Fix this hack.
1035 if (internalFormat.first == GL_BGR565_ANGLEX)
1036 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -04001037
Geoff Langca271392017-04-05 12:30:00 -04001038 result.insert(internalFormat.first);
1039 }
Geoff Langcec35902014-04-16 10:52:36 -04001040 }
1041 }
1042
1043 return result;
1044}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001045
Geoff Lang5d601382014-07-22 15:14:06 -04001046const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001047{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001048 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001049 {
Frank Henigman95fb2a12018-05-27 20:17:05 -04001050 case GL_UNSIGNED_BYTE:
1051 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001052 {
1053 static const Type info = GenTypeInfo(1, false);
1054 return info;
1055 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001056 case GL_UNSIGNED_SHORT:
1057 case GL_SHORT:
1058 case GL_HALF_FLOAT:
1059 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001060 {
1061 static const Type info = GenTypeInfo(2, false);
1062 return info;
1063 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001064 case GL_UNSIGNED_INT:
1065 case GL_INT:
1066 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001067 {
1068 static const Type info = GenTypeInfo(4, false);
1069 return info;
1070 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001071 case GL_UNSIGNED_SHORT_5_6_5:
1072 case GL_UNSIGNED_SHORT_4_4_4_4:
1073 case GL_UNSIGNED_SHORT_5_5_5_1:
1074 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1075 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001076 {
1077 static const Type info = GenTypeInfo(2, true);
1078 return info;
1079 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001080 case GL_UNSIGNED_INT_2_10_10_10_REV:
1081 case GL_UNSIGNED_INT_24_8:
1082 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1083 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001084 {
1085 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1086 static const Type info = GenTypeInfo(4, true);
1087 return info;
1088 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001089 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001090 {
1091 static const Type info = GenTypeInfo(8, true);
1092 return info;
1093 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001094 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001095 {
1096 static const Type defaultInfo;
1097 return defaultInfo;
1098 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001099 }
1100}
1101
Geoff Langca271392017-04-05 12:30:00 -04001102const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001103{
Geoff Langca271392017-04-05 12:30:00 -04001104 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001105 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001106 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001107
1108 // Sized internal formats only have one type per entry
1109 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001110 {
Geoff Lang5d601382014-07-22 15:14:06 -04001111 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001112 }
Geoff Langca271392017-04-05 12:30:00 -04001113
1114 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1115 if (!internalFormatInfo.sized)
1116 {
1117 return defaultInternalFormat;
1118 }
1119
1120 return internalFormatInfo;
1121}
1122
1123const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1124{
1125 static const InternalFormat defaultInternalFormat;
1126 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1127
1128 auto internalFormatIter = formatMap.find(internalFormat);
1129 if (internalFormatIter == formatMap.end())
1130 {
1131 return defaultInternalFormat;
1132 }
1133
1134 // If the internal format is sized, simply return it without the type check.
1135 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1136 {
1137 return internalFormatIter->second.begin()->second;
1138 }
1139
1140 auto typeIter = internalFormatIter->second.find(type);
1141 if (typeIter == internalFormatIter->second.end())
1142 {
1143 return defaultInternalFormat;
1144 }
1145
1146 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001147}
1148
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001149GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1150{
1151 const auto &typeInfo = GetTypeInfo(formatType);
1152 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1153 return components * typeInfo.bytes;
1154}
1155
Jamie Madillca2ff382018-07-11 09:01:17 -04001156bool InternalFormat::computeRowPitch(GLenum formatType,
1157 GLsizei width,
1158 GLint alignment,
1159 GLint rowLength,
1160 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001161{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001162 // Compressed images do not use pack/unpack parameters.
1163 if (compressed)
1164 {
1165 ASSERT(rowLength == 0);
Jamie Madillca2ff382018-07-11 09:01:17 -04001166 return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001167 }
1168
Geoff Lang3f234062016-07-13 15:35:45 -04001169 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001170 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001171
1172 ASSERT(alignment > 0 && isPow2(alignment));
1173 CheckedNumeric<GLuint> checkedAlignment(alignment);
1174 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
Jamie Madillca2ff382018-07-11 09:01:17 -04001175 return CheckedMathResult(aligned, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001176}
1177
Jamie Madillca2ff382018-07-11 09:01:17 -04001178bool InternalFormat::computeDepthPitch(GLsizei height,
1179 GLint imageHeight,
1180 GLuint rowPitch,
1181 GLuint *resultOut) const
Corentin Wallez0e487192016-10-03 16:30:38 -04001182{
1183 GLuint rows =
1184 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1185 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1186
Jamie Madillca2ff382018-07-11 09:01:17 -04001187 return CheckedMathResult(checkedRowPitch * rows, resultOut);
Corentin Wallez0e487192016-10-03 16:30:38 -04001188}
1189
Jamie Madillca2ff382018-07-11 09:01:17 -04001190bool InternalFormat::computeDepthPitch(GLenum formatType,
1191 GLsizei width,
1192 GLsizei height,
1193 GLint alignment,
1194 GLint rowLength,
1195 GLint imageHeight,
1196 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001197{
Jamie Madille2e406c2016-06-02 13:04:10 -04001198 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001199 if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1200 {
1201 return false;
1202 }
1203 return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001204}
1205
Jamie Madillca2ff382018-07-11 09:01:17 -04001206bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001207{
Jamie Madill513558d2016-06-02 13:04:11 -04001208 CheckedNumeric<GLuint> checkedWidth(size.width);
1209 CheckedNumeric<GLuint> checkedHeight(size.height);
1210 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001211 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1212 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001213
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001214 ASSERT(compressed);
1215 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1216 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1217 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
Jamie Madillca2ff382018-07-11 09:01:17 -04001218 return CheckedMathResult(bytes, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001219}
1220
Jamie Madillca2ff382018-07-11 09:01:17 -04001221bool InternalFormat::computeSkipBytes(GLenum formatType,
1222 GLuint rowPitch,
1223 GLuint depthPitch,
1224 const PixelStoreStateBase &state,
1225 bool is3D,
1226 GLuint *resultOut) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001227{
Olli Etuaho989cac32016-06-08 16:18:49 -07001228 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1229 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001230 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1231 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1232 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001233 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001234 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001235 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001236 {
1237 checkedSkipImagesBytes = 0;
1238 }
1239 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1240 checkedSkipPixels * checkedPixelBytes;
Jamie Madillca2ff382018-07-11 09:01:17 -04001241 return CheckedMathResult(skipBytes, resultOut);
Minmin Gongadff67b2015-10-14 10:34:45 -04001242}
1243
Jamie Madillca2ff382018-07-11 09:01:17 -04001244bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1245 const Extents &size,
1246 const PixelStoreStateBase &state,
1247 bool is3D,
1248 GLuint *resultOut) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001249{
Corentin Wallez886de362016-09-27 10:49:35 -04001250 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001251 if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
Corentin Wallez0e487192016-10-03 16:30:38 -04001252 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001253 return false;
Corentin Wallez0e487192016-10-03 16:30:38 -04001254 }
1255
Jamie Madillca2ff382018-07-11 09:01:17 -04001256 GLuint depthPitch = 0;
1257 if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1258 {
1259 return false;
1260 }
1261
1262 CheckedNumeric<GLuint> checkedCopyBytes(0);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001263 if (compressed)
1264 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001265 GLuint copyBytes = 0;
1266 if (!computeCompressedImageSize(size, &copyBytes))
1267 {
1268 return false;
1269 }
1270 checkedCopyBytes = copyBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001271 }
Corentin Wallez886de362016-09-27 10:49:35 -04001272 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001273 {
Corentin Wallez886de362016-09-27 10:49:35 -04001274 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1275 checkedCopyBytes += size.width * bytes;
1276
1277 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1278 checkedCopyBytes += heightMinusOne * rowPitch;
1279
1280 if (is3D)
1281 {
1282 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1283 checkedCopyBytes += depthMinusOne * depthPitch;
1284 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001285 }
1286
Jamie Madillca2ff382018-07-11 09:01:17 -04001287 GLuint skipBytes = 0;
1288 if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1289 {
1290 return false;
1291 }
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001292
Jamie Madillca2ff382018-07-11 09:01:17 -04001293 CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001294
Jamie Madillca2ff382018-07-11 09:01:17 -04001295 return CheckedMathResult(endByte, resultOut);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001296}
1297
Geoff Langca271392017-04-05 12:30:00 -04001298GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001299{
Geoff Langca271392017-04-05 12:30:00 -04001300 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1301 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001302 {
Geoff Langca271392017-04-05 12:30:00 -04001303 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001304 }
Geoff Langca271392017-04-05 12:30:00 -04001305
1306 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001307}
1308
Geoff Lange4a492b2014-06-19 14:14:41 -04001309const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001310{
Geoff Lange4a492b2014-06-19 14:14:41 -04001311 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001312 return formatSet;
1313}
1314
Jamie Madill09e2d932015-07-14 16:40:31 -04001315AttributeType GetAttributeType(GLenum enumValue)
1316{
1317 switch (enumValue)
1318 {
1319 case GL_FLOAT:
1320 return ATTRIBUTE_FLOAT;
1321 case GL_FLOAT_VEC2:
1322 return ATTRIBUTE_VEC2;
1323 case GL_FLOAT_VEC3:
1324 return ATTRIBUTE_VEC3;
1325 case GL_FLOAT_VEC4:
1326 return ATTRIBUTE_VEC4;
1327 case GL_INT:
1328 return ATTRIBUTE_INT;
1329 case GL_INT_VEC2:
1330 return ATTRIBUTE_IVEC2;
1331 case GL_INT_VEC3:
1332 return ATTRIBUTE_IVEC3;
1333 case GL_INT_VEC4:
1334 return ATTRIBUTE_IVEC4;
1335 case GL_UNSIGNED_INT:
1336 return ATTRIBUTE_UINT;
1337 case GL_UNSIGNED_INT_VEC2:
1338 return ATTRIBUTE_UVEC2;
1339 case GL_UNSIGNED_INT_VEC3:
1340 return ATTRIBUTE_UVEC3;
1341 case GL_UNSIGNED_INT_VEC4:
1342 return ATTRIBUTE_UVEC4;
1343 case GL_FLOAT_MAT2:
1344 return ATTRIBUTE_MAT2;
1345 case GL_FLOAT_MAT3:
1346 return ATTRIBUTE_MAT3;
1347 case GL_FLOAT_MAT4:
1348 return ATTRIBUTE_MAT4;
1349 case GL_FLOAT_MAT2x3:
1350 return ATTRIBUTE_MAT2x3;
1351 case GL_FLOAT_MAT2x4:
1352 return ATTRIBUTE_MAT2x4;
1353 case GL_FLOAT_MAT3x2:
1354 return ATTRIBUTE_MAT3x2;
1355 case GL_FLOAT_MAT3x4:
1356 return ATTRIBUTE_MAT3x4;
1357 case GL_FLOAT_MAT4x2:
1358 return ATTRIBUTE_MAT4x2;
1359 case GL_FLOAT_MAT4x3:
1360 return ATTRIBUTE_MAT4x3;
1361 default:
1362 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001363#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001364 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001365#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001366 }
1367}
1368
Jamie Madillba365932018-07-18 17:23:46 -04001369angle::FormatID GetVertexFormatID(GLenum type,
1370 GLboolean normalized,
1371 GLuint components,
1372 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001373{
1374 switch (type)
1375 {
1376 case GL_BYTE:
1377 switch (components)
1378 {
1379 case 1:
1380 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001381 return angle::FormatID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001382 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001383 return angle::FormatID::R8_SNORM;
1384 return angle::FormatID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001385 case 2:
1386 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001387 return angle::FormatID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001388 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001389 return angle::FormatID::R8G8_SNORM;
1390 return angle::FormatID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001391 case 3:
1392 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001393 return angle::FormatID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001394 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001395 return angle::FormatID::R8G8B8_SNORM;
1396 return angle::FormatID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001397 case 4:
1398 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001399 return angle::FormatID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001400 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001401 return angle::FormatID::R8G8B8A8_SNORM;
1402 return angle::FormatID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001403 default:
1404 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001405#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001406 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001407#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001408 }
1409 case GL_UNSIGNED_BYTE:
1410 switch (components)
1411 {
1412 case 1:
1413 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001414 return angle::FormatID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001415 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001416 return angle::FormatID::R8_UNORM;
1417 return angle::FormatID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001418 case 2:
1419 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001420 return angle::FormatID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001421 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001422 return angle::FormatID::R8G8_UNORM;
1423 return angle::FormatID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001424 case 3:
1425 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001426 return angle::FormatID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001427 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001428 return angle::FormatID::R8G8B8_UNORM;
1429 return angle::FormatID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001430 case 4:
1431 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001432 return angle::FormatID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001433 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001434 return angle::FormatID::R8G8B8A8_UNORM;
1435 return angle::FormatID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001436 default:
1437 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001438#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001439 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001440#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001441 }
1442 case GL_SHORT:
1443 switch (components)
1444 {
1445 case 1:
1446 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001447 return angle::FormatID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001448 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001449 return angle::FormatID::R16_SNORM;
1450 return angle::FormatID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001451 case 2:
1452 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001453 return angle::FormatID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001454 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001455 return angle::FormatID::R16G16_SNORM;
1456 return angle::FormatID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001457 case 3:
1458 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001459 return angle::FormatID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001460 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001461 return angle::FormatID::R16G16B16_SNORM;
1462 return angle::FormatID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001463 case 4:
1464 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001465 return angle::FormatID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001466 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001467 return angle::FormatID::R16G16B16A16_SNORM;
1468 return angle::FormatID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001469 default:
1470 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001471#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001472 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001473#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001474 }
1475 case GL_UNSIGNED_SHORT:
1476 switch (components)
1477 {
1478 case 1:
1479 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001480 return angle::FormatID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001481 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001482 return angle::FormatID::R16_UNORM;
1483 return angle::FormatID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001484 case 2:
1485 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001486 return angle::FormatID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001487 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001488 return angle::FormatID::R16G16_UNORM;
1489 return angle::FormatID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001490 case 3:
1491 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001492 return angle::FormatID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001493 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001494 return angle::FormatID::R16G16B16_UNORM;
1495 return angle::FormatID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001496 case 4:
1497 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001498 return angle::FormatID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001499 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001500 return angle::FormatID::R16G16B16A16_UNORM;
1501 return angle::FormatID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001502 default:
1503 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001504#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001505 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001506#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001507 }
1508 case GL_INT:
1509 switch (components)
1510 {
1511 case 1:
1512 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001513 return angle::FormatID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001514 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001515 return angle::FormatID::R32_SNORM;
1516 return angle::FormatID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001517 case 2:
1518 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001519 return angle::FormatID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001520 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001521 return angle::FormatID::R32G32_SNORM;
1522 return angle::FormatID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001523 case 3:
1524 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001525 return angle::FormatID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001526 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001527 return angle::FormatID::R32G32B32_SNORM;
1528 return angle::FormatID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001529 case 4:
1530 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001531 return angle::FormatID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001532 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001533 return angle::FormatID::R32G32B32A32_SNORM;
1534 return angle::FormatID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001535 default:
1536 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001537#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001538 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001539#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001540 }
1541 case GL_UNSIGNED_INT:
1542 switch (components)
1543 {
1544 case 1:
1545 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001546 return angle::FormatID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001547 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001548 return angle::FormatID::R32_UNORM;
1549 return angle::FormatID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001550 case 2:
1551 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001552 return angle::FormatID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001553 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001554 return angle::FormatID::R32G32_UNORM;
1555 return angle::FormatID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001556 case 3:
1557 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001558 return angle::FormatID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001559 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001560 return angle::FormatID::R32G32B32_UNORM;
1561 return angle::FormatID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001562 case 4:
1563 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001564 return angle::FormatID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001565 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001566 return angle::FormatID::R32G32B32A32_UNORM;
1567 return angle::FormatID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001568 default:
1569 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001570#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001571 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001572#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001573 }
1574 case GL_FLOAT:
1575 switch (components)
1576 {
1577 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001578 return angle::FormatID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001579 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001580 return angle::FormatID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001581 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001582 return angle::FormatID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001583 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001584 return angle::FormatID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001585 default:
1586 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001587#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001588 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001589#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001590 }
1591 case GL_HALF_FLOAT:
1592 switch (components)
1593 {
1594 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001595 return angle::FormatID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001596 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001597 return angle::FormatID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001598 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001599 return angle::FormatID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001600 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001601 return angle::FormatID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001602 default:
1603 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001604#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001605 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001606#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001607 }
1608 case GL_FIXED:
1609 switch (components)
1610 {
1611 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001612 return angle::FormatID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001613 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001614 return angle::FormatID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001615 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001616 return angle::FormatID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001617 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001618 return angle::FormatID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001619 default:
1620 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001621#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001622 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001623#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001624 }
1625 case GL_INT_2_10_10_10_REV:
1626 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001627 return angle::FormatID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001628 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001629 return angle::FormatID::R10G10B10A2_SNORM;
1630 return angle::FormatID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001631 case GL_UNSIGNED_INT_2_10_10_10_REV:
1632 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001633 return angle::FormatID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001634 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001635 return angle::FormatID::R10G10B10A2_UNORM;
1636 return angle::FormatID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001637 default:
1638 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001639#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001640 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001641#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001642 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001643}
1644
Jamie Madillba365932018-07-18 17:23:46 -04001645angle::FormatID GetVertexFormatID(const VertexAttribute &attrib)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001646{
1647 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1648}
1649
Jamie Madillba365932018-07-18 17:23:46 -04001650// TODO(fjhenigman): Do away with VertexFormatType; use angle::FormatID instead. anglebug.com/2531
Frank Henigman95fb2a12018-05-27 20:17:05 -04001651VertexFormatType GetVertexFormatType(GLenum type,
1652 GLboolean normalized,
1653 GLuint components,
1654 bool pureInteger)
1655{
1656 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1657 {
Jamie Madillba365932018-07-18 17:23:46 -04001658 case angle::FormatID::R8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001659 return VERTEX_FORMAT_SBYTE1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001660 case angle::FormatID::R8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001661 return VERTEX_FORMAT_SBYTE1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001662 case angle::FormatID::R8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001663 return VERTEX_FORMAT_SBYTE1;
Jamie Madillba365932018-07-18 17:23:46 -04001664 case angle::FormatID::R8G8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001665 return VERTEX_FORMAT_SBYTE2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001666 case angle::FormatID::R8G8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001667 return VERTEX_FORMAT_SBYTE2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001668 case angle::FormatID::R8G8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001669 return VERTEX_FORMAT_SBYTE2;
Jamie Madillba365932018-07-18 17:23:46 -04001670 case angle::FormatID::R8G8B8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001671 return VERTEX_FORMAT_SBYTE3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001672 case angle::FormatID::R8G8B8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001673 return VERTEX_FORMAT_SBYTE3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001674 case angle::FormatID::R8G8B8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001675 return VERTEX_FORMAT_SBYTE3;
Jamie Madillba365932018-07-18 17:23:46 -04001676 case angle::FormatID::R8G8B8A8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001677 return VERTEX_FORMAT_SBYTE4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001678 case angle::FormatID::R8G8B8A8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001679 return VERTEX_FORMAT_SBYTE4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001680 case angle::FormatID::R8G8B8A8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001681 return VERTEX_FORMAT_SBYTE4;
Jamie Madillba365932018-07-18 17:23:46 -04001682 case angle::FormatID::R8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001683 return VERTEX_FORMAT_UBYTE1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001684 case angle::FormatID::R8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001685 return VERTEX_FORMAT_UBYTE1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001686 case angle::FormatID::R8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001687 return VERTEX_FORMAT_UBYTE1;
Jamie Madillba365932018-07-18 17:23:46 -04001688 case angle::FormatID::R8G8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001689 return VERTEX_FORMAT_UBYTE2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001690 case angle::FormatID::R8G8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001691 return VERTEX_FORMAT_UBYTE2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001692 case angle::FormatID::R8G8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001693 return VERTEX_FORMAT_UBYTE2;
Jamie Madillba365932018-07-18 17:23:46 -04001694 case angle::FormatID::R8G8B8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001695 return VERTEX_FORMAT_UBYTE3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001696 case angle::FormatID::R8G8B8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001697 return VERTEX_FORMAT_UBYTE3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001698 case angle::FormatID::R8G8B8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001699 return VERTEX_FORMAT_UBYTE3;
Jamie Madillba365932018-07-18 17:23:46 -04001700 case angle::FormatID::R8G8B8A8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001701 return VERTEX_FORMAT_UBYTE4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001702 case angle::FormatID::R8G8B8A8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001703 return VERTEX_FORMAT_UBYTE4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001704 case angle::FormatID::R8G8B8A8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001705 return VERTEX_FORMAT_UBYTE4;
Jamie Madillba365932018-07-18 17:23:46 -04001706 case angle::FormatID::R16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001707 return VERTEX_FORMAT_SSHORT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001708 case angle::FormatID::R16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001709 return VERTEX_FORMAT_SSHORT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001710 case angle::FormatID::R16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001711 return VERTEX_FORMAT_SSHORT1;
Jamie Madillba365932018-07-18 17:23:46 -04001712 case angle::FormatID::R16G16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001713 return VERTEX_FORMAT_SSHORT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001714 case angle::FormatID::R16G16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001715 return VERTEX_FORMAT_SSHORT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001716 case angle::FormatID::R16G16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001717 return VERTEX_FORMAT_SSHORT2;
Jamie Madillba365932018-07-18 17:23:46 -04001718 case angle::FormatID::R16G16B16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001719 return VERTEX_FORMAT_SSHORT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001720 case angle::FormatID::R16G16B16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001721 return VERTEX_FORMAT_SSHORT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001722 case angle::FormatID::R16G16B16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001723 return VERTEX_FORMAT_SSHORT3;
Jamie Madillba365932018-07-18 17:23:46 -04001724 case angle::FormatID::R16G16B16A16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001725 return VERTEX_FORMAT_SSHORT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001726 case angle::FormatID::R16G16B16A16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001727 return VERTEX_FORMAT_SSHORT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001728 case angle::FormatID::R16G16B16A16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001729 return VERTEX_FORMAT_SSHORT4;
Jamie Madillba365932018-07-18 17:23:46 -04001730 case angle::FormatID::R16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001731 return VERTEX_FORMAT_USHORT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001732 case angle::FormatID::R16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001733 return VERTEX_FORMAT_USHORT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001734 case angle::FormatID::R16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001735 return VERTEX_FORMAT_USHORT1;
Jamie Madillba365932018-07-18 17:23:46 -04001736 case angle::FormatID::R16G16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001737 return VERTEX_FORMAT_USHORT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001738 case angle::FormatID::R16G16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001739 return VERTEX_FORMAT_USHORT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001740 case angle::FormatID::R16G16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001741 return VERTEX_FORMAT_USHORT2;
Jamie Madillba365932018-07-18 17:23:46 -04001742 case angle::FormatID::R16G16B16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001743 return VERTEX_FORMAT_USHORT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001744 case angle::FormatID::R16G16B16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001745 return VERTEX_FORMAT_USHORT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001746 case angle::FormatID::R16G16B16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001747 return VERTEX_FORMAT_USHORT3;
Jamie Madillba365932018-07-18 17:23:46 -04001748 case angle::FormatID::R16G16B16A16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001749 return VERTEX_FORMAT_USHORT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001750 case angle::FormatID::R16G16B16A16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001751 return VERTEX_FORMAT_USHORT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001752 case angle::FormatID::R16G16B16A16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001753 return VERTEX_FORMAT_USHORT4;
Jamie Madillba365932018-07-18 17:23:46 -04001754 case angle::FormatID::R32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001755 return VERTEX_FORMAT_SINT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001756 case angle::FormatID::R32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001757 return VERTEX_FORMAT_SINT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001758 case angle::FormatID::R32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001759 return VERTEX_FORMAT_SINT1;
Jamie Madillba365932018-07-18 17:23:46 -04001760 case angle::FormatID::R32G32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001761 return VERTEX_FORMAT_SINT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001762 case angle::FormatID::R32G32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001763 return VERTEX_FORMAT_SINT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001764 case angle::FormatID::R32G32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001765 return VERTEX_FORMAT_SINT2;
Jamie Madillba365932018-07-18 17:23:46 -04001766 case angle::FormatID::R32G32B32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001767 return VERTEX_FORMAT_SINT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001768 case angle::FormatID::R32G32B32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001769 return VERTEX_FORMAT_SINT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001770 case angle::FormatID::R32G32B32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001771 return VERTEX_FORMAT_SINT3;
Jamie Madillba365932018-07-18 17:23:46 -04001772 case angle::FormatID::R32G32B32A32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001773 return VERTEX_FORMAT_SINT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001774 case angle::FormatID::R32G32B32A32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001775 return VERTEX_FORMAT_SINT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001776 case angle::FormatID::R32G32B32A32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001777 return VERTEX_FORMAT_SINT4;
Jamie Madillba365932018-07-18 17:23:46 -04001778 case angle::FormatID::R32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001779 return VERTEX_FORMAT_UINT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001780 case angle::FormatID::R32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001781 return VERTEX_FORMAT_UINT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001782 case angle::FormatID::R32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001783 return VERTEX_FORMAT_UINT1;
Jamie Madillba365932018-07-18 17:23:46 -04001784 case angle::FormatID::R32G32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001785 return VERTEX_FORMAT_UINT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001786 case angle::FormatID::R32G32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001787 return VERTEX_FORMAT_UINT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001788 case angle::FormatID::R32G32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001789 return VERTEX_FORMAT_UINT2;
Jamie Madillba365932018-07-18 17:23:46 -04001790 case angle::FormatID::R32G32B32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001791 return VERTEX_FORMAT_UINT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001792 case angle::FormatID::R32G32B32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001793 return VERTEX_FORMAT_UINT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001794 case angle::FormatID::R32G32B32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001795 return VERTEX_FORMAT_UINT3;
Jamie Madillba365932018-07-18 17:23:46 -04001796 case angle::FormatID::R32G32B32A32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001797 return VERTEX_FORMAT_UINT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001798 case angle::FormatID::R32G32B32A32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001799 return VERTEX_FORMAT_UINT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001800 case angle::FormatID::R32G32B32A32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001801 return VERTEX_FORMAT_UINT4;
Jamie Madillba365932018-07-18 17:23:46 -04001802 case angle::FormatID::R32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001803 return VERTEX_FORMAT_FLOAT1;
Jamie Madillba365932018-07-18 17:23:46 -04001804 case angle::FormatID::R32G32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001805 return VERTEX_FORMAT_FLOAT2;
Jamie Madillba365932018-07-18 17:23:46 -04001806 case angle::FormatID::R32G32B32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001807 return VERTEX_FORMAT_FLOAT3;
Jamie Madillba365932018-07-18 17:23:46 -04001808 case angle::FormatID::R32G32B32A32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001809 return VERTEX_FORMAT_FLOAT4;
Jamie Madillba365932018-07-18 17:23:46 -04001810 case angle::FormatID::R16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001811 return VERTEX_FORMAT_HALF1;
Jamie Madillba365932018-07-18 17:23:46 -04001812 case angle::FormatID::R16G16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001813 return VERTEX_FORMAT_HALF2;
Jamie Madillba365932018-07-18 17:23:46 -04001814 case angle::FormatID::R16G16B16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001815 return VERTEX_FORMAT_HALF3;
Jamie Madillba365932018-07-18 17:23:46 -04001816 case angle::FormatID::R16G16B16A16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001817 return VERTEX_FORMAT_HALF4;
Jamie Madillba365932018-07-18 17:23:46 -04001818 case angle::FormatID::R32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001819 return VERTEX_FORMAT_FIXED1;
Jamie Madillba365932018-07-18 17:23:46 -04001820 case angle::FormatID::R32G32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001821 return VERTEX_FORMAT_FIXED2;
Jamie Madillba365932018-07-18 17:23:46 -04001822 case angle::FormatID::R32G32B32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001823 return VERTEX_FORMAT_FIXED3;
Jamie Madillba365932018-07-18 17:23:46 -04001824 case angle::FormatID::R32G32B32A32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001825 return VERTEX_FORMAT_FIXED4;
Jamie Madillba365932018-07-18 17:23:46 -04001826 case angle::FormatID::R10G10B10A2_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001827 return VERTEX_FORMAT_SINT210_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001828 case angle::FormatID::R10G10B10A2_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001829 return VERTEX_FORMAT_SINT210_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001830 case angle::FormatID::R10G10B10A2_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001831 return VERTEX_FORMAT_SINT210;
Jamie Madillba365932018-07-18 17:23:46 -04001832 case angle::FormatID::R10G10B10A2_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001833 return VERTEX_FORMAT_UINT210_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001834 case angle::FormatID::R10G10B10A2_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001835 return VERTEX_FORMAT_UINT210_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001836 case angle::FormatID::R10G10B10A2_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001837 return VERTEX_FORMAT_UINT210;
1838 default:
1839 return VERTEX_FORMAT_INVALID;
1840 }
1841}
1842
Jamie Madilld3dfda22015-07-06 08:28:49 -04001843VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1844{
1845 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1846}
1847
1848VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1849{
1850 if (!attrib.enabled)
1851 {
1852 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1853 }
1854 return GetVertexFormatType(attrib);
1855}
1856
1857const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1858{
1859 switch (vertexFormatType)
1860 {
1861 case VERTEX_FORMAT_SBYTE1:
1862 {
1863 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1864 return format;
1865 }
1866 case VERTEX_FORMAT_SBYTE1_NORM:
1867 {
1868 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1869 return format;
1870 }
1871 case VERTEX_FORMAT_SBYTE2:
1872 {
1873 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1874 return format;
1875 }
1876 case VERTEX_FORMAT_SBYTE2_NORM:
1877 {
1878 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1879 return format;
1880 }
1881 case VERTEX_FORMAT_SBYTE3:
1882 {
1883 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1884 return format;
1885 }
1886 case VERTEX_FORMAT_SBYTE3_NORM:
1887 {
1888 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1889 return format;
1890 }
1891 case VERTEX_FORMAT_SBYTE4:
1892 {
1893 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1894 return format;
1895 }
1896 case VERTEX_FORMAT_SBYTE4_NORM:
1897 {
1898 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1899 return format;
1900 }
1901 case VERTEX_FORMAT_UBYTE1:
1902 {
1903 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1904 return format;
1905 }
1906 case VERTEX_FORMAT_UBYTE1_NORM:
1907 {
1908 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1909 return format;
1910 }
1911 case VERTEX_FORMAT_UBYTE2:
1912 {
1913 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1914 return format;
1915 }
1916 case VERTEX_FORMAT_UBYTE2_NORM:
1917 {
1918 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1919 return format;
1920 }
1921 case VERTEX_FORMAT_UBYTE3:
1922 {
1923 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1924 return format;
1925 }
1926 case VERTEX_FORMAT_UBYTE3_NORM:
1927 {
1928 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1929 return format;
1930 }
1931 case VERTEX_FORMAT_UBYTE4:
1932 {
1933 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1934 return format;
1935 }
1936 case VERTEX_FORMAT_UBYTE4_NORM:
1937 {
1938 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1939 return format;
1940 }
1941 case VERTEX_FORMAT_SSHORT1:
1942 {
1943 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1944 return format;
1945 }
1946 case VERTEX_FORMAT_SSHORT1_NORM:
1947 {
1948 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1949 return format;
1950 }
1951 case VERTEX_FORMAT_SSHORT2:
1952 {
1953 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1954 return format;
1955 }
1956 case VERTEX_FORMAT_SSHORT2_NORM:
1957 {
1958 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1959 return format;
1960 }
1961 case VERTEX_FORMAT_SSHORT3:
1962 {
1963 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1964 return format;
1965 }
1966 case VERTEX_FORMAT_SSHORT3_NORM:
1967 {
1968 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1969 return format;
1970 }
1971 case VERTEX_FORMAT_SSHORT4:
1972 {
1973 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1974 return format;
1975 }
1976 case VERTEX_FORMAT_SSHORT4_NORM:
1977 {
1978 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1979 return format;
1980 }
1981 case VERTEX_FORMAT_USHORT1:
1982 {
1983 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1984 return format;
1985 }
1986 case VERTEX_FORMAT_USHORT1_NORM:
1987 {
1988 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1989 return format;
1990 }
1991 case VERTEX_FORMAT_USHORT2:
1992 {
1993 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1994 return format;
1995 }
1996 case VERTEX_FORMAT_USHORT2_NORM:
1997 {
1998 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1999 return format;
2000 }
2001 case VERTEX_FORMAT_USHORT3:
2002 {
2003 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
2004 return format;
2005 }
2006 case VERTEX_FORMAT_USHORT3_NORM:
2007 {
2008 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
2009 return format;
2010 }
2011 case VERTEX_FORMAT_USHORT4:
2012 {
2013 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
2014 return format;
2015 }
2016 case VERTEX_FORMAT_USHORT4_NORM:
2017 {
2018 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
2019 return format;
2020 }
2021 case VERTEX_FORMAT_SINT1:
2022 {
2023 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
2024 return format;
2025 }
2026 case VERTEX_FORMAT_SINT1_NORM:
2027 {
2028 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
2029 return format;
2030 }
2031 case VERTEX_FORMAT_SINT2:
2032 {
2033 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
2034 return format;
2035 }
2036 case VERTEX_FORMAT_SINT2_NORM:
2037 {
2038 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
2039 return format;
2040 }
2041 case VERTEX_FORMAT_SINT3:
2042 {
2043 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
2044 return format;
2045 }
2046 case VERTEX_FORMAT_SINT3_NORM:
2047 {
2048 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
2049 return format;
2050 }
2051 case VERTEX_FORMAT_SINT4:
2052 {
2053 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
2054 return format;
2055 }
2056 case VERTEX_FORMAT_SINT4_NORM:
2057 {
2058 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
2059 return format;
2060 }
2061 case VERTEX_FORMAT_UINT1:
2062 {
2063 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2064 return format;
2065 }
2066 case VERTEX_FORMAT_UINT1_NORM:
2067 {
2068 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2069 return format;
2070 }
2071 case VERTEX_FORMAT_UINT2:
2072 {
2073 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2074 return format;
2075 }
2076 case VERTEX_FORMAT_UINT2_NORM:
2077 {
2078 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2079 return format;
2080 }
2081 case VERTEX_FORMAT_UINT3:
2082 {
2083 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2084 return format;
2085 }
2086 case VERTEX_FORMAT_UINT3_NORM:
2087 {
2088 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2089 return format;
2090 }
2091 case VERTEX_FORMAT_UINT4:
2092 {
2093 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2094 return format;
2095 }
2096 case VERTEX_FORMAT_UINT4_NORM:
2097 {
2098 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2099 return format;
2100 }
2101 case VERTEX_FORMAT_SBYTE1_INT:
2102 {
2103 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2104 return format;
2105 }
2106 case VERTEX_FORMAT_SBYTE2_INT:
2107 {
2108 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2109 return format;
2110 }
2111 case VERTEX_FORMAT_SBYTE3_INT:
2112 {
2113 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2114 return format;
2115 }
2116 case VERTEX_FORMAT_SBYTE4_INT:
2117 {
2118 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2119 return format;
2120 }
2121 case VERTEX_FORMAT_UBYTE1_INT:
2122 {
2123 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2124 return format;
2125 }
2126 case VERTEX_FORMAT_UBYTE2_INT:
2127 {
2128 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2129 return format;
2130 }
2131 case VERTEX_FORMAT_UBYTE3_INT:
2132 {
2133 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2134 return format;
2135 }
2136 case VERTEX_FORMAT_UBYTE4_INT:
2137 {
2138 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2139 return format;
2140 }
2141 case VERTEX_FORMAT_SSHORT1_INT:
2142 {
2143 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2144 return format;
2145 }
2146 case VERTEX_FORMAT_SSHORT2_INT:
2147 {
2148 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2149 return format;
2150 }
2151 case VERTEX_FORMAT_SSHORT3_INT:
2152 {
2153 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2154 return format;
2155 }
2156 case VERTEX_FORMAT_SSHORT4_INT:
2157 {
2158 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2159 return format;
2160 }
2161 case VERTEX_FORMAT_USHORT1_INT:
2162 {
2163 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2164 return format;
2165 }
2166 case VERTEX_FORMAT_USHORT2_INT:
2167 {
2168 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2169 return format;
2170 }
2171 case VERTEX_FORMAT_USHORT3_INT:
2172 {
2173 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2174 return format;
2175 }
2176 case VERTEX_FORMAT_USHORT4_INT:
2177 {
2178 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2179 return format;
2180 }
2181 case VERTEX_FORMAT_SINT1_INT:
2182 {
2183 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2184 return format;
2185 }
2186 case VERTEX_FORMAT_SINT2_INT:
2187 {
2188 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2189 return format;
2190 }
2191 case VERTEX_FORMAT_SINT3_INT:
2192 {
2193 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2194 return format;
2195 }
2196 case VERTEX_FORMAT_SINT4_INT:
2197 {
2198 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2199 return format;
2200 }
2201 case VERTEX_FORMAT_UINT1_INT:
2202 {
2203 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2204 return format;
2205 }
2206 case VERTEX_FORMAT_UINT2_INT:
2207 {
2208 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2209 return format;
2210 }
2211 case VERTEX_FORMAT_UINT3_INT:
2212 {
2213 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2214 return format;
2215 }
2216 case VERTEX_FORMAT_UINT4_INT:
2217 {
2218 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2219 return format;
2220 }
2221 case VERTEX_FORMAT_FIXED1:
2222 {
2223 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2224 return format;
2225 }
2226 case VERTEX_FORMAT_FIXED2:
2227 {
2228 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2229 return format;
2230 }
2231 case VERTEX_FORMAT_FIXED3:
2232 {
2233 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2234 return format;
2235 }
2236 case VERTEX_FORMAT_FIXED4:
2237 {
2238 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2239 return format;
2240 }
2241 case VERTEX_FORMAT_HALF1:
2242 {
2243 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2244 return format;
2245 }
2246 case VERTEX_FORMAT_HALF2:
2247 {
2248 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2249 return format;
2250 }
2251 case VERTEX_FORMAT_HALF3:
2252 {
2253 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2254 return format;
2255 }
2256 case VERTEX_FORMAT_HALF4:
2257 {
2258 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2259 return format;
2260 }
2261 case VERTEX_FORMAT_FLOAT1:
2262 {
2263 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2264 return format;
2265 }
2266 case VERTEX_FORMAT_FLOAT2:
2267 {
2268 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2269 return format;
2270 }
2271 case VERTEX_FORMAT_FLOAT3:
2272 {
2273 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2274 return format;
2275 }
2276 case VERTEX_FORMAT_FLOAT4:
2277 {
2278 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2279 return format;
2280 }
2281 case VERTEX_FORMAT_SINT210:
2282 {
2283 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2284 return format;
2285 }
2286 case VERTEX_FORMAT_UINT210:
2287 {
2288 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2289 return format;
2290 }
2291 case VERTEX_FORMAT_SINT210_NORM:
2292 {
2293 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2294 return format;
2295 }
2296 case VERTEX_FORMAT_UINT210_NORM:
2297 {
2298 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2299 return format;
2300 }
2301 case VERTEX_FORMAT_SINT210_INT:
2302 {
2303 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2304 return format;
2305 }
2306 case VERTEX_FORMAT_UINT210_INT:
2307 {
2308 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2309 return format;
2310 }
2311 default:
2312 {
2313 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2314 return format;
2315 }
2316 }
2317}
2318
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002319size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2320{
2321 switch (vertexFormatType)
2322 {
2323 case VERTEX_FORMAT_SBYTE1:
2324 case VERTEX_FORMAT_SBYTE1_NORM:
2325 case VERTEX_FORMAT_UBYTE1:
2326 case VERTEX_FORMAT_UBYTE1_NORM:
2327 case VERTEX_FORMAT_SBYTE1_INT:
2328 case VERTEX_FORMAT_UBYTE1_INT:
2329 return 1;
2330
2331 case VERTEX_FORMAT_SBYTE2:
2332 case VERTEX_FORMAT_SBYTE2_NORM:
2333 case VERTEX_FORMAT_UBYTE2:
2334 case VERTEX_FORMAT_UBYTE2_NORM:
2335 case VERTEX_FORMAT_SBYTE2_INT:
2336 case VERTEX_FORMAT_UBYTE2_INT:
2337 case VERTEX_FORMAT_SSHORT1:
2338 case VERTEX_FORMAT_SSHORT1_NORM:
2339 case VERTEX_FORMAT_USHORT1:
2340 case VERTEX_FORMAT_USHORT1_NORM:
2341 case VERTEX_FORMAT_SSHORT1_INT:
2342 case VERTEX_FORMAT_USHORT1_INT:
2343 case VERTEX_FORMAT_HALF1:
2344 return 2;
2345
2346 case VERTEX_FORMAT_SBYTE3:
2347 case VERTEX_FORMAT_SBYTE3_NORM:
2348 case VERTEX_FORMAT_UBYTE3:
2349 case VERTEX_FORMAT_UBYTE3_NORM:
2350 case VERTEX_FORMAT_SBYTE3_INT:
2351 case VERTEX_FORMAT_UBYTE3_INT:
2352 return 3;
2353
2354 case VERTEX_FORMAT_SBYTE4:
2355 case VERTEX_FORMAT_SBYTE4_NORM:
2356 case VERTEX_FORMAT_UBYTE4:
2357 case VERTEX_FORMAT_UBYTE4_NORM:
2358 case VERTEX_FORMAT_SBYTE4_INT:
2359 case VERTEX_FORMAT_UBYTE4_INT:
2360 case VERTEX_FORMAT_SSHORT2:
2361 case VERTEX_FORMAT_SSHORT2_NORM:
2362 case VERTEX_FORMAT_USHORT2:
2363 case VERTEX_FORMAT_USHORT2_NORM:
2364 case VERTEX_FORMAT_SSHORT2_INT:
2365 case VERTEX_FORMAT_USHORT2_INT:
2366 case VERTEX_FORMAT_SINT1:
2367 case VERTEX_FORMAT_SINT1_NORM:
2368 case VERTEX_FORMAT_UINT1:
2369 case VERTEX_FORMAT_UINT1_NORM:
2370 case VERTEX_FORMAT_SINT1_INT:
2371 case VERTEX_FORMAT_UINT1_INT:
2372 case VERTEX_FORMAT_HALF2:
2373 case VERTEX_FORMAT_FIXED1:
2374 case VERTEX_FORMAT_FLOAT1:
2375 case VERTEX_FORMAT_SINT210:
2376 case VERTEX_FORMAT_UINT210:
2377 case VERTEX_FORMAT_SINT210_NORM:
2378 case VERTEX_FORMAT_UINT210_NORM:
2379 case VERTEX_FORMAT_SINT210_INT:
2380 case VERTEX_FORMAT_UINT210_INT:
2381 return 4;
2382
2383 case VERTEX_FORMAT_SSHORT3:
2384 case VERTEX_FORMAT_SSHORT3_NORM:
2385 case VERTEX_FORMAT_USHORT3:
2386 case VERTEX_FORMAT_USHORT3_NORM:
2387 case VERTEX_FORMAT_SSHORT3_INT:
2388 case VERTEX_FORMAT_USHORT3_INT:
2389 case VERTEX_FORMAT_HALF3:
2390 return 6;
2391
2392 case VERTEX_FORMAT_SSHORT4:
2393 case VERTEX_FORMAT_SSHORT4_NORM:
2394 case VERTEX_FORMAT_USHORT4:
2395 case VERTEX_FORMAT_USHORT4_NORM:
2396 case VERTEX_FORMAT_SSHORT4_INT:
2397 case VERTEX_FORMAT_USHORT4_INT:
2398 case VERTEX_FORMAT_SINT2:
2399 case VERTEX_FORMAT_SINT2_NORM:
2400 case VERTEX_FORMAT_UINT2:
2401 case VERTEX_FORMAT_UINT2_NORM:
2402 case VERTEX_FORMAT_SINT2_INT:
2403 case VERTEX_FORMAT_UINT2_INT:
2404 case VERTEX_FORMAT_HALF4:
2405 case VERTEX_FORMAT_FIXED2:
2406 case VERTEX_FORMAT_FLOAT2:
2407 return 8;
2408
2409 case VERTEX_FORMAT_SINT3:
2410 case VERTEX_FORMAT_SINT3_NORM:
2411 case VERTEX_FORMAT_UINT3:
2412 case VERTEX_FORMAT_UINT3_NORM:
2413 case VERTEX_FORMAT_SINT3_INT:
2414 case VERTEX_FORMAT_UINT3_INT:
2415 case VERTEX_FORMAT_FIXED3:
2416 case VERTEX_FORMAT_FLOAT3:
2417 return 12;
2418
2419 case VERTEX_FORMAT_SINT4:
2420 case VERTEX_FORMAT_SINT4_NORM:
2421 case VERTEX_FORMAT_UINT4:
2422 case VERTEX_FORMAT_UINT4_NORM:
2423 case VERTEX_FORMAT_SINT4_INT:
2424 case VERTEX_FORMAT_UINT4_INT:
2425 case VERTEX_FORMAT_FIXED4:
2426 case VERTEX_FORMAT_FLOAT4:
2427 return 16;
2428
2429 case VERTEX_FORMAT_INVALID:
2430 default:
2431 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002432#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002433 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002434#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002435 }
2436}
2437
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002438bool ValidES3InternalFormat(GLenum internalFormat)
2439{
2440 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2441 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2442}
2443
Frank Henigman95fb2a12018-05-27 20:17:05 -04002444VertexFormat::VertexFormat(GLenum typeIn,
2445 GLboolean normalizedIn,
2446 GLuint componentsIn,
2447 bool pureIntegerIn)
2448 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002449{
2450 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002451 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2452 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002453}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002454}