blob: 4222d726c38bddb70aa33cb82d0bb4da5d137f67 [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
Jamie Madilla3944d42016-07-22 22:13:26 -040019namespace
20{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000021// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
22// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
23// format and type combinations.
24
Jamie Madilld2b50a02016-06-09 00:13:35 -070025typedef std::pair<FormatType, GLenum> FormatPair;
26typedef std::map<FormatType, GLenum> FormatMap;
27
Jamie Madill89a0bf52013-09-18 14:36:24 -040028// A helper function to insert data into the format map with fewer characters.
Jamie Madilla3944d42016-07-22 22:13:26 -040029void InsertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000030{
Jamie Madilld2b50a02016-06-09 00:13:35 -070031 map->insert(FormatPair(FormatType(format, type), internalFormat));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000032}
33
Geoff Lange4a492b2014-06-19 14:14:41 -040034FormatMap BuildFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000035{
36 FormatMap map;
37
Jamie Madill1e8dcb52016-07-22 12:01:41 -040038 // clang-format off
Geoff Lang051dbc72015-01-05 15:48:58 -050039 // | Format | Type | Internal format |
40 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8);
41 InsertFormatMapping(&map, GL_RGBA, GL_BYTE, GL_RGBA8_SNORM);
42 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4);
43 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1);
44 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2);
45 InsertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F);
46 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F);
47 InsertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000048
Geoff Lang051dbc72015-01-05 15:48:58 -050049 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_RGBA8UI);
50 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_BYTE, GL_RGBA8I);
51 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_RGBA16UI);
52 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_SHORT, GL_RGBA16I);
53 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_RGBA32UI);
54 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_INT, GL_RGBA32I);
55 InsertFormatMapping(&map, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_RGB10_A2UI);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000056
Geoff Lang051dbc72015-01-05 15:48:58 -050057 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8);
58 InsertFormatMapping(&map, GL_RGB, GL_BYTE, GL_RGB8_SNORM);
59 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565);
60 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_R11F_G11F_B10F);
61 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_RGB9_E5);
62 InsertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F);
63 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F);
64 InsertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000065
Geoff Lang051dbc72015-01-05 15:48:58 -050066 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_RGB8UI);
67 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_BYTE, GL_RGB8I);
68 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_RGB16UI);
69 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_SHORT, GL_RGB16I);
70 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_RGB32UI);
71 InsertFormatMapping(&map, GL_RGB_INTEGER, GL_INT, GL_RGB32I);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000072
Geoff Lang051dbc72015-01-05 15:48:58 -050073 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_BYTE, GL_RG8);
74 InsertFormatMapping(&map, GL_RG, GL_BYTE, GL_RG8_SNORM);
75 InsertFormatMapping(&map, GL_RG, GL_FLOAT, GL_RG32F);
76 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT, GL_RG16F);
77 InsertFormatMapping(&map, GL_RG, GL_HALF_FLOAT_OES, GL_RG16F);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000078
Geoff Lang051dbc72015-01-05 15:48:58 -050079 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_RG8UI);
80 InsertFormatMapping(&map, GL_RG_INTEGER, GL_BYTE, GL_RG8I);
81 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_RG16UI);
82 InsertFormatMapping(&map, GL_RG_INTEGER, GL_SHORT, GL_RG16I);
83 InsertFormatMapping(&map, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_RG32UI);
84 InsertFormatMapping(&map, GL_RG_INTEGER, GL_INT, GL_RG32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040085
Geoff Lang051dbc72015-01-05 15:48:58 -050086 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_BYTE, GL_R8);
87 InsertFormatMapping(&map, GL_RED, GL_BYTE, GL_R8_SNORM);
88 InsertFormatMapping(&map, GL_RED, GL_FLOAT, GL_R32F);
89 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT, GL_R16F);
90 InsertFormatMapping(&map, GL_RED, GL_HALF_FLOAT_OES, GL_R16F);
Geoff Langfe28ca02013-06-04 10:10:48 -040091
Geoff Lang051dbc72015-01-05 15:48:58 -050092 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_R8UI);
93 InsertFormatMapping(&map, GL_RED_INTEGER, GL_BYTE, GL_R8I);
94 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_R16UI);
95 InsertFormatMapping(&map, GL_RED_INTEGER, GL_SHORT, GL_R16I);
96 InsertFormatMapping(&map, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_R32UI);
97 InsertFormatMapping(&map, GL_RED_INTEGER, GL_INT, GL_R32I);
Geoff Langfe28ca02013-06-04 10:10:48 -040098
Geoff Lang051dbc72015-01-05 15:48:58 -050099 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT);
100 InsertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT);
101 InsertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT);
102 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT);
103 InsertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT);
104 InsertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT);
105 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT);
106 InsertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT);
107 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT);
108 InsertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT);
109 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT);
110 InsertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT);
Geoff Langfe28ca02013-06-04 10:10:48 -0400111
Geoff Lang051dbc72015-01-05 15:48:58 -0500112 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT);
113 InsertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX);
114 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 -0400115
Geoff Lang051dbc72015-01-05 15:48:58 -0500116 InsertFormatMapping(&map, GL_SRGB_EXT, GL_UNSIGNED_BYTE, GL_SRGB8);
117 InsertFormatMapping(&map, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE, GL_SRGB8_ALPHA8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400118
Geoff Lang051dbc72015-01-05 15:48:58 -0500119 InsertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT);
120 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT);
121 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE);
122 InsertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE);
Geoff Lang05b05022014-06-11 15:31:45 -0400123
Geoff Lang051dbc72015-01-05 15:48:58 -0500124 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16);
125 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES);
126 InsertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F);
Geoff Langcec35902014-04-16 10:52:36 -0400127
Geoff Lang051dbc72015-01-05 15:48:58 -0500128 InsertFormatMapping(&map, GL_STENCIL, GL_UNSIGNED_BYTE, GL_STENCIL_INDEX8);
Geoff Langfe28ca02013-06-04 10:10:48 -0400129
Geoff Lang051dbc72015-01-05 15:48:58 -0500130 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8);
131 InsertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000132
Jamie Madill1e8dcb52016-07-22 12:01:41 -0400133 // From GL_EXT_texture_norm16
134 InsertFormatMapping(&map, GL_RED, GL_UNSIGNED_SHORT, GL_R16_EXT);
135 InsertFormatMapping(&map, GL_RED, GL_SHORT, GL_R16_SNORM_EXT);
136 InsertFormatMapping(&map, GL_RG, GL_UNSIGNED_SHORT, GL_RG16_EXT);
137 InsertFormatMapping(&map, GL_RG, GL_SHORT, GL_RG16_SNORM_EXT);
138 InsertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT, GL_RGB16_EXT);
139 InsertFormatMapping(&map, GL_RGB, GL_SHORT, GL_RGB16_SNORM_EXT);
140 InsertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT, GL_RGBA16_EXT);
141 InsertFormatMapping(&map, GL_RGBA, GL_SHORT, GL_RGBA16_SNORM_EXT);
142 // clang-format on
143
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000144 return map;
145}
146
Jamie Madilla3944d42016-07-22 22:13:26 -0400147GLenum GetSizedFormatInternal(GLenum format, GLenum type)
148{
149 static const FormatMap formatMap = BuildFormatMap();
150 auto iter = formatMap.find(FormatType(format, type));
151 if (iter != formatMap.end())
152 {
153 return iter->second;
154 }
155
156 // TODO(jmadill): Fix this hack.
157 if (format == GL_BGRA_EXT && type == GL_UNSIGNED_SHORT_5_6_5)
158 return GL_BGR565_ANGLEX;
159
160 if (format == GL_NONE)
161 return GL_NONE;
162
163 UNREACHABLE();
164 return GL_NONE;
165}
166
167typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair;
168typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap;
169
170} // anonymous namespace
171
172FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
173{
174}
175
176FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
177{
178}
179
180bool FormatType::operator<(const FormatType &other) const
181{
182 if (format != other.format)
183 return format < other.format;
184 return type < other.type;
185}
186
Geoff Lang5d601382014-07-22 15:14:06 -0400187Type::Type()
188 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200189 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400190 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -0400191{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000192}
193
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200194static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000195{
Geoff Lang5d601382014-07-22 15:14:06 -0400196 Type info;
197 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +0200198 GLuint i = 0;
199 while ((1u << i) < bytes)
200 {
201 ++i;
202 }
203 info.bytesShift = i;
204 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -0400205 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200206 return info;
Geoff Lang5d601382014-07-22 15:14:06 -0400207}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000208
Geoff Lang5d601382014-07-22 15:14:06 -0400209bool operator<(const Type& a, const Type& b)
210{
211 return memcmp(&a, &b, sizeof(Type)) < 0;
212}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000213
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000214// Information about internal formats
Geoff Lang493daf52014-07-03 13:38:44 -0400215static bool AlwaysSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000216{
Geoff Lang493daf52014-07-03 13:38:44 -0400217 return true;
218}
219
Geoff Lang493daf52014-07-03 13:38:44 -0400220static bool NeverSupported(GLuint, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000221{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000222 return false;
223}
224
Geoff Lange4a492b2014-06-19 14:14:41 -0400225template <GLuint minCoreGLVersion>
Geoff Langabce7622014-09-19 16:13:00 -0400226static bool RequireES(GLuint clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -0400227{
228 return clientVersion >= minCoreGLVersion;
229}
230
Geoff Langcec35902014-04-16 10:52:36 -0400231// Pointer to a boolean memeber of the Extensions struct
232typedef bool(Extensions::*ExtensionBool);
233
234// Check support for a single extension
235template <ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400236static bool RequireExt(GLuint, const Extensions & extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400237{
Geoff Lange4a492b2014-06-19 14:14:41 -0400238 return extensions.*bool1;
239}
240
241// Check for a minimum client version or a single extension
242template <GLuint minCoreGLVersion, ExtensionBool bool1>
Geoff Langabce7622014-09-19 16:13:00 -0400243static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400244{
245 return clientVersion >= minCoreGLVersion || extensions.*bool1;
246}
247
248// Check for a minimum client version or two extensions
249template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400250static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400251{
Geoff Langabce7622014-09-19 16:13:00 -0400252 return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2);
253}
254
255// Check for a minimum client version or at least one of two extensions
256template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2>
257static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions)
258{
259 return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400260}
261
262// Check support for two extensions
263template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langabce7622014-09-19 16:13:00 -0400264static bool RequireExtAndExt(GLuint, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400265{
Geoff Langabce7622014-09-19 16:13:00 -0400266 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400267}
268
Geoff Lang60ad73d2015-10-23 10:08:44 -0400269// Check support for either of two extensions
270template <ExtensionBool bool1, ExtensionBool bool2>
271static bool RequireExtOrExt(GLuint, const Extensions &extensions)
272{
273 return extensions.*bool1 || extensions.*bool2;
274}
275
Jamie Madillcd089732015-12-17 09:53:09 -0500276// Special function for half float formats with three or four channels.
277static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions)
278{
279 return clientVersion >= 3 || extensions.textureHalfFloat;
280}
281
282static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
283{
284 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
285}
286
287// Special function for half float formats with one or two channels.
288static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions)
289{
290 return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG);
291}
292
293static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
294{
295 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
296}
297
298// Special function for float formats with three or four channels.
299static bool FloatSupport(GLuint clientVersion, const Extensions &extensions)
300{
301 return clientVersion >= 3 || extensions.textureFloat;
302}
303
304static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions)
305{
306 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
307 return FloatSupport(clientVersion, extensions) &&
308 (extensions.colorBufferFloat || clientVersion == 2);
309}
310
311// Special function for float formats with one or two channels.
312static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions)
313{
314 return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG);
315}
316
317static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions)
318{
319 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
320 return FloatSupportRG(clientVersion, extensions) &&
321 (extensions.colorBufferFloat || clientVersion == 2);
322}
323
Geoff Lang5d601382014-07-22 15:14:06 -0400324InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400325 : internalFormat(GL_NONE),
326 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400327 greenBits(0),
328 blueBits(0),
329 luminanceBits(0),
330 alphaBits(0),
331 sharedBits(0),
332 depthBits(0),
333 stencilBits(0),
334 pixelBytes(0),
335 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400336 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400337 compressedBlockWidth(0),
338 compressedBlockHeight(0),
339 format(GL_NONE),
340 type(GL_NONE),
341 componentType(GL_NONE),
342 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400343 textureSupport(NeverSupported),
344 renderSupport(NeverSupported),
345 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000346{
Geoff Lang5d601382014-07-22 15:14:06 -0400347}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000348
Jamie Madilla3944d42016-07-22 22:13:26 -0400349bool InternalFormat::isLUMA() const
350{
351 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
352 (luminanceBits + alphaBits) > 0);
353}
354
Geoff Langf607c602016-09-21 11:46:48 -0400355GLenum InternalFormat::getReadPixelsFormat() const
356{
357 return format;
358}
359
360GLenum InternalFormat::getReadPixelsType() const
361{
362 switch (type)
363 {
364 case GL_HALF_FLOAT:
365 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
366 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
367 // OES_texture_half_float
368 return GL_HALF_FLOAT_OES;
369
370 default:
371 return type;
372 }
373}
374
Jamie Madilla3944d42016-07-22 22:13:26 -0400375Format::Format(GLenum internalFormat) : Format(GetInternalFormatInfo(internalFormat))
376{
377}
378
379Format::Format(const InternalFormat &internalFormat)
380 : info(&internalFormat), format(info->format), type(info->type), sized(true)
381{
382 ASSERT((info->pixelBytes > 0 && format != GL_NONE && type != GL_NONE) ||
383 internalFormat.format == GL_NONE);
384}
385
386Format::Format(GLenum internalFormat, GLenum format, GLenum type)
387 : info(nullptr), format(format), type(type), sized(false)
388{
389 const auto &plainInfo = GetInternalFormatInfo(internalFormat);
390 sized = plainInfo.pixelBytes > 0;
391 info = (sized ? &plainInfo : &GetInternalFormatInfo(GetSizedFormatInternal(format, type)));
392 ASSERT(format == GL_NONE || info->pixelBytes > 0);
393}
394
395Format::Format(const Format &other) = default;
396Format &Format::operator=(const Format &other) = default;
397
398GLenum Format::asSized() const
399{
400 return sized ? info->internalFormat : GetSizedFormatInternal(format, type);
401}
402
403bool Format::valid() const
404{
405 return info->format != GL_NONE;
406}
407
408// static
409bool Format::SameSized(const Format &a, const Format &b)
410{
411 return (a.info == b.info);
412}
413
414// static
415Format Format::Invalid()
416{
417 static Format invalid(GL_NONE, GL_NONE, GL_NONE);
418 return invalid;
419}
420
421bool InternalFormat::operator==(const InternalFormat &other) const
422{
423 // We assume there are no duplicates.
424 ASSERT((this == &other) == (internalFormat == other.internalFormat));
425 return internalFormat == other.internalFormat;
426}
427
428bool InternalFormat::operator!=(const InternalFormat &other) const
429{
430 // We assume there are no duplicates.
431 ASSERT((this != &other) == (internalFormat != other.internalFormat));
432 return internalFormat != other.internalFormat;
433}
434
435static void AddUnsizedFormat(InternalFormatInfoMap *map,
436 GLenum internalFormat,
437 GLenum format,
438 InternalFormat::SupportCheckFunction textureSupport,
439 InternalFormat::SupportCheckFunction renderSupport,
440 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400441{
442 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400443 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400444 formatInfo.format = format;
445 formatInfo.textureSupport = textureSupport;
446 formatInfo.renderSupport = renderSupport;
447 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400448 ASSERT(map->count(internalFormat) == 0);
449 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400450}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000451
Jamie Madilla3944d42016-07-22 22:13:26 -0400452void AddRGBAFormat(InternalFormatInfoMap *map,
453 GLenum internalFormat,
454 GLuint red,
455 GLuint green,
456 GLuint blue,
457 GLuint alpha,
458 GLuint shared,
459 GLenum format,
460 GLenum type,
461 GLenum componentType,
462 bool srgb,
463 InternalFormat::SupportCheckFunction textureSupport,
464 InternalFormat::SupportCheckFunction renderSupport,
465 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400466{
467 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400468 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400469 formatInfo.redBits = red;
470 formatInfo.greenBits = green;
471 formatInfo.blueBits = blue;
472 formatInfo.alphaBits = alpha;
473 formatInfo.sharedBits = shared;
474 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
475 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
476 formatInfo.format = format;
477 formatInfo.type = type;
478 formatInfo.componentType = componentType;
479 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
480 formatInfo.textureSupport = textureSupport;
481 formatInfo.renderSupport = renderSupport;
482 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400483 ASSERT(map->count(internalFormat) == 0);
484 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400485}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000486
Geoff Lang5d601382014-07-22 15:14:06 -0400487static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
488 InternalFormat::SupportCheckFunction textureSupport,
489 InternalFormat::SupportCheckFunction renderSupport,
490 InternalFormat::SupportCheckFunction filterSupport)
491{
492 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400493 formatInfo.internalFormat = GetSizedFormatInternal(format, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400494 formatInfo.luminanceBits = luminance;
495 formatInfo.alphaBits = alpha;
496 formatInfo.pixelBytes = (luminance + alpha) / 8;
497 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
498 formatInfo.format = format;
499 formatInfo.type = type;
500 formatInfo.componentType = componentType;
501 formatInfo.colorEncoding = GL_LINEAR;
502 formatInfo.textureSupport = textureSupport;
503 formatInfo.renderSupport = renderSupport;
504 formatInfo.filterSupport = filterSupport;
505 return formatInfo;
506}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000507
Jamie Madilla3944d42016-07-22 22:13:26 -0400508void AddDepthStencilFormat(InternalFormatInfoMap *map,
509 GLenum internalFormat,
510 GLuint depthBits,
511 GLuint stencilBits,
512 GLuint unusedBits,
513 GLenum format,
514 GLenum type,
515 GLenum componentType,
516 InternalFormat::SupportCheckFunction textureSupport,
517 InternalFormat::SupportCheckFunction renderSupport,
518 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400519{
520 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400521 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400522 formatInfo.depthBits = depthBits;
523 formatInfo.stencilBits = stencilBits;
524 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
525 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
526 formatInfo.format = format;
527 formatInfo.type = type;
528 formatInfo.componentType = componentType;
529 formatInfo.colorEncoding = GL_LINEAR;
530 formatInfo.textureSupport = textureSupport;
531 formatInfo.renderSupport = renderSupport;
532 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400533 ASSERT(map->count(internalFormat) == 0);
534 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400535}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000536
Geoff Lang5d601382014-07-22 15:14:06 -0400537static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
538 GLuint componentCount, GLenum format, GLenum type, bool srgb,
539 InternalFormat::SupportCheckFunction textureSupport,
540 InternalFormat::SupportCheckFunction renderSupport,
541 InternalFormat::SupportCheckFunction filterSupport)
542{
543 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400544 formatInfo.internalFormat = format;
Geoff Lang5d601382014-07-22 15:14:06 -0400545 formatInfo.compressedBlockWidth = compressedBlockWidth;
546 formatInfo.compressedBlockHeight = compressedBlockHeight;
547 formatInfo.pixelBytes = compressedBlockSize / 8;
548 formatInfo.componentCount = componentCount;
549 formatInfo.format = format;
550 formatInfo.type = type;
551 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
552 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
553 formatInfo.compressed = true;
554 formatInfo.textureSupport = textureSupport;
555 formatInfo.renderSupport = renderSupport;
556 formatInfo.filterSupport = filterSupport;
557 return formatInfo;
558}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000559
Geoff Lange4a492b2014-06-19 14:14:41 -0400560static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000561{
562 InternalFormatInfoMap map;
563
564 // From ES 3.0.1 spec, table 3.12
Jamie Madilla3944d42016-07-22 22:13:26 -0400565 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000566
Jamie Madilla3944d42016-07-22 22:13:26 -0400567 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000568
Jamie Madilla3944d42016-07-22 22:13:26 -0400569 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
570 AddRGBAFormat(&map, GL_R8, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported);
571 AddRGBAFormat(&map, GL_R8_SNORM, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
572 AddRGBAFormat(&map, GL_RG8, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported);
573 AddRGBAFormat(&map, GL_RG8_SNORM, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
574 AddRGBAFormat(&map, GL_RGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported);
575 AddRGBAFormat(&map, GL_RGB8_SNORM, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
576 AddRGBAFormat(&map, GL_RGB565, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported);
577 AddRGBAFormat(&map, GL_RGBA4, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported);
578 AddRGBAFormat(&map, GL_RGB5_A1, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported);
579 AddRGBAFormat(&map, GL_RGBA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported);
580 AddRGBAFormat(&map, GL_RGBA8_SNORM, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
581 AddRGBAFormat(&map, GL_RGB10_A2, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3>, RequireES<3>, AlwaysSupported);
582 AddRGBAFormat(&map, GL_RGB10_A2UI, 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);
583 AddRGBAFormat(&map, GL_SRGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
584 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported);
585 AddRGBAFormat(&map, GL_RGB9_E5, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3>, NeverSupported, AlwaysSupported);
586 AddRGBAFormat(&map, GL_R8I, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
587 AddRGBAFormat(&map, GL_R8UI, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
588 AddRGBAFormat(&map, GL_R16I, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
589 AddRGBAFormat(&map, GL_R16UI, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
590 AddRGBAFormat(&map, GL_R32I, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
591 AddRGBAFormat(&map, GL_R32UI, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
592 AddRGBAFormat(&map, GL_RG8I, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
593 AddRGBAFormat(&map, GL_RG8UI, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
594 AddRGBAFormat(&map, GL_RG16I, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
595 AddRGBAFormat(&map, GL_RG16UI, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
596 AddRGBAFormat(&map, GL_RG32I, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
597 AddRGBAFormat(&map, GL_R11F_G11F_B10F, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported);
598 AddRGBAFormat(&map, GL_RG32UI, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
599 AddRGBAFormat(&map, GL_RGB8I, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
600 AddRGBAFormat(&map, GL_RGB8UI, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
601 AddRGBAFormat(&map, GL_RGB16I, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
602 AddRGBAFormat(&map, GL_RGB16UI, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
603 AddRGBAFormat(&map, GL_RGB32I, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
604 AddRGBAFormat(&map, GL_RGB32UI, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
605 AddRGBAFormat(&map, GL_RGBA8I, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
606 AddRGBAFormat(&map, GL_RGBA8UI, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
607 AddRGBAFormat(&map, GL_RGBA16I, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
608 AddRGBAFormat(&map, GL_RGBA16UI, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
609 AddRGBAFormat(&map, GL_RGBA32I, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
610 AddRGBAFormat(&map, GL_RGBA32UI, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
611
612 AddRGBAFormat(&map, GL_BGRA8_EXT, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
613 AddRGBAFormat(&map, GL_BGRA4_ANGLEX, 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);
614 AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX, 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 +0000615
Jamie Madillec0b5802016-07-04 13:11:59 -0400616 // Special format which is not really supported, so always false for all supports.
Jamie Madilla3944d42016-07-22 22:13:26 -0400617 AddRGBAFormat(&map, GL_BGR565_ANGLEX, 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported);
Jamie Madillec0b5802016-07-04 13:11:59 -0400618
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000619 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madilla3944d42016-07-22 22:13:26 -0400620 // | Internal format | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
621 // | | | | | | type | | | | |
622 AddRGBAFormat(&map, GL_R16F, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
623 AddRGBAFormat(&map, GL_RG16F, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
624 AddRGBAFormat(&map, GL_RGB16F, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
625 AddRGBAFormat(&map, GL_RGBA16F, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
626 AddRGBAFormat(&map, GL_R32F, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
627 AddRGBAFormat(&map, GL_RG32F, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
628 AddRGBAFormat(&map, GL_RGB32F, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
629 AddRGBAFormat(&map, GL_RGBA32F, 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 +0000630
631 // Depth stencil formats
Jamie Madilla3944d42016-07-22 22:13:26 -0400632 // | Internal format | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
633 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, RequireESOrExt<3, &Extensions::depthTextures>);
634 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>);
635 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>);
636 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported );
637 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, 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 );
638 AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, 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 -0800639 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000640
641 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400642 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400643 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
644 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
645 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
646 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
647 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
648 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
649 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
650 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
651 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 +0000652
653 // Unsized formats
Jamie Madilla3944d42016-07-22 22:13:26 -0400654 // | Internal format | Format | Supported | Renderable | Filterable |
655 AddUnsizedFormat(&map, GL_ALPHA, GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported);
656 AddUnsizedFormat(&map, GL_LUMINANCE, GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported);
657 AddUnsizedFormat(&map, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported);
658 AddUnsizedFormat(&map, GL_RED, GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
659 AddUnsizedFormat(&map, GL_RG, GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
660 AddUnsizedFormat(&map, GL_RGB, GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported);
661 AddUnsizedFormat(&map, GL_RGBA, GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported);
662 AddUnsizedFormat(&map, GL_RED_INTEGER, GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
663 AddUnsizedFormat(&map, GL_RG_INTEGER, GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
664 AddUnsizedFormat(&map, GL_RGB_INTEGER, GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
665 AddUnsizedFormat(&map, GL_RGBA_INTEGER, GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
666 AddUnsizedFormat(&map, GL_BGRA_EXT, GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
667 AddUnsizedFormat(&map, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported);
668 AddUnsizedFormat(&map, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported);
669 AddUnsizedFormat(&map, GL_SRGB_EXT, GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
670 AddUnsizedFormat(&map, GL_SRGB_ALPHA_EXT, GL_RGBA, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000671
672 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400673 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
674 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
675 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)));
676 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
677 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)));
678 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
679 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
680 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)));
681 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)));
682 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)));
683 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 +0000684
685 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400686 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
687 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)));
688 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 +0000689
690 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400691 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 +0000692
693 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400694 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)));
695
696 // From GL_OES_compressed_ETC1_RGB8_texture
697 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 +0000698
Geoff Lang60ad73d2015-10-23 10:08:44 -0400699 // From KHR_texture_compression_astc_hdr
700 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
701 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)));
702 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)));
703 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)));
704 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)));
705 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)));
706 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)));
707 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)));
708 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)));
709 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)));
710 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)));
711 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)));
712 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)));
713 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)));
714 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)));
715
716 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)));
717 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)));
718 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)));
719 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)));
720 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)));
721 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)));
722 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)));
723 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)));
724 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)));
725 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)));
726 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)));
727 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)));
728 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)));
729 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)));
730
Corentin Walleze0902642014-11-04 12:32:15 -0800731 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
732 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
733 // - All other stencil formats (all depth-stencil) are either float or normalized
734 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Jamie Madilla3944d42016-07-22 22:13:26 -0400735 // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
736 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800737
738 // From GL_ANGLE_lossy_etc_decode
Geoff Langd13ca302016-09-08 09:35:57 -0400739 map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported)));
Minmin Gonge3939b92015-12-01 15:36:51 -0800740
Vincent Lang25ab4512016-05-13 18:13:59 +0200741 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400742 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
743 AddRGBAFormat(&map, GL_R16_EXT, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
744 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
745 AddRGBAFormat(&map, GL_RG16_EXT, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
746 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
747 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
748 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
749 AddRGBAFormat(&map, GL_RGBA16_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
750 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
Vincent Lang25ab4512016-05-13 18:13:59 +0200751
Geoff Lang9bbad182015-09-04 11:07:29 -0400752 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800753
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000754 return map;
755}
756
Geoff Lange4a492b2014-06-19 14:14:41 -0400757static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000758{
Geoff Lange4a492b2014-06-19 14:14:41 -0400759 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
760 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000761}
762
Geoff Lange4a492b2014-06-19 14:14:41 -0400763static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400764{
765 FormatSet result;
766
Jamie Madillec0b5802016-07-04 13:11:59 -0400767 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400768 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400769 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400770 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400771 // TODO(jmadill): Fix this hack.
772 if (iter.first == GL_BGR565_ANGLEX)
773 continue;
774
775 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400776 }
777 }
778
779 return result;
780}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000781
Geoff Lang5d601382014-07-22 15:14:06 -0400782const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000783{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200784 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000785 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200786 case GL_UNSIGNED_BYTE:
787 case GL_BYTE:
788 {
789 static const Type info = GenTypeInfo(1, false);
790 return info;
791 }
792 case GL_UNSIGNED_SHORT:
793 case GL_SHORT:
794 case GL_HALF_FLOAT:
795 case GL_HALF_FLOAT_OES:
796 {
797 static const Type info = GenTypeInfo(2, false);
798 return info;
799 }
800 case GL_UNSIGNED_INT:
801 case GL_INT:
802 case GL_FLOAT:
803 {
804 static const Type info = GenTypeInfo(4, false);
805 return info;
806 }
807 case GL_UNSIGNED_SHORT_5_6_5:
808 case GL_UNSIGNED_SHORT_4_4_4_4:
809 case GL_UNSIGNED_SHORT_5_5_5_1:
810 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
811 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
812 {
813 static const Type info = GenTypeInfo(2, true);
814 return info;
815 }
816 case GL_UNSIGNED_INT_2_10_10_10_REV:
817 case GL_UNSIGNED_INT_24_8:
818 case GL_UNSIGNED_INT_10F_11F_11F_REV:
819 case GL_UNSIGNED_INT_5_9_9_9_REV:
820 {
821 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
822 static const Type info = GenTypeInfo(4, true);
823 return info;
824 }
825 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
826 {
827 static const Type info = GenTypeInfo(8, true);
828 return info;
829 }
830 default:
831 {
832 static const Type defaultInfo;
833 return defaultInfo;
834 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000835 }
836}
837
Geoff Lang5d601382014-07-22 15:14:06 -0400838const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839{
Geoff Lang5d601382014-07-22 15:14:06 -0400840 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400841 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400842 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000843 {
Geoff Lang5d601382014-07-22 15:14:06 -0400844 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000845 }
846 else
847 {
Geoff Lang5d601382014-07-22 15:14:06 -0400848 static const InternalFormat defaultInternalFormat;
Jamie Madillec0b5802016-07-04 13:11:59 -0400849 UNREACHABLE();
Geoff Lang5d601382014-07-22 15:14:06 -0400850 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000851 }
852}
853
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400854GLuint InternalFormat::computePixelBytes(GLenum formatType) const
855{
856 const auto &typeInfo = GetTypeInfo(formatType);
857 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
858 return components * typeInfo.bytes;
859}
860
Jamie Madille2e406c2016-06-02 13:04:10 -0400861gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
862 GLsizei width,
863 GLint alignment,
864 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000865{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700866 // Compressed images do not use pack/unpack parameters.
867 if (compressed)
868 {
869 ASSERT(rowLength == 0);
870 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
871 }
872
Geoff Lang3f234062016-07-13 15:35:45 -0400873 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400874 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700875
876 ASSERT(alignment > 0 && isPow2(alignment));
877 CheckedNumeric<GLuint> checkedAlignment(alignment);
878 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
879 ANGLE_TRY_CHECKED_MATH(aligned);
880 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000881}
882
Jamie Madille2e406c2016-06-02 13:04:10 -0400883gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
884 GLsizei width,
885 GLsizei height,
886 GLint alignment,
887 GLint rowLength,
888 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000889{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700890 GLuint rows =
891 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400892 GLuint rowPitch = 0;
893 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
894
895 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
896 auto depthPitch = checkedRowPitch * rows;
897 ANGLE_TRY_CHECKED_MATH(depthPitch);
898 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000899}
900
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700901gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
902 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000903{
Jamie Madill513558d2016-06-02 13:04:11 -0400904 CheckedNumeric<GLuint> checkedWidth(size.width);
905 CheckedNumeric<GLuint> checkedHeight(size.height);
906 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700907 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
908 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400909
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700910 ASSERT(compressed);
911 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
912 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
913 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
914 ANGLE_TRY_CHECKED_MATH(bytes);
915 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000916}
917
Olli Etuaho989cac32016-06-08 16:18:49 -0700918gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
919 GLuint depthPitch,
920 GLint skipImages,
921 GLint skipRows,
922 GLint skipPixels,
923 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400924{
Olli Etuaho989cac32016-06-08 16:18:49 -0700925 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
926 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
927 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
928 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
929 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
930 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
931 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
932 if (!applySkipImages)
933 {
934 checkedSkipImagesBytes = 0;
935 }
936 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
937 checkedSkipPixels * checkedPixelBytes;
938 ANGLE_TRY_CHECKED_MATH(skipBytes);
939 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400940}
941
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400942gl::ErrorOrResult<GLuint> InternalFormat::computePackSize(GLenum formatType,
943 const gl::Extents &size,
944 const gl::PixelPackState &pack) const
945{
946 ASSERT(!compressed);
947
948 if (size.height == 0)
949 {
950 return 0;
951 }
952
953 CheckedNumeric<GLuint> rowPitch;
954 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, pack.alignment, pack.rowLength),
955 rowPitch);
956
957 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
958 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
959
960 CheckedNumeric<GLuint> totalSize = heightMinusOne * rowPitch;
961 totalSize += size.width * bytes;
962
963 ANGLE_TRY_CHECKED_MATH(totalSize);
964
965 return totalSize.ValueOrDie();
966}
967
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700968gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
969 GLenum formatType,
970 const gl::Extents &size,
971 const gl::PixelUnpackState &unpack) const
972{
973 // Compressed images do not use unpack parameters.
974 if (compressed)
975 {
976 return computeCompressedImageSize(formatType, size);
977 }
978
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400979 if (size.height == 0 || size.depth == 0)
980 {
981 return 0;
982 }
983
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400984 CheckedNumeric<GLuint> rowPitch;
985 CheckedNumeric<GLuint> depthPitch;
986 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, unpack.alignment, unpack.rowLength),
987 rowPitch);
988 ANGLE_TRY_RESULT(computeDepthPitch(formatType, size.width, size.height, unpack.alignment,
989 unpack.rowLength, unpack.imageHeight),
990 depthPitch);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700991
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400992 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
993 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
Jamie Madill1db8a262016-09-22 13:53:47 -0400994 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700995
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400996 CheckedNumeric<GLuint> totalSize = depthMinusOne * depthPitch;
997 totalSize += heightMinusOne * rowPitch;
Jamie Madill1db8a262016-09-22 13:53:47 -0400998 totalSize += size.width * bytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700999
1000 ANGLE_TRY_CHECKED_MATH(totalSize);
1001
1002 return totalSize.ValueOrDie();
1003}
1004
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001005gl::ErrorOrResult<GLuint> InternalFormat::computePackEndByte(GLenum formatType,
1006 const gl::Extents &size,
1007 const gl::PixelPackState &pack) const
1008{
1009 GLuint rowPitch;
1010 CheckedNumeric<GLuint> checkedSkipBytes;
1011 CheckedNumeric<GLuint> checkedCopyBytes;
1012
1013 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, pack.alignment, pack.rowLength),
1014 rowPitch);
1015 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, 0, 0, pack.skipRows, pack.skipPixels, false),
1016 checkedSkipBytes);
1017 ANGLE_TRY_RESULT(computePackSize(formatType, size, pack), checkedCopyBytes);
1018
1019 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1020
1021 ANGLE_TRY_CHECKED_MATH(endByte);
1022 return endByte.ValueOrDie();
1023}
1024
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001025gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackEndByte(GLenum formatType,
1026 const gl::Extents &size,
1027 const gl::PixelUnpackState &unpack,
1028 bool applySkipImages) const
1029{
1030 GLuint rowPitch;
1031 GLuint depthPitch;
1032 CheckedNumeric<GLuint> checkedSkipBytes;
1033 CheckedNumeric<GLuint> checkedCopyBytes;
1034
1035 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, unpack.alignment, unpack.rowLength),
1036 rowPitch);
1037 ANGLE_TRY_RESULT(computeDepthPitch(formatType, size.width, size.height, unpack.alignment,
1038 unpack.rowLength, unpack.imageHeight),
1039 depthPitch);
1040 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, unpack.skipImages, unpack.skipRows,
1041 unpack.skipPixels, applySkipImages),
1042 checkedSkipBytes);
1043 ANGLE_TRY_RESULT(computeUnpackSize(formatType, size, unpack), checkedCopyBytes);
1044
1045 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1046
1047 ANGLE_TRY_CHECKED_MATH(endByte);
1048 return endByte.ValueOrDie();
1049}
1050
Geoff Lang5d601382014-07-22 15:14:06 -04001051GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001052{
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001053 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -05001054 if (formatInfo.pixelBytes > 0)
1055 {
1056 return internalFormat;
1057 }
Jamie Madilla3944d42016-07-22 22:13:26 -04001058 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001059}
1060
Geoff Lange4a492b2014-06-19 14:14:41 -04001061const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001062{
Geoff Lange4a492b2014-06-19 14:14:41 -04001063 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001064 return formatSet;
1065}
1066
Jamie Madill09e2d932015-07-14 16:40:31 -04001067AttributeType GetAttributeType(GLenum enumValue)
1068{
1069 switch (enumValue)
1070 {
1071 case GL_FLOAT:
1072 return ATTRIBUTE_FLOAT;
1073 case GL_FLOAT_VEC2:
1074 return ATTRIBUTE_VEC2;
1075 case GL_FLOAT_VEC3:
1076 return ATTRIBUTE_VEC3;
1077 case GL_FLOAT_VEC4:
1078 return ATTRIBUTE_VEC4;
1079 case GL_INT:
1080 return ATTRIBUTE_INT;
1081 case GL_INT_VEC2:
1082 return ATTRIBUTE_IVEC2;
1083 case GL_INT_VEC3:
1084 return ATTRIBUTE_IVEC3;
1085 case GL_INT_VEC4:
1086 return ATTRIBUTE_IVEC4;
1087 case GL_UNSIGNED_INT:
1088 return ATTRIBUTE_UINT;
1089 case GL_UNSIGNED_INT_VEC2:
1090 return ATTRIBUTE_UVEC2;
1091 case GL_UNSIGNED_INT_VEC3:
1092 return ATTRIBUTE_UVEC3;
1093 case GL_UNSIGNED_INT_VEC4:
1094 return ATTRIBUTE_UVEC4;
1095 case GL_FLOAT_MAT2:
1096 return ATTRIBUTE_MAT2;
1097 case GL_FLOAT_MAT3:
1098 return ATTRIBUTE_MAT3;
1099 case GL_FLOAT_MAT4:
1100 return ATTRIBUTE_MAT4;
1101 case GL_FLOAT_MAT2x3:
1102 return ATTRIBUTE_MAT2x3;
1103 case GL_FLOAT_MAT2x4:
1104 return ATTRIBUTE_MAT2x4;
1105 case GL_FLOAT_MAT3x2:
1106 return ATTRIBUTE_MAT3x2;
1107 case GL_FLOAT_MAT3x4:
1108 return ATTRIBUTE_MAT3x4;
1109 case GL_FLOAT_MAT4x2:
1110 return ATTRIBUTE_MAT4x2;
1111 case GL_FLOAT_MAT4x3:
1112 return ATTRIBUTE_MAT4x3;
1113 default:
1114 UNREACHABLE();
1115 return ATTRIBUTE_FLOAT;
1116 }
1117}
1118
Jamie Madilld3dfda22015-07-06 08:28:49 -04001119VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1120{
1121 switch (type)
1122 {
1123 case GL_BYTE:
1124 switch (components)
1125 {
1126 case 1:
1127 if (pureInteger)
1128 return VERTEX_FORMAT_SBYTE1_INT;
1129 if (normalized)
1130 return VERTEX_FORMAT_SBYTE1_NORM;
1131 return VERTEX_FORMAT_SBYTE1;
1132 case 2:
1133 if (pureInteger)
1134 return VERTEX_FORMAT_SBYTE2_INT;
1135 if (normalized)
1136 return VERTEX_FORMAT_SBYTE2_NORM;
1137 return VERTEX_FORMAT_SBYTE2;
1138 case 3:
1139 if (pureInteger)
1140 return VERTEX_FORMAT_SBYTE3_INT;
1141 if (normalized)
1142 return VERTEX_FORMAT_SBYTE3_NORM;
1143 return VERTEX_FORMAT_SBYTE3;
1144 case 4:
1145 if (pureInteger)
1146 return VERTEX_FORMAT_SBYTE4_INT;
1147 if (normalized)
1148 return VERTEX_FORMAT_SBYTE4_NORM;
1149 return VERTEX_FORMAT_SBYTE4;
1150 default:
1151 UNREACHABLE();
1152 break;
1153 }
1154 case GL_UNSIGNED_BYTE:
1155 switch (components)
1156 {
1157 case 1:
1158 if (pureInteger)
1159 return VERTEX_FORMAT_UBYTE1_INT;
1160 if (normalized)
1161 return VERTEX_FORMAT_UBYTE1_NORM;
1162 return VERTEX_FORMAT_UBYTE1;
1163 case 2:
1164 if (pureInteger)
1165 return VERTEX_FORMAT_UBYTE2_INT;
1166 if (normalized)
1167 return VERTEX_FORMAT_UBYTE2_NORM;
1168 return VERTEX_FORMAT_UBYTE2;
1169 case 3:
1170 if (pureInteger)
1171 return VERTEX_FORMAT_UBYTE3_INT;
1172 if (normalized)
1173 return VERTEX_FORMAT_UBYTE3_NORM;
1174 return VERTEX_FORMAT_UBYTE3;
1175 case 4:
1176 if (pureInteger)
1177 return VERTEX_FORMAT_UBYTE4_INT;
1178 if (normalized)
1179 return VERTEX_FORMAT_UBYTE4_NORM;
1180 return VERTEX_FORMAT_UBYTE4;
1181 default:
1182 UNREACHABLE();
1183 break;
1184 }
1185 case GL_SHORT:
1186 switch (components)
1187 {
1188 case 1:
1189 if (pureInteger)
1190 return VERTEX_FORMAT_SSHORT1_INT;
1191 if (normalized)
1192 return VERTEX_FORMAT_SSHORT1_NORM;
1193 return VERTEX_FORMAT_SSHORT1;
1194 case 2:
1195 if (pureInteger)
1196 return VERTEX_FORMAT_SSHORT2_INT;
1197 if (normalized)
1198 return VERTEX_FORMAT_SSHORT2_NORM;
1199 return VERTEX_FORMAT_SSHORT2;
1200 case 3:
1201 if (pureInteger)
1202 return VERTEX_FORMAT_SSHORT3_INT;
1203 if (normalized)
1204 return VERTEX_FORMAT_SSHORT3_NORM;
1205 return VERTEX_FORMAT_SSHORT3;
1206 case 4:
1207 if (pureInteger)
1208 return VERTEX_FORMAT_SSHORT4_INT;
1209 if (normalized)
1210 return VERTEX_FORMAT_SSHORT4_NORM;
1211 return VERTEX_FORMAT_SSHORT4;
1212 default:
1213 UNREACHABLE();
1214 break;
1215 }
1216 case GL_UNSIGNED_SHORT:
1217 switch (components)
1218 {
1219 case 1:
1220 if (pureInteger)
1221 return VERTEX_FORMAT_USHORT1_INT;
1222 if (normalized)
1223 return VERTEX_FORMAT_USHORT1_NORM;
1224 return VERTEX_FORMAT_USHORT1;
1225 case 2:
1226 if (pureInteger)
1227 return VERTEX_FORMAT_USHORT2_INT;
1228 if (normalized)
1229 return VERTEX_FORMAT_USHORT2_NORM;
1230 return VERTEX_FORMAT_USHORT2;
1231 case 3:
1232 if (pureInteger)
1233 return VERTEX_FORMAT_USHORT3_INT;
1234 if (normalized)
1235 return VERTEX_FORMAT_USHORT3_NORM;
1236 return VERTEX_FORMAT_USHORT3;
1237 case 4:
1238 if (pureInteger)
1239 return VERTEX_FORMAT_USHORT4_INT;
1240 if (normalized)
1241 return VERTEX_FORMAT_USHORT4_NORM;
1242 return VERTEX_FORMAT_USHORT4;
1243 default:
1244 UNREACHABLE();
1245 break;
1246 }
1247 case GL_INT:
1248 switch (components)
1249 {
1250 case 1:
1251 if (pureInteger)
1252 return VERTEX_FORMAT_SINT1_INT;
1253 if (normalized)
1254 return VERTEX_FORMAT_SINT1_NORM;
1255 return VERTEX_FORMAT_SINT1;
1256 case 2:
1257 if (pureInteger)
1258 return VERTEX_FORMAT_SINT2_INT;
1259 if (normalized)
1260 return VERTEX_FORMAT_SINT2_NORM;
1261 return VERTEX_FORMAT_SINT2;
1262 case 3:
1263 if (pureInteger)
1264 return VERTEX_FORMAT_SINT3_INT;
1265 if (normalized)
1266 return VERTEX_FORMAT_SINT3_NORM;
1267 return VERTEX_FORMAT_SINT3;
1268 case 4:
1269 if (pureInteger)
1270 return VERTEX_FORMAT_SINT4_INT;
1271 if (normalized)
1272 return VERTEX_FORMAT_SINT4_NORM;
1273 return VERTEX_FORMAT_SINT4;
1274 default:
1275 UNREACHABLE();
1276 break;
1277 }
1278 case GL_UNSIGNED_INT:
1279 switch (components)
1280 {
1281 case 1:
1282 if (pureInteger)
1283 return VERTEX_FORMAT_UINT1_INT;
1284 if (normalized)
1285 return VERTEX_FORMAT_UINT1_NORM;
1286 return VERTEX_FORMAT_UINT1;
1287 case 2:
1288 if (pureInteger)
1289 return VERTEX_FORMAT_UINT2_INT;
1290 if (normalized)
1291 return VERTEX_FORMAT_UINT2_NORM;
1292 return VERTEX_FORMAT_UINT2;
1293 case 3:
1294 if (pureInteger)
1295 return VERTEX_FORMAT_UINT3_INT;
1296 if (normalized)
1297 return VERTEX_FORMAT_UINT3_NORM;
1298 return VERTEX_FORMAT_UINT3;
1299 case 4:
1300 if (pureInteger)
1301 return VERTEX_FORMAT_UINT4_INT;
1302 if (normalized)
1303 return VERTEX_FORMAT_UINT4_NORM;
1304 return VERTEX_FORMAT_UINT4;
1305 default:
1306 UNREACHABLE();
1307 break;
1308 }
1309 case GL_FLOAT:
1310 switch (components)
1311 {
1312 case 1:
1313 return VERTEX_FORMAT_FLOAT1;
1314 case 2:
1315 return VERTEX_FORMAT_FLOAT2;
1316 case 3:
1317 return VERTEX_FORMAT_FLOAT3;
1318 case 4:
1319 return VERTEX_FORMAT_FLOAT4;
1320 default:
1321 UNREACHABLE();
1322 break;
1323 }
1324 case GL_HALF_FLOAT:
1325 switch (components)
1326 {
1327 case 1:
1328 return VERTEX_FORMAT_HALF1;
1329 case 2:
1330 return VERTEX_FORMAT_HALF2;
1331 case 3:
1332 return VERTEX_FORMAT_HALF3;
1333 case 4:
1334 return VERTEX_FORMAT_HALF4;
1335 default:
1336 UNREACHABLE();
1337 break;
1338 }
1339 case GL_FIXED:
1340 switch (components)
1341 {
1342 case 1:
1343 return VERTEX_FORMAT_FIXED1;
1344 case 2:
1345 return VERTEX_FORMAT_FIXED2;
1346 case 3:
1347 return VERTEX_FORMAT_FIXED3;
1348 case 4:
1349 return VERTEX_FORMAT_FIXED4;
1350 default:
1351 UNREACHABLE();
1352 break;
1353 }
1354 case GL_INT_2_10_10_10_REV:
1355 if (pureInteger)
1356 return VERTEX_FORMAT_SINT210_INT;
1357 if (normalized)
1358 return VERTEX_FORMAT_SINT210_NORM;
1359 return VERTEX_FORMAT_SINT210;
1360 case GL_UNSIGNED_INT_2_10_10_10_REV:
1361 if (pureInteger)
1362 return VERTEX_FORMAT_UINT210_INT;
1363 if (normalized)
1364 return VERTEX_FORMAT_UINT210_NORM;
1365 return VERTEX_FORMAT_UINT210;
1366 default:
1367 UNREACHABLE();
1368 break;
1369 }
1370 return VERTEX_FORMAT_UBYTE1;
1371}
1372
1373VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1374{
1375 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1376}
1377
1378VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1379{
1380 if (!attrib.enabled)
1381 {
1382 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1383 }
1384 return GetVertexFormatType(attrib);
1385}
1386
1387const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1388{
1389 switch (vertexFormatType)
1390 {
1391 case VERTEX_FORMAT_SBYTE1:
1392 {
1393 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1394 return format;
1395 }
1396 case VERTEX_FORMAT_SBYTE1_NORM:
1397 {
1398 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1399 return format;
1400 }
1401 case VERTEX_FORMAT_SBYTE2:
1402 {
1403 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1404 return format;
1405 }
1406 case VERTEX_FORMAT_SBYTE2_NORM:
1407 {
1408 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1409 return format;
1410 }
1411 case VERTEX_FORMAT_SBYTE3:
1412 {
1413 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1414 return format;
1415 }
1416 case VERTEX_FORMAT_SBYTE3_NORM:
1417 {
1418 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1419 return format;
1420 }
1421 case VERTEX_FORMAT_SBYTE4:
1422 {
1423 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1424 return format;
1425 }
1426 case VERTEX_FORMAT_SBYTE4_NORM:
1427 {
1428 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1429 return format;
1430 }
1431 case VERTEX_FORMAT_UBYTE1:
1432 {
1433 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1434 return format;
1435 }
1436 case VERTEX_FORMAT_UBYTE1_NORM:
1437 {
1438 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1439 return format;
1440 }
1441 case VERTEX_FORMAT_UBYTE2:
1442 {
1443 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1444 return format;
1445 }
1446 case VERTEX_FORMAT_UBYTE2_NORM:
1447 {
1448 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1449 return format;
1450 }
1451 case VERTEX_FORMAT_UBYTE3:
1452 {
1453 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1454 return format;
1455 }
1456 case VERTEX_FORMAT_UBYTE3_NORM:
1457 {
1458 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1459 return format;
1460 }
1461 case VERTEX_FORMAT_UBYTE4:
1462 {
1463 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1464 return format;
1465 }
1466 case VERTEX_FORMAT_UBYTE4_NORM:
1467 {
1468 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1469 return format;
1470 }
1471 case VERTEX_FORMAT_SSHORT1:
1472 {
1473 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1474 return format;
1475 }
1476 case VERTEX_FORMAT_SSHORT1_NORM:
1477 {
1478 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1479 return format;
1480 }
1481 case VERTEX_FORMAT_SSHORT2:
1482 {
1483 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1484 return format;
1485 }
1486 case VERTEX_FORMAT_SSHORT2_NORM:
1487 {
1488 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1489 return format;
1490 }
1491 case VERTEX_FORMAT_SSHORT3:
1492 {
1493 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1494 return format;
1495 }
1496 case VERTEX_FORMAT_SSHORT3_NORM:
1497 {
1498 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1499 return format;
1500 }
1501 case VERTEX_FORMAT_SSHORT4:
1502 {
1503 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1504 return format;
1505 }
1506 case VERTEX_FORMAT_SSHORT4_NORM:
1507 {
1508 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1509 return format;
1510 }
1511 case VERTEX_FORMAT_USHORT1:
1512 {
1513 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1514 return format;
1515 }
1516 case VERTEX_FORMAT_USHORT1_NORM:
1517 {
1518 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1519 return format;
1520 }
1521 case VERTEX_FORMAT_USHORT2:
1522 {
1523 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1524 return format;
1525 }
1526 case VERTEX_FORMAT_USHORT2_NORM:
1527 {
1528 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1529 return format;
1530 }
1531 case VERTEX_FORMAT_USHORT3:
1532 {
1533 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1534 return format;
1535 }
1536 case VERTEX_FORMAT_USHORT3_NORM:
1537 {
1538 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1539 return format;
1540 }
1541 case VERTEX_FORMAT_USHORT4:
1542 {
1543 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1544 return format;
1545 }
1546 case VERTEX_FORMAT_USHORT4_NORM:
1547 {
1548 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1549 return format;
1550 }
1551 case VERTEX_FORMAT_SINT1:
1552 {
1553 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1554 return format;
1555 }
1556 case VERTEX_FORMAT_SINT1_NORM:
1557 {
1558 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1559 return format;
1560 }
1561 case VERTEX_FORMAT_SINT2:
1562 {
1563 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1564 return format;
1565 }
1566 case VERTEX_FORMAT_SINT2_NORM:
1567 {
1568 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1569 return format;
1570 }
1571 case VERTEX_FORMAT_SINT3:
1572 {
1573 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1574 return format;
1575 }
1576 case VERTEX_FORMAT_SINT3_NORM:
1577 {
1578 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1579 return format;
1580 }
1581 case VERTEX_FORMAT_SINT4:
1582 {
1583 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1584 return format;
1585 }
1586 case VERTEX_FORMAT_SINT4_NORM:
1587 {
1588 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1589 return format;
1590 }
1591 case VERTEX_FORMAT_UINT1:
1592 {
1593 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1594 return format;
1595 }
1596 case VERTEX_FORMAT_UINT1_NORM:
1597 {
1598 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1599 return format;
1600 }
1601 case VERTEX_FORMAT_UINT2:
1602 {
1603 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1604 return format;
1605 }
1606 case VERTEX_FORMAT_UINT2_NORM:
1607 {
1608 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1609 return format;
1610 }
1611 case VERTEX_FORMAT_UINT3:
1612 {
1613 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1614 return format;
1615 }
1616 case VERTEX_FORMAT_UINT3_NORM:
1617 {
1618 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1619 return format;
1620 }
1621 case VERTEX_FORMAT_UINT4:
1622 {
1623 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1624 return format;
1625 }
1626 case VERTEX_FORMAT_UINT4_NORM:
1627 {
1628 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1629 return format;
1630 }
1631 case VERTEX_FORMAT_SBYTE1_INT:
1632 {
1633 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1634 return format;
1635 }
1636 case VERTEX_FORMAT_SBYTE2_INT:
1637 {
1638 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1639 return format;
1640 }
1641 case VERTEX_FORMAT_SBYTE3_INT:
1642 {
1643 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1644 return format;
1645 }
1646 case VERTEX_FORMAT_SBYTE4_INT:
1647 {
1648 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1649 return format;
1650 }
1651 case VERTEX_FORMAT_UBYTE1_INT:
1652 {
1653 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1654 return format;
1655 }
1656 case VERTEX_FORMAT_UBYTE2_INT:
1657 {
1658 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1659 return format;
1660 }
1661 case VERTEX_FORMAT_UBYTE3_INT:
1662 {
1663 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1664 return format;
1665 }
1666 case VERTEX_FORMAT_UBYTE4_INT:
1667 {
1668 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1669 return format;
1670 }
1671 case VERTEX_FORMAT_SSHORT1_INT:
1672 {
1673 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1674 return format;
1675 }
1676 case VERTEX_FORMAT_SSHORT2_INT:
1677 {
1678 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1679 return format;
1680 }
1681 case VERTEX_FORMAT_SSHORT3_INT:
1682 {
1683 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1684 return format;
1685 }
1686 case VERTEX_FORMAT_SSHORT4_INT:
1687 {
1688 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1689 return format;
1690 }
1691 case VERTEX_FORMAT_USHORT1_INT:
1692 {
1693 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1694 return format;
1695 }
1696 case VERTEX_FORMAT_USHORT2_INT:
1697 {
1698 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1699 return format;
1700 }
1701 case VERTEX_FORMAT_USHORT3_INT:
1702 {
1703 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1704 return format;
1705 }
1706 case VERTEX_FORMAT_USHORT4_INT:
1707 {
1708 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1709 return format;
1710 }
1711 case VERTEX_FORMAT_SINT1_INT:
1712 {
1713 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1714 return format;
1715 }
1716 case VERTEX_FORMAT_SINT2_INT:
1717 {
1718 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1719 return format;
1720 }
1721 case VERTEX_FORMAT_SINT3_INT:
1722 {
1723 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1724 return format;
1725 }
1726 case VERTEX_FORMAT_SINT4_INT:
1727 {
1728 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1729 return format;
1730 }
1731 case VERTEX_FORMAT_UINT1_INT:
1732 {
1733 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1734 return format;
1735 }
1736 case VERTEX_FORMAT_UINT2_INT:
1737 {
1738 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1739 return format;
1740 }
1741 case VERTEX_FORMAT_UINT3_INT:
1742 {
1743 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1744 return format;
1745 }
1746 case VERTEX_FORMAT_UINT4_INT:
1747 {
1748 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1749 return format;
1750 }
1751 case VERTEX_FORMAT_FIXED1:
1752 {
1753 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1754 return format;
1755 }
1756 case VERTEX_FORMAT_FIXED2:
1757 {
1758 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1759 return format;
1760 }
1761 case VERTEX_FORMAT_FIXED3:
1762 {
1763 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1764 return format;
1765 }
1766 case VERTEX_FORMAT_FIXED4:
1767 {
1768 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1769 return format;
1770 }
1771 case VERTEX_FORMAT_HALF1:
1772 {
1773 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1774 return format;
1775 }
1776 case VERTEX_FORMAT_HALF2:
1777 {
1778 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1779 return format;
1780 }
1781 case VERTEX_FORMAT_HALF3:
1782 {
1783 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1784 return format;
1785 }
1786 case VERTEX_FORMAT_HALF4:
1787 {
1788 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1789 return format;
1790 }
1791 case VERTEX_FORMAT_FLOAT1:
1792 {
1793 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1794 return format;
1795 }
1796 case VERTEX_FORMAT_FLOAT2:
1797 {
1798 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1799 return format;
1800 }
1801 case VERTEX_FORMAT_FLOAT3:
1802 {
1803 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1804 return format;
1805 }
1806 case VERTEX_FORMAT_FLOAT4:
1807 {
1808 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1809 return format;
1810 }
1811 case VERTEX_FORMAT_SINT210:
1812 {
1813 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1814 return format;
1815 }
1816 case VERTEX_FORMAT_UINT210:
1817 {
1818 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1819 return format;
1820 }
1821 case VERTEX_FORMAT_SINT210_NORM:
1822 {
1823 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1824 return format;
1825 }
1826 case VERTEX_FORMAT_UINT210_NORM:
1827 {
1828 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1829 return format;
1830 }
1831 case VERTEX_FORMAT_SINT210_INT:
1832 {
1833 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1834 return format;
1835 }
1836 case VERTEX_FORMAT_UINT210_INT:
1837 {
1838 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1839 return format;
1840 }
1841 default:
1842 {
1843 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1844 return format;
1845 }
1846 }
1847}
1848
1849VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1850 : type(typeIn),
1851 normalized(normalizedIn),
1852 components(componentsIn),
1853 pureInteger(pureIntegerIn)
1854{
1855 // float -> !normalized
1856 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1857}
1858
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001859}