blob: c9c701ebfd1f0e320ff042915101b81b5284e6b0 [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
Jamie Madille2e406c2016-06-02 13:04:10 -040014using namespace angle;
15
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000016namespace gl
17{
18
19// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
20// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
21// format and type combinations.
22
23typedef std::pair<GLenum, GLenum> FormatTypePair;
Geoff Lang051dbc72015-01-05 15:48:58 -050024typedef std::pair<FormatTypePair, GLenum> FormatPair;
25typedef std::map<FormatTypePair, GLenum> FormatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026
Jamie Madill89a0bf52013-09-18 14:36:24 -040027// A helper function to insert data into the format map with fewer characters.
Geoff Lang051dbc72015-01-05 15:48:58 -050028static inline void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000029{
Geoff Lang051dbc72015-01-05 15:48:58 -050030 map->insert(FormatPair(FormatTypePair(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000031}
32
Geoff Lange4a492b2014-06-19 14:14:41 -040033FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000034{
35 FormatMap map;
36
Geoff Lang051dbc72015-01-05 15:48:58 -050037 // | Format | Type | Internal format |
38 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
39 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
40 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
41 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
42 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
43 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
44 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
45 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000046
Geoff Lang051dbc72015-01-05 15:48:58 -050047 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
48 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
49 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
50 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
51 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
52 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
53 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000054
Geoff Lang051dbc72015-01-05 15:48:58 -050055 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
56 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
57 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
58 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
59 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
60 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
61 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
62 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000063
Geoff Lang051dbc72015-01-05 15:48:58 -050064 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
65 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
66 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
67 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
68 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
69 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000070
Geoff Lang051dbc72015-01-05 15:48:58 -050071 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
72 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
73 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
74 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
75 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076
Geoff Lang051dbc72015-01-05 15:48:58 -050077 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
78 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
79 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
80 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
81 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
82 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040083
Geoff Lang051dbc72015-01-05 15:48:58 -050084 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
85 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
86 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
87 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
88 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -040089
Geoff Lang051dbc72015-01-05 15:48:58 -050090 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
91 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
92 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
93 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
94 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
95 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040096
Geoff Lang051dbc72015-01-05 15:48:58 -050097 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
98 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
99 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
100 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
101 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
102 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
103 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
104 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
105 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
106 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
107 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
108 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400109
Geoff Lang051dbc72015-01-05 15:48:58 -0500110 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
111 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
112 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 -0400113
Geoff Lang051dbc72015-01-05 15:48:58 -0500114 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
115 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400116
Geoff Lang051dbc72015-01-05 15:48:58 -0500117 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
118 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
119 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
120 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400121
Geoff Lang051dbc72015-01-05 15:48:58 -0500122 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
123 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
124 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400125
Geoff Lang051dbc72015-01-05 15:48:58 -0500126 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400127
Geoff Lang051dbc72015-01-05 15:48:58 -0500128 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
129 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000130
131 return map;
132}
133
Geoff Lang5d601382014-07-22 15:14:06 -0400134Type::Type()
135 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200136 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400137 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400138{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000139}
140
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200141static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000142{
Geoff Lang5d601382014-07-22 15:14:06 -0400143 Type info;
144 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200145 GLuint i = 0;
146 while ((1u << i) < bytes)
147 {
148 ++i;
149 }
150 info.bytesShift = i;
151 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400152 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200153 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400154}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000155
Geoff Lang5d601382014-07-22 15:14:06 -0400156bool operator<(const Type& a, const Type& b)
157{
158 return memcmp(&a, &b, sizeof(Type)) < 0;
159}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000160
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000161// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400162static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000163{
Geoff Lang493daf52014-07-03 13:38:44 -0400164 return true;
165}
166
Geoff Lang493daf52014-07-03 13:38:44 -0400167static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000168{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000169 return false;
170}
171
Geoff Lange4a492b2014-06-19 14:14:41 -0400172template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400173static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400174{
175 return clientVersion >= minCoreGLVersion;
176}
177
Geoff Langcec35902014-04-16 10:52:36 -0400178// Pointer to a boolean memeber of the Extensions struct
179typedef bool(Extensions::*ExtensionBool);
180
181// Check support for a single extension
182template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400183static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400184{
Geoff Lange4a492b2014-06-19 14:14:41 -0400185 return extensions.*bool1;
186}
187
188// Check for a minimum client version or a single extension
189template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400190static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400191{
192 return clientVersion >= minCoreGLVersion || extensions.*bool1;
193}
194
195// Check for a minimum client version or two extensions
196template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400197static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400198{
Geoff Langabce7622014-09-19 16:13:00 -0400199 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
200}
201
202// Check for a minimum client version or at least one of two extensions
203template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
204static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
205{
206 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400207}
208
209// Check support for two extensions
210template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400211static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400212{
Geoff Langabce7622014-09-19 16:13:00 -0400213 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400214}
215
Geoff Lang60ad73d2015-10-23 10:08:44 -0400216// Check support for either of two extensions
217template <ExtensionBool bool1, ExtensionBool bool2>
218static bool RequireExtOrExt(GLuint, const Extensions &extensions)
219{
220 return extensions.*bool1 || extensions.*bool2;
221}
222
Jamie Madillcd089732015-12-17 09:53:09 -0500223// Special function for half float formats with three or four channels.
224static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
225{
226 return clientVersion >= 3 || extensions.textureHalfFloat;
227}
228
229static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
230{
231 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
232}
233
234// Special function for half float formats with one or two channels.
235static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
236{
237 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
238}
239
240static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
241{
242 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
243}
244
245// Special function for float formats with three or four channels.
246static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
247{
248 return clientVersion >= 3 || extensions.textureFloat;
249}
250
251static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
252{
253 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
254 return FloatSupport(clientVersion, extensions) &&
255 (extensions.colorBufferFloat || clientVersion == 2);
256}
257
258// Special function for float formats with one or two channels.
259static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
260{
261 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
262}
263
264static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
265{
266 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
267 return FloatSupportRG(clientVersion, extensions) &&
268 (extensions.colorBufferFloat || clientVersion == 2);
269}
270
Geoff Lang5d601382014-07-22 15:14:06 -0400271InternalFormat::InternalFormat()
272 : redBits(0),
273 greenBits(0),
274 blueBits(0),
275 luminanceBits(0),
276 alphaBits(0),
277 sharedBits(0),
278 depthBits(0),
279 stencilBits(0),
280 pixelBytes(0),
281 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400282 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400283 compressedBlockWidth(0),
284 compressedBlockHeight(0),
285 format(GL_NONE),
286 type(GL_NONE),
287 componentType(GL_NONE),
288 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400289 textureSupport(NeverSupported),
290 renderSupport(NeverSupported),
291 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000292{
Geoff Lang5d601382014-07-22 15:14:06 -0400293}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000294
Geoff Lang5d601382014-07-22 15:14:06 -0400295static InternalFormat UnsizedFormat(GLenum format, InternalFormat::SupportCheckFunction textureSupport,
296 InternalFormat::SupportCheckFunction renderSupport,
297 InternalFormat::SupportCheckFunction filterSupport)
298{
299 InternalFormat formatInfo;
300 formatInfo.format = format;
301 formatInfo.textureSupport = textureSupport;
302 formatInfo.renderSupport = renderSupport;
303 formatInfo.filterSupport = filterSupport;
304 return formatInfo;
305}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000306
Geoff Lang5d601382014-07-22 15:14:06 -0400307static InternalFormat RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared,
308 GLenum format, GLenum type, GLenum componentType, bool srgb,
309 InternalFormat::SupportCheckFunction textureSupport,
310 InternalFormat::SupportCheckFunction renderSupport,
311 InternalFormat::SupportCheckFunction filterSupport)
312{
313 InternalFormat formatInfo;
314 formatInfo.redBits = red;
315 formatInfo.greenBits = green;
316 formatInfo.blueBits = blue;
317 formatInfo.alphaBits = alpha;
318 formatInfo.sharedBits = shared;
319 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
320 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
321 formatInfo.format = format;
322 formatInfo.type = type;
323 formatInfo.componentType = componentType;
324 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
325 formatInfo.textureSupport = textureSupport;
326 formatInfo.renderSupport = renderSupport;
327 formatInfo.filterSupport = filterSupport;
328 return formatInfo;
329}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000330
Geoff Lang5d601382014-07-22 15:14:06 -0400331static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
332 InternalFormat::SupportCheckFunction textureSupport,
333 InternalFormat::SupportCheckFunction renderSupport,
334 InternalFormat::SupportCheckFunction filterSupport)
335{
336 InternalFormat formatInfo;
337 formatInfo.luminanceBits = luminance;
338 formatInfo.alphaBits = alpha;
339 formatInfo.pixelBytes = (luminance + alpha) / 8;
340 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
341 formatInfo.format = format;
342 formatInfo.type = type;
343 formatInfo.componentType = componentType;
344 formatInfo.colorEncoding = GL_LINEAR;
345 formatInfo.textureSupport = textureSupport;
346 formatInfo.renderSupport = renderSupport;
347 formatInfo.filterSupport = filterSupport;
348 return formatInfo;
349}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000350
Geoff Lang5d601382014-07-22 15:14:06 -0400351static InternalFormat DepthStencilFormat(GLuint depthBits, GLuint stencilBits, GLuint unusedBits, GLenum format,
352 GLenum type, GLenum componentType, InternalFormat::SupportCheckFunction textureSupport,
353 InternalFormat::SupportCheckFunction renderSupport,
354 InternalFormat::SupportCheckFunction filterSupport)
355{
356 InternalFormat formatInfo;
357 formatInfo.depthBits = depthBits;
358 formatInfo.stencilBits = stencilBits;
359 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
360 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
361 formatInfo.format = format;
362 formatInfo.type = type;
363 formatInfo.componentType = componentType;
364 formatInfo.colorEncoding = GL_LINEAR;
365 formatInfo.textureSupport = textureSupport;
366 formatInfo.renderSupport = renderSupport;
367 formatInfo.filterSupport = filterSupport;
368 return formatInfo;
369}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000370
Geoff Lang5d601382014-07-22 15:14:06 -0400371static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
372 GLuint componentCount, GLenum format, GLenum type, bool srgb,
373 InternalFormat::SupportCheckFunction textureSupport,
374 InternalFormat::SupportCheckFunction renderSupport,
375 InternalFormat::SupportCheckFunction filterSupport)
376{
377 InternalFormat formatInfo;
378 formatInfo.compressedBlockWidth = compressedBlockWidth;
379 formatInfo.compressedBlockHeight = compressedBlockHeight;
380 formatInfo.pixelBytes = compressedBlockSize / 8;
381 formatInfo.componentCount = componentCount;
382 formatInfo.format = format;
383 formatInfo.type = type;
384 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
385 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
386 formatInfo.compressed = true;
387 formatInfo.textureSupport = textureSupport;
388 formatInfo.renderSupport = renderSupport;
389 formatInfo.filterSupport = filterSupport;
390 return formatInfo;
391}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000392
Geoff Lang5d601382014-07-22 15:14:06 -0400393typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
394typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000395
Geoff Lange4a492b2014-06-19 14:14:41 -0400396static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000397{
398 InternalFormatInfoMap map;
399
Geoff Lang9bbad182015-09-04 11:07:29 -0400400 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000401 // From ES 3.0.1 spec, table 3.12
Geoff Lang5d601382014-07-22 15:14:06 -0400402 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000403
Geoff Langabce7622014-09-19 16:13:00 -0400404 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
405 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)));
406 map.insert(InternalFormatInfoPair(GL_R8_SNORM, RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
407 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)));
408 map.insert(InternalFormatInfoPair(GL_RG8_SNORM, RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
409 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)));
410 map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
411 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)));
412 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)));
413 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)));
414 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)));
415 map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported)));
416 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 -0400417 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 -0400418 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)));
419 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)));
420 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)));
421 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)));
422 map.insert(InternalFormatInfoPair(GL_R8I, RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
423 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)));
424 map.insert(InternalFormatInfoPair(GL_R16I, RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
425 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)));
426 map.insert(InternalFormatInfoPair(GL_R32I, RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
427 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)));
428 map.insert(InternalFormatInfoPair(GL_RG8I, RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
429 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)));
430 map.insert(InternalFormatInfoPair(GL_RG16I, RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
431 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)));
432 map.insert(InternalFormatInfoPair(GL_RG32I, RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
433 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)));
434 map.insert(InternalFormatInfoPair(GL_RGB8I, RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
435 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)));
436 map.insert(InternalFormatInfoPair(GL_RGB16I, RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
437 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)));
438 map.insert(InternalFormatInfoPair(GL_RGB32I, RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported)));
439 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)));
440 map.insert(InternalFormatInfoPair(GL_RGBA8I, RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
441 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)));
442 map.insert(InternalFormatInfoPair(GL_RGBA16I, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
443 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)));
444 map.insert(InternalFormatInfoPair(GL_RGBA32I, RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported)));
445 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 +0000446
Geoff Langabce7622014-09-19 16:13:00 -0400447 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)));
448 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)));
449 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 +0000450
451 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madillcd089732015-12-17 09:53:09 -0500452 // | Internal format | | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
453 // | | | | | | | type | | | | |
454 map.insert(InternalFormatInfoPair(GL_R16F, RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
455 map.insert(InternalFormatInfoPair(GL_RG16F, RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>)));
456 map.insert(InternalFormatInfoPair(GL_RGB16F, RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
457 map.insert(InternalFormatInfoPair(GL_RGBA16F, RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>)));
458 map.insert(InternalFormatInfoPair(GL_R32F, RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
459 map.insert(InternalFormatInfoPair(GL_RG32F, RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> )));
460 map.insert(InternalFormatInfoPair(GL_RGB32F, RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> )));
461 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 +0000462
463 // Depth stencil formats
Geoff Langabce7622014-09-19 16:13:00 -0400464 // | Internal format | | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
465 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>)));
466 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>)));
467 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 -0500468 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 -0400469 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 )));
470 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 -0800471 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000472
473 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400474 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400475 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
476 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
477 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
478 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
479 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
480 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
481 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
482 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
483 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 +0000484
485 // Unsized formats
Geoff Langabce7622014-09-19 16:13:00 -0400486 // | Internal format | | Format | Supported | Renderable | Filterable |
487 map.insert(InternalFormatInfoPair(GL_ALPHA, UnsizedFormat(GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
488 map.insert(InternalFormatInfoPair(GL_LUMINANCE, UnsizedFormat(GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported)));
489 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, UnsizedFormat(GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported)));
490 map.insert(InternalFormatInfoPair(GL_RED, UnsizedFormat(GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
491 map.insert(InternalFormatInfoPair(GL_RG, UnsizedFormat(GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported)));
492 map.insert(InternalFormatInfoPair(GL_RGB, UnsizedFormat(GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported)));
493 map.insert(InternalFormatInfoPair(GL_RGBA, UnsizedFormat(GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported)));
494 map.insert(InternalFormatInfoPair(GL_RED_INTEGER, UnsizedFormat(GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
495 map.insert(InternalFormatInfoPair(GL_RG_INTEGER, UnsizedFormat(GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
496 map.insert(InternalFormatInfoPair(GL_RGB_INTEGER, UnsizedFormat(GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
497 map.insert(InternalFormatInfoPair(GL_RGBA_INTEGER, UnsizedFormat(GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported )));
498 map.insert(InternalFormatInfoPair(GL_BGRA_EXT, UnsizedFormat(GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported)));
499 map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, UnsizedFormat(GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported)));
500 map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL, UnsizedFormat(GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported)));
501 map.insert(InternalFormatInfoPair(GL_SRGB_EXT, UnsizedFormat(GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported)));
502 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 +0000503
504 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400505 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
506 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
507 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)));
508 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
509 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)));
510 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
511 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
512 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)));
513 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)));
514 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)));
515 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 +0000516
517 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400518 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
519 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)));
520 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 +0000521
522 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400523 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 +0000524
525 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400526 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)));
527
528 // From GL_OES_compressed_ETC1_RGB8_texture
529 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 +0000530
Geoff Lang60ad73d2015-10-23 10:08:44 -0400531 // From KHR_texture_compression_astc_hdr
532 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
533 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)));
534 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)));
535 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)));
536 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)));
537 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)));
538 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)));
539 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)));
540 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)));
541 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)));
542 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)));
543 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)));
544 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)));
545 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)));
546 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)));
547
548 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)));
549 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)));
550 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)));
551 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)));
552 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)));
553 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)));
554 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)));
555 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)));
556 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)));
557 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)));
558 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)));
559 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)));
560 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)));
561 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)));
562
Corentin Walleze0902642014-11-04 12:32:15 -0800563 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
564 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
565 // - All other stencil formats (all depth-stencil) are either float or normalized
566 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
567 // | Internal format | |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
568 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 -0800569
570 // From GL_ANGLE_lossy_etc_decode
571 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)));
572
Vincent Lang25ab4512016-05-13 18:13:59 +0200573 // From GL_EXT_texture_norm16
574 // | Internal format | | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
575 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)));
576 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)));
577 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)));
578 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)));
579 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)));
580 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)));
581 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)));
582 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)));
583
Geoff Lang9bbad182015-09-04 11:07:29 -0400584 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800585
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000586 return map;
587}
588
Geoff Lange4a492b2014-06-19 14:14:41 -0400589static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000590{
Geoff Lange4a492b2014-06-19 14:14:41 -0400591 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
592 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000593}
594
Geoff Lange4a492b2014-06-19 14:14:41 -0400595static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400596{
597 FormatSet result;
598
Geoff Lange4a492b2014-06-19 14:14:41 -0400599 const InternalFormatInfoMap &formats = GetInternalFormatMap();
Geoff Langcec35902014-04-16 10:52:36 -0400600 for (InternalFormatInfoMap::const_iterator i = formats.begin(); i != formats.end(); i++)
601 {
Geoff Lang5d601382014-07-22 15:14:06 -0400602 if (i->second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400603 {
604 result.insert(i->first);
605 }
606 }
607
608 return result;
609}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000610
Geoff Lang5d601382014-07-22 15:14:06 -0400611const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000612{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200613 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000614 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200615 case GL_UNSIGNED_BYTE:
616 case GL_BYTE:
617 {
618 static const Type info = GenTypeInfo(1, false);
619 return info;
620 }
621 case GL_UNSIGNED_SHORT:
622 case GL_SHORT:
623 case GL_HALF_FLOAT:
624 case GL_HALF_FLOAT_OES:
625 {
626 static const Type info = GenTypeInfo(2, false);
627 return info;
628 }
629 case GL_UNSIGNED_INT:
630 case GL_INT:
631 case GL_FLOAT:
632 {
633 static const Type info = GenTypeInfo(4, false);
634 return info;
635 }
636 case GL_UNSIGNED_SHORT_5_6_5:
637 case GL_UNSIGNED_SHORT_4_4_4_4:
638 case GL_UNSIGNED_SHORT_5_5_5_1:
639 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
640 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
641 {
642 static const Type info = GenTypeInfo(2, true);
643 return info;
644 }
645 case GL_UNSIGNED_INT_2_10_10_10_REV:
646 case GL_UNSIGNED_INT_24_8:
647 case GL_UNSIGNED_INT_10F_11F_11F_REV:
648 case GL_UNSIGNED_INT_5_9_9_9_REV:
649 {
650 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
651 static const Type info = GenTypeInfo(4, true);
652 return info;
653 }
654 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
655 {
656 static const Type info = GenTypeInfo(8, true);
657 return info;
658 }
659 default:
660 {
661 static const Type defaultInfo;
662 return defaultInfo;
663 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000664 }
665}
666
Geoff Lang5d601382014-07-22 15:14:06 -0400667const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000668{
Geoff Lang5d601382014-07-22 15:14:06 -0400669 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
670 InternalFormatInfoMap::const_iterator iter = formatMap.find(internalFormat);
671 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000672 {
Geoff Lang5d601382014-07-22 15:14:06 -0400673 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000674 }
675 else
676 {
Geoff Lang5d601382014-07-22 15:14:06 -0400677 static const InternalFormat defaultInternalFormat;
678 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000679 }
680}
681
Jamie Madille2e406c2016-06-02 13:04:10 -0400682gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
683 GLsizei width,
684 GLint alignment,
685 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000686{
687 ASSERT(alignment > 0 && isPow2(alignment));
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800688 GLuint rowBytes;
689 if (rowLength > 0)
690 {
691 ASSERT(!compressed);
Jamie Madille2e406c2016-06-02 13:04:10 -0400692 CheckedNumeric<GLuint> checkedBytes(pixelBytes);
693 checkedBytes *= rowLength;
694 ANGLE_TRY_CHECKED_MATH(checkedBytes);
695 rowBytes = checkedBytes.ValueOrDie();
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800696 }
697 else
698 {
Jamie Madille2e406c2016-06-02 13:04:10 -0400699 ANGLE_TRY_RESULT(computeBlockSize(formatType, width, 1), rowBytes);
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800700 }
Jamie Madille2e406c2016-06-02 13:04:10 -0400701 auto checkedResult = rx::CheckedRoundUp(rowBytes, static_cast<GLuint>(alignment));
702 ANGLE_TRY_CHECKED_MATH(checkedResult);
703 return checkedResult.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000704}
705
Jamie Madille2e406c2016-06-02 13:04:10 -0400706gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
707 GLsizei width,
708 GLsizei height,
709 GLint alignment,
710 GLint rowLength,
711 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000712{
Minmin Gongadff67b2015-10-14 10:34:45 -0400713 GLuint rows;
714 if (imageHeight > 0)
715 {
716 rows = imageHeight;
717 }
718 else
719 {
720 rows = height;
721 }
Jamie Madille2e406c2016-06-02 13:04:10 -0400722 GLuint rowPitch = 0;
723 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
724
725 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
726 auto depthPitch = checkedRowPitch * rows;
727 ANGLE_TRY_CHECKED_MATH(depthPitch);
728 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000729}
730
Jamie Madille2e406c2016-06-02 13:04:10 -0400731gl::ErrorOrResult<GLuint> InternalFormat::computeBlockSize(GLenum formatType,
732 GLsizei width,
733 GLsizei height) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000734{
Jamie Madille2e406c2016-06-02 13:04:10 -0400735 CheckedNumeric<GLuint> checkedWidth(width);
736 CheckedNumeric<GLuint> checkedHeight(height);
737
Geoff Lang5d601382014-07-22 15:14:06 -0400738 if (compressed)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000739 {
Jamie Madille2e406c2016-06-02 13:04:10 -0400740 auto numBlocksWide = (checkedWidth + compressedBlockWidth - 1u) / compressedBlockWidth;
741 auto numBlocksHigh = (checkedHeight + compressedBlockHeight - 1u) / compressedBlockHeight;
742 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes;
743 ANGLE_TRY_CHECKED_MATH(bytes);
744 return bytes.ValueOrDie();
Geoff Lang5d601382014-07-22 15:14:06 -0400745 }
Jamie Madille2e406c2016-06-02 13:04:10 -0400746
747 const Type &typeInfo = GetTypeInfo(formatType);
748 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
749
750 auto result = checkedWidth * checkedHeight * components * typeInfo.bytes;
751 ANGLE_TRY_CHECKED_MATH(result);
752 return result.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000753}
754
Minmin Gongadff67b2015-10-14 10:34:45 -0400755GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
756 GLint depthPitch,
757 GLint skipImages,
758 GLint skipRows,
759 GLint skipPixels) const
760{
761 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
762}
763
Geoff Lang5d601382014-07-22 15:14:06 -0400764GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000765{
Geoff Lang5d601382014-07-22 15:14:06 -0400766 const InternalFormat& formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500767 if (formatInfo.pixelBytes > 0)
768 {
769 return internalFormat;
770 }
771 else
772 {
773 static const FormatMap formatMap = BuildFormatMap();
774 FormatMap::const_iterator iter = formatMap.find(FormatTypePair(internalFormat, type));
775 if (iter != formatMap.end())
776 {
777 return iter->second;
778 }
779 else
780 {
781 return GL_NONE;
782 }
783 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000784}
785
Geoff Lange4a492b2014-06-19 14:14:41 -0400786const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400787{
Geoff Lange4a492b2014-06-19 14:14:41 -0400788 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400789 return formatSet;
790}
791
Jamie Madill09e2d932015-07-14 16:40:31 -0400792AttributeType GetAttributeType(GLenum enumValue)
793{
794 switch (enumValue)
795 {
796 case GL_FLOAT:
797 return ATTRIBUTE_FLOAT;
798 case GL_FLOAT_VEC2:
799 return ATTRIBUTE_VEC2;
800 case GL_FLOAT_VEC3:
801 return ATTRIBUTE_VEC3;
802 case GL_FLOAT_VEC4:
803 return ATTRIBUTE_VEC4;
804 case GL_INT:
805 return ATTRIBUTE_INT;
806 case GL_INT_VEC2:
807 return ATTRIBUTE_IVEC2;
808 case GL_INT_VEC3:
809 return ATTRIBUTE_IVEC3;
810 case GL_INT_VEC4:
811 return ATTRIBUTE_IVEC4;
812 case GL_UNSIGNED_INT:
813 return ATTRIBUTE_UINT;
814 case GL_UNSIGNED_INT_VEC2:
815 return ATTRIBUTE_UVEC2;
816 case GL_UNSIGNED_INT_VEC3:
817 return ATTRIBUTE_UVEC3;
818 case GL_UNSIGNED_INT_VEC4:
819 return ATTRIBUTE_UVEC4;
820 case GL_FLOAT_MAT2:
821 return ATTRIBUTE_MAT2;
822 case GL_FLOAT_MAT3:
823 return ATTRIBUTE_MAT3;
824 case GL_FLOAT_MAT4:
825 return ATTRIBUTE_MAT4;
826 case GL_FLOAT_MAT2x3:
827 return ATTRIBUTE_MAT2x3;
828 case GL_FLOAT_MAT2x4:
829 return ATTRIBUTE_MAT2x4;
830 case GL_FLOAT_MAT3x2:
831 return ATTRIBUTE_MAT3x2;
832 case GL_FLOAT_MAT3x4:
833 return ATTRIBUTE_MAT3x4;
834 case GL_FLOAT_MAT4x2:
835 return ATTRIBUTE_MAT4x2;
836 case GL_FLOAT_MAT4x3:
837 return ATTRIBUTE_MAT4x3;
838 default:
839 UNREACHABLE();
840 return ATTRIBUTE_FLOAT;
841 }
842}
843
Jamie Madilld3dfda22015-07-06 08:28:49 -0400844VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
845{
846 switch (type)
847 {
848 case GL_BYTE:
849 switch (components)
850 {
851 case 1:
852 if (pureInteger)
853 return VERTEX_FORMAT_SBYTE1_INT;
854 if (normalized)
855 return VERTEX_FORMAT_SBYTE1_NORM;
856 return VERTEX_FORMAT_SBYTE1;
857 case 2:
858 if (pureInteger)
859 return VERTEX_FORMAT_SBYTE2_INT;
860 if (normalized)
861 return VERTEX_FORMAT_SBYTE2_NORM;
862 return VERTEX_FORMAT_SBYTE2;
863 case 3:
864 if (pureInteger)
865 return VERTEX_FORMAT_SBYTE3_INT;
866 if (normalized)
867 return VERTEX_FORMAT_SBYTE3_NORM;
868 return VERTEX_FORMAT_SBYTE3;
869 case 4:
870 if (pureInteger)
871 return VERTEX_FORMAT_SBYTE4_INT;
872 if (normalized)
873 return VERTEX_FORMAT_SBYTE4_NORM;
874 return VERTEX_FORMAT_SBYTE4;
875 default:
876 UNREACHABLE();
877 break;
878 }
879 case GL_UNSIGNED_BYTE:
880 switch (components)
881 {
882 case 1:
883 if (pureInteger)
884 return VERTEX_FORMAT_UBYTE1_INT;
885 if (normalized)
886 return VERTEX_FORMAT_UBYTE1_NORM;
887 return VERTEX_FORMAT_UBYTE1;
888 case 2:
889 if (pureInteger)
890 return VERTEX_FORMAT_UBYTE2_INT;
891 if (normalized)
892 return VERTEX_FORMAT_UBYTE2_NORM;
893 return VERTEX_FORMAT_UBYTE2;
894 case 3:
895 if (pureInteger)
896 return VERTEX_FORMAT_UBYTE3_INT;
897 if (normalized)
898 return VERTEX_FORMAT_UBYTE3_NORM;
899 return VERTEX_FORMAT_UBYTE3;
900 case 4:
901 if (pureInteger)
902 return VERTEX_FORMAT_UBYTE4_INT;
903 if (normalized)
904 return VERTEX_FORMAT_UBYTE4_NORM;
905 return VERTEX_FORMAT_UBYTE4;
906 default:
907 UNREACHABLE();
908 break;
909 }
910 case GL_SHORT:
911 switch (components)
912 {
913 case 1:
914 if (pureInteger)
915 return VERTEX_FORMAT_SSHORT1_INT;
916 if (normalized)
917 return VERTEX_FORMAT_SSHORT1_NORM;
918 return VERTEX_FORMAT_SSHORT1;
919 case 2:
920 if (pureInteger)
921 return VERTEX_FORMAT_SSHORT2_INT;
922 if (normalized)
923 return VERTEX_FORMAT_SSHORT2_NORM;
924 return VERTEX_FORMAT_SSHORT2;
925 case 3:
926 if (pureInteger)
927 return VERTEX_FORMAT_SSHORT3_INT;
928 if (normalized)
929 return VERTEX_FORMAT_SSHORT3_NORM;
930 return VERTEX_FORMAT_SSHORT3;
931 case 4:
932 if (pureInteger)
933 return VERTEX_FORMAT_SSHORT4_INT;
934 if (normalized)
935 return VERTEX_FORMAT_SSHORT4_NORM;
936 return VERTEX_FORMAT_SSHORT4;
937 default:
938 UNREACHABLE();
939 break;
940 }
941 case GL_UNSIGNED_SHORT:
942 switch (components)
943 {
944 case 1:
945 if (pureInteger)
946 return VERTEX_FORMAT_USHORT1_INT;
947 if (normalized)
948 return VERTEX_FORMAT_USHORT1_NORM;
949 return VERTEX_FORMAT_USHORT1;
950 case 2:
951 if (pureInteger)
952 return VERTEX_FORMAT_USHORT2_INT;
953 if (normalized)
954 return VERTEX_FORMAT_USHORT2_NORM;
955 return VERTEX_FORMAT_USHORT2;
956 case 3:
957 if (pureInteger)
958 return VERTEX_FORMAT_USHORT3_INT;
959 if (normalized)
960 return VERTEX_FORMAT_USHORT3_NORM;
961 return VERTEX_FORMAT_USHORT3;
962 case 4:
963 if (pureInteger)
964 return VERTEX_FORMAT_USHORT4_INT;
965 if (normalized)
966 return VERTEX_FORMAT_USHORT4_NORM;
967 return VERTEX_FORMAT_USHORT4;
968 default:
969 UNREACHABLE();
970 break;
971 }
972 case GL_INT:
973 switch (components)
974 {
975 case 1:
976 if (pureInteger)
977 return VERTEX_FORMAT_SINT1_INT;
978 if (normalized)
979 return VERTEX_FORMAT_SINT1_NORM;
980 return VERTEX_FORMAT_SINT1;
981 case 2:
982 if (pureInteger)
983 return VERTEX_FORMAT_SINT2_INT;
984 if (normalized)
985 return VERTEX_FORMAT_SINT2_NORM;
986 return VERTEX_FORMAT_SINT2;
987 case 3:
988 if (pureInteger)
989 return VERTEX_FORMAT_SINT3_INT;
990 if (normalized)
991 return VERTEX_FORMAT_SINT3_NORM;
992 return VERTEX_FORMAT_SINT3;
993 case 4:
994 if (pureInteger)
995 return VERTEX_FORMAT_SINT4_INT;
996 if (normalized)
997 return VERTEX_FORMAT_SINT4_NORM;
998 return VERTEX_FORMAT_SINT4;
999 default:
1000 UNREACHABLE();
1001 break;
1002 }
1003 case GL_UNSIGNED_INT:
1004 switch (components)
1005 {
1006 case 1:
1007 if (pureInteger)
1008 return VERTEX_FORMAT_UINT1_INT;
1009 if (normalized)
1010 return VERTEX_FORMAT_UINT1_NORM;
1011 return VERTEX_FORMAT_UINT1;
1012 case 2:
1013 if (pureInteger)
1014 return VERTEX_FORMAT_UINT2_INT;
1015 if (normalized)
1016 return VERTEX_FORMAT_UINT2_NORM;
1017 return VERTEX_FORMAT_UINT2;
1018 case 3:
1019 if (pureInteger)
1020 return VERTEX_FORMAT_UINT3_INT;
1021 if (normalized)
1022 return VERTEX_FORMAT_UINT3_NORM;
1023 return VERTEX_FORMAT_UINT3;
1024 case 4:
1025 if (pureInteger)
1026 return VERTEX_FORMAT_UINT4_INT;
1027 if (normalized)
1028 return VERTEX_FORMAT_UINT4_NORM;
1029 return VERTEX_FORMAT_UINT4;
1030 default:
1031 UNREACHABLE();
1032 break;
1033 }
1034 case GL_FLOAT:
1035 switch (components)
1036 {
1037 case 1:
1038 return VERTEX_FORMAT_FLOAT1;
1039 case 2:
1040 return VERTEX_FORMAT_FLOAT2;
1041 case 3:
1042 return VERTEX_FORMAT_FLOAT3;
1043 case 4:
1044 return VERTEX_FORMAT_FLOAT4;
1045 default:
1046 UNREACHABLE();
1047 break;
1048 }
1049 case GL_HALF_FLOAT:
1050 switch (components)
1051 {
1052 case 1:
1053 return VERTEX_FORMAT_HALF1;
1054 case 2:
1055 return VERTEX_FORMAT_HALF2;
1056 case 3:
1057 return VERTEX_FORMAT_HALF3;
1058 case 4:
1059 return VERTEX_FORMAT_HALF4;
1060 default:
1061 UNREACHABLE();
1062 break;
1063 }
1064 case GL_FIXED:
1065 switch (components)
1066 {
1067 case 1:
1068 return VERTEX_FORMAT_FIXED1;
1069 case 2:
1070 return VERTEX_FORMAT_FIXED2;
1071 case 3:
1072 return VERTEX_FORMAT_FIXED3;
1073 case 4:
1074 return VERTEX_FORMAT_FIXED4;
1075 default:
1076 UNREACHABLE();
1077 break;
1078 }
1079 case GL_INT_2_10_10_10_REV:
1080 if (pureInteger)
1081 return VERTEX_FORMAT_SINT210_INT;
1082 if (normalized)
1083 return VERTEX_FORMAT_SINT210_NORM;
1084 return VERTEX_FORMAT_SINT210;
1085 case GL_UNSIGNED_INT_2_10_10_10_REV:
1086 if (pureInteger)
1087 return VERTEX_FORMAT_UINT210_INT;
1088 if (normalized)
1089 return VERTEX_FORMAT_UINT210_NORM;
1090 return VERTEX_FORMAT_UINT210;
1091 default:
1092 UNREACHABLE();
1093 break;
1094 }
1095 return VERTEX_FORMAT_UBYTE1;
1096}
1097
1098VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1099{
1100 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1101}
1102
1103VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1104{
1105 if (!attrib.enabled)
1106 {
1107 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1108 }
1109 return GetVertexFormatType(attrib);
1110}
1111
1112const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1113{
1114 switch (vertexFormatType)
1115 {
1116 case VERTEX_FORMAT_SBYTE1:
1117 {
1118 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1119 return format;
1120 }
1121 case VERTEX_FORMAT_SBYTE1_NORM:
1122 {
1123 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1124 return format;
1125 }
1126 case VERTEX_FORMAT_SBYTE2:
1127 {
1128 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1129 return format;
1130 }
1131 case VERTEX_FORMAT_SBYTE2_NORM:
1132 {
1133 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1134 return format;
1135 }
1136 case VERTEX_FORMAT_SBYTE3:
1137 {
1138 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1139 return format;
1140 }
1141 case VERTEX_FORMAT_SBYTE3_NORM:
1142 {
1143 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1144 return format;
1145 }
1146 case VERTEX_FORMAT_SBYTE4:
1147 {
1148 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1149 return format;
1150 }
1151 case VERTEX_FORMAT_SBYTE4_NORM:
1152 {
1153 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1154 return format;
1155 }
1156 case VERTEX_FORMAT_UBYTE1:
1157 {
1158 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1159 return format;
1160 }
1161 case VERTEX_FORMAT_UBYTE1_NORM:
1162 {
1163 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1164 return format;
1165 }
1166 case VERTEX_FORMAT_UBYTE2:
1167 {
1168 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1169 return format;
1170 }
1171 case VERTEX_FORMAT_UBYTE2_NORM:
1172 {
1173 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1174 return format;
1175 }
1176 case VERTEX_FORMAT_UBYTE3:
1177 {
1178 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1179 return format;
1180 }
1181 case VERTEX_FORMAT_UBYTE3_NORM:
1182 {
1183 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1184 return format;
1185 }
1186 case VERTEX_FORMAT_UBYTE4:
1187 {
1188 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1189 return format;
1190 }
1191 case VERTEX_FORMAT_UBYTE4_NORM:
1192 {
1193 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1194 return format;
1195 }
1196 case VERTEX_FORMAT_SSHORT1:
1197 {
1198 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1199 return format;
1200 }
1201 case VERTEX_FORMAT_SSHORT1_NORM:
1202 {
1203 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1204 return format;
1205 }
1206 case VERTEX_FORMAT_SSHORT2:
1207 {
1208 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1209 return format;
1210 }
1211 case VERTEX_FORMAT_SSHORT2_NORM:
1212 {
1213 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1214 return format;
1215 }
1216 case VERTEX_FORMAT_SSHORT3:
1217 {
1218 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1219 return format;
1220 }
1221 case VERTEX_FORMAT_SSHORT3_NORM:
1222 {
1223 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1224 return format;
1225 }
1226 case VERTEX_FORMAT_SSHORT4:
1227 {
1228 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1229 return format;
1230 }
1231 case VERTEX_FORMAT_SSHORT4_NORM:
1232 {
1233 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1234 return format;
1235 }
1236 case VERTEX_FORMAT_USHORT1:
1237 {
1238 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1239 return format;
1240 }
1241 case VERTEX_FORMAT_USHORT1_NORM:
1242 {
1243 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1244 return format;
1245 }
1246 case VERTEX_FORMAT_USHORT2:
1247 {
1248 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1249 return format;
1250 }
1251 case VERTEX_FORMAT_USHORT2_NORM:
1252 {
1253 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1254 return format;
1255 }
1256 case VERTEX_FORMAT_USHORT3:
1257 {
1258 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1259 return format;
1260 }
1261 case VERTEX_FORMAT_USHORT3_NORM:
1262 {
1263 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1264 return format;
1265 }
1266 case VERTEX_FORMAT_USHORT4:
1267 {
1268 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1269 return format;
1270 }
1271 case VERTEX_FORMAT_USHORT4_NORM:
1272 {
1273 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1274 return format;
1275 }
1276 case VERTEX_FORMAT_SINT1:
1277 {
1278 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1279 return format;
1280 }
1281 case VERTEX_FORMAT_SINT1_NORM:
1282 {
1283 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1284 return format;
1285 }
1286 case VERTEX_FORMAT_SINT2:
1287 {
1288 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1289 return format;
1290 }
1291 case VERTEX_FORMAT_SINT2_NORM:
1292 {
1293 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1294 return format;
1295 }
1296 case VERTEX_FORMAT_SINT3:
1297 {
1298 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1299 return format;
1300 }
1301 case VERTEX_FORMAT_SINT3_NORM:
1302 {
1303 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1304 return format;
1305 }
1306 case VERTEX_FORMAT_SINT4:
1307 {
1308 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1309 return format;
1310 }
1311 case VERTEX_FORMAT_SINT4_NORM:
1312 {
1313 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1314 return format;
1315 }
1316 case VERTEX_FORMAT_UINT1:
1317 {
1318 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1319 return format;
1320 }
1321 case VERTEX_FORMAT_UINT1_NORM:
1322 {
1323 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1324 return format;
1325 }
1326 case VERTEX_FORMAT_UINT2:
1327 {
1328 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1329 return format;
1330 }
1331 case VERTEX_FORMAT_UINT2_NORM:
1332 {
1333 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1334 return format;
1335 }
1336 case VERTEX_FORMAT_UINT3:
1337 {
1338 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1339 return format;
1340 }
1341 case VERTEX_FORMAT_UINT3_NORM:
1342 {
1343 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1344 return format;
1345 }
1346 case VERTEX_FORMAT_UINT4:
1347 {
1348 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1349 return format;
1350 }
1351 case VERTEX_FORMAT_UINT4_NORM:
1352 {
1353 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1354 return format;
1355 }
1356 case VERTEX_FORMAT_SBYTE1_INT:
1357 {
1358 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1359 return format;
1360 }
1361 case VERTEX_FORMAT_SBYTE2_INT:
1362 {
1363 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1364 return format;
1365 }
1366 case VERTEX_FORMAT_SBYTE3_INT:
1367 {
1368 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1369 return format;
1370 }
1371 case VERTEX_FORMAT_SBYTE4_INT:
1372 {
1373 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1374 return format;
1375 }
1376 case VERTEX_FORMAT_UBYTE1_INT:
1377 {
1378 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1379 return format;
1380 }
1381 case VERTEX_FORMAT_UBYTE2_INT:
1382 {
1383 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1384 return format;
1385 }
1386 case VERTEX_FORMAT_UBYTE3_INT:
1387 {
1388 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1389 return format;
1390 }
1391 case VERTEX_FORMAT_UBYTE4_INT:
1392 {
1393 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1394 return format;
1395 }
1396 case VERTEX_FORMAT_SSHORT1_INT:
1397 {
1398 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1399 return format;
1400 }
1401 case VERTEX_FORMAT_SSHORT2_INT:
1402 {
1403 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1404 return format;
1405 }
1406 case VERTEX_FORMAT_SSHORT3_INT:
1407 {
1408 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1409 return format;
1410 }
1411 case VERTEX_FORMAT_SSHORT4_INT:
1412 {
1413 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1414 return format;
1415 }
1416 case VERTEX_FORMAT_USHORT1_INT:
1417 {
1418 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1419 return format;
1420 }
1421 case VERTEX_FORMAT_USHORT2_INT:
1422 {
1423 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1424 return format;
1425 }
1426 case VERTEX_FORMAT_USHORT3_INT:
1427 {
1428 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1429 return format;
1430 }
1431 case VERTEX_FORMAT_USHORT4_INT:
1432 {
1433 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1434 return format;
1435 }
1436 case VERTEX_FORMAT_SINT1_INT:
1437 {
1438 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1439 return format;
1440 }
1441 case VERTEX_FORMAT_SINT2_INT:
1442 {
1443 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1444 return format;
1445 }
1446 case VERTEX_FORMAT_SINT3_INT:
1447 {
1448 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1449 return format;
1450 }
1451 case VERTEX_FORMAT_SINT4_INT:
1452 {
1453 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1454 return format;
1455 }
1456 case VERTEX_FORMAT_UINT1_INT:
1457 {
1458 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1459 return format;
1460 }
1461 case VERTEX_FORMAT_UINT2_INT:
1462 {
1463 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1464 return format;
1465 }
1466 case VERTEX_FORMAT_UINT3_INT:
1467 {
1468 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1469 return format;
1470 }
1471 case VERTEX_FORMAT_UINT4_INT:
1472 {
1473 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1474 return format;
1475 }
1476 case VERTEX_FORMAT_FIXED1:
1477 {
1478 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1479 return format;
1480 }
1481 case VERTEX_FORMAT_FIXED2:
1482 {
1483 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1484 return format;
1485 }
1486 case VERTEX_FORMAT_FIXED3:
1487 {
1488 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1489 return format;
1490 }
1491 case VERTEX_FORMAT_FIXED4:
1492 {
1493 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1494 return format;
1495 }
1496 case VERTEX_FORMAT_HALF1:
1497 {
1498 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1499 return format;
1500 }
1501 case VERTEX_FORMAT_HALF2:
1502 {
1503 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1504 return format;
1505 }
1506 case VERTEX_FORMAT_HALF3:
1507 {
1508 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1509 return format;
1510 }
1511 case VERTEX_FORMAT_HALF4:
1512 {
1513 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1514 return format;
1515 }
1516 case VERTEX_FORMAT_FLOAT1:
1517 {
1518 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1519 return format;
1520 }
1521 case VERTEX_FORMAT_FLOAT2:
1522 {
1523 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1524 return format;
1525 }
1526 case VERTEX_FORMAT_FLOAT3:
1527 {
1528 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1529 return format;
1530 }
1531 case VERTEX_FORMAT_FLOAT4:
1532 {
1533 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1534 return format;
1535 }
1536 case VERTEX_FORMAT_SINT210:
1537 {
1538 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1539 return format;
1540 }
1541 case VERTEX_FORMAT_UINT210:
1542 {
1543 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1544 return format;
1545 }
1546 case VERTEX_FORMAT_SINT210_NORM:
1547 {
1548 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1549 return format;
1550 }
1551 case VERTEX_FORMAT_UINT210_NORM:
1552 {
1553 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1554 return format;
1555 }
1556 case VERTEX_FORMAT_SINT210_INT:
1557 {
1558 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1559 return format;
1560 }
1561 case VERTEX_FORMAT_UINT210_INT:
1562 {
1563 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1564 return format;
1565 }
1566 default:
1567 {
1568 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1569 return format;
1570 }
1571 }
1572}
1573
1574VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1575 : type(typeIn),
1576 normalized(normalizedIn),
1577 components(componentsIn),
1578 pureInteger(pureIntegerIn)
1579{
1580 // float -> !normalized
1581 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1582}
1583
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001584}