blob: 0d64ae5330bfa8229781f8e416e1037161d3fe5b [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
Jamie Madillcd089732015-12-17 09:53:09 -0500222// Special function for half float formats with three or four channels.
223static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
224{
225 return clientVersion >= 3 || extensions.textureHalfFloat;
226}
227
228static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
229{
230 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
231}
232
233// Special function for half float formats with one or two channels.
234static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
235{
236 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
237}
238
239static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
240{
241 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
242}
243
244// Special function for float formats with three or four channels.
245static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
246{
247 return clientVersion >= 3 || extensions.textureFloat;
248}
249
250static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
251{
252 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
253 return FloatSupport(clientVersion, extensions) &&
254 (extensions.colorBufferFloat || clientVersion == 2);
255}
256
257// Special function for float formats with one or two channels.
258static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
259{
260 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
261}
262
263static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
264{
265 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
266 return FloatSupportRG(clientVersion, extensions) &&
267 (extensions.colorBufferFloat || clientVersion == 2);
268}
269
Geoff Lang5d601382014-07-22 15:14:06 -0400270InternalFormat::InternalFormat()
271 : redBits(0),
272 greenBits(0),
273 blueBits(0),
274 luminanceBits(0),
275 alphaBits(0),
276 sharedBits(0),
277 depthBits(0),
278 stencilBits(0),
279 pixelBytes(0),
280 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400281 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400282 compressedBlockWidth(0),
283 compressedBlockHeight(0),
284 format(GL_NONE),
285 type(GL_NONE),
286 componentType(GL_NONE),
287 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400288 textureSupport(NeverSupported),
289 renderSupport(NeverSupported),
290 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000291{
Geoff Lang5d601382014-07-22 15:14:06 -0400292}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000293
Geoff Lang5d601382014-07-22 15:14:06 -0400294static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
295 InternalFormat::SupportCheckFunction renderSupport,
296 InternalFormat::SupportCheckFunction filterSupport)
297{
298 InternalFormat formatInfo;
299 formatInfo.format = format;
300 formatInfo.textureSupport = textureSupport;
301 formatInfo.renderSupport = renderSupport;
302 formatInfo.filterSupport = filterSupport;
303 return formatInfo;
304}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000305
Geoff Lang5d601382014-07-22 15:14:06 -0400306static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
307 GLenum format, GLenum type, GLenum componentType, bool srgb,
308 InternalFormat::SupportCheckFunction textureSupport,
309 InternalFormat::SupportCheckFunction renderSupport,
310 InternalFormat::SupportCheckFunction filterSupport)
311{
312 InternalFormat formatInfo;
313 formatInfo.redBits = red;
314 formatInfo.greenBits = green;
315 formatInfo.blueBits = blue;
316 formatInfo.alphaBits = alpha;
317 formatInfo.sharedBits = shared;
318 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
319 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
320 formatInfo.format = format;
321 formatInfo.type = type;
322 formatInfo.componentType = componentType;
323 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
324 formatInfo.textureSupport = textureSupport;
325 formatInfo.renderSupport = renderSupport;
326 formatInfo.filterSupport = filterSupport;
327 return formatInfo;
328}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000329
Geoff Lang5d601382014-07-22 15:14:06 -0400330static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
331 InternalFormat::SupportCheckFunction textureSupport,
332 InternalFormat::SupportCheckFunction renderSupport,
333 InternalFormat::SupportCheckFunction filterSupport)
334{
335 InternalFormat formatInfo;
336 formatInfo.luminanceBits = luminance;
337 formatInfo.alphaBits = alpha;
338 formatInfo.pixelBytes = (luminance + alpha) / 8;
339 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
340 formatInfo.format = format;
341 formatInfo.type = type;
342 formatInfo.componentType = componentType;
343 formatInfo.colorEncoding = GL_LINEAR;
344 formatInfo.textureSupport = textureSupport;
345 formatInfo.renderSupport = renderSupport;
346 formatInfo.filterSupport = filterSupport;
347 return formatInfo;
348}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000349
Geoff Lang5d601382014-07-22 15:14:06 -0400350static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
351 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
352 InternalFormat::SupportCheckFunction renderSupport,
353 InternalFormat::SupportCheckFunction filterSupport)
354{
355 InternalFormat formatInfo;
356 formatInfo.depthBits = depthBits;
357 formatInfo.stencilBits = stencilBits;
358 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
359 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
360 formatInfo.format = format;
361 formatInfo.type = type;
362 formatInfo.componentType = componentType;
363 formatInfo.colorEncoding = GL_LINEAR;
364 formatInfo.textureSupport = textureSupport;
365 formatInfo.renderSupport = renderSupport;
366 formatInfo.filterSupport = filterSupport;
367 return formatInfo;
368}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000369
Geoff Lang5d601382014-07-22 15:14:06 -0400370static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
371 GLuint componentCount, GLenum format, GLenum type, bool srgb,
372 InternalFormat::SupportCheckFunction textureSupport,
373 InternalFormat::SupportCheckFunction renderSupport,
374 InternalFormat::SupportCheckFunction filterSupport)
375{
376 InternalFormat formatInfo;
377 formatInfo.compressedBlockWidth = compressedBlockWidth;
378 formatInfo.compressedBlockHeight = compressedBlockHeight;
379 formatInfo.pixelBytes = compressedBlockSize / 8;
380 formatInfo.componentCount = componentCount;
381 formatInfo.format = format;
382 formatInfo.type = type;
383 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
384 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
385 formatInfo.compressed = true;
386 formatInfo.textureSupport = textureSupport;
387 formatInfo.renderSupport = renderSupport;
388 formatInfo.filterSupport = filterSupport;
389 return formatInfo;
390}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000391
Geoff Lang5d601382014-07-22 15:14:06 -0400392typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
393typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000394
Geoff Lange4a492b2014-06-19 14:14:41 -0400395static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000396{
397 InternalFormatInfoMap map;
398
Geoff Lang9bbad182015-09-04 11:07:29 -0400399 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000400 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400401 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000402
Geoff Langabce7622014-09-19 16:13:00 -0400403 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
404 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)));
405 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
406 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)));
407 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
408 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)));
409 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
410 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)));
411 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)));
412 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)));
413 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)));
414 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
415 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 -0400416 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 -0400417 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)));
418 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)));
419 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)));
420 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)));
421 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
422 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)));
423 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
424 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)));
425 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
426 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)));
427 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
428 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)));
429 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
430 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)));
431 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
432 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)));
433 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
434 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)));
435 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
436 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)));
437 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
438 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)));
439 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
440 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)));
441 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
442 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)));
443 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
444 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 +0000445
Geoff Langabce7622014-09-19 16:13:00 -0400446 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)));
447 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)));
448 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 +0000449
450 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500451 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
452 // | | | | | | | type | | | | |
453 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
454 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
455 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
456 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
457 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
458 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
459 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
460 map.insert(InternalFormatInfoPair(GL_RGBA32F, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000461
462 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400463 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
464 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>)));
465 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>)));
466 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>)));
Jamie Madillf06e6072015-12-01 10:44:16 -0500467 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES, DepthStencilFormat(32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported )));
Geoff Langabce7622014-09-19 16:13:00 -0400468 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 )));
469 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 -0800470 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000471
472 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400473 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400474 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
475 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
476 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
477 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
478 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
479 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
480 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
481 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
482 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 +0000483
484 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400485 // | Internal format | | Format | Supported | Renderable | Filterable |
486 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
487 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
488 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
489 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
490 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
491 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
492 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
493 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
494 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
495 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
496 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
497 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
498 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
499 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
500 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
501 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 +0000502
503 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400504 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
505 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
506 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)));
507 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
508 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)));
509 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
510 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
511 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)));
512 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)));
513 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)));
514 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 +0000515
516 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400517 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
518 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)));
519 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 +0000520
521 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400522 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 +0000523
524 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400525 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)));
526
527 // From GL_OES_compressed_ETC1_RGB8_texture
528 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 +0000529
Geoff Lang60ad73d2015-10-23 10:08:44 -0400530 // From KHR_texture_compression_astc_hdr
531 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
532 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)));
533 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)));
534 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)));
535 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)));
536 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)));
537 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)));
538 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)));
539 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)));
540 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)));
541 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)));
542 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)));
543 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)));
544 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)));
545 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)));
546
547 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)));
548 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)));
549 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)));
550 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)));
551 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)));
552 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)));
553 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)));
554 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)));
555 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)));
556 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)));
557 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)));
558 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)));
559 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)));
560 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)));
561
Corentin Walleze0902642014-11-04 12:32:15 -0800562 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
563 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
564 // - All other stencil formats (all depth-stencil) are either float or normalized
565 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
566 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
567 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 -0400568 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800569
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000570 return map;
571}
572
Geoff Lange4a492b2014-06-19 14:14:41 -0400573static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000574{
Geoff Lange4a492b2014-06-19 14:14:41 -0400575 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
576 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000577}
578
Geoff Lange4a492b2014-06-19 14:14:41 -0400579static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400580{
581 FormatSet result;
582
Geoff Lange4a492b2014-06-19 14:14:41 -0400583 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400584 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
585 {
Geoff Lang5d601382014-07-22 15:14:06 -0400586 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400587 {
588 result.insert(i->first);
589 }
590 }
591
592 return result;
593}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000594
Geoff Lang5d601382014-07-22 15:14:06 -0400595const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200597 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000598 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200599 case GL_UNSIGNED_BYTE:
600 case GL_BYTE:
601 {
602 static const Type info = GenTypeInfo(1, false);
603 return info;
604 }
605 case GL_UNSIGNED_SHORT:
606 case GL_SHORT:
607 case GL_HALF_FLOAT:
608 case GL_HALF_FLOAT_OES:
609 {
610 static const Type info = GenTypeInfo(2, false);
611 return info;
612 }
613 case GL_UNSIGNED_INT:
614 case GL_INT:
615 case GL_FLOAT:
616 {
617 static const Type info = GenTypeInfo(4, false);
618 return info;
619 }
620 case GL_UNSIGNED_SHORT_5_6_5:
621 case GL_UNSIGNED_SHORT_4_4_4_4:
622 case GL_UNSIGNED_SHORT_5_5_5_1:
623 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
624 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
625 {
626 static const Type info = GenTypeInfo(2, true);
627 return info;
628 }
629 case GL_UNSIGNED_INT_2_10_10_10_REV:
630 case GL_UNSIGNED_INT_24_8:
631 case GL_UNSIGNED_INT_10F_11F_11F_REV:
632 case GL_UNSIGNED_INT_5_9_9_9_REV:
633 {
634 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
635 static const Type info = GenTypeInfo(4, true);
636 return info;
637 }
638 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
639 {
640 static const Type info = GenTypeInfo(8, true);
641 return info;
642 }
643 default:
644 {
645 static const Type defaultInfo;
646 return defaultInfo;
647 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000648 }
649}
650
Geoff Lang5d601382014-07-22 15:14:06 -0400651const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000652{
Geoff Lang5d601382014-07-22 15:14:06 -0400653 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
654 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
655 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000656 {
Geoff Lang5d601382014-07-22 15:14:06 -0400657 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000658 }
659 else
660 {
Geoff Lang5d601382014-07-22 15:14:06 -0400661 static const InternalFormat defaultInternalFormat;
662 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000663 }
664}
665
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800666GLuint InternalFormat::computeRowPitch(GLenum formatType, GLsizei width, GLint alignment, GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000667{
668 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800669 GLuint rowBytes;
670 if (rowLength > 0)
671 {
672 ASSERT(!compressed);
673 rowBytes = pixelBytes * rowLength;
674 }
675 else
676 {
677 rowBytes = computeBlockSize(formatType, width, 1);
678 }
679 return rx::roundUp(rowBytes, static_cast<GLuint>(alignment));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000680}
681
Minmin Gongadff67b2015-10-14 10:34:45 -0400682GLuint InternalFormat::computeDepthPitch(GLenum formatType,
683 GLsizei width,
684 GLsizei height,
685 GLint alignment,
686 GLint rowLength,
687 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000688{
Minmin Gongadff67b2015-10-14 10:34:45 -0400689 GLuint rows;
690 if (imageHeight > 0)
691 {
692 rows = imageHeight;
693 }
694 else
695 {
696 rows = height;
697 }
698 return computeRowPitch(formatType, width, alignment, rowLength) * rows;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000699}
700
Austin Kinross3ae64652015-01-26 15:51:39 -0800701GLuint InternalFormat::computeBlockSize(GLenum formatType, GLsizei width, GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000702{
Geoff Lang5d601382014-07-22 15:14:06 -0400703 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000704 {
Geoff Lang5d601382014-07-22 15:14:06 -0400705 GLsizei numBlocksWide = (width + compressedBlockWidth - 1) / compressedBlockWidth;
706 GLsizei numBlocksHight = (height + compressedBlockHeight - 1) / compressedBlockHeight;
707 return (pixelBytes * numBlocksWide * numBlocksHight);
708 }
709 else
710 {
Austin Kinross3ae64652015-01-26 15:51:39 -0800711 const Type &typeInfo = GetTypeInfo(formatType);
Geoff Lang5d601382014-07-22 15:14:06 -0400712 if (typeInfo.specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000713 {
Geoff Lang5d601382014-07-22 15:14:06 -0400714 return typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000715 }
716 else
717 {
Geoff Lang5d601382014-07-22 15:14:06 -0400718 return componentCount * typeInfo.bytes * width * height;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000719 }
720 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000721}
722
Minmin Gongadff67b2015-10-14 10:34:45 -0400723GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
724 GLint depthPitch,
725 GLint skipImages,
726 GLint skipRows,
727 GLint skipPixels) const
728{
729 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
730}
731
Geoff Lang5d601382014-07-22 15:14:06 -0400732GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000733{
Geoff Lang5d601382014-07-22 15:14:06 -0400734 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500735 if (formatInfo.pixelBytes > 0)
736 {
737 return internalFormat;
738 }
739 else
740 {
741 static const FormatMap formatMap = BuildFormatMap();
742 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
743 if (iter != formatMap.end())
744 {
745 return iter->second;
746 }
747 else
748 {
749 return GL_NONE;
750 }
751 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000752}
753
Geoff Lange4a492b2014-06-19 14:14:41 -0400754const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400755{
Geoff Lange4a492b2014-06-19 14:14:41 -0400756 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400757 return formatSet;
758}
759
Jamie Madill09e2d932015-07-14 16:40:31 -0400760AttributeType GetAttributeType(GLenum enumValue)
761{
762 switch (enumValue)
763 {
764 case GL_FLOAT:
765 return ATTRIBUTE_FLOAT;
766 case GL_FLOAT_VEC2:
767 return ATTRIBUTE_VEC2;
768 case GL_FLOAT_VEC3:
769 return ATTRIBUTE_VEC3;
770 case GL_FLOAT_VEC4:
771 return ATTRIBUTE_VEC4;
772 case GL_INT:
773 return ATTRIBUTE_INT;
774 case GL_INT_VEC2:
775 return ATTRIBUTE_IVEC2;
776 case GL_INT_VEC3:
777 return ATTRIBUTE_IVEC3;
778 case GL_INT_VEC4:
779 return ATTRIBUTE_IVEC4;
780 case GL_UNSIGNED_INT:
781 return ATTRIBUTE_UINT;
782 case GL_UNSIGNED_INT_VEC2:
783 return ATTRIBUTE_UVEC2;
784 case GL_UNSIGNED_INT_VEC3:
785 return ATTRIBUTE_UVEC3;
786 case GL_UNSIGNED_INT_VEC4:
787 return ATTRIBUTE_UVEC4;
788 case GL_FLOAT_MAT2:
789 return ATTRIBUTE_MAT2;
790 case GL_FLOAT_MAT3:
791 return ATTRIBUTE_MAT3;
792 case GL_FLOAT_MAT4:
793 return ATTRIBUTE_MAT4;
794 case GL_FLOAT_MAT2x3:
795 return ATTRIBUTE_MAT2x3;
796 case GL_FLOAT_MAT2x4:
797 return ATTRIBUTE_MAT2x4;
798 case GL_FLOAT_MAT3x2:
799 return ATTRIBUTE_MAT3x2;
800 case GL_FLOAT_MAT3x4:
801 return ATTRIBUTE_MAT3x4;
802 case GL_FLOAT_MAT4x2:
803 return ATTRIBUTE_MAT4x2;
804 case GL_FLOAT_MAT4x3:
805 return ATTRIBUTE_MAT4x3;
806 default:
807 UNREACHABLE();
808 return ATTRIBUTE_FLOAT;
809 }
810}
811
Jamie Madilld3dfda22015-07-06 08:28:49 -0400812VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
813{
814 switch (type)
815 {
816 case GL_BYTE:
817 switch (components)
818 {
819 case 1:
820 if (pureInteger)
821 return VERTEX_FORMAT_SBYTE1_INT;
822 if (normalized)
823 return VERTEX_FORMAT_SBYTE1_NORM;
824 return VERTEX_FORMAT_SBYTE1;
825 case 2:
826 if (pureInteger)
827 return VERTEX_FORMAT_SBYTE2_INT;
828 if (normalized)
829 return VERTEX_FORMAT_SBYTE2_NORM;
830 return VERTEX_FORMAT_SBYTE2;
831 case 3:
832 if (pureInteger)
833 return VERTEX_FORMAT_SBYTE3_INT;
834 if (normalized)
835 return VERTEX_FORMAT_SBYTE3_NORM;
836 return VERTEX_FORMAT_SBYTE3;
837 case 4:
838 if (pureInteger)
839 return VERTEX_FORMAT_SBYTE4_INT;
840 if (normalized)
841 return VERTEX_FORMAT_SBYTE4_NORM;
842 return VERTEX_FORMAT_SBYTE4;
843 default:
844 UNREACHABLE();
845 break;
846 }
847 case GL_UNSIGNED_BYTE:
848 switch (components)
849 {
850 case 1:
851 if (pureInteger)
852 return VERTEX_FORMAT_UBYTE1_INT;
853 if (normalized)
854 return VERTEX_FORMAT_UBYTE1_NORM;
855 return VERTEX_FORMAT_UBYTE1;
856 case 2:
857 if (pureInteger)
858 return VERTEX_FORMAT_UBYTE2_INT;
859 if (normalized)
860 return VERTEX_FORMAT_UBYTE2_NORM;
861 return VERTEX_FORMAT_UBYTE2;
862 case 3:
863 if (pureInteger)
864 return VERTEX_FORMAT_UBYTE3_INT;
865 if (normalized)
866 return VERTEX_FORMAT_UBYTE3_NORM;
867 return VERTEX_FORMAT_UBYTE3;
868 case 4:
869 if (pureInteger)
870 return VERTEX_FORMAT_UBYTE4_INT;
871 if (normalized)
872 return VERTEX_FORMAT_UBYTE4_NORM;
873 return VERTEX_FORMAT_UBYTE4;
874 default:
875 UNREACHABLE();
876 break;
877 }
878 case GL_SHORT:
879 switch (components)
880 {
881 case 1:
882 if (pureInteger)
883 return VERTEX_FORMAT_SSHORT1_INT;
884 if (normalized)
885 return VERTEX_FORMAT_SSHORT1_NORM;
886 return VERTEX_FORMAT_SSHORT1;
887 case 2:
888 if (pureInteger)
889 return VERTEX_FORMAT_SSHORT2_INT;
890 if (normalized)
891 return VERTEX_FORMAT_SSHORT2_NORM;
892 return VERTEX_FORMAT_SSHORT2;
893 case 3:
894 if (pureInteger)
895 return VERTEX_FORMAT_SSHORT3_INT;
896 if (normalized)
897 return VERTEX_FORMAT_SSHORT3_NORM;
898 return VERTEX_FORMAT_SSHORT3;
899 case 4:
900 if (pureInteger)
901 return VERTEX_FORMAT_SSHORT4_INT;
902 if (normalized)
903 return VERTEX_FORMAT_SSHORT4_NORM;
904 return VERTEX_FORMAT_SSHORT4;
905 default:
906 UNREACHABLE();
907 break;
908 }
909 case GL_UNSIGNED_SHORT:
910 switch (components)
911 {
912 case 1:
913 if (pureInteger)
914 return VERTEX_FORMAT_USHORT1_INT;
915 if (normalized)
916 return VERTEX_FORMAT_USHORT1_NORM;
917 return VERTEX_FORMAT_USHORT1;
918 case 2:
919 if (pureInteger)
920 return VERTEX_FORMAT_USHORT2_INT;
921 if (normalized)
922 return VERTEX_FORMAT_USHORT2_NORM;
923 return VERTEX_FORMAT_USHORT2;
924 case 3:
925 if (pureInteger)
926 return VERTEX_FORMAT_USHORT3_INT;
927 if (normalized)
928 return VERTEX_FORMAT_USHORT3_NORM;
929 return VERTEX_FORMAT_USHORT3;
930 case 4:
931 if (pureInteger)
932 return VERTEX_FORMAT_USHORT4_INT;
933 if (normalized)
934 return VERTEX_FORMAT_USHORT4_NORM;
935 return VERTEX_FORMAT_USHORT4;
936 default:
937 UNREACHABLE();
938 break;
939 }
940 case GL_INT:
941 switch (components)
942 {
943 case 1:
944 if (pureInteger)
945 return VERTEX_FORMAT_SINT1_INT;
946 if (normalized)
947 return VERTEX_FORMAT_SINT1_NORM;
948 return VERTEX_FORMAT_SINT1;
949 case 2:
950 if (pureInteger)
951 return VERTEX_FORMAT_SINT2_INT;
952 if (normalized)
953 return VERTEX_FORMAT_SINT2_NORM;
954 return VERTEX_FORMAT_SINT2;
955 case 3:
956 if (pureInteger)
957 return VERTEX_FORMAT_SINT3_INT;
958 if (normalized)
959 return VERTEX_FORMAT_SINT3_NORM;
960 return VERTEX_FORMAT_SINT3;
961 case 4:
962 if (pureInteger)
963 return VERTEX_FORMAT_SINT4_INT;
964 if (normalized)
965 return VERTEX_FORMAT_SINT4_NORM;
966 return VERTEX_FORMAT_SINT4;
967 default:
968 UNREACHABLE();
969 break;
970 }
971 case GL_UNSIGNED_INT:
972 switch (components)
973 {
974 case 1:
975 if (pureInteger)
976 return VERTEX_FORMAT_UINT1_INT;
977 if (normalized)
978 return VERTEX_FORMAT_UINT1_NORM;
979 return VERTEX_FORMAT_UINT1;
980 case 2:
981 if (pureInteger)
982 return VERTEX_FORMAT_UINT2_INT;
983 if (normalized)
984 return VERTEX_FORMAT_UINT2_NORM;
985 return VERTEX_FORMAT_UINT2;
986 case 3:
987 if (pureInteger)
988 return VERTEX_FORMAT_UINT3_INT;
989 if (normalized)
990 return VERTEX_FORMAT_UINT3_NORM;
991 return VERTEX_FORMAT_UINT3;
992 case 4:
993 if (pureInteger)
994 return VERTEX_FORMAT_UINT4_INT;
995 if (normalized)
996 return VERTEX_FORMAT_UINT4_NORM;
997 return VERTEX_FORMAT_UINT4;
998 default:
999 UNREACHABLE();
1000 break;
1001 }
1002 case GL_FLOAT:
1003 switch (components)
1004 {
1005 case 1:
1006 return VERTEX_FORMAT_FLOAT1;
1007 case 2:
1008 return VERTEX_FORMAT_FLOAT2;
1009 case 3:
1010 return VERTEX_FORMAT_FLOAT3;
1011 case 4:
1012 return VERTEX_FORMAT_FLOAT4;
1013 default:
1014 UNREACHABLE();
1015 break;
1016 }
1017 case GL_HALF_FLOAT:
1018 switch (components)
1019 {
1020 case 1:
1021 return VERTEX_FORMAT_HALF1;
1022 case 2:
1023 return VERTEX_FORMAT_HALF2;
1024 case 3:
1025 return VERTEX_FORMAT_HALF3;
1026 case 4:
1027 return VERTEX_FORMAT_HALF4;
1028 default:
1029 UNREACHABLE();
1030 break;
1031 }
1032 case GL_FIXED:
1033 switch (components)
1034 {
1035 case 1:
1036 return VERTEX_FORMAT_FIXED1;
1037 case 2:
1038 return VERTEX_FORMAT_FIXED2;
1039 case 3:
1040 return VERTEX_FORMAT_FIXED3;
1041 case 4:
1042 return VERTEX_FORMAT_FIXED4;
1043 default:
1044 UNREACHABLE();
1045 break;
1046 }
1047 case GL_INT_2_10_10_10_REV:
1048 if (pureInteger)
1049 return VERTEX_FORMAT_SINT210_INT;
1050 if (normalized)
1051 return VERTEX_FORMAT_SINT210_NORM;
1052 return VERTEX_FORMAT_SINT210;
1053 case GL_UNSIGNED_INT_2_10_10_10_REV:
1054 if (pureInteger)
1055 return VERTEX_FORMAT_UINT210_INT;
1056 if (normalized)
1057 return VERTEX_FORMAT_UINT210_NORM;
1058 return VERTEX_FORMAT_UINT210;
1059 default:
1060 UNREACHABLE();
1061 break;
1062 }
1063 return VERTEX_FORMAT_UBYTE1;
1064}
1065
1066VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1067{
1068 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1069}
1070
1071VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1072{
1073 if (!attrib.enabled)
1074 {
1075 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1076 }
1077 return GetVertexFormatType(attrib);
1078}
1079
1080const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1081{
1082 switch (vertexFormatType)
1083 {
1084 case VERTEX_FORMAT_SBYTE1:
1085 {
1086 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1087 return format;
1088 }
1089 case VERTEX_FORMAT_SBYTE1_NORM:
1090 {
1091 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1092 return format;
1093 }
1094 case VERTEX_FORMAT_SBYTE2:
1095 {
1096 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1097 return format;
1098 }
1099 case VERTEX_FORMAT_SBYTE2_NORM:
1100 {
1101 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1102 return format;
1103 }
1104 case VERTEX_FORMAT_SBYTE3:
1105 {
1106 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1107 return format;
1108 }
1109 case VERTEX_FORMAT_SBYTE3_NORM:
1110 {
1111 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1112 return format;
1113 }
1114 case VERTEX_FORMAT_SBYTE4:
1115 {
1116 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1117 return format;
1118 }
1119 case VERTEX_FORMAT_SBYTE4_NORM:
1120 {
1121 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1122 return format;
1123 }
1124 case VERTEX_FORMAT_UBYTE1:
1125 {
1126 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1127 return format;
1128 }
1129 case VERTEX_FORMAT_UBYTE1_NORM:
1130 {
1131 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1132 return format;
1133 }
1134 case VERTEX_FORMAT_UBYTE2:
1135 {
1136 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1137 return format;
1138 }
1139 case VERTEX_FORMAT_UBYTE2_NORM:
1140 {
1141 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1142 return format;
1143 }
1144 case VERTEX_FORMAT_UBYTE3:
1145 {
1146 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1147 return format;
1148 }
1149 case VERTEX_FORMAT_UBYTE3_NORM:
1150 {
1151 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1152 return format;
1153 }
1154 case VERTEX_FORMAT_UBYTE4:
1155 {
1156 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1157 return format;
1158 }
1159 case VERTEX_FORMAT_UBYTE4_NORM:
1160 {
1161 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1162 return format;
1163 }
1164 case VERTEX_FORMAT_SSHORT1:
1165 {
1166 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1167 return format;
1168 }
1169 case VERTEX_FORMAT_SSHORT1_NORM:
1170 {
1171 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1172 return format;
1173 }
1174 case VERTEX_FORMAT_SSHORT2:
1175 {
1176 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1177 return format;
1178 }
1179 case VERTEX_FORMAT_SSHORT2_NORM:
1180 {
1181 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1182 return format;
1183 }
1184 case VERTEX_FORMAT_SSHORT3:
1185 {
1186 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1187 return format;
1188 }
1189 case VERTEX_FORMAT_SSHORT3_NORM:
1190 {
1191 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1192 return format;
1193 }
1194 case VERTEX_FORMAT_SSHORT4:
1195 {
1196 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1197 return format;
1198 }
1199 case VERTEX_FORMAT_SSHORT4_NORM:
1200 {
1201 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1202 return format;
1203 }
1204 case VERTEX_FORMAT_USHORT1:
1205 {
1206 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1207 return format;
1208 }
1209 case VERTEX_FORMAT_USHORT1_NORM:
1210 {
1211 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1212 return format;
1213 }
1214 case VERTEX_FORMAT_USHORT2:
1215 {
1216 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1217 return format;
1218 }
1219 case VERTEX_FORMAT_USHORT2_NORM:
1220 {
1221 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1222 return format;
1223 }
1224 case VERTEX_FORMAT_USHORT3:
1225 {
1226 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1227 return format;
1228 }
1229 case VERTEX_FORMAT_USHORT3_NORM:
1230 {
1231 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1232 return format;
1233 }
1234 case VERTEX_FORMAT_USHORT4:
1235 {
1236 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1237 return format;
1238 }
1239 case VERTEX_FORMAT_USHORT4_NORM:
1240 {
1241 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1242 return format;
1243 }
1244 case VERTEX_FORMAT_SINT1:
1245 {
1246 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1247 return format;
1248 }
1249 case VERTEX_FORMAT_SINT1_NORM:
1250 {
1251 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1252 return format;
1253 }
1254 case VERTEX_FORMAT_SINT2:
1255 {
1256 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1257 return format;
1258 }
1259 case VERTEX_FORMAT_SINT2_NORM:
1260 {
1261 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1262 return format;
1263 }
1264 case VERTEX_FORMAT_SINT3:
1265 {
1266 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1267 return format;
1268 }
1269 case VERTEX_FORMAT_SINT3_NORM:
1270 {
1271 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1272 return format;
1273 }
1274 case VERTEX_FORMAT_SINT4:
1275 {
1276 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1277 return format;
1278 }
1279 case VERTEX_FORMAT_SINT4_NORM:
1280 {
1281 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1282 return format;
1283 }
1284 case VERTEX_FORMAT_UINT1:
1285 {
1286 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1287 return format;
1288 }
1289 case VERTEX_FORMAT_UINT1_NORM:
1290 {
1291 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1292 return format;
1293 }
1294 case VERTEX_FORMAT_UINT2:
1295 {
1296 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1297 return format;
1298 }
1299 case VERTEX_FORMAT_UINT2_NORM:
1300 {
1301 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1302 return format;
1303 }
1304 case VERTEX_FORMAT_UINT3:
1305 {
1306 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1307 return format;
1308 }
1309 case VERTEX_FORMAT_UINT3_NORM:
1310 {
1311 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1312 return format;
1313 }
1314 case VERTEX_FORMAT_UINT4:
1315 {
1316 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1317 return format;
1318 }
1319 case VERTEX_FORMAT_UINT4_NORM:
1320 {
1321 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1322 return format;
1323 }
1324 case VERTEX_FORMAT_SBYTE1_INT:
1325 {
1326 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1327 return format;
1328 }
1329 case VERTEX_FORMAT_SBYTE2_INT:
1330 {
1331 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1332 return format;
1333 }
1334 case VERTEX_FORMAT_SBYTE3_INT:
1335 {
1336 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1337 return format;
1338 }
1339 case VERTEX_FORMAT_SBYTE4_INT:
1340 {
1341 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1342 return format;
1343 }
1344 case VERTEX_FORMAT_UBYTE1_INT:
1345 {
1346 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1347 return format;
1348 }
1349 case VERTEX_FORMAT_UBYTE2_INT:
1350 {
1351 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1352 return format;
1353 }
1354 case VERTEX_FORMAT_UBYTE3_INT:
1355 {
1356 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1357 return format;
1358 }
1359 case VERTEX_FORMAT_UBYTE4_INT:
1360 {
1361 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1362 return format;
1363 }
1364 case VERTEX_FORMAT_SSHORT1_INT:
1365 {
1366 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1367 return format;
1368 }
1369 case VERTEX_FORMAT_SSHORT2_INT:
1370 {
1371 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1372 return format;
1373 }
1374 case VERTEX_FORMAT_SSHORT3_INT:
1375 {
1376 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1377 return format;
1378 }
1379 case VERTEX_FORMAT_SSHORT4_INT:
1380 {
1381 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1382 return format;
1383 }
1384 case VERTEX_FORMAT_USHORT1_INT:
1385 {
1386 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1387 return format;
1388 }
1389 case VERTEX_FORMAT_USHORT2_INT:
1390 {
1391 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1392 return format;
1393 }
1394 case VERTEX_FORMAT_USHORT3_INT:
1395 {
1396 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1397 return format;
1398 }
1399 case VERTEX_FORMAT_USHORT4_INT:
1400 {
1401 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1402 return format;
1403 }
1404 case VERTEX_FORMAT_SINT1_INT:
1405 {
1406 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1407 return format;
1408 }
1409 case VERTEX_FORMAT_SINT2_INT:
1410 {
1411 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1412 return format;
1413 }
1414 case VERTEX_FORMAT_SINT3_INT:
1415 {
1416 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1417 return format;
1418 }
1419 case VERTEX_FORMAT_SINT4_INT:
1420 {
1421 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1422 return format;
1423 }
1424 case VERTEX_FORMAT_UINT1_INT:
1425 {
1426 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1427 return format;
1428 }
1429 case VERTEX_FORMAT_UINT2_INT:
1430 {
1431 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1432 return format;
1433 }
1434 case VERTEX_FORMAT_UINT3_INT:
1435 {
1436 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1437 return format;
1438 }
1439 case VERTEX_FORMAT_UINT4_INT:
1440 {
1441 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1442 return format;
1443 }
1444 case VERTEX_FORMAT_FIXED1:
1445 {
1446 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1447 return format;
1448 }
1449 case VERTEX_FORMAT_FIXED2:
1450 {
1451 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1452 return format;
1453 }
1454 case VERTEX_FORMAT_FIXED3:
1455 {
1456 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1457 return format;
1458 }
1459 case VERTEX_FORMAT_FIXED4:
1460 {
1461 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1462 return format;
1463 }
1464 case VERTEX_FORMAT_HALF1:
1465 {
1466 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1467 return format;
1468 }
1469 case VERTEX_FORMAT_HALF2:
1470 {
1471 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1472 return format;
1473 }
1474 case VERTEX_FORMAT_HALF3:
1475 {
1476 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1477 return format;
1478 }
1479 case VERTEX_FORMAT_HALF4:
1480 {
1481 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1482 return format;
1483 }
1484 case VERTEX_FORMAT_FLOAT1:
1485 {
1486 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1487 return format;
1488 }
1489 case VERTEX_FORMAT_FLOAT2:
1490 {
1491 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1492 return format;
1493 }
1494 case VERTEX_FORMAT_FLOAT3:
1495 {
1496 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1497 return format;
1498 }
1499 case VERTEX_FORMAT_FLOAT4:
1500 {
1501 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1502 return format;
1503 }
1504 case VERTEX_FORMAT_SINT210:
1505 {
1506 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1507 return format;
1508 }
1509 case VERTEX_FORMAT_UINT210:
1510 {
1511 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1512 return format;
1513 }
1514 case VERTEX_FORMAT_SINT210_NORM:
1515 {
1516 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1517 return format;
1518 }
1519 case VERTEX_FORMAT_UINT210_NORM:
1520 {
1521 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1522 return format;
1523 }
1524 case VERTEX_FORMAT_SINT210_INT:
1525 {
1526 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1527 return format;
1528 }
1529 case VERTEX_FORMAT_UINT210_INT:
1530 {
1531 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1532 return format;
1533 }
1534 default:
1535 {
1536 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1537 return format;
1538 }
1539 }
1540}
1541
1542VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1543 : type(typeIn),
1544 normalized(normalizedIn),
1545 components(componentsIn),
1546 pureInteger(pureIntegerIn)
1547{
1548 // float -> !normalized
1549 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1550}
1551
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001552}