blob: 6d1207666fc0842695a99b4993b5d6a8666a266a [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 Lang3bd6e182015-09-22 09:30:02 -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
Zhenyao Mo1170e472015-09-11 21:48:20 +0000469 // | 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
Zhenyao Mo1170e472015-09-11 21:48:20 +0000474 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
Zhenyao Mo1170e472015-09-11 21:48:20 +0000477 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported)));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000478
Geoff Lang3bd6e182015-09-22 09:30:02 -0400479 // From KHR_texture_compression_astc_hdr
480 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
481 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)));
482 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)));
483 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)));
484 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)));
485 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)));
486 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)));
487 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)));
488 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)));
489 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)));
490 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)));
491 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)));
492 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)));
493 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)));
494 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)));
495
496 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)));
497 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)));
498 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)));
499 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)));
500 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)));
501 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)));
502 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)));
503 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)));
504 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)));
505 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)));
506 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)));
507 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)));
508 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)));
509 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)));
510
Corentin Walleze0902642014-11-04 12:32:15 -0800511 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
512 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
513 // - All other stencil formats (all depth-stencil) are either float or normalized
514 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
515 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
516 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 -0400517 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800518
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000519 return map;
520}
521
Geoff Lange4a492b2014-06-19 14:14:41 -0400522static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000523{
Geoff Lange4a492b2014-06-19 14:14:41 -0400524 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
525 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000526}
527
Geoff Lange4a492b2014-06-19 14:14:41 -0400528static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400529{
530 FormatSet result;
531
Geoff Lange4a492b2014-06-19 14:14:41 -0400532 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400533 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
534 {
Geoff Lang5d601382014-07-22 15:14:06 -0400535 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400536 {
537 result.insert(i->first);
538 }
539 }
540
541 return result;
542}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000543
Geoff Lang5d601382014-07-22 15:14:06 -0400544const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000545{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200546 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000547 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200548 case GL_UNSIGNED_BYTE:
549 case GL_BYTE:
550 {
551 static const Type info = GenTypeInfo(1, false);
552 return info;
553 }
554 case GL_UNSIGNED_SHORT:
555 case GL_SHORT:
556 case GL_HALF_FLOAT:
557 case GL_HALF_FLOAT_OES:
558 {
559 static const Type info = GenTypeInfo(2, false);
560 return info;
561 }
562 case GL_UNSIGNED_INT:
563 case GL_INT:
564 case GL_FLOAT:
565 {
566 static const Type info = GenTypeInfo(4, false);
567 return info;
568 }
569 case GL_UNSIGNED_SHORT_5_6_5:
570 case GL_UNSIGNED_SHORT_4_4_4_4:
571 case GL_UNSIGNED_SHORT_5_5_5_1:
572 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
573 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
574 {
575 static const Type info = GenTypeInfo(2, true);
576 return info;
577 }
578 case GL_UNSIGNED_INT_2_10_10_10_REV:
579 case GL_UNSIGNED_INT_24_8:
580 case GL_UNSIGNED_INT_10F_11F_11F_REV:
581 case GL_UNSIGNED_INT_5_9_9_9_REV:
582 {
583 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
584 static const Type info = GenTypeInfo(4, true);
585 return info;
586 }
587 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
588 {
589 static const Type info = GenTypeInfo(8, true);
590 return info;
591 }
592 default:
593 {
594 static const Type defaultInfo;
595 return defaultInfo;
596 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000597 }
598}
599
Geoff Lang5d601382014-07-22 15:14:06 -0400600const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000601{
Geoff Lang5d601382014-07-22 15:14:06 -0400602 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
603 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
604 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000605 {
Geoff Lang5d601382014-07-22 15:14:06 -0400606 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000607 }
608 else
609 {
Geoff Lang5d601382014-07-22 15:14:06 -0400610 static const InternalFormat defaultInternalFormat;
611 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000612 }
613}
614
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800615GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000616{
617 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800618 GLuint rowBytes;
619 if (rowLength > 0)
620 {
621 ASSERT(!compressed);
622 rowBytes = pixelBytes * rowLength;
623 }
624 else
625 {
626 rowBytes = computeBlockSize(formatType, width, 1);
627 }
628 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000629}
630
Minmin Gongadff67b2015-10-14 10:34:45 -0400631GLuint InternalFormat::computeDepthPitch(GLenum formatType,
632 GLsizei width,
633 GLsizei height,
634 GLint alignment,
635 GLint rowLength,
636 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000637{
Minmin Gongadff67b2015-10-14 10:34:45 -0400638 GLuint rows;
639 if (imageHeight > 0)
640 {
641 rows = imageHeight;
642 }
643 else
644 {
645 rows = height;
646 }
647 return computeRowPitch(formatType, width, alignment, rowLength) * rows;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648}
649
Austin Kinross3ae64652015-01-26 15:51:39 -0800650GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000651{
Geoff Lang5d601382014-07-22 15:14:06 -0400652 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000653 {
Geoff Lang5d601382014-07-22 15:14:06 -0400654 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
655 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
656 return (pixelBytes * numBlocksWide * numBlocksHight);
657 }
658 else
659 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800660 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400661 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000662 {
Geoff Lang5d601382014-07-22 15:14:06 -0400663 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000664 }
665 else
666 {
Geoff Lang5d601382014-07-22 15:14:06 -0400667 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000668 }
669 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000670}
671
Minmin Gongadff67b2015-10-14 10:34:45 -0400672GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
673 GLint depthPitch,
674 GLint skipImages,
675 GLint skipRows,
676 GLint skipPixels) const
677{
678 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
679}
680
Geoff Lang5d601382014-07-22 15:14:06 -0400681GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000682{
Geoff Lang5d601382014-07-22 15:14:06 -0400683 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500684 if (formatInfo.pixelBytes > 0)
685 {
686 return internalFormat;
687 }
688 else
689 {
690 static const FormatMap formatMap = BuildFormatMap();
691 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
692 if (iter != formatMap.end())
693 {
694 return iter->second;
695 }
696 else
697 {
698 return GL_NONE;
699 }
700 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000701}
702
Geoff Lange4a492b2014-06-19 14:14:41 -0400703const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400704{
Geoff Lange4a492b2014-06-19 14:14:41 -0400705 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400706 return formatSet;
707}
708
Jamie Madill09e2d932015-07-14 16:40:31 -0400709AttributeType GetAttributeType(GLenum enumValue)
710{
711 switch (enumValue)
712 {
713 case GL_FLOAT:
714 return ATTRIBUTE_FLOAT;
715 case GL_FLOAT_VEC2:
716 return ATTRIBUTE_VEC2;
717 case GL_FLOAT_VEC3:
718 return ATTRIBUTE_VEC3;
719 case GL_FLOAT_VEC4:
720 return ATTRIBUTE_VEC4;
721 case GL_INT:
722 return ATTRIBUTE_INT;
723 case GL_INT_VEC2:
724 return ATTRIBUTE_IVEC2;
725 case GL_INT_VEC3:
726 return ATTRIBUTE_IVEC3;
727 case GL_INT_VEC4:
728 return ATTRIBUTE_IVEC4;
729 case GL_UNSIGNED_INT:
730 return ATTRIBUTE_UINT;
731 case GL_UNSIGNED_INT_VEC2:
732 return ATTRIBUTE_UVEC2;
733 case GL_UNSIGNED_INT_VEC3:
734 return ATTRIBUTE_UVEC3;
735 case GL_UNSIGNED_INT_VEC4:
736 return ATTRIBUTE_UVEC4;
737 case GL_FLOAT_MAT2:
738 return ATTRIBUTE_MAT2;
739 case GL_FLOAT_MAT3:
740 return ATTRIBUTE_MAT3;
741 case GL_FLOAT_MAT4:
742 return ATTRIBUTE_MAT4;
743 case GL_FLOAT_MAT2x3:
744 return ATTRIBUTE_MAT2x3;
745 case GL_FLOAT_MAT2x4:
746 return ATTRIBUTE_MAT2x4;
747 case GL_FLOAT_MAT3x2:
748 return ATTRIBUTE_MAT3x2;
749 case GL_FLOAT_MAT3x4:
750 return ATTRIBUTE_MAT3x4;
751 case GL_FLOAT_MAT4x2:
752 return ATTRIBUTE_MAT4x2;
753 case GL_FLOAT_MAT4x3:
754 return ATTRIBUTE_MAT4x3;
755 default:
756 UNREACHABLE();
757 return ATTRIBUTE_FLOAT;
758 }
759}
760
Jamie Madilld3dfda22015-07-06 08:28:49 -0400761VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
762{
763 switch (type)
764 {
765 case GL_BYTE:
766 switch (components)
767 {
768 case 1:
769 if (pureInteger)
770 return VERTEX_FORMAT_SBYTE1_INT;
771 if (normalized)
772 return VERTEX_FORMAT_SBYTE1_NORM;
773 return VERTEX_FORMAT_SBYTE1;
774 case 2:
775 if (pureInteger)
776 return VERTEX_FORMAT_SBYTE2_INT;
777 if (normalized)
778 return VERTEX_FORMAT_SBYTE2_NORM;
779 return VERTEX_FORMAT_SBYTE2;
780 case 3:
781 if (pureInteger)
782 return VERTEX_FORMAT_SBYTE3_INT;
783 if (normalized)
784 return VERTEX_FORMAT_SBYTE3_NORM;
785 return VERTEX_FORMAT_SBYTE3;
786 case 4:
787 if (pureInteger)
788 return VERTEX_FORMAT_SBYTE4_INT;
789 if (normalized)
790 return VERTEX_FORMAT_SBYTE4_NORM;
791 return VERTEX_FORMAT_SBYTE4;
792 default:
793 UNREACHABLE();
794 break;
795 }
796 case GL_UNSIGNED_BYTE:
797 switch (components)
798 {
799 case 1:
800 if (pureInteger)
801 return VERTEX_FORMAT_UBYTE1_INT;
802 if (normalized)
803 return VERTEX_FORMAT_UBYTE1_NORM;
804 return VERTEX_FORMAT_UBYTE1;
805 case 2:
806 if (pureInteger)
807 return VERTEX_FORMAT_UBYTE2_INT;
808 if (normalized)
809 return VERTEX_FORMAT_UBYTE2_NORM;
810 return VERTEX_FORMAT_UBYTE2;
811 case 3:
812 if (pureInteger)
813 return VERTEX_FORMAT_UBYTE3_INT;
814 if (normalized)
815 return VERTEX_FORMAT_UBYTE3_NORM;
816 return VERTEX_FORMAT_UBYTE3;
817 case 4:
818 if (pureInteger)
819 return VERTEX_FORMAT_UBYTE4_INT;
820 if (normalized)
821 return VERTEX_FORMAT_UBYTE4_NORM;
822 return VERTEX_FORMAT_UBYTE4;
823 default:
824 UNREACHABLE();
825 break;
826 }
827 case GL_SHORT:
828 switch (components)
829 {
830 case 1:
831 if (pureInteger)
832 return VERTEX_FORMAT_SSHORT1_INT;
833 if (normalized)
834 return VERTEX_FORMAT_SSHORT1_NORM;
835 return VERTEX_FORMAT_SSHORT1;
836 case 2:
837 if (pureInteger)
838 return VERTEX_FORMAT_SSHORT2_INT;
839 if (normalized)
840 return VERTEX_FORMAT_SSHORT2_NORM;
841 return VERTEX_FORMAT_SSHORT2;
842 case 3:
843 if (pureInteger)
844 return VERTEX_FORMAT_SSHORT3_INT;
845 if (normalized)
846 return VERTEX_FORMAT_SSHORT3_NORM;
847 return VERTEX_FORMAT_SSHORT3;
848 case 4:
849 if (pureInteger)
850 return VERTEX_FORMAT_SSHORT4_INT;
851 if (normalized)
852 return VERTEX_FORMAT_SSHORT4_NORM;
853 return VERTEX_FORMAT_SSHORT4;
854 default:
855 UNREACHABLE();
856 break;
857 }
858 case GL_UNSIGNED_SHORT:
859 switch (components)
860 {
861 case 1:
862 if (pureInteger)
863 return VERTEX_FORMAT_USHORT1_INT;
864 if (normalized)
865 return VERTEX_FORMAT_USHORT1_NORM;
866 return VERTEX_FORMAT_USHORT1;
867 case 2:
868 if (pureInteger)
869 return VERTEX_FORMAT_USHORT2_INT;
870 if (normalized)
871 return VERTEX_FORMAT_USHORT2_NORM;
872 return VERTEX_FORMAT_USHORT2;
873 case 3:
874 if (pureInteger)
875 return VERTEX_FORMAT_USHORT3_INT;
876 if (normalized)
877 return VERTEX_FORMAT_USHORT3_NORM;
878 return VERTEX_FORMAT_USHORT3;
879 case 4:
880 if (pureInteger)
881 return VERTEX_FORMAT_USHORT4_INT;
882 if (normalized)
883 return VERTEX_FORMAT_USHORT4_NORM;
884 return VERTEX_FORMAT_USHORT4;
885 default:
886 UNREACHABLE();
887 break;
888 }
889 case GL_INT:
890 switch (components)
891 {
892 case 1:
893 if (pureInteger)
894 return VERTEX_FORMAT_SINT1_INT;
895 if (normalized)
896 return VERTEX_FORMAT_SINT1_NORM;
897 return VERTEX_FORMAT_SINT1;
898 case 2:
899 if (pureInteger)
900 return VERTEX_FORMAT_SINT2_INT;
901 if (normalized)
902 return VERTEX_FORMAT_SINT2_NORM;
903 return VERTEX_FORMAT_SINT2;
904 case 3:
905 if (pureInteger)
906 return VERTEX_FORMAT_SINT3_INT;
907 if (normalized)
908 return VERTEX_FORMAT_SINT3_NORM;
909 return VERTEX_FORMAT_SINT3;
910 case 4:
911 if (pureInteger)
912 return VERTEX_FORMAT_SINT4_INT;
913 if (normalized)
914 return VERTEX_FORMAT_SINT4_NORM;
915 return VERTEX_FORMAT_SINT4;
916 default:
917 UNREACHABLE();
918 break;
919 }
920 case GL_UNSIGNED_INT:
921 switch (components)
922 {
923 case 1:
924 if (pureInteger)
925 return VERTEX_FORMAT_UINT1_INT;
926 if (normalized)
927 return VERTEX_FORMAT_UINT1_NORM;
928 return VERTEX_FORMAT_UINT1;
929 case 2:
930 if (pureInteger)
931 return VERTEX_FORMAT_UINT2_INT;
932 if (normalized)
933 return VERTEX_FORMAT_UINT2_NORM;
934 return VERTEX_FORMAT_UINT2;
935 case 3:
936 if (pureInteger)
937 return VERTEX_FORMAT_UINT3_INT;
938 if (normalized)
939 return VERTEX_FORMAT_UINT3_NORM;
940 return VERTEX_FORMAT_UINT3;
941 case 4:
942 if (pureInteger)
943 return VERTEX_FORMAT_UINT4_INT;
944 if (normalized)
945 return VERTEX_FORMAT_UINT4_NORM;
946 return VERTEX_FORMAT_UINT4;
947 default:
948 UNREACHABLE();
949 break;
950 }
951 case GL_FLOAT:
952 switch (components)
953 {
954 case 1:
955 return VERTEX_FORMAT_FLOAT1;
956 case 2:
957 return VERTEX_FORMAT_FLOAT2;
958 case 3:
959 return VERTEX_FORMAT_FLOAT3;
960 case 4:
961 return VERTEX_FORMAT_FLOAT4;
962 default:
963 UNREACHABLE();
964 break;
965 }
966 case GL_HALF_FLOAT:
967 switch (components)
968 {
969 case 1:
970 return VERTEX_FORMAT_HALF1;
971 case 2:
972 return VERTEX_FORMAT_HALF2;
973 case 3:
974 return VERTEX_FORMAT_HALF3;
975 case 4:
976 return VERTEX_FORMAT_HALF4;
977 default:
978 UNREACHABLE();
979 break;
980 }
981 case GL_FIXED:
982 switch (components)
983 {
984 case 1:
985 return VERTEX_FORMAT_FIXED1;
986 case 2:
987 return VERTEX_FORMAT_FIXED2;
988 case 3:
989 return VERTEX_FORMAT_FIXED3;
990 case 4:
991 return VERTEX_FORMAT_FIXED4;
992 default:
993 UNREACHABLE();
994 break;
995 }
996 case GL_INT_2_10_10_10_REV:
997 if (pureInteger)
998 return VERTEX_FORMAT_SINT210_INT;
999 if (normalized)
1000 return VERTEX_FORMAT_SINT210_NORM;
1001 return VERTEX_FORMAT_SINT210;
1002 case GL_UNSIGNED_INT_2_10_10_10_REV:
1003 if (pureInteger)
1004 return VERTEX_FORMAT_UINT210_INT;
1005 if (normalized)
1006 return VERTEX_FORMAT_UINT210_NORM;
1007 return VERTEX_FORMAT_UINT210;
1008 default:
1009 UNREACHABLE();
1010 break;
1011 }
1012 return VERTEX_FORMAT_UBYTE1;
1013}
1014
1015VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1016{
1017 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1018}
1019
1020VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1021{
1022 if (!attrib.enabled)
1023 {
1024 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1025 }
1026 return GetVertexFormatType(attrib);
1027}
1028
1029const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1030{
1031 switch (vertexFormatType)
1032 {
1033 case VERTEX_FORMAT_SBYTE1:
1034 {
1035 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1036 return format;
1037 }
1038 case VERTEX_FORMAT_SBYTE1_NORM:
1039 {
1040 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1041 return format;
1042 }
1043 case VERTEX_FORMAT_SBYTE2:
1044 {
1045 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1046 return format;
1047 }
1048 case VERTEX_FORMAT_SBYTE2_NORM:
1049 {
1050 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1051 return format;
1052 }
1053 case VERTEX_FORMAT_SBYTE3:
1054 {
1055 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1056 return format;
1057 }
1058 case VERTEX_FORMAT_SBYTE3_NORM:
1059 {
1060 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1061 return format;
1062 }
1063 case VERTEX_FORMAT_SBYTE4:
1064 {
1065 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1066 return format;
1067 }
1068 case VERTEX_FORMAT_SBYTE4_NORM:
1069 {
1070 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1071 return format;
1072 }
1073 case VERTEX_FORMAT_UBYTE1:
1074 {
1075 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1076 return format;
1077 }
1078 case VERTEX_FORMAT_UBYTE1_NORM:
1079 {
1080 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1081 return format;
1082 }
1083 case VERTEX_FORMAT_UBYTE2:
1084 {
1085 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1086 return format;
1087 }
1088 case VERTEX_FORMAT_UBYTE2_NORM:
1089 {
1090 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1091 return format;
1092 }
1093 case VERTEX_FORMAT_UBYTE3:
1094 {
1095 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1096 return format;
1097 }
1098 case VERTEX_FORMAT_UBYTE3_NORM:
1099 {
1100 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1101 return format;
1102 }
1103 case VERTEX_FORMAT_UBYTE4:
1104 {
1105 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1106 return format;
1107 }
1108 case VERTEX_FORMAT_UBYTE4_NORM:
1109 {
1110 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1111 return format;
1112 }
1113 case VERTEX_FORMAT_SSHORT1:
1114 {
1115 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1116 return format;
1117 }
1118 case VERTEX_FORMAT_SSHORT1_NORM:
1119 {
1120 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1121 return format;
1122 }
1123 case VERTEX_FORMAT_SSHORT2:
1124 {
1125 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1126 return format;
1127 }
1128 case VERTEX_FORMAT_SSHORT2_NORM:
1129 {
1130 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1131 return format;
1132 }
1133 case VERTEX_FORMAT_SSHORT3:
1134 {
1135 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1136 return format;
1137 }
1138 case VERTEX_FORMAT_SSHORT3_NORM:
1139 {
1140 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1141 return format;
1142 }
1143 case VERTEX_FORMAT_SSHORT4:
1144 {
1145 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1146 return format;
1147 }
1148 case VERTEX_FORMAT_SSHORT4_NORM:
1149 {
1150 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1151 return format;
1152 }
1153 case VERTEX_FORMAT_USHORT1:
1154 {
1155 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1156 return format;
1157 }
1158 case VERTEX_FORMAT_USHORT1_NORM:
1159 {
1160 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1161 return format;
1162 }
1163 case VERTEX_FORMAT_USHORT2:
1164 {
1165 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1166 return format;
1167 }
1168 case VERTEX_FORMAT_USHORT2_NORM:
1169 {
1170 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1171 return format;
1172 }
1173 case VERTEX_FORMAT_USHORT3:
1174 {
1175 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1176 return format;
1177 }
1178 case VERTEX_FORMAT_USHORT3_NORM:
1179 {
1180 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1181 return format;
1182 }
1183 case VERTEX_FORMAT_USHORT4:
1184 {
1185 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1186 return format;
1187 }
1188 case VERTEX_FORMAT_USHORT4_NORM:
1189 {
1190 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1191 return format;
1192 }
1193 case VERTEX_FORMAT_SINT1:
1194 {
1195 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1196 return format;
1197 }
1198 case VERTEX_FORMAT_SINT1_NORM:
1199 {
1200 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1201 return format;
1202 }
1203 case VERTEX_FORMAT_SINT2:
1204 {
1205 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1206 return format;
1207 }
1208 case VERTEX_FORMAT_SINT2_NORM:
1209 {
1210 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1211 return format;
1212 }
1213 case VERTEX_FORMAT_SINT3:
1214 {
1215 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1216 return format;
1217 }
1218 case VERTEX_FORMAT_SINT3_NORM:
1219 {
1220 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1221 return format;
1222 }
1223 case VERTEX_FORMAT_SINT4:
1224 {
1225 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1226 return format;
1227 }
1228 case VERTEX_FORMAT_SINT4_NORM:
1229 {
1230 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1231 return format;
1232 }
1233 case VERTEX_FORMAT_UINT1:
1234 {
1235 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1236 return format;
1237 }
1238 case VERTEX_FORMAT_UINT1_NORM:
1239 {
1240 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1241 return format;
1242 }
1243 case VERTEX_FORMAT_UINT2:
1244 {
1245 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1246 return format;
1247 }
1248 case VERTEX_FORMAT_UINT2_NORM:
1249 {
1250 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1251 return format;
1252 }
1253 case VERTEX_FORMAT_UINT3:
1254 {
1255 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1256 return format;
1257 }
1258 case VERTEX_FORMAT_UINT3_NORM:
1259 {
1260 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1261 return format;
1262 }
1263 case VERTEX_FORMAT_UINT4:
1264 {
1265 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1266 return format;
1267 }
1268 case VERTEX_FORMAT_UINT4_NORM:
1269 {
1270 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1271 return format;
1272 }
1273 case VERTEX_FORMAT_SBYTE1_INT:
1274 {
1275 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1276 return format;
1277 }
1278 case VERTEX_FORMAT_SBYTE2_INT:
1279 {
1280 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1281 return format;
1282 }
1283 case VERTEX_FORMAT_SBYTE3_INT:
1284 {
1285 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1286 return format;
1287 }
1288 case VERTEX_FORMAT_SBYTE4_INT:
1289 {
1290 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1291 return format;
1292 }
1293 case VERTEX_FORMAT_UBYTE1_INT:
1294 {
1295 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1296 return format;
1297 }
1298 case VERTEX_FORMAT_UBYTE2_INT:
1299 {
1300 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1301 return format;
1302 }
1303 case VERTEX_FORMAT_UBYTE3_INT:
1304 {
1305 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1306 return format;
1307 }
1308 case VERTEX_FORMAT_UBYTE4_INT:
1309 {
1310 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1311 return format;
1312 }
1313 case VERTEX_FORMAT_SSHORT1_INT:
1314 {
1315 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1316 return format;
1317 }
1318 case VERTEX_FORMAT_SSHORT2_INT:
1319 {
1320 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1321 return format;
1322 }
1323 case VERTEX_FORMAT_SSHORT3_INT:
1324 {
1325 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1326 return format;
1327 }
1328 case VERTEX_FORMAT_SSHORT4_INT:
1329 {
1330 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1331 return format;
1332 }
1333 case VERTEX_FORMAT_USHORT1_INT:
1334 {
1335 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1336 return format;
1337 }
1338 case VERTEX_FORMAT_USHORT2_INT:
1339 {
1340 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1341 return format;
1342 }
1343 case VERTEX_FORMAT_USHORT3_INT:
1344 {
1345 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1346 return format;
1347 }
1348 case VERTEX_FORMAT_USHORT4_INT:
1349 {
1350 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1351 return format;
1352 }
1353 case VERTEX_FORMAT_SINT1_INT:
1354 {
1355 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1356 return format;
1357 }
1358 case VERTEX_FORMAT_SINT2_INT:
1359 {
1360 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1361 return format;
1362 }
1363 case VERTEX_FORMAT_SINT3_INT:
1364 {
1365 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1366 return format;
1367 }
1368 case VERTEX_FORMAT_SINT4_INT:
1369 {
1370 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1371 return format;
1372 }
1373 case VERTEX_FORMAT_UINT1_INT:
1374 {
1375 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1376 return format;
1377 }
1378 case VERTEX_FORMAT_UINT2_INT:
1379 {
1380 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1381 return format;
1382 }
1383 case VERTEX_FORMAT_UINT3_INT:
1384 {
1385 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1386 return format;
1387 }
1388 case VERTEX_FORMAT_UINT4_INT:
1389 {
1390 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1391 return format;
1392 }
1393 case VERTEX_FORMAT_FIXED1:
1394 {
1395 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1396 return format;
1397 }
1398 case VERTEX_FORMAT_FIXED2:
1399 {
1400 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1401 return format;
1402 }
1403 case VERTEX_FORMAT_FIXED3:
1404 {
1405 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1406 return format;
1407 }
1408 case VERTEX_FORMAT_FIXED4:
1409 {
1410 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1411 return format;
1412 }
1413 case VERTEX_FORMAT_HALF1:
1414 {
1415 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1416 return format;
1417 }
1418 case VERTEX_FORMAT_HALF2:
1419 {
1420 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1421 return format;
1422 }
1423 case VERTEX_FORMAT_HALF3:
1424 {
1425 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1426 return format;
1427 }
1428 case VERTEX_FORMAT_HALF4:
1429 {
1430 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1431 return format;
1432 }
1433 case VERTEX_FORMAT_FLOAT1:
1434 {
1435 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1436 return format;
1437 }
1438 case VERTEX_FORMAT_FLOAT2:
1439 {
1440 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1441 return format;
1442 }
1443 case VERTEX_FORMAT_FLOAT3:
1444 {
1445 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1446 return format;
1447 }
1448 case VERTEX_FORMAT_FLOAT4:
1449 {
1450 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1451 return format;
1452 }
1453 case VERTEX_FORMAT_SINT210:
1454 {
1455 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1456 return format;
1457 }
1458 case VERTEX_FORMAT_UINT210:
1459 {
1460 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1461 return format;
1462 }
1463 case VERTEX_FORMAT_SINT210_NORM:
1464 {
1465 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1466 return format;
1467 }
1468 case VERTEX_FORMAT_UINT210_NORM:
1469 {
1470 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1471 return format;
1472 }
1473 case VERTEX_FORMAT_SINT210_INT:
1474 {
1475 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1476 return format;
1477 }
1478 case VERTEX_FORMAT_UINT210_INT:
1479 {
1480 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1481 return format;
1482 }
1483 default:
1484 {
1485 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1486 return format;
1487 }
1488 }
1489}
1490
1491VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1492 : type(typeIn),
1493 normalized(normalizedIn),
1494 components(componentsIn),
1495 pureInteger(pureIntegerIn)
1496{
1497 // float -> !normalized
1498 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1499}
1500
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001501}