blob: 3ddafddc2fc6170e12f56d50a7760f5e82eb33c9 [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.
22
Jamie Madilld2b50a02016-06-09 00:13:35 -070023typedef std::pair<FormatType, GLenum> FormatPair;
24typedef std::map<FormatType, GLenum> FormatMap;
25
26FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
27{
28}
29
30FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
31{
32}
33
34bool FormatType::operator<(const FormatType &other) const
35{
36 if (format != other.format)
37 return format < other.format;
38 return type < other.type;
39}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000040
Jamie Madill89a0bf52013-09-18 14:36:24 -040041// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050042static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000043{
Jamie Madilld2b50a02016-06-09 00:13:35 -070044 map->insert(FormatPair(FormatType(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045}
46
Geoff Lange4a492b2014-06-19 14:14:41 -040047FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000048{
49 FormatMap map;
50
Jamie Madill1e8dcb52016-07-22 12:01:41 -040051 // clang-format off
Geoff Lang051dbc72015-01-05 15:48:58 -050052 // | Format | Type | Internal format |
53 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
54 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
55 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
56 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
57 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
58 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
59 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
60 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000061
Geoff Lang051dbc72015-01-05 15:48:58 -050062 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
63 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
64 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
65 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
66 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
67 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
68 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000069
Geoff Lang051dbc72015-01-05 15:48:58 -050070 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
71 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
72 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
73 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
74 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
75 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
76 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
77 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000078
Geoff Lang051dbc72015-01-05 15:48:58 -050079 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
80 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
81 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
82 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
83 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
84 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000085
Geoff Lang051dbc72015-01-05 15:48:58 -050086 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
87 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
88 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
89 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
90 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000091
Geoff Lang051dbc72015-01-05 15:48:58 -050092 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
93 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
94 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
95 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
96 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
97 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040098
Geoff Lang051dbc72015-01-05 15:48:58 -050099 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
100 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
101 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
102 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
103 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -0400104
Geoff Lang051dbc72015-01-05 15:48:58 -0500105 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
106 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
107 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
108 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
109 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
110 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -0400111
Geoff Lang051dbc72015-01-05 15:48:58 -0500112 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
113 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
114 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
115 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
116 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
117 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
118 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
119 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
120 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
121 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
122 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
123 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400124
Geoff Lang051dbc72015-01-05 15:48:58 -0500125 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
126 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
127 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX);
Geoff Langfe28ca02013-06-04 10:10:48 -0400128
Geoff Lang051dbc72015-01-05 15:48:58 -0500129 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
130 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400131
Geoff Lang051dbc72015-01-05 15:48:58 -0500132 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
133 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
134 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
135 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400136
Geoff Lang051dbc72015-01-05 15:48:58 -0500137 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
138 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
139 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400140
Geoff Lang051dbc72015-01-05 15:48:58 -0500141 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400142
Geoff Lang051dbc72015-01-05 15:48:58 -0500143 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
144 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000145
Jamie Madill1e8dcb52016-07-22 12:01:41 -0400146 // From GL_EXT_texture_norm16
147 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_SHORT, GL_R16_EXT);
148 InsertFormatMapping(&map, GL_RED, GL_SHORT, GL_R16_SNORM_EXT);
149 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_SHORT, GL_RG16_EXT);
150 InsertFormatMapping(&map, GL_RG, GL_SHORT, GL_RG16_SNORM_EXT);
151 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT, GL_RGB16_EXT);
152 InsertFormatMapping(&map, GL_RGB, GL_SHORT, GL_RGB16_SNORM_EXT);
153 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT, GL_RGBA16_EXT);
154 InsertFormatMapping(&map, GL_RGBA, GL_SHORT, GL_RGBA16_SNORM_EXT);
155 // clang-format on
156
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000157 return map;
158}
159
Geoff Lang5d601382014-07-22 15:14:06 -0400160Type::Type()
161 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200162 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400163 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400164{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000165}
166
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200167static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000168{
Geoff Lang5d601382014-07-22 15:14:06 -0400169 Type info;
170 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200171 GLuint i = 0;
172 while ((1u << i) < bytes)
173 {
174 ++i;
175 }
176 info.bytesShift = i;
177 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400178 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200179 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400180}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000181
Geoff Lang5d601382014-07-22 15:14:06 -0400182bool operator<(const Type& a, const Type& b)
183{
184 return memcmp(&a, &b, sizeof(Type)) < 0;
185}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000186
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000187// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400188static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000189{
Geoff Lang493daf52014-07-03 13:38:44 -0400190 return true;
191}
192
Geoff Lang493daf52014-07-03 13:38:44 -0400193static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000194{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000195 return false;
196}
197
Geoff Lange4a492b2014-06-19 14:14:41 -0400198template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400199static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400200{
201 return clientVersion >= minCoreGLVersion;
202}
203
Geoff Langcec35902014-04-16 10:52:36 -0400204// Pointer to a boolean memeber of the Extensions struct
205typedef bool(Extensions::*ExtensionBool);
206
207// Check support for a single extension
208template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400209static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400210{
Geoff Lange4a492b2014-06-19 14:14:41 -0400211 return extensions.*bool1;
212}
213
214// Check for a minimum client version or a single extension
215template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400216static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400217{
218 return clientVersion >= minCoreGLVersion || extensions.*bool1;
219}
220
221// Check for a minimum client version or two extensions
222template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400223static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400224{
Geoff Langabce7622014-09-19 16:13:00 -0400225 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
226}
227
228// Check for a minimum client version or at least one of two extensions
229template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
230static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
231{
232 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400233}
234
235// Check support for two extensions
236template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400237static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400238{
Geoff Langabce7622014-09-19 16:13:00 -0400239 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400240}
241
Geoff Lang60ad73d2015-10-23 10:08:44 -0400242// Check support for either of two extensions
243template <ExtensionBool bool1, ExtensionBool bool2>
244static bool RequireExtOrExt(GLuint, const Extensions &extensions)
245{
246 return extensions.*bool1 || extensions.*bool2;
247}
248
Jamie Madillcd089732015-12-17 09:53:09 -0500249// Special function for half float formats with three or four channels.
250static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
251{
252 return clientVersion >= 3 || extensions.textureHalfFloat;
253}
254
255static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
256{
257 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
258}
259
260// Special function for half float formats with one or two channels.
261static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
262{
263 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
264}
265
266static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
267{
268 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
269}
270
271// Special function for float formats with three or four channels.
272static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
273{
274 return clientVersion >= 3 || extensions.textureFloat;
275}
276
277static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
278{
279 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
280 return FloatSupport(clientVersion, extensions) &&
281 (extensions.colorBufferFloat || clientVersion == 2);
282}
283
284// Special function for float formats with one or two channels.
285static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
286{
287 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
288}
289
290static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
291{
292 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
293 return FloatSupportRG(clientVersion, extensions) &&
294 (extensions.colorBufferFloat || clientVersion == 2);
295}
296
Geoff Lang5d601382014-07-22 15:14:06 -0400297InternalFormat::InternalFormat()
298 : redBits(0),
299 greenBits(0),
300 blueBits(0),
301 luminanceBits(0),
302 alphaBits(0),
303 sharedBits(0),
304 depthBits(0),
305 stencilBits(0),
306 pixelBytes(0),
307 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400308 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400309 compressedBlockWidth(0),
310 compressedBlockHeight(0),
311 format(GL_NONE),
312 type(GL_NONE),
313 componentType(GL_NONE),
314 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400315 textureSupport(NeverSupported),
316 renderSupport(NeverSupported),
317 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000318{
Geoff Lang5d601382014-07-22 15:14:06 -0400319}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000320
Geoff Lang5d601382014-07-22 15:14:06 -0400321static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
322 InternalFormat::SupportCheckFunction renderSupport,
323 InternalFormat::SupportCheckFunction filterSupport)
324{
325 InternalFormat formatInfo;
326 formatInfo.format = format;
327 formatInfo.textureSupport = textureSupport;
328 formatInfo.renderSupport = renderSupport;
329 formatInfo.filterSupport = filterSupport;
330 return formatInfo;
331}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000332
Geoff Lang5d601382014-07-22 15:14:06 -0400333static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
334 GLenum format, GLenum type, GLenum componentType, bool srgb,
335 InternalFormat::SupportCheckFunction textureSupport,
336 InternalFormat::SupportCheckFunction renderSupport,
337 InternalFormat::SupportCheckFunction filterSupport)
338{
339 InternalFormat formatInfo;
340 formatInfo.redBits = red;
341 formatInfo.greenBits = green;
342 formatInfo.blueBits = blue;
343 formatInfo.alphaBits = alpha;
344 formatInfo.sharedBits = shared;
345 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
346 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
347 formatInfo.format = format;
348 formatInfo.type = type;
349 formatInfo.componentType = componentType;
350 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
351 formatInfo.textureSupport = textureSupport;
352 formatInfo.renderSupport = renderSupport;
353 formatInfo.filterSupport = filterSupport;
354 return formatInfo;
355}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000356
Geoff Lang5d601382014-07-22 15:14:06 -0400357static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
358 InternalFormat::SupportCheckFunction textureSupport,
359 InternalFormat::SupportCheckFunction renderSupport,
360 InternalFormat::SupportCheckFunction filterSupport)
361{
362 InternalFormat formatInfo;
363 formatInfo.luminanceBits = luminance;
364 formatInfo.alphaBits = alpha;
365 formatInfo.pixelBytes = (luminance + alpha) / 8;
366 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
367 formatInfo.format = format;
368 formatInfo.type = type;
369 formatInfo.componentType = componentType;
370 formatInfo.colorEncoding = GL_LINEAR;
371 formatInfo.textureSupport = textureSupport;
372 formatInfo.renderSupport = renderSupport;
373 formatInfo.filterSupport = filterSupport;
374 return formatInfo;
375}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000376
Geoff Lang5d601382014-07-22 15:14:06 -0400377static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
378 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
379 InternalFormat::SupportCheckFunction renderSupport,
380 InternalFormat::SupportCheckFunction filterSupport)
381{
382 InternalFormat formatInfo;
383 formatInfo.depthBits = depthBits;
384 formatInfo.stencilBits = stencilBits;
385 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
386 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
387 formatInfo.format = format;
388 formatInfo.type = type;
389 formatInfo.componentType = componentType;
390 formatInfo.colorEncoding = GL_LINEAR;
391 formatInfo.textureSupport = textureSupport;
392 formatInfo.renderSupport = renderSupport;
393 formatInfo.filterSupport = filterSupport;
394 return formatInfo;
395}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000396
Geoff Lang5d601382014-07-22 15:14:06 -0400397static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
398 GLuint componentCount, GLenum format, GLenum type, bool srgb,
399 InternalFormat::SupportCheckFunction textureSupport,
400 InternalFormat::SupportCheckFunction renderSupport,
401 InternalFormat::SupportCheckFunction filterSupport)
402{
403 InternalFormat formatInfo;
404 formatInfo.compressedBlockWidth = compressedBlockWidth;
405 formatInfo.compressedBlockHeight = compressedBlockHeight;
406 formatInfo.pixelBytes = compressedBlockSize / 8;
407 formatInfo.componentCount = componentCount;
408 formatInfo.format = format;
409 formatInfo.type = type;
410 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
411 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
412 formatInfo.compressed = true;
413 formatInfo.textureSupport = textureSupport;
414 formatInfo.renderSupport = renderSupport;
415 formatInfo.filterSupport = filterSupport;
416 return formatInfo;
417}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000418
Geoff Lang5d601382014-07-22 15:14:06 -0400419typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
420typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000421
Geoff Lange4a492b2014-06-19 14:14:41 -0400422static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000423{
424 InternalFormatInfoMap map;
425
Geoff Lang9bbad182015-09-04 11:07:29 -0400426 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000427 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400428 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000429
Geoff Langabce7622014-09-19 16:13:00 -0400430 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
431 map.insert(InternalFormatInfoPair(GL_R8, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported)));
432 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
433 map.insert(InternalFormatInfoPair(GL_RG8, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported)));
434 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
435 map.insert(InternalFormatInfoPair(GL_RGB8, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported)));
436 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
437 map.insert(InternalFormatInfoPair(GL_RGB565, RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported)));
438 map.insert(InternalFormatInfoPair(GL_RGBA4, RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported)));
439 map.insert(InternalFormatInfoPair(GL_RGB5_A1, RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported)));
440 map.insert(InternalFormatInfoPair(GL_RGBA8, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported)));
441 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
442 map.insert(InternalFormatInfoPair(GL_RGB10_A2, RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3>, RequireES<3>, AlwaysSupported)));
Geoff Lang9bbad182015-09-04 11:07:29 -0400443 map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, RGBAFormat(10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
Geoff Langabce7622014-09-19 16:13:00 -0400444 map.insert(InternalFormatInfoPair(GL_SRGB8, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
445 map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported)));
446 map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported)));
447 map.insert(InternalFormatInfoPair(GL_RGB9_E5, RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3>, NeverSupported, AlwaysSupported)));
448 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
449 map.insert(InternalFormatInfoPair(GL_R8UI, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
450 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
451 map.insert(InternalFormatInfoPair(GL_R16UI, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
452 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
453 map.insert(InternalFormatInfoPair(GL_R32UI, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
454 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
455 map.insert(InternalFormatInfoPair(GL_RG8UI, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
456 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
457 map.insert(InternalFormatInfoPair(GL_RG16UI, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
458 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
459 map.insert(InternalFormatInfoPair(GL_RG32UI, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
460 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
461 map.insert(InternalFormatInfoPair(GL_RGB8UI, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
462 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
463 map.insert(InternalFormatInfoPair(GL_RGB16UI, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
464 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
465 map.insert(InternalFormatInfoPair(GL_RGB32UI, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
466 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
467 map.insert(InternalFormatInfoPair(GL_RGBA8UI, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
468 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
469 map.insert(InternalFormatInfoPair(GL_RGBA16UI, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
470 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
471 map.insert(InternalFormatInfoPair(GL_RGBA32UI, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000472
Geoff Langabce7622014-09-19 16:13:00 -0400473 map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
474 map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, RGBAFormat( 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)));
475 map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, RGBAFormat( 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 +0000476
Jamie Madillec0b5802016-07-04 13:11:59 -0400477 // Special format which is not really supported, so always false for all supports.
478 map.insert(InternalFormatInfoPair(GL_BGR565_ANGLEX, RGBAFormat( 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported)));
479
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000480 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500481 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
482 // | | | | | | | type | | | | |
483 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
484 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
485 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
486 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
487 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
488 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
489 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
490 map.insert(InternalFormatInfoPair(GL_RGBA32F, RGBAFormat(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 +0000491
492 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400493 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
494 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, DepthStencilFormat(16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, RequireESOrExt<3, &Extensions::depthTextures>)));
495 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, DepthStencilFormat(24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>)));
496 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>)));
Jamie Madillf06e6072015-12-01 10:44:16 -0500497 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported )));
Geoff Langabce7622014-09-19 16:13:00 -0400498 map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, DepthStencilFormat(24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, &Extensions::depthTextures>, RequireESOrExtOrExt<3, &Extensions::depthTextures, &Extensions::packedDepthStencil>, AlwaysSupported )));
499 map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, DepthStencilFormat(32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3>, RequireES<3>, AlwaysSupported )));
Corentin Walleze0902642014-11-04 12:32:15 -0800500 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000501
502 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400503 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400504 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
505 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
506 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
507 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
508 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
509 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
510 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
511 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
512 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 +0000513
514 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400515 // | Internal format | | Format | Supported | Renderable | Filterable |
516 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
517 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
518 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
519 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
520 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
521 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
522 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
523 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
524 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
525 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
526 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
527 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
528 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
529 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
530 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
531 map.insert(InternalFormatInfoPair(GL_SRGB_ALPHA_EXT, UnsizedFormat(GL_RGBA, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000532
533 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400534 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
535 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
536 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
537 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
538 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
539 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
540 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
541 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>, NeverSupported, AlwaysSupported)));
542 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>, NeverSupported, AlwaysSupported)));
543 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
544 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>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000545
546 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400547 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
548 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)));
549 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 +0000550
551 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400552 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 +0000553
554 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400555 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)));
556
557 // From GL_OES_compressed_ETC1_RGB8_texture
558 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 +0000559
Geoff Lang60ad73d2015-10-23 10:08:44 -0400560 // From KHR_texture_compression_astc_hdr
561 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
562 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)));
563 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)));
564 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)));
565 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)));
566 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)));
567 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)));
568 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)));
569 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)));
570 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)));
571 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)));
572 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)));
573 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)));
574 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)));
575 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)));
576
577 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)));
578 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)));
579 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)));
580 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)));
581 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)));
582 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)));
583 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)));
584 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)));
585 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)));
586 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)));
587 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)));
588 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)));
589 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)));
590 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)));
591
Corentin Walleze0902642014-11-04 12:32:15 -0800592 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
593 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
594 // - All other stencil formats (all depth-stencil) are either float or normalized
595 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Jamie Madill6dd28432016-07-22 14:28:42 -0400596 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
597 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, DepthStencilFormat(0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800598
599 // From GL_ANGLE_lossy_etc_decode
600 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_OES, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
601
Vincent Lang25ab4512016-05-13 18:13:59 +0200602 // From GL_EXT_texture_norm16
603 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
604 map.insert(InternalFormatInfoPair(GL_R16_EXT, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
605 map.insert(InternalFormatInfoPair(GL_R16_SNORM_EXT, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
606 map.insert(InternalFormatInfoPair(GL_RG16_EXT, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
607 map.insert(InternalFormatInfoPair(GL_RG16_SNORM_EXT, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
608 map.insert(InternalFormatInfoPair(GL_RGB16_EXT, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
609 map.insert(InternalFormatInfoPair(GL_RGB16_SNORM_EXT, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
610 map.insert(InternalFormatInfoPair(GL_RGBA16_EXT, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
611 map.insert(InternalFormatInfoPair(GL_RGBA16_SNORM_EXT, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
612
Geoff Lang9bbad182015-09-04 11:07:29 -0400613 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800614
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000615 return map;
616}
617
Geoff Lange4a492b2014-06-19 14:14:41 -0400618static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000619{
Geoff Lange4a492b2014-06-19 14:14:41 -0400620 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
621 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000622}
623
Geoff Lange4a492b2014-06-19 14:14:41 -0400624static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400625{
626 FormatSet result;
627
Jamie Madillec0b5802016-07-04 13:11:59 -0400628 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400629 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400630 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400631 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400632 // TODO(jmadill): Fix this hack.
633 if (iter.first == GL_BGR565_ANGLEX)
634 continue;
635
636 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400637 }
638 }
639
640 return result;
641}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000642
Geoff Lang5d601382014-07-22 15:14:06 -0400643const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000644{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200645 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000646 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200647 case GL_UNSIGNED_BYTE:
648 case GL_BYTE:
649 {
650 static const Type info = GenTypeInfo(1, false);
651 return info;
652 }
653 case GL_UNSIGNED_SHORT:
654 case GL_SHORT:
655 case GL_HALF_FLOAT:
656 case GL_HALF_FLOAT_OES:
657 {
658 static const Type info = GenTypeInfo(2, false);
659 return info;
660 }
661 case GL_UNSIGNED_INT:
662 case GL_INT:
663 case GL_FLOAT:
664 {
665 static const Type info = GenTypeInfo(4, false);
666 return info;
667 }
668 case GL_UNSIGNED_SHORT_5_6_5:
669 case GL_UNSIGNED_SHORT_4_4_4_4:
670 case GL_UNSIGNED_SHORT_5_5_5_1:
671 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
672 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
673 {
674 static const Type info = GenTypeInfo(2, true);
675 return info;
676 }
677 case GL_UNSIGNED_INT_2_10_10_10_REV:
678 case GL_UNSIGNED_INT_24_8:
679 case GL_UNSIGNED_INT_10F_11F_11F_REV:
680 case GL_UNSIGNED_INT_5_9_9_9_REV:
681 {
682 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
683 static const Type info = GenTypeInfo(4, true);
684 return info;
685 }
686 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
687 {
688 static const Type info = GenTypeInfo(8, true);
689 return info;
690 }
691 default:
692 {
693 static const Type defaultInfo;
694 return defaultInfo;
695 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000696 }
697}
698
Geoff Lang5d601382014-07-22 15:14:06 -0400699const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000700{
Geoff Lang5d601382014-07-22 15:14:06 -0400701 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400702 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400703 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000704 {
Geoff Lang5d601382014-07-22 15:14:06 -0400705 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000706 }
707 else
708 {
Geoff Lang5d601382014-07-22 15:14:06 -0400709 static const InternalFormat defaultInternalFormat;
Jamie Madillec0b5802016-07-04 13:11:59 -0400710 UNREACHABLE();
Geoff Lang5d601382014-07-22 15:14:06 -0400711 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000712 }
713}
714
Jamie Madille2e406c2016-06-02 13:04:10 -0400715gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
716 GLsizei width,
717 GLint alignment,
718 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000719{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700720 // Compressed images do not use pack/unpack parameters.
721 if (compressed)
722 {
723 ASSERT(rowLength == 0);
724 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
725 }
726
Geoff Lang3f234062016-07-13 15:35:45 -0400727 const auto &typeInfo = GetTypeInfo(formatType);
728 CheckedNumeric<GLuint> checkedComponents(typeInfo.specialInterpretation ? 1u : componentCount);
729 CheckedNumeric<GLuint> checkedTypeBytes(typeInfo.bytes);
730 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
731 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * checkedComponents * checkedTypeBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700732
733 ASSERT(alignment > 0 && isPow2(alignment));
734 CheckedNumeric<GLuint> checkedAlignment(alignment);
735 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
736 ANGLE_TRY_CHECKED_MATH(aligned);
737 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000738}
739
Jamie Madille2e406c2016-06-02 13:04:10 -0400740gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
741 GLsizei width,
742 GLsizei height,
743 GLint alignment,
744 GLint rowLength,
745 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000746{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700747 GLuint rows =
748 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400749 GLuint rowPitch = 0;
750 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
751
752 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
753 auto depthPitch = checkedRowPitch * rows;
754 ANGLE_TRY_CHECKED_MATH(depthPitch);
755 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000756}
757
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700758gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
759 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000760{
Jamie Madill513558d2016-06-02 13:04:11 -0400761 CheckedNumeric<GLuint> checkedWidth(size.width);
762 CheckedNumeric<GLuint> checkedHeight(size.height);
763 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700764 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
765 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400766
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700767 ASSERT(compressed);
768 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
769 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
770 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
771 ANGLE_TRY_CHECKED_MATH(bytes);
772 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000773}
774
Olli Etuaho989cac32016-06-08 16:18:49 -0700775gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
776 GLuint depthPitch,
777 GLint skipImages,
778 GLint skipRows,
779 GLint skipPixels,
780 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400781{
Olli Etuaho989cac32016-06-08 16:18:49 -0700782 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
783 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
784 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
785 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
786 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
787 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
788 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
789 if (!applySkipImages)
790 {
791 checkedSkipImagesBytes = 0;
792 }
793 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
794 checkedSkipPixels * checkedPixelBytes;
795 ANGLE_TRY_CHECKED_MATH(skipBytes);
796 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400797}
798
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700799gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
800 GLenum formatType,
801 const gl::Extents &size,
802 const gl::PixelUnpackState &unpack) const
803{
804 // Compressed images do not use unpack parameters.
805 if (compressed)
806 {
807 return computeCompressedImageSize(formatType, size);
808 }
809
810 base::CheckedNumeric<GLuint> checkedGroups(unpack.rowLength > 0 ? unpack.rowLength
811 : size.width);
812 base::CheckedNumeric<GLuint> checkedRows(unpack.imageHeight > 0 ? unpack.imageHeight
813 : size.height);
814
815 // Compute the groups of all the layers in (0,depth-1)
816 auto layerGroups = checkedGroups * checkedRows * (size.depth - 1);
817
818 // Compute the groups in the last layer (for non-3D textures, the only one)
819 auto lastLayerGroups = checkedGroups * (size.height - 1) + size.width;
820
821 // The total size is the sum times the bytes per pixel.
822 auto totalSize = (layerGroups + lastLayerGroups) * pixelBytes;
823
824 ANGLE_TRY_CHECKED_MATH(totalSize);
825
826 return totalSize.ValueOrDie();
827}
828
Geoff Lang5d601382014-07-22 15:14:06 -0400829GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000830{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700831 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500832 if (formatInfo.pixelBytes > 0)
833 {
834 return internalFormat;
835 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700836
837 static const FormatMap formatMap = BuildFormatMap();
Jamie Madilld2b50a02016-06-09 00:13:35 -0700838 auto iter = formatMap.find(FormatType(internalFormat, type));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700839 if (iter != formatMap.end())
Geoff Lang051dbc72015-01-05 15:48:58 -0500840 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700841 return iter->second;
Geoff Lang051dbc72015-01-05 15:48:58 -0500842 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700843
844 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000845}
846
Geoff Lange4a492b2014-06-19 14:14:41 -0400847const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400848{
Geoff Lange4a492b2014-06-19 14:14:41 -0400849 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400850 return formatSet;
851}
852
Jamie Madill09e2d932015-07-14 16:40:31 -0400853AttributeType GetAttributeType(GLenum enumValue)
854{
855 switch (enumValue)
856 {
857 case GL_FLOAT:
858 return ATTRIBUTE_FLOAT;
859 case GL_FLOAT_VEC2:
860 return ATTRIBUTE_VEC2;
861 case GL_FLOAT_VEC3:
862 return ATTRIBUTE_VEC3;
863 case GL_FLOAT_VEC4:
864 return ATTRIBUTE_VEC4;
865 case GL_INT:
866 return ATTRIBUTE_INT;
867 case GL_INT_VEC2:
868 return ATTRIBUTE_IVEC2;
869 case GL_INT_VEC3:
870 return ATTRIBUTE_IVEC3;
871 case GL_INT_VEC4:
872 return ATTRIBUTE_IVEC4;
873 case GL_UNSIGNED_INT:
874 return ATTRIBUTE_UINT;
875 case GL_UNSIGNED_INT_VEC2:
876 return ATTRIBUTE_UVEC2;
877 case GL_UNSIGNED_INT_VEC3:
878 return ATTRIBUTE_UVEC3;
879 case GL_UNSIGNED_INT_VEC4:
880 return ATTRIBUTE_UVEC4;
881 case GL_FLOAT_MAT2:
882 return ATTRIBUTE_MAT2;
883 case GL_FLOAT_MAT3:
884 return ATTRIBUTE_MAT3;
885 case GL_FLOAT_MAT4:
886 return ATTRIBUTE_MAT4;
887 case GL_FLOAT_MAT2x3:
888 return ATTRIBUTE_MAT2x3;
889 case GL_FLOAT_MAT2x4:
890 return ATTRIBUTE_MAT2x4;
891 case GL_FLOAT_MAT3x2:
892 return ATTRIBUTE_MAT3x2;
893 case GL_FLOAT_MAT3x4:
894 return ATTRIBUTE_MAT3x4;
895 case GL_FLOAT_MAT4x2:
896 return ATTRIBUTE_MAT4x2;
897 case GL_FLOAT_MAT4x3:
898 return ATTRIBUTE_MAT4x3;
899 default:
900 UNREACHABLE();
901 return ATTRIBUTE_FLOAT;
902 }
903}
904
Jamie Madilld3dfda22015-07-06 08:28:49 -0400905VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
906{
907 switch (type)
908 {
909 case GL_BYTE:
910 switch (components)
911 {
912 case 1:
913 if (pureInteger)
914 return VERTEX_FORMAT_SBYTE1_INT;
915 if (normalized)
916 return VERTEX_FORMAT_SBYTE1_NORM;
917 return VERTEX_FORMAT_SBYTE1;
918 case 2:
919 if (pureInteger)
920 return VERTEX_FORMAT_SBYTE2_INT;
921 if (normalized)
922 return VERTEX_FORMAT_SBYTE2_NORM;
923 return VERTEX_FORMAT_SBYTE2;
924 case 3:
925 if (pureInteger)
926 return VERTEX_FORMAT_SBYTE3_INT;
927 if (normalized)
928 return VERTEX_FORMAT_SBYTE3_NORM;
929 return VERTEX_FORMAT_SBYTE3;
930 case 4:
931 if (pureInteger)
932 return VERTEX_FORMAT_SBYTE4_INT;
933 if (normalized)
934 return VERTEX_FORMAT_SBYTE4_NORM;
935 return VERTEX_FORMAT_SBYTE4;
936 default:
937 UNREACHABLE();
938 break;
939 }
940 case GL_UNSIGNED_BYTE:
941 switch (components)
942 {
943 case 1:
944 if (pureInteger)
945 return VERTEX_FORMAT_UBYTE1_INT;
946 if (normalized)
947 return VERTEX_FORMAT_UBYTE1_NORM;
948 return VERTEX_FORMAT_UBYTE1;
949 case 2:
950 if (pureInteger)
951 return VERTEX_FORMAT_UBYTE2_INT;
952 if (normalized)
953 return VERTEX_FORMAT_UBYTE2_NORM;
954 return VERTEX_FORMAT_UBYTE2;
955 case 3:
956 if (pureInteger)
957 return VERTEX_FORMAT_UBYTE3_INT;
958 if (normalized)
959 return VERTEX_FORMAT_UBYTE3_NORM;
960 return VERTEX_FORMAT_UBYTE3;
961 case 4:
962 if (pureInteger)
963 return VERTEX_FORMAT_UBYTE4_INT;
964 if (normalized)
965 return VERTEX_FORMAT_UBYTE4_NORM;
966 return VERTEX_FORMAT_UBYTE4;
967 default:
968 UNREACHABLE();
969 break;
970 }
971 case GL_SHORT:
972 switch (components)
973 {
974 case 1:
975 if (pureInteger)
976 return VERTEX_FORMAT_SSHORT1_INT;
977 if (normalized)
978 return VERTEX_FORMAT_SSHORT1_NORM;
979 return VERTEX_FORMAT_SSHORT1;
980 case 2:
981 if (pureInteger)
982 return VERTEX_FORMAT_SSHORT2_INT;
983 if (normalized)
984 return VERTEX_FORMAT_SSHORT2_NORM;
985 return VERTEX_FORMAT_SSHORT2;
986 case 3:
987 if (pureInteger)
988 return VERTEX_FORMAT_SSHORT3_INT;
989 if (normalized)
990 return VERTEX_FORMAT_SSHORT3_NORM;
991 return VERTEX_FORMAT_SSHORT3;
992 case 4:
993 if (pureInteger)
994 return VERTEX_FORMAT_SSHORT4_INT;
995 if (normalized)
996 return VERTEX_FORMAT_SSHORT4_NORM;
997 return VERTEX_FORMAT_SSHORT4;
998 default:
999 UNREACHABLE();
1000 break;
1001 }
1002 case GL_UNSIGNED_SHORT:
1003 switch (components)
1004 {
1005 case 1:
1006 if (pureInteger)
1007 return VERTEX_FORMAT_USHORT1_INT;
1008 if (normalized)
1009 return VERTEX_FORMAT_USHORT1_NORM;
1010 return VERTEX_FORMAT_USHORT1;
1011 case 2:
1012 if (pureInteger)
1013 return VERTEX_FORMAT_USHORT2_INT;
1014 if (normalized)
1015 return VERTEX_FORMAT_USHORT2_NORM;
1016 return VERTEX_FORMAT_USHORT2;
1017 case 3:
1018 if (pureInteger)
1019 return VERTEX_FORMAT_USHORT3_INT;
1020 if (normalized)
1021 return VERTEX_FORMAT_USHORT3_NORM;
1022 return VERTEX_FORMAT_USHORT3;
1023 case 4:
1024 if (pureInteger)
1025 return VERTEX_FORMAT_USHORT4_INT;
1026 if (normalized)
1027 return VERTEX_FORMAT_USHORT4_NORM;
1028 return VERTEX_FORMAT_USHORT4;
1029 default:
1030 UNREACHABLE();
1031 break;
1032 }
1033 case GL_INT:
1034 switch (components)
1035 {
1036 case 1:
1037 if (pureInteger)
1038 return VERTEX_FORMAT_SINT1_INT;
1039 if (normalized)
1040 return VERTEX_FORMAT_SINT1_NORM;
1041 return VERTEX_FORMAT_SINT1;
1042 case 2:
1043 if (pureInteger)
1044 return VERTEX_FORMAT_SINT2_INT;
1045 if (normalized)
1046 return VERTEX_FORMAT_SINT2_NORM;
1047 return VERTEX_FORMAT_SINT2;
1048 case 3:
1049 if (pureInteger)
1050 return VERTEX_FORMAT_SINT3_INT;
1051 if (normalized)
1052 return VERTEX_FORMAT_SINT3_NORM;
1053 return VERTEX_FORMAT_SINT3;
1054 case 4:
1055 if (pureInteger)
1056 return VERTEX_FORMAT_SINT4_INT;
1057 if (normalized)
1058 return VERTEX_FORMAT_SINT4_NORM;
1059 return VERTEX_FORMAT_SINT4;
1060 default:
1061 UNREACHABLE();
1062 break;
1063 }
1064 case GL_UNSIGNED_INT:
1065 switch (components)
1066 {
1067 case 1:
1068 if (pureInteger)
1069 return VERTEX_FORMAT_UINT1_INT;
1070 if (normalized)
1071 return VERTEX_FORMAT_UINT1_NORM;
1072 return VERTEX_FORMAT_UINT1;
1073 case 2:
1074 if (pureInteger)
1075 return VERTEX_FORMAT_UINT2_INT;
1076 if (normalized)
1077 return VERTEX_FORMAT_UINT2_NORM;
1078 return VERTEX_FORMAT_UINT2;
1079 case 3:
1080 if (pureInteger)
1081 return VERTEX_FORMAT_UINT3_INT;
1082 if (normalized)
1083 return VERTEX_FORMAT_UINT3_NORM;
1084 return VERTEX_FORMAT_UINT3;
1085 case 4:
1086 if (pureInteger)
1087 return VERTEX_FORMAT_UINT4_INT;
1088 if (normalized)
1089 return VERTEX_FORMAT_UINT4_NORM;
1090 return VERTEX_FORMAT_UINT4;
1091 default:
1092 UNREACHABLE();
1093 break;
1094 }
1095 case GL_FLOAT:
1096 switch (components)
1097 {
1098 case 1:
1099 return VERTEX_FORMAT_FLOAT1;
1100 case 2:
1101 return VERTEX_FORMAT_FLOAT2;
1102 case 3:
1103 return VERTEX_FORMAT_FLOAT3;
1104 case 4:
1105 return VERTEX_FORMAT_FLOAT4;
1106 default:
1107 UNREACHABLE();
1108 break;
1109 }
1110 case GL_HALF_FLOAT:
1111 switch (components)
1112 {
1113 case 1:
1114 return VERTEX_FORMAT_HALF1;
1115 case 2:
1116 return VERTEX_FORMAT_HALF2;
1117 case 3:
1118 return VERTEX_FORMAT_HALF3;
1119 case 4:
1120 return VERTEX_FORMAT_HALF4;
1121 default:
1122 UNREACHABLE();
1123 break;
1124 }
1125 case GL_FIXED:
1126 switch (components)
1127 {
1128 case 1:
1129 return VERTEX_FORMAT_FIXED1;
1130 case 2:
1131 return VERTEX_FORMAT_FIXED2;
1132 case 3:
1133 return VERTEX_FORMAT_FIXED3;
1134 case 4:
1135 return VERTEX_FORMAT_FIXED4;
1136 default:
1137 UNREACHABLE();
1138 break;
1139 }
1140 case GL_INT_2_10_10_10_REV:
1141 if (pureInteger)
1142 return VERTEX_FORMAT_SINT210_INT;
1143 if (normalized)
1144 return VERTEX_FORMAT_SINT210_NORM;
1145 return VERTEX_FORMAT_SINT210;
1146 case GL_UNSIGNED_INT_2_10_10_10_REV:
1147 if (pureInteger)
1148 return VERTEX_FORMAT_UINT210_INT;
1149 if (normalized)
1150 return VERTEX_FORMAT_UINT210_NORM;
1151 return VERTEX_FORMAT_UINT210;
1152 default:
1153 UNREACHABLE();
1154 break;
1155 }
1156 return VERTEX_FORMAT_UBYTE1;
1157}
1158
1159VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1160{
1161 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1162}
1163
1164VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1165{
1166 if (!attrib.enabled)
1167 {
1168 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1169 }
1170 return GetVertexFormatType(attrib);
1171}
1172
1173const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1174{
1175 switch (vertexFormatType)
1176 {
1177 case VERTEX_FORMAT_SBYTE1:
1178 {
1179 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1180 return format;
1181 }
1182 case VERTEX_FORMAT_SBYTE1_NORM:
1183 {
1184 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1185 return format;
1186 }
1187 case VERTEX_FORMAT_SBYTE2:
1188 {
1189 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1190 return format;
1191 }
1192 case VERTEX_FORMAT_SBYTE2_NORM:
1193 {
1194 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1195 return format;
1196 }
1197 case VERTEX_FORMAT_SBYTE3:
1198 {
1199 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1200 return format;
1201 }
1202 case VERTEX_FORMAT_SBYTE3_NORM:
1203 {
1204 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1205 return format;
1206 }
1207 case VERTEX_FORMAT_SBYTE4:
1208 {
1209 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1210 return format;
1211 }
1212 case VERTEX_FORMAT_SBYTE4_NORM:
1213 {
1214 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1215 return format;
1216 }
1217 case VERTEX_FORMAT_UBYTE1:
1218 {
1219 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1220 return format;
1221 }
1222 case VERTEX_FORMAT_UBYTE1_NORM:
1223 {
1224 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1225 return format;
1226 }
1227 case VERTEX_FORMAT_UBYTE2:
1228 {
1229 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1230 return format;
1231 }
1232 case VERTEX_FORMAT_UBYTE2_NORM:
1233 {
1234 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1235 return format;
1236 }
1237 case VERTEX_FORMAT_UBYTE3:
1238 {
1239 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1240 return format;
1241 }
1242 case VERTEX_FORMAT_UBYTE3_NORM:
1243 {
1244 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1245 return format;
1246 }
1247 case VERTEX_FORMAT_UBYTE4:
1248 {
1249 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1250 return format;
1251 }
1252 case VERTEX_FORMAT_UBYTE4_NORM:
1253 {
1254 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1255 return format;
1256 }
1257 case VERTEX_FORMAT_SSHORT1:
1258 {
1259 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1260 return format;
1261 }
1262 case VERTEX_FORMAT_SSHORT1_NORM:
1263 {
1264 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1265 return format;
1266 }
1267 case VERTEX_FORMAT_SSHORT2:
1268 {
1269 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1270 return format;
1271 }
1272 case VERTEX_FORMAT_SSHORT2_NORM:
1273 {
1274 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1275 return format;
1276 }
1277 case VERTEX_FORMAT_SSHORT3:
1278 {
1279 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1280 return format;
1281 }
1282 case VERTEX_FORMAT_SSHORT3_NORM:
1283 {
1284 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1285 return format;
1286 }
1287 case VERTEX_FORMAT_SSHORT4:
1288 {
1289 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1290 return format;
1291 }
1292 case VERTEX_FORMAT_SSHORT4_NORM:
1293 {
1294 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1295 return format;
1296 }
1297 case VERTEX_FORMAT_USHORT1:
1298 {
1299 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1300 return format;
1301 }
1302 case VERTEX_FORMAT_USHORT1_NORM:
1303 {
1304 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1305 return format;
1306 }
1307 case VERTEX_FORMAT_USHORT2:
1308 {
1309 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1310 return format;
1311 }
1312 case VERTEX_FORMAT_USHORT2_NORM:
1313 {
1314 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1315 return format;
1316 }
1317 case VERTEX_FORMAT_USHORT3:
1318 {
1319 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1320 return format;
1321 }
1322 case VERTEX_FORMAT_USHORT3_NORM:
1323 {
1324 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1325 return format;
1326 }
1327 case VERTEX_FORMAT_USHORT4:
1328 {
1329 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1330 return format;
1331 }
1332 case VERTEX_FORMAT_USHORT4_NORM:
1333 {
1334 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1335 return format;
1336 }
1337 case VERTEX_FORMAT_SINT1:
1338 {
1339 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1340 return format;
1341 }
1342 case VERTEX_FORMAT_SINT1_NORM:
1343 {
1344 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1345 return format;
1346 }
1347 case VERTEX_FORMAT_SINT2:
1348 {
1349 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1350 return format;
1351 }
1352 case VERTEX_FORMAT_SINT2_NORM:
1353 {
1354 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1355 return format;
1356 }
1357 case VERTEX_FORMAT_SINT3:
1358 {
1359 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1360 return format;
1361 }
1362 case VERTEX_FORMAT_SINT3_NORM:
1363 {
1364 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1365 return format;
1366 }
1367 case VERTEX_FORMAT_SINT4:
1368 {
1369 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1370 return format;
1371 }
1372 case VERTEX_FORMAT_SINT4_NORM:
1373 {
1374 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1375 return format;
1376 }
1377 case VERTEX_FORMAT_UINT1:
1378 {
1379 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1380 return format;
1381 }
1382 case VERTEX_FORMAT_UINT1_NORM:
1383 {
1384 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1385 return format;
1386 }
1387 case VERTEX_FORMAT_UINT2:
1388 {
1389 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1390 return format;
1391 }
1392 case VERTEX_FORMAT_UINT2_NORM:
1393 {
1394 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1395 return format;
1396 }
1397 case VERTEX_FORMAT_UINT3:
1398 {
1399 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1400 return format;
1401 }
1402 case VERTEX_FORMAT_UINT3_NORM:
1403 {
1404 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1405 return format;
1406 }
1407 case VERTEX_FORMAT_UINT4:
1408 {
1409 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1410 return format;
1411 }
1412 case VERTEX_FORMAT_UINT4_NORM:
1413 {
1414 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1415 return format;
1416 }
1417 case VERTEX_FORMAT_SBYTE1_INT:
1418 {
1419 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1420 return format;
1421 }
1422 case VERTEX_FORMAT_SBYTE2_INT:
1423 {
1424 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1425 return format;
1426 }
1427 case VERTEX_FORMAT_SBYTE3_INT:
1428 {
1429 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1430 return format;
1431 }
1432 case VERTEX_FORMAT_SBYTE4_INT:
1433 {
1434 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1435 return format;
1436 }
1437 case VERTEX_FORMAT_UBYTE1_INT:
1438 {
1439 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1440 return format;
1441 }
1442 case VERTEX_FORMAT_UBYTE2_INT:
1443 {
1444 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1445 return format;
1446 }
1447 case VERTEX_FORMAT_UBYTE3_INT:
1448 {
1449 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1450 return format;
1451 }
1452 case VERTEX_FORMAT_UBYTE4_INT:
1453 {
1454 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1455 return format;
1456 }
1457 case VERTEX_FORMAT_SSHORT1_INT:
1458 {
1459 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1460 return format;
1461 }
1462 case VERTEX_FORMAT_SSHORT2_INT:
1463 {
1464 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1465 return format;
1466 }
1467 case VERTEX_FORMAT_SSHORT3_INT:
1468 {
1469 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1470 return format;
1471 }
1472 case VERTEX_FORMAT_SSHORT4_INT:
1473 {
1474 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1475 return format;
1476 }
1477 case VERTEX_FORMAT_USHORT1_INT:
1478 {
1479 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1480 return format;
1481 }
1482 case VERTEX_FORMAT_USHORT2_INT:
1483 {
1484 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1485 return format;
1486 }
1487 case VERTEX_FORMAT_USHORT3_INT:
1488 {
1489 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1490 return format;
1491 }
1492 case VERTEX_FORMAT_USHORT4_INT:
1493 {
1494 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1495 return format;
1496 }
1497 case VERTEX_FORMAT_SINT1_INT:
1498 {
1499 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1500 return format;
1501 }
1502 case VERTEX_FORMAT_SINT2_INT:
1503 {
1504 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1505 return format;
1506 }
1507 case VERTEX_FORMAT_SINT3_INT:
1508 {
1509 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1510 return format;
1511 }
1512 case VERTEX_FORMAT_SINT4_INT:
1513 {
1514 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1515 return format;
1516 }
1517 case VERTEX_FORMAT_UINT1_INT:
1518 {
1519 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1520 return format;
1521 }
1522 case VERTEX_FORMAT_UINT2_INT:
1523 {
1524 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1525 return format;
1526 }
1527 case VERTEX_FORMAT_UINT3_INT:
1528 {
1529 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1530 return format;
1531 }
1532 case VERTEX_FORMAT_UINT4_INT:
1533 {
1534 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1535 return format;
1536 }
1537 case VERTEX_FORMAT_FIXED1:
1538 {
1539 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1540 return format;
1541 }
1542 case VERTEX_FORMAT_FIXED2:
1543 {
1544 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1545 return format;
1546 }
1547 case VERTEX_FORMAT_FIXED3:
1548 {
1549 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1550 return format;
1551 }
1552 case VERTEX_FORMAT_FIXED4:
1553 {
1554 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1555 return format;
1556 }
1557 case VERTEX_FORMAT_HALF1:
1558 {
1559 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1560 return format;
1561 }
1562 case VERTEX_FORMAT_HALF2:
1563 {
1564 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1565 return format;
1566 }
1567 case VERTEX_FORMAT_HALF3:
1568 {
1569 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1570 return format;
1571 }
1572 case VERTEX_FORMAT_HALF4:
1573 {
1574 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1575 return format;
1576 }
1577 case VERTEX_FORMAT_FLOAT1:
1578 {
1579 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1580 return format;
1581 }
1582 case VERTEX_FORMAT_FLOAT2:
1583 {
1584 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1585 return format;
1586 }
1587 case VERTEX_FORMAT_FLOAT3:
1588 {
1589 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1590 return format;
1591 }
1592 case VERTEX_FORMAT_FLOAT4:
1593 {
1594 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1595 return format;
1596 }
1597 case VERTEX_FORMAT_SINT210:
1598 {
1599 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1600 return format;
1601 }
1602 case VERTEX_FORMAT_UINT210:
1603 {
1604 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1605 return format;
1606 }
1607 case VERTEX_FORMAT_SINT210_NORM:
1608 {
1609 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1610 return format;
1611 }
1612 case VERTEX_FORMAT_UINT210_NORM:
1613 {
1614 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1615 return format;
1616 }
1617 case VERTEX_FORMAT_SINT210_INT:
1618 {
1619 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1620 return format;
1621 }
1622 case VERTEX_FORMAT_UINT210_INT:
1623 {
1624 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1625 return format;
1626 }
1627 default:
1628 {
1629 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1630 return format;
1631 }
1632 }
1633}
1634
1635VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1636 : type(typeIn),
1637 normalized(normalizedIn),
1638 components(componentsIn),
1639 pureInteger(pureIntegerIn)
1640{
1641 // float -> !normalized
1642 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1643}
1644
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001645}