blob: 928d0557f306f378a8a385102c6927dc104a0466 [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
Geoff Lang2b5420c2014-11-19 14:20:15 -05009#include "libANGLE/formatutils.h"
Yuly Novikovafcc41c2016-12-13 12:59:39 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Jamie Madilla3944d42016-07-22 22:13:26 -040027typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
28typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
29
30} // anonymous namespace
31
32FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
33{
34}
35
36FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
37{
38}
39
40bool FormatType::operator<(const FormatType &other) const
41{
42 if (format != other.format)
43 return format < other.format;
44 return type < other.type;
45}
46
Geoff Lang5d601382014-07-22 15:14:06 -040047Type::Type()
48 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020049 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -040050 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040051{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052}
53
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020054static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055{
Geoff Lang5d601382014-07-22 15:14:06 -040056 Type info;
57 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020058 GLuint i = 0;
59 while ((1u << i) < bytes)
60 {
61 ++i;
62 }
63 info.bytesShift = i;
64 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040065 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020066 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040067}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang5d601382014-07-22 15:14:06 -040069bool operator<(const Type& a, const Type& b)
70{
71 return memcmp(&a, &b, sizeof(Type)) < 0;
72}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000074// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040075static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076{
Geoff Lang493daf52014-07-03 13:38:44 -040077 return true;
78}
79
Geoff Langeb66a6e2016-10-31 13:06:12 -040080static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082 return false;
83}
84
Geoff Langeb66a6e2016-10-31 13:06:12 -040085template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
86static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040087{
Geoff Langeb66a6e2016-10-31 13:06:12 -040088 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040089}
90
Geoff Langcec35902014-04-16 10:52:36 -040091// Pointer to a boolean memeber of the Extensions struct
92typedef bool(Extensions::*ExtensionBool);
93
94// Check support for a single extension
95template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040096static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040097{
Geoff Lange4a492b2014-06-19 14:14:41 -040098 return extensions.*bool1;
99}
100
101// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400102template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
103static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400104{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
106 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400107}
108
109// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400110template <GLuint minCoreGLMajorVersion,
111 GLuint minCoreGLMinorVersion,
112 ExtensionBool bool1,
113 ExtensionBool bool2>
114static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400115{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400116 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
117 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400118}
119
120// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400121template <GLuint minCoreGLMajorVersion,
122 GLuint minCoreGLMinorVersion,
123 ExtensionBool bool1,
124 ExtensionBool bool2>
125static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400126{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400127 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
128 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400129}
130
131// Check support for two extensions
132template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400133static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400134{
Geoff Langabce7622014-09-19 16:13:00 -0400135 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400136}
137
Geoff Lang60ad73d2015-10-23 10:08:44 -0400138// Check support for either of two extensions
139template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400140static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400141{
142 return extensions.*bool1 || extensions.*bool2;
143}
144
Jamie Madillcd089732015-12-17 09:53:09 -0500145// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400146static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500147{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400148 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500149}
150
Geoff Langeb66a6e2016-10-31 13:06:12 -0400151static bool HalfFloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500152{
153 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
154}
155
156// Special function for half float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400157static bool HalfFloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500158{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500160}
161
Geoff Langeb66a6e2016-10-31 13:06:12 -0400162static bool HalfFloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500163{
164 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
165}
166
167// Special function for float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400168static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500169{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400170 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500171}
172
Geoff Langeb66a6e2016-10-31 13:06:12 -0400173static bool FloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
175 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
176 return FloatSupport(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400177 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500178}
179
180// Special function for float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400181static bool FloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500182{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400183 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500184}
185
Geoff Langeb66a6e2016-10-31 13:06:12 -0400186static bool FloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500187{
188 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
189 return FloatSupportRG(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400190 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500191}
192
Geoff Lang5d601382014-07-22 15:14:06 -0400193InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400194 : internalFormat(GL_NONE),
195 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400196 greenBits(0),
197 blueBits(0),
198 luminanceBits(0),
199 alphaBits(0),
200 sharedBits(0),
201 depthBits(0),
202 stencilBits(0),
203 pixelBytes(0),
204 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400205 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400206 compressedBlockWidth(0),
207 compressedBlockHeight(0),
208 format(GL_NONE),
209 type(GL_NONE),
210 componentType(GL_NONE),
211 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400212 textureSupport(NeverSupported),
213 renderSupport(NeverSupported),
214 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000215{
Geoff Lang5d601382014-07-22 15:14:06 -0400216}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000217
Jamie Madilla3944d42016-07-22 22:13:26 -0400218bool InternalFormat::isLUMA() const
219{
220 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
221 (luminanceBits + alphaBits) > 0);
222}
223
Geoff Langf607c602016-09-21 11:46:48 -0400224GLenum InternalFormat::getReadPixelsFormat() const
225{
226 return format;
227}
228
229GLenum InternalFormat::getReadPixelsType() const
230{
231 switch (type)
232 {
233 case GL_HALF_FLOAT:
234 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
235 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
236 // OES_texture_half_float
237 return GL_HALF_FLOAT_OES;
238
239 default:
240 return type;
241 }
242}
243
Jamie Madilla3944d42016-07-22 22:13:26 -0400244Format::Format(GLenum internalFormat) : Format(GetInternalFormatInfo(internalFormat))
245{
246}
247
248Format::Format(const InternalFormat &internalFormat)
249 : info(&internalFormat), format(info->format), type(info->type), sized(true)
250{
251 ASSERT((info->pixelBytes > 0 && format != GL_NONE && type != GL_NONE) ||
252 internalFormat.format == GL_NONE);
253}
254
255Format::Format(GLenum internalFormat, GLenum format, GLenum type)
256 : info(nullptr), format(format), type(type), sized(false)
257{
258 const auto &plainInfo = GetInternalFormatInfo(internalFormat);
259 sized = plainInfo.pixelBytes > 0;
260 info = (sized ? &plainInfo : &GetInternalFormatInfo(GetSizedFormatInternal(format, type)));
261 ASSERT(format == GL_NONE || info->pixelBytes > 0);
262}
263
264Format::Format(const Format &other) = default;
265Format &Format::operator=(const Format &other) = default;
266
267GLenum Format::asSized() const
268{
269 return sized ? info->internalFormat : GetSizedFormatInternal(format, type);
270}
271
272bool Format::valid() const
273{
274 return info->format != GL_NONE;
275}
276
277// static
278bool Format::SameSized(const Format &a, const Format &b)
279{
280 return (a.info == b.info);
281}
282
283// static
284Format Format::Invalid()
285{
286 static Format invalid(GL_NONE, GL_NONE, GL_NONE);
287 return invalid;
288}
289
Yuly Novikovafcc41c2016-12-13 12:59:39 -0500290std::ostream &operator<<(std::ostream &os, const Format &fmt)
291{
292 // TODO(ynovikov): return string representation when available
293 return FmtHexShort(os, fmt.asSized());
294}
295
Jamie Madilla3944d42016-07-22 22:13:26 -0400296bool InternalFormat::operator==(const InternalFormat &other) const
297{
298 // We assume there are no duplicates.
299 ASSERT((this == &other) == (internalFormat == other.internalFormat));
300 return internalFormat == other.internalFormat;
301}
302
303bool InternalFormat::operator!=(const InternalFormat &other) const
304{
305 // We assume there are no duplicates.
306 ASSERT((this != &other) == (internalFormat != other.internalFormat));
307 return internalFormat != other.internalFormat;
308}
309
310static void AddUnsizedFormat(InternalFormatInfoMap *map,
311 GLenum internalFormat,
312 GLenum format,
313 InternalFormat::SupportCheckFunction textureSupport,
314 InternalFormat::SupportCheckFunction renderSupport,
315 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400316{
317 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400318 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400319 formatInfo.format = format;
320 formatInfo.textureSupport = textureSupport;
321 formatInfo.renderSupport = renderSupport;
322 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400323 ASSERT(map->count(internalFormat) == 0);
324 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400325}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000326
Jamie Madilla3944d42016-07-22 22:13:26 -0400327void AddRGBAFormat(InternalFormatInfoMap *map,
328 GLenum internalFormat,
329 GLuint red,
330 GLuint green,
331 GLuint blue,
332 GLuint alpha,
333 GLuint shared,
334 GLenum format,
335 GLenum type,
336 GLenum componentType,
337 bool srgb,
338 InternalFormat::SupportCheckFunction textureSupport,
339 InternalFormat::SupportCheckFunction renderSupport,
340 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400341{
342 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400343 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400344 formatInfo.redBits = red;
345 formatInfo.greenBits = green;
346 formatInfo.blueBits = blue;
347 formatInfo.alphaBits = alpha;
348 formatInfo.sharedBits = shared;
349 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
350 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
351 formatInfo.format = format;
352 formatInfo.type = type;
353 formatInfo.componentType = componentType;
354 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
355 formatInfo.textureSupport = textureSupport;
356 formatInfo.renderSupport = renderSupport;
357 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400358 ASSERT(map->count(internalFormat) == 0);
359 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400360}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000361
Geoff Lang5d601382014-07-22 15:14:06 -0400362static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
363 InternalFormat::SupportCheckFunction textureSupport,
364 InternalFormat::SupportCheckFunction renderSupport,
365 InternalFormat::SupportCheckFunction filterSupport)
366{
367 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400368 formatInfo.internalFormat = GetSizedFormatInternal(format, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400369 formatInfo.luminanceBits = luminance;
370 formatInfo.alphaBits = alpha;
371 formatInfo.pixelBytes = (luminance + alpha) / 8;
372 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
373 formatInfo.format = format;
374 formatInfo.type = type;
375 formatInfo.componentType = componentType;
376 formatInfo.colorEncoding = GL_LINEAR;
377 formatInfo.textureSupport = textureSupport;
378 formatInfo.renderSupport = renderSupport;
379 formatInfo.filterSupport = filterSupport;
380 return formatInfo;
381}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000382
Jamie Madilla3944d42016-07-22 22:13:26 -0400383void AddDepthStencilFormat(InternalFormatInfoMap *map,
384 GLenum internalFormat,
385 GLuint depthBits,
386 GLuint stencilBits,
387 GLuint unusedBits,
388 GLenum format,
389 GLenum type,
390 GLenum componentType,
391 InternalFormat::SupportCheckFunction textureSupport,
392 InternalFormat::SupportCheckFunction renderSupport,
393 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400394{
395 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400396 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400397 formatInfo.depthBits = depthBits;
398 formatInfo.stencilBits = stencilBits;
399 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
400 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
401 formatInfo.format = format;
402 formatInfo.type = type;
403 formatInfo.componentType = componentType;
404 formatInfo.colorEncoding = GL_LINEAR;
405 formatInfo.textureSupport = textureSupport;
406 formatInfo.renderSupport = renderSupport;
407 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400408 ASSERT(map->count(internalFormat) == 0);
409 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400410}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000411
Geoff Lang5d601382014-07-22 15:14:06 -0400412static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
413 GLuint componentCount, GLenum format, GLenum type, bool srgb,
414 InternalFormat::SupportCheckFunction textureSupport,
415 InternalFormat::SupportCheckFunction renderSupport,
416 InternalFormat::SupportCheckFunction filterSupport)
417{
418 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400419 formatInfo.internalFormat = format;
Geoff Lang5d601382014-07-22 15:14:06 -0400420 formatInfo.compressedBlockWidth = compressedBlockWidth;
421 formatInfo.compressedBlockHeight = compressedBlockHeight;
422 formatInfo.pixelBytes = compressedBlockSize / 8;
423 formatInfo.componentCount = componentCount;
424 formatInfo.format = format;
425 formatInfo.type = type;
426 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
427 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
428 formatInfo.compressed = true;
429 formatInfo.textureSupport = textureSupport;
430 formatInfo.renderSupport = renderSupport;
431 formatInfo.filterSupport = filterSupport;
432 return formatInfo;
433}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000434
Geoff Lange4a492b2014-06-19 14:14:41 -0400435static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000436{
437 InternalFormatInfoMap map;
438
439 // From ES 3.0.1 spec, table 3.12
Jamie Madilla3944d42016-07-22 22:13:26 -0400440 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000441
Jamie Madilla3944d42016-07-22 22:13:26 -0400442 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000443
Geoff Langeb66a6e2016-10-31 13:06:12 -0400444 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
445 AddRGBAFormat(&map, GL_R8, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
446 AddRGBAFormat(&map, GL_R8_SNORM, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
447 AddRGBAFormat(&map, GL_RG8, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
448 AddRGBAFormat(&map, GL_RG8_SNORM, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
449 AddRGBAFormat(&map, GL_RGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
450 AddRGBAFormat(&map, GL_RGB8_SNORM, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
451 AddRGBAFormat(&map, GL_RGB565, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
452 AddRGBAFormat(&map, GL_RGBA4, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
453 AddRGBAFormat(&map, GL_RGB5_A1, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
454 AddRGBAFormat(&map, GL_RGBA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
455 AddRGBAFormat(&map, GL_RGBA8_SNORM, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
456 AddRGBAFormat(&map, GL_RGB10_A2, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3, 0>, RequireES<3, 0>, AlwaysSupported);
457 AddRGBAFormat(&map, GL_RGB10_A2UI, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
458 AddRGBAFormat(&map, GL_SRGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
459 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported);
460 AddRGBAFormat(&map, GL_RGB9_E5, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
461 AddRGBAFormat(&map, GL_R8I, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
462 AddRGBAFormat(&map, GL_R8UI, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
463 AddRGBAFormat(&map, GL_R16I, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
464 AddRGBAFormat(&map, GL_R16UI, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
465 AddRGBAFormat(&map, GL_R32I, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
466 AddRGBAFormat(&map, GL_R32UI, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
467 AddRGBAFormat(&map, GL_RG8I, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
468 AddRGBAFormat(&map, GL_RG8UI, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
469 AddRGBAFormat(&map, GL_RG16I, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
470 AddRGBAFormat(&map, GL_RG16UI, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
471 AddRGBAFormat(&map, GL_RG32I, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
472 AddRGBAFormat(&map, GL_R11F_G11F_B10F, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3, 0>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported);
473 AddRGBAFormat(&map, GL_RG32UI, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
474 AddRGBAFormat(&map, GL_RGB8I, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
475 AddRGBAFormat(&map, GL_RGB8UI, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
476 AddRGBAFormat(&map, GL_RGB16I, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
477 AddRGBAFormat(&map, GL_RGB16UI, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
478 AddRGBAFormat(&map, GL_RGB32I, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
479 AddRGBAFormat(&map, GL_RGB32UI, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
480 AddRGBAFormat(&map, GL_RGBA8I, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
481 AddRGBAFormat(&map, GL_RGBA8UI, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
482 AddRGBAFormat(&map, GL_RGBA16I, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
483 AddRGBAFormat(&map, GL_RGBA16UI, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
484 AddRGBAFormat(&map, GL_RGBA32I, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
485 AddRGBAFormat(&map, GL_RGBA32UI, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
Jamie Madilla3944d42016-07-22 22:13:26 -0400486
487 AddRGBAFormat(&map, GL_BGRA8_EXT, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
488 AddRGBAFormat(&map, GL_BGRA4_ANGLEX, 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
489 AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX, 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000490
Jamie Madillec0b5802016-07-04 13:11:59 -0400491 // Special format which is not really supported, so always false for all supports.
Jamie Madilla3944d42016-07-22 22:13:26 -0400492 AddRGBAFormat(&map, GL_BGR565_ANGLEX, 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported);
Jamie Madillec0b5802016-07-04 13:11:59 -0400493
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000494 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madilla3944d42016-07-22 22:13:26 -0400495 // | Internal format | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
496 // | | | | | | type | | | | |
497 AddRGBAFormat(&map, GL_R16F, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
498 AddRGBAFormat(&map, GL_RG16F, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
499 AddRGBAFormat(&map, GL_RGB16F, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
500 AddRGBAFormat(&map, GL_RGBA16F, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
501 AddRGBAFormat(&map, GL_R32F, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
502 AddRGBAFormat(&map, GL_RG32F, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
503 AddRGBAFormat(&map, GL_RGB32F, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
504 AddRGBAFormat(&map, GL_RGBA32F, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000505
506 // Depth stencil formats
Geoff Langeb66a6e2016-10-31 13:06:12 -0400507 // | Internal format | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
508 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
509 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
510 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
511 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported );
512 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, AlwaysSupported );
513 AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3, 0>, RequireES<3, 0>, AlwaysSupported );
Corentin Walleze0902642014-11-04 12:32:15 -0800514 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000515
516 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400517 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400518 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
519 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
520 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
521 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
522 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
523 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
524 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
525 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
526 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000527
528 // Unsized formats
Geoff Langeb66a6e2016-10-31 13:06:12 -0400529 // | Internal format | Format | Supported | Renderable | Filterable |
530 AddUnsizedFormat(&map, GL_ALPHA, GL_ALPHA, RequireES<2, 0>, NeverSupported, AlwaysSupported);
531 AddUnsizedFormat(&map, GL_LUMINANCE, GL_LUMINANCE, RequireES<2, 0>, NeverSupported, AlwaysSupported);
532 AddUnsizedFormat(&map, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, RequireES<2, 0>, NeverSupported, AlwaysSupported);
533 AddUnsizedFormat(&map, GL_RED, GL_RED, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
534 AddUnsizedFormat(&map, GL_RG, GL_RG, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
535 AddUnsizedFormat(&map, GL_RGB, GL_RGB, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
536 AddUnsizedFormat(&map, GL_RGBA, GL_RGBA, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
537 AddUnsizedFormat(&map, GL_RED_INTEGER, GL_RED_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
538 AddUnsizedFormat(&map, GL_RG_INTEGER, GL_RG_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
539 AddUnsizedFormat(&map, GL_RGB_INTEGER, GL_RGB_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
540 AddUnsizedFormat(&map, GL_RGBA_INTEGER, GL_RGBA_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
541 AddUnsizedFormat(&map, GL_BGRA_EXT, GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
542 AddUnsizedFormat(&map, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
543 AddUnsizedFormat(&map, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
544 AddUnsizedFormat(&map, GL_SRGB_EXT, GL_RGB, RequireESOrExt<3, 0, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
545 AddUnsizedFormat(&map, GL_SRGB_ALPHA_EXT, GL_RGBA, RequireESOrExt<3, 0, &Extensions::sRGB>, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000546
547 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langeb66a6e2016-10-31 13:06:12 -0400548 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
549 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
550 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
551 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
552 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
553 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
554 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
555 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
556 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
557 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
558 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000559
560 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400561 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
562 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported)));
563 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000564
565 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400566 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000567
568 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400569 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported)));
570
571 // From GL_OES_compressed_ETC1_RGB8_texture
572 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_OES, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_OES, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000573
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800574 // From GL_EXT_texture_compression_s3tc_srgb
575 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
576 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported)));
577 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported)));
578 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported)));
579 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported)));
580
Geoff Lang60ad73d2015-10-23 10:08:44 -0400581 // From KHR_texture_compression_astc_hdr
582 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
583 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
584 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
585 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
586 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
587 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
588 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
589 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
590 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
591 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
592 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
593 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
594 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
595 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
596 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
597
598 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
599 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
600 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
601 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
602 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
603 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
604 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
605 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
606 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
607 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
608 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
609 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
610 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
611 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
612
Corentin Walleze0902642014-11-04 12:32:15 -0800613 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
614 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
615 // - All other stencil formats (all depth-stencil) are either float or normalized
616 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400617 // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
618 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800619
620 // From GL_ANGLE_lossy_etc_decode
Geoff Langd13ca302016-09-08 09:35:57 -0400621 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800622
Vincent Lang25ab4512016-05-13 18:13:59 +0200623 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400624 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
625 AddRGBAFormat(&map, GL_R16_EXT, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
626 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
627 AddRGBAFormat(&map, GL_RG16_EXT, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
628 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
629 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
630 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
631 AddRGBAFormat(&map, GL_RGBA16_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
632 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
Vincent Lang25ab4512016-05-13 18:13:59 +0200633
Geoff Lang9bbad182015-09-04 11:07:29 -0400634 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800635
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636 return map;
637}
638
Geoff Lange4a492b2014-06-19 14:14:41 -0400639static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640{
Geoff Lange4a492b2014-06-19 14:14:41 -0400641 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
642 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000643}
644
Geoff Lange4a492b2014-06-19 14:14:41 -0400645static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400646{
647 FormatSet result;
648
Jamie Madillec0b5802016-07-04 13:11:59 -0400649 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400650 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400651 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400652 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400653 // TODO(jmadill): Fix this hack.
654 if (iter.first == GL_BGR565_ANGLEX)
655 continue;
656
657 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400658 }
659 }
660
661 return result;
662}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000663
Geoff Lang5d601382014-07-22 15:14:06 -0400664const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000665{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200666 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000667 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200668 case GL_UNSIGNED_BYTE:
669 case GL_BYTE:
670 {
671 static const Type info = GenTypeInfo(1, false);
672 return info;
673 }
674 case GL_UNSIGNED_SHORT:
675 case GL_SHORT:
676 case GL_HALF_FLOAT:
677 case GL_HALF_FLOAT_OES:
678 {
679 static const Type info = GenTypeInfo(2, false);
680 return info;
681 }
682 case GL_UNSIGNED_INT:
683 case GL_INT:
684 case GL_FLOAT:
685 {
686 static const Type info = GenTypeInfo(4, false);
687 return info;
688 }
689 case GL_UNSIGNED_SHORT_5_6_5:
690 case GL_UNSIGNED_SHORT_4_4_4_4:
691 case GL_UNSIGNED_SHORT_5_5_5_1:
692 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
693 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
694 {
695 static const Type info = GenTypeInfo(2, true);
696 return info;
697 }
698 case GL_UNSIGNED_INT_2_10_10_10_REV:
699 case GL_UNSIGNED_INT_24_8:
700 case GL_UNSIGNED_INT_10F_11F_11F_REV:
701 case GL_UNSIGNED_INT_5_9_9_9_REV:
702 {
703 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
704 static const Type info = GenTypeInfo(4, true);
705 return info;
706 }
707 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
708 {
709 static const Type info = GenTypeInfo(8, true);
710 return info;
711 }
712 default:
713 {
714 static const Type defaultInfo;
715 return defaultInfo;
716 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000717 }
718}
719
Geoff Lang5d601382014-07-22 15:14:06 -0400720const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000721{
Geoff Lang5d601382014-07-22 15:14:06 -0400722 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400723 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400724 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000725 {
Geoff Lang5d601382014-07-22 15:14:06 -0400726 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000727 }
728 else
729 {
Geoff Lang5d601382014-07-22 15:14:06 -0400730 static const InternalFormat defaultInternalFormat;
731 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000732 }
733}
734
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400735GLuint InternalFormat::computePixelBytes(GLenum formatType) const
736{
737 const auto &typeInfo = GetTypeInfo(formatType);
738 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
739 return components * typeInfo.bytes;
740}
741
Corentin Wallez886de362016-09-27 10:49:35 -0400742ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400743 GLsizei width,
744 GLint alignment,
745 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000746{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700747 // Compressed images do not use pack/unpack parameters.
748 if (compressed)
749 {
750 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400751 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700752 }
753
Geoff Lang3f234062016-07-13 15:35:45 -0400754 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400755 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700756
757 ASSERT(alignment > 0 && isPow2(alignment));
758 CheckedNumeric<GLuint> checkedAlignment(alignment);
759 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
760 ANGLE_TRY_CHECKED_MATH(aligned);
761 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000762}
763
Corentin Wallez0e487192016-10-03 16:30:38 -0400764ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
765 GLint imageHeight,
766 GLuint rowPitch) const
767{
768 GLuint rows =
769 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
770 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
771
772 auto depthPitch = checkedRowPitch * rows;
773 ANGLE_TRY_CHECKED_MATH(depthPitch);
774 return depthPitch.ValueOrDie();
775}
776
Corentin Wallez886de362016-09-27 10:49:35 -0400777ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400778 GLsizei width,
779 GLsizei height,
780 GLint alignment,
781 GLint rowLength,
782 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000783{
Jamie Madille2e406c2016-06-02 13:04:10 -0400784 GLuint rowPitch = 0;
785 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400786 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000787}
788
Corentin Wallez886de362016-09-27 10:49:35 -0400789ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
790 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000791{
Jamie Madill513558d2016-06-02 13:04:11 -0400792 CheckedNumeric<GLuint> checkedWidth(size.width);
793 CheckedNumeric<GLuint> checkedHeight(size.height);
794 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700795 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
796 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400797
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700798 ASSERT(compressed);
799 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
800 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
801 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
802 ANGLE_TRY_CHECKED_MATH(bytes);
803 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000804}
805
Corentin Wallez886de362016-09-27 10:49:35 -0400806ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700807 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400808 const PixelStoreStateBase &state,
809 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400810{
Olli Etuaho989cac32016-06-08 16:18:49 -0700811 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
812 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400813 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
814 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
815 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700816 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
817 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400818 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700819 {
820 checkedSkipImagesBytes = 0;
821 }
822 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
823 checkedSkipPixels * checkedPixelBytes;
824 ANGLE_TRY_CHECKED_MATH(skipBytes);
825 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400826}
827
Corentin Wallez886de362016-09-27 10:49:35 -0400828ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
829 GLenum formatType,
830 const Extents &size,
831 const PixelStoreStateBase &state,
832 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400833{
Corentin Wallez886de362016-09-27 10:49:35 -0400834 GLuint rowPitch = 0;
835 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400836 rowPitch);
837
Corentin Wallez0e487192016-10-03 16:30:38 -0400838 GLuint depthPitch = 0;
839 if (is3D)
840 {
841 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
842 }
843
Corentin Wallez886de362016-09-27 10:49:35 -0400844 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700845 if (compressed)
846 {
Corentin Wallez886de362016-09-27 10:49:35 -0400847 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700848 }
Corentin Wallez886de362016-09-27 10:49:35 -0400849 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400850 {
Corentin Wallez886de362016-09-27 10:49:35 -0400851 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
852 checkedCopyBytes += size.width * bytes;
853
854 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
855 checkedCopyBytes += heightMinusOne * rowPitch;
856
857 if (is3D)
858 {
859 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
860 checkedCopyBytes += depthMinusOne * depthPitch;
861 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400862 }
863
Corentin Wallez886de362016-09-27 10:49:35 -0400864 CheckedNumeric<GLuint> checkedSkipBytes = 0;
865 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400866
867 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
868
869 ANGLE_TRY_CHECKED_MATH(endByte);
870 return endByte.ValueOrDie();
871}
872
Geoff Lang5d601382014-07-22 15:14:06 -0400873GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000874{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700875 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500876 if (formatInfo.pixelBytes > 0)
877 {
878 return internalFormat;
879 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400880 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000881}
882
Geoff Lange4a492b2014-06-19 14:14:41 -0400883const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400884{
Geoff Lange4a492b2014-06-19 14:14:41 -0400885 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400886 return formatSet;
887}
888
Jamie Madill09e2d932015-07-14 16:40:31 -0400889AttributeType GetAttributeType(GLenum enumValue)
890{
891 switch (enumValue)
892 {
893 case GL_FLOAT:
894 return ATTRIBUTE_FLOAT;
895 case GL_FLOAT_VEC2:
896 return ATTRIBUTE_VEC2;
897 case GL_FLOAT_VEC3:
898 return ATTRIBUTE_VEC3;
899 case GL_FLOAT_VEC4:
900 return ATTRIBUTE_VEC4;
901 case GL_INT:
902 return ATTRIBUTE_INT;
903 case GL_INT_VEC2:
904 return ATTRIBUTE_IVEC2;
905 case GL_INT_VEC3:
906 return ATTRIBUTE_IVEC3;
907 case GL_INT_VEC4:
908 return ATTRIBUTE_IVEC4;
909 case GL_UNSIGNED_INT:
910 return ATTRIBUTE_UINT;
911 case GL_UNSIGNED_INT_VEC2:
912 return ATTRIBUTE_UVEC2;
913 case GL_UNSIGNED_INT_VEC3:
914 return ATTRIBUTE_UVEC3;
915 case GL_UNSIGNED_INT_VEC4:
916 return ATTRIBUTE_UVEC4;
917 case GL_FLOAT_MAT2:
918 return ATTRIBUTE_MAT2;
919 case GL_FLOAT_MAT3:
920 return ATTRIBUTE_MAT3;
921 case GL_FLOAT_MAT4:
922 return ATTRIBUTE_MAT4;
923 case GL_FLOAT_MAT2x3:
924 return ATTRIBUTE_MAT2x3;
925 case GL_FLOAT_MAT2x4:
926 return ATTRIBUTE_MAT2x4;
927 case GL_FLOAT_MAT3x2:
928 return ATTRIBUTE_MAT3x2;
929 case GL_FLOAT_MAT3x4:
930 return ATTRIBUTE_MAT3x4;
931 case GL_FLOAT_MAT4x2:
932 return ATTRIBUTE_MAT4x2;
933 case GL_FLOAT_MAT4x3:
934 return ATTRIBUTE_MAT4x3;
935 default:
936 UNREACHABLE();
937 return ATTRIBUTE_FLOAT;
938 }
939}
940
Jamie Madilld3dfda22015-07-06 08:28:49 -0400941VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
942{
943 switch (type)
944 {
945 case GL_BYTE:
946 switch (components)
947 {
948 case 1:
949 if (pureInteger)
950 return VERTEX_FORMAT_SBYTE1_INT;
951 if (normalized)
952 return VERTEX_FORMAT_SBYTE1_NORM;
953 return VERTEX_FORMAT_SBYTE1;
954 case 2:
955 if (pureInteger)
956 return VERTEX_FORMAT_SBYTE2_INT;
957 if (normalized)
958 return VERTEX_FORMAT_SBYTE2_NORM;
959 return VERTEX_FORMAT_SBYTE2;
960 case 3:
961 if (pureInteger)
962 return VERTEX_FORMAT_SBYTE3_INT;
963 if (normalized)
964 return VERTEX_FORMAT_SBYTE3_NORM;
965 return VERTEX_FORMAT_SBYTE3;
966 case 4:
967 if (pureInteger)
968 return VERTEX_FORMAT_SBYTE4_INT;
969 if (normalized)
970 return VERTEX_FORMAT_SBYTE4_NORM;
971 return VERTEX_FORMAT_SBYTE4;
972 default:
973 UNREACHABLE();
974 break;
975 }
976 case GL_UNSIGNED_BYTE:
977 switch (components)
978 {
979 case 1:
980 if (pureInteger)
981 return VERTEX_FORMAT_UBYTE1_INT;
982 if (normalized)
983 return VERTEX_FORMAT_UBYTE1_NORM;
984 return VERTEX_FORMAT_UBYTE1;
985 case 2:
986 if (pureInteger)
987 return VERTEX_FORMAT_UBYTE2_INT;
988 if (normalized)
989 return VERTEX_FORMAT_UBYTE2_NORM;
990 return VERTEX_FORMAT_UBYTE2;
991 case 3:
992 if (pureInteger)
993 return VERTEX_FORMAT_UBYTE3_INT;
994 if (normalized)
995 return VERTEX_FORMAT_UBYTE3_NORM;
996 return VERTEX_FORMAT_UBYTE3;
997 case 4:
998 if (pureInteger)
999 return VERTEX_FORMAT_UBYTE4_INT;
1000 if (normalized)
1001 return VERTEX_FORMAT_UBYTE4_NORM;
1002 return VERTEX_FORMAT_UBYTE4;
1003 default:
1004 UNREACHABLE();
1005 break;
1006 }
1007 case GL_SHORT:
1008 switch (components)
1009 {
1010 case 1:
1011 if (pureInteger)
1012 return VERTEX_FORMAT_SSHORT1_INT;
1013 if (normalized)
1014 return VERTEX_FORMAT_SSHORT1_NORM;
1015 return VERTEX_FORMAT_SSHORT1;
1016 case 2:
1017 if (pureInteger)
1018 return VERTEX_FORMAT_SSHORT2_INT;
1019 if (normalized)
1020 return VERTEX_FORMAT_SSHORT2_NORM;
1021 return VERTEX_FORMAT_SSHORT2;
1022 case 3:
1023 if (pureInteger)
1024 return VERTEX_FORMAT_SSHORT3_INT;
1025 if (normalized)
1026 return VERTEX_FORMAT_SSHORT3_NORM;
1027 return VERTEX_FORMAT_SSHORT3;
1028 case 4:
1029 if (pureInteger)
1030 return VERTEX_FORMAT_SSHORT4_INT;
1031 if (normalized)
1032 return VERTEX_FORMAT_SSHORT4_NORM;
1033 return VERTEX_FORMAT_SSHORT4;
1034 default:
1035 UNREACHABLE();
1036 break;
1037 }
1038 case GL_UNSIGNED_SHORT:
1039 switch (components)
1040 {
1041 case 1:
1042 if (pureInteger)
1043 return VERTEX_FORMAT_USHORT1_INT;
1044 if (normalized)
1045 return VERTEX_FORMAT_USHORT1_NORM;
1046 return VERTEX_FORMAT_USHORT1;
1047 case 2:
1048 if (pureInteger)
1049 return VERTEX_FORMAT_USHORT2_INT;
1050 if (normalized)
1051 return VERTEX_FORMAT_USHORT2_NORM;
1052 return VERTEX_FORMAT_USHORT2;
1053 case 3:
1054 if (pureInteger)
1055 return VERTEX_FORMAT_USHORT3_INT;
1056 if (normalized)
1057 return VERTEX_FORMAT_USHORT3_NORM;
1058 return VERTEX_FORMAT_USHORT3;
1059 case 4:
1060 if (pureInteger)
1061 return VERTEX_FORMAT_USHORT4_INT;
1062 if (normalized)
1063 return VERTEX_FORMAT_USHORT4_NORM;
1064 return VERTEX_FORMAT_USHORT4;
1065 default:
1066 UNREACHABLE();
1067 break;
1068 }
1069 case GL_INT:
1070 switch (components)
1071 {
1072 case 1:
1073 if (pureInteger)
1074 return VERTEX_FORMAT_SINT1_INT;
1075 if (normalized)
1076 return VERTEX_FORMAT_SINT1_NORM;
1077 return VERTEX_FORMAT_SINT1;
1078 case 2:
1079 if (pureInteger)
1080 return VERTEX_FORMAT_SINT2_INT;
1081 if (normalized)
1082 return VERTEX_FORMAT_SINT2_NORM;
1083 return VERTEX_FORMAT_SINT2;
1084 case 3:
1085 if (pureInteger)
1086 return VERTEX_FORMAT_SINT3_INT;
1087 if (normalized)
1088 return VERTEX_FORMAT_SINT3_NORM;
1089 return VERTEX_FORMAT_SINT3;
1090 case 4:
1091 if (pureInteger)
1092 return VERTEX_FORMAT_SINT4_INT;
1093 if (normalized)
1094 return VERTEX_FORMAT_SINT4_NORM;
1095 return VERTEX_FORMAT_SINT4;
1096 default:
1097 UNREACHABLE();
1098 break;
1099 }
1100 case GL_UNSIGNED_INT:
1101 switch (components)
1102 {
1103 case 1:
1104 if (pureInteger)
1105 return VERTEX_FORMAT_UINT1_INT;
1106 if (normalized)
1107 return VERTEX_FORMAT_UINT1_NORM;
1108 return VERTEX_FORMAT_UINT1;
1109 case 2:
1110 if (pureInteger)
1111 return VERTEX_FORMAT_UINT2_INT;
1112 if (normalized)
1113 return VERTEX_FORMAT_UINT2_NORM;
1114 return VERTEX_FORMAT_UINT2;
1115 case 3:
1116 if (pureInteger)
1117 return VERTEX_FORMAT_UINT3_INT;
1118 if (normalized)
1119 return VERTEX_FORMAT_UINT3_NORM;
1120 return VERTEX_FORMAT_UINT3;
1121 case 4:
1122 if (pureInteger)
1123 return VERTEX_FORMAT_UINT4_INT;
1124 if (normalized)
1125 return VERTEX_FORMAT_UINT4_NORM;
1126 return VERTEX_FORMAT_UINT4;
1127 default:
1128 UNREACHABLE();
1129 break;
1130 }
1131 case GL_FLOAT:
1132 switch (components)
1133 {
1134 case 1:
1135 return VERTEX_FORMAT_FLOAT1;
1136 case 2:
1137 return VERTEX_FORMAT_FLOAT2;
1138 case 3:
1139 return VERTEX_FORMAT_FLOAT3;
1140 case 4:
1141 return VERTEX_FORMAT_FLOAT4;
1142 default:
1143 UNREACHABLE();
1144 break;
1145 }
1146 case GL_HALF_FLOAT:
1147 switch (components)
1148 {
1149 case 1:
1150 return VERTEX_FORMAT_HALF1;
1151 case 2:
1152 return VERTEX_FORMAT_HALF2;
1153 case 3:
1154 return VERTEX_FORMAT_HALF3;
1155 case 4:
1156 return VERTEX_FORMAT_HALF4;
1157 default:
1158 UNREACHABLE();
1159 break;
1160 }
1161 case GL_FIXED:
1162 switch (components)
1163 {
1164 case 1:
1165 return VERTEX_FORMAT_FIXED1;
1166 case 2:
1167 return VERTEX_FORMAT_FIXED2;
1168 case 3:
1169 return VERTEX_FORMAT_FIXED3;
1170 case 4:
1171 return VERTEX_FORMAT_FIXED4;
1172 default:
1173 UNREACHABLE();
1174 break;
1175 }
1176 case GL_INT_2_10_10_10_REV:
1177 if (pureInteger)
1178 return VERTEX_FORMAT_SINT210_INT;
1179 if (normalized)
1180 return VERTEX_FORMAT_SINT210_NORM;
1181 return VERTEX_FORMAT_SINT210;
1182 case GL_UNSIGNED_INT_2_10_10_10_REV:
1183 if (pureInteger)
1184 return VERTEX_FORMAT_UINT210_INT;
1185 if (normalized)
1186 return VERTEX_FORMAT_UINT210_NORM;
1187 return VERTEX_FORMAT_UINT210;
1188 default:
1189 UNREACHABLE();
1190 break;
1191 }
1192 return VERTEX_FORMAT_UBYTE1;
1193}
1194
1195VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1196{
1197 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1198}
1199
1200VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1201{
1202 if (!attrib.enabled)
1203 {
1204 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1205 }
1206 return GetVertexFormatType(attrib);
1207}
1208
1209const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1210{
1211 switch (vertexFormatType)
1212 {
1213 case VERTEX_FORMAT_SBYTE1:
1214 {
1215 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1216 return format;
1217 }
1218 case VERTEX_FORMAT_SBYTE1_NORM:
1219 {
1220 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1221 return format;
1222 }
1223 case VERTEX_FORMAT_SBYTE2:
1224 {
1225 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1226 return format;
1227 }
1228 case VERTEX_FORMAT_SBYTE2_NORM:
1229 {
1230 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1231 return format;
1232 }
1233 case VERTEX_FORMAT_SBYTE3:
1234 {
1235 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1236 return format;
1237 }
1238 case VERTEX_FORMAT_SBYTE3_NORM:
1239 {
1240 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1241 return format;
1242 }
1243 case VERTEX_FORMAT_SBYTE4:
1244 {
1245 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1246 return format;
1247 }
1248 case VERTEX_FORMAT_SBYTE4_NORM:
1249 {
1250 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1251 return format;
1252 }
1253 case VERTEX_FORMAT_UBYTE1:
1254 {
1255 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1256 return format;
1257 }
1258 case VERTEX_FORMAT_UBYTE1_NORM:
1259 {
1260 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1261 return format;
1262 }
1263 case VERTEX_FORMAT_UBYTE2:
1264 {
1265 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1266 return format;
1267 }
1268 case VERTEX_FORMAT_UBYTE2_NORM:
1269 {
1270 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1271 return format;
1272 }
1273 case VERTEX_FORMAT_UBYTE3:
1274 {
1275 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1276 return format;
1277 }
1278 case VERTEX_FORMAT_UBYTE3_NORM:
1279 {
1280 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1281 return format;
1282 }
1283 case VERTEX_FORMAT_UBYTE4:
1284 {
1285 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1286 return format;
1287 }
1288 case VERTEX_FORMAT_UBYTE4_NORM:
1289 {
1290 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1291 return format;
1292 }
1293 case VERTEX_FORMAT_SSHORT1:
1294 {
1295 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1296 return format;
1297 }
1298 case VERTEX_FORMAT_SSHORT1_NORM:
1299 {
1300 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1301 return format;
1302 }
1303 case VERTEX_FORMAT_SSHORT2:
1304 {
1305 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1306 return format;
1307 }
1308 case VERTEX_FORMAT_SSHORT2_NORM:
1309 {
1310 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1311 return format;
1312 }
1313 case VERTEX_FORMAT_SSHORT3:
1314 {
1315 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1316 return format;
1317 }
1318 case VERTEX_FORMAT_SSHORT3_NORM:
1319 {
1320 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1321 return format;
1322 }
1323 case VERTEX_FORMAT_SSHORT4:
1324 {
1325 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1326 return format;
1327 }
1328 case VERTEX_FORMAT_SSHORT4_NORM:
1329 {
1330 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1331 return format;
1332 }
1333 case VERTEX_FORMAT_USHORT1:
1334 {
1335 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1336 return format;
1337 }
1338 case VERTEX_FORMAT_USHORT1_NORM:
1339 {
1340 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1341 return format;
1342 }
1343 case VERTEX_FORMAT_USHORT2:
1344 {
1345 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1346 return format;
1347 }
1348 case VERTEX_FORMAT_USHORT2_NORM:
1349 {
1350 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1351 return format;
1352 }
1353 case VERTEX_FORMAT_USHORT3:
1354 {
1355 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1356 return format;
1357 }
1358 case VERTEX_FORMAT_USHORT3_NORM:
1359 {
1360 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1361 return format;
1362 }
1363 case VERTEX_FORMAT_USHORT4:
1364 {
1365 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1366 return format;
1367 }
1368 case VERTEX_FORMAT_USHORT4_NORM:
1369 {
1370 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1371 return format;
1372 }
1373 case VERTEX_FORMAT_SINT1:
1374 {
1375 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1376 return format;
1377 }
1378 case VERTEX_FORMAT_SINT1_NORM:
1379 {
1380 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1381 return format;
1382 }
1383 case VERTEX_FORMAT_SINT2:
1384 {
1385 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1386 return format;
1387 }
1388 case VERTEX_FORMAT_SINT2_NORM:
1389 {
1390 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1391 return format;
1392 }
1393 case VERTEX_FORMAT_SINT3:
1394 {
1395 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1396 return format;
1397 }
1398 case VERTEX_FORMAT_SINT3_NORM:
1399 {
1400 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1401 return format;
1402 }
1403 case VERTEX_FORMAT_SINT4:
1404 {
1405 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1406 return format;
1407 }
1408 case VERTEX_FORMAT_SINT4_NORM:
1409 {
1410 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1411 return format;
1412 }
1413 case VERTEX_FORMAT_UINT1:
1414 {
1415 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1416 return format;
1417 }
1418 case VERTEX_FORMAT_UINT1_NORM:
1419 {
1420 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1421 return format;
1422 }
1423 case VERTEX_FORMAT_UINT2:
1424 {
1425 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1426 return format;
1427 }
1428 case VERTEX_FORMAT_UINT2_NORM:
1429 {
1430 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1431 return format;
1432 }
1433 case VERTEX_FORMAT_UINT3:
1434 {
1435 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1436 return format;
1437 }
1438 case VERTEX_FORMAT_UINT3_NORM:
1439 {
1440 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1441 return format;
1442 }
1443 case VERTEX_FORMAT_UINT4:
1444 {
1445 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1446 return format;
1447 }
1448 case VERTEX_FORMAT_UINT4_NORM:
1449 {
1450 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1451 return format;
1452 }
1453 case VERTEX_FORMAT_SBYTE1_INT:
1454 {
1455 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1456 return format;
1457 }
1458 case VERTEX_FORMAT_SBYTE2_INT:
1459 {
1460 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1461 return format;
1462 }
1463 case VERTEX_FORMAT_SBYTE3_INT:
1464 {
1465 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1466 return format;
1467 }
1468 case VERTEX_FORMAT_SBYTE4_INT:
1469 {
1470 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1471 return format;
1472 }
1473 case VERTEX_FORMAT_UBYTE1_INT:
1474 {
1475 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1476 return format;
1477 }
1478 case VERTEX_FORMAT_UBYTE2_INT:
1479 {
1480 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1481 return format;
1482 }
1483 case VERTEX_FORMAT_UBYTE3_INT:
1484 {
1485 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1486 return format;
1487 }
1488 case VERTEX_FORMAT_UBYTE4_INT:
1489 {
1490 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1491 return format;
1492 }
1493 case VERTEX_FORMAT_SSHORT1_INT:
1494 {
1495 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1496 return format;
1497 }
1498 case VERTEX_FORMAT_SSHORT2_INT:
1499 {
1500 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1501 return format;
1502 }
1503 case VERTEX_FORMAT_SSHORT3_INT:
1504 {
1505 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1506 return format;
1507 }
1508 case VERTEX_FORMAT_SSHORT4_INT:
1509 {
1510 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1511 return format;
1512 }
1513 case VERTEX_FORMAT_USHORT1_INT:
1514 {
1515 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1516 return format;
1517 }
1518 case VERTEX_FORMAT_USHORT2_INT:
1519 {
1520 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1521 return format;
1522 }
1523 case VERTEX_FORMAT_USHORT3_INT:
1524 {
1525 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1526 return format;
1527 }
1528 case VERTEX_FORMAT_USHORT4_INT:
1529 {
1530 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1531 return format;
1532 }
1533 case VERTEX_FORMAT_SINT1_INT:
1534 {
1535 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1536 return format;
1537 }
1538 case VERTEX_FORMAT_SINT2_INT:
1539 {
1540 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1541 return format;
1542 }
1543 case VERTEX_FORMAT_SINT3_INT:
1544 {
1545 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1546 return format;
1547 }
1548 case VERTEX_FORMAT_SINT4_INT:
1549 {
1550 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1551 return format;
1552 }
1553 case VERTEX_FORMAT_UINT1_INT:
1554 {
1555 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1556 return format;
1557 }
1558 case VERTEX_FORMAT_UINT2_INT:
1559 {
1560 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1561 return format;
1562 }
1563 case VERTEX_FORMAT_UINT3_INT:
1564 {
1565 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1566 return format;
1567 }
1568 case VERTEX_FORMAT_UINT4_INT:
1569 {
1570 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1571 return format;
1572 }
1573 case VERTEX_FORMAT_FIXED1:
1574 {
1575 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1576 return format;
1577 }
1578 case VERTEX_FORMAT_FIXED2:
1579 {
1580 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1581 return format;
1582 }
1583 case VERTEX_FORMAT_FIXED3:
1584 {
1585 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1586 return format;
1587 }
1588 case VERTEX_FORMAT_FIXED4:
1589 {
1590 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1591 return format;
1592 }
1593 case VERTEX_FORMAT_HALF1:
1594 {
1595 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1596 return format;
1597 }
1598 case VERTEX_FORMAT_HALF2:
1599 {
1600 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1601 return format;
1602 }
1603 case VERTEX_FORMAT_HALF3:
1604 {
1605 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1606 return format;
1607 }
1608 case VERTEX_FORMAT_HALF4:
1609 {
1610 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1611 return format;
1612 }
1613 case VERTEX_FORMAT_FLOAT1:
1614 {
1615 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1616 return format;
1617 }
1618 case VERTEX_FORMAT_FLOAT2:
1619 {
1620 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1621 return format;
1622 }
1623 case VERTEX_FORMAT_FLOAT3:
1624 {
1625 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1626 return format;
1627 }
1628 case VERTEX_FORMAT_FLOAT4:
1629 {
1630 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1631 return format;
1632 }
1633 case VERTEX_FORMAT_SINT210:
1634 {
1635 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1636 return format;
1637 }
1638 case VERTEX_FORMAT_UINT210:
1639 {
1640 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1641 return format;
1642 }
1643 case VERTEX_FORMAT_SINT210_NORM:
1644 {
1645 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1646 return format;
1647 }
1648 case VERTEX_FORMAT_UINT210_NORM:
1649 {
1650 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1651 return format;
1652 }
1653 case VERTEX_FORMAT_SINT210_INT:
1654 {
1655 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1656 return format;
1657 }
1658 case VERTEX_FORMAT_UINT210_INT:
1659 {
1660 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1661 return format;
1662 }
1663 default:
1664 {
1665 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1666 return format;
1667 }
1668 }
1669}
1670
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001671size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1672{
1673 switch (vertexFormatType)
1674 {
1675 case VERTEX_FORMAT_SBYTE1:
1676 case VERTEX_FORMAT_SBYTE1_NORM:
1677 case VERTEX_FORMAT_UBYTE1:
1678 case VERTEX_FORMAT_UBYTE1_NORM:
1679 case VERTEX_FORMAT_SBYTE1_INT:
1680 case VERTEX_FORMAT_UBYTE1_INT:
1681 return 1;
1682
1683 case VERTEX_FORMAT_SBYTE2:
1684 case VERTEX_FORMAT_SBYTE2_NORM:
1685 case VERTEX_FORMAT_UBYTE2:
1686 case VERTEX_FORMAT_UBYTE2_NORM:
1687 case VERTEX_FORMAT_SBYTE2_INT:
1688 case VERTEX_FORMAT_UBYTE2_INT:
1689 case VERTEX_FORMAT_SSHORT1:
1690 case VERTEX_FORMAT_SSHORT1_NORM:
1691 case VERTEX_FORMAT_USHORT1:
1692 case VERTEX_FORMAT_USHORT1_NORM:
1693 case VERTEX_FORMAT_SSHORT1_INT:
1694 case VERTEX_FORMAT_USHORT1_INT:
1695 case VERTEX_FORMAT_HALF1:
1696 return 2;
1697
1698 case VERTEX_FORMAT_SBYTE3:
1699 case VERTEX_FORMAT_SBYTE3_NORM:
1700 case VERTEX_FORMAT_UBYTE3:
1701 case VERTEX_FORMAT_UBYTE3_NORM:
1702 case VERTEX_FORMAT_SBYTE3_INT:
1703 case VERTEX_FORMAT_UBYTE3_INT:
1704 return 3;
1705
1706 case VERTEX_FORMAT_SBYTE4:
1707 case VERTEX_FORMAT_SBYTE4_NORM:
1708 case VERTEX_FORMAT_UBYTE4:
1709 case VERTEX_FORMAT_UBYTE4_NORM:
1710 case VERTEX_FORMAT_SBYTE4_INT:
1711 case VERTEX_FORMAT_UBYTE4_INT:
1712 case VERTEX_FORMAT_SSHORT2:
1713 case VERTEX_FORMAT_SSHORT2_NORM:
1714 case VERTEX_FORMAT_USHORT2:
1715 case VERTEX_FORMAT_USHORT2_NORM:
1716 case VERTEX_FORMAT_SSHORT2_INT:
1717 case VERTEX_FORMAT_USHORT2_INT:
1718 case VERTEX_FORMAT_SINT1:
1719 case VERTEX_FORMAT_SINT1_NORM:
1720 case VERTEX_FORMAT_UINT1:
1721 case VERTEX_FORMAT_UINT1_NORM:
1722 case VERTEX_FORMAT_SINT1_INT:
1723 case VERTEX_FORMAT_UINT1_INT:
1724 case VERTEX_FORMAT_HALF2:
1725 case VERTEX_FORMAT_FIXED1:
1726 case VERTEX_FORMAT_FLOAT1:
1727 case VERTEX_FORMAT_SINT210:
1728 case VERTEX_FORMAT_UINT210:
1729 case VERTEX_FORMAT_SINT210_NORM:
1730 case VERTEX_FORMAT_UINT210_NORM:
1731 case VERTEX_FORMAT_SINT210_INT:
1732 case VERTEX_FORMAT_UINT210_INT:
1733 return 4;
1734
1735 case VERTEX_FORMAT_SSHORT3:
1736 case VERTEX_FORMAT_SSHORT3_NORM:
1737 case VERTEX_FORMAT_USHORT3:
1738 case VERTEX_FORMAT_USHORT3_NORM:
1739 case VERTEX_FORMAT_SSHORT3_INT:
1740 case VERTEX_FORMAT_USHORT3_INT:
1741 case VERTEX_FORMAT_HALF3:
1742 return 6;
1743
1744 case VERTEX_FORMAT_SSHORT4:
1745 case VERTEX_FORMAT_SSHORT4_NORM:
1746 case VERTEX_FORMAT_USHORT4:
1747 case VERTEX_FORMAT_USHORT4_NORM:
1748 case VERTEX_FORMAT_SSHORT4_INT:
1749 case VERTEX_FORMAT_USHORT4_INT:
1750 case VERTEX_FORMAT_SINT2:
1751 case VERTEX_FORMAT_SINT2_NORM:
1752 case VERTEX_FORMAT_UINT2:
1753 case VERTEX_FORMAT_UINT2_NORM:
1754 case VERTEX_FORMAT_SINT2_INT:
1755 case VERTEX_FORMAT_UINT2_INT:
1756 case VERTEX_FORMAT_HALF4:
1757 case VERTEX_FORMAT_FIXED2:
1758 case VERTEX_FORMAT_FLOAT2:
1759 return 8;
1760
1761 case VERTEX_FORMAT_SINT3:
1762 case VERTEX_FORMAT_SINT3_NORM:
1763 case VERTEX_FORMAT_UINT3:
1764 case VERTEX_FORMAT_UINT3_NORM:
1765 case VERTEX_FORMAT_SINT3_INT:
1766 case VERTEX_FORMAT_UINT3_INT:
1767 case VERTEX_FORMAT_FIXED3:
1768 case VERTEX_FORMAT_FLOAT3:
1769 return 12;
1770
1771 case VERTEX_FORMAT_SINT4:
1772 case VERTEX_FORMAT_SINT4_NORM:
1773 case VERTEX_FORMAT_UINT4:
1774 case VERTEX_FORMAT_UINT4_NORM:
1775 case VERTEX_FORMAT_SINT4_INT:
1776 case VERTEX_FORMAT_UINT4_INT:
1777 case VERTEX_FORMAT_FIXED4:
1778 case VERTEX_FORMAT_FLOAT4:
1779 return 16;
1780
1781 case VERTEX_FORMAT_INVALID:
1782 default:
1783 UNREACHABLE();
1784 return 0;
1785 }
1786}
1787
Jamie Madilld3dfda22015-07-06 08:28:49 -04001788VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1789 : type(typeIn),
1790 normalized(normalizedIn),
1791 components(componentsIn),
1792 pureInteger(pureIntegerIn)
1793{
1794 // float -> !normalized
1795 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1796}
1797
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001798}