blob: 0d524289a95bb77e6710842364cb39ec705807ad [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
355Format::Format(GLenum internalFormat) : Format(GetInternalFormatInfo(internalFormat))
356{
357}
358
359Format::Format(const InternalFormat &internalFormat)
360 : info(&internalFormat), format(info->format), type(info->type), sized(true)
361{
362 ASSERT((info->pixelBytes > 0 && format != GL_NONE && type != GL_NONE) ||
363 internalFormat.format == GL_NONE);
364}
365
366Format::Format(GLenum internalFormat, GLenum format, GLenum type)
367 : info(nullptr), format(format), type(type), sized(false)
368{
369 const auto &plainInfo = GetInternalFormatInfo(internalFormat);
370 sized = plainInfo.pixelBytes > 0;
371 info = (sized ? &plainInfo : &GetInternalFormatInfo(GetSizedFormatInternal(format, type)));
372 ASSERT(format == GL_NONE || info->pixelBytes > 0);
373}
374
375Format::Format(const Format &other) = default;
376Format &Format::operator=(const Format &other) = default;
377
378GLenum Format::asSized() const
379{
380 return sized ? info->internalFormat : GetSizedFormatInternal(format, type);
381}
382
383bool Format::valid() const
384{
385 return info->format != GL_NONE;
386}
387
388// static
389bool Format::SameSized(const Format &a, const Format &b)
390{
391 return (a.info == b.info);
392}
393
394// static
395Format Format::Invalid()
396{
397 static Format invalid(GL_NONE, GL_NONE, GL_NONE);
398 return invalid;
399}
400
401bool InternalFormat::operator==(const InternalFormat &other) const
402{
403 // We assume there are no duplicates.
404 ASSERT((this == &other) == (internalFormat == other.internalFormat));
405 return internalFormat == other.internalFormat;
406}
407
408bool InternalFormat::operator!=(const InternalFormat &other) const
409{
410 // We assume there are no duplicates.
411 ASSERT((this != &other) == (internalFormat != other.internalFormat));
412 return internalFormat != other.internalFormat;
413}
414
415static void AddUnsizedFormat(InternalFormatInfoMap *map,
416 GLenum internalFormat,
417 GLenum format,
418 InternalFormat::SupportCheckFunction textureSupport,
419 InternalFormat::SupportCheckFunction renderSupport,
420 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400421{
422 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400423 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400424 formatInfo.format = format;
425 formatInfo.textureSupport = textureSupport;
426 formatInfo.renderSupport = renderSupport;
427 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400428 ASSERT(map->count(internalFormat) == 0);
429 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400430}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000431
Jamie Madilla3944d42016-07-22 22:13:26 -0400432void AddRGBAFormat(InternalFormatInfoMap *map,
433 GLenum internalFormat,
434 GLuint red,
435 GLuint green,
436 GLuint blue,
437 GLuint alpha,
438 GLuint shared,
439 GLenum format,
440 GLenum type,
441 GLenum componentType,
442 bool srgb,
443 InternalFormat::SupportCheckFunction textureSupport,
444 InternalFormat::SupportCheckFunction renderSupport,
445 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400446{
447 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400448 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400449 formatInfo.redBits = red;
450 formatInfo.greenBits = green;
451 formatInfo.blueBits = blue;
452 formatInfo.alphaBits = alpha;
453 formatInfo.sharedBits = shared;
454 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
455 formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
456 formatInfo.format = format;
457 formatInfo.type = type;
458 formatInfo.componentType = componentType;
459 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
460 formatInfo.textureSupport = textureSupport;
461 formatInfo.renderSupport = renderSupport;
462 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400463 ASSERT(map->count(internalFormat) == 0);
464 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400465}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000466
Geoff Lang5d601382014-07-22 15:14:06 -0400467static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType,
468 InternalFormat::SupportCheckFunction textureSupport,
469 InternalFormat::SupportCheckFunction renderSupport,
470 InternalFormat::SupportCheckFunction filterSupport)
471{
472 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400473 formatInfo.internalFormat = GetSizedFormatInternal(format, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400474 formatInfo.luminanceBits = luminance;
475 formatInfo.alphaBits = alpha;
476 formatInfo.pixelBytes = (luminance + alpha) / 8;
477 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
478 formatInfo.format = format;
479 formatInfo.type = type;
480 formatInfo.componentType = componentType;
481 formatInfo.colorEncoding = GL_LINEAR;
482 formatInfo.textureSupport = textureSupport;
483 formatInfo.renderSupport = renderSupport;
484 formatInfo.filterSupport = filterSupport;
485 return formatInfo;
486}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000487
Jamie Madilla3944d42016-07-22 22:13:26 -0400488void AddDepthStencilFormat(InternalFormatInfoMap *map,
489 GLenum internalFormat,
490 GLuint depthBits,
491 GLuint stencilBits,
492 GLuint unusedBits,
493 GLenum format,
494 GLenum type,
495 GLenum componentType,
496 InternalFormat::SupportCheckFunction textureSupport,
497 InternalFormat::SupportCheckFunction renderSupport,
498 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400499{
500 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400501 formatInfo.internalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400502 formatInfo.depthBits = depthBits;
503 formatInfo.stencilBits = stencilBits;
504 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
505 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
506 formatInfo.format = format;
507 formatInfo.type = type;
508 formatInfo.componentType = componentType;
509 formatInfo.colorEncoding = GL_LINEAR;
510 formatInfo.textureSupport = textureSupport;
511 formatInfo.renderSupport = renderSupport;
512 formatInfo.filterSupport = filterSupport;
Jamie Madilla3944d42016-07-22 22:13:26 -0400513 ASSERT(map->count(internalFormat) == 0);
514 (*map)[internalFormat] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400515}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000516
Geoff Lang5d601382014-07-22 15:14:06 -0400517static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize,
518 GLuint componentCount, GLenum format, GLenum type, bool srgb,
519 InternalFormat::SupportCheckFunction textureSupport,
520 InternalFormat::SupportCheckFunction renderSupport,
521 InternalFormat::SupportCheckFunction filterSupport)
522{
523 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400524 formatInfo.internalFormat = format;
Geoff Lang5d601382014-07-22 15:14:06 -0400525 formatInfo.compressedBlockWidth = compressedBlockWidth;
526 formatInfo.compressedBlockHeight = compressedBlockHeight;
527 formatInfo.pixelBytes = compressedBlockSize / 8;
528 formatInfo.componentCount = componentCount;
529 formatInfo.format = format;
530 formatInfo.type = type;
531 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
532 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
533 formatInfo.compressed = true;
534 formatInfo.textureSupport = textureSupport;
535 formatInfo.renderSupport = renderSupport;
536 formatInfo.filterSupport = filterSupport;
537 return formatInfo;
538}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000539
Geoff Lange4a492b2014-06-19 14:14:41 -0400540static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000541{
542 InternalFormatInfoMap map;
543
544 // From ES 3.0.1 spec, table 3.12
Jamie Madilla3944d42016-07-22 22:13:26 -0400545 map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat()));
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000546
Jamie Madilla3944d42016-07-22 22:13:26 -0400547 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000548
Jamie Madilla3944d42016-07-22 22:13:26 -0400549 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
550 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);
551 AddRGBAFormat(&map, GL_R8_SNORM, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
552 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);
553 AddRGBAFormat(&map, GL_RG8_SNORM, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
554 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);
555 AddRGBAFormat(&map, GL_RGB8_SNORM, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
556 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);
557 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);
558 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);
559 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);
560 AddRGBAFormat(&map, GL_RGBA8_SNORM, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported);
561 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);
562 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);
563 AddRGBAFormat(&map, GL_SRGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
564 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);
565 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);
566 AddRGBAFormat(&map, GL_R8I, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
567 AddRGBAFormat(&map, GL_R8UI, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
568 AddRGBAFormat(&map, GL_R16I, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
569 AddRGBAFormat(&map, GL_R16UI, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
570 AddRGBAFormat(&map, GL_R32I, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
571 AddRGBAFormat(&map, GL_R32UI, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
572 AddRGBAFormat(&map, GL_RG8I, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
573 AddRGBAFormat(&map, GL_RG8UI, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
574 AddRGBAFormat(&map, GL_RG16I, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
575 AddRGBAFormat(&map, GL_RG16UI, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
576 AddRGBAFormat(&map, GL_RG32I, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
577 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);
578 AddRGBAFormat(&map, GL_RG32UI, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
579 AddRGBAFormat(&map, GL_RGB8I, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
580 AddRGBAFormat(&map, GL_RGB8UI, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
581 AddRGBAFormat(&map, GL_RGB16I, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
582 AddRGBAFormat(&map, GL_RGB16UI, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
583 AddRGBAFormat(&map, GL_RGB32I, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported);
584 AddRGBAFormat(&map, GL_RGB32UI, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported);
585 AddRGBAFormat(&map, GL_RGBA8I, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
586 AddRGBAFormat(&map, GL_RGBA8UI, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
587 AddRGBAFormat(&map, GL_RGBA16I, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
588 AddRGBAFormat(&map, GL_RGBA16UI, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
589 AddRGBAFormat(&map, GL_RGBA32I, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
590 AddRGBAFormat(&map, GL_RGBA32UI, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported);
591
592 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);
593 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);
594 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 +0000595
Jamie Madillec0b5802016-07-04 13:11:59 -0400596 // Special format which is not really supported, so always false for all supports.
Jamie Madilla3944d42016-07-22 22:13:26 -0400597 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 -0400598
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000599 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Jamie Madilla3944d42016-07-22 22:13:26 -0400600 // | Internal format | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
601 // | | | | | | type | | | | |
602 AddRGBAFormat(&map, GL_R16F, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
603 AddRGBAFormat(&map, GL_RG16F, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
604 AddRGBAFormat(&map, GL_RGB16F, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
605 AddRGBAFormat(&map, GL_RGBA16F, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
606 AddRGBAFormat(&map, GL_R32F, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
607 AddRGBAFormat(&map, GL_RG32F, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
608 AddRGBAFormat(&map, GL_RGB32F, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
609 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 +0000610
611 // Depth stencil formats
Jamie Madilla3944d42016-07-22 22:13:26 -0400612 // | Internal format | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
613 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>);
614 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>);
615 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>);
616 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 );
617 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 );
618 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 -0800619 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000620
621 // Luminance alpha formats
Geoff Lang5d601382014-07-22 15:14:06 -0400622 // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
Geoff Langabce7622014-09-19 16:13:00 -0400623 map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
624 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
625 map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
626 map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
627 map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
628 map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported)));
629 map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported)));
630 map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported)));
631 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 +0000632
633 // Unsized formats
Jamie Madilla3944d42016-07-22 22:13:26 -0400634 // | Internal format | Format | Supported | Renderable | Filterable |
635 AddUnsizedFormat(&map, GL_ALPHA, GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported);
636 AddUnsizedFormat(&map, GL_LUMINANCE, GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported);
637 AddUnsizedFormat(&map, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported);
638 AddUnsizedFormat(&map, GL_RED, GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
639 AddUnsizedFormat(&map, GL_RG, GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
640 AddUnsizedFormat(&map, GL_RGB, GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported);
641 AddUnsizedFormat(&map, GL_RGBA, GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported);
642 AddUnsizedFormat(&map, GL_RED_INTEGER, GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
643 AddUnsizedFormat(&map, GL_RG_INTEGER, GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
644 AddUnsizedFormat(&map, GL_RGB_INTEGER, GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
645 AddUnsizedFormat(&map, GL_RGBA_INTEGER, GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported );
646 AddUnsizedFormat(&map, GL_BGRA_EXT, GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
647 AddUnsizedFormat(&map, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported);
648 AddUnsizedFormat(&map, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported);
649 AddUnsizedFormat(&map, GL_SRGB_EXT, GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
650 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 +0000651
652 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Lang0d8b7242015-09-09 14:56:53 -0400653 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
654 map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
655 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)));
656 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
657 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)));
658 map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported)));
659 map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported)));
660 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)));
661 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)));
662 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)));
663 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 +0000664
665 // From GL_EXT_texture_compression_dxt1
Geoff Lang6ea6f942015-09-11 13:11:22 -0400666 // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
667 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)));
668 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 +0000669
670 // From GL_ANGLE_texture_compression_dxt3
Geoff Lang6ea6f942015-09-11 13:11:22 -0400671 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 +0000672
673 // From GL_ANGLE_texture_compression_dxt5
Geoff Lang6ea6f942015-09-11 13:11:22 -0400674 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)));
675
676 // From GL_OES_compressed_ETC1_RGB8_texture
677 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 +0000678
Geoff Lang60ad73d2015-10-23 10:08:44 -0400679 // From KHR_texture_compression_astc_hdr
680 // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
681 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)));
682 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)));
683 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)));
684 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)));
685 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)));
686 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)));
687 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)));
688 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)));
689 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)));
690 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)));
691 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)));
692 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)));
693 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)));
694 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)));
695
696 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)));
697 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)));
698 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)));
699 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)));
700 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)));
701 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)));
702 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)));
703 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)));
704 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)));
705 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)));
706 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)));
707 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)));
708 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)));
709 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)));
710
Corentin Walleze0902642014-11-04 12:32:15 -0800711 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
712 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
713 // - All other stencil formats (all depth-stencil) are either float or normalized
714 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Jamie Madilla3944d42016-07-22 22:13:26 -0400715 // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
716 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 -0800717
718 // From GL_ANGLE_lossy_etc_decode
Geoff Langd13ca302016-09-08 09:35:57 -0400719 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 -0800720
Vincent Lang25ab4512016-05-13 18:13:59 +0200721 // From GL_EXT_texture_norm16
Jamie Madilla3944d42016-07-22 22:13:26 -0400722 // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
723 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);
724 AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
725 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);
726 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
727 AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
728 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
729 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);
730 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 +0200731
Geoff Lang9bbad182015-09-04 11:07:29 -0400732 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800733
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000734 return map;
735}
736
Geoff Lange4a492b2014-06-19 14:14:41 -0400737static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000738{
Geoff Lange4a492b2014-06-19 14:14:41 -0400739 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
740 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000741}
742
Geoff Lange4a492b2014-06-19 14:14:41 -0400743static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400744{
745 FormatSet result;
746
Jamie Madillec0b5802016-07-04 13:11:59 -0400747 for (auto iter : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400748 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400749 if (iter.second.pixelBytes > 0)
Geoff Langcec35902014-04-16 10:52:36 -0400750 {
Jamie Madillec0b5802016-07-04 13:11:59 -0400751 // TODO(jmadill): Fix this hack.
752 if (iter.first == GL_BGR565_ANGLEX)
753 continue;
754
755 result.insert(iter.first);
Geoff Langcec35902014-04-16 10:52:36 -0400756 }
757 }
758
759 return result;
760}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000761
Geoff Lang5d601382014-07-22 15:14:06 -0400762const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000763{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200764 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000765 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200766 case GL_UNSIGNED_BYTE:
767 case GL_BYTE:
768 {
769 static const Type info = GenTypeInfo(1, false);
770 return info;
771 }
772 case GL_UNSIGNED_SHORT:
773 case GL_SHORT:
774 case GL_HALF_FLOAT:
775 case GL_HALF_FLOAT_OES:
776 {
777 static const Type info = GenTypeInfo(2, false);
778 return info;
779 }
780 case GL_UNSIGNED_INT:
781 case GL_INT:
782 case GL_FLOAT:
783 {
784 static const Type info = GenTypeInfo(4, false);
785 return info;
786 }
787 case GL_UNSIGNED_SHORT_5_6_5:
788 case GL_UNSIGNED_SHORT_4_4_4_4:
789 case GL_UNSIGNED_SHORT_5_5_5_1:
790 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
791 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
792 {
793 static const Type info = GenTypeInfo(2, true);
794 return info;
795 }
796 case GL_UNSIGNED_INT_2_10_10_10_REV:
797 case GL_UNSIGNED_INT_24_8:
798 case GL_UNSIGNED_INT_10F_11F_11F_REV:
799 case GL_UNSIGNED_INT_5_9_9_9_REV:
800 {
801 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
802 static const Type info = GenTypeInfo(4, true);
803 return info;
804 }
805 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
806 {
807 static const Type info = GenTypeInfo(8, true);
808 return info;
809 }
810 default:
811 {
812 static const Type defaultInfo;
813 return defaultInfo;
814 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000815 }
816}
817
Geoff Lang5d601382014-07-22 15:14:06 -0400818const InternalFormat &GetInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000819{
Geoff Lang5d601382014-07-22 15:14:06 -0400820 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400821 auto iter = formatMap.find(internalFormat);
Geoff Lang5d601382014-07-22 15:14:06 -0400822 if (iter != formatMap.end())
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000823 {
Geoff Lang5d601382014-07-22 15:14:06 -0400824 return iter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000825 }
826 else
827 {
Geoff Lang5d601382014-07-22 15:14:06 -0400828 static const InternalFormat defaultInternalFormat;
Jamie Madillec0b5802016-07-04 13:11:59 -0400829 UNREACHABLE();
Geoff Lang5d601382014-07-22 15:14:06 -0400830 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000831 }
832}
833
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400834GLuint InternalFormat::computePixelBytes(GLenum formatType) const
835{
836 const auto &typeInfo = GetTypeInfo(formatType);
837 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
838 return components * typeInfo.bytes;
839}
840
Jamie Madille2e406c2016-06-02 13:04:10 -0400841gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
842 GLsizei width,
843 GLint alignment,
844 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000845{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700846 // Compressed images do not use pack/unpack parameters.
847 if (compressed)
848 {
849 ASSERT(rowLength == 0);
850 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
851 }
852
Geoff Lang3f234062016-07-13 15:35:45 -0400853 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400854 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700855
856 ASSERT(alignment > 0 && isPow2(alignment));
857 CheckedNumeric<GLuint> checkedAlignment(alignment);
858 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
859 ANGLE_TRY_CHECKED_MATH(aligned);
860 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000861}
862
Jamie Madille2e406c2016-06-02 13:04:10 -0400863gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
864 GLsizei width,
865 GLsizei height,
866 GLint alignment,
867 GLint rowLength,
868 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000869{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700870 GLuint rows =
871 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400872 GLuint rowPitch = 0;
873 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
874
875 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
876 auto depthPitch = checkedRowPitch * rows;
877 ANGLE_TRY_CHECKED_MATH(depthPitch);
878 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000879}
880
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700881gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
882 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000883{
Jamie Madill513558d2016-06-02 13:04:11 -0400884 CheckedNumeric<GLuint> checkedWidth(size.width);
885 CheckedNumeric<GLuint> checkedHeight(size.height);
886 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700887 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
888 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400889
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700890 ASSERT(compressed);
891 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
892 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
893 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
894 ANGLE_TRY_CHECKED_MATH(bytes);
895 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000896}
897
Olli Etuaho989cac32016-06-08 16:18:49 -0700898gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
899 GLuint depthPitch,
900 GLint skipImages,
901 GLint skipRows,
902 GLint skipPixels,
903 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400904{
Olli Etuaho989cac32016-06-08 16:18:49 -0700905 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
906 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
907 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
908 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
909 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
910 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
911 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
912 if (!applySkipImages)
913 {
914 checkedSkipImagesBytes = 0;
915 }
916 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
917 checkedSkipPixels * checkedPixelBytes;
918 ANGLE_TRY_CHECKED_MATH(skipBytes);
919 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400920}
921
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700922gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
923 GLenum formatType,
924 const gl::Extents &size,
925 const gl::PixelUnpackState &unpack) const
926{
927 // Compressed images do not use unpack parameters.
928 if (compressed)
929 {
930 return computeCompressedImageSize(formatType, size);
931 }
932
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400933 CheckedNumeric<GLuint> rowPitch;
934 CheckedNumeric<GLuint> depthPitch;
935 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, unpack.alignment, unpack.rowLength),
936 rowPitch);
937 ANGLE_TRY_RESULT(computeDepthPitch(formatType, size.width, size.height, unpack.alignment,
938 unpack.rowLength, unpack.imageHeight),
939 depthPitch);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700940
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400941 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
942 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
943 CheckedNumeric<GLuint> pixelBytes = computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700944
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400945 CheckedNumeric<GLuint> totalSize = depthMinusOne * depthPitch;
946 totalSize += heightMinusOne * rowPitch;
947 totalSize += size.width * pixelBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700948
949 ANGLE_TRY_CHECKED_MATH(totalSize);
950
951 return totalSize.ValueOrDie();
952}
953
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400954gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackEndByte(GLenum formatType,
955 const gl::Extents &size,
956 const gl::PixelUnpackState &unpack,
957 bool applySkipImages) const
958{
959 GLuint rowPitch;
960 GLuint depthPitch;
961 CheckedNumeric<GLuint> checkedSkipBytes;
962 CheckedNumeric<GLuint> checkedCopyBytes;
963
964 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, unpack.alignment, unpack.rowLength),
965 rowPitch);
966 ANGLE_TRY_RESULT(computeDepthPitch(formatType, size.width, size.height, unpack.alignment,
967 unpack.rowLength, unpack.imageHeight),
968 depthPitch);
969 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, unpack.skipImages, unpack.skipRows,
970 unpack.skipPixels, applySkipImages),
971 checkedSkipBytes);
972 ANGLE_TRY_RESULT(computeUnpackSize(formatType, size, unpack), checkedCopyBytes);
973
974 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
975
976 ANGLE_TRY_CHECKED_MATH(endByte);
977 return endByte.ValueOrDie();
978}
979
Geoff Lang5d601382014-07-22 15:14:06 -0400980GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000981{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700982 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500983 if (formatInfo.pixelBytes > 0)
984 {
985 return internalFormat;
986 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400987 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000988}
989
Geoff Lange4a492b2014-06-19 14:14:41 -0400990const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400991{
Geoff Lange4a492b2014-06-19 14:14:41 -0400992 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400993 return formatSet;
994}
995
Jamie Madill09e2d932015-07-14 16:40:31 -0400996AttributeType GetAttributeType(GLenum enumValue)
997{
998 switch (enumValue)
999 {
1000 case GL_FLOAT:
1001 return ATTRIBUTE_FLOAT;
1002 case GL_FLOAT_VEC2:
1003 return ATTRIBUTE_VEC2;
1004 case GL_FLOAT_VEC3:
1005 return ATTRIBUTE_VEC3;
1006 case GL_FLOAT_VEC4:
1007 return ATTRIBUTE_VEC4;
1008 case GL_INT:
1009 return ATTRIBUTE_INT;
1010 case GL_INT_VEC2:
1011 return ATTRIBUTE_IVEC2;
1012 case GL_INT_VEC3:
1013 return ATTRIBUTE_IVEC3;
1014 case GL_INT_VEC4:
1015 return ATTRIBUTE_IVEC4;
1016 case GL_UNSIGNED_INT:
1017 return ATTRIBUTE_UINT;
1018 case GL_UNSIGNED_INT_VEC2:
1019 return ATTRIBUTE_UVEC2;
1020 case GL_UNSIGNED_INT_VEC3:
1021 return ATTRIBUTE_UVEC3;
1022 case GL_UNSIGNED_INT_VEC4:
1023 return ATTRIBUTE_UVEC4;
1024 case GL_FLOAT_MAT2:
1025 return ATTRIBUTE_MAT2;
1026 case GL_FLOAT_MAT3:
1027 return ATTRIBUTE_MAT3;
1028 case GL_FLOAT_MAT4:
1029 return ATTRIBUTE_MAT4;
1030 case GL_FLOAT_MAT2x3:
1031 return ATTRIBUTE_MAT2x3;
1032 case GL_FLOAT_MAT2x4:
1033 return ATTRIBUTE_MAT2x4;
1034 case GL_FLOAT_MAT3x2:
1035 return ATTRIBUTE_MAT3x2;
1036 case GL_FLOAT_MAT3x4:
1037 return ATTRIBUTE_MAT3x4;
1038 case GL_FLOAT_MAT4x2:
1039 return ATTRIBUTE_MAT4x2;
1040 case GL_FLOAT_MAT4x3:
1041 return ATTRIBUTE_MAT4x3;
1042 default:
1043 UNREACHABLE();
1044 return ATTRIBUTE_FLOAT;
1045 }
1046}
1047
Jamie Madilld3dfda22015-07-06 08:28:49 -04001048VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1049{
1050 switch (type)
1051 {
1052 case GL_BYTE:
1053 switch (components)
1054 {
1055 case 1:
1056 if (pureInteger)
1057 return VERTEX_FORMAT_SBYTE1_INT;
1058 if (normalized)
1059 return VERTEX_FORMAT_SBYTE1_NORM;
1060 return VERTEX_FORMAT_SBYTE1;
1061 case 2:
1062 if (pureInteger)
1063 return VERTEX_FORMAT_SBYTE2_INT;
1064 if (normalized)
1065 return VERTEX_FORMAT_SBYTE2_NORM;
1066 return VERTEX_FORMAT_SBYTE2;
1067 case 3:
1068 if (pureInteger)
1069 return VERTEX_FORMAT_SBYTE3_INT;
1070 if (normalized)
1071 return VERTEX_FORMAT_SBYTE3_NORM;
1072 return VERTEX_FORMAT_SBYTE3;
1073 case 4:
1074 if (pureInteger)
1075 return VERTEX_FORMAT_SBYTE4_INT;
1076 if (normalized)
1077 return VERTEX_FORMAT_SBYTE4_NORM;
1078 return VERTEX_FORMAT_SBYTE4;
1079 default:
1080 UNREACHABLE();
1081 break;
1082 }
1083 case GL_UNSIGNED_BYTE:
1084 switch (components)
1085 {
1086 case 1:
1087 if (pureInteger)
1088 return VERTEX_FORMAT_UBYTE1_INT;
1089 if (normalized)
1090 return VERTEX_FORMAT_UBYTE1_NORM;
1091 return VERTEX_FORMAT_UBYTE1;
1092 case 2:
1093 if (pureInteger)
1094 return VERTEX_FORMAT_UBYTE2_INT;
1095 if (normalized)
1096 return VERTEX_FORMAT_UBYTE2_NORM;
1097 return VERTEX_FORMAT_UBYTE2;
1098 case 3:
1099 if (pureInteger)
1100 return VERTEX_FORMAT_UBYTE3_INT;
1101 if (normalized)
1102 return VERTEX_FORMAT_UBYTE3_NORM;
1103 return VERTEX_FORMAT_UBYTE3;
1104 case 4:
1105 if (pureInteger)
1106 return VERTEX_FORMAT_UBYTE4_INT;
1107 if (normalized)
1108 return VERTEX_FORMAT_UBYTE4_NORM;
1109 return VERTEX_FORMAT_UBYTE4;
1110 default:
1111 UNREACHABLE();
1112 break;
1113 }
1114 case GL_SHORT:
1115 switch (components)
1116 {
1117 case 1:
1118 if (pureInteger)
1119 return VERTEX_FORMAT_SSHORT1_INT;
1120 if (normalized)
1121 return VERTEX_FORMAT_SSHORT1_NORM;
1122 return VERTEX_FORMAT_SSHORT1;
1123 case 2:
1124 if (pureInteger)
1125 return VERTEX_FORMAT_SSHORT2_INT;
1126 if (normalized)
1127 return VERTEX_FORMAT_SSHORT2_NORM;
1128 return VERTEX_FORMAT_SSHORT2;
1129 case 3:
1130 if (pureInteger)
1131 return VERTEX_FORMAT_SSHORT3_INT;
1132 if (normalized)
1133 return VERTEX_FORMAT_SSHORT3_NORM;
1134 return VERTEX_FORMAT_SSHORT3;
1135 case 4:
1136 if (pureInteger)
1137 return VERTEX_FORMAT_SSHORT4_INT;
1138 if (normalized)
1139 return VERTEX_FORMAT_SSHORT4_NORM;
1140 return VERTEX_FORMAT_SSHORT4;
1141 default:
1142 UNREACHABLE();
1143 break;
1144 }
1145 case GL_UNSIGNED_SHORT:
1146 switch (components)
1147 {
1148 case 1:
1149 if (pureInteger)
1150 return VERTEX_FORMAT_USHORT1_INT;
1151 if (normalized)
1152 return VERTEX_FORMAT_USHORT1_NORM;
1153 return VERTEX_FORMAT_USHORT1;
1154 case 2:
1155 if (pureInteger)
1156 return VERTEX_FORMAT_USHORT2_INT;
1157 if (normalized)
1158 return VERTEX_FORMAT_USHORT2_NORM;
1159 return VERTEX_FORMAT_USHORT2;
1160 case 3:
1161 if (pureInteger)
1162 return VERTEX_FORMAT_USHORT3_INT;
1163 if (normalized)
1164 return VERTEX_FORMAT_USHORT3_NORM;
1165 return VERTEX_FORMAT_USHORT3;
1166 case 4:
1167 if (pureInteger)
1168 return VERTEX_FORMAT_USHORT4_INT;
1169 if (normalized)
1170 return VERTEX_FORMAT_USHORT4_NORM;
1171 return VERTEX_FORMAT_USHORT4;
1172 default:
1173 UNREACHABLE();
1174 break;
1175 }
1176 case GL_INT:
1177 switch (components)
1178 {
1179 case 1:
1180 if (pureInteger)
1181 return VERTEX_FORMAT_SINT1_INT;
1182 if (normalized)
1183 return VERTEX_FORMAT_SINT1_NORM;
1184 return VERTEX_FORMAT_SINT1;
1185 case 2:
1186 if (pureInteger)
1187 return VERTEX_FORMAT_SINT2_INT;
1188 if (normalized)
1189 return VERTEX_FORMAT_SINT2_NORM;
1190 return VERTEX_FORMAT_SINT2;
1191 case 3:
1192 if (pureInteger)
1193 return VERTEX_FORMAT_SINT3_INT;
1194 if (normalized)
1195 return VERTEX_FORMAT_SINT3_NORM;
1196 return VERTEX_FORMAT_SINT3;
1197 case 4:
1198 if (pureInteger)
1199 return VERTEX_FORMAT_SINT4_INT;
1200 if (normalized)
1201 return VERTEX_FORMAT_SINT4_NORM;
1202 return VERTEX_FORMAT_SINT4;
1203 default:
1204 UNREACHABLE();
1205 break;
1206 }
1207 case GL_UNSIGNED_INT:
1208 switch (components)
1209 {
1210 case 1:
1211 if (pureInteger)
1212 return VERTEX_FORMAT_UINT1_INT;
1213 if (normalized)
1214 return VERTEX_FORMAT_UINT1_NORM;
1215 return VERTEX_FORMAT_UINT1;
1216 case 2:
1217 if (pureInteger)
1218 return VERTEX_FORMAT_UINT2_INT;
1219 if (normalized)
1220 return VERTEX_FORMAT_UINT2_NORM;
1221 return VERTEX_FORMAT_UINT2;
1222 case 3:
1223 if (pureInteger)
1224 return VERTEX_FORMAT_UINT3_INT;
1225 if (normalized)
1226 return VERTEX_FORMAT_UINT3_NORM;
1227 return VERTEX_FORMAT_UINT3;
1228 case 4:
1229 if (pureInteger)
1230 return VERTEX_FORMAT_UINT4_INT;
1231 if (normalized)
1232 return VERTEX_FORMAT_UINT4_NORM;
1233 return VERTEX_FORMAT_UINT4;
1234 default:
1235 UNREACHABLE();
1236 break;
1237 }
1238 case GL_FLOAT:
1239 switch (components)
1240 {
1241 case 1:
1242 return VERTEX_FORMAT_FLOAT1;
1243 case 2:
1244 return VERTEX_FORMAT_FLOAT2;
1245 case 3:
1246 return VERTEX_FORMAT_FLOAT3;
1247 case 4:
1248 return VERTEX_FORMAT_FLOAT4;
1249 default:
1250 UNREACHABLE();
1251 break;
1252 }
1253 case GL_HALF_FLOAT:
1254 switch (components)
1255 {
1256 case 1:
1257 return VERTEX_FORMAT_HALF1;
1258 case 2:
1259 return VERTEX_FORMAT_HALF2;
1260 case 3:
1261 return VERTEX_FORMAT_HALF3;
1262 case 4:
1263 return VERTEX_FORMAT_HALF4;
1264 default:
1265 UNREACHABLE();
1266 break;
1267 }
1268 case GL_FIXED:
1269 switch (components)
1270 {
1271 case 1:
1272 return VERTEX_FORMAT_FIXED1;
1273 case 2:
1274 return VERTEX_FORMAT_FIXED2;
1275 case 3:
1276 return VERTEX_FORMAT_FIXED3;
1277 case 4:
1278 return VERTEX_FORMAT_FIXED4;
1279 default:
1280 UNREACHABLE();
1281 break;
1282 }
1283 case GL_INT_2_10_10_10_REV:
1284 if (pureInteger)
1285 return VERTEX_FORMAT_SINT210_INT;
1286 if (normalized)
1287 return VERTEX_FORMAT_SINT210_NORM;
1288 return VERTEX_FORMAT_SINT210;
1289 case GL_UNSIGNED_INT_2_10_10_10_REV:
1290 if (pureInteger)
1291 return VERTEX_FORMAT_UINT210_INT;
1292 if (normalized)
1293 return VERTEX_FORMAT_UINT210_NORM;
1294 return VERTEX_FORMAT_UINT210;
1295 default:
1296 UNREACHABLE();
1297 break;
1298 }
1299 return VERTEX_FORMAT_UBYTE1;
1300}
1301
1302VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1303{
1304 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1305}
1306
1307VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1308{
1309 if (!attrib.enabled)
1310 {
1311 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1312 }
1313 return GetVertexFormatType(attrib);
1314}
1315
1316const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1317{
1318 switch (vertexFormatType)
1319 {
1320 case VERTEX_FORMAT_SBYTE1:
1321 {
1322 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1323 return format;
1324 }
1325 case VERTEX_FORMAT_SBYTE1_NORM:
1326 {
1327 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1328 return format;
1329 }
1330 case VERTEX_FORMAT_SBYTE2:
1331 {
1332 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1333 return format;
1334 }
1335 case VERTEX_FORMAT_SBYTE2_NORM:
1336 {
1337 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1338 return format;
1339 }
1340 case VERTEX_FORMAT_SBYTE3:
1341 {
1342 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1343 return format;
1344 }
1345 case VERTEX_FORMAT_SBYTE3_NORM:
1346 {
1347 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1348 return format;
1349 }
1350 case VERTEX_FORMAT_SBYTE4:
1351 {
1352 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1353 return format;
1354 }
1355 case VERTEX_FORMAT_SBYTE4_NORM:
1356 {
1357 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1358 return format;
1359 }
1360 case VERTEX_FORMAT_UBYTE1:
1361 {
1362 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1363 return format;
1364 }
1365 case VERTEX_FORMAT_UBYTE1_NORM:
1366 {
1367 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1368 return format;
1369 }
1370 case VERTEX_FORMAT_UBYTE2:
1371 {
1372 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1373 return format;
1374 }
1375 case VERTEX_FORMAT_UBYTE2_NORM:
1376 {
1377 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1378 return format;
1379 }
1380 case VERTEX_FORMAT_UBYTE3:
1381 {
1382 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1383 return format;
1384 }
1385 case VERTEX_FORMAT_UBYTE3_NORM:
1386 {
1387 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1388 return format;
1389 }
1390 case VERTEX_FORMAT_UBYTE4:
1391 {
1392 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1393 return format;
1394 }
1395 case VERTEX_FORMAT_UBYTE4_NORM:
1396 {
1397 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1398 return format;
1399 }
1400 case VERTEX_FORMAT_SSHORT1:
1401 {
1402 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1403 return format;
1404 }
1405 case VERTEX_FORMAT_SSHORT1_NORM:
1406 {
1407 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1408 return format;
1409 }
1410 case VERTEX_FORMAT_SSHORT2:
1411 {
1412 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1413 return format;
1414 }
1415 case VERTEX_FORMAT_SSHORT2_NORM:
1416 {
1417 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1418 return format;
1419 }
1420 case VERTEX_FORMAT_SSHORT3:
1421 {
1422 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1423 return format;
1424 }
1425 case VERTEX_FORMAT_SSHORT3_NORM:
1426 {
1427 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1428 return format;
1429 }
1430 case VERTEX_FORMAT_SSHORT4:
1431 {
1432 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1433 return format;
1434 }
1435 case VERTEX_FORMAT_SSHORT4_NORM:
1436 {
1437 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1438 return format;
1439 }
1440 case VERTEX_FORMAT_USHORT1:
1441 {
1442 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1443 return format;
1444 }
1445 case VERTEX_FORMAT_USHORT1_NORM:
1446 {
1447 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1448 return format;
1449 }
1450 case VERTEX_FORMAT_USHORT2:
1451 {
1452 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1453 return format;
1454 }
1455 case VERTEX_FORMAT_USHORT2_NORM:
1456 {
1457 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1458 return format;
1459 }
1460 case VERTEX_FORMAT_USHORT3:
1461 {
1462 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1463 return format;
1464 }
1465 case VERTEX_FORMAT_USHORT3_NORM:
1466 {
1467 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1468 return format;
1469 }
1470 case VERTEX_FORMAT_USHORT4:
1471 {
1472 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1473 return format;
1474 }
1475 case VERTEX_FORMAT_USHORT4_NORM:
1476 {
1477 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1478 return format;
1479 }
1480 case VERTEX_FORMAT_SINT1:
1481 {
1482 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1483 return format;
1484 }
1485 case VERTEX_FORMAT_SINT1_NORM:
1486 {
1487 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1488 return format;
1489 }
1490 case VERTEX_FORMAT_SINT2:
1491 {
1492 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1493 return format;
1494 }
1495 case VERTEX_FORMAT_SINT2_NORM:
1496 {
1497 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1498 return format;
1499 }
1500 case VERTEX_FORMAT_SINT3:
1501 {
1502 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1503 return format;
1504 }
1505 case VERTEX_FORMAT_SINT3_NORM:
1506 {
1507 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1508 return format;
1509 }
1510 case VERTEX_FORMAT_SINT4:
1511 {
1512 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1513 return format;
1514 }
1515 case VERTEX_FORMAT_SINT4_NORM:
1516 {
1517 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1518 return format;
1519 }
1520 case VERTEX_FORMAT_UINT1:
1521 {
1522 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1523 return format;
1524 }
1525 case VERTEX_FORMAT_UINT1_NORM:
1526 {
1527 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1528 return format;
1529 }
1530 case VERTEX_FORMAT_UINT2:
1531 {
1532 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1533 return format;
1534 }
1535 case VERTEX_FORMAT_UINT2_NORM:
1536 {
1537 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1538 return format;
1539 }
1540 case VERTEX_FORMAT_UINT3:
1541 {
1542 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1543 return format;
1544 }
1545 case VERTEX_FORMAT_UINT3_NORM:
1546 {
1547 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1548 return format;
1549 }
1550 case VERTEX_FORMAT_UINT4:
1551 {
1552 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1553 return format;
1554 }
1555 case VERTEX_FORMAT_UINT4_NORM:
1556 {
1557 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1558 return format;
1559 }
1560 case VERTEX_FORMAT_SBYTE1_INT:
1561 {
1562 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1563 return format;
1564 }
1565 case VERTEX_FORMAT_SBYTE2_INT:
1566 {
1567 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1568 return format;
1569 }
1570 case VERTEX_FORMAT_SBYTE3_INT:
1571 {
1572 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1573 return format;
1574 }
1575 case VERTEX_FORMAT_SBYTE4_INT:
1576 {
1577 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1578 return format;
1579 }
1580 case VERTEX_FORMAT_UBYTE1_INT:
1581 {
1582 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1583 return format;
1584 }
1585 case VERTEX_FORMAT_UBYTE2_INT:
1586 {
1587 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1588 return format;
1589 }
1590 case VERTEX_FORMAT_UBYTE3_INT:
1591 {
1592 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1593 return format;
1594 }
1595 case VERTEX_FORMAT_UBYTE4_INT:
1596 {
1597 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1598 return format;
1599 }
1600 case VERTEX_FORMAT_SSHORT1_INT:
1601 {
1602 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1603 return format;
1604 }
1605 case VERTEX_FORMAT_SSHORT2_INT:
1606 {
1607 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1608 return format;
1609 }
1610 case VERTEX_FORMAT_SSHORT3_INT:
1611 {
1612 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1613 return format;
1614 }
1615 case VERTEX_FORMAT_SSHORT4_INT:
1616 {
1617 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1618 return format;
1619 }
1620 case VERTEX_FORMAT_USHORT1_INT:
1621 {
1622 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1623 return format;
1624 }
1625 case VERTEX_FORMAT_USHORT2_INT:
1626 {
1627 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1628 return format;
1629 }
1630 case VERTEX_FORMAT_USHORT3_INT:
1631 {
1632 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1633 return format;
1634 }
1635 case VERTEX_FORMAT_USHORT4_INT:
1636 {
1637 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1638 return format;
1639 }
1640 case VERTEX_FORMAT_SINT1_INT:
1641 {
1642 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1643 return format;
1644 }
1645 case VERTEX_FORMAT_SINT2_INT:
1646 {
1647 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1648 return format;
1649 }
1650 case VERTEX_FORMAT_SINT3_INT:
1651 {
1652 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1653 return format;
1654 }
1655 case VERTEX_FORMAT_SINT4_INT:
1656 {
1657 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1658 return format;
1659 }
1660 case VERTEX_FORMAT_UINT1_INT:
1661 {
1662 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1663 return format;
1664 }
1665 case VERTEX_FORMAT_UINT2_INT:
1666 {
1667 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1668 return format;
1669 }
1670 case VERTEX_FORMAT_UINT3_INT:
1671 {
1672 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1673 return format;
1674 }
1675 case VERTEX_FORMAT_UINT4_INT:
1676 {
1677 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1678 return format;
1679 }
1680 case VERTEX_FORMAT_FIXED1:
1681 {
1682 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1683 return format;
1684 }
1685 case VERTEX_FORMAT_FIXED2:
1686 {
1687 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1688 return format;
1689 }
1690 case VERTEX_FORMAT_FIXED3:
1691 {
1692 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1693 return format;
1694 }
1695 case VERTEX_FORMAT_FIXED4:
1696 {
1697 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1698 return format;
1699 }
1700 case VERTEX_FORMAT_HALF1:
1701 {
1702 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1703 return format;
1704 }
1705 case VERTEX_FORMAT_HALF2:
1706 {
1707 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1708 return format;
1709 }
1710 case VERTEX_FORMAT_HALF3:
1711 {
1712 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1713 return format;
1714 }
1715 case VERTEX_FORMAT_HALF4:
1716 {
1717 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1718 return format;
1719 }
1720 case VERTEX_FORMAT_FLOAT1:
1721 {
1722 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1723 return format;
1724 }
1725 case VERTEX_FORMAT_FLOAT2:
1726 {
1727 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1728 return format;
1729 }
1730 case VERTEX_FORMAT_FLOAT3:
1731 {
1732 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1733 return format;
1734 }
1735 case VERTEX_FORMAT_FLOAT4:
1736 {
1737 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1738 return format;
1739 }
1740 case VERTEX_FORMAT_SINT210:
1741 {
1742 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1743 return format;
1744 }
1745 case VERTEX_FORMAT_UINT210:
1746 {
1747 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1748 return format;
1749 }
1750 case VERTEX_FORMAT_SINT210_NORM:
1751 {
1752 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1753 return format;
1754 }
1755 case VERTEX_FORMAT_UINT210_NORM:
1756 {
1757 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1758 return format;
1759 }
1760 case VERTEX_FORMAT_SINT210_INT:
1761 {
1762 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1763 return format;
1764 }
1765 case VERTEX_FORMAT_UINT210_INT:
1766 {
1767 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1768 return format;
1769 }
1770 default:
1771 {
1772 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1773 return format;
1774 }
1775 }
1776}
1777
1778VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1779 : type(typeIn),
1780 normalized(normalizedIn),
1781 components(componentsIn),
1782 pureInteger(pureIntegerIn)
1783{
1784 // float -> !normalized
1785 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1786}
1787
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001788}