blob: e7c0e778248fdb5b0db280e03c283ee43785e950 [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
Jamie Madille2e406c2016-06-02 13:04:10 -0400834gl::ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
835 GLsizei width,
836 GLint alignment,
837 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000838{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700839 // Compressed images do not use pack/unpack parameters.
840 if (compressed)
841 {
842 ASSERT(rowLength == 0);
843 return computeCompressedImageSize(formatType, gl::Extents(width, 1, 1));
844 }
845
Geoff Lang3f234062016-07-13 15:35:45 -0400846 const auto &typeInfo = GetTypeInfo(formatType);
847 CheckedNumeric<GLuint> checkedComponents(typeInfo.specialInterpretation ? 1u : componentCount);
848 CheckedNumeric<GLuint> checkedTypeBytes(typeInfo.bytes);
849 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
850 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * checkedComponents * checkedTypeBytes;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700851
852 ASSERT(alignment > 0 && isPow2(alignment));
853 CheckedNumeric<GLuint> checkedAlignment(alignment);
854 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
855 ANGLE_TRY_CHECKED_MATH(aligned);
856 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000857}
858
Jamie Madille2e406c2016-06-02 13:04:10 -0400859gl::ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
860 GLsizei width,
861 GLsizei height,
862 GLint alignment,
863 GLint rowLength,
864 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000865{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700866 GLuint rows =
867 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
Jamie Madille2e406c2016-06-02 13:04:10 -0400868 GLuint rowPitch = 0;
869 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
870
871 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
872 auto depthPitch = checkedRowPitch * rows;
873 ANGLE_TRY_CHECKED_MATH(depthPitch);
874 return depthPitch.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000875}
876
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700877gl::ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
878 const gl::Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000879{
Jamie Madill513558d2016-06-02 13:04:11 -0400880 CheckedNumeric<GLuint> checkedWidth(size.width);
881 CheckedNumeric<GLuint> checkedHeight(size.height);
882 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700883 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
884 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400885
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700886 ASSERT(compressed);
887 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
888 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
889 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
890 ANGLE_TRY_CHECKED_MATH(bytes);
891 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000892}
893
Olli Etuaho989cac32016-06-08 16:18:49 -0700894gl::ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
895 GLuint depthPitch,
896 GLint skipImages,
897 GLint skipRows,
898 GLint skipPixels,
899 bool applySkipImages) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400900{
Olli Etuaho989cac32016-06-08 16:18:49 -0700901 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
902 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
903 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(skipImages));
904 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(skipRows));
905 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(skipPixels));
906 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
907 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
908 if (!applySkipImages)
909 {
910 checkedSkipImagesBytes = 0;
911 }
912 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
913 checkedSkipPixels * checkedPixelBytes;
914 ANGLE_TRY_CHECKED_MATH(skipBytes);
915 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400916}
917
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700918gl::ErrorOrResult<GLuint> InternalFormat::computeUnpackSize(
919 GLenum formatType,
920 const gl::Extents &size,
921 const gl::PixelUnpackState &unpack) const
922{
923 // Compressed images do not use unpack parameters.
924 if (compressed)
925 {
926 return computeCompressedImageSize(formatType, size);
927 }
928
929 base::CheckedNumeric<GLuint> checkedGroups(unpack.rowLength > 0 ? unpack.rowLength
930 : size.width);
931 base::CheckedNumeric<GLuint> checkedRows(unpack.imageHeight > 0 ? unpack.imageHeight
932 : size.height);
933
934 // Compute the groups of all the layers in (0,depth-1)
935 auto layerGroups = checkedGroups * checkedRows * (size.depth - 1);
936
937 // Compute the groups in the last layer (for non-3D textures, the only one)
938 auto lastLayerGroups = checkedGroups * (size.height - 1) + size.width;
939
940 // The total size is the sum times the bytes per pixel.
941 auto totalSize = (layerGroups + lastLayerGroups) * pixelBytes;
942
943 ANGLE_TRY_CHECKED_MATH(totalSize);
944
945 return totalSize.ValueOrDie();
946}
947
Geoff Lang5d601382014-07-22 15:14:06 -0400948GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000949{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700950 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500951 if (formatInfo.pixelBytes > 0)
952 {
953 return internalFormat;
954 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400955 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000956}
957
Geoff Lange4a492b2014-06-19 14:14:41 -0400958const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400959{
Geoff Lange4a492b2014-06-19 14:14:41 -0400960 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400961 return formatSet;
962}
963
Jamie Madill09e2d932015-07-14 16:40:31 -0400964AttributeType GetAttributeType(GLenum enumValue)
965{
966 switch (enumValue)
967 {
968 case GL_FLOAT:
969 return ATTRIBUTE_FLOAT;
970 case GL_FLOAT_VEC2:
971 return ATTRIBUTE_VEC2;
972 case GL_FLOAT_VEC3:
973 return ATTRIBUTE_VEC3;
974 case GL_FLOAT_VEC4:
975 return ATTRIBUTE_VEC4;
976 case GL_INT:
977 return ATTRIBUTE_INT;
978 case GL_INT_VEC2:
979 return ATTRIBUTE_IVEC2;
980 case GL_INT_VEC3:
981 return ATTRIBUTE_IVEC3;
982 case GL_INT_VEC4:
983 return ATTRIBUTE_IVEC4;
984 case GL_UNSIGNED_INT:
985 return ATTRIBUTE_UINT;
986 case GL_UNSIGNED_INT_VEC2:
987 return ATTRIBUTE_UVEC2;
988 case GL_UNSIGNED_INT_VEC3:
989 return ATTRIBUTE_UVEC3;
990 case GL_UNSIGNED_INT_VEC4:
991 return ATTRIBUTE_UVEC4;
992 case GL_FLOAT_MAT2:
993 return ATTRIBUTE_MAT2;
994 case GL_FLOAT_MAT3:
995 return ATTRIBUTE_MAT3;
996 case GL_FLOAT_MAT4:
997 return ATTRIBUTE_MAT4;
998 case GL_FLOAT_MAT2x3:
999 return ATTRIBUTE_MAT2x3;
1000 case GL_FLOAT_MAT2x4:
1001 return ATTRIBUTE_MAT2x4;
1002 case GL_FLOAT_MAT3x2:
1003 return ATTRIBUTE_MAT3x2;
1004 case GL_FLOAT_MAT3x4:
1005 return ATTRIBUTE_MAT3x4;
1006 case GL_FLOAT_MAT4x2:
1007 return ATTRIBUTE_MAT4x2;
1008 case GL_FLOAT_MAT4x3:
1009 return ATTRIBUTE_MAT4x3;
1010 default:
1011 UNREACHABLE();
1012 return ATTRIBUTE_FLOAT;
1013 }
1014}
1015
Jamie Madilld3dfda22015-07-06 08:28:49 -04001016VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1017{
1018 switch (type)
1019 {
1020 case GL_BYTE:
1021 switch (components)
1022 {
1023 case 1:
1024 if (pureInteger)
1025 return VERTEX_FORMAT_SBYTE1_INT;
1026 if (normalized)
1027 return VERTEX_FORMAT_SBYTE1_NORM;
1028 return VERTEX_FORMAT_SBYTE1;
1029 case 2:
1030 if (pureInteger)
1031 return VERTEX_FORMAT_SBYTE2_INT;
1032 if (normalized)
1033 return VERTEX_FORMAT_SBYTE2_NORM;
1034 return VERTEX_FORMAT_SBYTE2;
1035 case 3:
1036 if (pureInteger)
1037 return VERTEX_FORMAT_SBYTE3_INT;
1038 if (normalized)
1039 return VERTEX_FORMAT_SBYTE3_NORM;
1040 return VERTEX_FORMAT_SBYTE3;
1041 case 4:
1042 if (pureInteger)
1043 return VERTEX_FORMAT_SBYTE4_INT;
1044 if (normalized)
1045 return VERTEX_FORMAT_SBYTE4_NORM;
1046 return VERTEX_FORMAT_SBYTE4;
1047 default:
1048 UNREACHABLE();
1049 break;
1050 }
1051 case GL_UNSIGNED_BYTE:
1052 switch (components)
1053 {
1054 case 1:
1055 if (pureInteger)
1056 return VERTEX_FORMAT_UBYTE1_INT;
1057 if (normalized)
1058 return VERTEX_FORMAT_UBYTE1_NORM;
1059 return VERTEX_FORMAT_UBYTE1;
1060 case 2:
1061 if (pureInteger)
1062 return VERTEX_FORMAT_UBYTE2_INT;
1063 if (normalized)
1064 return VERTEX_FORMAT_UBYTE2_NORM;
1065 return VERTEX_FORMAT_UBYTE2;
1066 case 3:
1067 if (pureInteger)
1068 return VERTEX_FORMAT_UBYTE3_INT;
1069 if (normalized)
1070 return VERTEX_FORMAT_UBYTE3_NORM;
1071 return VERTEX_FORMAT_UBYTE3;
1072 case 4:
1073 if (pureInteger)
1074 return VERTEX_FORMAT_UBYTE4_INT;
1075 if (normalized)
1076 return VERTEX_FORMAT_UBYTE4_NORM;
1077 return VERTEX_FORMAT_UBYTE4;
1078 default:
1079 UNREACHABLE();
1080 break;
1081 }
1082 case GL_SHORT:
1083 switch (components)
1084 {
1085 case 1:
1086 if (pureInteger)
1087 return VERTEX_FORMAT_SSHORT1_INT;
1088 if (normalized)
1089 return VERTEX_FORMAT_SSHORT1_NORM;
1090 return VERTEX_FORMAT_SSHORT1;
1091 case 2:
1092 if (pureInteger)
1093 return VERTEX_FORMAT_SSHORT2_INT;
1094 if (normalized)
1095 return VERTEX_FORMAT_SSHORT2_NORM;
1096 return VERTEX_FORMAT_SSHORT2;
1097 case 3:
1098 if (pureInteger)
1099 return VERTEX_FORMAT_SSHORT3_INT;
1100 if (normalized)
1101 return VERTEX_FORMAT_SSHORT3_NORM;
1102 return VERTEX_FORMAT_SSHORT3;
1103 case 4:
1104 if (pureInteger)
1105 return VERTEX_FORMAT_SSHORT4_INT;
1106 if (normalized)
1107 return VERTEX_FORMAT_SSHORT4_NORM;
1108 return VERTEX_FORMAT_SSHORT4;
1109 default:
1110 UNREACHABLE();
1111 break;
1112 }
1113 case GL_UNSIGNED_SHORT:
1114 switch (components)
1115 {
1116 case 1:
1117 if (pureInteger)
1118 return VERTEX_FORMAT_USHORT1_INT;
1119 if (normalized)
1120 return VERTEX_FORMAT_USHORT1_NORM;
1121 return VERTEX_FORMAT_USHORT1;
1122 case 2:
1123 if (pureInteger)
1124 return VERTEX_FORMAT_USHORT2_INT;
1125 if (normalized)
1126 return VERTEX_FORMAT_USHORT2_NORM;
1127 return VERTEX_FORMAT_USHORT2;
1128 case 3:
1129 if (pureInteger)
1130 return VERTEX_FORMAT_USHORT3_INT;
1131 if (normalized)
1132 return VERTEX_FORMAT_USHORT3_NORM;
1133 return VERTEX_FORMAT_USHORT3;
1134 case 4:
1135 if (pureInteger)
1136 return VERTEX_FORMAT_USHORT4_INT;
1137 if (normalized)
1138 return VERTEX_FORMAT_USHORT4_NORM;
1139 return VERTEX_FORMAT_USHORT4;
1140 default:
1141 UNREACHABLE();
1142 break;
1143 }
1144 case GL_INT:
1145 switch (components)
1146 {
1147 case 1:
1148 if (pureInteger)
1149 return VERTEX_FORMAT_SINT1_INT;
1150 if (normalized)
1151 return VERTEX_FORMAT_SINT1_NORM;
1152 return VERTEX_FORMAT_SINT1;
1153 case 2:
1154 if (pureInteger)
1155 return VERTEX_FORMAT_SINT2_INT;
1156 if (normalized)
1157 return VERTEX_FORMAT_SINT2_NORM;
1158 return VERTEX_FORMAT_SINT2;
1159 case 3:
1160 if (pureInteger)
1161 return VERTEX_FORMAT_SINT3_INT;
1162 if (normalized)
1163 return VERTEX_FORMAT_SINT3_NORM;
1164 return VERTEX_FORMAT_SINT3;
1165 case 4:
1166 if (pureInteger)
1167 return VERTEX_FORMAT_SINT4_INT;
1168 if (normalized)
1169 return VERTEX_FORMAT_SINT4_NORM;
1170 return VERTEX_FORMAT_SINT4;
1171 default:
1172 UNREACHABLE();
1173 break;
1174 }
1175 case GL_UNSIGNED_INT:
1176 switch (components)
1177 {
1178 case 1:
1179 if (pureInteger)
1180 return VERTEX_FORMAT_UINT1_INT;
1181 if (normalized)
1182 return VERTEX_FORMAT_UINT1_NORM;
1183 return VERTEX_FORMAT_UINT1;
1184 case 2:
1185 if (pureInteger)
1186 return VERTEX_FORMAT_UINT2_INT;
1187 if (normalized)
1188 return VERTEX_FORMAT_UINT2_NORM;
1189 return VERTEX_FORMAT_UINT2;
1190 case 3:
1191 if (pureInteger)
1192 return VERTEX_FORMAT_UINT3_INT;
1193 if (normalized)
1194 return VERTEX_FORMAT_UINT3_NORM;
1195 return VERTEX_FORMAT_UINT3;
1196 case 4:
1197 if (pureInteger)
1198 return VERTEX_FORMAT_UINT4_INT;
1199 if (normalized)
1200 return VERTEX_FORMAT_UINT4_NORM;
1201 return VERTEX_FORMAT_UINT4;
1202 default:
1203 UNREACHABLE();
1204 break;
1205 }
1206 case GL_FLOAT:
1207 switch (components)
1208 {
1209 case 1:
1210 return VERTEX_FORMAT_FLOAT1;
1211 case 2:
1212 return VERTEX_FORMAT_FLOAT2;
1213 case 3:
1214 return VERTEX_FORMAT_FLOAT3;
1215 case 4:
1216 return VERTEX_FORMAT_FLOAT4;
1217 default:
1218 UNREACHABLE();
1219 break;
1220 }
1221 case GL_HALF_FLOAT:
1222 switch (components)
1223 {
1224 case 1:
1225 return VERTEX_FORMAT_HALF1;
1226 case 2:
1227 return VERTEX_FORMAT_HALF2;
1228 case 3:
1229 return VERTEX_FORMAT_HALF3;
1230 case 4:
1231 return VERTEX_FORMAT_HALF4;
1232 default:
1233 UNREACHABLE();
1234 break;
1235 }
1236 case GL_FIXED:
1237 switch (components)
1238 {
1239 case 1:
1240 return VERTEX_FORMAT_FIXED1;
1241 case 2:
1242 return VERTEX_FORMAT_FIXED2;
1243 case 3:
1244 return VERTEX_FORMAT_FIXED3;
1245 case 4:
1246 return VERTEX_FORMAT_FIXED4;
1247 default:
1248 UNREACHABLE();
1249 break;
1250 }
1251 case GL_INT_2_10_10_10_REV:
1252 if (pureInteger)
1253 return VERTEX_FORMAT_SINT210_INT;
1254 if (normalized)
1255 return VERTEX_FORMAT_SINT210_NORM;
1256 return VERTEX_FORMAT_SINT210;
1257 case GL_UNSIGNED_INT_2_10_10_10_REV:
1258 if (pureInteger)
1259 return VERTEX_FORMAT_UINT210_INT;
1260 if (normalized)
1261 return VERTEX_FORMAT_UINT210_NORM;
1262 return VERTEX_FORMAT_UINT210;
1263 default:
1264 UNREACHABLE();
1265 break;
1266 }
1267 return VERTEX_FORMAT_UBYTE1;
1268}
1269
1270VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1271{
1272 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1273}
1274
1275VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1276{
1277 if (!attrib.enabled)
1278 {
1279 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1280 }
1281 return GetVertexFormatType(attrib);
1282}
1283
1284const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1285{
1286 switch (vertexFormatType)
1287 {
1288 case VERTEX_FORMAT_SBYTE1:
1289 {
1290 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1291 return format;
1292 }
1293 case VERTEX_FORMAT_SBYTE1_NORM:
1294 {
1295 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1296 return format;
1297 }
1298 case VERTEX_FORMAT_SBYTE2:
1299 {
1300 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1301 return format;
1302 }
1303 case VERTEX_FORMAT_SBYTE2_NORM:
1304 {
1305 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1306 return format;
1307 }
1308 case VERTEX_FORMAT_SBYTE3:
1309 {
1310 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1311 return format;
1312 }
1313 case VERTEX_FORMAT_SBYTE3_NORM:
1314 {
1315 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1316 return format;
1317 }
1318 case VERTEX_FORMAT_SBYTE4:
1319 {
1320 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1321 return format;
1322 }
1323 case VERTEX_FORMAT_SBYTE4_NORM:
1324 {
1325 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1326 return format;
1327 }
1328 case VERTEX_FORMAT_UBYTE1:
1329 {
1330 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1331 return format;
1332 }
1333 case VERTEX_FORMAT_UBYTE1_NORM:
1334 {
1335 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1336 return format;
1337 }
1338 case VERTEX_FORMAT_UBYTE2:
1339 {
1340 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1341 return format;
1342 }
1343 case VERTEX_FORMAT_UBYTE2_NORM:
1344 {
1345 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1346 return format;
1347 }
1348 case VERTEX_FORMAT_UBYTE3:
1349 {
1350 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1351 return format;
1352 }
1353 case VERTEX_FORMAT_UBYTE3_NORM:
1354 {
1355 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1356 return format;
1357 }
1358 case VERTEX_FORMAT_UBYTE4:
1359 {
1360 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1361 return format;
1362 }
1363 case VERTEX_FORMAT_UBYTE4_NORM:
1364 {
1365 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1366 return format;
1367 }
1368 case VERTEX_FORMAT_SSHORT1:
1369 {
1370 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1371 return format;
1372 }
1373 case VERTEX_FORMAT_SSHORT1_NORM:
1374 {
1375 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1376 return format;
1377 }
1378 case VERTEX_FORMAT_SSHORT2:
1379 {
1380 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1381 return format;
1382 }
1383 case VERTEX_FORMAT_SSHORT2_NORM:
1384 {
1385 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1386 return format;
1387 }
1388 case VERTEX_FORMAT_SSHORT3:
1389 {
1390 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1391 return format;
1392 }
1393 case VERTEX_FORMAT_SSHORT3_NORM:
1394 {
1395 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1396 return format;
1397 }
1398 case VERTEX_FORMAT_SSHORT4:
1399 {
1400 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1401 return format;
1402 }
1403 case VERTEX_FORMAT_SSHORT4_NORM:
1404 {
1405 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1406 return format;
1407 }
1408 case VERTEX_FORMAT_USHORT1:
1409 {
1410 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1411 return format;
1412 }
1413 case VERTEX_FORMAT_USHORT1_NORM:
1414 {
1415 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1416 return format;
1417 }
1418 case VERTEX_FORMAT_USHORT2:
1419 {
1420 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1421 return format;
1422 }
1423 case VERTEX_FORMAT_USHORT2_NORM:
1424 {
1425 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1426 return format;
1427 }
1428 case VERTEX_FORMAT_USHORT3:
1429 {
1430 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1431 return format;
1432 }
1433 case VERTEX_FORMAT_USHORT3_NORM:
1434 {
1435 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1436 return format;
1437 }
1438 case VERTEX_FORMAT_USHORT4:
1439 {
1440 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1441 return format;
1442 }
1443 case VERTEX_FORMAT_USHORT4_NORM:
1444 {
1445 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1446 return format;
1447 }
1448 case VERTEX_FORMAT_SINT1:
1449 {
1450 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1451 return format;
1452 }
1453 case VERTEX_FORMAT_SINT1_NORM:
1454 {
1455 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1456 return format;
1457 }
1458 case VERTEX_FORMAT_SINT2:
1459 {
1460 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1461 return format;
1462 }
1463 case VERTEX_FORMAT_SINT2_NORM:
1464 {
1465 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1466 return format;
1467 }
1468 case VERTEX_FORMAT_SINT3:
1469 {
1470 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1471 return format;
1472 }
1473 case VERTEX_FORMAT_SINT3_NORM:
1474 {
1475 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1476 return format;
1477 }
1478 case VERTEX_FORMAT_SINT4:
1479 {
1480 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1481 return format;
1482 }
1483 case VERTEX_FORMAT_SINT4_NORM:
1484 {
1485 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1486 return format;
1487 }
1488 case VERTEX_FORMAT_UINT1:
1489 {
1490 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1491 return format;
1492 }
1493 case VERTEX_FORMAT_UINT1_NORM:
1494 {
1495 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1496 return format;
1497 }
1498 case VERTEX_FORMAT_UINT2:
1499 {
1500 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1501 return format;
1502 }
1503 case VERTEX_FORMAT_UINT2_NORM:
1504 {
1505 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1506 return format;
1507 }
1508 case VERTEX_FORMAT_UINT3:
1509 {
1510 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1511 return format;
1512 }
1513 case VERTEX_FORMAT_UINT3_NORM:
1514 {
1515 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1516 return format;
1517 }
1518 case VERTEX_FORMAT_UINT4:
1519 {
1520 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1521 return format;
1522 }
1523 case VERTEX_FORMAT_UINT4_NORM:
1524 {
1525 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1526 return format;
1527 }
1528 case VERTEX_FORMAT_SBYTE1_INT:
1529 {
1530 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1531 return format;
1532 }
1533 case VERTEX_FORMAT_SBYTE2_INT:
1534 {
1535 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1536 return format;
1537 }
1538 case VERTEX_FORMAT_SBYTE3_INT:
1539 {
1540 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1541 return format;
1542 }
1543 case VERTEX_FORMAT_SBYTE4_INT:
1544 {
1545 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1546 return format;
1547 }
1548 case VERTEX_FORMAT_UBYTE1_INT:
1549 {
1550 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1551 return format;
1552 }
1553 case VERTEX_FORMAT_UBYTE2_INT:
1554 {
1555 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1556 return format;
1557 }
1558 case VERTEX_FORMAT_UBYTE3_INT:
1559 {
1560 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1561 return format;
1562 }
1563 case VERTEX_FORMAT_UBYTE4_INT:
1564 {
1565 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1566 return format;
1567 }
1568 case VERTEX_FORMAT_SSHORT1_INT:
1569 {
1570 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1571 return format;
1572 }
1573 case VERTEX_FORMAT_SSHORT2_INT:
1574 {
1575 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1576 return format;
1577 }
1578 case VERTEX_FORMAT_SSHORT3_INT:
1579 {
1580 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1581 return format;
1582 }
1583 case VERTEX_FORMAT_SSHORT4_INT:
1584 {
1585 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1586 return format;
1587 }
1588 case VERTEX_FORMAT_USHORT1_INT:
1589 {
1590 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1591 return format;
1592 }
1593 case VERTEX_FORMAT_USHORT2_INT:
1594 {
1595 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1596 return format;
1597 }
1598 case VERTEX_FORMAT_USHORT3_INT:
1599 {
1600 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1601 return format;
1602 }
1603 case VERTEX_FORMAT_USHORT4_INT:
1604 {
1605 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1606 return format;
1607 }
1608 case VERTEX_FORMAT_SINT1_INT:
1609 {
1610 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1611 return format;
1612 }
1613 case VERTEX_FORMAT_SINT2_INT:
1614 {
1615 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1616 return format;
1617 }
1618 case VERTEX_FORMAT_SINT3_INT:
1619 {
1620 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1621 return format;
1622 }
1623 case VERTEX_FORMAT_SINT4_INT:
1624 {
1625 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1626 return format;
1627 }
1628 case VERTEX_FORMAT_UINT1_INT:
1629 {
1630 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1631 return format;
1632 }
1633 case VERTEX_FORMAT_UINT2_INT:
1634 {
1635 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1636 return format;
1637 }
1638 case VERTEX_FORMAT_UINT3_INT:
1639 {
1640 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1641 return format;
1642 }
1643 case VERTEX_FORMAT_UINT4_INT:
1644 {
1645 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1646 return format;
1647 }
1648 case VERTEX_FORMAT_FIXED1:
1649 {
1650 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1651 return format;
1652 }
1653 case VERTEX_FORMAT_FIXED2:
1654 {
1655 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1656 return format;
1657 }
1658 case VERTEX_FORMAT_FIXED3:
1659 {
1660 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1661 return format;
1662 }
1663 case VERTEX_FORMAT_FIXED4:
1664 {
1665 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1666 return format;
1667 }
1668 case VERTEX_FORMAT_HALF1:
1669 {
1670 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1671 return format;
1672 }
1673 case VERTEX_FORMAT_HALF2:
1674 {
1675 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1676 return format;
1677 }
1678 case VERTEX_FORMAT_HALF3:
1679 {
1680 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1681 return format;
1682 }
1683 case VERTEX_FORMAT_HALF4:
1684 {
1685 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1686 return format;
1687 }
1688 case VERTEX_FORMAT_FLOAT1:
1689 {
1690 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1691 return format;
1692 }
1693 case VERTEX_FORMAT_FLOAT2:
1694 {
1695 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1696 return format;
1697 }
1698 case VERTEX_FORMAT_FLOAT3:
1699 {
1700 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1701 return format;
1702 }
1703 case VERTEX_FORMAT_FLOAT4:
1704 {
1705 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1706 return format;
1707 }
1708 case VERTEX_FORMAT_SINT210:
1709 {
1710 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1711 return format;
1712 }
1713 case VERTEX_FORMAT_UINT210:
1714 {
1715 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1716 return format;
1717 }
1718 case VERTEX_FORMAT_SINT210_NORM:
1719 {
1720 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1721 return format;
1722 }
1723 case VERTEX_FORMAT_UINT210_NORM:
1724 {
1725 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1726 return format;
1727 }
1728 case VERTEX_FORMAT_SINT210_INT:
1729 {
1730 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1731 return format;
1732 }
1733 case VERTEX_FORMAT_UINT210_INT:
1734 {
1735 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1736 return format;
1737 }
1738 default:
1739 {
1740 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1741 return format;
1742 }
1743 }
1744}
1745
1746VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1747 : type(typeIn),
1748 normalized(normalizedIn),
1749 components(componentsIn),
1750 pureInteger(pureIntegerIn)
1751{
1752 // float -> !normalized
1753 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1754}
1755
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001756}