blob: e9c04e2e16afd8d4446a380b924bbddca1839dc6 [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
166static bool UnimplementedSupport(GLuint, const Extensions &)
167{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000168 return false;
169}
170
Geoff Lang493daf52014-07-03 13:38:44 -0400171static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000172{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000173 return false;
174}
175
Geoff Lange4a492b2014-06-19 14:14:41 -0400176template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400177static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400178{
179 return clientVersion >= minCoreGLVersion;
180}
181
Geoff Langcec35902014-04-16 10:52:36 -0400182// Pointer to a boolean memeber of the Extensions struct
183typedef bool(Extensions::*ExtensionBool);
184
185// Check support for a single extension
186template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400187static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400188{
Geoff Lange4a492b2014-06-19 14:14:41 -0400189 return extensions.*bool1;
190}
191
192// Check for a minimum client version or a single extension
193template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400194static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400195{
196 return clientVersion >= minCoreGLVersion || extensions.*bool1;
197}
198
199// Check for a minimum client version or two extensions
200template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400201static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400202{
Geoff Langabce7622014-09-19 16:13:00 -0400203 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
204}
205
206// Check for a minimum client version or at least one of two extensions
207template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
208static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
209{
210 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400211}
212
213// Check support for two extensions
214template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400215static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400216{
Geoff Langabce7622014-09-19 16:13:00 -0400217 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400218}
219
Geoff Lang5d601382014-07-22 15:14:06 -0400220InternalFormat::InternalFormat()
221 : redBits(0),
222 greenBits(0),
223 blueBits(0),
224 luminanceBits(0),
225 alphaBits(0),
226 sharedBits(0),
227 depthBits(0),
228 stencilBits(0),
229 pixelBytes(0),
230 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400231 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400232 compressedBlockWidth(0),
233 compressedBlockHeight(0),
234 format(GL_NONE),
235 type(GL_NONE),
236 componentType(GL_NONE),
237 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400238 textureSupport(NeverSupported),
239 renderSupport(NeverSupported),
240 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000241{
Geoff Lang5d601382014-07-22 15:14:06 -0400242}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000243
Geoff Lang5d601382014-07-22 15:14:06 -0400244static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
245 InternalFormat::SupportCheckFunction renderSupport,
246 InternalFormat::SupportCheckFunction filterSupport)
247{
248 InternalFormat formatInfo;
249 formatInfo.format = format;
250 formatInfo.textureSupport = textureSupport;
251 formatInfo.renderSupport = renderSupport;
252 formatInfo.filterSupport = filterSupport;
253 return formatInfo;
254}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000255
Geoff Lang5d601382014-07-22 15:14:06 -0400256static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
257 GLenum format, GLenum type, GLenum componentType, bool srgb,
258 InternalFormat::SupportCheckFunction textureSupport,
259 InternalFormat::SupportCheckFunction renderSupport,
260 InternalFormat::SupportCheckFunction filterSupport)
261{
262 InternalFormat formatInfo;
263 formatInfo.redBits = red;
264 formatInfo.greenBits = green;
265 formatInfo.blueBits = blue;
266 formatInfo.alphaBits = alpha;
267 formatInfo.sharedBits = shared;
268 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
269 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
270 formatInfo.format = format;
271 formatInfo.type = type;
272 formatInfo.componentType = componentType;
273 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
274 formatInfo.textureSupport = textureSupport;
275 formatInfo.renderSupport = renderSupport;
276 formatInfo.filterSupport = filterSupport;
277 return formatInfo;
278}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000279
Geoff Lang5d601382014-07-22 15:14:06 -0400280static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
281 InternalFormat::SupportCheckFunction textureSupport,
282 InternalFormat::SupportCheckFunction renderSupport,
283 InternalFormat::SupportCheckFunction filterSupport)
284{
285 InternalFormat formatInfo;
286 formatInfo.luminanceBits = luminance;
287 formatInfo.alphaBits = alpha;
288 formatInfo.pixelBytes = (luminance + alpha) / 8;
289 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
290 formatInfo.format = format;
291 formatInfo.type = type;
292 formatInfo.componentType = componentType;
293 formatInfo.colorEncoding = GL_LINEAR;
294 formatInfo.textureSupport = textureSupport;
295 formatInfo.renderSupport = renderSupport;
296 formatInfo.filterSupport = filterSupport;
297 return formatInfo;
298}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000299
Geoff Lang5d601382014-07-22 15:14:06 -0400300static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
301 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
302 InternalFormat::SupportCheckFunction renderSupport,
303 InternalFormat::SupportCheckFunction filterSupport)
304{
305 InternalFormat formatInfo;
306 formatInfo.depthBits = depthBits;
307 formatInfo.stencilBits = stencilBits;
308 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
309 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
310 formatInfo.format = format;
311 formatInfo.type = type;
312 formatInfo.componentType = componentType;
313 formatInfo.colorEncoding = GL_LINEAR;
314 formatInfo.textureSupport = textureSupport;
315 formatInfo.renderSupport = renderSupport;
316 formatInfo.filterSupport = filterSupport;
317 return formatInfo;
318}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000319
Geoff Lang5d601382014-07-22 15:14:06 -0400320static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
321 GLuint componentCount, GLenum format, GLenum type, bool srgb,
322 InternalFormat::SupportCheckFunction textureSupport,
323 InternalFormat::SupportCheckFunction renderSupport,
324 InternalFormat::SupportCheckFunction filterSupport)
325{
326 InternalFormat formatInfo;
327 formatInfo.compressedBlockWidth = compressedBlockWidth;
328 formatInfo.compressedBlockHeight = compressedBlockHeight;
329 formatInfo.pixelBytes = compressedBlockSize / 8;
330 formatInfo.componentCount = componentCount;
331 formatInfo.format = format;
332 formatInfo.type = type;
333 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
334 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
335 formatInfo.compressed = true;
336 formatInfo.textureSupport = textureSupport;
337 formatInfo.renderSupport = renderSupport;
338 formatInfo.filterSupport = filterSupport;
339 return formatInfo;
340}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000341
Geoff Lang5d601382014-07-22 15:14:06 -0400342typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
343typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000344
Geoff Lange4a492b2014-06-19 14:14:41 -0400345static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000346{
347 InternalFormatInfoMap map;
348
Geoff Langd0f9fdc2015-09-04 11:07:29 -0400349 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000350 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400351 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000352
Geoff Langabce7622014-09-19 16:13:00 -0400353 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
354 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)));
355 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
356 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)));
357 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
358 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)));
359 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
360 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)));
361 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)));
362 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)));
363 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)));
364 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
365 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 Langd0f9fdc2015-09-04 11:07:29 -0400366 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 -0400367 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)));
368 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)));
369 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)));
370 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)));
371 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
372 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)));
373 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
374 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)));
375 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
376 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)));
377 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
378 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)));
379 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
380 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)));
381 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
382 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)));
383 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
384 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)));
385 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
386 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)));
387 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
388 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)));
389 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
390 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)));
391 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
392 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)));
393 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
394 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 +0000395
Geoff Langabce7622014-09-19 16:13:00 -0400396 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)));
397 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)));
398 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 +0000399
400 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langabce7622014-09-19 16:13:00 -0400401 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
402 // | | | | | | | type | | | | |
403 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>)));
404 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>)));
405 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>)));
406 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>)));
407 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> )));
408 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> )));
409 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> )));
410 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 +0000411
412 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400413 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
414 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>)));
415 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>)));
416 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>)));
417 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 )));
418 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 )));
419 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 -0800420 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000421
422 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400423 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400424 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
425 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
426 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
427 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
428 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
429 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
430 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
431 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
432 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 +0000433
434 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400435 // | Internal format | | Format | Supported | Renderable | Filterable |
436 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
437 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
438 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
439 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
440 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
441 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
442 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
443 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
444 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
445 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
446 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
447 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
448 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
449 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
450 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
451 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 +0000452
453 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang5d601382014-07-22 15:14:06 -0400454 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
455 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
456 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
457 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
458 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
459 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
460 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
461 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
462 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, true, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
463 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
464 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, true, UnimplementedSupport, UnimplementedSupport, UnimplementedSupport)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000465
466 // From GL_EXT_texture_compression_dxt1
Geoff Langabce7622014-09-19 16:13:00 -0400467 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
468 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)));
469 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 +0000470
471 // From GL_ANGLE_texture_compression_dxt3
Geoff Langabce7622014-09-19 16:13:00 -0400472 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 +0000473
474 // From GL_ANGLE_texture_compression_dxt5
Geoff Langabce7622014-09-19 16:13:00 -0400475 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)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000476
Corentin Walleze0902642014-11-04 12:32:15 -0800477 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
478 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
479 // - All other stencil formats (all depth-stencil) are either float or normalized
480 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
481 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
482 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 Langd0f9fdc2015-09-04 11:07:29 -0400483 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800484
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000485 return map;
486}
487
Geoff Lange4a492b2014-06-19 14:14:41 -0400488static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000489{
Geoff Lange4a492b2014-06-19 14:14:41 -0400490 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
491 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000492}
493
Geoff Lange4a492b2014-06-19 14:14:41 -0400494static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400495{
496 FormatSet result;
497
Geoff Lange4a492b2014-06-19 14:14:41 -0400498 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400499 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
500 {
Geoff Lang5d601382014-07-22 15:14:06 -0400501 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400502 {
503 result.insert(i->first);
504 }
505 }
506
507 return result;
508}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000509
Geoff Lang5d601382014-07-22 15:14:06 -0400510const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000511{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200512 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000513 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200514 case GL_UNSIGNED_BYTE:
515 case GL_BYTE:
516 {
517 static const Type info = GenTypeInfo(1, false);
518 return info;
519 }
520 case GL_UNSIGNED_SHORT:
521 case GL_SHORT:
522 case GL_HALF_FLOAT:
523 case GL_HALF_FLOAT_OES:
524 {
525 static const Type info = GenTypeInfo(2, false);
526 return info;
527 }
528 case GL_UNSIGNED_INT:
529 case GL_INT:
530 case GL_FLOAT:
531 {
532 static const Type info = GenTypeInfo(4, false);
533 return info;
534 }
535 case GL_UNSIGNED_SHORT_5_6_5:
536 case GL_UNSIGNED_SHORT_4_4_4_4:
537 case GL_UNSIGNED_SHORT_5_5_5_1:
538 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
539 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
540 {
541 static const Type info = GenTypeInfo(2, true);
542 return info;
543 }
544 case GL_UNSIGNED_INT_2_10_10_10_REV:
545 case GL_UNSIGNED_INT_24_8:
546 case GL_UNSIGNED_INT_10F_11F_11F_REV:
547 case GL_UNSIGNED_INT_5_9_9_9_REV:
548 {
549 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
550 static const Type info = GenTypeInfo(4, true);
551 return info;
552 }
553 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
554 {
555 static const Type info = GenTypeInfo(8, true);
556 return info;
557 }
558 default:
559 {
560 static const Type defaultInfo;
561 return defaultInfo;
562 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000563 }
564}
565
Geoff Lang5d601382014-07-22 15:14:06 -0400566const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000567{
Geoff Lang5d601382014-07-22 15:14:06 -0400568 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
569 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
570 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000571 {
Geoff Lang5d601382014-07-22 15:14:06 -0400572 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000573 }
574 else
575 {
Geoff Lang5d601382014-07-22 15:14:06 -0400576 static const InternalFormat defaultInternalFormat;
577 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000578 }
579}
580
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800581GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000582{
583 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800584 GLuint rowBytes;
585 if (rowLength > 0)
586 {
587 ASSERT(!compressed);
588 rowBytes = pixelBytes * rowLength;
589 }
590 else
591 {
592 rowBytes = computeBlockSize(formatType, width, 1);
593 }
594 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000595}
596
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800597GLuint InternalFormat::computeDepthPitch(GLenum formatType, GLsizei width, GLsizei height, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000598{
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800599 return computeRowPitch(formatType, width, alignment, rowLength) * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000600}
601
Austin Kinross3ae64652015-01-26 15:51:39 -0800602GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000603{
Geoff Lang5d601382014-07-22 15:14:06 -0400604 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000605 {
Geoff Lang5d601382014-07-22 15:14:06 -0400606 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
607 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
608 return (pixelBytes * numBlocksWide * numBlocksHight);
609 }
610 else
611 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800612 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400613 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614 {
Geoff Lang5d601382014-07-22 15:14:06 -0400615 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000616 }
617 else
618 {
Geoff Lang5d601382014-07-22 15:14:06 -0400619 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000620 }
621 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000622}
623
Geoff Lang5d601382014-07-22 15:14:06 -0400624GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000625{
Geoff Lang5d601382014-07-22 15:14:06 -0400626 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500627 if (formatInfo.pixelBytes > 0)
628 {
629 return internalFormat;
630 }
631 else
632 {
633 static const FormatMap formatMap = BuildFormatMap();
634 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
635 if (iter != formatMap.end())
636 {
637 return iter->second;
638 }
639 else
640 {
641 return GL_NONE;
642 }
643 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000644}
645
Geoff Lange4a492b2014-06-19 14:14:41 -0400646const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400647{
Geoff Lange4a492b2014-06-19 14:14:41 -0400648 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400649 return formatSet;
650}
651
Jamie Madill09e2d932015-07-14 16:40:31 -0400652AttributeType GetAttributeType(GLenum enumValue)
653{
654 switch (enumValue)
655 {
656 case GL_FLOAT:
657 return ATTRIBUTE_FLOAT;
658 case GL_FLOAT_VEC2:
659 return ATTRIBUTE_VEC2;
660 case GL_FLOAT_VEC3:
661 return ATTRIBUTE_VEC3;
662 case GL_FLOAT_VEC4:
663 return ATTRIBUTE_VEC4;
664 case GL_INT:
665 return ATTRIBUTE_INT;
666 case GL_INT_VEC2:
667 return ATTRIBUTE_IVEC2;
668 case GL_INT_VEC3:
669 return ATTRIBUTE_IVEC3;
670 case GL_INT_VEC4:
671 return ATTRIBUTE_IVEC4;
672 case GL_UNSIGNED_INT:
673 return ATTRIBUTE_UINT;
674 case GL_UNSIGNED_INT_VEC2:
675 return ATTRIBUTE_UVEC2;
676 case GL_UNSIGNED_INT_VEC3:
677 return ATTRIBUTE_UVEC3;
678 case GL_UNSIGNED_INT_VEC4:
679 return ATTRIBUTE_UVEC4;
680 case GL_FLOAT_MAT2:
681 return ATTRIBUTE_MAT2;
682 case GL_FLOAT_MAT3:
683 return ATTRIBUTE_MAT3;
684 case GL_FLOAT_MAT4:
685 return ATTRIBUTE_MAT4;
686 case GL_FLOAT_MAT2x3:
687 return ATTRIBUTE_MAT2x3;
688 case GL_FLOAT_MAT2x4:
689 return ATTRIBUTE_MAT2x4;
690 case GL_FLOAT_MAT3x2:
691 return ATTRIBUTE_MAT3x2;
692 case GL_FLOAT_MAT3x4:
693 return ATTRIBUTE_MAT3x4;
694 case GL_FLOAT_MAT4x2:
695 return ATTRIBUTE_MAT4x2;
696 case GL_FLOAT_MAT4x3:
697 return ATTRIBUTE_MAT4x3;
698 default:
699 UNREACHABLE();
700 return ATTRIBUTE_FLOAT;
701 }
702}
703
Jamie Madilld3dfda22015-07-06 08:28:49 -0400704VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
705{
706 switch (type)
707 {
708 case GL_BYTE:
709 switch (components)
710 {
711 case 1:
712 if (pureInteger)
713 return VERTEX_FORMAT_SBYTE1_INT;
714 if (normalized)
715 return VERTEX_FORMAT_SBYTE1_NORM;
716 return VERTEX_FORMAT_SBYTE1;
717 case 2:
718 if (pureInteger)
719 return VERTEX_FORMAT_SBYTE2_INT;
720 if (normalized)
721 return VERTEX_FORMAT_SBYTE2_NORM;
722 return VERTEX_FORMAT_SBYTE2;
723 case 3:
724 if (pureInteger)
725 return VERTEX_FORMAT_SBYTE3_INT;
726 if (normalized)
727 return VERTEX_FORMAT_SBYTE3_NORM;
728 return VERTEX_FORMAT_SBYTE3;
729 case 4:
730 if (pureInteger)
731 return VERTEX_FORMAT_SBYTE4_INT;
732 if (normalized)
733 return VERTEX_FORMAT_SBYTE4_NORM;
734 return VERTEX_FORMAT_SBYTE4;
735 default:
736 UNREACHABLE();
737 break;
738 }
739 case GL_UNSIGNED_BYTE:
740 switch (components)
741 {
742 case 1:
743 if (pureInteger)
744 return VERTEX_FORMAT_UBYTE1_INT;
745 if (normalized)
746 return VERTEX_FORMAT_UBYTE1_NORM;
747 return VERTEX_FORMAT_UBYTE1;
748 case 2:
749 if (pureInteger)
750 return VERTEX_FORMAT_UBYTE2_INT;
751 if (normalized)
752 return VERTEX_FORMAT_UBYTE2_NORM;
753 return VERTEX_FORMAT_UBYTE2;
754 case 3:
755 if (pureInteger)
756 return VERTEX_FORMAT_UBYTE3_INT;
757 if (normalized)
758 return VERTEX_FORMAT_UBYTE3_NORM;
759 return VERTEX_FORMAT_UBYTE3;
760 case 4:
761 if (pureInteger)
762 return VERTEX_FORMAT_UBYTE4_INT;
763 if (normalized)
764 return VERTEX_FORMAT_UBYTE4_NORM;
765 return VERTEX_FORMAT_UBYTE4;
766 default:
767 UNREACHABLE();
768 break;
769 }
770 case GL_SHORT:
771 switch (components)
772 {
773 case 1:
774 if (pureInteger)
775 return VERTEX_FORMAT_SSHORT1_INT;
776 if (normalized)
777 return VERTEX_FORMAT_SSHORT1_NORM;
778 return VERTEX_FORMAT_SSHORT1;
779 case 2:
780 if (pureInteger)
781 return VERTEX_FORMAT_SSHORT2_INT;
782 if (normalized)
783 return VERTEX_FORMAT_SSHORT2_NORM;
784 return VERTEX_FORMAT_SSHORT2;
785 case 3:
786 if (pureInteger)
787 return VERTEX_FORMAT_SSHORT3_INT;
788 if (normalized)
789 return VERTEX_FORMAT_SSHORT3_NORM;
790 return VERTEX_FORMAT_SSHORT3;
791 case 4:
792 if (pureInteger)
793 return VERTEX_FORMAT_SSHORT4_INT;
794 if (normalized)
795 return VERTEX_FORMAT_SSHORT4_NORM;
796 return VERTEX_FORMAT_SSHORT4;
797 default:
798 UNREACHABLE();
799 break;
800 }
801 case GL_UNSIGNED_SHORT:
802 switch (components)
803 {
804 case 1:
805 if (pureInteger)
806 return VERTEX_FORMAT_USHORT1_INT;
807 if (normalized)
808 return VERTEX_FORMAT_USHORT1_NORM;
809 return VERTEX_FORMAT_USHORT1;
810 case 2:
811 if (pureInteger)
812 return VERTEX_FORMAT_USHORT2_INT;
813 if (normalized)
814 return VERTEX_FORMAT_USHORT2_NORM;
815 return VERTEX_FORMAT_USHORT2;
816 case 3:
817 if (pureInteger)
818 return VERTEX_FORMAT_USHORT3_INT;
819 if (normalized)
820 return VERTEX_FORMAT_USHORT3_NORM;
821 return VERTEX_FORMAT_USHORT3;
822 case 4:
823 if (pureInteger)
824 return VERTEX_FORMAT_USHORT4_INT;
825 if (normalized)
826 return VERTEX_FORMAT_USHORT4_NORM;
827 return VERTEX_FORMAT_USHORT4;
828 default:
829 UNREACHABLE();
830 break;
831 }
832 case GL_INT:
833 switch (components)
834 {
835 case 1:
836 if (pureInteger)
837 return VERTEX_FORMAT_SINT1_INT;
838 if (normalized)
839 return VERTEX_FORMAT_SINT1_NORM;
840 return VERTEX_FORMAT_SINT1;
841 case 2:
842 if (pureInteger)
843 return VERTEX_FORMAT_SINT2_INT;
844 if (normalized)
845 return VERTEX_FORMAT_SINT2_NORM;
846 return VERTEX_FORMAT_SINT2;
847 case 3:
848 if (pureInteger)
849 return VERTEX_FORMAT_SINT3_INT;
850 if (normalized)
851 return VERTEX_FORMAT_SINT3_NORM;
852 return VERTEX_FORMAT_SINT3;
853 case 4:
854 if (pureInteger)
855 return VERTEX_FORMAT_SINT4_INT;
856 if (normalized)
857 return VERTEX_FORMAT_SINT4_NORM;
858 return VERTEX_FORMAT_SINT4;
859 default:
860 UNREACHABLE();
861 break;
862 }
863 case GL_UNSIGNED_INT:
864 switch (components)
865 {
866 case 1:
867 if (pureInteger)
868 return VERTEX_FORMAT_UINT1_INT;
869 if (normalized)
870 return VERTEX_FORMAT_UINT1_NORM;
871 return VERTEX_FORMAT_UINT1;
872 case 2:
873 if (pureInteger)
874 return VERTEX_FORMAT_UINT2_INT;
875 if (normalized)
876 return VERTEX_FORMAT_UINT2_NORM;
877 return VERTEX_FORMAT_UINT2;
878 case 3:
879 if (pureInteger)
880 return VERTEX_FORMAT_UINT3_INT;
881 if (normalized)
882 return VERTEX_FORMAT_UINT3_NORM;
883 return VERTEX_FORMAT_UINT3;
884 case 4:
885 if (pureInteger)
886 return VERTEX_FORMAT_UINT4_INT;
887 if (normalized)
888 return VERTEX_FORMAT_UINT4_NORM;
889 return VERTEX_FORMAT_UINT4;
890 default:
891 UNREACHABLE();
892 break;
893 }
894 case GL_FLOAT:
895 switch (components)
896 {
897 case 1:
898 return VERTEX_FORMAT_FLOAT1;
899 case 2:
900 return VERTEX_FORMAT_FLOAT2;
901 case 3:
902 return VERTEX_FORMAT_FLOAT3;
903 case 4:
904 return VERTEX_FORMAT_FLOAT4;
905 default:
906 UNREACHABLE();
907 break;
908 }
909 case GL_HALF_FLOAT:
910 switch (components)
911 {
912 case 1:
913 return VERTEX_FORMAT_HALF1;
914 case 2:
915 return VERTEX_FORMAT_HALF2;
916 case 3:
917 return VERTEX_FORMAT_HALF3;
918 case 4:
919 return VERTEX_FORMAT_HALF4;
920 default:
921 UNREACHABLE();
922 break;
923 }
924 case GL_FIXED:
925 switch (components)
926 {
927 case 1:
928 return VERTEX_FORMAT_FIXED1;
929 case 2:
930 return VERTEX_FORMAT_FIXED2;
931 case 3:
932 return VERTEX_FORMAT_FIXED3;
933 case 4:
934 return VERTEX_FORMAT_FIXED4;
935 default:
936 UNREACHABLE();
937 break;
938 }
939 case GL_INT_2_10_10_10_REV:
940 if (pureInteger)
941 return VERTEX_FORMAT_SINT210_INT;
942 if (normalized)
943 return VERTEX_FORMAT_SINT210_NORM;
944 return VERTEX_FORMAT_SINT210;
945 case GL_UNSIGNED_INT_2_10_10_10_REV:
946 if (pureInteger)
947 return VERTEX_FORMAT_UINT210_INT;
948 if (normalized)
949 return VERTEX_FORMAT_UINT210_NORM;
950 return VERTEX_FORMAT_UINT210;
951 default:
952 UNREACHABLE();
953 break;
954 }
955 return VERTEX_FORMAT_UBYTE1;
956}
957
958VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
959{
960 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
961}
962
963VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
964{
965 if (!attrib.enabled)
966 {
967 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
968 }
969 return GetVertexFormatType(attrib);
970}
971
972const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
973{
974 switch (vertexFormatType)
975 {
976 case VERTEX_FORMAT_SBYTE1:
977 {
978 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
979 return format;
980 }
981 case VERTEX_FORMAT_SBYTE1_NORM:
982 {
983 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
984 return format;
985 }
986 case VERTEX_FORMAT_SBYTE2:
987 {
988 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
989 return format;
990 }
991 case VERTEX_FORMAT_SBYTE2_NORM:
992 {
993 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
994 return format;
995 }
996 case VERTEX_FORMAT_SBYTE3:
997 {
998 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
999 return format;
1000 }
1001 case VERTEX_FORMAT_SBYTE3_NORM:
1002 {
1003 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1004 return format;
1005 }
1006 case VERTEX_FORMAT_SBYTE4:
1007 {
1008 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1009 return format;
1010 }
1011 case VERTEX_FORMAT_SBYTE4_NORM:
1012 {
1013 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1014 return format;
1015 }
1016 case VERTEX_FORMAT_UBYTE1:
1017 {
1018 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1019 return format;
1020 }
1021 case VERTEX_FORMAT_UBYTE1_NORM:
1022 {
1023 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1024 return format;
1025 }
1026 case VERTEX_FORMAT_UBYTE2:
1027 {
1028 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1029 return format;
1030 }
1031 case VERTEX_FORMAT_UBYTE2_NORM:
1032 {
1033 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1034 return format;
1035 }
1036 case VERTEX_FORMAT_UBYTE3:
1037 {
1038 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1039 return format;
1040 }
1041 case VERTEX_FORMAT_UBYTE3_NORM:
1042 {
1043 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1044 return format;
1045 }
1046 case VERTEX_FORMAT_UBYTE4:
1047 {
1048 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1049 return format;
1050 }
1051 case VERTEX_FORMAT_UBYTE4_NORM:
1052 {
1053 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1054 return format;
1055 }
1056 case VERTEX_FORMAT_SSHORT1:
1057 {
1058 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1059 return format;
1060 }
1061 case VERTEX_FORMAT_SSHORT1_NORM:
1062 {
1063 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1064 return format;
1065 }
1066 case VERTEX_FORMAT_SSHORT2:
1067 {
1068 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1069 return format;
1070 }
1071 case VERTEX_FORMAT_SSHORT2_NORM:
1072 {
1073 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1074 return format;
1075 }
1076 case VERTEX_FORMAT_SSHORT3:
1077 {
1078 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1079 return format;
1080 }
1081 case VERTEX_FORMAT_SSHORT3_NORM:
1082 {
1083 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1084 return format;
1085 }
1086 case VERTEX_FORMAT_SSHORT4:
1087 {
1088 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1089 return format;
1090 }
1091 case VERTEX_FORMAT_SSHORT4_NORM:
1092 {
1093 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1094 return format;
1095 }
1096 case VERTEX_FORMAT_USHORT1:
1097 {
1098 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1099 return format;
1100 }
1101 case VERTEX_FORMAT_USHORT1_NORM:
1102 {
1103 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1104 return format;
1105 }
1106 case VERTEX_FORMAT_USHORT2:
1107 {
1108 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1109 return format;
1110 }
1111 case VERTEX_FORMAT_USHORT2_NORM:
1112 {
1113 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1114 return format;
1115 }
1116 case VERTEX_FORMAT_USHORT3:
1117 {
1118 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1119 return format;
1120 }
1121 case VERTEX_FORMAT_USHORT3_NORM:
1122 {
1123 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1124 return format;
1125 }
1126 case VERTEX_FORMAT_USHORT4:
1127 {
1128 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1129 return format;
1130 }
1131 case VERTEX_FORMAT_USHORT4_NORM:
1132 {
1133 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1134 return format;
1135 }
1136 case VERTEX_FORMAT_SINT1:
1137 {
1138 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1139 return format;
1140 }
1141 case VERTEX_FORMAT_SINT1_NORM:
1142 {
1143 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1144 return format;
1145 }
1146 case VERTEX_FORMAT_SINT2:
1147 {
1148 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1149 return format;
1150 }
1151 case VERTEX_FORMAT_SINT2_NORM:
1152 {
1153 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1154 return format;
1155 }
1156 case VERTEX_FORMAT_SINT3:
1157 {
1158 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1159 return format;
1160 }
1161 case VERTEX_FORMAT_SINT3_NORM:
1162 {
1163 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1164 return format;
1165 }
1166 case VERTEX_FORMAT_SINT4:
1167 {
1168 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1169 return format;
1170 }
1171 case VERTEX_FORMAT_SINT4_NORM:
1172 {
1173 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1174 return format;
1175 }
1176 case VERTEX_FORMAT_UINT1:
1177 {
1178 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1179 return format;
1180 }
1181 case VERTEX_FORMAT_UINT1_NORM:
1182 {
1183 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1184 return format;
1185 }
1186 case VERTEX_FORMAT_UINT2:
1187 {
1188 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1189 return format;
1190 }
1191 case VERTEX_FORMAT_UINT2_NORM:
1192 {
1193 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1194 return format;
1195 }
1196 case VERTEX_FORMAT_UINT3:
1197 {
1198 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1199 return format;
1200 }
1201 case VERTEX_FORMAT_UINT3_NORM:
1202 {
1203 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1204 return format;
1205 }
1206 case VERTEX_FORMAT_UINT4:
1207 {
1208 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1209 return format;
1210 }
1211 case VERTEX_FORMAT_UINT4_NORM:
1212 {
1213 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1214 return format;
1215 }
1216 case VERTEX_FORMAT_SBYTE1_INT:
1217 {
1218 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1219 return format;
1220 }
1221 case VERTEX_FORMAT_SBYTE2_INT:
1222 {
1223 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1224 return format;
1225 }
1226 case VERTEX_FORMAT_SBYTE3_INT:
1227 {
1228 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1229 return format;
1230 }
1231 case VERTEX_FORMAT_SBYTE4_INT:
1232 {
1233 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1234 return format;
1235 }
1236 case VERTEX_FORMAT_UBYTE1_INT:
1237 {
1238 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1239 return format;
1240 }
1241 case VERTEX_FORMAT_UBYTE2_INT:
1242 {
1243 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1244 return format;
1245 }
1246 case VERTEX_FORMAT_UBYTE3_INT:
1247 {
1248 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1249 return format;
1250 }
1251 case VERTEX_FORMAT_UBYTE4_INT:
1252 {
1253 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1254 return format;
1255 }
1256 case VERTEX_FORMAT_SSHORT1_INT:
1257 {
1258 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1259 return format;
1260 }
1261 case VERTEX_FORMAT_SSHORT2_INT:
1262 {
1263 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1264 return format;
1265 }
1266 case VERTEX_FORMAT_SSHORT3_INT:
1267 {
1268 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1269 return format;
1270 }
1271 case VERTEX_FORMAT_SSHORT4_INT:
1272 {
1273 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1274 return format;
1275 }
1276 case VERTEX_FORMAT_USHORT1_INT:
1277 {
1278 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1279 return format;
1280 }
1281 case VERTEX_FORMAT_USHORT2_INT:
1282 {
1283 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1284 return format;
1285 }
1286 case VERTEX_FORMAT_USHORT3_INT:
1287 {
1288 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1289 return format;
1290 }
1291 case VERTEX_FORMAT_USHORT4_INT:
1292 {
1293 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1294 return format;
1295 }
1296 case VERTEX_FORMAT_SINT1_INT:
1297 {
1298 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1299 return format;
1300 }
1301 case VERTEX_FORMAT_SINT2_INT:
1302 {
1303 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1304 return format;
1305 }
1306 case VERTEX_FORMAT_SINT3_INT:
1307 {
1308 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1309 return format;
1310 }
1311 case VERTEX_FORMAT_SINT4_INT:
1312 {
1313 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1314 return format;
1315 }
1316 case VERTEX_FORMAT_UINT1_INT:
1317 {
1318 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1319 return format;
1320 }
1321 case VERTEX_FORMAT_UINT2_INT:
1322 {
1323 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1324 return format;
1325 }
1326 case VERTEX_FORMAT_UINT3_INT:
1327 {
1328 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1329 return format;
1330 }
1331 case VERTEX_FORMAT_UINT4_INT:
1332 {
1333 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1334 return format;
1335 }
1336 case VERTEX_FORMAT_FIXED1:
1337 {
1338 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1339 return format;
1340 }
1341 case VERTEX_FORMAT_FIXED2:
1342 {
1343 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1344 return format;
1345 }
1346 case VERTEX_FORMAT_FIXED3:
1347 {
1348 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1349 return format;
1350 }
1351 case VERTEX_FORMAT_FIXED4:
1352 {
1353 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1354 return format;
1355 }
1356 case VERTEX_FORMAT_HALF1:
1357 {
1358 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1359 return format;
1360 }
1361 case VERTEX_FORMAT_HALF2:
1362 {
1363 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1364 return format;
1365 }
1366 case VERTEX_FORMAT_HALF3:
1367 {
1368 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1369 return format;
1370 }
1371 case VERTEX_FORMAT_HALF4:
1372 {
1373 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1374 return format;
1375 }
1376 case VERTEX_FORMAT_FLOAT1:
1377 {
1378 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1379 return format;
1380 }
1381 case VERTEX_FORMAT_FLOAT2:
1382 {
1383 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1384 return format;
1385 }
1386 case VERTEX_FORMAT_FLOAT3:
1387 {
1388 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1389 return format;
1390 }
1391 case VERTEX_FORMAT_FLOAT4:
1392 {
1393 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1394 return format;
1395 }
1396 case VERTEX_FORMAT_SINT210:
1397 {
1398 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1399 return format;
1400 }
1401 case VERTEX_FORMAT_UINT210:
1402 {
1403 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1404 return format;
1405 }
1406 case VERTEX_FORMAT_SINT210_NORM:
1407 {
1408 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1409 return format;
1410 }
1411 case VERTEX_FORMAT_UINT210_NORM:
1412 {
1413 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1414 return format;
1415 }
1416 case VERTEX_FORMAT_SINT210_INT:
1417 {
1418 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1419 return format;
1420 }
1421 case VERTEX_FORMAT_UINT210_INT:
1422 {
1423 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1424 return format;
1425 }
1426 default:
1427 {
1428 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1429 return format;
1430 }
1431 }
1432}
1433
1434VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1435 : type(typeIn),
1436 normalized(normalizedIn),
1437 components(componentsIn),
1438 pureInteger(pureIntegerIn)
1439{
1440 // float -> !normalized
1441 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1442}
1443
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001444}