blob: c9b2aba669f04a50323ee6bbd74e7daccff0546d [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
14namespace gl
15{
16
17// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
18// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
19// format and type combinations.
20
21typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Lang051dbc72015-01-05 15:48:58 -050022typedef std::pair<FormatTypePair, GLenum> FormatPair;
23typedef std::map<FormatTypePair, GLenum> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madill89a0bf52013-09-18 14:36:24 -040025// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050026static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000027{
Geoff Lang051dbc72015-01-05 15:48:58 -050028 map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000029}
30
Geoff Lange4a492b2014-06-19 14:14:41 -040031FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000032{
33 FormatMap map;
34
Geoff Lang051dbc72015-01-05 15:48:58 -050035 // | Format | Type | Internal format |
36 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
37 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
38 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
39 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
40 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
41 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
42 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
43 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000044
Geoff Lang051dbc72015-01-05 15:48:58 -050045 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
46 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
47 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
48 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
49 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
50 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
51 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052
Geoff Lang051dbc72015-01-05 15:48:58 -050053 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
54 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
55 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
56 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
57 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
58 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
59 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
60 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000061
Geoff Lang051dbc72015-01-05 15:48:58 -050062 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
63 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
64 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
65 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
66 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
67 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang051dbc72015-01-05 15:48:58 -050069 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
70 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
71 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
72 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
73 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000074
Geoff Lang051dbc72015-01-05 15:48:58 -050075 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
76 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
77 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
78 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
79 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
80 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040081
Geoff Lang051dbc72015-01-05 15:48:58 -050082 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
83 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
84 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
85 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
86 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -040087
Geoff Lang051dbc72015-01-05 15:48:58 -050088 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
89 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
90 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
91 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
92 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
93 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040094
Geoff Lang051dbc72015-01-05 15:48:58 -050095 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
96 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
97 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
98 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
99 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
100 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
101 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
102 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
103 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
104 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
105 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
106 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400107
Geoff Lang051dbc72015-01-05 15:48:58 -0500108 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
109 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
110 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 -0400111
Geoff Lang051dbc72015-01-05 15:48:58 -0500112 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
113 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400114
Geoff Lang051dbc72015-01-05 15:48:58 -0500115 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
116 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
117 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
118 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400119
Geoff Lang051dbc72015-01-05 15:48:58 -0500120 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
121 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
122 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400123
Geoff Lang051dbc72015-01-05 15:48:58 -0500124 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400125
Geoff Lang051dbc72015-01-05 15:48:58 -0500126 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
127 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000128
129 return map;
130}
131
Geoff Lang5d601382014-07-22 15:14:06 -0400132Type::Type()
133 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200134 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400135 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400136{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000137}
138
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200139static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000140{
Geoff Lang5d601382014-07-22 15:14:06 -0400141 Type info;
142 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200143 GLuint i = 0;
144 while ((1u << i) < bytes)
145 {
146 ++i;
147 }
148 info.bytesShift = i;
149 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400150 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200151 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400152}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000153
Geoff Lang5d601382014-07-22 15:14:06 -0400154bool operator<(const Type& a, const Type& b)
155{
156 return memcmp(&a, &b, sizeof(Type)) < 0;
157}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000158
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000159// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400160static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000161{
Geoff Lang493daf52014-07-03 13:38:44 -0400162 return true;
163}
164
Geoff Lang493daf52014-07-03 13:38:44 -0400165static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000166{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000167 return false;
168}
169
Geoff Lange4a492b2014-06-19 14:14:41 -0400170template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400171static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400172{
173 return clientVersion >= minCoreGLVersion;
174}
175
Geoff Langcec35902014-04-16 10:52:36 -0400176// Pointer to a boolean memeber of the Extensions struct
177typedef bool(Extensions::*ExtensionBool);
178
179// Check support for a single extension
180template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400181static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400182{
Geoff Lange4a492b2014-06-19 14:14:41 -0400183 return extensions.*bool1;
184}
185
186// Check for a minimum client version or a single extension
187template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400188static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400189{
190 return clientVersion >= minCoreGLVersion || extensions.*bool1;
191}
192
193// Check for a minimum client version or two extensions
194template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400195static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400196{
Geoff Langabce7622014-09-19 16:13:00 -0400197 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
198}
199
200// Check for a minimum client version or at least one of two extensions
201template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
202static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
203{
204 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400205}
206
207// Check support for two extensions
208template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400209static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400210{
Geoff Langabce7622014-09-19 16:13:00 -0400211 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400212}
213
Geoff Lang60ad73d2015-10-23 10:08:44 -0400214// Check support for either of two extensions
215template <ExtensionBool bool1, ExtensionBool bool2>
216static bool RequireExtOrExt(GLuint, const Extensions &extensions)
217{
218 return extensions.*bool1 || extensions.*bool2;
219}
220
Jamie Madillcd089732015-12-17 09:53:09 -0500221// Special function for half float formats with three or four channels.
222static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
223{
224 return clientVersion >= 3 || extensions.textureHalfFloat;
225}
226
227static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
228{
229 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
230}
231
232// Special function for half float formats with one or two channels.
233static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
234{
235 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
236}
237
238static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
239{
240 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
241}
242
243// Special function for float formats with three or four channels.
244static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
245{
246 return clientVersion >= 3 || extensions.textureFloat;
247}
248
249static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
250{
251 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
252 return FloatSupport(clientVersion, extensions) &&
253 (extensions.colorBufferFloat || clientVersion == 2);
254}
255
256// Special function for float formats with one or two channels.
257static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
258{
259 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
260}
261
262static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
263{
264 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
265 return FloatSupportRG(clientVersion, extensions) &&
266 (extensions.colorBufferFloat || clientVersion == 2);
267}
268
Geoff Lang5d601382014-07-22 15:14:06 -0400269InternalFormat::InternalFormat()
270 : redBits(0),
271 greenBits(0),
272 blueBits(0),
273 luminanceBits(0),
274 alphaBits(0),
275 sharedBits(0),
276 depthBits(0),
277 stencilBits(0),
278 pixelBytes(0),
279 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400280 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400281 compressedBlockWidth(0),
282 compressedBlockHeight(0),
283 format(GL_NONE),
284 type(GL_NONE),
285 componentType(GL_NONE),
286 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400287 textureSupport(NeverSupported),
288 renderSupport(NeverSupported),
289 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000290{
Geoff Lang5d601382014-07-22 15:14:06 -0400291}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000292
Geoff Lang5d601382014-07-22 15:14:06 -0400293static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
294 InternalFormat::SupportCheckFunction renderSupport,
295 InternalFormat::SupportCheckFunction filterSupport)
296{
297 InternalFormat formatInfo;
298 formatInfo.format = format;
299 formatInfo.textureSupport = textureSupport;
300 formatInfo.renderSupport = renderSupport;
301 formatInfo.filterSupport = filterSupport;
302 return formatInfo;
303}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000304
Geoff Lang5d601382014-07-22 15:14:06 -0400305static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
306 GLenum format, GLenum type, GLenum componentType, bool srgb,
307 InternalFormat::SupportCheckFunction textureSupport,
308 InternalFormat::SupportCheckFunction renderSupport,
309 InternalFormat::SupportCheckFunction filterSupport)
310{
311 InternalFormat formatInfo;
312 formatInfo.redBits = red;
313 formatInfo.greenBits = green;
314 formatInfo.blueBits = blue;
315 formatInfo.alphaBits = alpha;
316 formatInfo.sharedBits = shared;
317 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
318 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
319 formatInfo.format = format;
320 formatInfo.type = type;
321 formatInfo.componentType = componentType;
322 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
323 formatInfo.textureSupport = textureSupport;
324 formatInfo.renderSupport = renderSupport;
325 formatInfo.filterSupport = filterSupport;
326 return formatInfo;
327}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000328
Geoff Lang5d601382014-07-22 15:14:06 -0400329static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
330 InternalFormat::SupportCheckFunction textureSupport,
331 InternalFormat::SupportCheckFunction renderSupport,
332 InternalFormat::SupportCheckFunction filterSupport)
333{
334 InternalFormat formatInfo;
335 formatInfo.luminanceBits = luminance;
336 formatInfo.alphaBits = alpha;
337 formatInfo.pixelBytes = (luminance + alpha) / 8;
338 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
339 formatInfo.format = format;
340 formatInfo.type = type;
341 formatInfo.componentType = componentType;
342 formatInfo.colorEncoding = GL_LINEAR;
343 formatInfo.textureSupport = textureSupport;
344 formatInfo.renderSupport = renderSupport;
345 formatInfo.filterSupport = filterSupport;
346 return formatInfo;
347}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000348
Geoff Lang5d601382014-07-22 15:14:06 -0400349static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
350 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
351 InternalFormat::SupportCheckFunction renderSupport,
352 InternalFormat::SupportCheckFunction filterSupport)
353{
354 InternalFormat formatInfo;
355 formatInfo.depthBits = depthBits;
356 formatInfo.stencilBits = stencilBits;
357 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
358 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
359 formatInfo.format = format;
360 formatInfo.type = type;
361 formatInfo.componentType = componentType;
362 formatInfo.colorEncoding = GL_LINEAR;
363 formatInfo.textureSupport = textureSupport;
364 formatInfo.renderSupport = renderSupport;
365 formatInfo.filterSupport = filterSupport;
366 return formatInfo;
367}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000368
Geoff Lang5d601382014-07-22 15:14:06 -0400369static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
370 GLuint componentCount, GLenum format, GLenum type, bool srgb,
371 InternalFormat::SupportCheckFunction textureSupport,
372 InternalFormat::SupportCheckFunction renderSupport,
373 InternalFormat::SupportCheckFunction filterSupport)
374{
375 InternalFormat formatInfo;
376 formatInfo.compressedBlockWidth = compressedBlockWidth;
377 formatInfo.compressedBlockHeight = compressedBlockHeight;
378 formatInfo.pixelBytes = compressedBlockSize / 8;
379 formatInfo.componentCount = componentCount;
380 formatInfo.format = format;
381 formatInfo.type = type;
382 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
383 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
384 formatInfo.compressed = true;
385 formatInfo.textureSupport = textureSupport;
386 formatInfo.renderSupport = renderSupport;
387 formatInfo.filterSupport = filterSupport;
388 return formatInfo;
389}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000390
Geoff Lang5d601382014-07-22 15:14:06 -0400391typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
392typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000393
Geoff Lange4a492b2014-06-19 14:14:41 -0400394static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000395{
396 InternalFormatInfoMap map;
397
Geoff Lang9bbad182015-09-04 11:07:29 -0400398 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000399 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400400 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000401
Geoff Langabce7622014-09-19 16:13:00 -0400402 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
403 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)));
404 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
405 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)));
406 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
407 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)));
408 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
409 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)));
410 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)));
411 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)));
412 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)));
413 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
414 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 -0400415 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 -0400416 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)));
417 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)));
418 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)));
419 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)));
420 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
421 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)));
422 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
423 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)));
424 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
425 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)));
426 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
427 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)));
428 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
429 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)));
430 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
431 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)));
432 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
433 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)));
434 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
435 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)));
436 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
437 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)));
438 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
439 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)));
440 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
441 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)));
442 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
443 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 +0000444
Geoff Langabce7622014-09-19 16:13:00 -0400445 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)));
446 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)));
447 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 +0000448
449 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500450 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
451 // | | | | | | | type | | | | |
452 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
453 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
454 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
455 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
456 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
457 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
458 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
459 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 +0000460
461 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400462 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
463 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>)));
464 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>)));
465 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 -0500466 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 -0400467 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 )));
468 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 -0800469 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000470
471 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400472 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400473 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
474 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
475 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
476 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
477 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
478 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
479 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
480 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
481 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 +0000482
483 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400484 // | Internal format | | Format | Supported | Renderable | Filterable |
485 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
486 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
487 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
488 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
489 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
490 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
491 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
492 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
493 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
494 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
495 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
496 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
497 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
498 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
499 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
500 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 +0000501
502 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400503 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
504 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
505 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)));
506 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
507 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)));
508 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
509 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
510 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)));
511 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)));
512 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)));
513 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 +0000514
515 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400516 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
517 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)));
518 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 +0000519
520 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400521 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 +0000522
523 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400524 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)));
525
526 // From GL_OES_compressed_ETC1_RGB8_texture
527 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 +0000528
Geoff Lang60ad73d2015-10-23 10:08:44 -0400529 // From KHR_texture_compression_astc_hdr
530 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
531 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)));
532 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)));
533 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)));
534 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)));
535 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)));
536 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)));
537 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)));
538 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)));
539 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)));
540 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)));
541 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)));
542 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)));
543 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)));
544 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)));
545
546 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)));
547 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)));
548 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)));
549 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)));
550 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)));
551 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)));
552 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)));
553 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)));
554 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)));
555 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)));
556 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)));
557 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)));
558 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)));
559 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)));
560
Corentin Walleze0902642014-11-04 12:32:15 -0800561 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
562 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
563 // - All other stencil formats (all depth-stencil) are either float or normalized
564 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
565 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
566 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 -0800567
568 // From GL_ANGLE_lossy_etc_decode
569 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)));
570
Geoff Lang9bbad182015-09-04 11:07:29 -0400571 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800572
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000573 return map;
574}
575
Geoff Lange4a492b2014-06-19 14:14:41 -0400576static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000577{
Geoff Lange4a492b2014-06-19 14:14:41 -0400578 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
579 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000580}
581
Geoff Lange4a492b2014-06-19 14:14:41 -0400582static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400583{
584 FormatSet result;
585
Geoff Lange4a492b2014-06-19 14:14:41 -0400586 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400587 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
588 {
Geoff Lang5d601382014-07-22 15:14:06 -0400589 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400590 {
591 result.insert(i->first);
592 }
593 }
594
595 return result;
596}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000597
Geoff Lang5d601382014-07-22 15:14:06 -0400598const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000599{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200600 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000601 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200602 case GL_UNSIGNED_BYTE:
603 case GL_BYTE:
604 {
605 static const Type info = GenTypeInfo(1, false);
606 return info;
607 }
608 case GL_UNSIGNED_SHORT:
609 case GL_SHORT:
610 case GL_HALF_FLOAT:
611 case GL_HALF_FLOAT_OES:
612 {
613 static const Type info = GenTypeInfo(2, false);
614 return info;
615 }
616 case GL_UNSIGNED_INT:
617 case GL_INT:
618 case GL_FLOAT:
619 {
620 static const Type info = GenTypeInfo(4, false);
621 return info;
622 }
623 case GL_UNSIGNED_SHORT_5_6_5:
624 case GL_UNSIGNED_SHORT_4_4_4_4:
625 case GL_UNSIGNED_SHORT_5_5_5_1:
626 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
627 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
628 {
629 static const Type info = GenTypeInfo(2, true);
630 return info;
631 }
632 case GL_UNSIGNED_INT_2_10_10_10_REV:
633 case GL_UNSIGNED_INT_24_8:
634 case GL_UNSIGNED_INT_10F_11F_11F_REV:
635 case GL_UNSIGNED_INT_5_9_9_9_REV:
636 {
637 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
638 static const Type info = GenTypeInfo(4, true);
639 return info;
640 }
641 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
642 {
643 static const Type info = GenTypeInfo(8, true);
644 return info;
645 }
646 default:
647 {
648 static const Type defaultInfo;
649 return defaultInfo;
650 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000651 }
652}
653
Geoff Lang5d601382014-07-22 15:14:06 -0400654const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000655{
Geoff Lang5d601382014-07-22 15:14:06 -0400656 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
657 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
658 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000659 {
Geoff Lang5d601382014-07-22 15:14:06 -0400660 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000661 }
662 else
663 {
Geoff Lang5d601382014-07-22 15:14:06 -0400664 static const InternalFormat defaultInternalFormat;
665 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000666 }
667}
668
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800669GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000670{
671 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800672 GLuint rowBytes;
673 if (rowLength > 0)
674 {
675 ASSERT(!compressed);
676 rowBytes = pixelBytes * rowLength;
677 }
678 else
679 {
680 rowBytes = computeBlockSize(formatType, width, 1);
681 }
682 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000683}
684
Minmin Gongadff67b2015-10-14 10:34:45 -0400685GLuint InternalFormat::computeDepthPitch(GLenum formatType,
686 GLsizei width,
687 GLsizei height,
688 GLint alignment,
689 GLint rowLength,
690 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000691{
Minmin Gongadff67b2015-10-14 10:34:45 -0400692 GLuint rows;
693 if (imageHeight > 0)
694 {
695 rows = imageHeight;
696 }
697 else
698 {
699 rows = height;
700 }
701 return computeRowPitch(formatType, width, alignment, rowLength) * rows;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000702}
703
Austin Kinross3ae64652015-01-26 15:51:39 -0800704GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000705{
Geoff Lang5d601382014-07-22 15:14:06 -0400706 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707 {
Geoff Lang5d601382014-07-22 15:14:06 -0400708 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
709 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
710 return (pixelBytes * numBlocksWide * numBlocksHight);
711 }
712 else
713 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800714 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400715 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000716 {
Geoff Lang5d601382014-07-22 15:14:06 -0400717 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000718 }
719 else
720 {
Geoff Lang5d601382014-07-22 15:14:06 -0400721 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000722 }
723 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000724}
725
Minmin Gongadff67b2015-10-14 10:34:45 -0400726GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
727 GLint depthPitch,
728 GLint skipImages,
729 GLint skipRows,
730 GLint skipPixels) const
731{
732 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
733}
734
Geoff Lang5d601382014-07-22 15:14:06 -0400735GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000736{
Geoff Lang5d601382014-07-22 15:14:06 -0400737 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500738 if (formatInfo.pixelBytes > 0)
739 {
740 return internalFormat;
741 }
742 else
743 {
744 static const FormatMap formatMap = BuildFormatMap();
745 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
746 if (iter != formatMap.end())
747 {
748 return iter->second;
749 }
750 else
751 {
752 return GL_NONE;
753 }
754 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000755}
756
Geoff Lange4a492b2014-06-19 14:14:41 -0400757const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400758{
Geoff Lange4a492b2014-06-19 14:14:41 -0400759 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400760 return formatSet;
761}
762
Jamie Madill09e2d932015-07-14 16:40:31 -0400763AttributeType GetAttributeType(GLenum enumValue)
764{
765 switch (enumValue)
766 {
767 case GL_FLOAT:
768 return ATTRIBUTE_FLOAT;
769 case GL_FLOAT_VEC2:
770 return ATTRIBUTE_VEC2;
771 case GL_FLOAT_VEC3:
772 return ATTRIBUTE_VEC3;
773 case GL_FLOAT_VEC4:
774 return ATTRIBUTE_VEC4;
775 case GL_INT:
776 return ATTRIBUTE_INT;
777 case GL_INT_VEC2:
778 return ATTRIBUTE_IVEC2;
779 case GL_INT_VEC3:
780 return ATTRIBUTE_IVEC3;
781 case GL_INT_VEC4:
782 return ATTRIBUTE_IVEC4;
783 case GL_UNSIGNED_INT:
784 return ATTRIBUTE_UINT;
785 case GL_UNSIGNED_INT_VEC2:
786 return ATTRIBUTE_UVEC2;
787 case GL_UNSIGNED_INT_VEC3:
788 return ATTRIBUTE_UVEC3;
789 case GL_UNSIGNED_INT_VEC4:
790 return ATTRIBUTE_UVEC4;
791 case GL_FLOAT_MAT2:
792 return ATTRIBUTE_MAT2;
793 case GL_FLOAT_MAT3:
794 return ATTRIBUTE_MAT3;
795 case GL_FLOAT_MAT4:
796 return ATTRIBUTE_MAT4;
797 case GL_FLOAT_MAT2x3:
798 return ATTRIBUTE_MAT2x3;
799 case GL_FLOAT_MAT2x4:
800 return ATTRIBUTE_MAT2x4;
801 case GL_FLOAT_MAT3x2:
802 return ATTRIBUTE_MAT3x2;
803 case GL_FLOAT_MAT3x4:
804 return ATTRIBUTE_MAT3x4;
805 case GL_FLOAT_MAT4x2:
806 return ATTRIBUTE_MAT4x2;
807 case GL_FLOAT_MAT4x3:
808 return ATTRIBUTE_MAT4x3;
809 default:
810 UNREACHABLE();
811 return ATTRIBUTE_FLOAT;
812 }
813}
814
Jamie Madilld3dfda22015-07-06 08:28:49 -0400815VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
816{
817 switch (type)
818 {
819 case GL_BYTE:
820 switch (components)
821 {
822 case 1:
823 if (pureInteger)
824 return VERTEX_FORMAT_SBYTE1_INT;
825 if (normalized)
826 return VERTEX_FORMAT_SBYTE1_NORM;
827 return VERTEX_FORMAT_SBYTE1;
828 case 2:
829 if (pureInteger)
830 return VERTEX_FORMAT_SBYTE2_INT;
831 if (normalized)
832 return VERTEX_FORMAT_SBYTE2_NORM;
833 return VERTEX_FORMAT_SBYTE2;
834 case 3:
835 if (pureInteger)
836 return VERTEX_FORMAT_SBYTE3_INT;
837 if (normalized)
838 return VERTEX_FORMAT_SBYTE3_NORM;
839 return VERTEX_FORMAT_SBYTE3;
840 case 4:
841 if (pureInteger)
842 return VERTEX_FORMAT_SBYTE4_INT;
843 if (normalized)
844 return VERTEX_FORMAT_SBYTE4_NORM;
845 return VERTEX_FORMAT_SBYTE4;
846 default:
847 UNREACHABLE();
848 break;
849 }
850 case GL_UNSIGNED_BYTE:
851 switch (components)
852 {
853 case 1:
854 if (pureInteger)
855 return VERTEX_FORMAT_UBYTE1_INT;
856 if (normalized)
857 return VERTEX_FORMAT_UBYTE1_NORM;
858 return VERTEX_FORMAT_UBYTE1;
859 case 2:
860 if (pureInteger)
861 return VERTEX_FORMAT_UBYTE2_INT;
862 if (normalized)
863 return VERTEX_FORMAT_UBYTE2_NORM;
864 return VERTEX_FORMAT_UBYTE2;
865 case 3:
866 if (pureInteger)
867 return VERTEX_FORMAT_UBYTE3_INT;
868 if (normalized)
869 return VERTEX_FORMAT_UBYTE3_NORM;
870 return VERTEX_FORMAT_UBYTE3;
871 case 4:
872 if (pureInteger)
873 return VERTEX_FORMAT_UBYTE4_INT;
874 if (normalized)
875 return VERTEX_FORMAT_UBYTE4_NORM;
876 return VERTEX_FORMAT_UBYTE4;
877 default:
878 UNREACHABLE();
879 break;
880 }
881 case GL_SHORT:
882 switch (components)
883 {
884 case 1:
885 if (pureInteger)
886 return VERTEX_FORMAT_SSHORT1_INT;
887 if (normalized)
888 return VERTEX_FORMAT_SSHORT1_NORM;
889 return VERTEX_FORMAT_SSHORT1;
890 case 2:
891 if (pureInteger)
892 return VERTEX_FORMAT_SSHORT2_INT;
893 if (normalized)
894 return VERTEX_FORMAT_SSHORT2_NORM;
895 return VERTEX_FORMAT_SSHORT2;
896 case 3:
897 if (pureInteger)
898 return VERTEX_FORMAT_SSHORT3_INT;
899 if (normalized)
900 return VERTEX_FORMAT_SSHORT3_NORM;
901 return VERTEX_FORMAT_SSHORT3;
902 case 4:
903 if (pureInteger)
904 return VERTEX_FORMAT_SSHORT4_INT;
905 if (normalized)
906 return VERTEX_FORMAT_SSHORT4_NORM;
907 return VERTEX_FORMAT_SSHORT4;
908 default:
909 UNREACHABLE();
910 break;
911 }
912 case GL_UNSIGNED_SHORT:
913 switch (components)
914 {
915 case 1:
916 if (pureInteger)
917 return VERTEX_FORMAT_USHORT1_INT;
918 if (normalized)
919 return VERTEX_FORMAT_USHORT1_NORM;
920 return VERTEX_FORMAT_USHORT1;
921 case 2:
922 if (pureInteger)
923 return VERTEX_FORMAT_USHORT2_INT;
924 if (normalized)
925 return VERTEX_FORMAT_USHORT2_NORM;
926 return VERTEX_FORMAT_USHORT2;
927 case 3:
928 if (pureInteger)
929 return VERTEX_FORMAT_USHORT3_INT;
930 if (normalized)
931 return VERTEX_FORMAT_USHORT3_NORM;
932 return VERTEX_FORMAT_USHORT3;
933 case 4:
934 if (pureInteger)
935 return VERTEX_FORMAT_USHORT4_INT;
936 if (normalized)
937 return VERTEX_FORMAT_USHORT4_NORM;
938 return VERTEX_FORMAT_USHORT4;
939 default:
940 UNREACHABLE();
941 break;
942 }
943 case GL_INT:
944 switch (components)
945 {
946 case 1:
947 if (pureInteger)
948 return VERTEX_FORMAT_SINT1_INT;
949 if (normalized)
950 return VERTEX_FORMAT_SINT1_NORM;
951 return VERTEX_FORMAT_SINT1;
952 case 2:
953 if (pureInteger)
954 return VERTEX_FORMAT_SINT2_INT;
955 if (normalized)
956 return VERTEX_FORMAT_SINT2_NORM;
957 return VERTEX_FORMAT_SINT2;
958 case 3:
959 if (pureInteger)
960 return VERTEX_FORMAT_SINT3_INT;
961 if (normalized)
962 return VERTEX_FORMAT_SINT3_NORM;
963 return VERTEX_FORMAT_SINT3;
964 case 4:
965 if (pureInteger)
966 return VERTEX_FORMAT_SINT4_INT;
967 if (normalized)
968 return VERTEX_FORMAT_SINT4_NORM;
969 return VERTEX_FORMAT_SINT4;
970 default:
971 UNREACHABLE();
972 break;
973 }
974 case GL_UNSIGNED_INT:
975 switch (components)
976 {
977 case 1:
978 if (pureInteger)
979 return VERTEX_FORMAT_UINT1_INT;
980 if (normalized)
981 return VERTEX_FORMAT_UINT1_NORM;
982 return VERTEX_FORMAT_UINT1;
983 case 2:
984 if (pureInteger)
985 return VERTEX_FORMAT_UINT2_INT;
986 if (normalized)
987 return VERTEX_FORMAT_UINT2_NORM;
988 return VERTEX_FORMAT_UINT2;
989 case 3:
990 if (pureInteger)
991 return VERTEX_FORMAT_UINT3_INT;
992 if (normalized)
993 return VERTEX_FORMAT_UINT3_NORM;
994 return VERTEX_FORMAT_UINT3;
995 case 4:
996 if (pureInteger)
997 return VERTEX_FORMAT_UINT4_INT;
998 if (normalized)
999 return VERTEX_FORMAT_UINT4_NORM;
1000 return VERTEX_FORMAT_UINT4;
1001 default:
1002 UNREACHABLE();
1003 break;
1004 }
1005 case GL_FLOAT:
1006 switch (components)
1007 {
1008 case 1:
1009 return VERTEX_FORMAT_FLOAT1;
1010 case 2:
1011 return VERTEX_FORMAT_FLOAT2;
1012 case 3:
1013 return VERTEX_FORMAT_FLOAT3;
1014 case 4:
1015 return VERTEX_FORMAT_FLOAT4;
1016 default:
1017 UNREACHABLE();
1018 break;
1019 }
1020 case GL_HALF_FLOAT:
1021 switch (components)
1022 {
1023 case 1:
1024 return VERTEX_FORMAT_HALF1;
1025 case 2:
1026 return VERTEX_FORMAT_HALF2;
1027 case 3:
1028 return VERTEX_FORMAT_HALF3;
1029 case 4:
1030 return VERTEX_FORMAT_HALF4;
1031 default:
1032 UNREACHABLE();
1033 break;
1034 }
1035 case GL_FIXED:
1036 switch (components)
1037 {
1038 case 1:
1039 return VERTEX_FORMAT_FIXED1;
1040 case 2:
1041 return VERTEX_FORMAT_FIXED2;
1042 case 3:
1043 return VERTEX_FORMAT_FIXED3;
1044 case 4:
1045 return VERTEX_FORMAT_FIXED4;
1046 default:
1047 UNREACHABLE();
1048 break;
1049 }
1050 case GL_INT_2_10_10_10_REV:
1051 if (pureInteger)
1052 return VERTEX_FORMAT_SINT210_INT;
1053 if (normalized)
1054 return VERTEX_FORMAT_SINT210_NORM;
1055 return VERTEX_FORMAT_SINT210;
1056 case GL_UNSIGNED_INT_2_10_10_10_REV:
1057 if (pureInteger)
1058 return VERTEX_FORMAT_UINT210_INT;
1059 if (normalized)
1060 return VERTEX_FORMAT_UINT210_NORM;
1061 return VERTEX_FORMAT_UINT210;
1062 default:
1063 UNREACHABLE();
1064 break;
1065 }
1066 return VERTEX_FORMAT_UBYTE1;
1067}
1068
1069VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1070{
1071 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1072}
1073
1074VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1075{
1076 if (!attrib.enabled)
1077 {
1078 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1079 }
1080 return GetVertexFormatType(attrib);
1081}
1082
1083const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1084{
1085 switch (vertexFormatType)
1086 {
1087 case VERTEX_FORMAT_SBYTE1:
1088 {
1089 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1090 return format;
1091 }
1092 case VERTEX_FORMAT_SBYTE1_NORM:
1093 {
1094 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1095 return format;
1096 }
1097 case VERTEX_FORMAT_SBYTE2:
1098 {
1099 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1100 return format;
1101 }
1102 case VERTEX_FORMAT_SBYTE2_NORM:
1103 {
1104 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1105 return format;
1106 }
1107 case VERTEX_FORMAT_SBYTE3:
1108 {
1109 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1110 return format;
1111 }
1112 case VERTEX_FORMAT_SBYTE3_NORM:
1113 {
1114 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1115 return format;
1116 }
1117 case VERTEX_FORMAT_SBYTE4:
1118 {
1119 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1120 return format;
1121 }
1122 case VERTEX_FORMAT_SBYTE4_NORM:
1123 {
1124 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1125 return format;
1126 }
1127 case VERTEX_FORMAT_UBYTE1:
1128 {
1129 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1130 return format;
1131 }
1132 case VERTEX_FORMAT_UBYTE1_NORM:
1133 {
1134 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1135 return format;
1136 }
1137 case VERTEX_FORMAT_UBYTE2:
1138 {
1139 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1140 return format;
1141 }
1142 case VERTEX_FORMAT_UBYTE2_NORM:
1143 {
1144 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1145 return format;
1146 }
1147 case VERTEX_FORMAT_UBYTE3:
1148 {
1149 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1150 return format;
1151 }
1152 case VERTEX_FORMAT_UBYTE3_NORM:
1153 {
1154 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1155 return format;
1156 }
1157 case VERTEX_FORMAT_UBYTE4:
1158 {
1159 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1160 return format;
1161 }
1162 case VERTEX_FORMAT_UBYTE4_NORM:
1163 {
1164 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1165 return format;
1166 }
1167 case VERTEX_FORMAT_SSHORT1:
1168 {
1169 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1170 return format;
1171 }
1172 case VERTEX_FORMAT_SSHORT1_NORM:
1173 {
1174 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1175 return format;
1176 }
1177 case VERTEX_FORMAT_SSHORT2:
1178 {
1179 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1180 return format;
1181 }
1182 case VERTEX_FORMAT_SSHORT2_NORM:
1183 {
1184 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1185 return format;
1186 }
1187 case VERTEX_FORMAT_SSHORT3:
1188 {
1189 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1190 return format;
1191 }
1192 case VERTEX_FORMAT_SSHORT3_NORM:
1193 {
1194 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1195 return format;
1196 }
1197 case VERTEX_FORMAT_SSHORT4:
1198 {
1199 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1200 return format;
1201 }
1202 case VERTEX_FORMAT_SSHORT4_NORM:
1203 {
1204 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1205 return format;
1206 }
1207 case VERTEX_FORMAT_USHORT1:
1208 {
1209 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1210 return format;
1211 }
1212 case VERTEX_FORMAT_USHORT1_NORM:
1213 {
1214 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1215 return format;
1216 }
1217 case VERTEX_FORMAT_USHORT2:
1218 {
1219 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1220 return format;
1221 }
1222 case VERTEX_FORMAT_USHORT2_NORM:
1223 {
1224 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1225 return format;
1226 }
1227 case VERTEX_FORMAT_USHORT3:
1228 {
1229 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1230 return format;
1231 }
1232 case VERTEX_FORMAT_USHORT3_NORM:
1233 {
1234 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1235 return format;
1236 }
1237 case VERTEX_FORMAT_USHORT4:
1238 {
1239 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1240 return format;
1241 }
1242 case VERTEX_FORMAT_USHORT4_NORM:
1243 {
1244 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1245 return format;
1246 }
1247 case VERTEX_FORMAT_SINT1:
1248 {
1249 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1250 return format;
1251 }
1252 case VERTEX_FORMAT_SINT1_NORM:
1253 {
1254 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1255 return format;
1256 }
1257 case VERTEX_FORMAT_SINT2:
1258 {
1259 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1260 return format;
1261 }
1262 case VERTEX_FORMAT_SINT2_NORM:
1263 {
1264 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1265 return format;
1266 }
1267 case VERTEX_FORMAT_SINT3:
1268 {
1269 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1270 return format;
1271 }
1272 case VERTEX_FORMAT_SINT3_NORM:
1273 {
1274 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1275 return format;
1276 }
1277 case VERTEX_FORMAT_SINT4:
1278 {
1279 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1280 return format;
1281 }
1282 case VERTEX_FORMAT_SINT4_NORM:
1283 {
1284 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1285 return format;
1286 }
1287 case VERTEX_FORMAT_UINT1:
1288 {
1289 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1290 return format;
1291 }
1292 case VERTEX_FORMAT_UINT1_NORM:
1293 {
1294 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1295 return format;
1296 }
1297 case VERTEX_FORMAT_UINT2:
1298 {
1299 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1300 return format;
1301 }
1302 case VERTEX_FORMAT_UINT2_NORM:
1303 {
1304 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1305 return format;
1306 }
1307 case VERTEX_FORMAT_UINT3:
1308 {
1309 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1310 return format;
1311 }
1312 case VERTEX_FORMAT_UINT3_NORM:
1313 {
1314 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1315 return format;
1316 }
1317 case VERTEX_FORMAT_UINT4:
1318 {
1319 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1320 return format;
1321 }
1322 case VERTEX_FORMAT_UINT4_NORM:
1323 {
1324 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1325 return format;
1326 }
1327 case VERTEX_FORMAT_SBYTE1_INT:
1328 {
1329 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1330 return format;
1331 }
1332 case VERTEX_FORMAT_SBYTE2_INT:
1333 {
1334 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1335 return format;
1336 }
1337 case VERTEX_FORMAT_SBYTE3_INT:
1338 {
1339 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1340 return format;
1341 }
1342 case VERTEX_FORMAT_SBYTE4_INT:
1343 {
1344 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1345 return format;
1346 }
1347 case VERTEX_FORMAT_UBYTE1_INT:
1348 {
1349 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1350 return format;
1351 }
1352 case VERTEX_FORMAT_UBYTE2_INT:
1353 {
1354 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1355 return format;
1356 }
1357 case VERTEX_FORMAT_UBYTE3_INT:
1358 {
1359 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1360 return format;
1361 }
1362 case VERTEX_FORMAT_UBYTE4_INT:
1363 {
1364 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1365 return format;
1366 }
1367 case VERTEX_FORMAT_SSHORT1_INT:
1368 {
1369 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1370 return format;
1371 }
1372 case VERTEX_FORMAT_SSHORT2_INT:
1373 {
1374 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1375 return format;
1376 }
1377 case VERTEX_FORMAT_SSHORT3_INT:
1378 {
1379 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1380 return format;
1381 }
1382 case VERTEX_FORMAT_SSHORT4_INT:
1383 {
1384 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1385 return format;
1386 }
1387 case VERTEX_FORMAT_USHORT1_INT:
1388 {
1389 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1390 return format;
1391 }
1392 case VERTEX_FORMAT_USHORT2_INT:
1393 {
1394 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1395 return format;
1396 }
1397 case VERTEX_FORMAT_USHORT3_INT:
1398 {
1399 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1400 return format;
1401 }
1402 case VERTEX_FORMAT_USHORT4_INT:
1403 {
1404 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1405 return format;
1406 }
1407 case VERTEX_FORMAT_SINT1_INT:
1408 {
1409 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1410 return format;
1411 }
1412 case VERTEX_FORMAT_SINT2_INT:
1413 {
1414 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1415 return format;
1416 }
1417 case VERTEX_FORMAT_SINT3_INT:
1418 {
1419 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1420 return format;
1421 }
1422 case VERTEX_FORMAT_SINT4_INT:
1423 {
1424 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1425 return format;
1426 }
1427 case VERTEX_FORMAT_UINT1_INT:
1428 {
1429 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1430 return format;
1431 }
1432 case VERTEX_FORMAT_UINT2_INT:
1433 {
1434 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1435 return format;
1436 }
1437 case VERTEX_FORMAT_UINT3_INT:
1438 {
1439 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1440 return format;
1441 }
1442 case VERTEX_FORMAT_UINT4_INT:
1443 {
1444 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1445 return format;
1446 }
1447 case VERTEX_FORMAT_FIXED1:
1448 {
1449 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1450 return format;
1451 }
1452 case VERTEX_FORMAT_FIXED2:
1453 {
1454 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1455 return format;
1456 }
1457 case VERTEX_FORMAT_FIXED3:
1458 {
1459 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1460 return format;
1461 }
1462 case VERTEX_FORMAT_FIXED4:
1463 {
1464 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1465 return format;
1466 }
1467 case VERTEX_FORMAT_HALF1:
1468 {
1469 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1470 return format;
1471 }
1472 case VERTEX_FORMAT_HALF2:
1473 {
1474 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1475 return format;
1476 }
1477 case VERTEX_FORMAT_HALF3:
1478 {
1479 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1480 return format;
1481 }
1482 case VERTEX_FORMAT_HALF4:
1483 {
1484 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1485 return format;
1486 }
1487 case VERTEX_FORMAT_FLOAT1:
1488 {
1489 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1490 return format;
1491 }
1492 case VERTEX_FORMAT_FLOAT2:
1493 {
1494 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1495 return format;
1496 }
1497 case VERTEX_FORMAT_FLOAT3:
1498 {
1499 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1500 return format;
1501 }
1502 case VERTEX_FORMAT_FLOAT4:
1503 {
1504 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1505 return format;
1506 }
1507 case VERTEX_FORMAT_SINT210:
1508 {
1509 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1510 return format;
1511 }
1512 case VERTEX_FORMAT_UINT210:
1513 {
1514 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1515 return format;
1516 }
1517 case VERTEX_FORMAT_SINT210_NORM:
1518 {
1519 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1520 return format;
1521 }
1522 case VERTEX_FORMAT_UINT210_NORM:
1523 {
1524 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1525 return format;
1526 }
1527 case VERTEX_FORMAT_SINT210_INT:
1528 {
1529 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1530 return format;
1531 }
1532 case VERTEX_FORMAT_UINT210_INT:
1533 {
1534 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1535 return format;
1536 }
1537 default:
1538 {
1539 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1540 return format;
1541 }
1542 }
1543}
1544
1545VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1546 : type(typeIn),
1547 normalized(normalizedIn),
1548 components(componentsIn),
1549 pureInteger(pureIntegerIn)
1550{
1551 // float -> !normalized
1552 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1553}
1554
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001555}