blob: 3fd42d373a28d1ab6b61991daa82c64c70f983b0 [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
Jamie Madillec0b5802016-07-04 13:11:59 -0400465 // Special format which is not really supported, so always false for all supports.
466 map.insert(InternalFormatInfoPair(GL_BGR565_ANGLEX, RGBAFormat( 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported)));
467
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000468 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500469 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
470 // | | | | | | | type | | | | |
471 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
472 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
473 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
474 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
475 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
476 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
477 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
478 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 +0000479
480 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400481 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
482 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>)));
483 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>)));
484 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 -0500485 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 -0400486 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 )));
487 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 -0800488 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000489
490 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400491 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400492 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
493 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
494 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
495 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
496 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
497 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
498 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
499 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
500 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 +0000501
502 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400503 // | Internal format | | Format | Supported | Renderable | Filterable |
504 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
505 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
506 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
507 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
508 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
509 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
510 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
511 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
512 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
513 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
514 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
515 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
516 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
517 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
518 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
519 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 +0000520
521 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400522 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
523 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
524 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)));
525 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
526 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)));
527 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
528 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
529 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)));
530 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)));
531 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)));
532 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 +0000533
534 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400535 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
536 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)));
537 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 +0000538
539 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400540 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 +0000541
542 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400543 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)));
544
545 // From GL_OES_compressed_ETC1_RGB8_texture
546 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 +0000547
Geoff Lang60ad73d2015-10-23 10:08:44 -0400548 // From KHR_texture_compression_astc_hdr
549 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
550 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)));
551 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)));
552 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)));
553 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)));
554 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)));
555 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)));
556 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)));
557 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)));
558 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)));
559 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)));
560 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)));
561 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)));
562 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)));
563 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)));
564
565 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)));
566 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)));
567 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)));
568 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)));
569 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)));
570 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)));
571 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)));
572 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)));
573 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)));
574 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)));
575 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)));
576 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)));
577 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)));
578 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)));
579
Corentin Walleze0902642014-11-04 12:32:15 -0800580 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
581 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
582 // - All other stencil formats (all depth-stencil) are either float or normalized
583 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
584 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
585 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 -0800586
587 // From GL_ANGLE_lossy_etc_decode
588 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)));
589
Vincent Lang25ab4512016-05-13 18:13:59 +0200590 // From GL_EXT_texture_norm16
591 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
592 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)));
593 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)));
594 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)));
595 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)));
596 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)));
597 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)));
598 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)));
599 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)));
600
Geoff Lang9bbad182015-09-04 11:07:29 -0400601 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800602
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000603 return map;
604}
605
Geoff Lange4a492b2014-06-19 14:14:41 -0400606static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000607{
Geoff Lange4a492b2014-06-19 14:14:41 -0400608 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
609 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000610}
611
Geoff Lange4a492b2014-06-19 14:14:41 -0400612static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400613{
614 FormatSet result;
615
Jamie Madillec0b5802016-07-04 13:11:59 -0400616 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400617 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400618 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400619 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400620 // TODO(jmadill): Fix this hack.
621 if (iter.first == GL_BGR565_ANGLEX)
622 continue;
623
624 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400625 }
626 }
627
628 return result;
629}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000630
Geoff Lang5d601382014-07-22 15:14:06 -0400631const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000632{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200633 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000634 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200635 case GL_UNSIGNED_BYTE:
636 case GL_BYTE:
637 {
638 static const Type info = GenTypeInfo(1, false);
639 return info;
640 }
641 case GL_UNSIGNED_SHORT:
642 case GL_SHORT:
643 case GL_HALF_FLOAT:
644 case GL_HALF_FLOAT_OES:
645 {
646 static const Type info = GenTypeInfo(2, false);
647 return info;
648 }
649 case GL_UNSIGNED_INT:
650 case GL_INT:
651 case GL_FLOAT:
652 {
653 static const Type info = GenTypeInfo(4, false);
654 return info;
655 }
656 case GL_UNSIGNED_SHORT_5_6_5:
657 case GL_UNSIGNED_SHORT_4_4_4_4:
658 case GL_UNSIGNED_SHORT_5_5_5_1:
659 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
660 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
661 {
662 static const Type info = GenTypeInfo(2, true);
663 return info;
664 }
665 case GL_UNSIGNED_INT_2_10_10_10_REV:
666 case GL_UNSIGNED_INT_24_8:
667 case GL_UNSIGNED_INT_10F_11F_11F_REV:
668 case GL_UNSIGNED_INT_5_9_9_9_REV:
669 {
670 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
671 static const Type info = GenTypeInfo(4, true);
672 return info;
673 }
674 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
675 {
676 static const Type info = GenTypeInfo(8, true);
677 return info;
678 }
679 default:
680 {
681 static const Type defaultInfo;
682 return defaultInfo;
683 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000684 }
685}
686
Geoff Lang5d601382014-07-22 15:14:06 -0400687const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000688{
Geoff Lang5d601382014-07-22 15:14:06 -0400689 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400690 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400691 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000692 {
Geoff Lang5d601382014-07-22 15:14:06 -0400693 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000694 }
695 else
696 {
Geoff Lang5d601382014-07-22 15:14:06 -0400697 static const InternalFormat defaultInternalFormat;
Jamie Madillec0b5802016-07-04 13:11:59 -0400698 UNREACHABLE();
Geoff Lang5d601382014-07-22 15:14:06 -0400699 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000700 }
701}
702
Jamie Madille2e406c2016-06-02 13:04:10 -0400703gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
704 GLsizei width,
705 GLint alignment,
706 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700708 // Compressed images do not use pack/unpack parameters.
709 if (compressed)
710 {
711 ASSERT(rowLength == 0);
712 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
713 }
714
715 CheckedNumeric<GLuint> checkedRowBytes(0);
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800716 if (rowLength > 0)
717 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700718 CheckedNumeric<GLuint> checkePixelBytes(pixelBytes);
719 checkedRowBytes = checkePixelBytes * rowLength;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800720 }
721 else
722 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700723 CheckedNumeric<GLuint> checkedWidth(width);
724 const auto &typeInfo = GetTypeInfo(formatType);
725 CheckedNumeric<GLuint> checkedComponents(typeInfo.specialInterpretation ? 1u
726 : componentCount);
727 CheckedNumeric<GLuint> checkedTypeBytes(typeInfo.bytes);
728 checkedRowBytes = checkedWidth * checkedComponents * checkedTypeBytes;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800729 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700730
731 ASSERT(alignment > 0 && isPow2(alignment));
732 CheckedNumeric<GLuint> checkedAlignment(alignment);
733 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
734 ANGLE_TRY_CHECKED_MATH(aligned);
735 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000736}
737
Jamie Madille2e406c2016-06-02 13:04:10 -0400738gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
739 GLsizei width,
740 GLsizei height,
741 GLint alignment,
742 GLint rowLength,
743 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000744{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700745 GLuint rows =
746 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400747 GLuint rowPitch = 0;
748 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
749
750 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
751 auto depthPitch = checkedRowPitch * rows;
752 ANGLE_TRY_CHECKED_MATH(depthPitch);
753 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000754}
755
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700756gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
757 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000758{
Jamie Madill513558d2016-06-02 13:04:11 -0400759 CheckedNumeric<GLuint> checkedWidth(size.width);
760 CheckedNumeric<GLuint> checkedHeight(size.height);
761 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700762 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
763 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400764
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700765 ASSERT(compressed);
766 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
767 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
768 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
769 ANGLE_TRY_CHECKED_MATH(bytes);
770 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000771}
772
Olli Etuaho989cac32016-06-08 16:18:49 -0700773gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
774 GLuint depthPitch,
775 GLint skipImages,
776 GLint skipRows,
777 GLint skipPixels,
778 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400779{
Olli Etuaho989cac32016-06-08 16:18:49 -0700780 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
781 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
782 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
783 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
784 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
785 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
786 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
787 if (!applySkipImages)
788 {
789 checkedSkipImagesBytes = 0;
790 }
791 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
792 checkedSkipPixels * checkedPixelBytes;
793 ANGLE_TRY_CHECKED_MATH(skipBytes);
794 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400795}
796
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700797gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
798 GLenum formatType,
799 const gl::Extents &size,
800 const gl::PixelUnpackState &unpack) const
801{
802 // Compressed images do not use unpack parameters.
803 if (compressed)
804 {
805 return computeCompressedImageSize(formatType, size);
806 }
807
808 base::CheckedNumeric<GLuint> checkedGroups(unpack.rowLength > 0 ? unpack.rowLength
809 : size.width);
810 base::CheckedNumeric<GLuint> checkedRows(unpack.imageHeight > 0 ? unpack.imageHeight
811 : size.height);
812
813 // Compute the groups of all the layers in (0,depth-1)
814 auto layerGroups = checkedGroups * checkedRows * (size.depth - 1);
815
816 // Compute the groups in the last layer (for non-3D textures, the only one)
817 auto lastLayerGroups = checkedGroups * (size.height - 1) + size.width;
818
819 // The total size is the sum times the bytes per pixel.
820 auto totalSize = (layerGroups + lastLayerGroups) * pixelBytes;
821
822 ANGLE_TRY_CHECKED_MATH(totalSize);
823
824 return totalSize.ValueOrDie();
825}
826
Geoff Lang5d601382014-07-22 15:14:06 -0400827GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000828{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700829 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500830 if (formatInfo.pixelBytes > 0)
831 {
832 return internalFormat;
833 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700834
835 static const FormatMap formatMap = BuildFormatMap();
Jamie Madilld2b50a02016-06-09 00:13:35 -0700836 auto iter = formatMap.find(FormatType(internalFormat, type));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700837 if (iter != formatMap.end())
Geoff Lang051dbc72015-01-05 15:48:58 -0500838 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700839 return iter->second;
Geoff Lang051dbc72015-01-05 15:48:58 -0500840 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700841
842 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843}
844
Geoff Lange4a492b2014-06-19 14:14:41 -0400845const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400846{
Geoff Lange4a492b2014-06-19 14:14:41 -0400847 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400848 return formatSet;
849}
850
Jamie Madill09e2d932015-07-14 16:40:31 -0400851AttributeType GetAttributeType(GLenum enumValue)
852{
853 switch (enumValue)
854 {
855 case GL_FLOAT:
856 return ATTRIBUTE_FLOAT;
857 case GL_FLOAT_VEC2:
858 return ATTRIBUTE_VEC2;
859 case GL_FLOAT_VEC3:
860 return ATTRIBUTE_VEC3;
861 case GL_FLOAT_VEC4:
862 return ATTRIBUTE_VEC4;
863 case GL_INT:
864 return ATTRIBUTE_INT;
865 case GL_INT_VEC2:
866 return ATTRIBUTE_IVEC2;
867 case GL_INT_VEC3:
868 return ATTRIBUTE_IVEC3;
869 case GL_INT_VEC4:
870 return ATTRIBUTE_IVEC4;
871 case GL_UNSIGNED_INT:
872 return ATTRIBUTE_UINT;
873 case GL_UNSIGNED_INT_VEC2:
874 return ATTRIBUTE_UVEC2;
875 case GL_UNSIGNED_INT_VEC3:
876 return ATTRIBUTE_UVEC3;
877 case GL_UNSIGNED_INT_VEC4:
878 return ATTRIBUTE_UVEC4;
879 case GL_FLOAT_MAT2:
880 return ATTRIBUTE_MAT2;
881 case GL_FLOAT_MAT3:
882 return ATTRIBUTE_MAT3;
883 case GL_FLOAT_MAT4:
884 return ATTRIBUTE_MAT4;
885 case GL_FLOAT_MAT2x3:
886 return ATTRIBUTE_MAT2x3;
887 case GL_FLOAT_MAT2x4:
888 return ATTRIBUTE_MAT2x4;
889 case GL_FLOAT_MAT3x2:
890 return ATTRIBUTE_MAT3x2;
891 case GL_FLOAT_MAT3x4:
892 return ATTRIBUTE_MAT3x4;
893 case GL_FLOAT_MAT4x2:
894 return ATTRIBUTE_MAT4x2;
895 case GL_FLOAT_MAT4x3:
896 return ATTRIBUTE_MAT4x3;
897 default:
898 UNREACHABLE();
899 return ATTRIBUTE_FLOAT;
900 }
901}
902
Jamie Madilld3dfda22015-07-06 08:28:49 -0400903VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
904{
905 switch (type)
906 {
907 case GL_BYTE:
908 switch (components)
909 {
910 case 1:
911 if (pureInteger)
912 return VERTEX_FORMAT_SBYTE1_INT;
913 if (normalized)
914 return VERTEX_FORMAT_SBYTE1_NORM;
915 return VERTEX_FORMAT_SBYTE1;
916 case 2:
917 if (pureInteger)
918 return VERTEX_FORMAT_SBYTE2_INT;
919 if (normalized)
920 return VERTEX_FORMAT_SBYTE2_NORM;
921 return VERTEX_FORMAT_SBYTE2;
922 case 3:
923 if (pureInteger)
924 return VERTEX_FORMAT_SBYTE3_INT;
925 if (normalized)
926 return VERTEX_FORMAT_SBYTE3_NORM;
927 return VERTEX_FORMAT_SBYTE3;
928 case 4:
929 if (pureInteger)
930 return VERTEX_FORMAT_SBYTE4_INT;
931 if (normalized)
932 return VERTEX_FORMAT_SBYTE4_NORM;
933 return VERTEX_FORMAT_SBYTE4;
934 default:
935 UNREACHABLE();
936 break;
937 }
938 case GL_UNSIGNED_BYTE:
939 switch (components)
940 {
941 case 1:
942 if (pureInteger)
943 return VERTEX_FORMAT_UBYTE1_INT;
944 if (normalized)
945 return VERTEX_FORMAT_UBYTE1_NORM;
946 return VERTEX_FORMAT_UBYTE1;
947 case 2:
948 if (pureInteger)
949 return VERTEX_FORMAT_UBYTE2_INT;
950 if (normalized)
951 return VERTEX_FORMAT_UBYTE2_NORM;
952 return VERTEX_FORMAT_UBYTE2;
953 case 3:
954 if (pureInteger)
955 return VERTEX_FORMAT_UBYTE3_INT;
956 if (normalized)
957 return VERTEX_FORMAT_UBYTE3_NORM;
958 return VERTEX_FORMAT_UBYTE3;
959 case 4:
960 if (pureInteger)
961 return VERTEX_FORMAT_UBYTE4_INT;
962 if (normalized)
963 return VERTEX_FORMAT_UBYTE4_NORM;
964 return VERTEX_FORMAT_UBYTE4;
965 default:
966 UNREACHABLE();
967 break;
968 }
969 case GL_SHORT:
970 switch (components)
971 {
972 case 1:
973 if (pureInteger)
974 return VERTEX_FORMAT_SSHORT1_INT;
975 if (normalized)
976 return VERTEX_FORMAT_SSHORT1_NORM;
977 return VERTEX_FORMAT_SSHORT1;
978 case 2:
979 if (pureInteger)
980 return VERTEX_FORMAT_SSHORT2_INT;
981 if (normalized)
982 return VERTEX_FORMAT_SSHORT2_NORM;
983 return VERTEX_FORMAT_SSHORT2;
984 case 3:
985 if (pureInteger)
986 return VERTEX_FORMAT_SSHORT3_INT;
987 if (normalized)
988 return VERTEX_FORMAT_SSHORT3_NORM;
989 return VERTEX_FORMAT_SSHORT3;
990 case 4:
991 if (pureInteger)
992 return VERTEX_FORMAT_SSHORT4_INT;
993 if (normalized)
994 return VERTEX_FORMAT_SSHORT4_NORM;
995 return VERTEX_FORMAT_SSHORT4;
996 default:
997 UNREACHABLE();
998 break;
999 }
1000 case GL_UNSIGNED_SHORT:
1001 switch (components)
1002 {
1003 case 1:
1004 if (pureInteger)
1005 return VERTEX_FORMAT_USHORT1_INT;
1006 if (normalized)
1007 return VERTEX_FORMAT_USHORT1_NORM;
1008 return VERTEX_FORMAT_USHORT1;
1009 case 2:
1010 if (pureInteger)
1011 return VERTEX_FORMAT_USHORT2_INT;
1012 if (normalized)
1013 return VERTEX_FORMAT_USHORT2_NORM;
1014 return VERTEX_FORMAT_USHORT2;
1015 case 3:
1016 if (pureInteger)
1017 return VERTEX_FORMAT_USHORT3_INT;
1018 if (normalized)
1019 return VERTEX_FORMAT_USHORT3_NORM;
1020 return VERTEX_FORMAT_USHORT3;
1021 case 4:
1022 if (pureInteger)
1023 return VERTEX_FORMAT_USHORT4_INT;
1024 if (normalized)
1025 return VERTEX_FORMAT_USHORT4_NORM;
1026 return VERTEX_FORMAT_USHORT4;
1027 default:
1028 UNREACHABLE();
1029 break;
1030 }
1031 case GL_INT:
1032 switch (components)
1033 {
1034 case 1:
1035 if (pureInteger)
1036 return VERTEX_FORMAT_SINT1_INT;
1037 if (normalized)
1038 return VERTEX_FORMAT_SINT1_NORM;
1039 return VERTEX_FORMAT_SINT1;
1040 case 2:
1041 if (pureInteger)
1042 return VERTEX_FORMAT_SINT2_INT;
1043 if (normalized)
1044 return VERTEX_FORMAT_SINT2_NORM;
1045 return VERTEX_FORMAT_SINT2;
1046 case 3:
1047 if (pureInteger)
1048 return VERTEX_FORMAT_SINT3_INT;
1049 if (normalized)
1050 return VERTEX_FORMAT_SINT3_NORM;
1051 return VERTEX_FORMAT_SINT3;
1052 case 4:
1053 if (pureInteger)
1054 return VERTEX_FORMAT_SINT4_INT;
1055 if (normalized)
1056 return VERTEX_FORMAT_SINT4_NORM;
1057 return VERTEX_FORMAT_SINT4;
1058 default:
1059 UNREACHABLE();
1060 break;
1061 }
1062 case GL_UNSIGNED_INT:
1063 switch (components)
1064 {
1065 case 1:
1066 if (pureInteger)
1067 return VERTEX_FORMAT_UINT1_INT;
1068 if (normalized)
1069 return VERTEX_FORMAT_UINT1_NORM;
1070 return VERTEX_FORMAT_UINT1;
1071 case 2:
1072 if (pureInteger)
1073 return VERTEX_FORMAT_UINT2_INT;
1074 if (normalized)
1075 return VERTEX_FORMAT_UINT2_NORM;
1076 return VERTEX_FORMAT_UINT2;
1077 case 3:
1078 if (pureInteger)
1079 return VERTEX_FORMAT_UINT3_INT;
1080 if (normalized)
1081 return VERTEX_FORMAT_UINT3_NORM;
1082 return VERTEX_FORMAT_UINT3;
1083 case 4:
1084 if (pureInteger)
1085 return VERTEX_FORMAT_UINT4_INT;
1086 if (normalized)
1087 return VERTEX_FORMAT_UINT4_NORM;
1088 return VERTEX_FORMAT_UINT4;
1089 default:
1090 UNREACHABLE();
1091 break;
1092 }
1093 case GL_FLOAT:
1094 switch (components)
1095 {
1096 case 1:
1097 return VERTEX_FORMAT_FLOAT1;
1098 case 2:
1099 return VERTEX_FORMAT_FLOAT2;
1100 case 3:
1101 return VERTEX_FORMAT_FLOAT3;
1102 case 4:
1103 return VERTEX_FORMAT_FLOAT4;
1104 default:
1105 UNREACHABLE();
1106 break;
1107 }
1108 case GL_HALF_FLOAT:
1109 switch (components)
1110 {
1111 case 1:
1112 return VERTEX_FORMAT_HALF1;
1113 case 2:
1114 return VERTEX_FORMAT_HALF2;
1115 case 3:
1116 return VERTEX_FORMAT_HALF3;
1117 case 4:
1118 return VERTEX_FORMAT_HALF4;
1119 default:
1120 UNREACHABLE();
1121 break;
1122 }
1123 case GL_FIXED:
1124 switch (components)
1125 {
1126 case 1:
1127 return VERTEX_FORMAT_FIXED1;
1128 case 2:
1129 return VERTEX_FORMAT_FIXED2;
1130 case 3:
1131 return VERTEX_FORMAT_FIXED3;
1132 case 4:
1133 return VERTEX_FORMAT_FIXED4;
1134 default:
1135 UNREACHABLE();
1136 break;
1137 }
1138 case GL_INT_2_10_10_10_REV:
1139 if (pureInteger)
1140 return VERTEX_FORMAT_SINT210_INT;
1141 if (normalized)
1142 return VERTEX_FORMAT_SINT210_NORM;
1143 return VERTEX_FORMAT_SINT210;
1144 case GL_UNSIGNED_INT_2_10_10_10_REV:
1145 if (pureInteger)
1146 return VERTEX_FORMAT_UINT210_INT;
1147 if (normalized)
1148 return VERTEX_FORMAT_UINT210_NORM;
1149 return VERTEX_FORMAT_UINT210;
1150 default:
1151 UNREACHABLE();
1152 break;
1153 }
1154 return VERTEX_FORMAT_UBYTE1;
1155}
1156
1157VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1158{
1159 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1160}
1161
1162VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1163{
1164 if (!attrib.enabled)
1165 {
1166 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1167 }
1168 return GetVertexFormatType(attrib);
1169}
1170
1171const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1172{
1173 switch (vertexFormatType)
1174 {
1175 case VERTEX_FORMAT_SBYTE1:
1176 {
1177 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1178 return format;
1179 }
1180 case VERTEX_FORMAT_SBYTE1_NORM:
1181 {
1182 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1183 return format;
1184 }
1185 case VERTEX_FORMAT_SBYTE2:
1186 {
1187 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1188 return format;
1189 }
1190 case VERTEX_FORMAT_SBYTE2_NORM:
1191 {
1192 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1193 return format;
1194 }
1195 case VERTEX_FORMAT_SBYTE3:
1196 {
1197 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1198 return format;
1199 }
1200 case VERTEX_FORMAT_SBYTE3_NORM:
1201 {
1202 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1203 return format;
1204 }
1205 case VERTEX_FORMAT_SBYTE4:
1206 {
1207 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1208 return format;
1209 }
1210 case VERTEX_FORMAT_SBYTE4_NORM:
1211 {
1212 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1213 return format;
1214 }
1215 case VERTEX_FORMAT_UBYTE1:
1216 {
1217 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1218 return format;
1219 }
1220 case VERTEX_FORMAT_UBYTE1_NORM:
1221 {
1222 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1223 return format;
1224 }
1225 case VERTEX_FORMAT_UBYTE2:
1226 {
1227 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1228 return format;
1229 }
1230 case VERTEX_FORMAT_UBYTE2_NORM:
1231 {
1232 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1233 return format;
1234 }
1235 case VERTEX_FORMAT_UBYTE3:
1236 {
1237 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1238 return format;
1239 }
1240 case VERTEX_FORMAT_UBYTE3_NORM:
1241 {
1242 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1243 return format;
1244 }
1245 case VERTEX_FORMAT_UBYTE4:
1246 {
1247 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1248 return format;
1249 }
1250 case VERTEX_FORMAT_UBYTE4_NORM:
1251 {
1252 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1253 return format;
1254 }
1255 case VERTEX_FORMAT_SSHORT1:
1256 {
1257 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1258 return format;
1259 }
1260 case VERTEX_FORMAT_SSHORT1_NORM:
1261 {
1262 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1263 return format;
1264 }
1265 case VERTEX_FORMAT_SSHORT2:
1266 {
1267 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1268 return format;
1269 }
1270 case VERTEX_FORMAT_SSHORT2_NORM:
1271 {
1272 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1273 return format;
1274 }
1275 case VERTEX_FORMAT_SSHORT3:
1276 {
1277 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1278 return format;
1279 }
1280 case VERTEX_FORMAT_SSHORT3_NORM:
1281 {
1282 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1283 return format;
1284 }
1285 case VERTEX_FORMAT_SSHORT4:
1286 {
1287 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1288 return format;
1289 }
1290 case VERTEX_FORMAT_SSHORT4_NORM:
1291 {
1292 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1293 return format;
1294 }
1295 case VERTEX_FORMAT_USHORT1:
1296 {
1297 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1298 return format;
1299 }
1300 case VERTEX_FORMAT_USHORT1_NORM:
1301 {
1302 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1303 return format;
1304 }
1305 case VERTEX_FORMAT_USHORT2:
1306 {
1307 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1308 return format;
1309 }
1310 case VERTEX_FORMAT_USHORT2_NORM:
1311 {
1312 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1313 return format;
1314 }
1315 case VERTEX_FORMAT_USHORT3:
1316 {
1317 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1318 return format;
1319 }
1320 case VERTEX_FORMAT_USHORT3_NORM:
1321 {
1322 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1323 return format;
1324 }
1325 case VERTEX_FORMAT_USHORT4:
1326 {
1327 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1328 return format;
1329 }
1330 case VERTEX_FORMAT_USHORT4_NORM:
1331 {
1332 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1333 return format;
1334 }
1335 case VERTEX_FORMAT_SINT1:
1336 {
1337 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1338 return format;
1339 }
1340 case VERTEX_FORMAT_SINT1_NORM:
1341 {
1342 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1343 return format;
1344 }
1345 case VERTEX_FORMAT_SINT2:
1346 {
1347 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1348 return format;
1349 }
1350 case VERTEX_FORMAT_SINT2_NORM:
1351 {
1352 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1353 return format;
1354 }
1355 case VERTEX_FORMAT_SINT3:
1356 {
1357 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1358 return format;
1359 }
1360 case VERTEX_FORMAT_SINT3_NORM:
1361 {
1362 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1363 return format;
1364 }
1365 case VERTEX_FORMAT_SINT4:
1366 {
1367 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1368 return format;
1369 }
1370 case VERTEX_FORMAT_SINT4_NORM:
1371 {
1372 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1373 return format;
1374 }
1375 case VERTEX_FORMAT_UINT1:
1376 {
1377 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1378 return format;
1379 }
1380 case VERTEX_FORMAT_UINT1_NORM:
1381 {
1382 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1383 return format;
1384 }
1385 case VERTEX_FORMAT_UINT2:
1386 {
1387 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1388 return format;
1389 }
1390 case VERTEX_FORMAT_UINT2_NORM:
1391 {
1392 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1393 return format;
1394 }
1395 case VERTEX_FORMAT_UINT3:
1396 {
1397 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1398 return format;
1399 }
1400 case VERTEX_FORMAT_UINT3_NORM:
1401 {
1402 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1403 return format;
1404 }
1405 case VERTEX_FORMAT_UINT4:
1406 {
1407 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1408 return format;
1409 }
1410 case VERTEX_FORMAT_UINT4_NORM:
1411 {
1412 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1413 return format;
1414 }
1415 case VERTEX_FORMAT_SBYTE1_INT:
1416 {
1417 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1418 return format;
1419 }
1420 case VERTEX_FORMAT_SBYTE2_INT:
1421 {
1422 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1423 return format;
1424 }
1425 case VERTEX_FORMAT_SBYTE3_INT:
1426 {
1427 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1428 return format;
1429 }
1430 case VERTEX_FORMAT_SBYTE4_INT:
1431 {
1432 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1433 return format;
1434 }
1435 case VERTEX_FORMAT_UBYTE1_INT:
1436 {
1437 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1438 return format;
1439 }
1440 case VERTEX_FORMAT_UBYTE2_INT:
1441 {
1442 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1443 return format;
1444 }
1445 case VERTEX_FORMAT_UBYTE3_INT:
1446 {
1447 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1448 return format;
1449 }
1450 case VERTEX_FORMAT_UBYTE4_INT:
1451 {
1452 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1453 return format;
1454 }
1455 case VERTEX_FORMAT_SSHORT1_INT:
1456 {
1457 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1458 return format;
1459 }
1460 case VERTEX_FORMAT_SSHORT2_INT:
1461 {
1462 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1463 return format;
1464 }
1465 case VERTEX_FORMAT_SSHORT3_INT:
1466 {
1467 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1468 return format;
1469 }
1470 case VERTEX_FORMAT_SSHORT4_INT:
1471 {
1472 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1473 return format;
1474 }
1475 case VERTEX_FORMAT_USHORT1_INT:
1476 {
1477 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1478 return format;
1479 }
1480 case VERTEX_FORMAT_USHORT2_INT:
1481 {
1482 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1483 return format;
1484 }
1485 case VERTEX_FORMAT_USHORT3_INT:
1486 {
1487 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1488 return format;
1489 }
1490 case VERTEX_FORMAT_USHORT4_INT:
1491 {
1492 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1493 return format;
1494 }
1495 case VERTEX_FORMAT_SINT1_INT:
1496 {
1497 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1498 return format;
1499 }
1500 case VERTEX_FORMAT_SINT2_INT:
1501 {
1502 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1503 return format;
1504 }
1505 case VERTEX_FORMAT_SINT3_INT:
1506 {
1507 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1508 return format;
1509 }
1510 case VERTEX_FORMAT_SINT4_INT:
1511 {
1512 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1513 return format;
1514 }
1515 case VERTEX_FORMAT_UINT1_INT:
1516 {
1517 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1518 return format;
1519 }
1520 case VERTEX_FORMAT_UINT2_INT:
1521 {
1522 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1523 return format;
1524 }
1525 case VERTEX_FORMAT_UINT3_INT:
1526 {
1527 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1528 return format;
1529 }
1530 case VERTEX_FORMAT_UINT4_INT:
1531 {
1532 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1533 return format;
1534 }
1535 case VERTEX_FORMAT_FIXED1:
1536 {
1537 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1538 return format;
1539 }
1540 case VERTEX_FORMAT_FIXED2:
1541 {
1542 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1543 return format;
1544 }
1545 case VERTEX_FORMAT_FIXED3:
1546 {
1547 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1548 return format;
1549 }
1550 case VERTEX_FORMAT_FIXED4:
1551 {
1552 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1553 return format;
1554 }
1555 case VERTEX_FORMAT_HALF1:
1556 {
1557 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1558 return format;
1559 }
1560 case VERTEX_FORMAT_HALF2:
1561 {
1562 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1563 return format;
1564 }
1565 case VERTEX_FORMAT_HALF3:
1566 {
1567 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1568 return format;
1569 }
1570 case VERTEX_FORMAT_HALF4:
1571 {
1572 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1573 return format;
1574 }
1575 case VERTEX_FORMAT_FLOAT1:
1576 {
1577 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1578 return format;
1579 }
1580 case VERTEX_FORMAT_FLOAT2:
1581 {
1582 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1583 return format;
1584 }
1585 case VERTEX_FORMAT_FLOAT3:
1586 {
1587 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1588 return format;
1589 }
1590 case VERTEX_FORMAT_FLOAT4:
1591 {
1592 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1593 return format;
1594 }
1595 case VERTEX_FORMAT_SINT210:
1596 {
1597 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1598 return format;
1599 }
1600 case VERTEX_FORMAT_UINT210:
1601 {
1602 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1603 return format;
1604 }
1605 case VERTEX_FORMAT_SINT210_NORM:
1606 {
1607 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1608 return format;
1609 }
1610 case VERTEX_FORMAT_UINT210_NORM:
1611 {
1612 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1613 return format;
1614 }
1615 case VERTEX_FORMAT_SINT210_INT:
1616 {
1617 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1618 return format;
1619 }
1620 case VERTEX_FORMAT_UINT210_INT:
1621 {
1622 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1623 return format;
1624 }
1625 default:
1626 {
1627 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1628 return format;
1629 }
1630 }
1631}
1632
1633VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1634 : type(typeIn),
1635 normalized(normalizedIn),
1636 components(componentsIn),
1637 pureInteger(pureIntegerIn)
1638{
1639 // float -> !normalized
1640 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1641}
1642
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001643}