blob: 8b696d5f3926454eb64383523d3fbcb498e31e7b [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
Shannon Woods4d161ba2014-03-17 18:13:30 -04009#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/formatutils.h"
11#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
Geoff Lang60ad73d2015-10-23 10:08:44 -0400567 // From KHR_texture_compression_astc_hdr
568 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
569 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)));
570 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)));
571 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)));
572 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)));
573 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)));
574 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)));
575 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)));
576 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)));
577 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)));
578 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)));
579 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)));
580 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)));
581 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)));
582 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)));
583
584 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)));
585 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)));
586 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)));
587 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)));
588 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)));
589 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)));
590 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)));
591 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)));
592 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)));
593 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)));
594 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)));
595 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)));
596 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)));
597 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)));
598
Corentin Walleze0902642014-11-04 12:32:15 -0800599 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
600 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
601 // - All other stencil formats (all depth-stencil) are either float or normalized
602 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400603 // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
604 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 -0800605
606 // From GL_ANGLE_lossy_etc_decode
Geoff Langd13ca302016-09-08 09:35:57 -0400607 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 -0800608
Vincent Lang25ab4512016-05-13 18:13:59 +0200609 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400610 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
611 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);
612 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
613 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);
614 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
615 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
616 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
617 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);
618 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 +0200619
Geoff Lang9bbad182015-09-04 11:07:29 -0400620 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800621
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000622 return map;
623}
624
Geoff Lange4a492b2014-06-19 14:14:41 -0400625static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000626{
Geoff Lange4a492b2014-06-19 14:14:41 -0400627 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
628 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000629}
630
Geoff Lange4a492b2014-06-19 14:14:41 -0400631static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400632{
633 FormatSet result;
634
Jamie Madillec0b5802016-07-04 13:11:59 -0400635 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400636 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400637 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400638 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400639 // TODO(jmadill): Fix this hack.
640 if (iter.first == GL_BGR565_ANGLEX)
641 continue;
642
643 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400644 }
645 }
646
647 return result;
648}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000649
Geoff Lang5d601382014-07-22 15:14:06 -0400650const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000651{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200652 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000653 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200654 case GL_UNSIGNED_BYTE:
655 case GL_BYTE:
656 {
657 static const Type info = GenTypeInfo(1, false);
658 return info;
659 }
660 case GL_UNSIGNED_SHORT:
661 case GL_SHORT:
662 case GL_HALF_FLOAT:
663 case GL_HALF_FLOAT_OES:
664 {
665 static const Type info = GenTypeInfo(2, false);
666 return info;
667 }
668 case GL_UNSIGNED_INT:
669 case GL_INT:
670 case GL_FLOAT:
671 {
672 static const Type info = GenTypeInfo(4, false);
673 return info;
674 }
675 case GL_UNSIGNED_SHORT_5_6_5:
676 case GL_UNSIGNED_SHORT_4_4_4_4:
677 case GL_UNSIGNED_SHORT_5_5_5_1:
678 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
679 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
680 {
681 static const Type info = GenTypeInfo(2, true);
682 return info;
683 }
684 case GL_UNSIGNED_INT_2_10_10_10_REV:
685 case GL_UNSIGNED_INT_24_8:
686 case GL_UNSIGNED_INT_10F_11F_11F_REV:
687 case GL_UNSIGNED_INT_5_9_9_9_REV:
688 {
689 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
690 static const Type info = GenTypeInfo(4, true);
691 return info;
692 }
693 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
694 {
695 static const Type info = GenTypeInfo(8, true);
696 return info;
697 }
698 default:
699 {
700 static const Type defaultInfo;
701 return defaultInfo;
702 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000703 }
704}
705
Geoff Lang5d601382014-07-22 15:14:06 -0400706const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707{
Geoff Lang5d601382014-07-22 15:14:06 -0400708 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400709 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400710 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000711 {
Geoff Lang5d601382014-07-22 15:14:06 -0400712 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000713 }
714 else
715 {
Geoff Lang5d601382014-07-22 15:14:06 -0400716 static const InternalFormat defaultInternalFormat;
717 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000718 }
719}
720
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400721GLuint InternalFormat::computePixelBytes(GLenum formatType) const
722{
723 const auto &typeInfo = GetTypeInfo(formatType);
724 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
725 return components * typeInfo.bytes;
726}
727
Corentin Wallez886de362016-09-27 10:49:35 -0400728ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400729 GLsizei width,
730 GLint alignment,
731 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000732{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700733 // Compressed images do not use pack/unpack parameters.
734 if (compressed)
735 {
736 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400737 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700738 }
739
Geoff Lang3f234062016-07-13 15:35:45 -0400740 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400741 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700742
743 ASSERT(alignment > 0 && isPow2(alignment));
744 CheckedNumeric<GLuint> checkedAlignment(alignment);
745 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
746 ANGLE_TRY_CHECKED_MATH(aligned);
747 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000748}
749
Corentin Wallez0e487192016-10-03 16:30:38 -0400750ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
751 GLint imageHeight,
752 GLuint rowPitch) const
753{
754 GLuint rows =
755 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
756 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
757
758 auto depthPitch = checkedRowPitch * rows;
759 ANGLE_TRY_CHECKED_MATH(depthPitch);
760 return depthPitch.ValueOrDie();
761}
762
Corentin Wallez886de362016-09-27 10:49:35 -0400763ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400764 GLsizei width,
765 GLsizei height,
766 GLint alignment,
767 GLint rowLength,
768 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000769{
Jamie Madille2e406c2016-06-02 13:04:10 -0400770 GLuint rowPitch = 0;
771 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400772 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000773}
774
Corentin Wallez886de362016-09-27 10:49:35 -0400775ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
776 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000777{
Jamie Madill513558d2016-06-02 13:04:11 -0400778 CheckedNumeric<GLuint> checkedWidth(size.width);
779 CheckedNumeric<GLuint> checkedHeight(size.height);
780 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700781 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
782 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400783
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700784 ASSERT(compressed);
785 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
786 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
787 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
788 ANGLE_TRY_CHECKED_MATH(bytes);
789 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000790}
791
Corentin Wallez886de362016-09-27 10:49:35 -0400792ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700793 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400794 const PixelStoreStateBase &state,
795 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400796{
Olli Etuaho989cac32016-06-08 16:18:49 -0700797 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
798 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400799 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
800 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
801 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700802 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
803 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400804 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700805 {
806 checkedSkipImagesBytes = 0;
807 }
808 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
809 checkedSkipPixels * checkedPixelBytes;
810 ANGLE_TRY_CHECKED_MATH(skipBytes);
811 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400812}
813
Corentin Wallez886de362016-09-27 10:49:35 -0400814ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
815 GLenum formatType,
816 const Extents &size,
817 const PixelStoreStateBase &state,
818 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400819{
Corentin Wallez886de362016-09-27 10:49:35 -0400820 GLuint rowPitch = 0;
821 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400822 rowPitch);
823
Corentin Wallez0e487192016-10-03 16:30:38 -0400824 GLuint depthPitch = 0;
825 if (is3D)
826 {
827 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
828 }
829
Corentin Wallez886de362016-09-27 10:49:35 -0400830 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700831 if (compressed)
832 {
Corentin Wallez886de362016-09-27 10:49:35 -0400833 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700834 }
Corentin Wallez886de362016-09-27 10:49:35 -0400835 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400836 {
Corentin Wallez886de362016-09-27 10:49:35 -0400837 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
838 checkedCopyBytes += size.width * bytes;
839
840 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
841 checkedCopyBytes += heightMinusOne * rowPitch;
842
843 if (is3D)
844 {
845 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
846 checkedCopyBytes += depthMinusOne * depthPitch;
847 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400848 }
849
Corentin Wallez886de362016-09-27 10:49:35 -0400850 CheckedNumeric<GLuint> checkedSkipBytes = 0;
851 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400852
853 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
854
855 ANGLE_TRY_CHECKED_MATH(endByte);
856 return endByte.ValueOrDie();
857}
858
Geoff Lang5d601382014-07-22 15:14:06 -0400859GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000860{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700861 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500862 if (formatInfo.pixelBytes > 0)
863 {
864 return internalFormat;
865 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400866 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000867}
868
Geoff Lange4a492b2014-06-19 14:14:41 -0400869const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400870{
Geoff Lange4a492b2014-06-19 14:14:41 -0400871 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400872 return formatSet;
873}
874
Jamie Madill09e2d932015-07-14 16:40:31 -0400875AttributeType GetAttributeType(GLenum enumValue)
876{
877 switch (enumValue)
878 {
879 case GL_FLOAT:
880 return ATTRIBUTE_FLOAT;
881 case GL_FLOAT_VEC2:
882 return ATTRIBUTE_VEC2;
883 case GL_FLOAT_VEC3:
884 return ATTRIBUTE_VEC3;
885 case GL_FLOAT_VEC4:
886 return ATTRIBUTE_VEC4;
887 case GL_INT:
888 return ATTRIBUTE_INT;
889 case GL_INT_VEC2:
890 return ATTRIBUTE_IVEC2;
891 case GL_INT_VEC3:
892 return ATTRIBUTE_IVEC3;
893 case GL_INT_VEC4:
894 return ATTRIBUTE_IVEC4;
895 case GL_UNSIGNED_INT:
896 return ATTRIBUTE_UINT;
897 case GL_UNSIGNED_INT_VEC2:
898 return ATTRIBUTE_UVEC2;
899 case GL_UNSIGNED_INT_VEC3:
900 return ATTRIBUTE_UVEC3;
901 case GL_UNSIGNED_INT_VEC4:
902 return ATTRIBUTE_UVEC4;
903 case GL_FLOAT_MAT2:
904 return ATTRIBUTE_MAT2;
905 case GL_FLOAT_MAT3:
906 return ATTRIBUTE_MAT3;
907 case GL_FLOAT_MAT4:
908 return ATTRIBUTE_MAT4;
909 case GL_FLOAT_MAT2x3:
910 return ATTRIBUTE_MAT2x3;
911 case GL_FLOAT_MAT2x4:
912 return ATTRIBUTE_MAT2x4;
913 case GL_FLOAT_MAT3x2:
914 return ATTRIBUTE_MAT3x2;
915 case GL_FLOAT_MAT3x4:
916 return ATTRIBUTE_MAT3x4;
917 case GL_FLOAT_MAT4x2:
918 return ATTRIBUTE_MAT4x2;
919 case GL_FLOAT_MAT4x3:
920 return ATTRIBUTE_MAT4x3;
921 default:
922 UNREACHABLE();
923 return ATTRIBUTE_FLOAT;
924 }
925}
926
Jamie Madilld3dfda22015-07-06 08:28:49 -0400927VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
928{
929 switch (type)
930 {
931 case GL_BYTE:
932 switch (components)
933 {
934 case 1:
935 if (pureInteger)
936 return VERTEX_FORMAT_SBYTE1_INT;
937 if (normalized)
938 return VERTEX_FORMAT_SBYTE1_NORM;
939 return VERTEX_FORMAT_SBYTE1;
940 case 2:
941 if (pureInteger)
942 return VERTEX_FORMAT_SBYTE2_INT;
943 if (normalized)
944 return VERTEX_FORMAT_SBYTE2_NORM;
945 return VERTEX_FORMAT_SBYTE2;
946 case 3:
947 if (pureInteger)
948 return VERTEX_FORMAT_SBYTE3_INT;
949 if (normalized)
950 return VERTEX_FORMAT_SBYTE3_NORM;
951 return VERTEX_FORMAT_SBYTE3;
952 case 4:
953 if (pureInteger)
954 return VERTEX_FORMAT_SBYTE4_INT;
955 if (normalized)
956 return VERTEX_FORMAT_SBYTE4_NORM;
957 return VERTEX_FORMAT_SBYTE4;
958 default:
959 UNREACHABLE();
960 break;
961 }
962 case GL_UNSIGNED_BYTE:
963 switch (components)
964 {
965 case 1:
966 if (pureInteger)
967 return VERTEX_FORMAT_UBYTE1_INT;
968 if (normalized)
969 return VERTEX_FORMAT_UBYTE1_NORM;
970 return VERTEX_FORMAT_UBYTE1;
971 case 2:
972 if (pureInteger)
973 return VERTEX_FORMAT_UBYTE2_INT;
974 if (normalized)
975 return VERTEX_FORMAT_UBYTE2_NORM;
976 return VERTEX_FORMAT_UBYTE2;
977 case 3:
978 if (pureInteger)
979 return VERTEX_FORMAT_UBYTE3_INT;
980 if (normalized)
981 return VERTEX_FORMAT_UBYTE3_NORM;
982 return VERTEX_FORMAT_UBYTE3;
983 case 4:
984 if (pureInteger)
985 return VERTEX_FORMAT_UBYTE4_INT;
986 if (normalized)
987 return VERTEX_FORMAT_UBYTE4_NORM;
988 return VERTEX_FORMAT_UBYTE4;
989 default:
990 UNREACHABLE();
991 break;
992 }
993 case GL_SHORT:
994 switch (components)
995 {
996 case 1:
997 if (pureInteger)
998 return VERTEX_FORMAT_SSHORT1_INT;
999 if (normalized)
1000 return VERTEX_FORMAT_SSHORT1_NORM;
1001 return VERTEX_FORMAT_SSHORT1;
1002 case 2:
1003 if (pureInteger)
1004 return VERTEX_FORMAT_SSHORT2_INT;
1005 if (normalized)
1006 return VERTEX_FORMAT_SSHORT2_NORM;
1007 return VERTEX_FORMAT_SSHORT2;
1008 case 3:
1009 if (pureInteger)
1010 return VERTEX_FORMAT_SSHORT3_INT;
1011 if (normalized)
1012 return VERTEX_FORMAT_SSHORT3_NORM;
1013 return VERTEX_FORMAT_SSHORT3;
1014 case 4:
1015 if (pureInteger)
1016 return VERTEX_FORMAT_SSHORT4_INT;
1017 if (normalized)
1018 return VERTEX_FORMAT_SSHORT4_NORM;
1019 return VERTEX_FORMAT_SSHORT4;
1020 default:
1021 UNREACHABLE();
1022 break;
1023 }
1024 case GL_UNSIGNED_SHORT:
1025 switch (components)
1026 {
1027 case 1:
1028 if (pureInteger)
1029 return VERTEX_FORMAT_USHORT1_INT;
1030 if (normalized)
1031 return VERTEX_FORMAT_USHORT1_NORM;
1032 return VERTEX_FORMAT_USHORT1;
1033 case 2:
1034 if (pureInteger)
1035 return VERTEX_FORMAT_USHORT2_INT;
1036 if (normalized)
1037 return VERTEX_FORMAT_USHORT2_NORM;
1038 return VERTEX_FORMAT_USHORT2;
1039 case 3:
1040 if (pureInteger)
1041 return VERTEX_FORMAT_USHORT3_INT;
1042 if (normalized)
1043 return VERTEX_FORMAT_USHORT3_NORM;
1044 return VERTEX_FORMAT_USHORT3;
1045 case 4:
1046 if (pureInteger)
1047 return VERTEX_FORMAT_USHORT4_INT;
1048 if (normalized)
1049 return VERTEX_FORMAT_USHORT4_NORM;
1050 return VERTEX_FORMAT_USHORT4;
1051 default:
1052 UNREACHABLE();
1053 break;
1054 }
1055 case GL_INT:
1056 switch (components)
1057 {
1058 case 1:
1059 if (pureInteger)
1060 return VERTEX_FORMAT_SINT1_INT;
1061 if (normalized)
1062 return VERTEX_FORMAT_SINT1_NORM;
1063 return VERTEX_FORMAT_SINT1;
1064 case 2:
1065 if (pureInteger)
1066 return VERTEX_FORMAT_SINT2_INT;
1067 if (normalized)
1068 return VERTEX_FORMAT_SINT2_NORM;
1069 return VERTEX_FORMAT_SINT2;
1070 case 3:
1071 if (pureInteger)
1072 return VERTEX_FORMAT_SINT3_INT;
1073 if (normalized)
1074 return VERTEX_FORMAT_SINT3_NORM;
1075 return VERTEX_FORMAT_SINT3;
1076 case 4:
1077 if (pureInteger)
1078 return VERTEX_FORMAT_SINT4_INT;
1079 if (normalized)
1080 return VERTEX_FORMAT_SINT4_NORM;
1081 return VERTEX_FORMAT_SINT4;
1082 default:
1083 UNREACHABLE();
1084 break;
1085 }
1086 case GL_UNSIGNED_INT:
1087 switch (components)
1088 {
1089 case 1:
1090 if (pureInteger)
1091 return VERTEX_FORMAT_UINT1_INT;
1092 if (normalized)
1093 return VERTEX_FORMAT_UINT1_NORM;
1094 return VERTEX_FORMAT_UINT1;
1095 case 2:
1096 if (pureInteger)
1097 return VERTEX_FORMAT_UINT2_INT;
1098 if (normalized)
1099 return VERTEX_FORMAT_UINT2_NORM;
1100 return VERTEX_FORMAT_UINT2;
1101 case 3:
1102 if (pureInteger)
1103 return VERTEX_FORMAT_UINT3_INT;
1104 if (normalized)
1105 return VERTEX_FORMAT_UINT3_NORM;
1106 return VERTEX_FORMAT_UINT3;
1107 case 4:
1108 if (pureInteger)
1109 return VERTEX_FORMAT_UINT4_INT;
1110 if (normalized)
1111 return VERTEX_FORMAT_UINT4_NORM;
1112 return VERTEX_FORMAT_UINT4;
1113 default:
1114 UNREACHABLE();
1115 break;
1116 }
1117 case GL_FLOAT:
1118 switch (components)
1119 {
1120 case 1:
1121 return VERTEX_FORMAT_FLOAT1;
1122 case 2:
1123 return VERTEX_FORMAT_FLOAT2;
1124 case 3:
1125 return VERTEX_FORMAT_FLOAT3;
1126 case 4:
1127 return VERTEX_FORMAT_FLOAT4;
1128 default:
1129 UNREACHABLE();
1130 break;
1131 }
1132 case GL_HALF_FLOAT:
1133 switch (components)
1134 {
1135 case 1:
1136 return VERTEX_FORMAT_HALF1;
1137 case 2:
1138 return VERTEX_FORMAT_HALF2;
1139 case 3:
1140 return VERTEX_FORMAT_HALF3;
1141 case 4:
1142 return VERTEX_FORMAT_HALF4;
1143 default:
1144 UNREACHABLE();
1145 break;
1146 }
1147 case GL_FIXED:
1148 switch (components)
1149 {
1150 case 1:
1151 return VERTEX_FORMAT_FIXED1;
1152 case 2:
1153 return VERTEX_FORMAT_FIXED2;
1154 case 3:
1155 return VERTEX_FORMAT_FIXED3;
1156 case 4:
1157 return VERTEX_FORMAT_FIXED4;
1158 default:
1159 UNREACHABLE();
1160 break;
1161 }
1162 case GL_INT_2_10_10_10_REV:
1163 if (pureInteger)
1164 return VERTEX_FORMAT_SINT210_INT;
1165 if (normalized)
1166 return VERTEX_FORMAT_SINT210_NORM;
1167 return VERTEX_FORMAT_SINT210;
1168 case GL_UNSIGNED_INT_2_10_10_10_REV:
1169 if (pureInteger)
1170 return VERTEX_FORMAT_UINT210_INT;
1171 if (normalized)
1172 return VERTEX_FORMAT_UINT210_NORM;
1173 return VERTEX_FORMAT_UINT210;
1174 default:
1175 UNREACHABLE();
1176 break;
1177 }
1178 return VERTEX_FORMAT_UBYTE1;
1179}
1180
1181VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1182{
1183 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1184}
1185
1186VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1187{
1188 if (!attrib.enabled)
1189 {
1190 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1191 }
1192 return GetVertexFormatType(attrib);
1193}
1194
1195const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1196{
1197 switch (vertexFormatType)
1198 {
1199 case VERTEX_FORMAT_SBYTE1:
1200 {
1201 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1202 return format;
1203 }
1204 case VERTEX_FORMAT_SBYTE1_NORM:
1205 {
1206 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1207 return format;
1208 }
1209 case VERTEX_FORMAT_SBYTE2:
1210 {
1211 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1212 return format;
1213 }
1214 case VERTEX_FORMAT_SBYTE2_NORM:
1215 {
1216 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1217 return format;
1218 }
1219 case VERTEX_FORMAT_SBYTE3:
1220 {
1221 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1222 return format;
1223 }
1224 case VERTEX_FORMAT_SBYTE3_NORM:
1225 {
1226 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1227 return format;
1228 }
1229 case VERTEX_FORMAT_SBYTE4:
1230 {
1231 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1232 return format;
1233 }
1234 case VERTEX_FORMAT_SBYTE4_NORM:
1235 {
1236 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1237 return format;
1238 }
1239 case VERTEX_FORMAT_UBYTE1:
1240 {
1241 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1242 return format;
1243 }
1244 case VERTEX_FORMAT_UBYTE1_NORM:
1245 {
1246 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1247 return format;
1248 }
1249 case VERTEX_FORMAT_UBYTE2:
1250 {
1251 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1252 return format;
1253 }
1254 case VERTEX_FORMAT_UBYTE2_NORM:
1255 {
1256 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1257 return format;
1258 }
1259 case VERTEX_FORMAT_UBYTE3:
1260 {
1261 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1262 return format;
1263 }
1264 case VERTEX_FORMAT_UBYTE3_NORM:
1265 {
1266 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1267 return format;
1268 }
1269 case VERTEX_FORMAT_UBYTE4:
1270 {
1271 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1272 return format;
1273 }
1274 case VERTEX_FORMAT_UBYTE4_NORM:
1275 {
1276 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1277 return format;
1278 }
1279 case VERTEX_FORMAT_SSHORT1:
1280 {
1281 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1282 return format;
1283 }
1284 case VERTEX_FORMAT_SSHORT1_NORM:
1285 {
1286 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1287 return format;
1288 }
1289 case VERTEX_FORMAT_SSHORT2:
1290 {
1291 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1292 return format;
1293 }
1294 case VERTEX_FORMAT_SSHORT2_NORM:
1295 {
1296 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1297 return format;
1298 }
1299 case VERTEX_FORMAT_SSHORT3:
1300 {
1301 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1302 return format;
1303 }
1304 case VERTEX_FORMAT_SSHORT3_NORM:
1305 {
1306 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1307 return format;
1308 }
1309 case VERTEX_FORMAT_SSHORT4:
1310 {
1311 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1312 return format;
1313 }
1314 case VERTEX_FORMAT_SSHORT4_NORM:
1315 {
1316 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1317 return format;
1318 }
1319 case VERTEX_FORMAT_USHORT1:
1320 {
1321 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1322 return format;
1323 }
1324 case VERTEX_FORMAT_USHORT1_NORM:
1325 {
1326 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1327 return format;
1328 }
1329 case VERTEX_FORMAT_USHORT2:
1330 {
1331 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1332 return format;
1333 }
1334 case VERTEX_FORMAT_USHORT2_NORM:
1335 {
1336 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1337 return format;
1338 }
1339 case VERTEX_FORMAT_USHORT3:
1340 {
1341 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1342 return format;
1343 }
1344 case VERTEX_FORMAT_USHORT3_NORM:
1345 {
1346 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1347 return format;
1348 }
1349 case VERTEX_FORMAT_USHORT4:
1350 {
1351 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1352 return format;
1353 }
1354 case VERTEX_FORMAT_USHORT4_NORM:
1355 {
1356 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1357 return format;
1358 }
1359 case VERTEX_FORMAT_SINT1:
1360 {
1361 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1362 return format;
1363 }
1364 case VERTEX_FORMAT_SINT1_NORM:
1365 {
1366 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1367 return format;
1368 }
1369 case VERTEX_FORMAT_SINT2:
1370 {
1371 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1372 return format;
1373 }
1374 case VERTEX_FORMAT_SINT2_NORM:
1375 {
1376 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1377 return format;
1378 }
1379 case VERTEX_FORMAT_SINT3:
1380 {
1381 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1382 return format;
1383 }
1384 case VERTEX_FORMAT_SINT3_NORM:
1385 {
1386 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1387 return format;
1388 }
1389 case VERTEX_FORMAT_SINT4:
1390 {
1391 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1392 return format;
1393 }
1394 case VERTEX_FORMAT_SINT4_NORM:
1395 {
1396 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1397 return format;
1398 }
1399 case VERTEX_FORMAT_UINT1:
1400 {
1401 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1402 return format;
1403 }
1404 case VERTEX_FORMAT_UINT1_NORM:
1405 {
1406 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1407 return format;
1408 }
1409 case VERTEX_FORMAT_UINT2:
1410 {
1411 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1412 return format;
1413 }
1414 case VERTEX_FORMAT_UINT2_NORM:
1415 {
1416 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1417 return format;
1418 }
1419 case VERTEX_FORMAT_UINT3:
1420 {
1421 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1422 return format;
1423 }
1424 case VERTEX_FORMAT_UINT3_NORM:
1425 {
1426 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1427 return format;
1428 }
1429 case VERTEX_FORMAT_UINT4:
1430 {
1431 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1432 return format;
1433 }
1434 case VERTEX_FORMAT_UINT4_NORM:
1435 {
1436 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1437 return format;
1438 }
1439 case VERTEX_FORMAT_SBYTE1_INT:
1440 {
1441 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1442 return format;
1443 }
1444 case VERTEX_FORMAT_SBYTE2_INT:
1445 {
1446 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1447 return format;
1448 }
1449 case VERTEX_FORMAT_SBYTE3_INT:
1450 {
1451 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1452 return format;
1453 }
1454 case VERTEX_FORMAT_SBYTE4_INT:
1455 {
1456 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1457 return format;
1458 }
1459 case VERTEX_FORMAT_UBYTE1_INT:
1460 {
1461 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1462 return format;
1463 }
1464 case VERTEX_FORMAT_UBYTE2_INT:
1465 {
1466 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1467 return format;
1468 }
1469 case VERTEX_FORMAT_UBYTE3_INT:
1470 {
1471 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1472 return format;
1473 }
1474 case VERTEX_FORMAT_UBYTE4_INT:
1475 {
1476 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1477 return format;
1478 }
1479 case VERTEX_FORMAT_SSHORT1_INT:
1480 {
1481 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1482 return format;
1483 }
1484 case VERTEX_FORMAT_SSHORT2_INT:
1485 {
1486 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1487 return format;
1488 }
1489 case VERTEX_FORMAT_SSHORT3_INT:
1490 {
1491 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1492 return format;
1493 }
1494 case VERTEX_FORMAT_SSHORT4_INT:
1495 {
1496 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1497 return format;
1498 }
1499 case VERTEX_FORMAT_USHORT1_INT:
1500 {
1501 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1502 return format;
1503 }
1504 case VERTEX_FORMAT_USHORT2_INT:
1505 {
1506 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1507 return format;
1508 }
1509 case VERTEX_FORMAT_USHORT3_INT:
1510 {
1511 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1512 return format;
1513 }
1514 case VERTEX_FORMAT_USHORT4_INT:
1515 {
1516 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1517 return format;
1518 }
1519 case VERTEX_FORMAT_SINT1_INT:
1520 {
1521 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1522 return format;
1523 }
1524 case VERTEX_FORMAT_SINT2_INT:
1525 {
1526 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1527 return format;
1528 }
1529 case VERTEX_FORMAT_SINT3_INT:
1530 {
1531 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1532 return format;
1533 }
1534 case VERTEX_FORMAT_SINT4_INT:
1535 {
1536 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1537 return format;
1538 }
1539 case VERTEX_FORMAT_UINT1_INT:
1540 {
1541 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1542 return format;
1543 }
1544 case VERTEX_FORMAT_UINT2_INT:
1545 {
1546 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1547 return format;
1548 }
1549 case VERTEX_FORMAT_UINT3_INT:
1550 {
1551 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1552 return format;
1553 }
1554 case VERTEX_FORMAT_UINT4_INT:
1555 {
1556 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1557 return format;
1558 }
1559 case VERTEX_FORMAT_FIXED1:
1560 {
1561 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1562 return format;
1563 }
1564 case VERTEX_FORMAT_FIXED2:
1565 {
1566 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1567 return format;
1568 }
1569 case VERTEX_FORMAT_FIXED3:
1570 {
1571 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1572 return format;
1573 }
1574 case VERTEX_FORMAT_FIXED4:
1575 {
1576 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1577 return format;
1578 }
1579 case VERTEX_FORMAT_HALF1:
1580 {
1581 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1582 return format;
1583 }
1584 case VERTEX_FORMAT_HALF2:
1585 {
1586 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1587 return format;
1588 }
1589 case VERTEX_FORMAT_HALF3:
1590 {
1591 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1592 return format;
1593 }
1594 case VERTEX_FORMAT_HALF4:
1595 {
1596 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1597 return format;
1598 }
1599 case VERTEX_FORMAT_FLOAT1:
1600 {
1601 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1602 return format;
1603 }
1604 case VERTEX_FORMAT_FLOAT2:
1605 {
1606 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1607 return format;
1608 }
1609 case VERTEX_FORMAT_FLOAT3:
1610 {
1611 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1612 return format;
1613 }
1614 case VERTEX_FORMAT_FLOAT4:
1615 {
1616 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1617 return format;
1618 }
1619 case VERTEX_FORMAT_SINT210:
1620 {
1621 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1622 return format;
1623 }
1624 case VERTEX_FORMAT_UINT210:
1625 {
1626 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1627 return format;
1628 }
1629 case VERTEX_FORMAT_SINT210_NORM:
1630 {
1631 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1632 return format;
1633 }
1634 case VERTEX_FORMAT_UINT210_NORM:
1635 {
1636 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1637 return format;
1638 }
1639 case VERTEX_FORMAT_SINT210_INT:
1640 {
1641 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1642 return format;
1643 }
1644 case VERTEX_FORMAT_UINT210_INT:
1645 {
1646 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1647 return format;
1648 }
1649 default:
1650 {
1651 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1652 return format;
1653 }
1654 }
1655}
1656
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001657size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1658{
1659 switch (vertexFormatType)
1660 {
1661 case VERTEX_FORMAT_SBYTE1:
1662 case VERTEX_FORMAT_SBYTE1_NORM:
1663 case VERTEX_FORMAT_UBYTE1:
1664 case VERTEX_FORMAT_UBYTE1_NORM:
1665 case VERTEX_FORMAT_SBYTE1_INT:
1666 case VERTEX_FORMAT_UBYTE1_INT:
1667 return 1;
1668
1669 case VERTEX_FORMAT_SBYTE2:
1670 case VERTEX_FORMAT_SBYTE2_NORM:
1671 case VERTEX_FORMAT_UBYTE2:
1672 case VERTEX_FORMAT_UBYTE2_NORM:
1673 case VERTEX_FORMAT_SBYTE2_INT:
1674 case VERTEX_FORMAT_UBYTE2_INT:
1675 case VERTEX_FORMAT_SSHORT1:
1676 case VERTEX_FORMAT_SSHORT1_NORM:
1677 case VERTEX_FORMAT_USHORT1:
1678 case VERTEX_FORMAT_USHORT1_NORM:
1679 case VERTEX_FORMAT_SSHORT1_INT:
1680 case VERTEX_FORMAT_USHORT1_INT:
1681 case VERTEX_FORMAT_HALF1:
1682 return 2;
1683
1684 case VERTEX_FORMAT_SBYTE3:
1685 case VERTEX_FORMAT_SBYTE3_NORM:
1686 case VERTEX_FORMAT_UBYTE3:
1687 case VERTEX_FORMAT_UBYTE3_NORM:
1688 case VERTEX_FORMAT_SBYTE3_INT:
1689 case VERTEX_FORMAT_UBYTE3_INT:
1690 return 3;
1691
1692 case VERTEX_FORMAT_SBYTE4:
1693 case VERTEX_FORMAT_SBYTE4_NORM:
1694 case VERTEX_FORMAT_UBYTE4:
1695 case VERTEX_FORMAT_UBYTE4_NORM:
1696 case VERTEX_FORMAT_SBYTE4_INT:
1697 case VERTEX_FORMAT_UBYTE4_INT:
1698 case VERTEX_FORMAT_SSHORT2:
1699 case VERTEX_FORMAT_SSHORT2_NORM:
1700 case VERTEX_FORMAT_USHORT2:
1701 case VERTEX_FORMAT_USHORT2_NORM:
1702 case VERTEX_FORMAT_SSHORT2_INT:
1703 case VERTEX_FORMAT_USHORT2_INT:
1704 case VERTEX_FORMAT_SINT1:
1705 case VERTEX_FORMAT_SINT1_NORM:
1706 case VERTEX_FORMAT_UINT1:
1707 case VERTEX_FORMAT_UINT1_NORM:
1708 case VERTEX_FORMAT_SINT1_INT:
1709 case VERTEX_FORMAT_UINT1_INT:
1710 case VERTEX_FORMAT_HALF2:
1711 case VERTEX_FORMAT_FIXED1:
1712 case VERTEX_FORMAT_FLOAT1:
1713 case VERTEX_FORMAT_SINT210:
1714 case VERTEX_FORMAT_UINT210:
1715 case VERTEX_FORMAT_SINT210_NORM:
1716 case VERTEX_FORMAT_UINT210_NORM:
1717 case VERTEX_FORMAT_SINT210_INT:
1718 case VERTEX_FORMAT_UINT210_INT:
1719 return 4;
1720
1721 case VERTEX_FORMAT_SSHORT3:
1722 case VERTEX_FORMAT_SSHORT3_NORM:
1723 case VERTEX_FORMAT_USHORT3:
1724 case VERTEX_FORMAT_USHORT3_NORM:
1725 case VERTEX_FORMAT_SSHORT3_INT:
1726 case VERTEX_FORMAT_USHORT3_INT:
1727 case VERTEX_FORMAT_HALF3:
1728 return 6;
1729
1730 case VERTEX_FORMAT_SSHORT4:
1731 case VERTEX_FORMAT_SSHORT4_NORM:
1732 case VERTEX_FORMAT_USHORT4:
1733 case VERTEX_FORMAT_USHORT4_NORM:
1734 case VERTEX_FORMAT_SSHORT4_INT:
1735 case VERTEX_FORMAT_USHORT4_INT:
1736 case VERTEX_FORMAT_SINT2:
1737 case VERTEX_FORMAT_SINT2_NORM:
1738 case VERTEX_FORMAT_UINT2:
1739 case VERTEX_FORMAT_UINT2_NORM:
1740 case VERTEX_FORMAT_SINT2_INT:
1741 case VERTEX_FORMAT_UINT2_INT:
1742 case VERTEX_FORMAT_HALF4:
1743 case VERTEX_FORMAT_FIXED2:
1744 case VERTEX_FORMAT_FLOAT2:
1745 return 8;
1746
1747 case VERTEX_FORMAT_SINT3:
1748 case VERTEX_FORMAT_SINT3_NORM:
1749 case VERTEX_FORMAT_UINT3:
1750 case VERTEX_FORMAT_UINT3_NORM:
1751 case VERTEX_FORMAT_SINT3_INT:
1752 case VERTEX_FORMAT_UINT3_INT:
1753 case VERTEX_FORMAT_FIXED3:
1754 case VERTEX_FORMAT_FLOAT3:
1755 return 12;
1756
1757 case VERTEX_FORMAT_SINT4:
1758 case VERTEX_FORMAT_SINT4_NORM:
1759 case VERTEX_FORMAT_UINT4:
1760 case VERTEX_FORMAT_UINT4_NORM:
1761 case VERTEX_FORMAT_SINT4_INT:
1762 case VERTEX_FORMAT_UINT4_INT:
1763 case VERTEX_FORMAT_FIXED4:
1764 case VERTEX_FORMAT_FLOAT4:
1765 return 16;
1766
1767 case VERTEX_FORMAT_INVALID:
1768 default:
1769 UNREACHABLE();
1770 return 0;
1771 }
1772}
1773
Jamie Madilld3dfda22015-07-06 08:28:49 -04001774VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1775 : type(typeIn),
1776 normalized(normalizedIn),
1777 components(componentsIn),
1778 pureInteger(pureIntegerIn)
1779{
1780 // float -> !normalized
1781 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1782}
1783
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001784}