blob: 949141330d46467b355da7c96a572fb5bee4db64 [file] [log] [blame]
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001//
Geoff Langcec35902014-04-16 10:52:36 -04002// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// formatutils.cpp: Queries for GL image formats.
8
Shannon Woods4d161ba2014-03-17 18:13:30 -04009#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/formatutils.h"
11#include "libANGLE/Context.h"
12#include "libANGLE/Framebuffer.h"
13#include "libANGLE/renderer/Renderer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
15namespace gl
16{
17
18// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
19// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
20// format and type combinations.
21
22typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Lang051dbc72015-01-05 15:48:58 -050023typedef std::pair<FormatTypePair, GLenum> FormatPair;
24typedef std::map<FormatTypePair, GLenum> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000025
Jamie Madill89a0bf52013-09-18 14:36:24 -040026// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050027static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000028{
Geoff Lang051dbc72015-01-05 15:48:58 -050029 map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000030}
31
Geoff Lange4a492b2014-06-19 14:14:41 -040032FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000033{
34 FormatMap map;
35
Geoff Lang051dbc72015-01-05 15:48:58 -050036 // | Format | Type | Internal format |
37 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
38 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
39 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
40 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
41 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
42 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
43 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
44 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000045
Geoff Lang051dbc72015-01-05 15:48:58 -050046 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
47 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
48 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
49 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
50 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
51 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
52 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000053
Geoff Lang051dbc72015-01-05 15:48:58 -050054 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
55 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
56 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
57 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
58 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
59 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
60 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
61 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000062
Geoff Lang051dbc72015-01-05 15:48:58 -050063 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
64 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
65 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
66 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
67 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
68 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000069
Geoff Lang051dbc72015-01-05 15:48:58 -050070 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
71 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
72 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
73 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
74 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000075
Geoff Lang051dbc72015-01-05 15:48:58 -050076 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
77 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
78 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
79 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
80 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
81 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040082
Geoff Lang051dbc72015-01-05 15:48:58 -050083 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
84 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
85 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
86 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
87 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -040088
Geoff Lang051dbc72015-01-05 15:48:58 -050089 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
90 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
91 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
92 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
93 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
94 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040095
Geoff Lang051dbc72015-01-05 15:48:58 -050096 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
97 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
98 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
99 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
100 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
101 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
102 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
103 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
104 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
105 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
106 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
107 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400108
Geoff Lang051dbc72015-01-05 15:48:58 -0500109 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
110 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
111 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX);
Geoff Langfe28ca02013-06-04 10:10:48 -0400112
Geoff Lang051dbc72015-01-05 15:48:58 -0500113 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
114 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400115
Geoff Lang051dbc72015-01-05 15:48:58 -0500116 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
117 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
118 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
119 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400120
Geoff Lang051dbc72015-01-05 15:48:58 -0500121 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
122 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
123 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400124
Geoff Lang051dbc72015-01-05 15:48:58 -0500125 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400126
Geoff Lang051dbc72015-01-05 15:48:58 -0500127 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
128 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000129
130 return map;
131}
132
Geoff Lang5d601382014-07-22 15:14:06 -0400133Type::Type()
134 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200135 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400136 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400137{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000138}
139
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200140static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000141{
Geoff Lang5d601382014-07-22 15:14:06 -0400142 Type info;
143 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200144 GLuint i = 0;
145 while ((1u << i) < bytes)
146 {
147 ++i;
148 }
149 info.bytesShift = i;
150 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400151 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200152 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400153}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000154
Geoff Lang5d601382014-07-22 15:14:06 -0400155bool operator<(const Type& a, const Type& b)
156{
157 return memcmp(&a, &b, sizeof(Type)) < 0;
158}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000159
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000160// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400161static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000162{
Geoff Lang493daf52014-07-03 13:38:44 -0400163 return true;
164}
165
Geoff Lang493daf52014-07-03 13:38:44 -0400166static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000167{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000168 return false;
169}
170
Geoff Lange4a492b2014-06-19 14:14:41 -0400171template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400172static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400173{
174 return clientVersion >= minCoreGLVersion;
175}
176
Geoff Langcec35902014-04-16 10:52:36 -0400177// Pointer to a boolean memeber of the Extensions struct
178typedef bool(Extensions::*ExtensionBool);
179
180// Check support for a single extension
181template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400182static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400183{
Geoff Lange4a492b2014-06-19 14:14:41 -0400184 return extensions.*bool1;
185}
186
187// Check for a minimum client version or a single extension
188template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400189static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400190{
191 return clientVersion >= minCoreGLVersion || extensions.*bool1;
192}
193
194// Check for a minimum client version or two extensions
195template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400196static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400197{
Geoff Langabce7622014-09-19 16:13:00 -0400198 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
199}
200
201// Check for a minimum client version or at least one of two extensions
202template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
203static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
204{
205 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400206}
207
208// Check support for two extensions
209template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400210static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400211{
Geoff Langabce7622014-09-19 16:13:00 -0400212 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400213}
214
Geoff Lang60ad73d2015-10-23 10:08:44 -0400215// Check support for either of two extensions
216template <ExtensionBool bool1, ExtensionBool bool2>
217static bool RequireExtOrExt(GLuint, const Extensions &extensions)
218{
219 return extensions.*bool1 || extensions.*bool2;
220}
221
Geoff Lang5d601382014-07-22 15:14:06 -0400222InternalFormat::InternalFormat()
223 : redBits(0),
224 greenBits(0),
225 blueBits(0),
226 luminanceBits(0),
227 alphaBits(0),
228 sharedBits(0),
229 depthBits(0),
230 stencilBits(0),
231 pixelBytes(0),
232 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400233 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400234 compressedBlockWidth(0),
235 compressedBlockHeight(0),
236 format(GL_NONE),
237 type(GL_NONE),
238 componentType(GL_NONE),
239 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400240 textureSupport(NeverSupported),
241 renderSupport(NeverSupported),
242 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000243{
Geoff Lang5d601382014-07-22 15:14:06 -0400244}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000245
Geoff Lang5d601382014-07-22 15:14:06 -0400246static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
247 InternalFormat::SupportCheckFunction renderSupport,
248 InternalFormat::SupportCheckFunction filterSupport)
249{
250 InternalFormat formatInfo;
251 formatInfo.format = format;
252 formatInfo.textureSupport = textureSupport;
253 formatInfo.renderSupport = renderSupport;
254 formatInfo.filterSupport = filterSupport;
255 return formatInfo;
256}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000257
Geoff Lang5d601382014-07-22 15:14:06 -0400258static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
259 GLenum format, GLenum type, GLenum componentType, bool srgb,
260 InternalFormat::SupportCheckFunction textureSupport,
261 InternalFormat::SupportCheckFunction renderSupport,
262 InternalFormat::SupportCheckFunction filterSupport)
263{
264 InternalFormat formatInfo;
265 formatInfo.redBits = red;
266 formatInfo.greenBits = green;
267 formatInfo.blueBits = blue;
268 formatInfo.alphaBits = alpha;
269 formatInfo.sharedBits = shared;
270 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
271 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
272 formatInfo.format = format;
273 formatInfo.type = type;
274 formatInfo.componentType = componentType;
275 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
276 formatInfo.textureSupport = textureSupport;
277 formatInfo.renderSupport = renderSupport;
278 formatInfo.filterSupport = filterSupport;
279 return formatInfo;
280}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000281
Geoff Lang5d601382014-07-22 15:14:06 -0400282static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
283 InternalFormat::SupportCheckFunction textureSupport,
284 InternalFormat::SupportCheckFunction renderSupport,
285 InternalFormat::SupportCheckFunction filterSupport)
286{
287 InternalFormat formatInfo;
288 formatInfo.luminanceBits = luminance;
289 formatInfo.alphaBits = alpha;
290 formatInfo.pixelBytes = (luminance + alpha) / 8;
291 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
292 formatInfo.format = format;
293 formatInfo.type = type;
294 formatInfo.componentType = componentType;
295 formatInfo.colorEncoding = GL_LINEAR;
296 formatInfo.textureSupport = textureSupport;
297 formatInfo.renderSupport = renderSupport;
298 formatInfo.filterSupport = filterSupport;
299 return formatInfo;
300}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301
Geoff Lang5d601382014-07-22 15:14:06 -0400302static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
303 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
304 InternalFormat::SupportCheckFunction renderSupport,
305 InternalFormat::SupportCheckFunction filterSupport)
306{
307 InternalFormat formatInfo;
308 formatInfo.depthBits = depthBits;
309 formatInfo.stencilBits = stencilBits;
310 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
311 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
312 formatInfo.format = format;
313 formatInfo.type = type;
314 formatInfo.componentType = componentType;
315 formatInfo.colorEncoding = GL_LINEAR;
316 formatInfo.textureSupport = textureSupport;
317 formatInfo.renderSupport = renderSupport;
318 formatInfo.filterSupport = filterSupport;
319 return formatInfo;
320}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000321
Geoff Lang5d601382014-07-22 15:14:06 -0400322static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
323 GLuint componentCount, GLenum format, GLenum type, bool srgb,
324 InternalFormat::SupportCheckFunction textureSupport,
325 InternalFormat::SupportCheckFunction renderSupport,
326 InternalFormat::SupportCheckFunction filterSupport)
327{
328 InternalFormat formatInfo;
329 formatInfo.compressedBlockWidth = compressedBlockWidth;
330 formatInfo.compressedBlockHeight = compressedBlockHeight;
331 formatInfo.pixelBytes = compressedBlockSize / 8;
332 formatInfo.componentCount = componentCount;
333 formatInfo.format = format;
334 formatInfo.type = type;
335 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
336 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
337 formatInfo.compressed = true;
338 formatInfo.textureSupport = textureSupport;
339 formatInfo.renderSupport = renderSupport;
340 formatInfo.filterSupport = filterSupport;
341 return formatInfo;
342}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000343
Geoff Lang5d601382014-07-22 15:14:06 -0400344typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
345typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000346
Geoff Lange4a492b2014-06-19 14:14:41 -0400347static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000348{
349 InternalFormatInfoMap map;
350
Geoff Lang9bbad182015-09-04 11:07:29 -0400351 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000352 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400353 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000354
Geoff Langabce7622014-09-19 16:13:00 -0400355 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
356 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)));
357 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
358 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)));
359 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
360 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)));
361 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
362 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)));
363 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)));
364 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)));
365 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)));
366 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
367 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 -0400368 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 -0400369 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)));
370 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)));
371 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)));
372 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)));
373 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
374 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)));
375 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
376 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)));
377 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
378 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)));
379 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
380 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)));
381 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
382 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)));
383 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
384 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)));
385 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
386 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)));
387 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
388 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)));
389 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
390 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)));
391 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
392 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)));
393 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
394 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)));
395 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
396 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 +0000397
Geoff Langabce7622014-09-19 16:13:00 -0400398 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)));
399 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)));
400 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 +0000401
402 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langabce7622014-09-19 16:13:00 -0400403 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
404 // | | | | | | | type | | | | |
405 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>)));
406 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureHalfFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureHalfFloatLinear>)));
407 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>)));
408 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireESOrExt<3, &Extensions::textureHalfFloat>, RequireExt<&Extensions::textureHalfFloatLinear>)));
409 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear> )));
410 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireESOrExtAndExt<3, &Extensions::textureFloat, &Extensions::textureRG>, RequireExt<&Extensions::textureFloatLinear> )));
411 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureFloat>, RequireESOrExt<3, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear> )));
412 map.insert(InternalFormatInfoPair(GL_RGBA32F, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, &Extensions::textureFloat>, RequireESOrExt<3, &Extensions::textureFloat>, RequireExt<&Extensions::textureFloatLinear> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000413
414 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400415 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
416 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>)));
417 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>)));
418 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>)));
419 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::depthTextures>, RequireExt<&Extensions::depthTextures>, AlwaysSupported )));
420 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 )));
421 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 -0800422 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000423
424 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400425 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400426 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
427 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
428 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
429 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
430 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
431 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
432 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
433 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
434 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 +0000435
436 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400437 // | Internal format | | Format | Supported | Renderable | Filterable |
438 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
439 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
440 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
441 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
442 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
443 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
444 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
445 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
446 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
447 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
448 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
449 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
450 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
451 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
452 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
453 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 +0000454
455 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400456 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
457 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
458 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)));
459 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
460 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)));
461 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
462 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
463 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)));
464 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)));
465 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)));
466 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 +0000467
468 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400469 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
470 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)));
471 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 +0000472
473 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400474 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 +0000475
476 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400477 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)));
478
479 // From GL_OES_compressed_ETC1_RGB8_texture
480 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 +0000481
Geoff Lang60ad73d2015-10-23 10:08:44 -0400482 // From KHR_texture_compression_astc_hdr
483 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
484 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)));
485 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)));
486 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)));
487 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)));
488 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)));
489 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)));
490 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)));
491 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)));
492 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)));
493 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)));
494 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)));
495 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)));
496 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)));
497 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)));
498
499 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)));
500 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)));
501 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)));
502 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)));
503 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)));
504 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)));
505 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)));
506 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)));
507 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)));
508 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)));
509 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)));
510 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)));
511 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)));
512 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)));
513
Corentin Walleze0902642014-11-04 12:32:15 -0800514 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
515 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
516 // - All other stencil formats (all depth-stencil) are either float or normalized
517 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
518 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
519 map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, DepthStencilFormat(0, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported)));
Geoff Lang9bbad182015-09-04 11:07:29 -0400520 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800521
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000522 return map;
523}
524
Geoff Lange4a492b2014-06-19 14:14:41 -0400525static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000526{
Geoff Lange4a492b2014-06-19 14:14:41 -0400527 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
528 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000529}
530
Geoff Lange4a492b2014-06-19 14:14:41 -0400531static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400532{
533 FormatSet result;
534
Geoff Lange4a492b2014-06-19 14:14:41 -0400535 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400536 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
537 {
Geoff Lang5d601382014-07-22 15:14:06 -0400538 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400539 {
540 result.insert(i->first);
541 }
542 }
543
544 return result;
545}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000546
Geoff Lang5d601382014-07-22 15:14:06 -0400547const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000548{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200549 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000550 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200551 case GL_UNSIGNED_BYTE:
552 case GL_BYTE:
553 {
554 static const Type info = GenTypeInfo(1, false);
555 return info;
556 }
557 case GL_UNSIGNED_SHORT:
558 case GL_SHORT:
559 case GL_HALF_FLOAT:
560 case GL_HALF_FLOAT_OES:
561 {
562 static const Type info = GenTypeInfo(2, false);
563 return info;
564 }
565 case GL_UNSIGNED_INT:
566 case GL_INT:
567 case GL_FLOAT:
568 {
569 static const Type info = GenTypeInfo(4, false);
570 return info;
571 }
572 case GL_UNSIGNED_SHORT_5_6_5:
573 case GL_UNSIGNED_SHORT_4_4_4_4:
574 case GL_UNSIGNED_SHORT_5_5_5_1:
575 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
576 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
577 {
578 static const Type info = GenTypeInfo(2, true);
579 return info;
580 }
581 case GL_UNSIGNED_INT_2_10_10_10_REV:
582 case GL_UNSIGNED_INT_24_8:
583 case GL_UNSIGNED_INT_10F_11F_11F_REV:
584 case GL_UNSIGNED_INT_5_9_9_9_REV:
585 {
586 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
587 static const Type info = GenTypeInfo(4, true);
588 return info;
589 }
590 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
591 {
592 static const Type info = GenTypeInfo(8, true);
593 return info;
594 }
595 default:
596 {
597 static const Type defaultInfo;
598 return defaultInfo;
599 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000600 }
601}
602
Geoff Lang5d601382014-07-22 15:14:06 -0400603const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000604{
Geoff Lang5d601382014-07-22 15:14:06 -0400605 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
606 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
607 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000608 {
Geoff Lang5d601382014-07-22 15:14:06 -0400609 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000610 }
611 else
612 {
Geoff Lang5d601382014-07-22 15:14:06 -0400613 static const InternalFormat defaultInternalFormat;
614 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000615 }
616}
617
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800618GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000619{
620 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800621 GLuint rowBytes;
622 if (rowLength > 0)
623 {
624 ASSERT(!compressed);
625 rowBytes = pixelBytes * rowLength;
626 }
627 else
628 {
629 rowBytes = computeBlockSize(formatType, width, 1);
630 }
631 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000632}
633
Minmin Gongadff67b2015-10-14 10:34:45 -0400634GLuint InternalFormat::computeDepthPitch(GLenum formatType,
635 GLsizei width,
636 GLsizei height,
637 GLint alignment,
638 GLint rowLength,
639 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640{
Minmin Gongadff67b2015-10-14 10:34:45 -0400641 GLuint rows;
642 if (imageHeight > 0)
643 {
644 rows = imageHeight;
645 }
646 else
647 {
648 rows = height;
649 }
650 return computeRowPitch(formatType, width, alignment, rowLength) * rows;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000651}
652
Austin Kinross3ae64652015-01-26 15:51:39 -0800653GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000654{
Geoff Lang5d601382014-07-22 15:14:06 -0400655 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656 {
Geoff Lang5d601382014-07-22 15:14:06 -0400657 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
658 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
659 return (pixelBytes * numBlocksWide * numBlocksHight);
660 }
661 else
662 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800663 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400664 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000665 {
Geoff Lang5d601382014-07-22 15:14:06 -0400666 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000667 }
668 else
669 {
Geoff Lang5d601382014-07-22 15:14:06 -0400670 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000671 }
672 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000673}
674
Minmin Gongadff67b2015-10-14 10:34:45 -0400675GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
676 GLint depthPitch,
677 GLint skipImages,
678 GLint skipRows,
679 GLint skipPixels) const
680{
681 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
682}
683
Geoff Lang5d601382014-07-22 15:14:06 -0400684GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000685{
Geoff Lang5d601382014-07-22 15:14:06 -0400686 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500687 if (formatInfo.pixelBytes > 0)
688 {
689 return internalFormat;
690 }
691 else
692 {
693 static const FormatMap formatMap = BuildFormatMap();
694 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
695 if (iter != formatMap.end())
696 {
697 return iter->second;
698 }
699 else
700 {
701 return GL_NONE;
702 }
703 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000704}
705
Geoff Lange4a492b2014-06-19 14:14:41 -0400706const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400707{
Geoff Lange4a492b2014-06-19 14:14:41 -0400708 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400709 return formatSet;
710}
711
Jamie Madill09e2d932015-07-14 16:40:31 -0400712AttributeType GetAttributeType(GLenum enumValue)
713{
714 switch (enumValue)
715 {
716 case GL_FLOAT:
717 return ATTRIBUTE_FLOAT;
718 case GL_FLOAT_VEC2:
719 return ATTRIBUTE_VEC2;
720 case GL_FLOAT_VEC3:
721 return ATTRIBUTE_VEC3;
722 case GL_FLOAT_VEC4:
723 return ATTRIBUTE_VEC4;
724 case GL_INT:
725 return ATTRIBUTE_INT;
726 case GL_INT_VEC2:
727 return ATTRIBUTE_IVEC2;
728 case GL_INT_VEC3:
729 return ATTRIBUTE_IVEC3;
730 case GL_INT_VEC4:
731 return ATTRIBUTE_IVEC4;
732 case GL_UNSIGNED_INT:
733 return ATTRIBUTE_UINT;
734 case GL_UNSIGNED_INT_VEC2:
735 return ATTRIBUTE_UVEC2;
736 case GL_UNSIGNED_INT_VEC3:
737 return ATTRIBUTE_UVEC3;
738 case GL_UNSIGNED_INT_VEC4:
739 return ATTRIBUTE_UVEC4;
740 case GL_FLOAT_MAT2:
741 return ATTRIBUTE_MAT2;
742 case GL_FLOAT_MAT3:
743 return ATTRIBUTE_MAT3;
744 case GL_FLOAT_MAT4:
745 return ATTRIBUTE_MAT4;
746 case GL_FLOAT_MAT2x3:
747 return ATTRIBUTE_MAT2x3;
748 case GL_FLOAT_MAT2x4:
749 return ATTRIBUTE_MAT2x4;
750 case GL_FLOAT_MAT3x2:
751 return ATTRIBUTE_MAT3x2;
752 case GL_FLOAT_MAT3x4:
753 return ATTRIBUTE_MAT3x4;
754 case GL_FLOAT_MAT4x2:
755 return ATTRIBUTE_MAT4x2;
756 case GL_FLOAT_MAT4x3:
757 return ATTRIBUTE_MAT4x3;
758 default:
759 UNREACHABLE();
760 return ATTRIBUTE_FLOAT;
761 }
762}
763
Jamie Madilld3dfda22015-07-06 08:28:49 -0400764VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
765{
766 switch (type)
767 {
768 case GL_BYTE:
769 switch (components)
770 {
771 case 1:
772 if (pureInteger)
773 return VERTEX_FORMAT_SBYTE1_INT;
774 if (normalized)
775 return VERTEX_FORMAT_SBYTE1_NORM;
776 return VERTEX_FORMAT_SBYTE1;
777 case 2:
778 if (pureInteger)
779 return VERTEX_FORMAT_SBYTE2_INT;
780 if (normalized)
781 return VERTEX_FORMAT_SBYTE2_NORM;
782 return VERTEX_FORMAT_SBYTE2;
783 case 3:
784 if (pureInteger)
785 return VERTEX_FORMAT_SBYTE3_INT;
786 if (normalized)
787 return VERTEX_FORMAT_SBYTE3_NORM;
788 return VERTEX_FORMAT_SBYTE3;
789 case 4:
790 if (pureInteger)
791 return VERTEX_FORMAT_SBYTE4_INT;
792 if (normalized)
793 return VERTEX_FORMAT_SBYTE4_NORM;
794 return VERTEX_FORMAT_SBYTE4;
795 default:
796 UNREACHABLE();
797 break;
798 }
799 case GL_UNSIGNED_BYTE:
800 switch (components)
801 {
802 case 1:
803 if (pureInteger)
804 return VERTEX_FORMAT_UBYTE1_INT;
805 if (normalized)
806 return VERTEX_FORMAT_UBYTE1_NORM;
807 return VERTEX_FORMAT_UBYTE1;
808 case 2:
809 if (pureInteger)
810 return VERTEX_FORMAT_UBYTE2_INT;
811 if (normalized)
812 return VERTEX_FORMAT_UBYTE2_NORM;
813 return VERTEX_FORMAT_UBYTE2;
814 case 3:
815 if (pureInteger)
816 return VERTEX_FORMAT_UBYTE3_INT;
817 if (normalized)
818 return VERTEX_FORMAT_UBYTE3_NORM;
819 return VERTEX_FORMAT_UBYTE3;
820 case 4:
821 if (pureInteger)
822 return VERTEX_FORMAT_UBYTE4_INT;
823 if (normalized)
824 return VERTEX_FORMAT_UBYTE4_NORM;
825 return VERTEX_FORMAT_UBYTE4;
826 default:
827 UNREACHABLE();
828 break;
829 }
830 case GL_SHORT:
831 switch (components)
832 {
833 case 1:
834 if (pureInteger)
835 return VERTEX_FORMAT_SSHORT1_INT;
836 if (normalized)
837 return VERTEX_FORMAT_SSHORT1_NORM;
838 return VERTEX_FORMAT_SSHORT1;
839 case 2:
840 if (pureInteger)
841 return VERTEX_FORMAT_SSHORT2_INT;
842 if (normalized)
843 return VERTEX_FORMAT_SSHORT2_NORM;
844 return VERTEX_FORMAT_SSHORT2;
845 case 3:
846 if (pureInteger)
847 return VERTEX_FORMAT_SSHORT3_INT;
848 if (normalized)
849 return VERTEX_FORMAT_SSHORT3_NORM;
850 return VERTEX_FORMAT_SSHORT3;
851 case 4:
852 if (pureInteger)
853 return VERTEX_FORMAT_SSHORT4_INT;
854 if (normalized)
855 return VERTEX_FORMAT_SSHORT4_NORM;
856 return VERTEX_FORMAT_SSHORT4;
857 default:
858 UNREACHABLE();
859 break;
860 }
861 case GL_UNSIGNED_SHORT:
862 switch (components)
863 {
864 case 1:
865 if (pureInteger)
866 return VERTEX_FORMAT_USHORT1_INT;
867 if (normalized)
868 return VERTEX_FORMAT_USHORT1_NORM;
869 return VERTEX_FORMAT_USHORT1;
870 case 2:
871 if (pureInteger)
872 return VERTEX_FORMAT_USHORT2_INT;
873 if (normalized)
874 return VERTEX_FORMAT_USHORT2_NORM;
875 return VERTEX_FORMAT_USHORT2;
876 case 3:
877 if (pureInteger)
878 return VERTEX_FORMAT_USHORT3_INT;
879 if (normalized)
880 return VERTEX_FORMAT_USHORT3_NORM;
881 return VERTEX_FORMAT_USHORT3;
882 case 4:
883 if (pureInteger)
884 return VERTEX_FORMAT_USHORT4_INT;
885 if (normalized)
886 return VERTEX_FORMAT_USHORT4_NORM;
887 return VERTEX_FORMAT_USHORT4;
888 default:
889 UNREACHABLE();
890 break;
891 }
892 case GL_INT:
893 switch (components)
894 {
895 case 1:
896 if (pureInteger)
897 return VERTEX_FORMAT_SINT1_INT;
898 if (normalized)
899 return VERTEX_FORMAT_SINT1_NORM;
900 return VERTEX_FORMAT_SINT1;
901 case 2:
902 if (pureInteger)
903 return VERTEX_FORMAT_SINT2_INT;
904 if (normalized)
905 return VERTEX_FORMAT_SINT2_NORM;
906 return VERTEX_FORMAT_SINT2;
907 case 3:
908 if (pureInteger)
909 return VERTEX_FORMAT_SINT3_INT;
910 if (normalized)
911 return VERTEX_FORMAT_SINT3_NORM;
912 return VERTEX_FORMAT_SINT3;
913 case 4:
914 if (pureInteger)
915 return VERTEX_FORMAT_SINT4_INT;
916 if (normalized)
917 return VERTEX_FORMAT_SINT4_NORM;
918 return VERTEX_FORMAT_SINT4;
919 default:
920 UNREACHABLE();
921 break;
922 }
923 case GL_UNSIGNED_INT:
924 switch (components)
925 {
926 case 1:
927 if (pureInteger)
928 return VERTEX_FORMAT_UINT1_INT;
929 if (normalized)
930 return VERTEX_FORMAT_UINT1_NORM;
931 return VERTEX_FORMAT_UINT1;
932 case 2:
933 if (pureInteger)
934 return VERTEX_FORMAT_UINT2_INT;
935 if (normalized)
936 return VERTEX_FORMAT_UINT2_NORM;
937 return VERTEX_FORMAT_UINT2;
938 case 3:
939 if (pureInteger)
940 return VERTEX_FORMAT_UINT3_INT;
941 if (normalized)
942 return VERTEX_FORMAT_UINT3_NORM;
943 return VERTEX_FORMAT_UINT3;
944 case 4:
945 if (pureInteger)
946 return VERTEX_FORMAT_UINT4_INT;
947 if (normalized)
948 return VERTEX_FORMAT_UINT4_NORM;
949 return VERTEX_FORMAT_UINT4;
950 default:
951 UNREACHABLE();
952 break;
953 }
954 case GL_FLOAT:
955 switch (components)
956 {
957 case 1:
958 return VERTEX_FORMAT_FLOAT1;
959 case 2:
960 return VERTEX_FORMAT_FLOAT2;
961 case 3:
962 return VERTEX_FORMAT_FLOAT3;
963 case 4:
964 return VERTEX_FORMAT_FLOAT4;
965 default:
966 UNREACHABLE();
967 break;
968 }
969 case GL_HALF_FLOAT:
970 switch (components)
971 {
972 case 1:
973 return VERTEX_FORMAT_HALF1;
974 case 2:
975 return VERTEX_FORMAT_HALF2;
976 case 3:
977 return VERTEX_FORMAT_HALF3;
978 case 4:
979 return VERTEX_FORMAT_HALF4;
980 default:
981 UNREACHABLE();
982 break;
983 }
984 case GL_FIXED:
985 switch (components)
986 {
987 case 1:
988 return VERTEX_FORMAT_FIXED1;
989 case 2:
990 return VERTEX_FORMAT_FIXED2;
991 case 3:
992 return VERTEX_FORMAT_FIXED3;
993 case 4:
994 return VERTEX_FORMAT_FIXED4;
995 default:
996 UNREACHABLE();
997 break;
998 }
999 case GL_INT_2_10_10_10_REV:
1000 if (pureInteger)
1001 return VERTEX_FORMAT_SINT210_INT;
1002 if (normalized)
1003 return VERTEX_FORMAT_SINT210_NORM;
1004 return VERTEX_FORMAT_SINT210;
1005 case GL_UNSIGNED_INT_2_10_10_10_REV:
1006 if (pureInteger)
1007 return VERTEX_FORMAT_UINT210_INT;
1008 if (normalized)
1009 return VERTEX_FORMAT_UINT210_NORM;
1010 return VERTEX_FORMAT_UINT210;
1011 default:
1012 UNREACHABLE();
1013 break;
1014 }
1015 return VERTEX_FORMAT_UBYTE1;
1016}
1017
1018VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1019{
1020 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1021}
1022
1023VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1024{
1025 if (!attrib.enabled)
1026 {
1027 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1028 }
1029 return GetVertexFormatType(attrib);
1030}
1031
1032const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1033{
1034 switch (vertexFormatType)
1035 {
1036 case VERTEX_FORMAT_SBYTE1:
1037 {
1038 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1039 return format;
1040 }
1041 case VERTEX_FORMAT_SBYTE1_NORM:
1042 {
1043 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1044 return format;
1045 }
1046 case VERTEX_FORMAT_SBYTE2:
1047 {
1048 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1049 return format;
1050 }
1051 case VERTEX_FORMAT_SBYTE2_NORM:
1052 {
1053 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1054 return format;
1055 }
1056 case VERTEX_FORMAT_SBYTE3:
1057 {
1058 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1059 return format;
1060 }
1061 case VERTEX_FORMAT_SBYTE3_NORM:
1062 {
1063 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1064 return format;
1065 }
1066 case VERTEX_FORMAT_SBYTE4:
1067 {
1068 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1069 return format;
1070 }
1071 case VERTEX_FORMAT_SBYTE4_NORM:
1072 {
1073 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1074 return format;
1075 }
1076 case VERTEX_FORMAT_UBYTE1:
1077 {
1078 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1079 return format;
1080 }
1081 case VERTEX_FORMAT_UBYTE1_NORM:
1082 {
1083 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1084 return format;
1085 }
1086 case VERTEX_FORMAT_UBYTE2:
1087 {
1088 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1089 return format;
1090 }
1091 case VERTEX_FORMAT_UBYTE2_NORM:
1092 {
1093 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1094 return format;
1095 }
1096 case VERTEX_FORMAT_UBYTE3:
1097 {
1098 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1099 return format;
1100 }
1101 case VERTEX_FORMAT_UBYTE3_NORM:
1102 {
1103 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1104 return format;
1105 }
1106 case VERTEX_FORMAT_UBYTE4:
1107 {
1108 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1109 return format;
1110 }
1111 case VERTEX_FORMAT_UBYTE4_NORM:
1112 {
1113 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1114 return format;
1115 }
1116 case VERTEX_FORMAT_SSHORT1:
1117 {
1118 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1119 return format;
1120 }
1121 case VERTEX_FORMAT_SSHORT1_NORM:
1122 {
1123 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1124 return format;
1125 }
1126 case VERTEX_FORMAT_SSHORT2:
1127 {
1128 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1129 return format;
1130 }
1131 case VERTEX_FORMAT_SSHORT2_NORM:
1132 {
1133 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1134 return format;
1135 }
1136 case VERTEX_FORMAT_SSHORT3:
1137 {
1138 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1139 return format;
1140 }
1141 case VERTEX_FORMAT_SSHORT3_NORM:
1142 {
1143 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1144 return format;
1145 }
1146 case VERTEX_FORMAT_SSHORT4:
1147 {
1148 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1149 return format;
1150 }
1151 case VERTEX_FORMAT_SSHORT4_NORM:
1152 {
1153 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1154 return format;
1155 }
1156 case VERTEX_FORMAT_USHORT1:
1157 {
1158 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1159 return format;
1160 }
1161 case VERTEX_FORMAT_USHORT1_NORM:
1162 {
1163 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1164 return format;
1165 }
1166 case VERTEX_FORMAT_USHORT2:
1167 {
1168 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1169 return format;
1170 }
1171 case VERTEX_FORMAT_USHORT2_NORM:
1172 {
1173 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1174 return format;
1175 }
1176 case VERTEX_FORMAT_USHORT3:
1177 {
1178 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1179 return format;
1180 }
1181 case VERTEX_FORMAT_USHORT3_NORM:
1182 {
1183 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1184 return format;
1185 }
1186 case VERTEX_FORMAT_USHORT4:
1187 {
1188 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1189 return format;
1190 }
1191 case VERTEX_FORMAT_USHORT4_NORM:
1192 {
1193 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1194 return format;
1195 }
1196 case VERTEX_FORMAT_SINT1:
1197 {
1198 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1199 return format;
1200 }
1201 case VERTEX_FORMAT_SINT1_NORM:
1202 {
1203 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1204 return format;
1205 }
1206 case VERTEX_FORMAT_SINT2:
1207 {
1208 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1209 return format;
1210 }
1211 case VERTEX_FORMAT_SINT2_NORM:
1212 {
1213 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1214 return format;
1215 }
1216 case VERTEX_FORMAT_SINT3:
1217 {
1218 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1219 return format;
1220 }
1221 case VERTEX_FORMAT_SINT3_NORM:
1222 {
1223 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1224 return format;
1225 }
1226 case VERTEX_FORMAT_SINT4:
1227 {
1228 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1229 return format;
1230 }
1231 case VERTEX_FORMAT_SINT4_NORM:
1232 {
1233 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1234 return format;
1235 }
1236 case VERTEX_FORMAT_UINT1:
1237 {
1238 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1239 return format;
1240 }
1241 case VERTEX_FORMAT_UINT1_NORM:
1242 {
1243 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1244 return format;
1245 }
1246 case VERTEX_FORMAT_UINT2:
1247 {
1248 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1249 return format;
1250 }
1251 case VERTEX_FORMAT_UINT2_NORM:
1252 {
1253 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1254 return format;
1255 }
1256 case VERTEX_FORMAT_UINT3:
1257 {
1258 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1259 return format;
1260 }
1261 case VERTEX_FORMAT_UINT3_NORM:
1262 {
1263 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1264 return format;
1265 }
1266 case VERTEX_FORMAT_UINT4:
1267 {
1268 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1269 return format;
1270 }
1271 case VERTEX_FORMAT_UINT4_NORM:
1272 {
1273 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1274 return format;
1275 }
1276 case VERTEX_FORMAT_SBYTE1_INT:
1277 {
1278 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1279 return format;
1280 }
1281 case VERTEX_FORMAT_SBYTE2_INT:
1282 {
1283 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1284 return format;
1285 }
1286 case VERTEX_FORMAT_SBYTE3_INT:
1287 {
1288 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1289 return format;
1290 }
1291 case VERTEX_FORMAT_SBYTE4_INT:
1292 {
1293 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1294 return format;
1295 }
1296 case VERTEX_FORMAT_UBYTE1_INT:
1297 {
1298 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1299 return format;
1300 }
1301 case VERTEX_FORMAT_UBYTE2_INT:
1302 {
1303 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1304 return format;
1305 }
1306 case VERTEX_FORMAT_UBYTE3_INT:
1307 {
1308 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1309 return format;
1310 }
1311 case VERTEX_FORMAT_UBYTE4_INT:
1312 {
1313 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1314 return format;
1315 }
1316 case VERTEX_FORMAT_SSHORT1_INT:
1317 {
1318 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1319 return format;
1320 }
1321 case VERTEX_FORMAT_SSHORT2_INT:
1322 {
1323 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1324 return format;
1325 }
1326 case VERTEX_FORMAT_SSHORT3_INT:
1327 {
1328 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1329 return format;
1330 }
1331 case VERTEX_FORMAT_SSHORT4_INT:
1332 {
1333 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1334 return format;
1335 }
1336 case VERTEX_FORMAT_USHORT1_INT:
1337 {
1338 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1339 return format;
1340 }
1341 case VERTEX_FORMAT_USHORT2_INT:
1342 {
1343 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1344 return format;
1345 }
1346 case VERTEX_FORMAT_USHORT3_INT:
1347 {
1348 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1349 return format;
1350 }
1351 case VERTEX_FORMAT_USHORT4_INT:
1352 {
1353 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1354 return format;
1355 }
1356 case VERTEX_FORMAT_SINT1_INT:
1357 {
1358 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1359 return format;
1360 }
1361 case VERTEX_FORMAT_SINT2_INT:
1362 {
1363 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1364 return format;
1365 }
1366 case VERTEX_FORMAT_SINT3_INT:
1367 {
1368 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1369 return format;
1370 }
1371 case VERTEX_FORMAT_SINT4_INT:
1372 {
1373 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1374 return format;
1375 }
1376 case VERTEX_FORMAT_UINT1_INT:
1377 {
1378 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1379 return format;
1380 }
1381 case VERTEX_FORMAT_UINT2_INT:
1382 {
1383 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1384 return format;
1385 }
1386 case VERTEX_FORMAT_UINT3_INT:
1387 {
1388 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1389 return format;
1390 }
1391 case VERTEX_FORMAT_UINT4_INT:
1392 {
1393 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1394 return format;
1395 }
1396 case VERTEX_FORMAT_FIXED1:
1397 {
1398 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1399 return format;
1400 }
1401 case VERTEX_FORMAT_FIXED2:
1402 {
1403 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1404 return format;
1405 }
1406 case VERTEX_FORMAT_FIXED3:
1407 {
1408 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1409 return format;
1410 }
1411 case VERTEX_FORMAT_FIXED4:
1412 {
1413 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1414 return format;
1415 }
1416 case VERTEX_FORMAT_HALF1:
1417 {
1418 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1419 return format;
1420 }
1421 case VERTEX_FORMAT_HALF2:
1422 {
1423 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1424 return format;
1425 }
1426 case VERTEX_FORMAT_HALF3:
1427 {
1428 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1429 return format;
1430 }
1431 case VERTEX_FORMAT_HALF4:
1432 {
1433 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1434 return format;
1435 }
1436 case VERTEX_FORMAT_FLOAT1:
1437 {
1438 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1439 return format;
1440 }
1441 case VERTEX_FORMAT_FLOAT2:
1442 {
1443 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1444 return format;
1445 }
1446 case VERTEX_FORMAT_FLOAT3:
1447 {
1448 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1449 return format;
1450 }
1451 case VERTEX_FORMAT_FLOAT4:
1452 {
1453 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1454 return format;
1455 }
1456 case VERTEX_FORMAT_SINT210:
1457 {
1458 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1459 return format;
1460 }
1461 case VERTEX_FORMAT_UINT210:
1462 {
1463 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1464 return format;
1465 }
1466 case VERTEX_FORMAT_SINT210_NORM:
1467 {
1468 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1469 return format;
1470 }
1471 case VERTEX_FORMAT_UINT210_NORM:
1472 {
1473 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1474 return format;
1475 }
1476 case VERTEX_FORMAT_SINT210_INT:
1477 {
1478 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1479 return format;
1480 }
1481 case VERTEX_FORMAT_UINT210_INT:
1482 {
1483 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1484 return format;
1485 }
1486 default:
1487 {
1488 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1489 return format;
1490 }
1491 }
1492}
1493
1494VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1495 : type(typeIn),
1496 normalized(normalizedIn),
1497 components(componentsIn),
1498 pureInteger(pureIntegerIn)
1499{
1500 // float -> !normalized
1501 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1502}
1503
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001504}