blob: 6692d3fa4ba50aeacee6b55c1c7b21b30a8f6741 [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
Yuly Novikovafcc41c2016-12-13 12:59:39 -05009#include "common/mathutil.h"
Jamie Madill6a6b09c2017-01-12 21:52:29 +000010#include "libANGLE/formatutils.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050011#include "libANGLE/Context.h"
12#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000013
Jamie Madille2e406c2016-06-02 13:04:10 -040014using namespace angle;
15
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000016namespace gl
17{
18
19// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
20// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
21// format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040022GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000023
Jamie Madilled4d3422016-10-03 15:45:35 -040024namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000025{
Jamie Madilla3944d42016-07-22 22:13:26 -040026typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
27typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
28
29} // anonymous namespace
30
31FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
32{
33}
34
35FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
36{
37}
38
39bool FormatType::operator<(const FormatType &other) const
40{
41 if (format != other.format)
42 return format < other.format;
43 return type < other.type;
44}
45
Geoff Lang5d601382014-07-22 15:14:06 -040046Type::Type()
47 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020048 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -040049 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040050{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000051}
52
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020053static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000054{
Geoff Lang5d601382014-07-22 15:14:06 -040055 Type info;
56 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020057 GLuint i = 0;
58 while ((1u << i) < bytes)
59 {
60 ++i;
61 }
62 info.bytesShift = i;
63 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040064 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020065 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040066}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000067
Geoff Lang5d601382014-07-22 15:14:06 -040068bool operator<(const Type& a, const Type& b)
69{
70 return memcmp(&a, &b, sizeof(Type)) < 0;
71}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000072
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040074static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075{
Geoff Lang493daf52014-07-03 13:38:44 -040076 return true;
77}
78
Geoff Langeb66a6e2016-10-31 13:06:12 -040079static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000080{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081 return false;
82}
83
Geoff Langeb66a6e2016-10-31 13:06:12 -040084template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
85static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040086{
Geoff Langeb66a6e2016-10-31 13:06:12 -040087 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040088}
89
Geoff Langcec35902014-04-16 10:52:36 -040090// Pointer to a boolean memeber of the Extensions struct
91typedef bool(Extensions::*ExtensionBool);
92
93// Check support for a single extension
94template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040095static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040096{
Geoff Lange4a492b2014-06-19 14:14:41 -040097 return extensions.*bool1;
98}
99
100// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400101template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
102static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400103{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400104 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
105 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400106}
107
108// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400109template <GLuint minCoreGLMajorVersion,
110 GLuint minCoreGLMinorVersion,
111 ExtensionBool bool1,
112 ExtensionBool bool2>
113static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400114{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400115 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
116 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400117}
118
119// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400120template <GLuint minCoreGLMajorVersion,
121 GLuint minCoreGLMinorVersion,
122 ExtensionBool bool1,
123 ExtensionBool bool2>
124static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400125{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400126 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
127 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400128}
129
130// Check support for two extensions
131template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400132static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400133{
Geoff Langabce7622014-09-19 16:13:00 -0400134 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400135}
136
Geoff Lang60ad73d2015-10-23 10:08:44 -0400137// Check support for either of two extensions
138template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400139static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400140{
141 return extensions.*bool1 || extensions.*bool2;
142}
143
Jamie Madillcd089732015-12-17 09:53:09 -0500144// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400145static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500146{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400147 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500148}
149
Geoff Langeb66a6e2016-10-31 13:06:12 -0400150static bool HalfFloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500151{
152 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
153}
154
155// Special function for half float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400156static bool HalfFloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500157{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400158 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500159}
160
Geoff Langeb66a6e2016-10-31 13:06:12 -0400161static bool HalfFloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500162{
163 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
164}
165
166// Special function for float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400167static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500168{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400169 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500170}
171
Geoff Langeb66a6e2016-10-31 13:06:12 -0400172static bool FloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500173{
174 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
175 return FloatSupport(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400176 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500177}
178
179// Special function for float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400180static bool FloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500181{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400182 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500183}
184
Geoff Langeb66a6e2016-10-31 13:06:12 -0400185static bool FloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500186{
187 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
188 return FloatSupportRG(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400189 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500190}
191
Geoff Lang5d601382014-07-22 15:14:06 -0400192InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400193 : internalFormat(GL_NONE),
194 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400195 greenBits(0),
196 blueBits(0),
197 luminanceBits(0),
198 alphaBits(0),
199 sharedBits(0),
200 depthBits(0),
201 stencilBits(0),
202 pixelBytes(0),
203 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400204 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400205 compressedBlockWidth(0),
206 compressedBlockHeight(0),
207 format(GL_NONE),
208 type(GL_NONE),
209 componentType(GL_NONE),
210 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400211 textureSupport(NeverSupported),
212 renderSupport(NeverSupported),
213 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000214{
Geoff Lang5d601382014-07-22 15:14:06 -0400215}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000216
Jamie Madilla3944d42016-07-22 22:13:26 -0400217bool InternalFormat::isLUMA() const
218{
219 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
220 (luminanceBits + alphaBits) > 0);
221}
222
Geoff Langf607c602016-09-21 11:46:48 -0400223GLenum InternalFormat::getReadPixelsFormat() const
224{
225 return format;
226}
227
228GLenum InternalFormat::getReadPixelsType() const
229{
230 switch (type)
231 {
232 case GL_HALF_FLOAT:
233 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
234 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
235 // OES_texture_half_float
236 return GL_HALF_FLOAT_OES;
237
238 default:
239 return type;
240 }
241}
242
Jamie Madilla3944d42016-07-22 22:13:26 -0400243Format::Format(GLenum internalFormat) : Format(GetInternalFormatInfo(internalFormat))
244{
245}
246
247Format::Format(const InternalFormat &internalFormat)
248 : info(&internalFormat), format(info->format), type(info->type), sized(true)
249{
250 ASSERT((info->pixelBytes > 0 && format != GL_NONE && type != GL_NONE) ||
251 internalFormat.format == GL_NONE);
252}
253
254Format::Format(GLenum internalFormat, GLenum format, GLenum type)
255 : info(nullptr), format(format), type(type), sized(false)
256{
257 const auto &plainInfo = GetInternalFormatInfo(internalFormat);
258 sized = plainInfo.pixelBytes > 0;
259 info = (sized ? &plainInfo : &GetInternalFormatInfo(GetSizedFormatInternal(format, type)));
260 ASSERT(format == GL_NONE || info->pixelBytes > 0);
261}
262
263Format::Format(const Format &other) = default;
264Format &Format::operator=(const Format &other) = default;
265
266GLenum Format::asSized() const
267{
268 return sized ? info->internalFormat : GetSizedFormatInternal(format, type);
269}
270
271bool Format::valid() const
272{
273 return info->format != GL_NONE;
274}
275
276// static
277bool Format::SameSized(const Format &a, const Format &b)
278{
279 return (a.info == b.info);
280}
281
282// static
283Format Format::Invalid()
284{
285 static Format invalid(GL_NONE, GL_NONE, GL_NONE);
286 return invalid;
287}
288
289bool InternalFormat::operator==(const InternalFormat &other) const
290{
291 // We assume there are no duplicates.
292 ASSERT((this == &other) == (internalFormat == other.internalFormat));
293 return internalFormat == other.internalFormat;
294}
295
296bool 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
303static void AddUnsizedFormat(InternalFormatInfoMap *map,
304 GLenum internalFormat,
305 GLenum format,
306 InternalFormat::SupportCheckFunction textureSupport,
307 InternalFormat::SupportCheckFunction renderSupport,
308 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400309{
310 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400311 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400312 formatInfo.format = format;
313 formatInfo.textureSupport = textureSupport;
314 formatInfo.renderSupport = renderSupport;
315 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400316 ASSERT(map->count(internalFormat) == 0);
317 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400318}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000319
Jamie Madilla3944d42016-07-22 22:13:26 -0400320void AddRGBAFormat(InternalFormatInfoMap *map,
321 GLenum internalFormat,
322 GLuint red,
323 GLuint green,
324 GLuint blue,
325 GLuint alpha,
326 GLuint shared,
327 GLenum format,
328 GLenum type,
329 GLenum componentType,
330 bool srgb,
331 InternalFormat::SupportCheckFunction textureSupport,
332 InternalFormat::SupportCheckFunction renderSupport,
333 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400334{
335 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400336 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400337 formatInfo.redBits = red;
338 formatInfo.greenBits = green;
339 formatInfo.blueBits = blue;
340 formatInfo.alphaBits = alpha;
341 formatInfo.sharedBits = shared;
342 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
343 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
344 formatInfo.format = format;
345 formatInfo.type = type;
346 formatInfo.componentType = componentType;
347 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
348 formatInfo.textureSupport = textureSupport;
349 formatInfo.renderSupport = renderSupport;
350 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400351 ASSERT(map->count(internalFormat) == 0);
352 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400353}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000354
Geoff Lang5d601382014-07-22 15:14:06 -0400355static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
356 InternalFormat::SupportCheckFunction textureSupport,
357 InternalFormat::SupportCheckFunction renderSupport,
358 InternalFormat::SupportCheckFunction filterSupport)
359{
360 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400361 formatInfo.internalFormat = GetSizedFormatInternal(format, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400362 formatInfo.luminanceBits = luminance;
363 formatInfo.alphaBits = alpha;
364 formatInfo.pixelBytes = (luminance + alpha) / 8;
365 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
366 formatInfo.format = format;
367 formatInfo.type = type;
368 formatInfo.componentType = componentType;
369 formatInfo.colorEncoding = GL_LINEAR;
370 formatInfo.textureSupport = textureSupport;
371 formatInfo.renderSupport = renderSupport;
372 formatInfo.filterSupport = filterSupport;
373 return formatInfo;
374}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000375
Jamie Madilla3944d42016-07-22 22:13:26 -0400376void AddDepthStencilFormat(InternalFormatInfoMap *map,
377 GLenum internalFormat,
378 GLuint depthBits,
379 GLuint stencilBits,
380 GLuint unusedBits,
381 GLenum format,
382 GLenum type,
383 GLenum componentType,
384 InternalFormat::SupportCheckFunction textureSupport,
385 InternalFormat::SupportCheckFunction renderSupport,
386 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400387{
388 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400389 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400390 formatInfo.depthBits = depthBits;
391 formatInfo.stencilBits = stencilBits;
392 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
393 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
394 formatInfo.format = format;
395 formatInfo.type = type;
396 formatInfo.componentType = componentType;
397 formatInfo.colorEncoding = GL_LINEAR;
398 formatInfo.textureSupport = textureSupport;
399 formatInfo.renderSupport = renderSupport;
400 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400401 ASSERT(map->count(internalFormat) == 0);
402 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400403}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000404
Geoff Lang5d601382014-07-22 15:14:06 -0400405static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
406 GLuint componentCount, GLenum format, GLenum type, bool srgb,
407 InternalFormat::SupportCheckFunction textureSupport,
408 InternalFormat::SupportCheckFunction renderSupport,
409 InternalFormat::SupportCheckFunction filterSupport)
410{
411 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400412 formatInfo.internalFormat = format;
Geoff Lang5d601382014-07-22 15:14:06 -0400413 formatInfo.compressedBlockWidth = compressedBlockWidth;
414 formatInfo.compressedBlockHeight = compressedBlockHeight;
415 formatInfo.pixelBytes = compressedBlockSize / 8;
416 formatInfo.componentCount = componentCount;
417 formatInfo.format = format;
418 formatInfo.type = type;
419 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
420 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
421 formatInfo.compressed = true;
422 formatInfo.textureSupport = textureSupport;
423 formatInfo.renderSupport = renderSupport;
424 formatInfo.filterSupport = filterSupport;
425 return formatInfo;
426}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000427
Geoff Lange4a492b2014-06-19 14:14:41 -0400428static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000429{
430 InternalFormatInfoMap map;
431
432 // From ES 3.0.1 spec, table 3.12
Jamie Madilla3944d42016-07-22 22:13:26 -0400433 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000434
Jamie Madilla3944d42016-07-22 22:13:26 -0400435 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000436
Geoff Langeb66a6e2016-10-31 13:06:12 -0400437 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
438 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);
439 AddRGBAFormat(&map, GL_R8_SNORM, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
440 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);
441 AddRGBAFormat(&map, GL_RG8_SNORM, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
442 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);
443 AddRGBAFormat(&map, GL_RGB8_SNORM, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
444 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);
445 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);
446 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);
447 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);
448 AddRGBAFormat(&map, GL_RGBA8_SNORM, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
449 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);
450 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);
451 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);
452 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);
453 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);
454 AddRGBAFormat(&map, GL_R8I, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
455 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);
456 AddRGBAFormat(&map, GL_R16I, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
457 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);
458 AddRGBAFormat(&map, GL_R32I, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
459 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);
460 AddRGBAFormat(&map, GL_RG8I, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
461 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);
462 AddRGBAFormat(&map, GL_RG16I, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
463 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);
464 AddRGBAFormat(&map, GL_RG32I, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
465 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);
466 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);
467 AddRGBAFormat(&map, GL_RGB8I, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
468 AddRGBAFormat(&map, GL_RGB8UI, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
469 AddRGBAFormat(&map, GL_RGB16I, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
470 AddRGBAFormat(&map, GL_RGB16UI, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
471 AddRGBAFormat(&map, GL_RGB32I, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
472 AddRGBAFormat(&map, GL_RGB32UI, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
473 AddRGBAFormat(&map, GL_RGBA8I, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
474 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);
475 AddRGBAFormat(&map, GL_RGBA16I, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
476 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);
477 AddRGBAFormat(&map, GL_RGBA32I, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
478 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 -0400479
480 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);
481 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);
482 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 +0000483
Jamie Madillec0b5802016-07-04 13:11:59 -0400484 // Special format which is not really supported, so always false for all supports.
Jamie Madilla3944d42016-07-22 22:13:26 -0400485 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 -0400486
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000487 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madilla3944d42016-07-22 22:13:26 -0400488 // | Internal format | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
489 // | | | | | | type | | | | |
490 AddRGBAFormat(&map, GL_R16F, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
491 AddRGBAFormat(&map, GL_RG16F, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
492 AddRGBAFormat(&map, GL_RGB16F, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
493 AddRGBAFormat(&map, GL_RGBA16F, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
494 AddRGBAFormat(&map, GL_R32F, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
495 AddRGBAFormat(&map, GL_RG32F, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
496 AddRGBAFormat(&map, GL_RGB32F, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
497 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 +0000498
499 // Depth stencil formats
Geoff Langeb66a6e2016-10-31 13:06:12 -0400500 // | Internal format | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
501 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>);
502 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>);
503 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>);
504 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 );
505 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 );
506 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 -0800507 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000508
509 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400510 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400511 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
512 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
513 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
514 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
515 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
516 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
517 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
518 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
519 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 +0000520
521 // Unsized formats
Geoff Langeb66a6e2016-10-31 13:06:12 -0400522 // | Internal format | Format | Supported | Renderable | Filterable |
523 AddUnsizedFormat(&map, GL_ALPHA, GL_ALPHA, RequireES<2, 0>, NeverSupported, AlwaysSupported);
524 AddUnsizedFormat(&map, GL_LUMINANCE, GL_LUMINANCE, RequireES<2, 0>, NeverSupported, AlwaysSupported);
525 AddUnsizedFormat(&map, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, RequireES<2, 0>, NeverSupported, AlwaysSupported);
526 AddUnsizedFormat(&map, GL_RED, GL_RED, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
527 AddUnsizedFormat(&map, GL_RG, GL_RG, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
528 AddUnsizedFormat(&map, GL_RGB, GL_RGB, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
529 AddUnsizedFormat(&map, GL_RGBA, GL_RGBA, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
530 AddUnsizedFormat(&map, GL_RED_INTEGER, GL_RED_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
531 AddUnsizedFormat(&map, GL_RG_INTEGER, GL_RG_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
532 AddUnsizedFormat(&map, GL_RGB_INTEGER, GL_RGB_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
533 AddUnsizedFormat(&map, GL_RGBA_INTEGER, GL_RGBA_INTEGER, RequireES<3, 0>, NeverSupported, NeverSupported );
534 AddUnsizedFormat(&map, GL_BGRA_EXT, GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
535 AddUnsizedFormat(&map, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
536 AddUnsizedFormat(&map, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
537 AddUnsizedFormat(&map, GL_SRGB_EXT, GL_RGB, RequireESOrExt<3, 0, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
538 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 +0000539
540 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langeb66a6e2016-10-31 13:06:12 -0400541 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
542 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)));
543 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)));
544 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)));
545 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)));
546 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)));
547 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)));
548 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)));
549 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)));
550 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)));
551 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 +0000552
553 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400554 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
555 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)));
556 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 +0000557
558 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400559 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 +0000560
561 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400562 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)));
563
564 // From GL_OES_compressed_ETC1_RGB8_texture
565 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 +0000566
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800567 // From GL_EXT_texture_compression_s3tc_srgb
568 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
569 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)));
570 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)));
571 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)));
572 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)));
573
Geoff Lang60ad73d2015-10-23 10:08:44 -0400574 // From KHR_texture_compression_astc_hdr
575 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
576 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)));
577 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)));
578 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)));
579 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)));
580 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)));
581 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)));
582 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)));
583 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)));
584 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)));
585 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)));
586 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)));
587 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)));
588 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)));
589 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)));
590
591 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)));
592 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)));
593 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)));
594 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)));
595 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)));
596 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)));
597 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)));
598 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)));
599 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)));
600 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)));
601 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)));
602 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)));
603 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)));
604 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)));
605
Corentin Walleze0902642014-11-04 12:32:15 -0800606 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
607 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
608 // - All other stencil formats (all depth-stencil) are either float or normalized
609 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400610 // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
611 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 -0800612
613 // From GL_ANGLE_lossy_etc_decode
Geoff Langd13ca302016-09-08 09:35:57 -0400614 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800615
Vincent Lang25ab4512016-05-13 18:13:59 +0200616 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400617 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
618 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);
619 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
620 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);
621 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
622 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
623 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
624 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);
625 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 +0200626
Geoff Lang9bbad182015-09-04 11:07:29 -0400627 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800628
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000629 return map;
630}
631
Geoff Lange4a492b2014-06-19 14:14:41 -0400632static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000633{
Geoff Lange4a492b2014-06-19 14:14:41 -0400634 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
635 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636}
637
Geoff Lange4a492b2014-06-19 14:14:41 -0400638static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400639{
640 FormatSet result;
641
Jamie Madillec0b5802016-07-04 13:11:59 -0400642 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400643 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400644 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400645 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400646 // TODO(jmadill): Fix this hack.
647 if (iter.first == GL_BGR565_ANGLEX)
648 continue;
649
650 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400651 }
652 }
653
654 return result;
655}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656
Geoff Lang5d601382014-07-22 15:14:06 -0400657const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000658{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200659 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000660 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200661 case GL_UNSIGNED_BYTE:
662 case GL_BYTE:
663 {
664 static const Type info = GenTypeInfo(1, false);
665 return info;
666 }
667 case GL_UNSIGNED_SHORT:
668 case GL_SHORT:
669 case GL_HALF_FLOAT:
670 case GL_HALF_FLOAT_OES:
671 {
672 static const Type info = GenTypeInfo(2, false);
673 return info;
674 }
675 case GL_UNSIGNED_INT:
676 case GL_INT:
677 case GL_FLOAT:
678 {
679 static const Type info = GenTypeInfo(4, false);
680 return info;
681 }
682 case GL_UNSIGNED_SHORT_5_6_5:
683 case GL_UNSIGNED_SHORT_4_4_4_4:
684 case GL_UNSIGNED_SHORT_5_5_5_1:
685 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
686 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
687 {
688 static const Type info = GenTypeInfo(2, true);
689 return info;
690 }
691 case GL_UNSIGNED_INT_2_10_10_10_REV:
692 case GL_UNSIGNED_INT_24_8:
693 case GL_UNSIGNED_INT_10F_11F_11F_REV:
694 case GL_UNSIGNED_INT_5_9_9_9_REV:
695 {
696 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
697 static const Type info = GenTypeInfo(4, true);
698 return info;
699 }
700 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
701 {
702 static const Type info = GenTypeInfo(8, true);
703 return info;
704 }
705 default:
706 {
707 static const Type defaultInfo;
708 return defaultInfo;
709 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000710 }
711}
712
Geoff Lang5d601382014-07-22 15:14:06 -0400713const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000714{
Geoff Lang5d601382014-07-22 15:14:06 -0400715 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400716 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400717 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000718 {
Geoff Lang5d601382014-07-22 15:14:06 -0400719 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000720 }
721 else
722 {
Geoff Lang5d601382014-07-22 15:14:06 -0400723 static const InternalFormat defaultInternalFormat;
724 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000725 }
726}
727
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400728GLuint InternalFormat::computePixelBytes(GLenum formatType) const
729{
730 const auto &typeInfo = GetTypeInfo(formatType);
731 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
732 return components * typeInfo.bytes;
733}
734
Corentin Wallez886de362016-09-27 10:49:35 -0400735ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400736 GLsizei width,
737 GLint alignment,
738 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000739{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700740 // Compressed images do not use pack/unpack parameters.
741 if (compressed)
742 {
743 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400744 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700745 }
746
Geoff Lang3f234062016-07-13 15:35:45 -0400747 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400748 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700749
750 ASSERT(alignment > 0 && isPow2(alignment));
751 CheckedNumeric<GLuint> checkedAlignment(alignment);
752 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
753 ANGLE_TRY_CHECKED_MATH(aligned);
754 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000755}
756
Corentin Wallez0e487192016-10-03 16:30:38 -0400757ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
758 GLint imageHeight,
759 GLuint rowPitch) const
760{
761 GLuint rows =
762 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
763 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
764
765 auto depthPitch = checkedRowPitch * rows;
766 ANGLE_TRY_CHECKED_MATH(depthPitch);
767 return depthPitch.ValueOrDie();
768}
769
Corentin Wallez886de362016-09-27 10:49:35 -0400770ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400771 GLsizei width,
772 GLsizei height,
773 GLint alignment,
774 GLint rowLength,
775 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000776{
Jamie Madille2e406c2016-06-02 13:04:10 -0400777 GLuint rowPitch = 0;
778 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400779 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000780}
781
Corentin Wallez886de362016-09-27 10:49:35 -0400782ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
783 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000784{
Jamie Madill513558d2016-06-02 13:04:11 -0400785 CheckedNumeric<GLuint> checkedWidth(size.width);
786 CheckedNumeric<GLuint> checkedHeight(size.height);
787 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700788 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
789 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400790
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700791 ASSERT(compressed);
792 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
793 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
794 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
795 ANGLE_TRY_CHECKED_MATH(bytes);
796 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000797}
798
Corentin Wallez886de362016-09-27 10:49:35 -0400799ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700800 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400801 const PixelStoreStateBase &state,
802 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400803{
Olli Etuaho989cac32016-06-08 16:18:49 -0700804 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
805 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400806 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
807 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
808 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700809 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
810 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400811 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700812 {
813 checkedSkipImagesBytes = 0;
814 }
815 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
816 checkedSkipPixels * checkedPixelBytes;
817 ANGLE_TRY_CHECKED_MATH(skipBytes);
818 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400819}
820
Corentin Wallez886de362016-09-27 10:49:35 -0400821ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
822 GLenum formatType,
823 const Extents &size,
824 const PixelStoreStateBase &state,
825 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400826{
Corentin Wallez886de362016-09-27 10:49:35 -0400827 GLuint rowPitch = 0;
828 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400829 rowPitch);
830
Corentin Wallez0e487192016-10-03 16:30:38 -0400831 GLuint depthPitch = 0;
832 if (is3D)
833 {
834 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
835 }
836
Corentin Wallez886de362016-09-27 10:49:35 -0400837 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700838 if (compressed)
839 {
Corentin Wallez886de362016-09-27 10:49:35 -0400840 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700841 }
Corentin Wallez886de362016-09-27 10:49:35 -0400842 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400843 {
Corentin Wallez886de362016-09-27 10:49:35 -0400844 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
845 checkedCopyBytes += size.width * bytes;
846
847 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
848 checkedCopyBytes += heightMinusOne * rowPitch;
849
850 if (is3D)
851 {
852 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
853 checkedCopyBytes += depthMinusOne * depthPitch;
854 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400855 }
856
Corentin Wallez886de362016-09-27 10:49:35 -0400857 CheckedNumeric<GLuint> checkedSkipBytes = 0;
858 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400859
860 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
861
862 ANGLE_TRY_CHECKED_MATH(endByte);
863 return endByte.ValueOrDie();
864}
865
Geoff Lang5d601382014-07-22 15:14:06 -0400866GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000867{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700868 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500869 if (formatInfo.pixelBytes > 0)
870 {
871 return internalFormat;
872 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400873 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000874}
875
Geoff Lange4a492b2014-06-19 14:14:41 -0400876const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400877{
Geoff Lange4a492b2014-06-19 14:14:41 -0400878 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400879 return formatSet;
880}
881
Jamie Madill09e2d932015-07-14 16:40:31 -0400882AttributeType GetAttributeType(GLenum enumValue)
883{
884 switch (enumValue)
885 {
886 case GL_FLOAT:
887 return ATTRIBUTE_FLOAT;
888 case GL_FLOAT_VEC2:
889 return ATTRIBUTE_VEC2;
890 case GL_FLOAT_VEC3:
891 return ATTRIBUTE_VEC3;
892 case GL_FLOAT_VEC4:
893 return ATTRIBUTE_VEC4;
894 case GL_INT:
895 return ATTRIBUTE_INT;
896 case GL_INT_VEC2:
897 return ATTRIBUTE_IVEC2;
898 case GL_INT_VEC3:
899 return ATTRIBUTE_IVEC3;
900 case GL_INT_VEC4:
901 return ATTRIBUTE_IVEC4;
902 case GL_UNSIGNED_INT:
903 return ATTRIBUTE_UINT;
904 case GL_UNSIGNED_INT_VEC2:
905 return ATTRIBUTE_UVEC2;
906 case GL_UNSIGNED_INT_VEC3:
907 return ATTRIBUTE_UVEC3;
908 case GL_UNSIGNED_INT_VEC4:
909 return ATTRIBUTE_UVEC4;
910 case GL_FLOAT_MAT2:
911 return ATTRIBUTE_MAT2;
912 case GL_FLOAT_MAT3:
913 return ATTRIBUTE_MAT3;
914 case GL_FLOAT_MAT4:
915 return ATTRIBUTE_MAT4;
916 case GL_FLOAT_MAT2x3:
917 return ATTRIBUTE_MAT2x3;
918 case GL_FLOAT_MAT2x4:
919 return ATTRIBUTE_MAT2x4;
920 case GL_FLOAT_MAT3x2:
921 return ATTRIBUTE_MAT3x2;
922 case GL_FLOAT_MAT3x4:
923 return ATTRIBUTE_MAT3x4;
924 case GL_FLOAT_MAT4x2:
925 return ATTRIBUTE_MAT4x2;
926 case GL_FLOAT_MAT4x3:
927 return ATTRIBUTE_MAT4x3;
928 default:
929 UNREACHABLE();
930 return ATTRIBUTE_FLOAT;
931 }
932}
933
Jamie Madilld3dfda22015-07-06 08:28:49 -0400934VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
935{
936 switch (type)
937 {
938 case GL_BYTE:
939 switch (components)
940 {
941 case 1:
942 if (pureInteger)
943 return VERTEX_FORMAT_SBYTE1_INT;
944 if (normalized)
945 return VERTEX_FORMAT_SBYTE1_NORM;
946 return VERTEX_FORMAT_SBYTE1;
947 case 2:
948 if (pureInteger)
949 return VERTEX_FORMAT_SBYTE2_INT;
950 if (normalized)
951 return VERTEX_FORMAT_SBYTE2_NORM;
952 return VERTEX_FORMAT_SBYTE2;
953 case 3:
954 if (pureInteger)
955 return VERTEX_FORMAT_SBYTE3_INT;
956 if (normalized)
957 return VERTEX_FORMAT_SBYTE3_NORM;
958 return VERTEX_FORMAT_SBYTE3;
959 case 4:
960 if (pureInteger)
961 return VERTEX_FORMAT_SBYTE4_INT;
962 if (normalized)
963 return VERTEX_FORMAT_SBYTE4_NORM;
964 return VERTEX_FORMAT_SBYTE4;
965 default:
966 UNREACHABLE();
967 break;
968 }
969 case GL_UNSIGNED_BYTE:
970 switch (components)
971 {
972 case 1:
973 if (pureInteger)
974 return VERTEX_FORMAT_UBYTE1_INT;
975 if (normalized)
976 return VERTEX_FORMAT_UBYTE1_NORM;
977 return VERTEX_FORMAT_UBYTE1;
978 case 2:
979 if (pureInteger)
980 return VERTEX_FORMAT_UBYTE2_INT;
981 if (normalized)
982 return VERTEX_FORMAT_UBYTE2_NORM;
983 return VERTEX_FORMAT_UBYTE2;
984 case 3:
985 if (pureInteger)
986 return VERTEX_FORMAT_UBYTE3_INT;
987 if (normalized)
988 return VERTEX_FORMAT_UBYTE3_NORM;
989 return VERTEX_FORMAT_UBYTE3;
990 case 4:
991 if (pureInteger)
992 return VERTEX_FORMAT_UBYTE4_INT;
993 if (normalized)
994 return VERTEX_FORMAT_UBYTE4_NORM;
995 return VERTEX_FORMAT_UBYTE4;
996 default:
997 UNREACHABLE();
998 break;
999 }
1000 case GL_SHORT:
1001 switch (components)
1002 {
1003 case 1:
1004 if (pureInteger)
1005 return VERTEX_FORMAT_SSHORT1_INT;
1006 if (normalized)
1007 return VERTEX_FORMAT_SSHORT1_NORM;
1008 return VERTEX_FORMAT_SSHORT1;
1009 case 2:
1010 if (pureInteger)
1011 return VERTEX_FORMAT_SSHORT2_INT;
1012 if (normalized)
1013 return VERTEX_FORMAT_SSHORT2_NORM;
1014 return VERTEX_FORMAT_SSHORT2;
1015 case 3:
1016 if (pureInteger)
1017 return VERTEX_FORMAT_SSHORT3_INT;
1018 if (normalized)
1019 return VERTEX_FORMAT_SSHORT3_NORM;
1020 return VERTEX_FORMAT_SSHORT3;
1021 case 4:
1022 if (pureInteger)
1023 return VERTEX_FORMAT_SSHORT4_INT;
1024 if (normalized)
1025 return VERTEX_FORMAT_SSHORT4_NORM;
1026 return VERTEX_FORMAT_SSHORT4;
1027 default:
1028 UNREACHABLE();
1029 break;
1030 }
1031 case GL_UNSIGNED_SHORT:
1032 switch (components)
1033 {
1034 case 1:
1035 if (pureInteger)
1036 return VERTEX_FORMAT_USHORT1_INT;
1037 if (normalized)
1038 return VERTEX_FORMAT_USHORT1_NORM;
1039 return VERTEX_FORMAT_USHORT1;
1040 case 2:
1041 if (pureInteger)
1042 return VERTEX_FORMAT_USHORT2_INT;
1043 if (normalized)
1044 return VERTEX_FORMAT_USHORT2_NORM;
1045 return VERTEX_FORMAT_USHORT2;
1046 case 3:
1047 if (pureInteger)
1048 return VERTEX_FORMAT_USHORT3_INT;
1049 if (normalized)
1050 return VERTEX_FORMAT_USHORT3_NORM;
1051 return VERTEX_FORMAT_USHORT3;
1052 case 4:
1053 if (pureInteger)
1054 return VERTEX_FORMAT_USHORT4_INT;
1055 if (normalized)
1056 return VERTEX_FORMAT_USHORT4_NORM;
1057 return VERTEX_FORMAT_USHORT4;
1058 default:
1059 UNREACHABLE();
1060 break;
1061 }
1062 case GL_INT:
1063 switch (components)
1064 {
1065 case 1:
1066 if (pureInteger)
1067 return VERTEX_FORMAT_SINT1_INT;
1068 if (normalized)
1069 return VERTEX_FORMAT_SINT1_NORM;
1070 return VERTEX_FORMAT_SINT1;
1071 case 2:
1072 if (pureInteger)
1073 return VERTEX_FORMAT_SINT2_INT;
1074 if (normalized)
1075 return VERTEX_FORMAT_SINT2_NORM;
1076 return VERTEX_FORMAT_SINT2;
1077 case 3:
1078 if (pureInteger)
1079 return VERTEX_FORMAT_SINT3_INT;
1080 if (normalized)
1081 return VERTEX_FORMAT_SINT3_NORM;
1082 return VERTEX_FORMAT_SINT3;
1083 case 4:
1084 if (pureInteger)
1085 return VERTEX_FORMAT_SINT4_INT;
1086 if (normalized)
1087 return VERTEX_FORMAT_SINT4_NORM;
1088 return VERTEX_FORMAT_SINT4;
1089 default:
1090 UNREACHABLE();
1091 break;
1092 }
1093 case GL_UNSIGNED_INT:
1094 switch (components)
1095 {
1096 case 1:
1097 if (pureInteger)
1098 return VERTEX_FORMAT_UINT1_INT;
1099 if (normalized)
1100 return VERTEX_FORMAT_UINT1_NORM;
1101 return VERTEX_FORMAT_UINT1;
1102 case 2:
1103 if (pureInteger)
1104 return VERTEX_FORMAT_UINT2_INT;
1105 if (normalized)
1106 return VERTEX_FORMAT_UINT2_NORM;
1107 return VERTEX_FORMAT_UINT2;
1108 case 3:
1109 if (pureInteger)
1110 return VERTEX_FORMAT_UINT3_INT;
1111 if (normalized)
1112 return VERTEX_FORMAT_UINT3_NORM;
1113 return VERTEX_FORMAT_UINT3;
1114 case 4:
1115 if (pureInteger)
1116 return VERTEX_FORMAT_UINT4_INT;
1117 if (normalized)
1118 return VERTEX_FORMAT_UINT4_NORM;
1119 return VERTEX_FORMAT_UINT4;
1120 default:
1121 UNREACHABLE();
1122 break;
1123 }
1124 case GL_FLOAT:
1125 switch (components)
1126 {
1127 case 1:
1128 return VERTEX_FORMAT_FLOAT1;
1129 case 2:
1130 return VERTEX_FORMAT_FLOAT2;
1131 case 3:
1132 return VERTEX_FORMAT_FLOAT3;
1133 case 4:
1134 return VERTEX_FORMAT_FLOAT4;
1135 default:
1136 UNREACHABLE();
1137 break;
1138 }
1139 case GL_HALF_FLOAT:
1140 switch (components)
1141 {
1142 case 1:
1143 return VERTEX_FORMAT_HALF1;
1144 case 2:
1145 return VERTEX_FORMAT_HALF2;
1146 case 3:
1147 return VERTEX_FORMAT_HALF3;
1148 case 4:
1149 return VERTEX_FORMAT_HALF4;
1150 default:
1151 UNREACHABLE();
1152 break;
1153 }
1154 case GL_FIXED:
1155 switch (components)
1156 {
1157 case 1:
1158 return VERTEX_FORMAT_FIXED1;
1159 case 2:
1160 return VERTEX_FORMAT_FIXED2;
1161 case 3:
1162 return VERTEX_FORMAT_FIXED3;
1163 case 4:
1164 return VERTEX_FORMAT_FIXED4;
1165 default:
1166 UNREACHABLE();
1167 break;
1168 }
1169 case GL_INT_2_10_10_10_REV:
1170 if (pureInteger)
1171 return VERTEX_FORMAT_SINT210_INT;
1172 if (normalized)
1173 return VERTEX_FORMAT_SINT210_NORM;
1174 return VERTEX_FORMAT_SINT210;
1175 case GL_UNSIGNED_INT_2_10_10_10_REV:
1176 if (pureInteger)
1177 return VERTEX_FORMAT_UINT210_INT;
1178 if (normalized)
1179 return VERTEX_FORMAT_UINT210_NORM;
1180 return VERTEX_FORMAT_UINT210;
1181 default:
1182 UNREACHABLE();
1183 break;
1184 }
1185 return VERTEX_FORMAT_UBYTE1;
1186}
1187
1188VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1189{
1190 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1191}
1192
1193VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1194{
1195 if (!attrib.enabled)
1196 {
1197 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1198 }
1199 return GetVertexFormatType(attrib);
1200}
1201
1202const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1203{
1204 switch (vertexFormatType)
1205 {
1206 case VERTEX_FORMAT_SBYTE1:
1207 {
1208 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1209 return format;
1210 }
1211 case VERTEX_FORMAT_SBYTE1_NORM:
1212 {
1213 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1214 return format;
1215 }
1216 case VERTEX_FORMAT_SBYTE2:
1217 {
1218 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1219 return format;
1220 }
1221 case VERTEX_FORMAT_SBYTE2_NORM:
1222 {
1223 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1224 return format;
1225 }
1226 case VERTEX_FORMAT_SBYTE3:
1227 {
1228 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1229 return format;
1230 }
1231 case VERTEX_FORMAT_SBYTE3_NORM:
1232 {
1233 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1234 return format;
1235 }
1236 case VERTEX_FORMAT_SBYTE4:
1237 {
1238 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1239 return format;
1240 }
1241 case VERTEX_FORMAT_SBYTE4_NORM:
1242 {
1243 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1244 return format;
1245 }
1246 case VERTEX_FORMAT_UBYTE1:
1247 {
1248 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1249 return format;
1250 }
1251 case VERTEX_FORMAT_UBYTE1_NORM:
1252 {
1253 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1254 return format;
1255 }
1256 case VERTEX_FORMAT_UBYTE2:
1257 {
1258 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1259 return format;
1260 }
1261 case VERTEX_FORMAT_UBYTE2_NORM:
1262 {
1263 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1264 return format;
1265 }
1266 case VERTEX_FORMAT_UBYTE3:
1267 {
1268 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1269 return format;
1270 }
1271 case VERTEX_FORMAT_UBYTE3_NORM:
1272 {
1273 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1274 return format;
1275 }
1276 case VERTEX_FORMAT_UBYTE4:
1277 {
1278 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1279 return format;
1280 }
1281 case VERTEX_FORMAT_UBYTE4_NORM:
1282 {
1283 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1284 return format;
1285 }
1286 case VERTEX_FORMAT_SSHORT1:
1287 {
1288 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1289 return format;
1290 }
1291 case VERTEX_FORMAT_SSHORT1_NORM:
1292 {
1293 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1294 return format;
1295 }
1296 case VERTEX_FORMAT_SSHORT2:
1297 {
1298 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1299 return format;
1300 }
1301 case VERTEX_FORMAT_SSHORT2_NORM:
1302 {
1303 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1304 return format;
1305 }
1306 case VERTEX_FORMAT_SSHORT3:
1307 {
1308 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1309 return format;
1310 }
1311 case VERTEX_FORMAT_SSHORT3_NORM:
1312 {
1313 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1314 return format;
1315 }
1316 case VERTEX_FORMAT_SSHORT4:
1317 {
1318 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1319 return format;
1320 }
1321 case VERTEX_FORMAT_SSHORT4_NORM:
1322 {
1323 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1324 return format;
1325 }
1326 case VERTEX_FORMAT_USHORT1:
1327 {
1328 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1329 return format;
1330 }
1331 case VERTEX_FORMAT_USHORT1_NORM:
1332 {
1333 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1334 return format;
1335 }
1336 case VERTEX_FORMAT_USHORT2:
1337 {
1338 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1339 return format;
1340 }
1341 case VERTEX_FORMAT_USHORT2_NORM:
1342 {
1343 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1344 return format;
1345 }
1346 case VERTEX_FORMAT_USHORT3:
1347 {
1348 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1349 return format;
1350 }
1351 case VERTEX_FORMAT_USHORT3_NORM:
1352 {
1353 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1354 return format;
1355 }
1356 case VERTEX_FORMAT_USHORT4:
1357 {
1358 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1359 return format;
1360 }
1361 case VERTEX_FORMAT_USHORT4_NORM:
1362 {
1363 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1364 return format;
1365 }
1366 case VERTEX_FORMAT_SINT1:
1367 {
1368 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1369 return format;
1370 }
1371 case VERTEX_FORMAT_SINT1_NORM:
1372 {
1373 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1374 return format;
1375 }
1376 case VERTEX_FORMAT_SINT2:
1377 {
1378 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1379 return format;
1380 }
1381 case VERTEX_FORMAT_SINT2_NORM:
1382 {
1383 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1384 return format;
1385 }
1386 case VERTEX_FORMAT_SINT3:
1387 {
1388 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1389 return format;
1390 }
1391 case VERTEX_FORMAT_SINT3_NORM:
1392 {
1393 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1394 return format;
1395 }
1396 case VERTEX_FORMAT_SINT4:
1397 {
1398 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1399 return format;
1400 }
1401 case VERTEX_FORMAT_SINT4_NORM:
1402 {
1403 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1404 return format;
1405 }
1406 case VERTEX_FORMAT_UINT1:
1407 {
1408 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1409 return format;
1410 }
1411 case VERTEX_FORMAT_UINT1_NORM:
1412 {
1413 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1414 return format;
1415 }
1416 case VERTEX_FORMAT_UINT2:
1417 {
1418 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1419 return format;
1420 }
1421 case VERTEX_FORMAT_UINT2_NORM:
1422 {
1423 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1424 return format;
1425 }
1426 case VERTEX_FORMAT_UINT3:
1427 {
1428 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1429 return format;
1430 }
1431 case VERTEX_FORMAT_UINT3_NORM:
1432 {
1433 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1434 return format;
1435 }
1436 case VERTEX_FORMAT_UINT4:
1437 {
1438 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1439 return format;
1440 }
1441 case VERTEX_FORMAT_UINT4_NORM:
1442 {
1443 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1444 return format;
1445 }
1446 case VERTEX_FORMAT_SBYTE1_INT:
1447 {
1448 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1449 return format;
1450 }
1451 case VERTEX_FORMAT_SBYTE2_INT:
1452 {
1453 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1454 return format;
1455 }
1456 case VERTEX_FORMAT_SBYTE3_INT:
1457 {
1458 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1459 return format;
1460 }
1461 case VERTEX_FORMAT_SBYTE4_INT:
1462 {
1463 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1464 return format;
1465 }
1466 case VERTEX_FORMAT_UBYTE1_INT:
1467 {
1468 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1469 return format;
1470 }
1471 case VERTEX_FORMAT_UBYTE2_INT:
1472 {
1473 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1474 return format;
1475 }
1476 case VERTEX_FORMAT_UBYTE3_INT:
1477 {
1478 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1479 return format;
1480 }
1481 case VERTEX_FORMAT_UBYTE4_INT:
1482 {
1483 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1484 return format;
1485 }
1486 case VERTEX_FORMAT_SSHORT1_INT:
1487 {
1488 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1489 return format;
1490 }
1491 case VERTEX_FORMAT_SSHORT2_INT:
1492 {
1493 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1494 return format;
1495 }
1496 case VERTEX_FORMAT_SSHORT3_INT:
1497 {
1498 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1499 return format;
1500 }
1501 case VERTEX_FORMAT_SSHORT4_INT:
1502 {
1503 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1504 return format;
1505 }
1506 case VERTEX_FORMAT_USHORT1_INT:
1507 {
1508 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1509 return format;
1510 }
1511 case VERTEX_FORMAT_USHORT2_INT:
1512 {
1513 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1514 return format;
1515 }
1516 case VERTEX_FORMAT_USHORT3_INT:
1517 {
1518 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1519 return format;
1520 }
1521 case VERTEX_FORMAT_USHORT4_INT:
1522 {
1523 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1524 return format;
1525 }
1526 case VERTEX_FORMAT_SINT1_INT:
1527 {
1528 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1529 return format;
1530 }
1531 case VERTEX_FORMAT_SINT2_INT:
1532 {
1533 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1534 return format;
1535 }
1536 case VERTEX_FORMAT_SINT3_INT:
1537 {
1538 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1539 return format;
1540 }
1541 case VERTEX_FORMAT_SINT4_INT:
1542 {
1543 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1544 return format;
1545 }
1546 case VERTEX_FORMAT_UINT1_INT:
1547 {
1548 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1549 return format;
1550 }
1551 case VERTEX_FORMAT_UINT2_INT:
1552 {
1553 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1554 return format;
1555 }
1556 case VERTEX_FORMAT_UINT3_INT:
1557 {
1558 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1559 return format;
1560 }
1561 case VERTEX_FORMAT_UINT4_INT:
1562 {
1563 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1564 return format;
1565 }
1566 case VERTEX_FORMAT_FIXED1:
1567 {
1568 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1569 return format;
1570 }
1571 case VERTEX_FORMAT_FIXED2:
1572 {
1573 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1574 return format;
1575 }
1576 case VERTEX_FORMAT_FIXED3:
1577 {
1578 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1579 return format;
1580 }
1581 case VERTEX_FORMAT_FIXED4:
1582 {
1583 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1584 return format;
1585 }
1586 case VERTEX_FORMAT_HALF1:
1587 {
1588 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1589 return format;
1590 }
1591 case VERTEX_FORMAT_HALF2:
1592 {
1593 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1594 return format;
1595 }
1596 case VERTEX_FORMAT_HALF3:
1597 {
1598 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1599 return format;
1600 }
1601 case VERTEX_FORMAT_HALF4:
1602 {
1603 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1604 return format;
1605 }
1606 case VERTEX_FORMAT_FLOAT1:
1607 {
1608 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1609 return format;
1610 }
1611 case VERTEX_FORMAT_FLOAT2:
1612 {
1613 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1614 return format;
1615 }
1616 case VERTEX_FORMAT_FLOAT3:
1617 {
1618 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1619 return format;
1620 }
1621 case VERTEX_FORMAT_FLOAT4:
1622 {
1623 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1624 return format;
1625 }
1626 case VERTEX_FORMAT_SINT210:
1627 {
1628 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1629 return format;
1630 }
1631 case VERTEX_FORMAT_UINT210:
1632 {
1633 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1634 return format;
1635 }
1636 case VERTEX_FORMAT_SINT210_NORM:
1637 {
1638 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1639 return format;
1640 }
1641 case VERTEX_FORMAT_UINT210_NORM:
1642 {
1643 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1644 return format;
1645 }
1646 case VERTEX_FORMAT_SINT210_INT:
1647 {
1648 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1649 return format;
1650 }
1651 case VERTEX_FORMAT_UINT210_INT:
1652 {
1653 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1654 return format;
1655 }
1656 default:
1657 {
1658 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1659 return format;
1660 }
1661 }
1662}
1663
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001664size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1665{
1666 switch (vertexFormatType)
1667 {
1668 case VERTEX_FORMAT_SBYTE1:
1669 case VERTEX_FORMAT_SBYTE1_NORM:
1670 case VERTEX_FORMAT_UBYTE1:
1671 case VERTEX_FORMAT_UBYTE1_NORM:
1672 case VERTEX_FORMAT_SBYTE1_INT:
1673 case VERTEX_FORMAT_UBYTE1_INT:
1674 return 1;
1675
1676 case VERTEX_FORMAT_SBYTE2:
1677 case VERTEX_FORMAT_SBYTE2_NORM:
1678 case VERTEX_FORMAT_UBYTE2:
1679 case VERTEX_FORMAT_UBYTE2_NORM:
1680 case VERTEX_FORMAT_SBYTE2_INT:
1681 case VERTEX_FORMAT_UBYTE2_INT:
1682 case VERTEX_FORMAT_SSHORT1:
1683 case VERTEX_FORMAT_SSHORT1_NORM:
1684 case VERTEX_FORMAT_USHORT1:
1685 case VERTEX_FORMAT_USHORT1_NORM:
1686 case VERTEX_FORMAT_SSHORT1_INT:
1687 case VERTEX_FORMAT_USHORT1_INT:
1688 case VERTEX_FORMAT_HALF1:
1689 return 2;
1690
1691 case VERTEX_FORMAT_SBYTE3:
1692 case VERTEX_FORMAT_SBYTE3_NORM:
1693 case VERTEX_FORMAT_UBYTE3:
1694 case VERTEX_FORMAT_UBYTE3_NORM:
1695 case VERTEX_FORMAT_SBYTE3_INT:
1696 case VERTEX_FORMAT_UBYTE3_INT:
1697 return 3;
1698
1699 case VERTEX_FORMAT_SBYTE4:
1700 case VERTEX_FORMAT_SBYTE4_NORM:
1701 case VERTEX_FORMAT_UBYTE4:
1702 case VERTEX_FORMAT_UBYTE4_NORM:
1703 case VERTEX_FORMAT_SBYTE4_INT:
1704 case VERTEX_FORMAT_UBYTE4_INT:
1705 case VERTEX_FORMAT_SSHORT2:
1706 case VERTEX_FORMAT_SSHORT2_NORM:
1707 case VERTEX_FORMAT_USHORT2:
1708 case VERTEX_FORMAT_USHORT2_NORM:
1709 case VERTEX_FORMAT_SSHORT2_INT:
1710 case VERTEX_FORMAT_USHORT2_INT:
1711 case VERTEX_FORMAT_SINT1:
1712 case VERTEX_FORMAT_SINT1_NORM:
1713 case VERTEX_FORMAT_UINT1:
1714 case VERTEX_FORMAT_UINT1_NORM:
1715 case VERTEX_FORMAT_SINT1_INT:
1716 case VERTEX_FORMAT_UINT1_INT:
1717 case VERTEX_FORMAT_HALF2:
1718 case VERTEX_FORMAT_FIXED1:
1719 case VERTEX_FORMAT_FLOAT1:
1720 case VERTEX_FORMAT_SINT210:
1721 case VERTEX_FORMAT_UINT210:
1722 case VERTEX_FORMAT_SINT210_NORM:
1723 case VERTEX_FORMAT_UINT210_NORM:
1724 case VERTEX_FORMAT_SINT210_INT:
1725 case VERTEX_FORMAT_UINT210_INT:
1726 return 4;
1727
1728 case VERTEX_FORMAT_SSHORT3:
1729 case VERTEX_FORMAT_SSHORT3_NORM:
1730 case VERTEX_FORMAT_USHORT3:
1731 case VERTEX_FORMAT_USHORT3_NORM:
1732 case VERTEX_FORMAT_SSHORT3_INT:
1733 case VERTEX_FORMAT_USHORT3_INT:
1734 case VERTEX_FORMAT_HALF3:
1735 return 6;
1736
1737 case VERTEX_FORMAT_SSHORT4:
1738 case VERTEX_FORMAT_SSHORT4_NORM:
1739 case VERTEX_FORMAT_USHORT4:
1740 case VERTEX_FORMAT_USHORT4_NORM:
1741 case VERTEX_FORMAT_SSHORT4_INT:
1742 case VERTEX_FORMAT_USHORT4_INT:
1743 case VERTEX_FORMAT_SINT2:
1744 case VERTEX_FORMAT_SINT2_NORM:
1745 case VERTEX_FORMAT_UINT2:
1746 case VERTEX_FORMAT_UINT2_NORM:
1747 case VERTEX_FORMAT_SINT2_INT:
1748 case VERTEX_FORMAT_UINT2_INT:
1749 case VERTEX_FORMAT_HALF4:
1750 case VERTEX_FORMAT_FIXED2:
1751 case VERTEX_FORMAT_FLOAT2:
1752 return 8;
1753
1754 case VERTEX_FORMAT_SINT3:
1755 case VERTEX_FORMAT_SINT3_NORM:
1756 case VERTEX_FORMAT_UINT3:
1757 case VERTEX_FORMAT_UINT3_NORM:
1758 case VERTEX_FORMAT_SINT3_INT:
1759 case VERTEX_FORMAT_UINT3_INT:
1760 case VERTEX_FORMAT_FIXED3:
1761 case VERTEX_FORMAT_FLOAT3:
1762 return 12;
1763
1764 case VERTEX_FORMAT_SINT4:
1765 case VERTEX_FORMAT_SINT4_NORM:
1766 case VERTEX_FORMAT_UINT4:
1767 case VERTEX_FORMAT_UINT4_NORM:
1768 case VERTEX_FORMAT_SINT4_INT:
1769 case VERTEX_FORMAT_UINT4_INT:
1770 case VERTEX_FORMAT_FIXED4:
1771 case VERTEX_FORMAT_FLOAT4:
1772 return 16;
1773
1774 case VERTEX_FORMAT_INVALID:
1775 default:
1776 UNREACHABLE();
1777 return 0;
1778 }
1779}
1780
Jamie Madilld3dfda22015-07-06 08:28:49 -04001781VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1782 : type(typeIn),
1783 normalized(normalizedIn),
1784 components(componentsIn),
1785 pureInteger(pureIntegerIn)
1786{
1787 // float -> !normalized
1788 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1789}
1790
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001791}