blob: a188d6be163812085dbbb546f45e6c4cf2197960 [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"
13#include "libANGLE/renderer/Renderer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
15namespace gl
16{
17
18// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
19// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
20// format and type combinations.
21
22typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Lang051dbc72015-01-05 15:48:58 -050023typedef std::pair<FormatTypePair, GLenum> FormatPair;
24typedef std::map<FormatTypePair, GLenum> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000025
Jamie Madill89a0bf52013-09-18 14:36:24 -040026// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050027static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000028{
Geoff Lang051dbc72015-01-05 15:48:58 -050029 map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000030}
31
Geoff Lange4a492b2014-06-19 14:14:41 -040032FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000033{
34 FormatMap map;
35
Geoff Lang051dbc72015-01-05 15:48:58 -050036 // | Format | Type | Internal format |
37 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
38 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
39 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
40 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
41 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
42 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
43 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
44 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045
Geoff Lang051dbc72015-01-05 15:48:58 -050046 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
47 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
48 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
49 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
50 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
51 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
52 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000053
Geoff Lang051dbc72015-01-05 15:48:58 -050054 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
55 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
56 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
57 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
58 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
59 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
60 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
61 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000062
Geoff Lang051dbc72015-01-05 15:48:58 -050063 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
64 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
65 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
66 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
67 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
68 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000069
Geoff Lang051dbc72015-01-05 15:48:58 -050070 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
71 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
72 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
73 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
74 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075
Geoff Lang051dbc72015-01-05 15:48:58 -050076 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
77 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
78 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
79 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
80 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
81 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040082
Geoff Lang051dbc72015-01-05 15:48:58 -050083 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
84 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
85 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
86 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
87 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -040088
Geoff Lang051dbc72015-01-05 15:48:58 -050089 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
90 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
91 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
92 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
93 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
94 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040095
Geoff Lang051dbc72015-01-05 15:48:58 -050096 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
97 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
98 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
99 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
100 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
101 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
102 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
103 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
104 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
105 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
106 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
107 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400108
Geoff Lang051dbc72015-01-05 15:48:58 -0500109 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
110 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
111 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 -0400112
Geoff Lang051dbc72015-01-05 15:48:58 -0500113 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
114 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400115
Geoff Lang051dbc72015-01-05 15:48:58 -0500116 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
117 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
118 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
119 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400120
Geoff Lang051dbc72015-01-05 15:48:58 -0500121 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
122 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
123 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400124
Geoff Lang051dbc72015-01-05 15:48:58 -0500125 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400126
Geoff Lang051dbc72015-01-05 15:48:58 -0500127 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
128 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000129
130 return map;
131}
132
Geoff Lang5d601382014-07-22 15:14:06 -0400133Type::Type()
134 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200135 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400136 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400137{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000138}
139
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200140static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000141{
Geoff Lang5d601382014-07-22 15:14:06 -0400142 Type info;
143 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200144 GLuint i = 0;
145 while ((1u << i) < bytes)
146 {
147 ++i;
148 }
149 info.bytesShift = i;
150 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400151 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200152 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400153}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000154
Geoff Lang5d601382014-07-22 15:14:06 -0400155bool operator<(const Type& a, const Type& b)
156{
157 return memcmp(&a, &b, sizeof(Type)) < 0;
158}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000159
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000160// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400161static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000162{
Geoff Lang493daf52014-07-03 13:38:44 -0400163 return true;
164}
165
Geoff Lang493daf52014-07-03 13:38:44 -0400166static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000167{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000168 return false;
169}
170
Geoff Lange4a492b2014-06-19 14:14:41 -0400171template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400172static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400173{
174 return clientVersion >= minCoreGLVersion;
175}
176
Geoff Langcec35902014-04-16 10:52:36 -0400177// Pointer to a boolean memeber of the Extensions struct
178typedef bool(Extensions::*ExtensionBool);
179
180// Check support for a single extension
181template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400182static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400183{
Geoff Lange4a492b2014-06-19 14:14:41 -0400184 return extensions.*bool1;
185}
186
187// Check for a minimum client version or a single extension
188template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400189static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400190{
191 return clientVersion >= minCoreGLVersion || extensions.*bool1;
192}
193
194// Check for a minimum client version or two extensions
195template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400196static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400197{
Geoff Langabce7622014-09-19 16:13:00 -0400198 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
199}
200
201// Check for a minimum client version or at least one of two extensions
202template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
203static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
204{
205 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400206}
207
208// Check support for two extensions
209template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400210static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400211{
Geoff Langabce7622014-09-19 16:13:00 -0400212 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400213}
214
Geoff Lang5d601382014-07-22 15:14:06 -0400215InternalFormat::InternalFormat()
216 : redBits(0),
217 greenBits(0),
218 blueBits(0),
219 luminanceBits(0),
220 alphaBits(0),
221 sharedBits(0),
222 depthBits(0),
223 stencilBits(0),
224 pixelBytes(0),
225 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400226 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400227 compressedBlockWidth(0),
228 compressedBlockHeight(0),
229 format(GL_NONE),
230 type(GL_NONE),
231 componentType(GL_NONE),
232 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400233 textureSupport(NeverSupported),
234 renderSupport(NeverSupported),
235 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000236{
Geoff Lang5d601382014-07-22 15:14:06 -0400237}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000238
Geoff Lang5d601382014-07-22 15:14:06 -0400239static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
240 InternalFormat::SupportCheckFunction renderSupport,
241 InternalFormat::SupportCheckFunction filterSupport)
242{
243 InternalFormat formatInfo;
244 formatInfo.format = format;
245 formatInfo.textureSupport = textureSupport;
246 formatInfo.renderSupport = renderSupport;
247 formatInfo.filterSupport = filterSupport;
248 return formatInfo;
249}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000250
Geoff Lang5d601382014-07-22 15:14:06 -0400251static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
252 GLenum format, GLenum type, GLenum componentType, bool srgb,
253 InternalFormat::SupportCheckFunction textureSupport,
254 InternalFormat::SupportCheckFunction renderSupport,
255 InternalFormat::SupportCheckFunction filterSupport)
256{
257 InternalFormat formatInfo;
258 formatInfo.redBits = red;
259 formatInfo.greenBits = green;
260 formatInfo.blueBits = blue;
261 formatInfo.alphaBits = alpha;
262 formatInfo.sharedBits = shared;
263 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
264 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
265 formatInfo.format = format;
266 formatInfo.type = type;
267 formatInfo.componentType = componentType;
268 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
269 formatInfo.textureSupport = textureSupport;
270 formatInfo.renderSupport = renderSupport;
271 formatInfo.filterSupport = filterSupport;
272 return formatInfo;
273}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000274
Geoff Lang5d601382014-07-22 15:14:06 -0400275static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
276 InternalFormat::SupportCheckFunction textureSupport,
277 InternalFormat::SupportCheckFunction renderSupport,
278 InternalFormat::SupportCheckFunction filterSupport)
279{
280 InternalFormat formatInfo;
281 formatInfo.luminanceBits = luminance;
282 formatInfo.alphaBits = alpha;
283 formatInfo.pixelBytes = (luminance + alpha) / 8;
284 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
285 formatInfo.format = format;
286 formatInfo.type = type;
287 formatInfo.componentType = componentType;
288 formatInfo.colorEncoding = GL_LINEAR;
289 formatInfo.textureSupport = textureSupport;
290 formatInfo.renderSupport = renderSupport;
291 formatInfo.filterSupport = filterSupport;
292 return formatInfo;
293}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000294
Geoff Lang5d601382014-07-22 15:14:06 -0400295static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
296 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
297 InternalFormat::SupportCheckFunction renderSupport,
298 InternalFormat::SupportCheckFunction filterSupport)
299{
300 InternalFormat formatInfo;
301 formatInfo.depthBits = depthBits;
302 formatInfo.stencilBits = stencilBits;
303 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
304 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
305 formatInfo.format = format;
306 formatInfo.type = type;
307 formatInfo.componentType = componentType;
308 formatInfo.colorEncoding = GL_LINEAR;
309 formatInfo.textureSupport = textureSupport;
310 formatInfo.renderSupport = renderSupport;
311 formatInfo.filterSupport = filterSupport;
312 return formatInfo;
313}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000314
Geoff Lang5d601382014-07-22 15:14:06 -0400315static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
316 GLuint componentCount, GLenum format, GLenum type, bool srgb,
317 InternalFormat::SupportCheckFunction textureSupport,
318 InternalFormat::SupportCheckFunction renderSupport,
319 InternalFormat::SupportCheckFunction filterSupport)
320{
321 InternalFormat formatInfo;
322 formatInfo.compressedBlockWidth = compressedBlockWidth;
323 formatInfo.compressedBlockHeight = compressedBlockHeight;
324 formatInfo.pixelBytes = compressedBlockSize / 8;
325 formatInfo.componentCount = componentCount;
326 formatInfo.format = format;
327 formatInfo.type = type;
328 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
329 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
330 formatInfo.compressed = true;
331 formatInfo.textureSupport = textureSupport;
332 formatInfo.renderSupport = renderSupport;
333 formatInfo.filterSupport = filterSupport;
334 return formatInfo;
335}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000336
Geoff Lang5d601382014-07-22 15:14:06 -0400337typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
338typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000339
Geoff Lange4a492b2014-06-19 14:14:41 -0400340static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000341{
342 InternalFormatInfoMap map;
343
Geoff Lang9bbad182015-09-04 11:07:29 -0400344 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000345 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400346 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000347
Geoff Langabce7622014-09-19 16:13:00 -0400348 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
349 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)));
350 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
351 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)));
352 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
353 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)));
354 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
355 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)));
356 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)));
357 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)));
358 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)));
359 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
360 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 -0400361 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 -0400362 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)));
363 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)));
364 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)));
365 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)));
366 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
367 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)));
368 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
369 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)));
370 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
371 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)));
372 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
373 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)));
374 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
375 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)));
376 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
377 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)));
378 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
379 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)));
380 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
381 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)));
382 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
383 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)));
384 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
385 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)));
386 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
387 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)));
388 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
389 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 +0000390
Geoff Langabce7622014-09-19 16:13:00 -0400391 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)));
392 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)));
393 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 +0000394
395 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langabce7622014-09-19 16:13:00 -0400396 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
397 // | | | | | | | type | | | | |
398 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>)));
399 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>)));
400 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>)));
401 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>)));
402 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear> )));
403 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear> )));
404 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureFloat>, RequireESOrExt<3, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear> )));
405 map.insert(InternalFormatInfoPair(GL_RGBA32F, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureFloat>, RequireESOrExt<3, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000406
407 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400408 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
409 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>)));
410 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>)));
411 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>)));
412 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::depthTextures>, RequireExt<&Extensions::depthTextures>, AlwaysSupported )));
413 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 )));
414 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 -0800415 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000416
417 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400418 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400419 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
420 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
421 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
422 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
423 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
424 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
425 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
426 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
427 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 +0000428
429 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400430 // | Internal format | | Format | Supported | Renderable | Filterable |
431 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
432 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
433 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
434 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
435 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
436 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
437 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
438 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
439 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
440 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
441 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
442 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
443 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
444 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
445 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
446 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 +0000447
448 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400449 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
450 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
451 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)));
452 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
453 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)));
454 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
455 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
456 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)));
457 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)));
458 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)));
459 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 +0000460
461 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400462 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
463 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)));
464 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 +0000465
466 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400467 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 +0000468
469 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400470 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)));
471
472 // From GL_OES_compressed_ETC1_RGB8_texture
473 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 +0000474
Corentin Walleze0902642014-11-04 12:32:15 -0800475 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
476 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
477 // - All other stencil formats (all depth-stencil) are either float or normalized
478 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
479 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
480 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, DepthStencilFormat(0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported)));
Geoff Lang9bbad182015-09-04 11:07:29 -0400481 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800482
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000483 return map;
484}
485
Geoff Lange4a492b2014-06-19 14:14:41 -0400486static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000487{
Geoff Lange4a492b2014-06-19 14:14:41 -0400488 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
489 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000490}
491
Geoff Lange4a492b2014-06-19 14:14:41 -0400492static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400493{
494 FormatSet result;
495
Geoff Lange4a492b2014-06-19 14:14:41 -0400496 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400497 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
498 {
Geoff Lang5d601382014-07-22 15:14:06 -0400499 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400500 {
501 result.insert(i->first);
502 }
503 }
504
505 return result;
506}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000507
Geoff Lang5d601382014-07-22 15:14:06 -0400508const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000509{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200510 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000511 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200512 case GL_UNSIGNED_BYTE:
513 case GL_BYTE:
514 {
515 static const Type info = GenTypeInfo(1, false);
516 return info;
517 }
518 case GL_UNSIGNED_SHORT:
519 case GL_SHORT:
520 case GL_HALF_FLOAT:
521 case GL_HALF_FLOAT_OES:
522 {
523 static const Type info = GenTypeInfo(2, false);
524 return info;
525 }
526 case GL_UNSIGNED_INT:
527 case GL_INT:
528 case GL_FLOAT:
529 {
530 static const Type info = GenTypeInfo(4, false);
531 return info;
532 }
533 case GL_UNSIGNED_SHORT_5_6_5:
534 case GL_UNSIGNED_SHORT_4_4_4_4:
535 case GL_UNSIGNED_SHORT_5_5_5_1:
536 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
537 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
538 {
539 static const Type info = GenTypeInfo(2, true);
540 return info;
541 }
542 case GL_UNSIGNED_INT_2_10_10_10_REV:
543 case GL_UNSIGNED_INT_24_8:
544 case GL_UNSIGNED_INT_10F_11F_11F_REV:
545 case GL_UNSIGNED_INT_5_9_9_9_REV:
546 {
547 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
548 static const Type info = GenTypeInfo(4, true);
549 return info;
550 }
551 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
552 {
553 static const Type info = GenTypeInfo(8, true);
554 return info;
555 }
556 default:
557 {
558 static const Type defaultInfo;
559 return defaultInfo;
560 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000561 }
562}
563
Geoff Lang5d601382014-07-22 15:14:06 -0400564const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000565{
Geoff Lang5d601382014-07-22 15:14:06 -0400566 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
567 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
568 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000569 {
Geoff Lang5d601382014-07-22 15:14:06 -0400570 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000571 }
572 else
573 {
Geoff Lang5d601382014-07-22 15:14:06 -0400574 static const InternalFormat defaultInternalFormat;
575 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000576 }
577}
578
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800579GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000580{
581 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800582 GLuint rowBytes;
583 if (rowLength > 0)
584 {
585 ASSERT(!compressed);
586 rowBytes = pixelBytes * rowLength;
587 }
588 else
589 {
590 rowBytes = computeBlockSize(formatType, width, 1);
591 }
592 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000593}
594
Minmin Gongadff67b2015-10-14 10:34:45 -0400595GLuint InternalFormat::computeDepthPitch(GLenum formatType,
596 GLsizei width,
597 GLsizei height,
598 GLint alignment,
599 GLint rowLength,
600 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000601{
Minmin Gongadff67b2015-10-14 10:34:45 -0400602 GLuint rows;
603 if (imageHeight > 0)
604 {
605 rows = imageHeight;
606 }
607 else
608 {
609 rows = height;
610 }
611 return computeRowPitch(formatType, width, alignment, rowLength) * rows;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000612}
613
Austin Kinross3ae64652015-01-26 15:51:39 -0800614GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000615{
Geoff Lang5d601382014-07-22 15:14:06 -0400616 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000617 {
Geoff Lang5d601382014-07-22 15:14:06 -0400618 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
619 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
620 return (pixelBytes * numBlocksWide * numBlocksHight);
621 }
622 else
623 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800624 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400625 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000626 {
Geoff Lang5d601382014-07-22 15:14:06 -0400627 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628 }
629 else
630 {
Geoff Lang5d601382014-07-22 15:14:06 -0400631 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000632 }
633 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000634}
635
Minmin Gongadff67b2015-10-14 10:34:45 -0400636GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
637 GLint depthPitch,
638 GLint skipImages,
639 GLint skipRows,
640 GLint skipPixels) const
641{
642 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
643}
644
Geoff Lang5d601382014-07-22 15:14:06 -0400645GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000646{
Geoff Lang5d601382014-07-22 15:14:06 -0400647 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500648 if (formatInfo.pixelBytes > 0)
649 {
650 return internalFormat;
651 }
652 else
653 {
654 static const FormatMap formatMap = BuildFormatMap();
655 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
656 if (iter != formatMap.end())
657 {
658 return iter->second;
659 }
660 else
661 {
662 return GL_NONE;
663 }
664 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000665}
666
Geoff Lange4a492b2014-06-19 14:14:41 -0400667const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400668{
Geoff Lange4a492b2014-06-19 14:14:41 -0400669 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400670 return formatSet;
671}
672
Jamie Madill09e2d932015-07-14 16:40:31 -0400673AttributeType GetAttributeType(GLenum enumValue)
674{
675 switch (enumValue)
676 {
677 case GL_FLOAT:
678 return ATTRIBUTE_FLOAT;
679 case GL_FLOAT_VEC2:
680 return ATTRIBUTE_VEC2;
681 case GL_FLOAT_VEC3:
682 return ATTRIBUTE_VEC3;
683 case GL_FLOAT_VEC4:
684 return ATTRIBUTE_VEC4;
685 case GL_INT:
686 return ATTRIBUTE_INT;
687 case GL_INT_VEC2:
688 return ATTRIBUTE_IVEC2;
689 case GL_INT_VEC3:
690 return ATTRIBUTE_IVEC3;
691 case GL_INT_VEC4:
692 return ATTRIBUTE_IVEC4;
693 case GL_UNSIGNED_INT:
694 return ATTRIBUTE_UINT;
695 case GL_UNSIGNED_INT_VEC2:
696 return ATTRIBUTE_UVEC2;
697 case GL_UNSIGNED_INT_VEC3:
698 return ATTRIBUTE_UVEC3;
699 case GL_UNSIGNED_INT_VEC4:
700 return ATTRIBUTE_UVEC4;
701 case GL_FLOAT_MAT2:
702 return ATTRIBUTE_MAT2;
703 case GL_FLOAT_MAT3:
704 return ATTRIBUTE_MAT3;
705 case GL_FLOAT_MAT4:
706 return ATTRIBUTE_MAT4;
707 case GL_FLOAT_MAT2x3:
708 return ATTRIBUTE_MAT2x3;
709 case GL_FLOAT_MAT2x4:
710 return ATTRIBUTE_MAT2x4;
711 case GL_FLOAT_MAT3x2:
712 return ATTRIBUTE_MAT3x2;
713 case GL_FLOAT_MAT3x4:
714 return ATTRIBUTE_MAT3x4;
715 case GL_FLOAT_MAT4x2:
716 return ATTRIBUTE_MAT4x2;
717 case GL_FLOAT_MAT4x3:
718 return ATTRIBUTE_MAT4x3;
719 default:
720 UNREACHABLE();
721 return ATTRIBUTE_FLOAT;
722 }
723}
724
Jamie Madilld3dfda22015-07-06 08:28:49 -0400725VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
726{
727 switch (type)
728 {
729 case GL_BYTE:
730 switch (components)
731 {
732 case 1:
733 if (pureInteger)
734 return VERTEX_FORMAT_SBYTE1_INT;
735 if (normalized)
736 return VERTEX_FORMAT_SBYTE1_NORM;
737 return VERTEX_FORMAT_SBYTE1;
738 case 2:
739 if (pureInteger)
740 return VERTEX_FORMAT_SBYTE2_INT;
741 if (normalized)
742 return VERTEX_FORMAT_SBYTE2_NORM;
743 return VERTEX_FORMAT_SBYTE2;
744 case 3:
745 if (pureInteger)
746 return VERTEX_FORMAT_SBYTE3_INT;
747 if (normalized)
748 return VERTEX_FORMAT_SBYTE3_NORM;
749 return VERTEX_FORMAT_SBYTE3;
750 case 4:
751 if (pureInteger)
752 return VERTEX_FORMAT_SBYTE4_INT;
753 if (normalized)
754 return VERTEX_FORMAT_SBYTE4_NORM;
755 return VERTEX_FORMAT_SBYTE4;
756 default:
757 UNREACHABLE();
758 break;
759 }
760 case GL_UNSIGNED_BYTE:
761 switch (components)
762 {
763 case 1:
764 if (pureInteger)
765 return VERTEX_FORMAT_UBYTE1_INT;
766 if (normalized)
767 return VERTEX_FORMAT_UBYTE1_NORM;
768 return VERTEX_FORMAT_UBYTE1;
769 case 2:
770 if (pureInteger)
771 return VERTEX_FORMAT_UBYTE2_INT;
772 if (normalized)
773 return VERTEX_FORMAT_UBYTE2_NORM;
774 return VERTEX_FORMAT_UBYTE2;
775 case 3:
776 if (pureInteger)
777 return VERTEX_FORMAT_UBYTE3_INT;
778 if (normalized)
779 return VERTEX_FORMAT_UBYTE3_NORM;
780 return VERTEX_FORMAT_UBYTE3;
781 case 4:
782 if (pureInteger)
783 return VERTEX_FORMAT_UBYTE4_INT;
784 if (normalized)
785 return VERTEX_FORMAT_UBYTE4_NORM;
786 return VERTEX_FORMAT_UBYTE4;
787 default:
788 UNREACHABLE();
789 break;
790 }
791 case GL_SHORT:
792 switch (components)
793 {
794 case 1:
795 if (pureInteger)
796 return VERTEX_FORMAT_SSHORT1_INT;
797 if (normalized)
798 return VERTEX_FORMAT_SSHORT1_NORM;
799 return VERTEX_FORMAT_SSHORT1;
800 case 2:
801 if (pureInteger)
802 return VERTEX_FORMAT_SSHORT2_INT;
803 if (normalized)
804 return VERTEX_FORMAT_SSHORT2_NORM;
805 return VERTEX_FORMAT_SSHORT2;
806 case 3:
807 if (pureInteger)
808 return VERTEX_FORMAT_SSHORT3_INT;
809 if (normalized)
810 return VERTEX_FORMAT_SSHORT3_NORM;
811 return VERTEX_FORMAT_SSHORT3;
812 case 4:
813 if (pureInteger)
814 return VERTEX_FORMAT_SSHORT4_INT;
815 if (normalized)
816 return VERTEX_FORMAT_SSHORT4_NORM;
817 return VERTEX_FORMAT_SSHORT4;
818 default:
819 UNREACHABLE();
820 break;
821 }
822 case GL_UNSIGNED_SHORT:
823 switch (components)
824 {
825 case 1:
826 if (pureInteger)
827 return VERTEX_FORMAT_USHORT1_INT;
828 if (normalized)
829 return VERTEX_FORMAT_USHORT1_NORM;
830 return VERTEX_FORMAT_USHORT1;
831 case 2:
832 if (pureInteger)
833 return VERTEX_FORMAT_USHORT2_INT;
834 if (normalized)
835 return VERTEX_FORMAT_USHORT2_NORM;
836 return VERTEX_FORMAT_USHORT2;
837 case 3:
838 if (pureInteger)
839 return VERTEX_FORMAT_USHORT3_INT;
840 if (normalized)
841 return VERTEX_FORMAT_USHORT3_NORM;
842 return VERTEX_FORMAT_USHORT3;
843 case 4:
844 if (pureInteger)
845 return VERTEX_FORMAT_USHORT4_INT;
846 if (normalized)
847 return VERTEX_FORMAT_USHORT4_NORM;
848 return VERTEX_FORMAT_USHORT4;
849 default:
850 UNREACHABLE();
851 break;
852 }
853 case GL_INT:
854 switch (components)
855 {
856 case 1:
857 if (pureInteger)
858 return VERTEX_FORMAT_SINT1_INT;
859 if (normalized)
860 return VERTEX_FORMAT_SINT1_NORM;
861 return VERTEX_FORMAT_SINT1;
862 case 2:
863 if (pureInteger)
864 return VERTEX_FORMAT_SINT2_INT;
865 if (normalized)
866 return VERTEX_FORMAT_SINT2_NORM;
867 return VERTEX_FORMAT_SINT2;
868 case 3:
869 if (pureInteger)
870 return VERTEX_FORMAT_SINT3_INT;
871 if (normalized)
872 return VERTEX_FORMAT_SINT3_NORM;
873 return VERTEX_FORMAT_SINT3;
874 case 4:
875 if (pureInteger)
876 return VERTEX_FORMAT_SINT4_INT;
877 if (normalized)
878 return VERTEX_FORMAT_SINT4_NORM;
879 return VERTEX_FORMAT_SINT4;
880 default:
881 UNREACHABLE();
882 break;
883 }
884 case GL_UNSIGNED_INT:
885 switch (components)
886 {
887 case 1:
888 if (pureInteger)
889 return VERTEX_FORMAT_UINT1_INT;
890 if (normalized)
891 return VERTEX_FORMAT_UINT1_NORM;
892 return VERTEX_FORMAT_UINT1;
893 case 2:
894 if (pureInteger)
895 return VERTEX_FORMAT_UINT2_INT;
896 if (normalized)
897 return VERTEX_FORMAT_UINT2_NORM;
898 return VERTEX_FORMAT_UINT2;
899 case 3:
900 if (pureInteger)
901 return VERTEX_FORMAT_UINT3_INT;
902 if (normalized)
903 return VERTEX_FORMAT_UINT3_NORM;
904 return VERTEX_FORMAT_UINT3;
905 case 4:
906 if (pureInteger)
907 return VERTEX_FORMAT_UINT4_INT;
908 if (normalized)
909 return VERTEX_FORMAT_UINT4_NORM;
910 return VERTEX_FORMAT_UINT4;
911 default:
912 UNREACHABLE();
913 break;
914 }
915 case GL_FLOAT:
916 switch (components)
917 {
918 case 1:
919 return VERTEX_FORMAT_FLOAT1;
920 case 2:
921 return VERTEX_FORMAT_FLOAT2;
922 case 3:
923 return VERTEX_FORMAT_FLOAT3;
924 case 4:
925 return VERTEX_FORMAT_FLOAT4;
926 default:
927 UNREACHABLE();
928 break;
929 }
930 case GL_HALF_FLOAT:
931 switch (components)
932 {
933 case 1:
934 return VERTEX_FORMAT_HALF1;
935 case 2:
936 return VERTEX_FORMAT_HALF2;
937 case 3:
938 return VERTEX_FORMAT_HALF3;
939 case 4:
940 return VERTEX_FORMAT_HALF4;
941 default:
942 UNREACHABLE();
943 break;
944 }
945 case GL_FIXED:
946 switch (components)
947 {
948 case 1:
949 return VERTEX_FORMAT_FIXED1;
950 case 2:
951 return VERTEX_FORMAT_FIXED2;
952 case 3:
953 return VERTEX_FORMAT_FIXED3;
954 case 4:
955 return VERTEX_FORMAT_FIXED4;
956 default:
957 UNREACHABLE();
958 break;
959 }
960 case GL_INT_2_10_10_10_REV:
961 if (pureInteger)
962 return VERTEX_FORMAT_SINT210_INT;
963 if (normalized)
964 return VERTEX_FORMAT_SINT210_NORM;
965 return VERTEX_FORMAT_SINT210;
966 case GL_UNSIGNED_INT_2_10_10_10_REV:
967 if (pureInteger)
968 return VERTEX_FORMAT_UINT210_INT;
969 if (normalized)
970 return VERTEX_FORMAT_UINT210_NORM;
971 return VERTEX_FORMAT_UINT210;
972 default:
973 UNREACHABLE();
974 break;
975 }
976 return VERTEX_FORMAT_UBYTE1;
977}
978
979VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
980{
981 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
982}
983
984VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
985{
986 if (!attrib.enabled)
987 {
988 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
989 }
990 return GetVertexFormatType(attrib);
991}
992
993const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
994{
995 switch (vertexFormatType)
996 {
997 case VERTEX_FORMAT_SBYTE1:
998 {
999 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1000 return format;
1001 }
1002 case VERTEX_FORMAT_SBYTE1_NORM:
1003 {
1004 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1005 return format;
1006 }
1007 case VERTEX_FORMAT_SBYTE2:
1008 {
1009 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1010 return format;
1011 }
1012 case VERTEX_FORMAT_SBYTE2_NORM:
1013 {
1014 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1015 return format;
1016 }
1017 case VERTEX_FORMAT_SBYTE3:
1018 {
1019 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1020 return format;
1021 }
1022 case VERTEX_FORMAT_SBYTE3_NORM:
1023 {
1024 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1025 return format;
1026 }
1027 case VERTEX_FORMAT_SBYTE4:
1028 {
1029 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1030 return format;
1031 }
1032 case VERTEX_FORMAT_SBYTE4_NORM:
1033 {
1034 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1035 return format;
1036 }
1037 case VERTEX_FORMAT_UBYTE1:
1038 {
1039 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1040 return format;
1041 }
1042 case VERTEX_FORMAT_UBYTE1_NORM:
1043 {
1044 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1045 return format;
1046 }
1047 case VERTEX_FORMAT_UBYTE2:
1048 {
1049 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1050 return format;
1051 }
1052 case VERTEX_FORMAT_UBYTE2_NORM:
1053 {
1054 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1055 return format;
1056 }
1057 case VERTEX_FORMAT_UBYTE3:
1058 {
1059 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1060 return format;
1061 }
1062 case VERTEX_FORMAT_UBYTE3_NORM:
1063 {
1064 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1065 return format;
1066 }
1067 case VERTEX_FORMAT_UBYTE4:
1068 {
1069 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1070 return format;
1071 }
1072 case VERTEX_FORMAT_UBYTE4_NORM:
1073 {
1074 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1075 return format;
1076 }
1077 case VERTEX_FORMAT_SSHORT1:
1078 {
1079 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1080 return format;
1081 }
1082 case VERTEX_FORMAT_SSHORT1_NORM:
1083 {
1084 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1085 return format;
1086 }
1087 case VERTEX_FORMAT_SSHORT2:
1088 {
1089 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1090 return format;
1091 }
1092 case VERTEX_FORMAT_SSHORT2_NORM:
1093 {
1094 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1095 return format;
1096 }
1097 case VERTEX_FORMAT_SSHORT3:
1098 {
1099 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1100 return format;
1101 }
1102 case VERTEX_FORMAT_SSHORT3_NORM:
1103 {
1104 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1105 return format;
1106 }
1107 case VERTEX_FORMAT_SSHORT4:
1108 {
1109 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1110 return format;
1111 }
1112 case VERTEX_FORMAT_SSHORT4_NORM:
1113 {
1114 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1115 return format;
1116 }
1117 case VERTEX_FORMAT_USHORT1:
1118 {
1119 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1120 return format;
1121 }
1122 case VERTEX_FORMAT_USHORT1_NORM:
1123 {
1124 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1125 return format;
1126 }
1127 case VERTEX_FORMAT_USHORT2:
1128 {
1129 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1130 return format;
1131 }
1132 case VERTEX_FORMAT_USHORT2_NORM:
1133 {
1134 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1135 return format;
1136 }
1137 case VERTEX_FORMAT_USHORT3:
1138 {
1139 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1140 return format;
1141 }
1142 case VERTEX_FORMAT_USHORT3_NORM:
1143 {
1144 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1145 return format;
1146 }
1147 case VERTEX_FORMAT_USHORT4:
1148 {
1149 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1150 return format;
1151 }
1152 case VERTEX_FORMAT_USHORT4_NORM:
1153 {
1154 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1155 return format;
1156 }
1157 case VERTEX_FORMAT_SINT1:
1158 {
1159 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1160 return format;
1161 }
1162 case VERTEX_FORMAT_SINT1_NORM:
1163 {
1164 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1165 return format;
1166 }
1167 case VERTEX_FORMAT_SINT2:
1168 {
1169 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1170 return format;
1171 }
1172 case VERTEX_FORMAT_SINT2_NORM:
1173 {
1174 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1175 return format;
1176 }
1177 case VERTEX_FORMAT_SINT3:
1178 {
1179 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1180 return format;
1181 }
1182 case VERTEX_FORMAT_SINT3_NORM:
1183 {
1184 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1185 return format;
1186 }
1187 case VERTEX_FORMAT_SINT4:
1188 {
1189 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1190 return format;
1191 }
1192 case VERTEX_FORMAT_SINT4_NORM:
1193 {
1194 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1195 return format;
1196 }
1197 case VERTEX_FORMAT_UINT1:
1198 {
1199 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1200 return format;
1201 }
1202 case VERTEX_FORMAT_UINT1_NORM:
1203 {
1204 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1205 return format;
1206 }
1207 case VERTEX_FORMAT_UINT2:
1208 {
1209 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1210 return format;
1211 }
1212 case VERTEX_FORMAT_UINT2_NORM:
1213 {
1214 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1215 return format;
1216 }
1217 case VERTEX_FORMAT_UINT3:
1218 {
1219 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1220 return format;
1221 }
1222 case VERTEX_FORMAT_UINT3_NORM:
1223 {
1224 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1225 return format;
1226 }
1227 case VERTEX_FORMAT_UINT4:
1228 {
1229 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1230 return format;
1231 }
1232 case VERTEX_FORMAT_UINT4_NORM:
1233 {
1234 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1235 return format;
1236 }
1237 case VERTEX_FORMAT_SBYTE1_INT:
1238 {
1239 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1240 return format;
1241 }
1242 case VERTEX_FORMAT_SBYTE2_INT:
1243 {
1244 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1245 return format;
1246 }
1247 case VERTEX_FORMAT_SBYTE3_INT:
1248 {
1249 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1250 return format;
1251 }
1252 case VERTEX_FORMAT_SBYTE4_INT:
1253 {
1254 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1255 return format;
1256 }
1257 case VERTEX_FORMAT_UBYTE1_INT:
1258 {
1259 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1260 return format;
1261 }
1262 case VERTEX_FORMAT_UBYTE2_INT:
1263 {
1264 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1265 return format;
1266 }
1267 case VERTEX_FORMAT_UBYTE3_INT:
1268 {
1269 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1270 return format;
1271 }
1272 case VERTEX_FORMAT_UBYTE4_INT:
1273 {
1274 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1275 return format;
1276 }
1277 case VERTEX_FORMAT_SSHORT1_INT:
1278 {
1279 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1280 return format;
1281 }
1282 case VERTEX_FORMAT_SSHORT2_INT:
1283 {
1284 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1285 return format;
1286 }
1287 case VERTEX_FORMAT_SSHORT3_INT:
1288 {
1289 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1290 return format;
1291 }
1292 case VERTEX_FORMAT_SSHORT4_INT:
1293 {
1294 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1295 return format;
1296 }
1297 case VERTEX_FORMAT_USHORT1_INT:
1298 {
1299 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1300 return format;
1301 }
1302 case VERTEX_FORMAT_USHORT2_INT:
1303 {
1304 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1305 return format;
1306 }
1307 case VERTEX_FORMAT_USHORT3_INT:
1308 {
1309 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1310 return format;
1311 }
1312 case VERTEX_FORMAT_USHORT4_INT:
1313 {
1314 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1315 return format;
1316 }
1317 case VERTEX_FORMAT_SINT1_INT:
1318 {
1319 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1320 return format;
1321 }
1322 case VERTEX_FORMAT_SINT2_INT:
1323 {
1324 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1325 return format;
1326 }
1327 case VERTEX_FORMAT_SINT3_INT:
1328 {
1329 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1330 return format;
1331 }
1332 case VERTEX_FORMAT_SINT4_INT:
1333 {
1334 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1335 return format;
1336 }
1337 case VERTEX_FORMAT_UINT1_INT:
1338 {
1339 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1340 return format;
1341 }
1342 case VERTEX_FORMAT_UINT2_INT:
1343 {
1344 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1345 return format;
1346 }
1347 case VERTEX_FORMAT_UINT3_INT:
1348 {
1349 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1350 return format;
1351 }
1352 case VERTEX_FORMAT_UINT4_INT:
1353 {
1354 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1355 return format;
1356 }
1357 case VERTEX_FORMAT_FIXED1:
1358 {
1359 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1360 return format;
1361 }
1362 case VERTEX_FORMAT_FIXED2:
1363 {
1364 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1365 return format;
1366 }
1367 case VERTEX_FORMAT_FIXED3:
1368 {
1369 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1370 return format;
1371 }
1372 case VERTEX_FORMAT_FIXED4:
1373 {
1374 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1375 return format;
1376 }
1377 case VERTEX_FORMAT_HALF1:
1378 {
1379 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1380 return format;
1381 }
1382 case VERTEX_FORMAT_HALF2:
1383 {
1384 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1385 return format;
1386 }
1387 case VERTEX_FORMAT_HALF3:
1388 {
1389 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1390 return format;
1391 }
1392 case VERTEX_FORMAT_HALF4:
1393 {
1394 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1395 return format;
1396 }
1397 case VERTEX_FORMAT_FLOAT1:
1398 {
1399 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1400 return format;
1401 }
1402 case VERTEX_FORMAT_FLOAT2:
1403 {
1404 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1405 return format;
1406 }
1407 case VERTEX_FORMAT_FLOAT3:
1408 {
1409 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1410 return format;
1411 }
1412 case VERTEX_FORMAT_FLOAT4:
1413 {
1414 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1415 return format;
1416 }
1417 case VERTEX_FORMAT_SINT210:
1418 {
1419 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1420 return format;
1421 }
1422 case VERTEX_FORMAT_UINT210:
1423 {
1424 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1425 return format;
1426 }
1427 case VERTEX_FORMAT_SINT210_NORM:
1428 {
1429 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1430 return format;
1431 }
1432 case VERTEX_FORMAT_UINT210_NORM:
1433 {
1434 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1435 return format;
1436 }
1437 case VERTEX_FORMAT_SINT210_INT:
1438 {
1439 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1440 return format;
1441 }
1442 case VERTEX_FORMAT_UINT210_INT:
1443 {
1444 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1445 return format;
1446 }
1447 default:
1448 {
1449 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1450 return format;
1451 }
1452 }
1453}
1454
1455VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1456 : type(typeIn),
1457 normalized(normalizedIn),
1458 components(componentsIn),
1459 pureInteger(pureIntegerIn)
1460{
1461 // float -> !normalized
1462 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1463}
1464
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001465}