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