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