blob: dba699923220bbdcfb8b18171b3060f8f5892f85 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
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 Novikovd73f8522017-01-13 17:48:57 -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
Minmin Gong390208b2017-02-28 18:03:06 -0800621 // | Internal format | |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
622 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)));
623 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
624 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
625 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
626 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800627
Vincent Lang25ab4512016-05-13 18:13:59 +0200628 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400629 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
630 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);
631 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
632 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);
633 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
634 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
635 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
636 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);
637 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 +0200638
Geoff Lang9bbad182015-09-04 11:07:29 -0400639 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800640
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000641 return map;
642}
643
Geoff Lange4a492b2014-06-19 14:14:41 -0400644static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000645{
Geoff Lange4a492b2014-06-19 14:14:41 -0400646 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
647 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648}
649
Geoff Lange4a492b2014-06-19 14:14:41 -0400650static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400651{
652 FormatSet result;
653
Jamie Madillec0b5802016-07-04 13:11:59 -0400654 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400655 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400656 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400657 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400658 // TODO(jmadill): Fix this hack.
659 if (iter.first == GL_BGR565_ANGLEX)
660 continue;
661
662 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400663 }
664 }
665
666 return result;
667}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000668
Geoff Lang5d601382014-07-22 15:14:06 -0400669const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000670{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200671 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000672 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200673 case GL_UNSIGNED_BYTE:
674 case GL_BYTE:
675 {
676 static const Type info = GenTypeInfo(1, false);
677 return info;
678 }
679 case GL_UNSIGNED_SHORT:
680 case GL_SHORT:
681 case GL_HALF_FLOAT:
682 case GL_HALF_FLOAT_OES:
683 {
684 static const Type info = GenTypeInfo(2, false);
685 return info;
686 }
687 case GL_UNSIGNED_INT:
688 case GL_INT:
689 case GL_FLOAT:
690 {
691 static const Type info = GenTypeInfo(4, false);
692 return info;
693 }
694 case GL_UNSIGNED_SHORT_5_6_5:
695 case GL_UNSIGNED_SHORT_4_4_4_4:
696 case GL_UNSIGNED_SHORT_5_5_5_1:
697 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
698 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
699 {
700 static const Type info = GenTypeInfo(2, true);
701 return info;
702 }
703 case GL_UNSIGNED_INT_2_10_10_10_REV:
704 case GL_UNSIGNED_INT_24_8:
705 case GL_UNSIGNED_INT_10F_11F_11F_REV:
706 case GL_UNSIGNED_INT_5_9_9_9_REV:
707 {
708 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
709 static const Type info = GenTypeInfo(4, true);
710 return info;
711 }
712 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
713 {
714 static const Type info = GenTypeInfo(8, true);
715 return info;
716 }
717 default:
718 {
719 static const Type defaultInfo;
720 return defaultInfo;
721 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000722 }
723}
724
Geoff Lang5d601382014-07-22 15:14:06 -0400725const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000726{
Geoff Lang5d601382014-07-22 15:14:06 -0400727 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400728 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400729 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000730 {
Geoff Lang5d601382014-07-22 15:14:06 -0400731 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000732 }
733 else
734 {
Geoff Lang5d601382014-07-22 15:14:06 -0400735 static const InternalFormat defaultInternalFormat;
736 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737 }
738}
739
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400740GLuint InternalFormat::computePixelBytes(GLenum formatType) const
741{
742 const auto &typeInfo = GetTypeInfo(formatType);
743 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
744 return components * typeInfo.bytes;
745}
746
Corentin Wallez886de362016-09-27 10:49:35 -0400747ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400748 GLsizei width,
749 GLint alignment,
750 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000751{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700752 // Compressed images do not use pack/unpack parameters.
753 if (compressed)
754 {
755 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400756 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700757 }
758
Geoff Lang3f234062016-07-13 15:35:45 -0400759 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400760 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700761
762 ASSERT(alignment > 0 && isPow2(alignment));
763 CheckedNumeric<GLuint> checkedAlignment(alignment);
764 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
765 ANGLE_TRY_CHECKED_MATH(aligned);
766 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000767}
768
Corentin Wallez0e487192016-10-03 16:30:38 -0400769ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
770 GLint imageHeight,
771 GLuint rowPitch) const
772{
773 GLuint rows =
774 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
775 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
776
777 auto depthPitch = checkedRowPitch * rows;
778 ANGLE_TRY_CHECKED_MATH(depthPitch);
779 return depthPitch.ValueOrDie();
780}
781
Corentin Wallez886de362016-09-27 10:49:35 -0400782ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400783 GLsizei width,
784 GLsizei height,
785 GLint alignment,
786 GLint rowLength,
787 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000788{
Jamie Madille2e406c2016-06-02 13:04:10 -0400789 GLuint rowPitch = 0;
790 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400791 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000792}
793
Corentin Wallez886de362016-09-27 10:49:35 -0400794ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
795 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000796{
Jamie Madill513558d2016-06-02 13:04:11 -0400797 CheckedNumeric<GLuint> checkedWidth(size.width);
798 CheckedNumeric<GLuint> checkedHeight(size.height);
799 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700800 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
801 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400802
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700803 ASSERT(compressed);
804 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
805 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
806 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
807 ANGLE_TRY_CHECKED_MATH(bytes);
808 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000809}
810
Corentin Wallez886de362016-09-27 10:49:35 -0400811ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700812 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400813 const PixelStoreStateBase &state,
814 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400815{
Olli Etuaho989cac32016-06-08 16:18:49 -0700816 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
817 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400818 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
819 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
820 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700821 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
822 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400823 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700824 {
825 checkedSkipImagesBytes = 0;
826 }
827 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
828 checkedSkipPixels * checkedPixelBytes;
829 ANGLE_TRY_CHECKED_MATH(skipBytes);
830 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400831}
832
Corentin Wallez886de362016-09-27 10:49:35 -0400833ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
834 GLenum formatType,
835 const Extents &size,
836 const PixelStoreStateBase &state,
837 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400838{
Corentin Wallez886de362016-09-27 10:49:35 -0400839 GLuint rowPitch = 0;
840 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400841 rowPitch);
842
Corentin Wallez0e487192016-10-03 16:30:38 -0400843 GLuint depthPitch = 0;
844 if (is3D)
845 {
846 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
847 }
848
Corentin Wallez886de362016-09-27 10:49:35 -0400849 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700850 if (compressed)
851 {
Corentin Wallez886de362016-09-27 10:49:35 -0400852 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700853 }
Corentin Wallez886de362016-09-27 10:49:35 -0400854 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400855 {
Corentin Wallez886de362016-09-27 10:49:35 -0400856 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
857 checkedCopyBytes += size.width * bytes;
858
859 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
860 checkedCopyBytes += heightMinusOne * rowPitch;
861
862 if (is3D)
863 {
864 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
865 checkedCopyBytes += depthMinusOne * depthPitch;
866 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400867 }
868
Corentin Wallez886de362016-09-27 10:49:35 -0400869 CheckedNumeric<GLuint> checkedSkipBytes = 0;
870 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400871
872 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
873
874 ANGLE_TRY_CHECKED_MATH(endByte);
875 return endByte.ValueOrDie();
876}
877
Geoff Lang5d601382014-07-22 15:14:06 -0400878GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000879{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700880 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500881 if (formatInfo.pixelBytes > 0)
882 {
883 return internalFormat;
884 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400885 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000886}
887
Geoff Lange4a492b2014-06-19 14:14:41 -0400888const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400889{
Geoff Lange4a492b2014-06-19 14:14:41 -0400890 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400891 return formatSet;
892}
893
Jamie Madill09e2d932015-07-14 16:40:31 -0400894AttributeType GetAttributeType(GLenum enumValue)
895{
896 switch (enumValue)
897 {
898 case GL_FLOAT:
899 return ATTRIBUTE_FLOAT;
900 case GL_FLOAT_VEC2:
901 return ATTRIBUTE_VEC2;
902 case GL_FLOAT_VEC3:
903 return ATTRIBUTE_VEC3;
904 case GL_FLOAT_VEC4:
905 return ATTRIBUTE_VEC4;
906 case GL_INT:
907 return ATTRIBUTE_INT;
908 case GL_INT_VEC2:
909 return ATTRIBUTE_IVEC2;
910 case GL_INT_VEC3:
911 return ATTRIBUTE_IVEC3;
912 case GL_INT_VEC4:
913 return ATTRIBUTE_IVEC4;
914 case GL_UNSIGNED_INT:
915 return ATTRIBUTE_UINT;
916 case GL_UNSIGNED_INT_VEC2:
917 return ATTRIBUTE_UVEC2;
918 case GL_UNSIGNED_INT_VEC3:
919 return ATTRIBUTE_UVEC3;
920 case GL_UNSIGNED_INT_VEC4:
921 return ATTRIBUTE_UVEC4;
922 case GL_FLOAT_MAT2:
923 return ATTRIBUTE_MAT2;
924 case GL_FLOAT_MAT3:
925 return ATTRIBUTE_MAT3;
926 case GL_FLOAT_MAT4:
927 return ATTRIBUTE_MAT4;
928 case GL_FLOAT_MAT2x3:
929 return ATTRIBUTE_MAT2x3;
930 case GL_FLOAT_MAT2x4:
931 return ATTRIBUTE_MAT2x4;
932 case GL_FLOAT_MAT3x2:
933 return ATTRIBUTE_MAT3x2;
934 case GL_FLOAT_MAT3x4:
935 return ATTRIBUTE_MAT3x4;
936 case GL_FLOAT_MAT4x2:
937 return ATTRIBUTE_MAT4x2;
938 case GL_FLOAT_MAT4x3:
939 return ATTRIBUTE_MAT4x3;
940 default:
941 UNREACHABLE();
942 return ATTRIBUTE_FLOAT;
943 }
944}
945
Jamie Madilld3dfda22015-07-06 08:28:49 -0400946VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
947{
948 switch (type)
949 {
950 case GL_BYTE:
951 switch (components)
952 {
953 case 1:
954 if (pureInteger)
955 return VERTEX_FORMAT_SBYTE1_INT;
956 if (normalized)
957 return VERTEX_FORMAT_SBYTE1_NORM;
958 return VERTEX_FORMAT_SBYTE1;
959 case 2:
960 if (pureInteger)
961 return VERTEX_FORMAT_SBYTE2_INT;
962 if (normalized)
963 return VERTEX_FORMAT_SBYTE2_NORM;
964 return VERTEX_FORMAT_SBYTE2;
965 case 3:
966 if (pureInteger)
967 return VERTEX_FORMAT_SBYTE3_INT;
968 if (normalized)
969 return VERTEX_FORMAT_SBYTE3_NORM;
970 return VERTEX_FORMAT_SBYTE3;
971 case 4:
972 if (pureInteger)
973 return VERTEX_FORMAT_SBYTE4_INT;
974 if (normalized)
975 return VERTEX_FORMAT_SBYTE4_NORM;
976 return VERTEX_FORMAT_SBYTE4;
977 default:
978 UNREACHABLE();
979 break;
980 }
981 case GL_UNSIGNED_BYTE:
982 switch (components)
983 {
984 case 1:
985 if (pureInteger)
986 return VERTEX_FORMAT_UBYTE1_INT;
987 if (normalized)
988 return VERTEX_FORMAT_UBYTE1_NORM;
989 return VERTEX_FORMAT_UBYTE1;
990 case 2:
991 if (pureInteger)
992 return VERTEX_FORMAT_UBYTE2_INT;
993 if (normalized)
994 return VERTEX_FORMAT_UBYTE2_NORM;
995 return VERTEX_FORMAT_UBYTE2;
996 case 3:
997 if (pureInteger)
998 return VERTEX_FORMAT_UBYTE3_INT;
999 if (normalized)
1000 return VERTEX_FORMAT_UBYTE3_NORM;
1001 return VERTEX_FORMAT_UBYTE3;
1002 case 4:
1003 if (pureInteger)
1004 return VERTEX_FORMAT_UBYTE4_INT;
1005 if (normalized)
1006 return VERTEX_FORMAT_UBYTE4_NORM;
1007 return VERTEX_FORMAT_UBYTE4;
1008 default:
1009 UNREACHABLE();
1010 break;
1011 }
1012 case GL_SHORT:
1013 switch (components)
1014 {
1015 case 1:
1016 if (pureInteger)
1017 return VERTEX_FORMAT_SSHORT1_INT;
1018 if (normalized)
1019 return VERTEX_FORMAT_SSHORT1_NORM;
1020 return VERTEX_FORMAT_SSHORT1;
1021 case 2:
1022 if (pureInteger)
1023 return VERTEX_FORMAT_SSHORT2_INT;
1024 if (normalized)
1025 return VERTEX_FORMAT_SSHORT2_NORM;
1026 return VERTEX_FORMAT_SSHORT2;
1027 case 3:
1028 if (pureInteger)
1029 return VERTEX_FORMAT_SSHORT3_INT;
1030 if (normalized)
1031 return VERTEX_FORMAT_SSHORT3_NORM;
1032 return VERTEX_FORMAT_SSHORT3;
1033 case 4:
1034 if (pureInteger)
1035 return VERTEX_FORMAT_SSHORT4_INT;
1036 if (normalized)
1037 return VERTEX_FORMAT_SSHORT4_NORM;
1038 return VERTEX_FORMAT_SSHORT4;
1039 default:
1040 UNREACHABLE();
1041 break;
1042 }
1043 case GL_UNSIGNED_SHORT:
1044 switch (components)
1045 {
1046 case 1:
1047 if (pureInteger)
1048 return VERTEX_FORMAT_USHORT1_INT;
1049 if (normalized)
1050 return VERTEX_FORMAT_USHORT1_NORM;
1051 return VERTEX_FORMAT_USHORT1;
1052 case 2:
1053 if (pureInteger)
1054 return VERTEX_FORMAT_USHORT2_INT;
1055 if (normalized)
1056 return VERTEX_FORMAT_USHORT2_NORM;
1057 return VERTEX_FORMAT_USHORT2;
1058 case 3:
1059 if (pureInteger)
1060 return VERTEX_FORMAT_USHORT3_INT;
1061 if (normalized)
1062 return VERTEX_FORMAT_USHORT3_NORM;
1063 return VERTEX_FORMAT_USHORT3;
1064 case 4:
1065 if (pureInteger)
1066 return VERTEX_FORMAT_USHORT4_INT;
1067 if (normalized)
1068 return VERTEX_FORMAT_USHORT4_NORM;
1069 return VERTEX_FORMAT_USHORT4;
1070 default:
1071 UNREACHABLE();
1072 break;
1073 }
1074 case GL_INT:
1075 switch (components)
1076 {
1077 case 1:
1078 if (pureInteger)
1079 return VERTEX_FORMAT_SINT1_INT;
1080 if (normalized)
1081 return VERTEX_FORMAT_SINT1_NORM;
1082 return VERTEX_FORMAT_SINT1;
1083 case 2:
1084 if (pureInteger)
1085 return VERTEX_FORMAT_SINT2_INT;
1086 if (normalized)
1087 return VERTEX_FORMAT_SINT2_NORM;
1088 return VERTEX_FORMAT_SINT2;
1089 case 3:
1090 if (pureInteger)
1091 return VERTEX_FORMAT_SINT3_INT;
1092 if (normalized)
1093 return VERTEX_FORMAT_SINT3_NORM;
1094 return VERTEX_FORMAT_SINT3;
1095 case 4:
1096 if (pureInteger)
1097 return VERTEX_FORMAT_SINT4_INT;
1098 if (normalized)
1099 return VERTEX_FORMAT_SINT4_NORM;
1100 return VERTEX_FORMAT_SINT4;
1101 default:
1102 UNREACHABLE();
1103 break;
1104 }
1105 case GL_UNSIGNED_INT:
1106 switch (components)
1107 {
1108 case 1:
1109 if (pureInteger)
1110 return VERTEX_FORMAT_UINT1_INT;
1111 if (normalized)
1112 return VERTEX_FORMAT_UINT1_NORM;
1113 return VERTEX_FORMAT_UINT1;
1114 case 2:
1115 if (pureInteger)
1116 return VERTEX_FORMAT_UINT2_INT;
1117 if (normalized)
1118 return VERTEX_FORMAT_UINT2_NORM;
1119 return VERTEX_FORMAT_UINT2;
1120 case 3:
1121 if (pureInteger)
1122 return VERTEX_FORMAT_UINT3_INT;
1123 if (normalized)
1124 return VERTEX_FORMAT_UINT3_NORM;
1125 return VERTEX_FORMAT_UINT3;
1126 case 4:
1127 if (pureInteger)
1128 return VERTEX_FORMAT_UINT4_INT;
1129 if (normalized)
1130 return VERTEX_FORMAT_UINT4_NORM;
1131 return VERTEX_FORMAT_UINT4;
1132 default:
1133 UNREACHABLE();
1134 break;
1135 }
1136 case GL_FLOAT:
1137 switch (components)
1138 {
1139 case 1:
1140 return VERTEX_FORMAT_FLOAT1;
1141 case 2:
1142 return VERTEX_FORMAT_FLOAT2;
1143 case 3:
1144 return VERTEX_FORMAT_FLOAT3;
1145 case 4:
1146 return VERTEX_FORMAT_FLOAT4;
1147 default:
1148 UNREACHABLE();
1149 break;
1150 }
1151 case GL_HALF_FLOAT:
1152 switch (components)
1153 {
1154 case 1:
1155 return VERTEX_FORMAT_HALF1;
1156 case 2:
1157 return VERTEX_FORMAT_HALF2;
1158 case 3:
1159 return VERTEX_FORMAT_HALF3;
1160 case 4:
1161 return VERTEX_FORMAT_HALF4;
1162 default:
1163 UNREACHABLE();
1164 break;
1165 }
1166 case GL_FIXED:
1167 switch (components)
1168 {
1169 case 1:
1170 return VERTEX_FORMAT_FIXED1;
1171 case 2:
1172 return VERTEX_FORMAT_FIXED2;
1173 case 3:
1174 return VERTEX_FORMAT_FIXED3;
1175 case 4:
1176 return VERTEX_FORMAT_FIXED4;
1177 default:
1178 UNREACHABLE();
1179 break;
1180 }
1181 case GL_INT_2_10_10_10_REV:
1182 if (pureInteger)
1183 return VERTEX_FORMAT_SINT210_INT;
1184 if (normalized)
1185 return VERTEX_FORMAT_SINT210_NORM;
1186 return VERTEX_FORMAT_SINT210;
1187 case GL_UNSIGNED_INT_2_10_10_10_REV:
1188 if (pureInteger)
1189 return VERTEX_FORMAT_UINT210_INT;
1190 if (normalized)
1191 return VERTEX_FORMAT_UINT210_NORM;
1192 return VERTEX_FORMAT_UINT210;
1193 default:
1194 UNREACHABLE();
1195 break;
1196 }
1197 return VERTEX_FORMAT_UBYTE1;
1198}
1199
1200VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1201{
1202 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1203}
1204
1205VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1206{
1207 if (!attrib.enabled)
1208 {
1209 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1210 }
1211 return GetVertexFormatType(attrib);
1212}
1213
1214const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1215{
1216 switch (vertexFormatType)
1217 {
1218 case VERTEX_FORMAT_SBYTE1:
1219 {
1220 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1221 return format;
1222 }
1223 case VERTEX_FORMAT_SBYTE1_NORM:
1224 {
1225 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1226 return format;
1227 }
1228 case VERTEX_FORMAT_SBYTE2:
1229 {
1230 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1231 return format;
1232 }
1233 case VERTEX_FORMAT_SBYTE2_NORM:
1234 {
1235 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1236 return format;
1237 }
1238 case VERTEX_FORMAT_SBYTE3:
1239 {
1240 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1241 return format;
1242 }
1243 case VERTEX_FORMAT_SBYTE3_NORM:
1244 {
1245 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1246 return format;
1247 }
1248 case VERTEX_FORMAT_SBYTE4:
1249 {
1250 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1251 return format;
1252 }
1253 case VERTEX_FORMAT_SBYTE4_NORM:
1254 {
1255 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1256 return format;
1257 }
1258 case VERTEX_FORMAT_UBYTE1:
1259 {
1260 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1261 return format;
1262 }
1263 case VERTEX_FORMAT_UBYTE1_NORM:
1264 {
1265 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1266 return format;
1267 }
1268 case VERTEX_FORMAT_UBYTE2:
1269 {
1270 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1271 return format;
1272 }
1273 case VERTEX_FORMAT_UBYTE2_NORM:
1274 {
1275 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1276 return format;
1277 }
1278 case VERTEX_FORMAT_UBYTE3:
1279 {
1280 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1281 return format;
1282 }
1283 case VERTEX_FORMAT_UBYTE3_NORM:
1284 {
1285 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1286 return format;
1287 }
1288 case VERTEX_FORMAT_UBYTE4:
1289 {
1290 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1291 return format;
1292 }
1293 case VERTEX_FORMAT_UBYTE4_NORM:
1294 {
1295 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1296 return format;
1297 }
1298 case VERTEX_FORMAT_SSHORT1:
1299 {
1300 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1301 return format;
1302 }
1303 case VERTEX_FORMAT_SSHORT1_NORM:
1304 {
1305 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1306 return format;
1307 }
1308 case VERTEX_FORMAT_SSHORT2:
1309 {
1310 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1311 return format;
1312 }
1313 case VERTEX_FORMAT_SSHORT2_NORM:
1314 {
1315 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1316 return format;
1317 }
1318 case VERTEX_FORMAT_SSHORT3:
1319 {
1320 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1321 return format;
1322 }
1323 case VERTEX_FORMAT_SSHORT3_NORM:
1324 {
1325 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1326 return format;
1327 }
1328 case VERTEX_FORMAT_SSHORT4:
1329 {
1330 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1331 return format;
1332 }
1333 case VERTEX_FORMAT_SSHORT4_NORM:
1334 {
1335 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1336 return format;
1337 }
1338 case VERTEX_FORMAT_USHORT1:
1339 {
1340 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1341 return format;
1342 }
1343 case VERTEX_FORMAT_USHORT1_NORM:
1344 {
1345 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1346 return format;
1347 }
1348 case VERTEX_FORMAT_USHORT2:
1349 {
1350 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1351 return format;
1352 }
1353 case VERTEX_FORMAT_USHORT2_NORM:
1354 {
1355 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1356 return format;
1357 }
1358 case VERTEX_FORMAT_USHORT3:
1359 {
1360 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1361 return format;
1362 }
1363 case VERTEX_FORMAT_USHORT3_NORM:
1364 {
1365 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1366 return format;
1367 }
1368 case VERTEX_FORMAT_USHORT4:
1369 {
1370 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1371 return format;
1372 }
1373 case VERTEX_FORMAT_USHORT4_NORM:
1374 {
1375 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1376 return format;
1377 }
1378 case VERTEX_FORMAT_SINT1:
1379 {
1380 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1381 return format;
1382 }
1383 case VERTEX_FORMAT_SINT1_NORM:
1384 {
1385 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1386 return format;
1387 }
1388 case VERTEX_FORMAT_SINT2:
1389 {
1390 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1391 return format;
1392 }
1393 case VERTEX_FORMAT_SINT2_NORM:
1394 {
1395 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1396 return format;
1397 }
1398 case VERTEX_FORMAT_SINT3:
1399 {
1400 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1401 return format;
1402 }
1403 case VERTEX_FORMAT_SINT3_NORM:
1404 {
1405 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1406 return format;
1407 }
1408 case VERTEX_FORMAT_SINT4:
1409 {
1410 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1411 return format;
1412 }
1413 case VERTEX_FORMAT_SINT4_NORM:
1414 {
1415 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1416 return format;
1417 }
1418 case VERTEX_FORMAT_UINT1:
1419 {
1420 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1421 return format;
1422 }
1423 case VERTEX_FORMAT_UINT1_NORM:
1424 {
1425 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1426 return format;
1427 }
1428 case VERTEX_FORMAT_UINT2:
1429 {
1430 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1431 return format;
1432 }
1433 case VERTEX_FORMAT_UINT2_NORM:
1434 {
1435 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1436 return format;
1437 }
1438 case VERTEX_FORMAT_UINT3:
1439 {
1440 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1441 return format;
1442 }
1443 case VERTEX_FORMAT_UINT3_NORM:
1444 {
1445 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1446 return format;
1447 }
1448 case VERTEX_FORMAT_UINT4:
1449 {
1450 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1451 return format;
1452 }
1453 case VERTEX_FORMAT_UINT4_NORM:
1454 {
1455 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1456 return format;
1457 }
1458 case VERTEX_FORMAT_SBYTE1_INT:
1459 {
1460 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1461 return format;
1462 }
1463 case VERTEX_FORMAT_SBYTE2_INT:
1464 {
1465 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1466 return format;
1467 }
1468 case VERTEX_FORMAT_SBYTE3_INT:
1469 {
1470 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1471 return format;
1472 }
1473 case VERTEX_FORMAT_SBYTE4_INT:
1474 {
1475 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1476 return format;
1477 }
1478 case VERTEX_FORMAT_UBYTE1_INT:
1479 {
1480 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1481 return format;
1482 }
1483 case VERTEX_FORMAT_UBYTE2_INT:
1484 {
1485 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1486 return format;
1487 }
1488 case VERTEX_FORMAT_UBYTE3_INT:
1489 {
1490 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1491 return format;
1492 }
1493 case VERTEX_FORMAT_UBYTE4_INT:
1494 {
1495 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1496 return format;
1497 }
1498 case VERTEX_FORMAT_SSHORT1_INT:
1499 {
1500 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1501 return format;
1502 }
1503 case VERTEX_FORMAT_SSHORT2_INT:
1504 {
1505 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1506 return format;
1507 }
1508 case VERTEX_FORMAT_SSHORT3_INT:
1509 {
1510 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1511 return format;
1512 }
1513 case VERTEX_FORMAT_SSHORT4_INT:
1514 {
1515 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1516 return format;
1517 }
1518 case VERTEX_FORMAT_USHORT1_INT:
1519 {
1520 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1521 return format;
1522 }
1523 case VERTEX_FORMAT_USHORT2_INT:
1524 {
1525 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1526 return format;
1527 }
1528 case VERTEX_FORMAT_USHORT3_INT:
1529 {
1530 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1531 return format;
1532 }
1533 case VERTEX_FORMAT_USHORT4_INT:
1534 {
1535 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1536 return format;
1537 }
1538 case VERTEX_FORMAT_SINT1_INT:
1539 {
1540 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1541 return format;
1542 }
1543 case VERTEX_FORMAT_SINT2_INT:
1544 {
1545 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1546 return format;
1547 }
1548 case VERTEX_FORMAT_SINT3_INT:
1549 {
1550 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1551 return format;
1552 }
1553 case VERTEX_FORMAT_SINT4_INT:
1554 {
1555 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1556 return format;
1557 }
1558 case VERTEX_FORMAT_UINT1_INT:
1559 {
1560 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1561 return format;
1562 }
1563 case VERTEX_FORMAT_UINT2_INT:
1564 {
1565 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1566 return format;
1567 }
1568 case VERTEX_FORMAT_UINT3_INT:
1569 {
1570 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1571 return format;
1572 }
1573 case VERTEX_FORMAT_UINT4_INT:
1574 {
1575 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1576 return format;
1577 }
1578 case VERTEX_FORMAT_FIXED1:
1579 {
1580 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1581 return format;
1582 }
1583 case VERTEX_FORMAT_FIXED2:
1584 {
1585 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1586 return format;
1587 }
1588 case VERTEX_FORMAT_FIXED3:
1589 {
1590 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1591 return format;
1592 }
1593 case VERTEX_FORMAT_FIXED4:
1594 {
1595 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1596 return format;
1597 }
1598 case VERTEX_FORMAT_HALF1:
1599 {
1600 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1601 return format;
1602 }
1603 case VERTEX_FORMAT_HALF2:
1604 {
1605 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1606 return format;
1607 }
1608 case VERTEX_FORMAT_HALF3:
1609 {
1610 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1611 return format;
1612 }
1613 case VERTEX_FORMAT_HALF4:
1614 {
1615 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1616 return format;
1617 }
1618 case VERTEX_FORMAT_FLOAT1:
1619 {
1620 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1621 return format;
1622 }
1623 case VERTEX_FORMAT_FLOAT2:
1624 {
1625 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1626 return format;
1627 }
1628 case VERTEX_FORMAT_FLOAT3:
1629 {
1630 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1631 return format;
1632 }
1633 case VERTEX_FORMAT_FLOAT4:
1634 {
1635 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1636 return format;
1637 }
1638 case VERTEX_FORMAT_SINT210:
1639 {
1640 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1641 return format;
1642 }
1643 case VERTEX_FORMAT_UINT210:
1644 {
1645 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1646 return format;
1647 }
1648 case VERTEX_FORMAT_SINT210_NORM:
1649 {
1650 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1651 return format;
1652 }
1653 case VERTEX_FORMAT_UINT210_NORM:
1654 {
1655 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1656 return format;
1657 }
1658 case VERTEX_FORMAT_SINT210_INT:
1659 {
1660 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1661 return format;
1662 }
1663 case VERTEX_FORMAT_UINT210_INT:
1664 {
1665 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1666 return format;
1667 }
1668 default:
1669 {
1670 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1671 return format;
1672 }
1673 }
1674}
1675
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001676size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1677{
1678 switch (vertexFormatType)
1679 {
1680 case VERTEX_FORMAT_SBYTE1:
1681 case VERTEX_FORMAT_SBYTE1_NORM:
1682 case VERTEX_FORMAT_UBYTE1:
1683 case VERTEX_FORMAT_UBYTE1_NORM:
1684 case VERTEX_FORMAT_SBYTE1_INT:
1685 case VERTEX_FORMAT_UBYTE1_INT:
1686 return 1;
1687
1688 case VERTEX_FORMAT_SBYTE2:
1689 case VERTEX_FORMAT_SBYTE2_NORM:
1690 case VERTEX_FORMAT_UBYTE2:
1691 case VERTEX_FORMAT_UBYTE2_NORM:
1692 case VERTEX_FORMAT_SBYTE2_INT:
1693 case VERTEX_FORMAT_UBYTE2_INT:
1694 case VERTEX_FORMAT_SSHORT1:
1695 case VERTEX_FORMAT_SSHORT1_NORM:
1696 case VERTEX_FORMAT_USHORT1:
1697 case VERTEX_FORMAT_USHORT1_NORM:
1698 case VERTEX_FORMAT_SSHORT1_INT:
1699 case VERTEX_FORMAT_USHORT1_INT:
1700 case VERTEX_FORMAT_HALF1:
1701 return 2;
1702
1703 case VERTEX_FORMAT_SBYTE3:
1704 case VERTEX_FORMAT_SBYTE3_NORM:
1705 case VERTEX_FORMAT_UBYTE3:
1706 case VERTEX_FORMAT_UBYTE3_NORM:
1707 case VERTEX_FORMAT_SBYTE3_INT:
1708 case VERTEX_FORMAT_UBYTE3_INT:
1709 return 3;
1710
1711 case VERTEX_FORMAT_SBYTE4:
1712 case VERTEX_FORMAT_SBYTE4_NORM:
1713 case VERTEX_FORMAT_UBYTE4:
1714 case VERTEX_FORMAT_UBYTE4_NORM:
1715 case VERTEX_FORMAT_SBYTE4_INT:
1716 case VERTEX_FORMAT_UBYTE4_INT:
1717 case VERTEX_FORMAT_SSHORT2:
1718 case VERTEX_FORMAT_SSHORT2_NORM:
1719 case VERTEX_FORMAT_USHORT2:
1720 case VERTEX_FORMAT_USHORT2_NORM:
1721 case VERTEX_FORMAT_SSHORT2_INT:
1722 case VERTEX_FORMAT_USHORT2_INT:
1723 case VERTEX_FORMAT_SINT1:
1724 case VERTEX_FORMAT_SINT1_NORM:
1725 case VERTEX_FORMAT_UINT1:
1726 case VERTEX_FORMAT_UINT1_NORM:
1727 case VERTEX_FORMAT_SINT1_INT:
1728 case VERTEX_FORMAT_UINT1_INT:
1729 case VERTEX_FORMAT_HALF2:
1730 case VERTEX_FORMAT_FIXED1:
1731 case VERTEX_FORMAT_FLOAT1:
1732 case VERTEX_FORMAT_SINT210:
1733 case VERTEX_FORMAT_UINT210:
1734 case VERTEX_FORMAT_SINT210_NORM:
1735 case VERTEX_FORMAT_UINT210_NORM:
1736 case VERTEX_FORMAT_SINT210_INT:
1737 case VERTEX_FORMAT_UINT210_INT:
1738 return 4;
1739
1740 case VERTEX_FORMAT_SSHORT3:
1741 case VERTEX_FORMAT_SSHORT3_NORM:
1742 case VERTEX_FORMAT_USHORT3:
1743 case VERTEX_FORMAT_USHORT3_NORM:
1744 case VERTEX_FORMAT_SSHORT3_INT:
1745 case VERTEX_FORMAT_USHORT3_INT:
1746 case VERTEX_FORMAT_HALF3:
1747 return 6;
1748
1749 case VERTEX_FORMAT_SSHORT4:
1750 case VERTEX_FORMAT_SSHORT4_NORM:
1751 case VERTEX_FORMAT_USHORT4:
1752 case VERTEX_FORMAT_USHORT4_NORM:
1753 case VERTEX_FORMAT_SSHORT4_INT:
1754 case VERTEX_FORMAT_USHORT4_INT:
1755 case VERTEX_FORMAT_SINT2:
1756 case VERTEX_FORMAT_SINT2_NORM:
1757 case VERTEX_FORMAT_UINT2:
1758 case VERTEX_FORMAT_UINT2_NORM:
1759 case VERTEX_FORMAT_SINT2_INT:
1760 case VERTEX_FORMAT_UINT2_INT:
1761 case VERTEX_FORMAT_HALF4:
1762 case VERTEX_FORMAT_FIXED2:
1763 case VERTEX_FORMAT_FLOAT2:
1764 return 8;
1765
1766 case VERTEX_FORMAT_SINT3:
1767 case VERTEX_FORMAT_SINT3_NORM:
1768 case VERTEX_FORMAT_UINT3:
1769 case VERTEX_FORMAT_UINT3_NORM:
1770 case VERTEX_FORMAT_SINT3_INT:
1771 case VERTEX_FORMAT_UINT3_INT:
1772 case VERTEX_FORMAT_FIXED3:
1773 case VERTEX_FORMAT_FLOAT3:
1774 return 12;
1775
1776 case VERTEX_FORMAT_SINT4:
1777 case VERTEX_FORMAT_SINT4_NORM:
1778 case VERTEX_FORMAT_UINT4:
1779 case VERTEX_FORMAT_UINT4_NORM:
1780 case VERTEX_FORMAT_SINT4_INT:
1781 case VERTEX_FORMAT_UINT4_INT:
1782 case VERTEX_FORMAT_FIXED4:
1783 case VERTEX_FORMAT_FLOAT4:
1784 return 16;
1785
1786 case VERTEX_FORMAT_INVALID:
1787 default:
1788 UNREACHABLE();
1789 return 0;
1790 }
1791}
1792
Jamie Madilld3dfda22015-07-06 08:28:49 -04001793VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1794 : type(typeIn),
1795 normalized(normalizedIn),
1796 components(componentsIn),
1797 pureInteger(pureIntegerIn)
1798{
1799 // float -> !normalized
1800 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1801}
1802
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001803}