blob: 67977bcce6a743ea49e031d418b79fc57e5fdbbb [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 Wallez0e487192016-10-03 16:30:38 -0400883ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
884 GLint imageHeight,
885 GLuint rowPitch) const
886{
887 GLuint rows =
888 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
889 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
890
891 auto depthPitch = checkedRowPitch * rows;
892 ANGLE_TRY_CHECKED_MATH(depthPitch);
893 return depthPitch.ValueOrDie();
894}
895
Corentin Wallez886de362016-09-27 10:49:35 -0400896ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400897 GLsizei width,
898 GLsizei height,
899 GLint alignment,
900 GLint rowLength,
901 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000902{
Jamie Madille2e406c2016-06-02 13:04:10 -0400903 GLuint rowPitch = 0;
904 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400905 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000906}
907
Corentin Wallez886de362016-09-27 10:49:35 -0400908ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
909 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000910{
Jamie Madill513558d2016-06-02 13:04:11 -0400911 CheckedNumeric<GLuint> checkedWidth(size.width);
912 CheckedNumeric<GLuint> checkedHeight(size.height);
913 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700914 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
915 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400916
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700917 ASSERT(compressed);
918 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
919 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
920 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
921 ANGLE_TRY_CHECKED_MATH(bytes);
922 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923}
924
Corentin Wallez886de362016-09-27 10:49:35 -0400925ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700926 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400927 const PixelStoreStateBase &state,
928 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400929{
Olli Etuaho989cac32016-06-08 16:18:49 -0700930 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
931 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400932 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
933 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
934 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700935 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
936 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400937 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700938 {
939 checkedSkipImagesBytes = 0;
940 }
941 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
942 checkedSkipPixels * checkedPixelBytes;
943 ANGLE_TRY_CHECKED_MATH(skipBytes);
944 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400945}
946
Corentin Wallez886de362016-09-27 10:49:35 -0400947ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
948 GLenum formatType,
949 const Extents &size,
950 const PixelStoreStateBase &state,
951 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400952{
Corentin Wallez886de362016-09-27 10:49:35 -0400953 GLuint rowPitch = 0;
954 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400955 rowPitch);
956
Corentin Wallez0e487192016-10-03 16:30:38 -0400957 GLuint depthPitch = 0;
958 if (is3D)
959 {
960 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
961 }
962
Corentin Wallez886de362016-09-27 10:49:35 -0400963 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700964 if (compressed)
965 {
Corentin Wallez886de362016-09-27 10:49:35 -0400966 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700967 }
Corentin Wallez886de362016-09-27 10:49:35 -0400968 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400969 {
Corentin Wallez886de362016-09-27 10:49:35 -0400970 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
971 checkedCopyBytes += size.width * bytes;
972
973 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
974 checkedCopyBytes += heightMinusOne * rowPitch;
975
976 if (is3D)
977 {
978 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
979 checkedCopyBytes += depthMinusOne * depthPitch;
980 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400981 }
982
Corentin Wallez886de362016-09-27 10:49:35 -0400983 CheckedNumeric<GLuint> checkedSkipBytes = 0;
984 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400985
986 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
987
988 ANGLE_TRY_CHECKED_MATH(endByte);
989 return endByte.ValueOrDie();
990}
991
Geoff Lang5d601382014-07-22 15:14:06 -0400992GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000993{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700994 const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat);
Geoff Lang051dbc72015-01-05 15:48:58 -0500995 if (formatInfo.pixelBytes > 0)
996 {
997 return internalFormat;
998 }
Jamie Madilla3944d42016-07-22 22:13:26 -0400999 return GetSizedFormatInternal(internalFormat, type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001000}
1001
Geoff Lange4a492b2014-06-19 14:14:41 -04001002const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001003{
Geoff Lange4a492b2014-06-19 14:14:41 -04001004 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001005 return formatSet;
1006}
1007
Jamie Madill09e2d932015-07-14 16:40:31 -04001008AttributeType GetAttributeType(GLenum enumValue)
1009{
1010 switch (enumValue)
1011 {
1012 case GL_FLOAT:
1013 return ATTRIBUTE_FLOAT;
1014 case GL_FLOAT_VEC2:
1015 return ATTRIBUTE_VEC2;
1016 case GL_FLOAT_VEC3:
1017 return ATTRIBUTE_VEC3;
1018 case GL_FLOAT_VEC4:
1019 return ATTRIBUTE_VEC4;
1020 case GL_INT:
1021 return ATTRIBUTE_INT;
1022 case GL_INT_VEC2:
1023 return ATTRIBUTE_IVEC2;
1024 case GL_INT_VEC3:
1025 return ATTRIBUTE_IVEC3;
1026 case GL_INT_VEC4:
1027 return ATTRIBUTE_IVEC4;
1028 case GL_UNSIGNED_INT:
1029 return ATTRIBUTE_UINT;
1030 case GL_UNSIGNED_INT_VEC2:
1031 return ATTRIBUTE_UVEC2;
1032 case GL_UNSIGNED_INT_VEC3:
1033 return ATTRIBUTE_UVEC3;
1034 case GL_UNSIGNED_INT_VEC4:
1035 return ATTRIBUTE_UVEC4;
1036 case GL_FLOAT_MAT2:
1037 return ATTRIBUTE_MAT2;
1038 case GL_FLOAT_MAT3:
1039 return ATTRIBUTE_MAT3;
1040 case GL_FLOAT_MAT4:
1041 return ATTRIBUTE_MAT4;
1042 case GL_FLOAT_MAT2x3:
1043 return ATTRIBUTE_MAT2x3;
1044 case GL_FLOAT_MAT2x4:
1045 return ATTRIBUTE_MAT2x4;
1046 case GL_FLOAT_MAT3x2:
1047 return ATTRIBUTE_MAT3x2;
1048 case GL_FLOAT_MAT3x4:
1049 return ATTRIBUTE_MAT3x4;
1050 case GL_FLOAT_MAT4x2:
1051 return ATTRIBUTE_MAT4x2;
1052 case GL_FLOAT_MAT4x3:
1053 return ATTRIBUTE_MAT4x3;
1054 default:
1055 UNREACHABLE();
1056 return ATTRIBUTE_FLOAT;
1057 }
1058}
1059
Jamie Madilld3dfda22015-07-06 08:28:49 -04001060VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1061{
1062 switch (type)
1063 {
1064 case GL_BYTE:
1065 switch (components)
1066 {
1067 case 1:
1068 if (pureInteger)
1069 return VERTEX_FORMAT_SBYTE1_INT;
1070 if (normalized)
1071 return VERTEX_FORMAT_SBYTE1_NORM;
1072 return VERTEX_FORMAT_SBYTE1;
1073 case 2:
1074 if (pureInteger)
1075 return VERTEX_FORMAT_SBYTE2_INT;
1076 if (normalized)
1077 return VERTEX_FORMAT_SBYTE2_NORM;
1078 return VERTEX_FORMAT_SBYTE2;
1079 case 3:
1080 if (pureInteger)
1081 return VERTEX_FORMAT_SBYTE3_INT;
1082 if (normalized)
1083 return VERTEX_FORMAT_SBYTE3_NORM;
1084 return VERTEX_FORMAT_SBYTE3;
1085 case 4:
1086 if (pureInteger)
1087 return VERTEX_FORMAT_SBYTE4_INT;
1088 if (normalized)
1089 return VERTEX_FORMAT_SBYTE4_NORM;
1090 return VERTEX_FORMAT_SBYTE4;
1091 default:
1092 UNREACHABLE();
1093 break;
1094 }
1095 case GL_UNSIGNED_BYTE:
1096 switch (components)
1097 {
1098 case 1:
1099 if (pureInteger)
1100 return VERTEX_FORMAT_UBYTE1_INT;
1101 if (normalized)
1102 return VERTEX_FORMAT_UBYTE1_NORM;
1103 return VERTEX_FORMAT_UBYTE1;
1104 case 2:
1105 if (pureInteger)
1106 return VERTEX_FORMAT_UBYTE2_INT;
1107 if (normalized)
1108 return VERTEX_FORMAT_UBYTE2_NORM;
1109 return VERTEX_FORMAT_UBYTE2;
1110 case 3:
1111 if (pureInteger)
1112 return VERTEX_FORMAT_UBYTE3_INT;
1113 if (normalized)
1114 return VERTEX_FORMAT_UBYTE3_NORM;
1115 return VERTEX_FORMAT_UBYTE3;
1116 case 4:
1117 if (pureInteger)
1118 return VERTEX_FORMAT_UBYTE4_INT;
1119 if (normalized)
1120 return VERTEX_FORMAT_UBYTE4_NORM;
1121 return VERTEX_FORMAT_UBYTE4;
1122 default:
1123 UNREACHABLE();
1124 break;
1125 }
1126 case GL_SHORT:
1127 switch (components)
1128 {
1129 case 1:
1130 if (pureInteger)
1131 return VERTEX_FORMAT_SSHORT1_INT;
1132 if (normalized)
1133 return VERTEX_FORMAT_SSHORT1_NORM;
1134 return VERTEX_FORMAT_SSHORT1;
1135 case 2:
1136 if (pureInteger)
1137 return VERTEX_FORMAT_SSHORT2_INT;
1138 if (normalized)
1139 return VERTEX_FORMAT_SSHORT2_NORM;
1140 return VERTEX_FORMAT_SSHORT2;
1141 case 3:
1142 if (pureInteger)
1143 return VERTEX_FORMAT_SSHORT3_INT;
1144 if (normalized)
1145 return VERTEX_FORMAT_SSHORT3_NORM;
1146 return VERTEX_FORMAT_SSHORT3;
1147 case 4:
1148 if (pureInteger)
1149 return VERTEX_FORMAT_SSHORT4_INT;
1150 if (normalized)
1151 return VERTEX_FORMAT_SSHORT4_NORM;
1152 return VERTEX_FORMAT_SSHORT4;
1153 default:
1154 UNREACHABLE();
1155 break;
1156 }
1157 case GL_UNSIGNED_SHORT:
1158 switch (components)
1159 {
1160 case 1:
1161 if (pureInteger)
1162 return VERTEX_FORMAT_USHORT1_INT;
1163 if (normalized)
1164 return VERTEX_FORMAT_USHORT1_NORM;
1165 return VERTEX_FORMAT_USHORT1;
1166 case 2:
1167 if (pureInteger)
1168 return VERTEX_FORMAT_USHORT2_INT;
1169 if (normalized)
1170 return VERTEX_FORMAT_USHORT2_NORM;
1171 return VERTEX_FORMAT_USHORT2;
1172 case 3:
1173 if (pureInteger)
1174 return VERTEX_FORMAT_USHORT3_INT;
1175 if (normalized)
1176 return VERTEX_FORMAT_USHORT3_NORM;
1177 return VERTEX_FORMAT_USHORT3;
1178 case 4:
1179 if (pureInteger)
1180 return VERTEX_FORMAT_USHORT4_INT;
1181 if (normalized)
1182 return VERTEX_FORMAT_USHORT4_NORM;
1183 return VERTEX_FORMAT_USHORT4;
1184 default:
1185 UNREACHABLE();
1186 break;
1187 }
1188 case GL_INT:
1189 switch (components)
1190 {
1191 case 1:
1192 if (pureInteger)
1193 return VERTEX_FORMAT_SINT1_INT;
1194 if (normalized)
1195 return VERTEX_FORMAT_SINT1_NORM;
1196 return VERTEX_FORMAT_SINT1;
1197 case 2:
1198 if (pureInteger)
1199 return VERTEX_FORMAT_SINT2_INT;
1200 if (normalized)
1201 return VERTEX_FORMAT_SINT2_NORM;
1202 return VERTEX_FORMAT_SINT2;
1203 case 3:
1204 if (pureInteger)
1205 return VERTEX_FORMAT_SINT3_INT;
1206 if (normalized)
1207 return VERTEX_FORMAT_SINT3_NORM;
1208 return VERTEX_FORMAT_SINT3;
1209 case 4:
1210 if (pureInteger)
1211 return VERTEX_FORMAT_SINT4_INT;
1212 if (normalized)
1213 return VERTEX_FORMAT_SINT4_NORM;
1214 return VERTEX_FORMAT_SINT4;
1215 default:
1216 UNREACHABLE();
1217 break;
1218 }
1219 case GL_UNSIGNED_INT:
1220 switch (components)
1221 {
1222 case 1:
1223 if (pureInteger)
1224 return VERTEX_FORMAT_UINT1_INT;
1225 if (normalized)
1226 return VERTEX_FORMAT_UINT1_NORM;
1227 return VERTEX_FORMAT_UINT1;
1228 case 2:
1229 if (pureInteger)
1230 return VERTEX_FORMAT_UINT2_INT;
1231 if (normalized)
1232 return VERTEX_FORMAT_UINT2_NORM;
1233 return VERTEX_FORMAT_UINT2;
1234 case 3:
1235 if (pureInteger)
1236 return VERTEX_FORMAT_UINT3_INT;
1237 if (normalized)
1238 return VERTEX_FORMAT_UINT3_NORM;
1239 return VERTEX_FORMAT_UINT3;
1240 case 4:
1241 if (pureInteger)
1242 return VERTEX_FORMAT_UINT4_INT;
1243 if (normalized)
1244 return VERTEX_FORMAT_UINT4_NORM;
1245 return VERTEX_FORMAT_UINT4;
1246 default:
1247 UNREACHABLE();
1248 break;
1249 }
1250 case GL_FLOAT:
1251 switch (components)
1252 {
1253 case 1:
1254 return VERTEX_FORMAT_FLOAT1;
1255 case 2:
1256 return VERTEX_FORMAT_FLOAT2;
1257 case 3:
1258 return VERTEX_FORMAT_FLOAT3;
1259 case 4:
1260 return VERTEX_FORMAT_FLOAT4;
1261 default:
1262 UNREACHABLE();
1263 break;
1264 }
1265 case GL_HALF_FLOAT:
1266 switch (components)
1267 {
1268 case 1:
1269 return VERTEX_FORMAT_HALF1;
1270 case 2:
1271 return VERTEX_FORMAT_HALF2;
1272 case 3:
1273 return VERTEX_FORMAT_HALF3;
1274 case 4:
1275 return VERTEX_FORMAT_HALF4;
1276 default:
1277 UNREACHABLE();
1278 break;
1279 }
1280 case GL_FIXED:
1281 switch (components)
1282 {
1283 case 1:
1284 return VERTEX_FORMAT_FIXED1;
1285 case 2:
1286 return VERTEX_FORMAT_FIXED2;
1287 case 3:
1288 return VERTEX_FORMAT_FIXED3;
1289 case 4:
1290 return VERTEX_FORMAT_FIXED4;
1291 default:
1292 UNREACHABLE();
1293 break;
1294 }
1295 case GL_INT_2_10_10_10_REV:
1296 if (pureInteger)
1297 return VERTEX_FORMAT_SINT210_INT;
1298 if (normalized)
1299 return VERTEX_FORMAT_SINT210_NORM;
1300 return VERTEX_FORMAT_SINT210;
1301 case GL_UNSIGNED_INT_2_10_10_10_REV:
1302 if (pureInteger)
1303 return VERTEX_FORMAT_UINT210_INT;
1304 if (normalized)
1305 return VERTEX_FORMAT_UINT210_NORM;
1306 return VERTEX_FORMAT_UINT210;
1307 default:
1308 UNREACHABLE();
1309 break;
1310 }
1311 return VERTEX_FORMAT_UBYTE1;
1312}
1313
1314VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1315{
1316 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1317}
1318
1319VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1320{
1321 if (!attrib.enabled)
1322 {
1323 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1324 }
1325 return GetVertexFormatType(attrib);
1326}
1327
1328const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1329{
1330 switch (vertexFormatType)
1331 {
1332 case VERTEX_FORMAT_SBYTE1:
1333 {
1334 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1335 return format;
1336 }
1337 case VERTEX_FORMAT_SBYTE1_NORM:
1338 {
1339 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1340 return format;
1341 }
1342 case VERTEX_FORMAT_SBYTE2:
1343 {
1344 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1345 return format;
1346 }
1347 case VERTEX_FORMAT_SBYTE2_NORM:
1348 {
1349 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1350 return format;
1351 }
1352 case VERTEX_FORMAT_SBYTE3:
1353 {
1354 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1355 return format;
1356 }
1357 case VERTEX_FORMAT_SBYTE3_NORM:
1358 {
1359 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1360 return format;
1361 }
1362 case VERTEX_FORMAT_SBYTE4:
1363 {
1364 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1365 return format;
1366 }
1367 case VERTEX_FORMAT_SBYTE4_NORM:
1368 {
1369 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1370 return format;
1371 }
1372 case VERTEX_FORMAT_UBYTE1:
1373 {
1374 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1375 return format;
1376 }
1377 case VERTEX_FORMAT_UBYTE1_NORM:
1378 {
1379 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1380 return format;
1381 }
1382 case VERTEX_FORMAT_UBYTE2:
1383 {
1384 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1385 return format;
1386 }
1387 case VERTEX_FORMAT_UBYTE2_NORM:
1388 {
1389 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1390 return format;
1391 }
1392 case VERTEX_FORMAT_UBYTE3:
1393 {
1394 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1395 return format;
1396 }
1397 case VERTEX_FORMAT_UBYTE3_NORM:
1398 {
1399 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1400 return format;
1401 }
1402 case VERTEX_FORMAT_UBYTE4:
1403 {
1404 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1405 return format;
1406 }
1407 case VERTEX_FORMAT_UBYTE4_NORM:
1408 {
1409 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1410 return format;
1411 }
1412 case VERTEX_FORMAT_SSHORT1:
1413 {
1414 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1415 return format;
1416 }
1417 case VERTEX_FORMAT_SSHORT1_NORM:
1418 {
1419 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1420 return format;
1421 }
1422 case VERTEX_FORMAT_SSHORT2:
1423 {
1424 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1425 return format;
1426 }
1427 case VERTEX_FORMAT_SSHORT2_NORM:
1428 {
1429 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1430 return format;
1431 }
1432 case VERTEX_FORMAT_SSHORT3:
1433 {
1434 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1435 return format;
1436 }
1437 case VERTEX_FORMAT_SSHORT3_NORM:
1438 {
1439 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1440 return format;
1441 }
1442 case VERTEX_FORMAT_SSHORT4:
1443 {
1444 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1445 return format;
1446 }
1447 case VERTEX_FORMAT_SSHORT4_NORM:
1448 {
1449 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1450 return format;
1451 }
1452 case VERTEX_FORMAT_USHORT1:
1453 {
1454 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1455 return format;
1456 }
1457 case VERTEX_FORMAT_USHORT1_NORM:
1458 {
1459 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1460 return format;
1461 }
1462 case VERTEX_FORMAT_USHORT2:
1463 {
1464 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1465 return format;
1466 }
1467 case VERTEX_FORMAT_USHORT2_NORM:
1468 {
1469 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1470 return format;
1471 }
1472 case VERTEX_FORMAT_USHORT3:
1473 {
1474 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1475 return format;
1476 }
1477 case VERTEX_FORMAT_USHORT3_NORM:
1478 {
1479 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1480 return format;
1481 }
1482 case VERTEX_FORMAT_USHORT4:
1483 {
1484 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1485 return format;
1486 }
1487 case VERTEX_FORMAT_USHORT4_NORM:
1488 {
1489 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1490 return format;
1491 }
1492 case VERTEX_FORMAT_SINT1:
1493 {
1494 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1495 return format;
1496 }
1497 case VERTEX_FORMAT_SINT1_NORM:
1498 {
1499 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1500 return format;
1501 }
1502 case VERTEX_FORMAT_SINT2:
1503 {
1504 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1505 return format;
1506 }
1507 case VERTEX_FORMAT_SINT2_NORM:
1508 {
1509 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1510 return format;
1511 }
1512 case VERTEX_FORMAT_SINT3:
1513 {
1514 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1515 return format;
1516 }
1517 case VERTEX_FORMAT_SINT3_NORM:
1518 {
1519 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1520 return format;
1521 }
1522 case VERTEX_FORMAT_SINT4:
1523 {
1524 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1525 return format;
1526 }
1527 case VERTEX_FORMAT_SINT4_NORM:
1528 {
1529 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1530 return format;
1531 }
1532 case VERTEX_FORMAT_UINT1:
1533 {
1534 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1535 return format;
1536 }
1537 case VERTEX_FORMAT_UINT1_NORM:
1538 {
1539 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1540 return format;
1541 }
1542 case VERTEX_FORMAT_UINT2:
1543 {
1544 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1545 return format;
1546 }
1547 case VERTEX_FORMAT_UINT2_NORM:
1548 {
1549 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1550 return format;
1551 }
1552 case VERTEX_FORMAT_UINT3:
1553 {
1554 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1555 return format;
1556 }
1557 case VERTEX_FORMAT_UINT3_NORM:
1558 {
1559 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1560 return format;
1561 }
1562 case VERTEX_FORMAT_UINT4:
1563 {
1564 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1565 return format;
1566 }
1567 case VERTEX_FORMAT_UINT4_NORM:
1568 {
1569 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1570 return format;
1571 }
1572 case VERTEX_FORMAT_SBYTE1_INT:
1573 {
1574 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1575 return format;
1576 }
1577 case VERTEX_FORMAT_SBYTE2_INT:
1578 {
1579 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1580 return format;
1581 }
1582 case VERTEX_FORMAT_SBYTE3_INT:
1583 {
1584 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1585 return format;
1586 }
1587 case VERTEX_FORMAT_SBYTE4_INT:
1588 {
1589 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1590 return format;
1591 }
1592 case VERTEX_FORMAT_UBYTE1_INT:
1593 {
1594 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1595 return format;
1596 }
1597 case VERTEX_FORMAT_UBYTE2_INT:
1598 {
1599 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1600 return format;
1601 }
1602 case VERTEX_FORMAT_UBYTE3_INT:
1603 {
1604 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1605 return format;
1606 }
1607 case VERTEX_FORMAT_UBYTE4_INT:
1608 {
1609 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1610 return format;
1611 }
1612 case VERTEX_FORMAT_SSHORT1_INT:
1613 {
1614 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1615 return format;
1616 }
1617 case VERTEX_FORMAT_SSHORT2_INT:
1618 {
1619 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1620 return format;
1621 }
1622 case VERTEX_FORMAT_SSHORT3_INT:
1623 {
1624 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1625 return format;
1626 }
1627 case VERTEX_FORMAT_SSHORT4_INT:
1628 {
1629 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1630 return format;
1631 }
1632 case VERTEX_FORMAT_USHORT1_INT:
1633 {
1634 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1635 return format;
1636 }
1637 case VERTEX_FORMAT_USHORT2_INT:
1638 {
1639 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1640 return format;
1641 }
1642 case VERTEX_FORMAT_USHORT3_INT:
1643 {
1644 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1645 return format;
1646 }
1647 case VERTEX_FORMAT_USHORT4_INT:
1648 {
1649 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1650 return format;
1651 }
1652 case VERTEX_FORMAT_SINT1_INT:
1653 {
1654 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1655 return format;
1656 }
1657 case VERTEX_FORMAT_SINT2_INT:
1658 {
1659 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1660 return format;
1661 }
1662 case VERTEX_FORMAT_SINT3_INT:
1663 {
1664 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1665 return format;
1666 }
1667 case VERTEX_FORMAT_SINT4_INT:
1668 {
1669 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1670 return format;
1671 }
1672 case VERTEX_FORMAT_UINT1_INT:
1673 {
1674 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1675 return format;
1676 }
1677 case VERTEX_FORMAT_UINT2_INT:
1678 {
1679 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1680 return format;
1681 }
1682 case VERTEX_FORMAT_UINT3_INT:
1683 {
1684 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1685 return format;
1686 }
1687 case VERTEX_FORMAT_UINT4_INT:
1688 {
1689 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1690 return format;
1691 }
1692 case VERTEX_FORMAT_FIXED1:
1693 {
1694 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1695 return format;
1696 }
1697 case VERTEX_FORMAT_FIXED2:
1698 {
1699 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1700 return format;
1701 }
1702 case VERTEX_FORMAT_FIXED3:
1703 {
1704 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1705 return format;
1706 }
1707 case VERTEX_FORMAT_FIXED4:
1708 {
1709 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1710 return format;
1711 }
1712 case VERTEX_FORMAT_HALF1:
1713 {
1714 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1715 return format;
1716 }
1717 case VERTEX_FORMAT_HALF2:
1718 {
1719 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1720 return format;
1721 }
1722 case VERTEX_FORMAT_HALF3:
1723 {
1724 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1725 return format;
1726 }
1727 case VERTEX_FORMAT_HALF4:
1728 {
1729 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1730 return format;
1731 }
1732 case VERTEX_FORMAT_FLOAT1:
1733 {
1734 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1735 return format;
1736 }
1737 case VERTEX_FORMAT_FLOAT2:
1738 {
1739 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1740 return format;
1741 }
1742 case VERTEX_FORMAT_FLOAT3:
1743 {
1744 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1745 return format;
1746 }
1747 case VERTEX_FORMAT_FLOAT4:
1748 {
1749 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1750 return format;
1751 }
1752 case VERTEX_FORMAT_SINT210:
1753 {
1754 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1755 return format;
1756 }
1757 case VERTEX_FORMAT_UINT210:
1758 {
1759 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1760 return format;
1761 }
1762 case VERTEX_FORMAT_SINT210_NORM:
1763 {
1764 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1765 return format;
1766 }
1767 case VERTEX_FORMAT_UINT210_NORM:
1768 {
1769 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1770 return format;
1771 }
1772 case VERTEX_FORMAT_SINT210_INT:
1773 {
1774 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1775 return format;
1776 }
1777 case VERTEX_FORMAT_UINT210_INT:
1778 {
1779 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1780 return format;
1781 }
1782 default:
1783 {
1784 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1785 return format;
1786 }
1787 }
1788}
1789
1790VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1791 : type(typeIn),
1792 normalized(normalizedIn),
1793 components(componentsIn),
1794 pureInteger(pureIntegerIn)
1795{
1796 // float -> !normalized
1797 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1798}
1799
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001800}