blob: a26c7aa79ef8e54687a834d920c016bb70c19060 [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{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700687 // Compressed images do not use pack/unpack parameters.
688 if (compressed)
689 {
690 ASSERT(rowLength == 0);
691 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
692 }
693
694 CheckedNumeric<GLuint> checkedRowBytes(0);
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800695 if (rowLength > 0)
696 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700697 CheckedNumeric<GLuint> checkePixelBytes(pixelBytes);
698 checkedRowBytes = checkePixelBytes * rowLength;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800699 }
700 else
701 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700702 CheckedNumeric<GLuint> checkedWidth(width);
703 const auto &typeInfo = GetTypeInfo(formatType);
704 CheckedNumeric<GLuint> checkedComponents(typeInfo.specialInterpretation ? 1u
705 : componentCount);
706 CheckedNumeric<GLuint> checkedTypeBytes(typeInfo.bytes);
707 checkedRowBytes = checkedWidth * checkedComponents * checkedTypeBytes;
Minmin Gongb8aee3b2015-01-27 14:42:36 -0800708 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700709
710 ASSERT(alignment > 0 && isPow2(alignment));
711 CheckedNumeric<GLuint> checkedAlignment(alignment);
712 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
713 ANGLE_TRY_CHECKED_MATH(aligned);
714 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000715}
716
Jamie Madille2e406c2016-06-02 13:04:10 -0400717gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
718 GLsizei width,
719 GLsizei height,
720 GLint alignment,
721 GLint rowLength,
722 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000723{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700724 GLuint rows =
725 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400726 GLuint rowPitch = 0;
727 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
728
729 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
730 auto depthPitch = checkedRowPitch * rows;
731 ANGLE_TRY_CHECKED_MATH(depthPitch);
732 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000733}
734
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700735gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
736 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737{
Jamie Madill513558d2016-06-02 13:04:11 -0400738 CheckedNumeric<GLuint> checkedWidth(size.width);
739 CheckedNumeric<GLuint> checkedHeight(size.height);
740 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700741 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
742 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400743
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700744 ASSERT(compressed);
745 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
746 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
747 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
748 ANGLE_TRY_CHECKED_MATH(bytes);
749 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000750}
751
Minmin Gongadff67b2015-10-14 10:34:45 -0400752GLuint InternalFormat::computeSkipPixels(GLint rowPitch,
753 GLint depthPitch,
754 GLint skipImages,
755 GLint skipRows,
756 GLint skipPixels) const
757{
758 return skipImages * depthPitch + skipRows * rowPitch + skipPixels * pixelBytes;
759}
760
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700761gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
762 GLenum formatType,
763 const gl::Extents &size,
764 const gl::PixelUnpackState &unpack) const
765{
766 // Compressed images do not use unpack parameters.
767 if (compressed)
768 {
769 return computeCompressedImageSize(formatType, size);
770 }
771
772 base::CheckedNumeric<GLuint> checkedGroups(unpack.rowLength > 0 ? unpack.rowLength
773 : size.width);
774 base::CheckedNumeric<GLuint> checkedRows(unpack.imageHeight > 0 ? unpack.imageHeight
775 : size.height);
776
777 // Compute the groups of all the layers in (0,depth-1)
778 auto layerGroups = checkedGroups * checkedRows * (size.depth - 1);
779
780 // Compute the groups in the last layer (for non-3D textures, the only one)
781 auto lastLayerGroups = checkedGroups * (size.height - 1) + size.width;
782
783 // The total size is the sum times the bytes per pixel.
784 auto totalSize = (layerGroups + lastLayerGroups) * pixelBytes;
785
786 ANGLE_TRY_CHECKED_MATH(totalSize);
787
788 return totalSize.ValueOrDie();
789}
790
Geoff Lang5d601382014-07-22 15:14:06 -0400791GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000792{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700793 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500794 if (formatInfo.pixelBytes > 0)
795 {
796 return internalFormat;
797 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700798
799 static const FormatMap formatMap = BuildFormatMap();
800 auto iter = formatMap.find(FormatTypePair(internalFormat, type));
801 if (iter != formatMap.end())
Geoff Lang051dbc72015-01-05 15:48:58 -0500802 {
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700803 return iter->second;
Geoff Lang051dbc72015-01-05 15:48:58 -0500804 }
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700805
806 return GL_NONE;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000807}
808
Geoff Lange4a492b2014-06-19 14:14:41 -0400809const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400810{
Geoff Lange4a492b2014-06-19 14:14:41 -0400811 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400812 return formatSet;
813}
814
Jamie Madill09e2d932015-07-14 16:40:31 -0400815AttributeType GetAttributeType(GLenum enumValue)
816{
817 switch (enumValue)
818 {
819 case GL_FLOAT:
820 return ATTRIBUTE_FLOAT;
821 case GL_FLOAT_VEC2:
822 return ATTRIBUTE_VEC2;
823 case GL_FLOAT_VEC3:
824 return ATTRIBUTE_VEC3;
825 case GL_FLOAT_VEC4:
826 return ATTRIBUTE_VEC4;
827 case GL_INT:
828 return ATTRIBUTE_INT;
829 case GL_INT_VEC2:
830 return ATTRIBUTE_IVEC2;
831 case GL_INT_VEC3:
832 return ATTRIBUTE_IVEC3;
833 case GL_INT_VEC4:
834 return ATTRIBUTE_IVEC4;
835 case GL_UNSIGNED_INT:
836 return ATTRIBUTE_UINT;
837 case GL_UNSIGNED_INT_VEC2:
838 return ATTRIBUTE_UVEC2;
839 case GL_UNSIGNED_INT_VEC3:
840 return ATTRIBUTE_UVEC3;
841 case GL_UNSIGNED_INT_VEC4:
842 return ATTRIBUTE_UVEC4;
843 case GL_FLOAT_MAT2:
844 return ATTRIBUTE_MAT2;
845 case GL_FLOAT_MAT3:
846 return ATTRIBUTE_MAT3;
847 case GL_FLOAT_MAT4:
848 return ATTRIBUTE_MAT4;
849 case GL_FLOAT_MAT2x3:
850 return ATTRIBUTE_MAT2x3;
851 case GL_FLOAT_MAT2x4:
852 return ATTRIBUTE_MAT2x4;
853 case GL_FLOAT_MAT3x2:
854 return ATTRIBUTE_MAT3x2;
855 case GL_FLOAT_MAT3x4:
856 return ATTRIBUTE_MAT3x4;
857 case GL_FLOAT_MAT4x2:
858 return ATTRIBUTE_MAT4x2;
859 case GL_FLOAT_MAT4x3:
860 return ATTRIBUTE_MAT4x3;
861 default:
862 UNREACHABLE();
863 return ATTRIBUTE_FLOAT;
864 }
865}
866
Jamie Madilld3dfda22015-07-06 08:28:49 -0400867VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
868{
869 switch (type)
870 {
871 case GL_BYTE:
872 switch (components)
873 {
874 case 1:
875 if (pureInteger)
876 return VERTEX_FORMAT_SBYTE1_INT;
877 if (normalized)
878 return VERTEX_FORMAT_SBYTE1_NORM;
879 return VERTEX_FORMAT_SBYTE1;
880 case 2:
881 if (pureInteger)
882 return VERTEX_FORMAT_SBYTE2_INT;
883 if (normalized)
884 return VERTEX_FORMAT_SBYTE2_NORM;
885 return VERTEX_FORMAT_SBYTE2;
886 case 3:
887 if (pureInteger)
888 return VERTEX_FORMAT_SBYTE3_INT;
889 if (normalized)
890 return VERTEX_FORMAT_SBYTE3_NORM;
891 return VERTEX_FORMAT_SBYTE3;
892 case 4:
893 if (pureInteger)
894 return VERTEX_FORMAT_SBYTE4_INT;
895 if (normalized)
896 return VERTEX_FORMAT_SBYTE4_NORM;
897 return VERTEX_FORMAT_SBYTE4;
898 default:
899 UNREACHABLE();
900 break;
901 }
902 case GL_UNSIGNED_BYTE:
903 switch (components)
904 {
905 case 1:
906 if (pureInteger)
907 return VERTEX_FORMAT_UBYTE1_INT;
908 if (normalized)
909 return VERTEX_FORMAT_UBYTE1_NORM;
910 return VERTEX_FORMAT_UBYTE1;
911 case 2:
912 if (pureInteger)
913 return VERTEX_FORMAT_UBYTE2_INT;
914 if (normalized)
915 return VERTEX_FORMAT_UBYTE2_NORM;
916 return VERTEX_FORMAT_UBYTE2;
917 case 3:
918 if (pureInteger)
919 return VERTEX_FORMAT_UBYTE3_INT;
920 if (normalized)
921 return VERTEX_FORMAT_UBYTE3_NORM;
922 return VERTEX_FORMAT_UBYTE3;
923 case 4:
924 if (pureInteger)
925 return VERTEX_FORMAT_UBYTE4_INT;
926 if (normalized)
927 return VERTEX_FORMAT_UBYTE4_NORM;
928 return VERTEX_FORMAT_UBYTE4;
929 default:
930 UNREACHABLE();
931 break;
932 }
933 case GL_SHORT:
934 switch (components)
935 {
936 case 1:
937 if (pureInteger)
938 return VERTEX_FORMAT_SSHORT1_INT;
939 if (normalized)
940 return VERTEX_FORMAT_SSHORT1_NORM;
941 return VERTEX_FORMAT_SSHORT1;
942 case 2:
943 if (pureInteger)
944 return VERTEX_FORMAT_SSHORT2_INT;
945 if (normalized)
946 return VERTEX_FORMAT_SSHORT2_NORM;
947 return VERTEX_FORMAT_SSHORT2;
948 case 3:
949 if (pureInteger)
950 return VERTEX_FORMAT_SSHORT3_INT;
951 if (normalized)
952 return VERTEX_FORMAT_SSHORT3_NORM;
953 return VERTEX_FORMAT_SSHORT3;
954 case 4:
955 if (pureInteger)
956 return VERTEX_FORMAT_SSHORT4_INT;
957 if (normalized)
958 return VERTEX_FORMAT_SSHORT4_NORM;
959 return VERTEX_FORMAT_SSHORT4;
960 default:
961 UNREACHABLE();
962 break;
963 }
964 case GL_UNSIGNED_SHORT:
965 switch (components)
966 {
967 case 1:
968 if (pureInteger)
969 return VERTEX_FORMAT_USHORT1_INT;
970 if (normalized)
971 return VERTEX_FORMAT_USHORT1_NORM;
972 return VERTEX_FORMAT_USHORT1;
973 case 2:
974 if (pureInteger)
975 return VERTEX_FORMAT_USHORT2_INT;
976 if (normalized)
977 return VERTEX_FORMAT_USHORT2_NORM;
978 return VERTEX_FORMAT_USHORT2;
979 case 3:
980 if (pureInteger)
981 return VERTEX_FORMAT_USHORT3_INT;
982 if (normalized)
983 return VERTEX_FORMAT_USHORT3_NORM;
984 return VERTEX_FORMAT_USHORT3;
985 case 4:
986 if (pureInteger)
987 return VERTEX_FORMAT_USHORT4_INT;
988 if (normalized)
989 return VERTEX_FORMAT_USHORT4_NORM;
990 return VERTEX_FORMAT_USHORT4;
991 default:
992 UNREACHABLE();
993 break;
994 }
995 case GL_INT:
996 switch (components)
997 {
998 case 1:
999 if (pureInteger)
1000 return VERTEX_FORMAT_SINT1_INT;
1001 if (normalized)
1002 return VERTEX_FORMAT_SINT1_NORM;
1003 return VERTEX_FORMAT_SINT1;
1004 case 2:
1005 if (pureInteger)
1006 return VERTEX_FORMAT_SINT2_INT;
1007 if (normalized)
1008 return VERTEX_FORMAT_SINT2_NORM;
1009 return VERTEX_FORMAT_SINT2;
1010 case 3:
1011 if (pureInteger)
1012 return VERTEX_FORMAT_SINT3_INT;
1013 if (normalized)
1014 return VERTEX_FORMAT_SINT3_NORM;
1015 return VERTEX_FORMAT_SINT3;
1016 case 4:
1017 if (pureInteger)
1018 return VERTEX_FORMAT_SINT4_INT;
1019 if (normalized)
1020 return VERTEX_FORMAT_SINT4_NORM;
1021 return VERTEX_FORMAT_SINT4;
1022 default:
1023 UNREACHABLE();
1024 break;
1025 }
1026 case GL_UNSIGNED_INT:
1027 switch (components)
1028 {
1029 case 1:
1030 if (pureInteger)
1031 return VERTEX_FORMAT_UINT1_INT;
1032 if (normalized)
1033 return VERTEX_FORMAT_UINT1_NORM;
1034 return VERTEX_FORMAT_UINT1;
1035 case 2:
1036 if (pureInteger)
1037 return VERTEX_FORMAT_UINT2_INT;
1038 if (normalized)
1039 return VERTEX_FORMAT_UINT2_NORM;
1040 return VERTEX_FORMAT_UINT2;
1041 case 3:
1042 if (pureInteger)
1043 return VERTEX_FORMAT_UINT3_INT;
1044 if (normalized)
1045 return VERTEX_FORMAT_UINT3_NORM;
1046 return VERTEX_FORMAT_UINT3;
1047 case 4:
1048 if (pureInteger)
1049 return VERTEX_FORMAT_UINT4_INT;
1050 if (normalized)
1051 return VERTEX_FORMAT_UINT4_NORM;
1052 return VERTEX_FORMAT_UINT4;
1053 default:
1054 UNREACHABLE();
1055 break;
1056 }
1057 case GL_FLOAT:
1058 switch (components)
1059 {
1060 case 1:
1061 return VERTEX_FORMAT_FLOAT1;
1062 case 2:
1063 return VERTEX_FORMAT_FLOAT2;
1064 case 3:
1065 return VERTEX_FORMAT_FLOAT3;
1066 case 4:
1067 return VERTEX_FORMAT_FLOAT4;
1068 default:
1069 UNREACHABLE();
1070 break;
1071 }
1072 case GL_HALF_FLOAT:
1073 switch (components)
1074 {
1075 case 1:
1076 return VERTEX_FORMAT_HALF1;
1077 case 2:
1078 return VERTEX_FORMAT_HALF2;
1079 case 3:
1080 return VERTEX_FORMAT_HALF3;
1081 case 4:
1082 return VERTEX_FORMAT_HALF4;
1083 default:
1084 UNREACHABLE();
1085 break;
1086 }
1087 case GL_FIXED:
1088 switch (components)
1089 {
1090 case 1:
1091 return VERTEX_FORMAT_FIXED1;
1092 case 2:
1093 return VERTEX_FORMAT_FIXED2;
1094 case 3:
1095 return VERTEX_FORMAT_FIXED3;
1096 case 4:
1097 return VERTEX_FORMAT_FIXED4;
1098 default:
1099 UNREACHABLE();
1100 break;
1101 }
1102 case GL_INT_2_10_10_10_REV:
1103 if (pureInteger)
1104 return VERTEX_FORMAT_SINT210_INT;
1105 if (normalized)
1106 return VERTEX_FORMAT_SINT210_NORM;
1107 return VERTEX_FORMAT_SINT210;
1108 case GL_UNSIGNED_INT_2_10_10_10_REV:
1109 if (pureInteger)
1110 return VERTEX_FORMAT_UINT210_INT;
1111 if (normalized)
1112 return VERTEX_FORMAT_UINT210_NORM;
1113 return VERTEX_FORMAT_UINT210;
1114 default:
1115 UNREACHABLE();
1116 break;
1117 }
1118 return VERTEX_FORMAT_UBYTE1;
1119}
1120
1121VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1122{
1123 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1124}
1125
1126VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1127{
1128 if (!attrib.enabled)
1129 {
1130 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1131 }
1132 return GetVertexFormatType(attrib);
1133}
1134
1135const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1136{
1137 switch (vertexFormatType)
1138 {
1139 case VERTEX_FORMAT_SBYTE1:
1140 {
1141 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1142 return format;
1143 }
1144 case VERTEX_FORMAT_SBYTE1_NORM:
1145 {
1146 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1147 return format;
1148 }
1149 case VERTEX_FORMAT_SBYTE2:
1150 {
1151 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1152 return format;
1153 }
1154 case VERTEX_FORMAT_SBYTE2_NORM:
1155 {
1156 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1157 return format;
1158 }
1159 case VERTEX_FORMAT_SBYTE3:
1160 {
1161 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1162 return format;
1163 }
1164 case VERTEX_FORMAT_SBYTE3_NORM:
1165 {
1166 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1167 return format;
1168 }
1169 case VERTEX_FORMAT_SBYTE4:
1170 {
1171 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1172 return format;
1173 }
1174 case VERTEX_FORMAT_SBYTE4_NORM:
1175 {
1176 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1177 return format;
1178 }
1179 case VERTEX_FORMAT_UBYTE1:
1180 {
1181 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1182 return format;
1183 }
1184 case VERTEX_FORMAT_UBYTE1_NORM:
1185 {
1186 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1187 return format;
1188 }
1189 case VERTEX_FORMAT_UBYTE2:
1190 {
1191 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1192 return format;
1193 }
1194 case VERTEX_FORMAT_UBYTE2_NORM:
1195 {
1196 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1197 return format;
1198 }
1199 case VERTEX_FORMAT_UBYTE3:
1200 {
1201 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1202 return format;
1203 }
1204 case VERTEX_FORMAT_UBYTE3_NORM:
1205 {
1206 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1207 return format;
1208 }
1209 case VERTEX_FORMAT_UBYTE4:
1210 {
1211 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1212 return format;
1213 }
1214 case VERTEX_FORMAT_UBYTE4_NORM:
1215 {
1216 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1217 return format;
1218 }
1219 case VERTEX_FORMAT_SSHORT1:
1220 {
1221 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1222 return format;
1223 }
1224 case VERTEX_FORMAT_SSHORT1_NORM:
1225 {
1226 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1227 return format;
1228 }
1229 case VERTEX_FORMAT_SSHORT2:
1230 {
1231 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1232 return format;
1233 }
1234 case VERTEX_FORMAT_SSHORT2_NORM:
1235 {
1236 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1237 return format;
1238 }
1239 case VERTEX_FORMAT_SSHORT3:
1240 {
1241 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1242 return format;
1243 }
1244 case VERTEX_FORMAT_SSHORT3_NORM:
1245 {
1246 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1247 return format;
1248 }
1249 case VERTEX_FORMAT_SSHORT4:
1250 {
1251 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1252 return format;
1253 }
1254 case VERTEX_FORMAT_SSHORT4_NORM:
1255 {
1256 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1257 return format;
1258 }
1259 case VERTEX_FORMAT_USHORT1:
1260 {
1261 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1262 return format;
1263 }
1264 case VERTEX_FORMAT_USHORT1_NORM:
1265 {
1266 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1267 return format;
1268 }
1269 case VERTEX_FORMAT_USHORT2:
1270 {
1271 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1272 return format;
1273 }
1274 case VERTEX_FORMAT_USHORT2_NORM:
1275 {
1276 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1277 return format;
1278 }
1279 case VERTEX_FORMAT_USHORT3:
1280 {
1281 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1282 return format;
1283 }
1284 case VERTEX_FORMAT_USHORT3_NORM:
1285 {
1286 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1287 return format;
1288 }
1289 case VERTEX_FORMAT_USHORT4:
1290 {
1291 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1292 return format;
1293 }
1294 case VERTEX_FORMAT_USHORT4_NORM:
1295 {
1296 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1297 return format;
1298 }
1299 case VERTEX_FORMAT_SINT1:
1300 {
1301 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1302 return format;
1303 }
1304 case VERTEX_FORMAT_SINT1_NORM:
1305 {
1306 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1307 return format;
1308 }
1309 case VERTEX_FORMAT_SINT2:
1310 {
1311 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1312 return format;
1313 }
1314 case VERTEX_FORMAT_SINT2_NORM:
1315 {
1316 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1317 return format;
1318 }
1319 case VERTEX_FORMAT_SINT3:
1320 {
1321 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1322 return format;
1323 }
1324 case VERTEX_FORMAT_SINT3_NORM:
1325 {
1326 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1327 return format;
1328 }
1329 case VERTEX_FORMAT_SINT4:
1330 {
1331 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1332 return format;
1333 }
1334 case VERTEX_FORMAT_SINT4_NORM:
1335 {
1336 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1337 return format;
1338 }
1339 case VERTEX_FORMAT_UINT1:
1340 {
1341 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1342 return format;
1343 }
1344 case VERTEX_FORMAT_UINT1_NORM:
1345 {
1346 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1347 return format;
1348 }
1349 case VERTEX_FORMAT_UINT2:
1350 {
1351 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1352 return format;
1353 }
1354 case VERTEX_FORMAT_UINT2_NORM:
1355 {
1356 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1357 return format;
1358 }
1359 case VERTEX_FORMAT_UINT3:
1360 {
1361 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1362 return format;
1363 }
1364 case VERTEX_FORMAT_UINT3_NORM:
1365 {
1366 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1367 return format;
1368 }
1369 case VERTEX_FORMAT_UINT4:
1370 {
1371 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1372 return format;
1373 }
1374 case VERTEX_FORMAT_UINT4_NORM:
1375 {
1376 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1377 return format;
1378 }
1379 case VERTEX_FORMAT_SBYTE1_INT:
1380 {
1381 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1382 return format;
1383 }
1384 case VERTEX_FORMAT_SBYTE2_INT:
1385 {
1386 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1387 return format;
1388 }
1389 case VERTEX_FORMAT_SBYTE3_INT:
1390 {
1391 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1392 return format;
1393 }
1394 case VERTEX_FORMAT_SBYTE4_INT:
1395 {
1396 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1397 return format;
1398 }
1399 case VERTEX_FORMAT_UBYTE1_INT:
1400 {
1401 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1402 return format;
1403 }
1404 case VERTEX_FORMAT_UBYTE2_INT:
1405 {
1406 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1407 return format;
1408 }
1409 case VERTEX_FORMAT_UBYTE3_INT:
1410 {
1411 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1412 return format;
1413 }
1414 case VERTEX_FORMAT_UBYTE4_INT:
1415 {
1416 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1417 return format;
1418 }
1419 case VERTEX_FORMAT_SSHORT1_INT:
1420 {
1421 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1422 return format;
1423 }
1424 case VERTEX_FORMAT_SSHORT2_INT:
1425 {
1426 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1427 return format;
1428 }
1429 case VERTEX_FORMAT_SSHORT3_INT:
1430 {
1431 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1432 return format;
1433 }
1434 case VERTEX_FORMAT_SSHORT4_INT:
1435 {
1436 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1437 return format;
1438 }
1439 case VERTEX_FORMAT_USHORT1_INT:
1440 {
1441 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1442 return format;
1443 }
1444 case VERTEX_FORMAT_USHORT2_INT:
1445 {
1446 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1447 return format;
1448 }
1449 case VERTEX_FORMAT_USHORT3_INT:
1450 {
1451 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1452 return format;
1453 }
1454 case VERTEX_FORMAT_USHORT4_INT:
1455 {
1456 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1457 return format;
1458 }
1459 case VERTEX_FORMAT_SINT1_INT:
1460 {
1461 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1462 return format;
1463 }
1464 case VERTEX_FORMAT_SINT2_INT:
1465 {
1466 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1467 return format;
1468 }
1469 case VERTEX_FORMAT_SINT3_INT:
1470 {
1471 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1472 return format;
1473 }
1474 case VERTEX_FORMAT_SINT4_INT:
1475 {
1476 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1477 return format;
1478 }
1479 case VERTEX_FORMAT_UINT1_INT:
1480 {
1481 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1482 return format;
1483 }
1484 case VERTEX_FORMAT_UINT2_INT:
1485 {
1486 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1487 return format;
1488 }
1489 case VERTEX_FORMAT_UINT3_INT:
1490 {
1491 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1492 return format;
1493 }
1494 case VERTEX_FORMAT_UINT4_INT:
1495 {
1496 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1497 return format;
1498 }
1499 case VERTEX_FORMAT_FIXED1:
1500 {
1501 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1502 return format;
1503 }
1504 case VERTEX_FORMAT_FIXED2:
1505 {
1506 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1507 return format;
1508 }
1509 case VERTEX_FORMAT_FIXED3:
1510 {
1511 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1512 return format;
1513 }
1514 case VERTEX_FORMAT_FIXED4:
1515 {
1516 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1517 return format;
1518 }
1519 case VERTEX_FORMAT_HALF1:
1520 {
1521 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1522 return format;
1523 }
1524 case VERTEX_FORMAT_HALF2:
1525 {
1526 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1527 return format;
1528 }
1529 case VERTEX_FORMAT_HALF3:
1530 {
1531 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1532 return format;
1533 }
1534 case VERTEX_FORMAT_HALF4:
1535 {
1536 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1537 return format;
1538 }
1539 case VERTEX_FORMAT_FLOAT1:
1540 {
1541 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1542 return format;
1543 }
1544 case VERTEX_FORMAT_FLOAT2:
1545 {
1546 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1547 return format;
1548 }
1549 case VERTEX_FORMAT_FLOAT3:
1550 {
1551 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1552 return format;
1553 }
1554 case VERTEX_FORMAT_FLOAT4:
1555 {
1556 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1557 return format;
1558 }
1559 case VERTEX_FORMAT_SINT210:
1560 {
1561 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1562 return format;
1563 }
1564 case VERTEX_FORMAT_UINT210:
1565 {
1566 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1567 return format;
1568 }
1569 case VERTEX_FORMAT_SINT210_NORM:
1570 {
1571 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1572 return format;
1573 }
1574 case VERTEX_FORMAT_UINT210_NORM:
1575 {
1576 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1577 return format;
1578 }
1579 case VERTEX_FORMAT_SINT210_INT:
1580 {
1581 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1582 return format;
1583 }
1584 case VERTEX_FORMAT_UINT210_INT:
1585 {
1586 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1587 return format;
1588 }
1589 default:
1590 {
1591 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1592 return format;
1593 }
1594 }
1595}
1596
1597VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1598 : type(typeIn),
1599 normalized(normalizedIn),
1600 components(componentsIn),
1601 pureInteger(pureIntegerIn)
1602{
1603 // float -> !normalized
1604 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1605}
1606
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001607}