blob: c9533aa24fc7453c0a2afcbd5a8d5167f7e12658 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Shannon Woods4d161ba2014-03-17 18:13:30 -04009#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/formatutils.h"
11#include "libANGLE/Context.h"
12#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000013
Jamie Madille2e406c2016-06-02 13:04:10 -040014using namespace angle;
15
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000016namespace gl
17{
18
19// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
20// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
21// format and type combinations.
22
Jamie Madilld2b50a02016-06-09 00:13:35 -070023typedef std::pair<FormatType, GLenum> FormatPair;
24typedef std::map<FormatType, GLenum> FormatMap;
25
26FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
27{
28}
29
30FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
31{
32}
33
34bool FormatType::operator<(const FormatType &other) const
35{
36 if (format != other.format)
37 return format < other.format;
38 return type < other.type;
39}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000040
Jamie Madill89a0bf52013-09-18 14:36:24 -040041// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050042static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000043{
Jamie Madilld2b50a02016-06-09 00:13:35 -070044 map->insert(FormatPair(FormatType(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045}
46
Geoff Lange4a492b2014-06-19 14:14:41 -040047FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000048{
49 FormatMap map;
50
Geoff Lang051dbc72015-01-05 15:48:58 -050051 // | Format | Type | Internal format |
52 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
53 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
54 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
55 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
56 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
57 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
58 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
59 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000060
Geoff Lang051dbc72015-01-05 15:48:58 -050061 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
62 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
63 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
64 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
65 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
66 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
67 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang051dbc72015-01-05 15:48:58 -050069 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
70 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
71 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
72 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
73 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
74 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
75 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
76 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000077
Geoff Lang051dbc72015-01-05 15:48:58 -050078 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
79 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
80 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
81 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
82 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
83 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000084
Geoff Lang051dbc72015-01-05 15:48:58 -050085 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
86 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
87 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
88 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
89 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000090
Geoff Lang051dbc72015-01-05 15:48:58 -050091 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
92 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
93 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
94 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
95 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
96 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040097
Geoff Lang051dbc72015-01-05 15:48:58 -050098 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
99 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
100 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
101 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
102 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -0400103
Geoff Lang051dbc72015-01-05 15:48:58 -0500104 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
105 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
106 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
107 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
108 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
109 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -0400110
Geoff Lang051dbc72015-01-05 15:48:58 -0500111 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
112 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
113 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
114 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
115 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
116 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
117 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
118 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
119 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
120 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
121 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
122 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400123
Geoff Lang051dbc72015-01-05 15:48:58 -0500124 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
125 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
126 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 -0400127
Geoff Lang051dbc72015-01-05 15:48:58 -0500128 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
129 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400130
Geoff Lang051dbc72015-01-05 15:48:58 -0500131 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
132 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
133 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
134 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400135
Geoff Lang051dbc72015-01-05 15:48:58 -0500136 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
137 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
138 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400139
Geoff Lang051dbc72015-01-05 15:48:58 -0500140 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400141
Geoff Lang051dbc72015-01-05 15:48:58 -0500142 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
143 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000144
145 return map;
146}
147
Geoff Lang5d601382014-07-22 15:14:06 -0400148Type::Type()
149 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200150 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400151 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400152{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000153}
154
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200155static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000156{
Geoff Lang5d601382014-07-22 15:14:06 -0400157 Type info;
158 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200159 GLuint i = 0;
160 while ((1u << i) < bytes)
161 {
162 ++i;
163 }
164 info.bytesShift = i;
165 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400166 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200167 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400168}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000169
Geoff Lang5d601382014-07-22 15:14:06 -0400170bool operator<(const Type& a, const Type& b)
171{
172 return memcmp(&a, &b, sizeof(Type)) < 0;
173}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000174
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000175// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400176static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000177{
Geoff Lang493daf52014-07-03 13:38:44 -0400178 return true;
179}
180
Geoff Lang493daf52014-07-03 13:38:44 -0400181static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000182{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000183 return false;
184}
185
Geoff Lange4a492b2014-06-19 14:14:41 -0400186template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400187static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400188{
189 return clientVersion >= minCoreGLVersion;
190}
191
Geoff Langcec35902014-04-16 10:52:36 -0400192// Pointer to a boolean memeber of the Extensions struct
193typedef bool(Extensions::*ExtensionBool);
194
195// Check support for a single extension
196template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400197static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400198{
Geoff Lange4a492b2014-06-19 14:14:41 -0400199 return extensions.*bool1;
200}
201
202// Check for a minimum client version or a single extension
203template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400204static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400205{
206 return clientVersion >= minCoreGLVersion || extensions.*bool1;
207}
208
209// Check for a minimum client version or two extensions
210template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400211static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400212{
Geoff Langabce7622014-09-19 16:13:00 -0400213 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
214}
215
216// Check for a minimum client version or at least one of two extensions
217template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
218static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
219{
220 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400221}
222
223// Check support for two extensions
224template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400225static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400226{
Geoff Langabce7622014-09-19 16:13:00 -0400227 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400228}
229
Geoff Lang60ad73d2015-10-23 10:08:44 -0400230// Check support for either of two extensions
231template <ExtensionBool bool1, ExtensionBool bool2>
232static bool RequireExtOrExt(GLuint, const Extensions &extensions)
233{
234 return extensions.*bool1 || extensions.*bool2;
235}
236
Jamie Madillcd089732015-12-17 09:53:09 -0500237// Special function for half float formats with three or four channels.
238static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
239{
240 return clientVersion >= 3 || extensions.textureHalfFloat;
241}
242
243static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
244{
245 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
246}
247
248// Special function for half float formats with one or two channels.
249static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
250{
251 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
252}
253
254static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
255{
256 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
257}
258
259// Special function for float formats with three or four channels.
260static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
261{
262 return clientVersion >= 3 || extensions.textureFloat;
263}
264
265static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
266{
267 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
268 return FloatSupport(clientVersion, extensions) &&
269 (extensions.colorBufferFloat || clientVersion == 2);
270}
271
272// Special function for float formats with one or two channels.
273static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
274{
275 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
276}
277
278static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
279{
280 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
281 return FloatSupportRG(clientVersion, extensions) &&
282 (extensions.colorBufferFloat || clientVersion == 2);
283}
284
Geoff Lang5d601382014-07-22 15:14:06 -0400285InternalFormat::InternalFormat()
286 : redBits(0),
287 greenBits(0),
288 blueBits(0),
289 luminanceBits(0),
290 alphaBits(0),
291 sharedBits(0),
292 depthBits(0),
293 stencilBits(0),
294 pixelBytes(0),
295 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400296 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400297 compressedBlockWidth(0),
298 compressedBlockHeight(0),
299 format(GL_NONE),
300 type(GL_NONE),
301 componentType(GL_NONE),
302 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400303 textureSupport(NeverSupported),
304 renderSupport(NeverSupported),
305 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000306{
Geoff Lang5d601382014-07-22 15:14:06 -0400307}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000308
Geoff Lang5d601382014-07-22 15:14:06 -0400309static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
310 InternalFormat::SupportCheckFunction renderSupport,
311 InternalFormat::SupportCheckFunction filterSupport)
312{
313 InternalFormat formatInfo;
314 formatInfo.format = format;
315 formatInfo.textureSupport = textureSupport;
316 formatInfo.renderSupport = renderSupport;
317 formatInfo.filterSupport = filterSupport;
318 return formatInfo;
319}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000320
Geoff Lang5d601382014-07-22 15:14:06 -0400321static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
322 GLenum format, GLenum type, GLenum componentType, bool srgb,
323 InternalFormat::SupportCheckFunction textureSupport,
324 InternalFormat::SupportCheckFunction renderSupport,
325 InternalFormat::SupportCheckFunction filterSupport)
326{
327 InternalFormat formatInfo;
328 formatInfo.redBits = red;
329 formatInfo.greenBits = green;
330 formatInfo.blueBits = blue;
331 formatInfo.alphaBits = alpha;
332 formatInfo.sharedBits = shared;
333 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
334 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
335 formatInfo.format = format;
336 formatInfo.type = type;
337 formatInfo.componentType = componentType;
338 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
339 formatInfo.textureSupport = textureSupport;
340 formatInfo.renderSupport = renderSupport;
341 formatInfo.filterSupport = filterSupport;
342 return formatInfo;
343}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000344
Geoff Lang5d601382014-07-22 15:14:06 -0400345static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
346 InternalFormat::SupportCheckFunction textureSupport,
347 InternalFormat::SupportCheckFunction renderSupport,
348 InternalFormat::SupportCheckFunction filterSupport)
349{
350 InternalFormat formatInfo;
351 formatInfo.luminanceBits = luminance;
352 formatInfo.alphaBits = alpha;
353 formatInfo.pixelBytes = (luminance + alpha) / 8;
354 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
355 formatInfo.format = format;
356 formatInfo.type = type;
357 formatInfo.componentType = componentType;
358 formatInfo.colorEncoding = GL_LINEAR;
359 formatInfo.textureSupport = textureSupport;
360 formatInfo.renderSupport = renderSupport;
361 formatInfo.filterSupport = filterSupport;
362 return formatInfo;
363}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000364
Geoff Lang5d601382014-07-22 15:14:06 -0400365static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
366 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
367 InternalFormat::SupportCheckFunction renderSupport,
368 InternalFormat::SupportCheckFunction filterSupport)
369{
370 InternalFormat formatInfo;
371 formatInfo.depthBits = depthBits;
372 formatInfo.stencilBits = stencilBits;
373 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
374 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
375 formatInfo.format = format;
376 formatInfo.type = type;
377 formatInfo.componentType = componentType;
378 formatInfo.colorEncoding = GL_LINEAR;
379 formatInfo.textureSupport = textureSupport;
380 formatInfo.renderSupport = renderSupport;
381 formatInfo.filterSupport = filterSupport;
382 return formatInfo;
383}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000384
Geoff Lang5d601382014-07-22 15:14:06 -0400385static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
386 GLuint componentCount, GLenum format, GLenum type, bool srgb,
387 InternalFormat::SupportCheckFunction textureSupport,
388 InternalFormat::SupportCheckFunction renderSupport,
389 InternalFormat::SupportCheckFunction filterSupport)
390{
391 InternalFormat formatInfo;
392 formatInfo.compressedBlockWidth = compressedBlockWidth;
393 formatInfo.compressedBlockHeight = compressedBlockHeight;
394 formatInfo.pixelBytes = compressedBlockSize / 8;
395 formatInfo.componentCount = componentCount;
396 formatInfo.format = format;
397 formatInfo.type = type;
398 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
399 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
400 formatInfo.compressed = true;
401 formatInfo.textureSupport = textureSupport;
402 formatInfo.renderSupport = renderSupport;
403 formatInfo.filterSupport = filterSupport;
404 return formatInfo;
405}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000406
Geoff Lang5d601382014-07-22 15:14:06 -0400407typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
408typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000409
Geoff Lange4a492b2014-06-19 14:14:41 -0400410static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000411{
412 InternalFormatInfoMap map;
413
Geoff Lang9bbad182015-09-04 11:07:29 -0400414 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000415 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400416 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000417
Geoff Langabce7622014-09-19 16:13:00 -0400418 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
419 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)));
420 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
421 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)));
422 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
423 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)));
424 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
425 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)));
426 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)));
427 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)));
428 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)));
429 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
430 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 -0400431 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 -0400432 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)));
433 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)));
434 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)));
435 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)));
436 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
437 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)));
438 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
439 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)));
440 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
441 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)));
442 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
443 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)));
444 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
445 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)));
446 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
447 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)));
448 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
449 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)));
450 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
451 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)));
452 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
453 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)));
454 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
455 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)));
456 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
457 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)));
458 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
459 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 +0000460
Geoff Langabce7622014-09-19 16:13:00 -0400461 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)));
462 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)));
463 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 +0000464
465 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500466 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
467 // | | | | | | | type | | | | |
468 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
469 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
470 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
471 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
472 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
473 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
474 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
475 map.insert(InternalFormatInfoPair(GL_RGBA32F, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000476
477 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400478 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
479 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>)));
480 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>)));
481 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>)));
Jamie Madillf06e6072015-12-01 10:44:16 -0500482 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported )));
Geoff Langabce7622014-09-19 16:13:00 -0400483 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 )));
484 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 -0800485 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000486
487 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400488 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400489 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
490 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
491 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
492 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
493 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
494 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
495 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
496 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
497 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 +0000498
499 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400500 // | Internal format | | Format | Supported | Renderable | Filterable |
501 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
502 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
503 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
504 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
505 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
506 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
507 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
508 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
509 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
510 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
511 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
512 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
513 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
514 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
515 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
516 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 +0000517
518 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400519 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
520 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
521 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)));
522 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
523 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)));
524 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
525 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
526 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)));
527 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)));
528 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)));
529 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 +0000530
531 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400532 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
533 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)));
534 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 +0000535
536 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400537 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 +0000538
539 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400540 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)));
541
542 // From GL_OES_compressed_ETC1_RGB8_texture
543 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 +0000544
Geoff Lang60ad73d2015-10-23 10:08:44 -0400545 // From KHR_texture_compression_astc_hdr
546 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
547 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
548 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
549 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
550 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
551 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
552 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
553 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
554 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
555 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
556 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
557 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
558 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
559 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
560 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
561
562 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
563 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
564 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
565 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
566 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
567 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
568 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
569 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
570 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
571 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
572 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
573 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
574 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
575 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported)));
576
Corentin Walleze0902642014-11-04 12:32:15 -0800577 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
578 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
579 // - All other stencil formats (all depth-stencil) are either float or normalized
580 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
581 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
582 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, DepthStencilFormat(0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800583
584 // From GL_ANGLE_lossy_etc_decode
585 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_OES, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
586
Vincent Lang25ab4512016-05-13 18:13:59 +0200587 // From GL_EXT_texture_norm16
588 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
589 map.insert(InternalFormatInfoPair(GL_R16_EXT, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
590 map.insert(InternalFormatInfoPair(GL_R16_SNORM_EXT, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
591 map.insert(InternalFormatInfoPair(GL_RG16_EXT, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
592 map.insert(InternalFormatInfoPair(GL_RG16_SNORM_EXT, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
593 map.insert(InternalFormatInfoPair(GL_RGB16_EXT, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
594 map.insert(InternalFormatInfoPair(GL_RGB16_SNORM_EXT, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
595 map.insert(InternalFormatInfoPair(GL_RGBA16_EXT, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported)));
596 map.insert(InternalFormatInfoPair(GL_RGBA16_SNORM_EXT, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported)));
597
Geoff Lang9bbad182015-09-04 11:07:29 -0400598 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800599
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000600 return map;
601}
602
Geoff Lange4a492b2014-06-19 14:14:41 -0400603static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000604{
Geoff Lange4a492b2014-06-19 14:14:41 -0400605 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
606 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000607}
608
Geoff Lange4a492b2014-06-19 14:14:41 -0400609static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400610{
611 FormatSet result;
612
Geoff Lange4a492b2014-06-19 14:14:41 -0400613 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400614 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
615 {
Geoff Lang5d601382014-07-22 15:14:06 -0400616 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400617 {
618 result.insert(i->first);
619 }
620 }
621
622 return result;
623}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000624
Geoff Lang5d601382014-07-22 15:14:06 -0400625const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000626{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200627 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000628 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200629 case GL_UNSIGNED_BYTE:
630 case GL_BYTE:
631 {
632 static const Type info = GenTypeInfo(1, false);
633 return info;
634 }
635 case GL_UNSIGNED_SHORT:
636 case GL_SHORT:
637 case GL_HALF_FLOAT:
638 case GL_HALF_FLOAT_OES:
639 {
640 static const Type info = GenTypeInfo(2, false);
641 return info;
642 }
643 case GL_UNSIGNED_INT:
644 case GL_INT:
645 case GL_FLOAT:
646 {
647 static const Type info = GenTypeInfo(4, false);
648 return info;
649 }
650 case GL_UNSIGNED_SHORT_5_6_5:
651 case GL_UNSIGNED_SHORT_4_4_4_4:
652 case GL_UNSIGNED_SHORT_5_5_5_1:
653 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
654 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
655 {
656 static const Type info = GenTypeInfo(2, true);
657 return info;
658 }
659 case GL_UNSIGNED_INT_2_10_10_10_REV:
660 case GL_UNSIGNED_INT_24_8:
661 case GL_UNSIGNED_INT_10F_11F_11F_REV:
662 case GL_UNSIGNED_INT_5_9_9_9_REV:
663 {
664 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
665 static const Type info = GenTypeInfo(4, true);
666 return info;
667 }
668 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
669 {
670 static const Type info = GenTypeInfo(8, true);
671 return info;
672 }
673 default:
674 {
675 static const Type defaultInfo;
676 return defaultInfo;
677 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000678 }
679}
680
Geoff Lang5d601382014-07-22 15:14:06 -0400681const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000682{
Geoff Lang5d601382014-07-22 15:14:06 -0400683 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
684 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
685 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000686 {
Geoff Lang5d601382014-07-22 15:14:06 -0400687 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000688 }
689 else
690 {
Geoff Lang5d601382014-07-22 15:14:06 -0400691 static const InternalFormat defaultInternalFormat;
692 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000693 }
694}
695
Jamie Madille2e406c2016-06-02 13:04:10 -0400696gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
697 GLsizei width,
698 GLint alignment,
699 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000700{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700701 // Compressed images do not use pack/unpack parameters.
702 if (compressed)
703 {
704 ASSERT(rowLength == 0);
705 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
706 }
707
708 CheckedNumeric<GLuint> checkedRowBytes(0);
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800709 if (rowLength > 0)
710 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700711 CheckedNumeric<GLuint> checkePixelBytes(pixelBytes);
712 checkedRowBytes = checkePixelBytes * rowLength;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800713 }
714 else
715 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700716 CheckedNumeric<GLuint> checkedWidth(width);
717 const auto &typeInfo = GetTypeInfo(formatType);
718 CheckedNumeric<GLuint> checkedComponents(typeInfo.specialInterpretation ? 1u
719 : componentCount);
720 CheckedNumeric<GLuint> checkedTypeBytes(typeInfo.bytes);
721 checkedRowBytes = checkedWidth * checkedComponents * checkedTypeBytes;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800722 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700723
724 ASSERT(alignment > 0 && isPow2(alignment));
725 CheckedNumeric<GLuint> checkedAlignment(alignment);
726 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
727 ANGLE_TRY_CHECKED_MATH(aligned);
728 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000729}
730
Jamie Madille2e406c2016-06-02 13:04:10 -0400731gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
732 GLsizei width,
733 GLsizei height,
734 GLint alignment,
735 GLint rowLength,
736 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700738 GLuint rows =
739 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400740 GLuint rowPitch = 0;
741 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
742
743 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
744 auto depthPitch = checkedRowPitch * rows;
745 ANGLE_TRY_CHECKED_MATH(depthPitch);
746 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000747}
748
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700749gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
750 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000751{
Jamie Madill513558d2016-06-02 13:04:11 -0400752 CheckedNumeric<GLuint> checkedWidth(size.width);
753 CheckedNumeric<GLuint> checkedHeight(size.height);
754 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700755 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
756 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400757
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700758 ASSERT(compressed);
759 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
760 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
761 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
762 ANGLE_TRY_CHECKED_MATH(bytes);
763 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000764}
765
Olli Etuaho989cac32016-06-08 16:18:49 -0700766gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
767 GLuint depthPitch,
768 GLint skipImages,
769 GLint skipRows,
770 GLint skipPixels,
771 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400772{
Olli Etuaho989cac32016-06-08 16:18:49 -0700773 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
774 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
775 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
776 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
777 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
778 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
779 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
780 if (!applySkipImages)
781 {
782 checkedSkipImagesBytes = 0;
783 }
784 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
785 checkedSkipPixels * checkedPixelBytes;
786 ANGLE_TRY_CHECKED_MATH(skipBytes);
787 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400788}
789
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700790gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
791 GLenum formatType,
792 const gl::Extents &size,
793 const gl::PixelUnpackState &unpack) const
794{
795 // Compressed images do not use unpack parameters.
796 if (compressed)
797 {
798 return computeCompressedImageSize(formatType, size);
799 }
800
801 base::CheckedNumeric<GLuint> checkedGroups(unpack.rowLength > 0 ? unpack.rowLength
802 : size.width);
803 base::CheckedNumeric<GLuint> checkedRows(unpack.imageHeight > 0 ? unpack.imageHeight
804 : size.height);
805
806 // Compute the groups of all the layers in (0,depth-1)
807 auto layerGroups = checkedGroups * checkedRows * (size.depth - 1);
808
809 // Compute the groups in the last layer (for non-3D textures, the only one)
810 auto lastLayerGroups = checkedGroups * (size.height - 1) + size.width;
811
812 // The total size is the sum times the bytes per pixel.
813 auto totalSize = (layerGroups + lastLayerGroups) * pixelBytes;
814
815 ANGLE_TRY_CHECKED_MATH(totalSize);
816
817 return totalSize.ValueOrDie();
818}
819
Geoff Lang5d601382014-07-22 15:14:06 -0400820GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000821{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700822 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500823 if (formatInfo.pixelBytes > 0)
824 {
825 return internalFormat;
826 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700827
828 static const FormatMap formatMap = BuildFormatMap();
Jamie Madilld2b50a02016-06-09 00:13:35 -0700829 auto iter = formatMap.find(FormatType(internalFormat, type));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700830 if (iter != formatMap.end())
Geoff Lang051dbc72015-01-05 15:48:58 -0500831 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700832 return iter->second;
Geoff Lang051dbc72015-01-05 15:48:58 -0500833 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700834
835 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000836}
837
Geoff Lange4a492b2014-06-19 14:14:41 -0400838const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400839{
Geoff Lange4a492b2014-06-19 14:14:41 -0400840 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400841 return formatSet;
842}
843
Jamie Madill09e2d932015-07-14 16:40:31 -0400844AttributeType GetAttributeType(GLenum enumValue)
845{
846 switch (enumValue)
847 {
848 case GL_FLOAT:
849 return ATTRIBUTE_FLOAT;
850 case GL_FLOAT_VEC2:
851 return ATTRIBUTE_VEC2;
852 case GL_FLOAT_VEC3:
853 return ATTRIBUTE_VEC3;
854 case GL_FLOAT_VEC4:
855 return ATTRIBUTE_VEC4;
856 case GL_INT:
857 return ATTRIBUTE_INT;
858 case GL_INT_VEC2:
859 return ATTRIBUTE_IVEC2;
860 case GL_INT_VEC3:
861 return ATTRIBUTE_IVEC3;
862 case GL_INT_VEC4:
863 return ATTRIBUTE_IVEC4;
864 case GL_UNSIGNED_INT:
865 return ATTRIBUTE_UINT;
866 case GL_UNSIGNED_INT_VEC2:
867 return ATTRIBUTE_UVEC2;
868 case GL_UNSIGNED_INT_VEC3:
869 return ATTRIBUTE_UVEC3;
870 case GL_UNSIGNED_INT_VEC4:
871 return ATTRIBUTE_UVEC4;
872 case GL_FLOAT_MAT2:
873 return ATTRIBUTE_MAT2;
874 case GL_FLOAT_MAT3:
875 return ATTRIBUTE_MAT3;
876 case GL_FLOAT_MAT4:
877 return ATTRIBUTE_MAT4;
878 case GL_FLOAT_MAT2x3:
879 return ATTRIBUTE_MAT2x3;
880 case GL_FLOAT_MAT2x4:
881 return ATTRIBUTE_MAT2x4;
882 case GL_FLOAT_MAT3x2:
883 return ATTRIBUTE_MAT3x2;
884 case GL_FLOAT_MAT3x4:
885 return ATTRIBUTE_MAT3x4;
886 case GL_FLOAT_MAT4x2:
887 return ATTRIBUTE_MAT4x2;
888 case GL_FLOAT_MAT4x3:
889 return ATTRIBUTE_MAT4x3;
890 default:
891 UNREACHABLE();
892 return ATTRIBUTE_FLOAT;
893 }
894}
895
Jamie Madilld3dfda22015-07-06 08:28:49 -0400896VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
897{
898 switch (type)
899 {
900 case GL_BYTE:
901 switch (components)
902 {
903 case 1:
904 if (pureInteger)
905 return VERTEX_FORMAT_SBYTE1_INT;
906 if (normalized)
907 return VERTEX_FORMAT_SBYTE1_NORM;
908 return VERTEX_FORMAT_SBYTE1;
909 case 2:
910 if (pureInteger)
911 return VERTEX_FORMAT_SBYTE2_INT;
912 if (normalized)
913 return VERTEX_FORMAT_SBYTE2_NORM;
914 return VERTEX_FORMAT_SBYTE2;
915 case 3:
916 if (pureInteger)
917 return VERTEX_FORMAT_SBYTE3_INT;
918 if (normalized)
919 return VERTEX_FORMAT_SBYTE3_NORM;
920 return VERTEX_FORMAT_SBYTE3;
921 case 4:
922 if (pureInteger)
923 return VERTEX_FORMAT_SBYTE4_INT;
924 if (normalized)
925 return VERTEX_FORMAT_SBYTE4_NORM;
926 return VERTEX_FORMAT_SBYTE4;
927 default:
928 UNREACHABLE();
929 break;
930 }
931 case GL_UNSIGNED_BYTE:
932 switch (components)
933 {
934 case 1:
935 if (pureInteger)
936 return VERTEX_FORMAT_UBYTE1_INT;
937 if (normalized)
938 return VERTEX_FORMAT_UBYTE1_NORM;
939 return VERTEX_FORMAT_UBYTE1;
940 case 2:
941 if (pureInteger)
942 return VERTEX_FORMAT_UBYTE2_INT;
943 if (normalized)
944 return VERTEX_FORMAT_UBYTE2_NORM;
945 return VERTEX_FORMAT_UBYTE2;
946 case 3:
947 if (pureInteger)
948 return VERTEX_FORMAT_UBYTE3_INT;
949 if (normalized)
950 return VERTEX_FORMAT_UBYTE3_NORM;
951 return VERTEX_FORMAT_UBYTE3;
952 case 4:
953 if (pureInteger)
954 return VERTEX_FORMAT_UBYTE4_INT;
955 if (normalized)
956 return VERTEX_FORMAT_UBYTE4_NORM;
957 return VERTEX_FORMAT_UBYTE4;
958 default:
959 UNREACHABLE();
960 break;
961 }
962 case GL_SHORT:
963 switch (components)
964 {
965 case 1:
966 if (pureInteger)
967 return VERTEX_FORMAT_SSHORT1_INT;
968 if (normalized)
969 return VERTEX_FORMAT_SSHORT1_NORM;
970 return VERTEX_FORMAT_SSHORT1;
971 case 2:
972 if (pureInteger)
973 return VERTEX_FORMAT_SSHORT2_INT;
974 if (normalized)
975 return VERTEX_FORMAT_SSHORT2_NORM;
976 return VERTEX_FORMAT_SSHORT2;
977 case 3:
978 if (pureInteger)
979 return VERTEX_FORMAT_SSHORT3_INT;
980 if (normalized)
981 return VERTEX_FORMAT_SSHORT3_NORM;
982 return VERTEX_FORMAT_SSHORT3;
983 case 4:
984 if (pureInteger)
985 return VERTEX_FORMAT_SSHORT4_INT;
986 if (normalized)
987 return VERTEX_FORMAT_SSHORT4_NORM;
988 return VERTEX_FORMAT_SSHORT4;
989 default:
990 UNREACHABLE();
991 break;
992 }
993 case GL_UNSIGNED_SHORT:
994 switch (components)
995 {
996 case 1:
997 if (pureInteger)
998 return VERTEX_FORMAT_USHORT1_INT;
999 if (normalized)
1000 return VERTEX_FORMAT_USHORT1_NORM;
1001 return VERTEX_FORMAT_USHORT1;
1002 case 2:
1003 if (pureInteger)
1004 return VERTEX_FORMAT_USHORT2_INT;
1005 if (normalized)
1006 return VERTEX_FORMAT_USHORT2_NORM;
1007 return VERTEX_FORMAT_USHORT2;
1008 case 3:
1009 if (pureInteger)
1010 return VERTEX_FORMAT_USHORT3_INT;
1011 if (normalized)
1012 return VERTEX_FORMAT_USHORT3_NORM;
1013 return VERTEX_FORMAT_USHORT3;
1014 case 4:
1015 if (pureInteger)
1016 return VERTEX_FORMAT_USHORT4_INT;
1017 if (normalized)
1018 return VERTEX_FORMAT_USHORT4_NORM;
1019 return VERTEX_FORMAT_USHORT4;
1020 default:
1021 UNREACHABLE();
1022 break;
1023 }
1024 case GL_INT:
1025 switch (components)
1026 {
1027 case 1:
1028 if (pureInteger)
1029 return VERTEX_FORMAT_SINT1_INT;
1030 if (normalized)
1031 return VERTEX_FORMAT_SINT1_NORM;
1032 return VERTEX_FORMAT_SINT1;
1033 case 2:
1034 if (pureInteger)
1035 return VERTEX_FORMAT_SINT2_INT;
1036 if (normalized)
1037 return VERTEX_FORMAT_SINT2_NORM;
1038 return VERTEX_FORMAT_SINT2;
1039 case 3:
1040 if (pureInteger)
1041 return VERTEX_FORMAT_SINT3_INT;
1042 if (normalized)
1043 return VERTEX_FORMAT_SINT3_NORM;
1044 return VERTEX_FORMAT_SINT3;
1045 case 4:
1046 if (pureInteger)
1047 return VERTEX_FORMAT_SINT4_INT;
1048 if (normalized)
1049 return VERTEX_FORMAT_SINT4_NORM;
1050 return VERTEX_FORMAT_SINT4;
1051 default:
1052 UNREACHABLE();
1053 break;
1054 }
1055 case GL_UNSIGNED_INT:
1056 switch (components)
1057 {
1058 case 1:
1059 if (pureInteger)
1060 return VERTEX_FORMAT_UINT1_INT;
1061 if (normalized)
1062 return VERTEX_FORMAT_UINT1_NORM;
1063 return VERTEX_FORMAT_UINT1;
1064 case 2:
1065 if (pureInteger)
1066 return VERTEX_FORMAT_UINT2_INT;
1067 if (normalized)
1068 return VERTEX_FORMAT_UINT2_NORM;
1069 return VERTEX_FORMAT_UINT2;
1070 case 3:
1071 if (pureInteger)
1072 return VERTEX_FORMAT_UINT3_INT;
1073 if (normalized)
1074 return VERTEX_FORMAT_UINT3_NORM;
1075 return VERTEX_FORMAT_UINT3;
1076 case 4:
1077 if (pureInteger)
1078 return VERTEX_FORMAT_UINT4_INT;
1079 if (normalized)
1080 return VERTEX_FORMAT_UINT4_NORM;
1081 return VERTEX_FORMAT_UINT4;
1082 default:
1083 UNREACHABLE();
1084 break;
1085 }
1086 case GL_FLOAT:
1087 switch (components)
1088 {
1089 case 1:
1090 return VERTEX_FORMAT_FLOAT1;
1091 case 2:
1092 return VERTEX_FORMAT_FLOAT2;
1093 case 3:
1094 return VERTEX_FORMAT_FLOAT3;
1095 case 4:
1096 return VERTEX_FORMAT_FLOAT4;
1097 default:
1098 UNREACHABLE();
1099 break;
1100 }
1101 case GL_HALF_FLOAT:
1102 switch (components)
1103 {
1104 case 1:
1105 return VERTEX_FORMAT_HALF1;
1106 case 2:
1107 return VERTEX_FORMAT_HALF2;
1108 case 3:
1109 return VERTEX_FORMAT_HALF3;
1110 case 4:
1111 return VERTEX_FORMAT_HALF4;
1112 default:
1113 UNREACHABLE();
1114 break;
1115 }
1116 case GL_FIXED:
1117 switch (components)
1118 {
1119 case 1:
1120 return VERTEX_FORMAT_FIXED1;
1121 case 2:
1122 return VERTEX_FORMAT_FIXED2;
1123 case 3:
1124 return VERTEX_FORMAT_FIXED3;
1125 case 4:
1126 return VERTEX_FORMAT_FIXED4;
1127 default:
1128 UNREACHABLE();
1129 break;
1130 }
1131 case GL_INT_2_10_10_10_REV:
1132 if (pureInteger)
1133 return VERTEX_FORMAT_SINT210_INT;
1134 if (normalized)
1135 return VERTEX_FORMAT_SINT210_NORM;
1136 return VERTEX_FORMAT_SINT210;
1137 case GL_UNSIGNED_INT_2_10_10_10_REV:
1138 if (pureInteger)
1139 return VERTEX_FORMAT_UINT210_INT;
1140 if (normalized)
1141 return VERTEX_FORMAT_UINT210_NORM;
1142 return VERTEX_FORMAT_UINT210;
1143 default:
1144 UNREACHABLE();
1145 break;
1146 }
1147 return VERTEX_FORMAT_UBYTE1;
1148}
1149
1150VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1151{
1152 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1153}
1154
1155VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1156{
1157 if (!attrib.enabled)
1158 {
1159 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1160 }
1161 return GetVertexFormatType(attrib);
1162}
1163
1164const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1165{
1166 switch (vertexFormatType)
1167 {
1168 case VERTEX_FORMAT_SBYTE1:
1169 {
1170 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1171 return format;
1172 }
1173 case VERTEX_FORMAT_SBYTE1_NORM:
1174 {
1175 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1176 return format;
1177 }
1178 case VERTEX_FORMAT_SBYTE2:
1179 {
1180 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1181 return format;
1182 }
1183 case VERTEX_FORMAT_SBYTE2_NORM:
1184 {
1185 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1186 return format;
1187 }
1188 case VERTEX_FORMAT_SBYTE3:
1189 {
1190 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1191 return format;
1192 }
1193 case VERTEX_FORMAT_SBYTE3_NORM:
1194 {
1195 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1196 return format;
1197 }
1198 case VERTEX_FORMAT_SBYTE4:
1199 {
1200 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1201 return format;
1202 }
1203 case VERTEX_FORMAT_SBYTE4_NORM:
1204 {
1205 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1206 return format;
1207 }
1208 case VERTEX_FORMAT_UBYTE1:
1209 {
1210 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1211 return format;
1212 }
1213 case VERTEX_FORMAT_UBYTE1_NORM:
1214 {
1215 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1216 return format;
1217 }
1218 case VERTEX_FORMAT_UBYTE2:
1219 {
1220 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1221 return format;
1222 }
1223 case VERTEX_FORMAT_UBYTE2_NORM:
1224 {
1225 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1226 return format;
1227 }
1228 case VERTEX_FORMAT_UBYTE3:
1229 {
1230 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1231 return format;
1232 }
1233 case VERTEX_FORMAT_UBYTE3_NORM:
1234 {
1235 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1236 return format;
1237 }
1238 case VERTEX_FORMAT_UBYTE4:
1239 {
1240 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1241 return format;
1242 }
1243 case VERTEX_FORMAT_UBYTE4_NORM:
1244 {
1245 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1246 return format;
1247 }
1248 case VERTEX_FORMAT_SSHORT1:
1249 {
1250 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1251 return format;
1252 }
1253 case VERTEX_FORMAT_SSHORT1_NORM:
1254 {
1255 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1256 return format;
1257 }
1258 case VERTEX_FORMAT_SSHORT2:
1259 {
1260 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1261 return format;
1262 }
1263 case VERTEX_FORMAT_SSHORT2_NORM:
1264 {
1265 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1266 return format;
1267 }
1268 case VERTEX_FORMAT_SSHORT3:
1269 {
1270 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1271 return format;
1272 }
1273 case VERTEX_FORMAT_SSHORT3_NORM:
1274 {
1275 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1276 return format;
1277 }
1278 case VERTEX_FORMAT_SSHORT4:
1279 {
1280 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1281 return format;
1282 }
1283 case VERTEX_FORMAT_SSHORT4_NORM:
1284 {
1285 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1286 return format;
1287 }
1288 case VERTEX_FORMAT_USHORT1:
1289 {
1290 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1291 return format;
1292 }
1293 case VERTEX_FORMAT_USHORT1_NORM:
1294 {
1295 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1296 return format;
1297 }
1298 case VERTEX_FORMAT_USHORT2:
1299 {
1300 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1301 return format;
1302 }
1303 case VERTEX_FORMAT_USHORT2_NORM:
1304 {
1305 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1306 return format;
1307 }
1308 case VERTEX_FORMAT_USHORT3:
1309 {
1310 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1311 return format;
1312 }
1313 case VERTEX_FORMAT_USHORT3_NORM:
1314 {
1315 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1316 return format;
1317 }
1318 case VERTEX_FORMAT_USHORT4:
1319 {
1320 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1321 return format;
1322 }
1323 case VERTEX_FORMAT_USHORT4_NORM:
1324 {
1325 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1326 return format;
1327 }
1328 case VERTEX_FORMAT_SINT1:
1329 {
1330 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1331 return format;
1332 }
1333 case VERTEX_FORMAT_SINT1_NORM:
1334 {
1335 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1336 return format;
1337 }
1338 case VERTEX_FORMAT_SINT2:
1339 {
1340 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1341 return format;
1342 }
1343 case VERTEX_FORMAT_SINT2_NORM:
1344 {
1345 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1346 return format;
1347 }
1348 case VERTEX_FORMAT_SINT3:
1349 {
1350 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1351 return format;
1352 }
1353 case VERTEX_FORMAT_SINT3_NORM:
1354 {
1355 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1356 return format;
1357 }
1358 case VERTEX_FORMAT_SINT4:
1359 {
1360 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1361 return format;
1362 }
1363 case VERTEX_FORMAT_SINT4_NORM:
1364 {
1365 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1366 return format;
1367 }
1368 case VERTEX_FORMAT_UINT1:
1369 {
1370 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1371 return format;
1372 }
1373 case VERTEX_FORMAT_UINT1_NORM:
1374 {
1375 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1376 return format;
1377 }
1378 case VERTEX_FORMAT_UINT2:
1379 {
1380 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1381 return format;
1382 }
1383 case VERTEX_FORMAT_UINT2_NORM:
1384 {
1385 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1386 return format;
1387 }
1388 case VERTEX_FORMAT_UINT3:
1389 {
1390 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1391 return format;
1392 }
1393 case VERTEX_FORMAT_UINT3_NORM:
1394 {
1395 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1396 return format;
1397 }
1398 case VERTEX_FORMAT_UINT4:
1399 {
1400 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1401 return format;
1402 }
1403 case VERTEX_FORMAT_UINT4_NORM:
1404 {
1405 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1406 return format;
1407 }
1408 case VERTEX_FORMAT_SBYTE1_INT:
1409 {
1410 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1411 return format;
1412 }
1413 case VERTEX_FORMAT_SBYTE2_INT:
1414 {
1415 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1416 return format;
1417 }
1418 case VERTEX_FORMAT_SBYTE3_INT:
1419 {
1420 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1421 return format;
1422 }
1423 case VERTEX_FORMAT_SBYTE4_INT:
1424 {
1425 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1426 return format;
1427 }
1428 case VERTEX_FORMAT_UBYTE1_INT:
1429 {
1430 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1431 return format;
1432 }
1433 case VERTEX_FORMAT_UBYTE2_INT:
1434 {
1435 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1436 return format;
1437 }
1438 case VERTEX_FORMAT_UBYTE3_INT:
1439 {
1440 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1441 return format;
1442 }
1443 case VERTEX_FORMAT_UBYTE4_INT:
1444 {
1445 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1446 return format;
1447 }
1448 case VERTEX_FORMAT_SSHORT1_INT:
1449 {
1450 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1451 return format;
1452 }
1453 case VERTEX_FORMAT_SSHORT2_INT:
1454 {
1455 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1456 return format;
1457 }
1458 case VERTEX_FORMAT_SSHORT3_INT:
1459 {
1460 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1461 return format;
1462 }
1463 case VERTEX_FORMAT_SSHORT4_INT:
1464 {
1465 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1466 return format;
1467 }
1468 case VERTEX_FORMAT_USHORT1_INT:
1469 {
1470 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1471 return format;
1472 }
1473 case VERTEX_FORMAT_USHORT2_INT:
1474 {
1475 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1476 return format;
1477 }
1478 case VERTEX_FORMAT_USHORT3_INT:
1479 {
1480 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1481 return format;
1482 }
1483 case VERTEX_FORMAT_USHORT4_INT:
1484 {
1485 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1486 return format;
1487 }
1488 case VERTEX_FORMAT_SINT1_INT:
1489 {
1490 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1491 return format;
1492 }
1493 case VERTEX_FORMAT_SINT2_INT:
1494 {
1495 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1496 return format;
1497 }
1498 case VERTEX_FORMAT_SINT3_INT:
1499 {
1500 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1501 return format;
1502 }
1503 case VERTEX_FORMAT_SINT4_INT:
1504 {
1505 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1506 return format;
1507 }
1508 case VERTEX_FORMAT_UINT1_INT:
1509 {
1510 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1511 return format;
1512 }
1513 case VERTEX_FORMAT_UINT2_INT:
1514 {
1515 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1516 return format;
1517 }
1518 case VERTEX_FORMAT_UINT3_INT:
1519 {
1520 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1521 return format;
1522 }
1523 case VERTEX_FORMAT_UINT4_INT:
1524 {
1525 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1526 return format;
1527 }
1528 case VERTEX_FORMAT_FIXED1:
1529 {
1530 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1531 return format;
1532 }
1533 case VERTEX_FORMAT_FIXED2:
1534 {
1535 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1536 return format;
1537 }
1538 case VERTEX_FORMAT_FIXED3:
1539 {
1540 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1541 return format;
1542 }
1543 case VERTEX_FORMAT_FIXED4:
1544 {
1545 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1546 return format;
1547 }
1548 case VERTEX_FORMAT_HALF1:
1549 {
1550 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1551 return format;
1552 }
1553 case VERTEX_FORMAT_HALF2:
1554 {
1555 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1556 return format;
1557 }
1558 case VERTEX_FORMAT_HALF3:
1559 {
1560 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1561 return format;
1562 }
1563 case VERTEX_FORMAT_HALF4:
1564 {
1565 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1566 return format;
1567 }
1568 case VERTEX_FORMAT_FLOAT1:
1569 {
1570 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1571 return format;
1572 }
1573 case VERTEX_FORMAT_FLOAT2:
1574 {
1575 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1576 return format;
1577 }
1578 case VERTEX_FORMAT_FLOAT3:
1579 {
1580 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1581 return format;
1582 }
1583 case VERTEX_FORMAT_FLOAT4:
1584 {
1585 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1586 return format;
1587 }
1588 case VERTEX_FORMAT_SINT210:
1589 {
1590 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1591 return format;
1592 }
1593 case VERTEX_FORMAT_UINT210:
1594 {
1595 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1596 return format;
1597 }
1598 case VERTEX_FORMAT_SINT210_NORM:
1599 {
1600 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1601 return format;
1602 }
1603 case VERTEX_FORMAT_UINT210_NORM:
1604 {
1605 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1606 return format;
1607 }
1608 case VERTEX_FORMAT_SINT210_INT:
1609 {
1610 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1611 return format;
1612 }
1613 case VERTEX_FORMAT_UINT210_INT:
1614 {
1615 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1616 return format;
1617 }
1618 default:
1619 {
1620 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1621 return format;
1622 }
1623 }
1624}
1625
1626VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1627 : type(typeIn),
1628 normalized(normalizedIn),
1629 components(componentsIn),
1630 pureInteger(pureIntegerIn)
1631{
1632 // float -> !normalized
1633 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1634}
1635
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001636}