blob: 1ba6ec2a06e70f6dcd2a0fc57f910e02c173ad22 [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
Corentin Walleze0902642014-11-04 12:32:15 -0800897 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
898 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
899 // - All other stencil formats (all depth-stencil) are either float or normalized
900 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Yuly Novikovf15f8862018-06-04 18:59:41 -0400901 // | Internal format |sized|D |S |X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
902 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 -0800903
904 // From GL_ANGLE_lossy_etc_decode
Yuly Novikovf15f8862018-06-04 18:59:41 -0400905 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
906 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, AlwaysSupported, NeverSupported, NeverSupported);
907 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);
908 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);
909 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);
910 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 -0800911
Vincent Lang25ab4512016-05-13 18:13:59 +0200912 // From GL_EXT_texture_norm16
Yuly Novikovf15f8862018-06-04 18:59:41 -0400913 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
914 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>);
915 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 );
916 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>);
917 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 );
918 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 );
919 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 );
920 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>);
921 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 +0200922
Geoff Langca271392017-04-05 12:30:00 -0400923 // Unsized formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400924 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
925 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);
926 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
927 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);
928 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
929 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);
930 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);
931 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
932 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);
933 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);
934 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);
935 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);
936 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
937 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);
938 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);
939 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 -0400940
941 // Unsized integer formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400942 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
943 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);
944 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);
945 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);
946 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);
947 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);
948 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);
949 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);
950 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);
951 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);
952 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);
953 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);
954 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);
955 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);
956 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);
957 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);
958 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);
959 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);
960 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);
961 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);
962 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);
963 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);
964 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);
965 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);
966 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);
967 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 -0400968
969 // Unsized floating point formats
Yuly Novikovd0828192018-06-15 15:51:07 -0400970 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Filterable | Texture attachment | Renderbuffer |
971 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
972 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
973 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
974 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported, NeverSupported);
975 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);
976 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);
977 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);
978 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);
979 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);
980 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);
981 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);
982 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);
983 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);
984 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 -0400985
986 // Unsized luminance alpha formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400987 // | Internal format |sized | L | A | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
Yuly Novikovd0828192018-06-15 15:51:07 -0400988 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
989 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, AlwaysSupported, AlwaysSupported, NeverSupported, NeverSupported);
990 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 -0400991 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
992 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>, NeverSupported, NeverSupported);
993 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);
994 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
995 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear>, NeverSupported, NeverSupported);
996 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 -0400997
998 // Unsized depth stencil formats
Yuly Novikovf15f8862018-06-04 18:59:41 -0400999 // | Internal format |sized | D |S | X | Format | Type | Component type | Texture supported | Filterable | Texture attachment | Renderbuffer |
1000 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> );
1001 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> );
1002 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> );
1003 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>);
1004 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>);
1005 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 -04001006 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -08001007
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001008 return map;
1009}
1010
Geoff Lange4a492b2014-06-19 14:14:41 -04001011static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001012{
Geoff Lange4a492b2014-06-19 14:14:41 -04001013 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
1014 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001015}
1016
Geoff Lange4a492b2014-06-19 14:14:41 -04001017static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -04001018{
1019 FormatSet result;
1020
Geoff Langca271392017-04-05 12:30:00 -04001021 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -04001022 {
Geoff Langca271392017-04-05 12:30:00 -04001023 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -04001024 {
Geoff Langca271392017-04-05 12:30:00 -04001025 if (type.second.sized)
1026 {
1027 // TODO(jmadill): Fix this hack.
1028 if (internalFormat.first == GL_BGR565_ANGLEX)
1029 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -04001030
Geoff Langca271392017-04-05 12:30:00 -04001031 result.insert(internalFormat.first);
1032 }
Geoff Langcec35902014-04-16 10:52:36 -04001033 }
1034 }
1035
1036 return result;
1037}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001038
Geoff Lang5d601382014-07-22 15:14:06 -04001039const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001040{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001041 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001042 {
Frank Henigman95fb2a12018-05-27 20:17:05 -04001043 case GL_UNSIGNED_BYTE:
1044 case GL_BYTE:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001045 {
1046 static const Type info = GenTypeInfo(1, false);
1047 return info;
1048 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001049 case GL_UNSIGNED_SHORT:
1050 case GL_SHORT:
1051 case GL_HALF_FLOAT:
1052 case GL_HALF_FLOAT_OES:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001053 {
1054 static const Type info = GenTypeInfo(2, false);
1055 return info;
1056 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001057 case GL_UNSIGNED_INT:
1058 case GL_INT:
1059 case GL_FLOAT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001060 {
1061 static const Type info = GenTypeInfo(4, false);
1062 return info;
1063 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001064 case GL_UNSIGNED_SHORT_5_6_5:
1065 case GL_UNSIGNED_SHORT_4_4_4_4:
1066 case GL_UNSIGNED_SHORT_5_5_5_1:
1067 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
1068 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001069 {
1070 static const Type info = GenTypeInfo(2, true);
1071 return info;
1072 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001073 case GL_UNSIGNED_INT_2_10_10_10_REV:
1074 case GL_UNSIGNED_INT_24_8:
1075 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1076 case GL_UNSIGNED_INT_5_9_9_9_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001077 {
1078 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
1079 static const Type info = GenTypeInfo(4, true);
1080 return info;
1081 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001082 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001083 {
1084 static const Type info = GenTypeInfo(8, true);
1085 return info;
1086 }
Frank Henigman95fb2a12018-05-27 20:17:05 -04001087 default:
Olli Etuaho31f8f4f2015-03-25 16:03:57 +02001088 {
1089 static const Type defaultInfo;
1090 return defaultInfo;
1091 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001092 }
1093}
1094
Geoff Langca271392017-04-05 12:30:00 -04001095const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001096{
Geoff Langca271392017-04-05 12:30:00 -04001097 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -04001098 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -04001099 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -04001100
1101 // Sized internal formats only have one type per entry
1102 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001103 {
Geoff Lang5d601382014-07-22 15:14:06 -04001104 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001105 }
Geoff Langca271392017-04-05 12:30:00 -04001106
1107 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
1108 if (!internalFormatInfo.sized)
1109 {
1110 return defaultInternalFormat;
1111 }
1112
1113 return internalFormatInfo;
1114}
1115
1116const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
1117{
1118 static const InternalFormat defaultInternalFormat;
1119 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1120
1121 auto internalFormatIter = formatMap.find(internalFormat);
1122 if (internalFormatIter == formatMap.end())
1123 {
1124 return defaultInternalFormat;
1125 }
1126
1127 // If the internal format is sized, simply return it without the type check.
1128 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
1129 {
1130 return internalFormatIter->second.begin()->second;
1131 }
1132
1133 auto typeIter = internalFormatIter->second.find(type);
1134 if (typeIter == internalFormatIter->second.end())
1135 {
1136 return defaultInternalFormat;
1137 }
1138
1139 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001140}
1141
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001142GLuint InternalFormat::computePixelBytes(GLenum formatType) const
1143{
1144 const auto &typeInfo = GetTypeInfo(formatType);
1145 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
1146 return components * typeInfo.bytes;
1147}
1148
Jamie Madillca2ff382018-07-11 09:01:17 -04001149bool InternalFormat::computeRowPitch(GLenum formatType,
1150 GLsizei width,
1151 GLint alignment,
1152 GLint rowLength,
1153 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001154{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001155 // Compressed images do not use pack/unpack parameters.
1156 if (compressed)
1157 {
1158 ASSERT(rowLength == 0);
Jamie Madillca2ff382018-07-11 09:01:17 -04001159 return computeCompressedImageSize(Extents(width, 1, 1), resultOut);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001160 }
1161
Geoff Lang3f234062016-07-13 15:35:45 -04001162 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001163 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001164
1165 ASSERT(alignment > 0 && isPow2(alignment));
1166 CheckedNumeric<GLuint> checkedAlignment(alignment);
1167 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
Jamie Madillca2ff382018-07-11 09:01:17 -04001168 return CheckedMathResult(aligned, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001169}
1170
Jamie Madillca2ff382018-07-11 09:01:17 -04001171bool InternalFormat::computeDepthPitch(GLsizei height,
1172 GLint imageHeight,
1173 GLuint rowPitch,
1174 GLuint *resultOut) const
Corentin Wallez0e487192016-10-03 16:30:38 -04001175{
1176 GLuint rows =
1177 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
1178 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1179
Jamie Madillca2ff382018-07-11 09:01:17 -04001180 return CheckedMathResult(checkedRowPitch * rows, resultOut);
Corentin Wallez0e487192016-10-03 16:30:38 -04001181}
1182
Jamie Madillca2ff382018-07-11 09:01:17 -04001183bool InternalFormat::computeDepthPitch(GLenum formatType,
1184 GLsizei width,
1185 GLsizei height,
1186 GLint alignment,
1187 GLint rowLength,
1188 GLint imageHeight,
1189 GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001190{
Jamie Madille2e406c2016-06-02 13:04:10 -04001191 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001192 if (!computeRowPitch(formatType, width, alignment, rowLength, &rowPitch))
1193 {
1194 return false;
1195 }
1196 return computeDepthPitch(height, imageHeight, rowPitch, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001197}
1198
Jamie Madillca2ff382018-07-11 09:01:17 -04001199bool InternalFormat::computeCompressedImageSize(const Extents &size, GLuint *resultOut) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001200{
Jamie Madill513558d2016-06-02 13:04:11 -04001201 CheckedNumeric<GLuint> checkedWidth(size.width);
1202 CheckedNumeric<GLuint> checkedHeight(size.height);
1203 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001204 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
1205 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -04001206
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001207 ASSERT(compressed);
1208 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
1209 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
1210 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
Jamie Madillca2ff382018-07-11 09:01:17 -04001211 return CheckedMathResult(bytes, resultOut);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001212}
1213
Jamie Madillca2ff382018-07-11 09:01:17 -04001214bool InternalFormat::computeSkipBytes(GLenum formatType,
1215 GLuint rowPitch,
1216 GLuint depthPitch,
1217 const PixelStoreStateBase &state,
1218 bool is3D,
1219 GLuint *resultOut) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001220{
Olli Etuaho989cac32016-06-08 16:18:49 -07001221 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1222 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001223 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1224 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1225 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Jeff Gilbert31d3deb2018-05-18 18:32:16 -07001226 CheckedNumeric<GLuint> checkedPixelBytes(computePixelBytes(formatType));
Olli Etuaho989cac32016-06-08 16:18:49 -07001227 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001228 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001229 {
1230 checkedSkipImagesBytes = 0;
1231 }
1232 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1233 checkedSkipPixels * checkedPixelBytes;
Jamie Madillca2ff382018-07-11 09:01:17 -04001234 return CheckedMathResult(skipBytes, resultOut);
Minmin Gongadff67b2015-10-14 10:34:45 -04001235}
1236
Jamie Madillca2ff382018-07-11 09:01:17 -04001237bool InternalFormat::computePackUnpackEndByte(GLenum formatType,
1238 const Extents &size,
1239 const PixelStoreStateBase &state,
1240 bool is3D,
1241 GLuint *resultOut) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001242{
Corentin Wallez886de362016-09-27 10:49:35 -04001243 GLuint rowPitch = 0;
Jamie Madillca2ff382018-07-11 09:01:17 -04001244 if (!computeRowPitch(formatType, size.width, state.alignment, state.rowLength, &rowPitch))
Corentin Wallez0e487192016-10-03 16:30:38 -04001245 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001246 return false;
Corentin Wallez0e487192016-10-03 16:30:38 -04001247 }
1248
Jamie Madillca2ff382018-07-11 09:01:17 -04001249 GLuint depthPitch = 0;
1250 if (is3D && !computeDepthPitch(size.height, state.imageHeight, rowPitch, &depthPitch))
1251 {
1252 return false;
1253 }
1254
1255 CheckedNumeric<GLuint> checkedCopyBytes(0);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001256 if (compressed)
1257 {
Jamie Madillca2ff382018-07-11 09:01:17 -04001258 GLuint copyBytes = 0;
1259 if (!computeCompressedImageSize(size, &copyBytes))
1260 {
1261 return false;
1262 }
1263 checkedCopyBytes = copyBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001264 }
Corentin Wallez886de362016-09-27 10:49:35 -04001265 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001266 {
Corentin Wallez886de362016-09-27 10:49:35 -04001267 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1268 checkedCopyBytes += size.width * bytes;
1269
1270 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1271 checkedCopyBytes += heightMinusOne * rowPitch;
1272
1273 if (is3D)
1274 {
1275 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1276 checkedCopyBytes += depthMinusOne * depthPitch;
1277 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001278 }
1279
Jamie Madillca2ff382018-07-11 09:01:17 -04001280 GLuint skipBytes = 0;
1281 if (!computeSkipBytes(formatType, rowPitch, depthPitch, state, is3D, &skipBytes))
1282 {
1283 return false;
1284 }
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001285
Jamie Madillca2ff382018-07-11 09:01:17 -04001286 CheckedNumeric<GLuint> endByte = checkedCopyBytes + CheckedNumeric<GLuint>(skipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001287
Jamie Madillca2ff382018-07-11 09:01:17 -04001288 return CheckedMathResult(endByte, resultOut);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001289}
1290
Geoff Langca271392017-04-05 12:30:00 -04001291GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001292{
Geoff Langca271392017-04-05 12:30:00 -04001293 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1294 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001295 {
Geoff Langca271392017-04-05 12:30:00 -04001296 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001297 }
Geoff Langca271392017-04-05 12:30:00 -04001298
1299 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001300}
1301
Geoff Lange4a492b2014-06-19 14:14:41 -04001302const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001303{
Geoff Lange4a492b2014-06-19 14:14:41 -04001304 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001305 return formatSet;
1306}
1307
Jamie Madill09e2d932015-07-14 16:40:31 -04001308AttributeType GetAttributeType(GLenum enumValue)
1309{
1310 switch (enumValue)
1311 {
1312 case GL_FLOAT:
1313 return ATTRIBUTE_FLOAT;
1314 case GL_FLOAT_VEC2:
1315 return ATTRIBUTE_VEC2;
1316 case GL_FLOAT_VEC3:
1317 return ATTRIBUTE_VEC3;
1318 case GL_FLOAT_VEC4:
1319 return ATTRIBUTE_VEC4;
1320 case GL_INT:
1321 return ATTRIBUTE_INT;
1322 case GL_INT_VEC2:
1323 return ATTRIBUTE_IVEC2;
1324 case GL_INT_VEC3:
1325 return ATTRIBUTE_IVEC3;
1326 case GL_INT_VEC4:
1327 return ATTRIBUTE_IVEC4;
1328 case GL_UNSIGNED_INT:
1329 return ATTRIBUTE_UINT;
1330 case GL_UNSIGNED_INT_VEC2:
1331 return ATTRIBUTE_UVEC2;
1332 case GL_UNSIGNED_INT_VEC3:
1333 return ATTRIBUTE_UVEC3;
1334 case GL_UNSIGNED_INT_VEC4:
1335 return ATTRIBUTE_UVEC4;
1336 case GL_FLOAT_MAT2:
1337 return ATTRIBUTE_MAT2;
1338 case GL_FLOAT_MAT3:
1339 return ATTRIBUTE_MAT3;
1340 case GL_FLOAT_MAT4:
1341 return ATTRIBUTE_MAT4;
1342 case GL_FLOAT_MAT2x3:
1343 return ATTRIBUTE_MAT2x3;
1344 case GL_FLOAT_MAT2x4:
1345 return ATTRIBUTE_MAT2x4;
1346 case GL_FLOAT_MAT3x2:
1347 return ATTRIBUTE_MAT3x2;
1348 case GL_FLOAT_MAT3x4:
1349 return ATTRIBUTE_MAT3x4;
1350 case GL_FLOAT_MAT4x2:
1351 return ATTRIBUTE_MAT4x2;
1352 case GL_FLOAT_MAT4x3:
1353 return ATTRIBUTE_MAT4x3;
1354 default:
1355 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001356#if !UNREACHABLE_IS_NORETURN
Jamie Madill09e2d932015-07-14 16:40:31 -04001357 return ATTRIBUTE_FLOAT;
Nico Weberb5db2b42018-02-12 15:31:56 -05001358#endif
Jamie Madill09e2d932015-07-14 16:40:31 -04001359 }
1360}
1361
Jamie Madillba365932018-07-18 17:23:46 -04001362angle::FormatID GetVertexFormatID(GLenum type,
1363 GLboolean normalized,
1364 GLuint components,
1365 bool pureInteger)
Jamie Madilld3dfda22015-07-06 08:28:49 -04001366{
1367 switch (type)
1368 {
1369 case GL_BYTE:
1370 switch (components)
1371 {
1372 case 1:
1373 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001374 return angle::FormatID::R8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001375 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001376 return angle::FormatID::R8_SNORM;
1377 return angle::FormatID::R8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001378 case 2:
1379 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001380 return angle::FormatID::R8G8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001381 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001382 return angle::FormatID::R8G8_SNORM;
1383 return angle::FormatID::R8G8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001384 case 3:
1385 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001386 return angle::FormatID::R8G8B8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001387 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001388 return angle::FormatID::R8G8B8_SNORM;
1389 return angle::FormatID::R8G8B8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001390 case 4:
1391 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001392 return angle::FormatID::R8G8B8A8_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001393 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001394 return angle::FormatID::R8G8B8A8_SNORM;
1395 return angle::FormatID::R8G8B8A8_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001396 default:
1397 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001398#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001399 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001400#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001401 }
1402 case GL_UNSIGNED_BYTE:
1403 switch (components)
1404 {
1405 case 1:
1406 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001407 return angle::FormatID::R8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001408 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001409 return angle::FormatID::R8_UNORM;
1410 return angle::FormatID::R8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001411 case 2:
1412 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001413 return angle::FormatID::R8G8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001414 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001415 return angle::FormatID::R8G8_UNORM;
1416 return angle::FormatID::R8G8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001417 case 3:
1418 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001419 return angle::FormatID::R8G8B8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001420 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001421 return angle::FormatID::R8G8B8_UNORM;
1422 return angle::FormatID::R8G8B8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001423 case 4:
1424 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001425 return angle::FormatID::R8G8B8A8_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001426 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001427 return angle::FormatID::R8G8B8A8_UNORM;
1428 return angle::FormatID::R8G8B8A8_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001429 default:
1430 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001431#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001432 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001433#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001434 }
1435 case GL_SHORT:
1436 switch (components)
1437 {
1438 case 1:
1439 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001440 return angle::FormatID::R16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001441 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001442 return angle::FormatID::R16_SNORM;
1443 return angle::FormatID::R16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001444 case 2:
1445 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001446 return angle::FormatID::R16G16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001447 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001448 return angle::FormatID::R16G16_SNORM;
1449 return angle::FormatID::R16G16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001450 case 3:
1451 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001452 return angle::FormatID::R16G16B16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001453 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001454 return angle::FormatID::R16G16B16_SNORM;
1455 return angle::FormatID::R16G16B16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001456 case 4:
1457 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001458 return angle::FormatID::R16G16B16A16_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001459 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001460 return angle::FormatID::R16G16B16A16_SNORM;
1461 return angle::FormatID::R16G16B16A16_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001462 default:
1463 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001464#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001465 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001466#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001467 }
1468 case GL_UNSIGNED_SHORT:
1469 switch (components)
1470 {
1471 case 1:
1472 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001473 return angle::FormatID::R16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001474 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001475 return angle::FormatID::R16_UNORM;
1476 return angle::FormatID::R16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001477 case 2:
1478 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001479 return angle::FormatID::R16G16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001480 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001481 return angle::FormatID::R16G16_UNORM;
1482 return angle::FormatID::R16G16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001483 case 3:
1484 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001485 return angle::FormatID::R16G16B16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001486 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001487 return angle::FormatID::R16G16B16_UNORM;
1488 return angle::FormatID::R16G16B16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001489 case 4:
1490 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001491 return angle::FormatID::R16G16B16A16_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001492 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001493 return angle::FormatID::R16G16B16A16_UNORM;
1494 return angle::FormatID::R16G16B16A16_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001495 default:
1496 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001497#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001498 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001499#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001500 }
1501 case GL_INT:
1502 switch (components)
1503 {
1504 case 1:
1505 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001506 return angle::FormatID::R32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001507 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001508 return angle::FormatID::R32_SNORM;
1509 return angle::FormatID::R32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001510 case 2:
1511 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001512 return angle::FormatID::R32G32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001513 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001514 return angle::FormatID::R32G32_SNORM;
1515 return angle::FormatID::R32G32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001516 case 3:
1517 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001518 return angle::FormatID::R32G32B32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001519 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001520 return angle::FormatID::R32G32B32_SNORM;
1521 return angle::FormatID::R32G32B32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001522 case 4:
1523 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001524 return angle::FormatID::R32G32B32A32_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001525 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001526 return angle::FormatID::R32G32B32A32_SNORM;
1527 return angle::FormatID::R32G32B32A32_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001528 default:
1529 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001530#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001531 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001532#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001533 }
1534 case GL_UNSIGNED_INT:
1535 switch (components)
1536 {
1537 case 1:
1538 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001539 return angle::FormatID::R32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001540 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001541 return angle::FormatID::R32_UNORM;
1542 return angle::FormatID::R32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001543 case 2:
1544 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001545 return angle::FormatID::R32G32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001546 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001547 return angle::FormatID::R32G32_UNORM;
1548 return angle::FormatID::R32G32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001549 case 3:
1550 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001551 return angle::FormatID::R32G32B32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001552 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001553 return angle::FormatID::R32G32B32_UNORM;
1554 return angle::FormatID::R32G32B32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001555 case 4:
1556 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001557 return angle::FormatID::R32G32B32A32_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001558 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001559 return angle::FormatID::R32G32B32A32_UNORM;
1560 return angle::FormatID::R32G32B32A32_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001561 default:
1562 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001563#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001564 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001565#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001566 }
1567 case GL_FLOAT:
1568 switch (components)
1569 {
1570 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001571 return angle::FormatID::R32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001572 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001573 return angle::FormatID::R32G32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001574 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001575 return angle::FormatID::R32G32B32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001576 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001577 return angle::FormatID::R32G32B32A32_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001578 default:
1579 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001580#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001581 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001582#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001583 }
1584 case GL_HALF_FLOAT:
1585 switch (components)
1586 {
1587 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001588 return angle::FormatID::R16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001589 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001590 return angle::FormatID::R16G16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001591 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001592 return angle::FormatID::R16G16B16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001593 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001594 return angle::FormatID::R16G16B16A16_FLOAT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001595 default:
1596 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001597#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001598 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001599#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001600 }
1601 case GL_FIXED:
1602 switch (components)
1603 {
1604 case 1:
Jamie Madillba365932018-07-18 17:23:46 -04001605 return angle::FormatID::R32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001606 case 2:
Jamie Madillba365932018-07-18 17:23:46 -04001607 return angle::FormatID::R32G32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001608 case 3:
Jamie Madillba365932018-07-18 17:23:46 -04001609 return angle::FormatID::R32G32B32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001610 case 4:
Jamie Madillba365932018-07-18 17:23:46 -04001611 return angle::FormatID::R32G32B32A32_FIXED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001612 default:
1613 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001614#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001615 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001616#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001617 }
1618 case GL_INT_2_10_10_10_REV:
1619 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001620 return angle::FormatID::R10G10B10A2_SINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001621 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001622 return angle::FormatID::R10G10B10A2_SNORM;
1623 return angle::FormatID::R10G10B10A2_SSCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001624 case GL_UNSIGNED_INT_2_10_10_10_REV:
1625 if (pureInteger)
Jamie Madillba365932018-07-18 17:23:46 -04001626 return angle::FormatID::R10G10B10A2_UINT;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001627 if (normalized)
Jamie Madillba365932018-07-18 17:23:46 -04001628 return angle::FormatID::R10G10B10A2_UNORM;
1629 return angle::FormatID::R10G10B10A2_USCALED;
Jamie Madilld3dfda22015-07-06 08:28:49 -04001630 default:
1631 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05001632#if !UNREACHABLE_IS_NORETURN
Jamie Madillba365932018-07-18 17:23:46 -04001633 return angle::FormatID::NONE;
Nico Weberb5db2b42018-02-12 15:31:56 -05001634#endif
Jamie Madilld3dfda22015-07-06 08:28:49 -04001635 }
Jamie Madilld3dfda22015-07-06 08:28:49 -04001636}
1637
Jamie Madillba365932018-07-18 17:23:46 -04001638angle::FormatID GetVertexFormatID(const VertexAttribute &attrib)
Frank Henigman95fb2a12018-05-27 20:17:05 -04001639{
1640 return GetVertexFormatID(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1641}
1642
Jamie Madillba365932018-07-18 17:23:46 -04001643// TODO(fjhenigman): Do away with VertexFormatType; use angle::FormatID instead. anglebug.com/2531
Frank Henigman95fb2a12018-05-27 20:17:05 -04001644VertexFormatType GetVertexFormatType(GLenum type,
1645 GLboolean normalized,
1646 GLuint components,
1647 bool pureInteger)
1648{
1649 switch (GetVertexFormatID(type, normalized, components, pureInteger))
1650 {
Jamie Madillba365932018-07-18 17:23:46 -04001651 case angle::FormatID::R8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001652 return VERTEX_FORMAT_SBYTE1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001653 case angle::FormatID::R8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001654 return VERTEX_FORMAT_SBYTE1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001655 case angle::FormatID::R8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001656 return VERTEX_FORMAT_SBYTE1;
Jamie Madillba365932018-07-18 17:23:46 -04001657 case angle::FormatID::R8G8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001658 return VERTEX_FORMAT_SBYTE2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001659 case angle::FormatID::R8G8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001660 return VERTEX_FORMAT_SBYTE2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001661 case angle::FormatID::R8G8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001662 return VERTEX_FORMAT_SBYTE2;
Jamie Madillba365932018-07-18 17:23:46 -04001663 case angle::FormatID::R8G8B8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001664 return VERTEX_FORMAT_SBYTE3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001665 case angle::FormatID::R8G8B8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001666 return VERTEX_FORMAT_SBYTE3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001667 case angle::FormatID::R8G8B8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001668 return VERTEX_FORMAT_SBYTE3;
Jamie Madillba365932018-07-18 17:23:46 -04001669 case angle::FormatID::R8G8B8A8_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001670 return VERTEX_FORMAT_SBYTE4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001671 case angle::FormatID::R8G8B8A8_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001672 return VERTEX_FORMAT_SBYTE4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001673 case angle::FormatID::R8G8B8A8_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001674 return VERTEX_FORMAT_SBYTE4;
Jamie Madillba365932018-07-18 17:23:46 -04001675 case angle::FormatID::R8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001676 return VERTEX_FORMAT_UBYTE1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001677 case angle::FormatID::R8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001678 return VERTEX_FORMAT_UBYTE1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001679 case angle::FormatID::R8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001680 return VERTEX_FORMAT_UBYTE1;
Jamie Madillba365932018-07-18 17:23:46 -04001681 case angle::FormatID::R8G8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001682 return VERTEX_FORMAT_UBYTE2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001683 case angle::FormatID::R8G8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001684 return VERTEX_FORMAT_UBYTE2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001685 case angle::FormatID::R8G8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001686 return VERTEX_FORMAT_UBYTE2;
Jamie Madillba365932018-07-18 17:23:46 -04001687 case angle::FormatID::R8G8B8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001688 return VERTEX_FORMAT_UBYTE3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001689 case angle::FormatID::R8G8B8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001690 return VERTEX_FORMAT_UBYTE3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001691 case angle::FormatID::R8G8B8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001692 return VERTEX_FORMAT_UBYTE3;
Jamie Madillba365932018-07-18 17:23:46 -04001693 case angle::FormatID::R8G8B8A8_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001694 return VERTEX_FORMAT_UBYTE4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001695 case angle::FormatID::R8G8B8A8_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001696 return VERTEX_FORMAT_UBYTE4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001697 case angle::FormatID::R8G8B8A8_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001698 return VERTEX_FORMAT_UBYTE4;
Jamie Madillba365932018-07-18 17:23:46 -04001699 case angle::FormatID::R16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001700 return VERTEX_FORMAT_SSHORT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001701 case angle::FormatID::R16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001702 return VERTEX_FORMAT_SSHORT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001703 case angle::FormatID::R16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001704 return VERTEX_FORMAT_SSHORT1;
Jamie Madillba365932018-07-18 17:23:46 -04001705 case angle::FormatID::R16G16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001706 return VERTEX_FORMAT_SSHORT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001707 case angle::FormatID::R16G16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001708 return VERTEX_FORMAT_SSHORT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001709 case angle::FormatID::R16G16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001710 return VERTEX_FORMAT_SSHORT2;
Jamie Madillba365932018-07-18 17:23:46 -04001711 case angle::FormatID::R16G16B16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001712 return VERTEX_FORMAT_SSHORT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001713 case angle::FormatID::R16G16B16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001714 return VERTEX_FORMAT_SSHORT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001715 case angle::FormatID::R16G16B16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001716 return VERTEX_FORMAT_SSHORT3;
Jamie Madillba365932018-07-18 17:23:46 -04001717 case angle::FormatID::R16G16B16A16_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001718 return VERTEX_FORMAT_SSHORT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001719 case angle::FormatID::R16G16B16A16_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001720 return VERTEX_FORMAT_SSHORT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001721 case angle::FormatID::R16G16B16A16_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001722 return VERTEX_FORMAT_SSHORT4;
Jamie Madillba365932018-07-18 17:23:46 -04001723 case angle::FormatID::R16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001724 return VERTEX_FORMAT_USHORT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001725 case angle::FormatID::R16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001726 return VERTEX_FORMAT_USHORT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001727 case angle::FormatID::R16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001728 return VERTEX_FORMAT_USHORT1;
Jamie Madillba365932018-07-18 17:23:46 -04001729 case angle::FormatID::R16G16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001730 return VERTEX_FORMAT_USHORT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001731 case angle::FormatID::R16G16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001732 return VERTEX_FORMAT_USHORT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001733 case angle::FormatID::R16G16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001734 return VERTEX_FORMAT_USHORT2;
Jamie Madillba365932018-07-18 17:23:46 -04001735 case angle::FormatID::R16G16B16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001736 return VERTEX_FORMAT_USHORT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001737 case angle::FormatID::R16G16B16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001738 return VERTEX_FORMAT_USHORT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001739 case angle::FormatID::R16G16B16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001740 return VERTEX_FORMAT_USHORT3;
Jamie Madillba365932018-07-18 17:23:46 -04001741 case angle::FormatID::R16G16B16A16_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001742 return VERTEX_FORMAT_USHORT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001743 case angle::FormatID::R16G16B16A16_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001744 return VERTEX_FORMAT_USHORT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001745 case angle::FormatID::R16G16B16A16_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001746 return VERTEX_FORMAT_USHORT4;
Jamie Madillba365932018-07-18 17:23:46 -04001747 case angle::FormatID::R32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001748 return VERTEX_FORMAT_SINT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001749 case angle::FormatID::R32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001750 return VERTEX_FORMAT_SINT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001751 case angle::FormatID::R32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001752 return VERTEX_FORMAT_SINT1;
Jamie Madillba365932018-07-18 17:23:46 -04001753 case angle::FormatID::R32G32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001754 return VERTEX_FORMAT_SINT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001755 case angle::FormatID::R32G32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001756 return VERTEX_FORMAT_SINT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001757 case angle::FormatID::R32G32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001758 return VERTEX_FORMAT_SINT2;
Jamie Madillba365932018-07-18 17:23:46 -04001759 case angle::FormatID::R32G32B32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001760 return VERTEX_FORMAT_SINT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001761 case angle::FormatID::R32G32B32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001762 return VERTEX_FORMAT_SINT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001763 case angle::FormatID::R32G32B32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001764 return VERTEX_FORMAT_SINT3;
Jamie Madillba365932018-07-18 17:23:46 -04001765 case angle::FormatID::R32G32B32A32_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001766 return VERTEX_FORMAT_SINT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001767 case angle::FormatID::R32G32B32A32_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001768 return VERTEX_FORMAT_SINT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001769 case angle::FormatID::R32G32B32A32_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001770 return VERTEX_FORMAT_SINT4;
Jamie Madillba365932018-07-18 17:23:46 -04001771 case angle::FormatID::R32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001772 return VERTEX_FORMAT_UINT1_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001773 case angle::FormatID::R32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001774 return VERTEX_FORMAT_UINT1_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001775 case angle::FormatID::R32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001776 return VERTEX_FORMAT_UINT1;
Jamie Madillba365932018-07-18 17:23:46 -04001777 case angle::FormatID::R32G32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001778 return VERTEX_FORMAT_UINT2_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001779 case angle::FormatID::R32G32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001780 return VERTEX_FORMAT_UINT2_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001781 case angle::FormatID::R32G32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001782 return VERTEX_FORMAT_UINT2;
Jamie Madillba365932018-07-18 17:23:46 -04001783 case angle::FormatID::R32G32B32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001784 return VERTEX_FORMAT_UINT3_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001785 case angle::FormatID::R32G32B32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001786 return VERTEX_FORMAT_UINT3_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001787 case angle::FormatID::R32G32B32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001788 return VERTEX_FORMAT_UINT3;
Jamie Madillba365932018-07-18 17:23:46 -04001789 case angle::FormatID::R32G32B32A32_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001790 return VERTEX_FORMAT_UINT4_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001791 case angle::FormatID::R32G32B32A32_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001792 return VERTEX_FORMAT_UINT4_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001793 case angle::FormatID::R32G32B32A32_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001794 return VERTEX_FORMAT_UINT4;
Jamie Madillba365932018-07-18 17:23:46 -04001795 case angle::FormatID::R32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001796 return VERTEX_FORMAT_FLOAT1;
Jamie Madillba365932018-07-18 17:23:46 -04001797 case angle::FormatID::R32G32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001798 return VERTEX_FORMAT_FLOAT2;
Jamie Madillba365932018-07-18 17:23:46 -04001799 case angle::FormatID::R32G32B32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001800 return VERTEX_FORMAT_FLOAT3;
Jamie Madillba365932018-07-18 17:23:46 -04001801 case angle::FormatID::R32G32B32A32_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001802 return VERTEX_FORMAT_FLOAT4;
Jamie Madillba365932018-07-18 17:23:46 -04001803 case angle::FormatID::R16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001804 return VERTEX_FORMAT_HALF1;
Jamie Madillba365932018-07-18 17:23:46 -04001805 case angle::FormatID::R16G16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001806 return VERTEX_FORMAT_HALF2;
Jamie Madillba365932018-07-18 17:23:46 -04001807 case angle::FormatID::R16G16B16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001808 return VERTEX_FORMAT_HALF3;
Jamie Madillba365932018-07-18 17:23:46 -04001809 case angle::FormatID::R16G16B16A16_FLOAT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001810 return VERTEX_FORMAT_HALF4;
Jamie Madillba365932018-07-18 17:23:46 -04001811 case angle::FormatID::R32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001812 return VERTEX_FORMAT_FIXED1;
Jamie Madillba365932018-07-18 17:23:46 -04001813 case angle::FormatID::R32G32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001814 return VERTEX_FORMAT_FIXED2;
Jamie Madillba365932018-07-18 17:23:46 -04001815 case angle::FormatID::R32G32B32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001816 return VERTEX_FORMAT_FIXED3;
Jamie Madillba365932018-07-18 17:23:46 -04001817 case angle::FormatID::R32G32B32A32_FIXED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001818 return VERTEX_FORMAT_FIXED4;
Jamie Madillba365932018-07-18 17:23:46 -04001819 case angle::FormatID::R10G10B10A2_SINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001820 return VERTEX_FORMAT_SINT210_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001821 case angle::FormatID::R10G10B10A2_SNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001822 return VERTEX_FORMAT_SINT210_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001823 case angle::FormatID::R10G10B10A2_SSCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001824 return VERTEX_FORMAT_SINT210;
Jamie Madillba365932018-07-18 17:23:46 -04001825 case angle::FormatID::R10G10B10A2_UINT:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001826 return VERTEX_FORMAT_UINT210_INT;
Jamie Madillba365932018-07-18 17:23:46 -04001827 case angle::FormatID::R10G10B10A2_UNORM:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001828 return VERTEX_FORMAT_UINT210_NORM;
Jamie Madillba365932018-07-18 17:23:46 -04001829 case angle::FormatID::R10G10B10A2_USCALED:
Frank Henigman95fb2a12018-05-27 20:17:05 -04001830 return VERTEX_FORMAT_UINT210;
1831 default:
1832 return VERTEX_FORMAT_INVALID;
1833 }
1834}
1835
Jamie Madilld3dfda22015-07-06 08:28:49 -04001836VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1837{
1838 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1839}
1840
1841VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1842{
1843 if (!attrib.enabled)
1844 {
1845 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1846 }
1847 return GetVertexFormatType(attrib);
1848}
1849
1850const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1851{
1852 switch (vertexFormatType)
1853 {
1854 case VERTEX_FORMAT_SBYTE1:
1855 {
1856 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1857 return format;
1858 }
1859 case VERTEX_FORMAT_SBYTE1_NORM:
1860 {
1861 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1862 return format;
1863 }
1864 case VERTEX_FORMAT_SBYTE2:
1865 {
1866 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1867 return format;
1868 }
1869 case VERTEX_FORMAT_SBYTE2_NORM:
1870 {
1871 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1872 return format;
1873 }
1874 case VERTEX_FORMAT_SBYTE3:
1875 {
1876 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1877 return format;
1878 }
1879 case VERTEX_FORMAT_SBYTE3_NORM:
1880 {
1881 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1882 return format;
1883 }
1884 case VERTEX_FORMAT_SBYTE4:
1885 {
1886 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1887 return format;
1888 }
1889 case VERTEX_FORMAT_SBYTE4_NORM:
1890 {
1891 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1892 return format;
1893 }
1894 case VERTEX_FORMAT_UBYTE1:
1895 {
1896 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1897 return format;
1898 }
1899 case VERTEX_FORMAT_UBYTE1_NORM:
1900 {
1901 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1902 return format;
1903 }
1904 case VERTEX_FORMAT_UBYTE2:
1905 {
1906 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1907 return format;
1908 }
1909 case VERTEX_FORMAT_UBYTE2_NORM:
1910 {
1911 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1912 return format;
1913 }
1914 case VERTEX_FORMAT_UBYTE3:
1915 {
1916 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1917 return format;
1918 }
1919 case VERTEX_FORMAT_UBYTE3_NORM:
1920 {
1921 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1922 return format;
1923 }
1924 case VERTEX_FORMAT_UBYTE4:
1925 {
1926 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1927 return format;
1928 }
1929 case VERTEX_FORMAT_UBYTE4_NORM:
1930 {
1931 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1932 return format;
1933 }
1934 case VERTEX_FORMAT_SSHORT1:
1935 {
1936 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1937 return format;
1938 }
1939 case VERTEX_FORMAT_SSHORT1_NORM:
1940 {
1941 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1942 return format;
1943 }
1944 case VERTEX_FORMAT_SSHORT2:
1945 {
1946 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1947 return format;
1948 }
1949 case VERTEX_FORMAT_SSHORT2_NORM:
1950 {
1951 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1952 return format;
1953 }
1954 case VERTEX_FORMAT_SSHORT3:
1955 {
1956 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1957 return format;
1958 }
1959 case VERTEX_FORMAT_SSHORT3_NORM:
1960 {
1961 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1962 return format;
1963 }
1964 case VERTEX_FORMAT_SSHORT4:
1965 {
1966 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1967 return format;
1968 }
1969 case VERTEX_FORMAT_SSHORT4_NORM:
1970 {
1971 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1972 return format;
1973 }
1974 case VERTEX_FORMAT_USHORT1:
1975 {
1976 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1977 return format;
1978 }
1979 case VERTEX_FORMAT_USHORT1_NORM:
1980 {
1981 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1982 return format;
1983 }
1984 case VERTEX_FORMAT_USHORT2:
1985 {
1986 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1987 return format;
1988 }
1989 case VERTEX_FORMAT_USHORT2_NORM:
1990 {
1991 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1992 return format;
1993 }
1994 case VERTEX_FORMAT_USHORT3:
1995 {
1996 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1997 return format;
1998 }
1999 case VERTEX_FORMAT_USHORT3_NORM:
2000 {
2001 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
2002 return format;
2003 }
2004 case VERTEX_FORMAT_USHORT4:
2005 {
2006 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
2007 return format;
2008 }
2009 case VERTEX_FORMAT_USHORT4_NORM:
2010 {
2011 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
2012 return format;
2013 }
2014 case VERTEX_FORMAT_SINT1:
2015 {
2016 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
2017 return format;
2018 }
2019 case VERTEX_FORMAT_SINT1_NORM:
2020 {
2021 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
2022 return format;
2023 }
2024 case VERTEX_FORMAT_SINT2:
2025 {
2026 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
2027 return format;
2028 }
2029 case VERTEX_FORMAT_SINT2_NORM:
2030 {
2031 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
2032 return format;
2033 }
2034 case VERTEX_FORMAT_SINT3:
2035 {
2036 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
2037 return format;
2038 }
2039 case VERTEX_FORMAT_SINT3_NORM:
2040 {
2041 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
2042 return format;
2043 }
2044 case VERTEX_FORMAT_SINT4:
2045 {
2046 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
2047 return format;
2048 }
2049 case VERTEX_FORMAT_SINT4_NORM:
2050 {
2051 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
2052 return format;
2053 }
2054 case VERTEX_FORMAT_UINT1:
2055 {
2056 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
2057 return format;
2058 }
2059 case VERTEX_FORMAT_UINT1_NORM:
2060 {
2061 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
2062 return format;
2063 }
2064 case VERTEX_FORMAT_UINT2:
2065 {
2066 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
2067 return format;
2068 }
2069 case VERTEX_FORMAT_UINT2_NORM:
2070 {
2071 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
2072 return format;
2073 }
2074 case VERTEX_FORMAT_UINT3:
2075 {
2076 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
2077 return format;
2078 }
2079 case VERTEX_FORMAT_UINT3_NORM:
2080 {
2081 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
2082 return format;
2083 }
2084 case VERTEX_FORMAT_UINT4:
2085 {
2086 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
2087 return format;
2088 }
2089 case VERTEX_FORMAT_UINT4_NORM:
2090 {
2091 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
2092 return format;
2093 }
2094 case VERTEX_FORMAT_SBYTE1_INT:
2095 {
2096 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
2097 return format;
2098 }
2099 case VERTEX_FORMAT_SBYTE2_INT:
2100 {
2101 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
2102 return format;
2103 }
2104 case VERTEX_FORMAT_SBYTE3_INT:
2105 {
2106 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
2107 return format;
2108 }
2109 case VERTEX_FORMAT_SBYTE4_INT:
2110 {
2111 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
2112 return format;
2113 }
2114 case VERTEX_FORMAT_UBYTE1_INT:
2115 {
2116 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
2117 return format;
2118 }
2119 case VERTEX_FORMAT_UBYTE2_INT:
2120 {
2121 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
2122 return format;
2123 }
2124 case VERTEX_FORMAT_UBYTE3_INT:
2125 {
2126 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
2127 return format;
2128 }
2129 case VERTEX_FORMAT_UBYTE4_INT:
2130 {
2131 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
2132 return format;
2133 }
2134 case VERTEX_FORMAT_SSHORT1_INT:
2135 {
2136 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
2137 return format;
2138 }
2139 case VERTEX_FORMAT_SSHORT2_INT:
2140 {
2141 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
2142 return format;
2143 }
2144 case VERTEX_FORMAT_SSHORT3_INT:
2145 {
2146 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
2147 return format;
2148 }
2149 case VERTEX_FORMAT_SSHORT4_INT:
2150 {
2151 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
2152 return format;
2153 }
2154 case VERTEX_FORMAT_USHORT1_INT:
2155 {
2156 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
2157 return format;
2158 }
2159 case VERTEX_FORMAT_USHORT2_INT:
2160 {
2161 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
2162 return format;
2163 }
2164 case VERTEX_FORMAT_USHORT3_INT:
2165 {
2166 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
2167 return format;
2168 }
2169 case VERTEX_FORMAT_USHORT4_INT:
2170 {
2171 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
2172 return format;
2173 }
2174 case VERTEX_FORMAT_SINT1_INT:
2175 {
2176 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
2177 return format;
2178 }
2179 case VERTEX_FORMAT_SINT2_INT:
2180 {
2181 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
2182 return format;
2183 }
2184 case VERTEX_FORMAT_SINT3_INT:
2185 {
2186 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
2187 return format;
2188 }
2189 case VERTEX_FORMAT_SINT4_INT:
2190 {
2191 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
2192 return format;
2193 }
2194 case VERTEX_FORMAT_UINT1_INT:
2195 {
2196 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
2197 return format;
2198 }
2199 case VERTEX_FORMAT_UINT2_INT:
2200 {
2201 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
2202 return format;
2203 }
2204 case VERTEX_FORMAT_UINT3_INT:
2205 {
2206 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
2207 return format;
2208 }
2209 case VERTEX_FORMAT_UINT4_INT:
2210 {
2211 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
2212 return format;
2213 }
2214 case VERTEX_FORMAT_FIXED1:
2215 {
2216 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
2217 return format;
2218 }
2219 case VERTEX_FORMAT_FIXED2:
2220 {
2221 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
2222 return format;
2223 }
2224 case VERTEX_FORMAT_FIXED3:
2225 {
2226 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
2227 return format;
2228 }
2229 case VERTEX_FORMAT_FIXED4:
2230 {
2231 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
2232 return format;
2233 }
2234 case VERTEX_FORMAT_HALF1:
2235 {
2236 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
2237 return format;
2238 }
2239 case VERTEX_FORMAT_HALF2:
2240 {
2241 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
2242 return format;
2243 }
2244 case VERTEX_FORMAT_HALF3:
2245 {
2246 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
2247 return format;
2248 }
2249 case VERTEX_FORMAT_HALF4:
2250 {
2251 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
2252 return format;
2253 }
2254 case VERTEX_FORMAT_FLOAT1:
2255 {
2256 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
2257 return format;
2258 }
2259 case VERTEX_FORMAT_FLOAT2:
2260 {
2261 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
2262 return format;
2263 }
2264 case VERTEX_FORMAT_FLOAT3:
2265 {
2266 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
2267 return format;
2268 }
2269 case VERTEX_FORMAT_FLOAT4:
2270 {
2271 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
2272 return format;
2273 }
2274 case VERTEX_FORMAT_SINT210:
2275 {
2276 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2277 return format;
2278 }
2279 case VERTEX_FORMAT_UINT210:
2280 {
2281 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
2282 return format;
2283 }
2284 case VERTEX_FORMAT_SINT210_NORM:
2285 {
2286 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2287 return format;
2288 }
2289 case VERTEX_FORMAT_UINT210_NORM:
2290 {
2291 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
2292 return format;
2293 }
2294 case VERTEX_FORMAT_SINT210_INT:
2295 {
2296 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2297 return format;
2298 }
2299 case VERTEX_FORMAT_UINT210_INT:
2300 {
2301 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
2302 return format;
2303 }
2304 default:
2305 {
2306 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
2307 return format;
2308 }
2309 }
2310}
2311
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002312size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
2313{
2314 switch (vertexFormatType)
2315 {
2316 case VERTEX_FORMAT_SBYTE1:
2317 case VERTEX_FORMAT_SBYTE1_NORM:
2318 case VERTEX_FORMAT_UBYTE1:
2319 case VERTEX_FORMAT_UBYTE1_NORM:
2320 case VERTEX_FORMAT_SBYTE1_INT:
2321 case VERTEX_FORMAT_UBYTE1_INT:
2322 return 1;
2323
2324 case VERTEX_FORMAT_SBYTE2:
2325 case VERTEX_FORMAT_SBYTE2_NORM:
2326 case VERTEX_FORMAT_UBYTE2:
2327 case VERTEX_FORMAT_UBYTE2_NORM:
2328 case VERTEX_FORMAT_SBYTE2_INT:
2329 case VERTEX_FORMAT_UBYTE2_INT:
2330 case VERTEX_FORMAT_SSHORT1:
2331 case VERTEX_FORMAT_SSHORT1_NORM:
2332 case VERTEX_FORMAT_USHORT1:
2333 case VERTEX_FORMAT_USHORT1_NORM:
2334 case VERTEX_FORMAT_SSHORT1_INT:
2335 case VERTEX_FORMAT_USHORT1_INT:
2336 case VERTEX_FORMAT_HALF1:
2337 return 2;
2338
2339 case VERTEX_FORMAT_SBYTE3:
2340 case VERTEX_FORMAT_SBYTE3_NORM:
2341 case VERTEX_FORMAT_UBYTE3:
2342 case VERTEX_FORMAT_UBYTE3_NORM:
2343 case VERTEX_FORMAT_SBYTE3_INT:
2344 case VERTEX_FORMAT_UBYTE3_INT:
2345 return 3;
2346
2347 case VERTEX_FORMAT_SBYTE4:
2348 case VERTEX_FORMAT_SBYTE4_NORM:
2349 case VERTEX_FORMAT_UBYTE4:
2350 case VERTEX_FORMAT_UBYTE4_NORM:
2351 case VERTEX_FORMAT_SBYTE4_INT:
2352 case VERTEX_FORMAT_UBYTE4_INT:
2353 case VERTEX_FORMAT_SSHORT2:
2354 case VERTEX_FORMAT_SSHORT2_NORM:
2355 case VERTEX_FORMAT_USHORT2:
2356 case VERTEX_FORMAT_USHORT2_NORM:
2357 case VERTEX_FORMAT_SSHORT2_INT:
2358 case VERTEX_FORMAT_USHORT2_INT:
2359 case VERTEX_FORMAT_SINT1:
2360 case VERTEX_FORMAT_SINT1_NORM:
2361 case VERTEX_FORMAT_UINT1:
2362 case VERTEX_FORMAT_UINT1_NORM:
2363 case VERTEX_FORMAT_SINT1_INT:
2364 case VERTEX_FORMAT_UINT1_INT:
2365 case VERTEX_FORMAT_HALF2:
2366 case VERTEX_FORMAT_FIXED1:
2367 case VERTEX_FORMAT_FLOAT1:
2368 case VERTEX_FORMAT_SINT210:
2369 case VERTEX_FORMAT_UINT210:
2370 case VERTEX_FORMAT_SINT210_NORM:
2371 case VERTEX_FORMAT_UINT210_NORM:
2372 case VERTEX_FORMAT_SINT210_INT:
2373 case VERTEX_FORMAT_UINT210_INT:
2374 return 4;
2375
2376 case VERTEX_FORMAT_SSHORT3:
2377 case VERTEX_FORMAT_SSHORT3_NORM:
2378 case VERTEX_FORMAT_USHORT3:
2379 case VERTEX_FORMAT_USHORT3_NORM:
2380 case VERTEX_FORMAT_SSHORT3_INT:
2381 case VERTEX_FORMAT_USHORT3_INT:
2382 case VERTEX_FORMAT_HALF3:
2383 return 6;
2384
2385 case VERTEX_FORMAT_SSHORT4:
2386 case VERTEX_FORMAT_SSHORT4_NORM:
2387 case VERTEX_FORMAT_USHORT4:
2388 case VERTEX_FORMAT_USHORT4_NORM:
2389 case VERTEX_FORMAT_SSHORT4_INT:
2390 case VERTEX_FORMAT_USHORT4_INT:
2391 case VERTEX_FORMAT_SINT2:
2392 case VERTEX_FORMAT_SINT2_NORM:
2393 case VERTEX_FORMAT_UINT2:
2394 case VERTEX_FORMAT_UINT2_NORM:
2395 case VERTEX_FORMAT_SINT2_INT:
2396 case VERTEX_FORMAT_UINT2_INT:
2397 case VERTEX_FORMAT_HALF4:
2398 case VERTEX_FORMAT_FIXED2:
2399 case VERTEX_FORMAT_FLOAT2:
2400 return 8;
2401
2402 case VERTEX_FORMAT_SINT3:
2403 case VERTEX_FORMAT_SINT3_NORM:
2404 case VERTEX_FORMAT_UINT3:
2405 case VERTEX_FORMAT_UINT3_NORM:
2406 case VERTEX_FORMAT_SINT3_INT:
2407 case VERTEX_FORMAT_UINT3_INT:
2408 case VERTEX_FORMAT_FIXED3:
2409 case VERTEX_FORMAT_FLOAT3:
2410 return 12;
2411
2412 case VERTEX_FORMAT_SINT4:
2413 case VERTEX_FORMAT_SINT4_NORM:
2414 case VERTEX_FORMAT_UINT4:
2415 case VERTEX_FORMAT_UINT4_NORM:
2416 case VERTEX_FORMAT_SINT4_INT:
2417 case VERTEX_FORMAT_UINT4_INT:
2418 case VERTEX_FORMAT_FIXED4:
2419 case VERTEX_FORMAT_FLOAT4:
2420 return 16;
2421
2422 case VERTEX_FORMAT_INVALID:
2423 default:
2424 UNREACHABLE();
Nico Weberb5db2b42018-02-12 15:31:56 -05002425#if !UNREACHABLE_IS_NORETURN
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002426 return 0;
Nico Weberb5db2b42018-02-12 15:31:56 -05002427#endif
Corentin Wallez0c7baf12016-12-19 15:43:10 -05002428 }
2429}
2430
Geoff Lang6d1ccf02017-04-24 14:09:58 -04002431bool ValidES3InternalFormat(GLenum internalFormat)
2432{
2433 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
2434 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
2435}
2436
Frank Henigman95fb2a12018-05-27 20:17:05 -04002437VertexFormat::VertexFormat(GLenum typeIn,
2438 GLboolean normalizedIn,
2439 GLuint componentsIn,
2440 bool pureIntegerIn)
2441 : type(typeIn), normalized(normalizedIn), components(componentsIn), pureInteger(pureIntegerIn)
Jamie Madilld3dfda22015-07-06 08:28:49 -04002442{
2443 // float -> !normalized
Frank Henigman95fb2a12018-05-27 20:17:05 -04002444 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) ||
2445 normalized == GL_FALSE);
Jamie Madilld3dfda22015-07-06 08:28:49 -04002446}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002447}