blob: 008f58147acf9cf82d43733de429bfbcb174c75a [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
Jamie Madill6a6b09c2017-01-12 21:52:29 +00009#include "libANGLE/formatutils.h"
Yuly Novikovd73f8522017-01-13 17:48:57 -050010
11#include "common/mathutil.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050012#include "libANGLE/Context.h"
13#include "libANGLE/Framebuffer.h"
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000014
Jamie Madille2e406c2016-06-02 13:04:10 -040015using namespace angle;
16
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000017namespace gl
18{
19
20// ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation
21// can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid
22// format and type combinations.
Jamie Madilled4d3422016-10-03 15:45:35 -040023GLenum GetSizedFormatInternal(GLenum format, GLenum type);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000024
Jamie Madilled4d3422016-10-03 15:45:35 -040025namespace
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000026{
Geoff Langca271392017-04-05 12:30:00 -040027using InternalFormatInfoMap =
28 std::unordered_map<GLenum, std::unordered_map<GLenum, InternalFormat>>;
Jamie Madilla3944d42016-07-22 22:13:26 -040029
30} // anonymous namespace
31
32FormatType::FormatType() : format(GL_NONE), type(GL_NONE)
33{
34}
35
36FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_)
37{
38}
39
40bool FormatType::operator<(const FormatType &other) const
41{
42 if (format != other.format)
43 return format < other.format;
44 return type < other.type;
45}
46
Geoff Lang5d601382014-07-22 15:14:06 -040047Type::Type()
48 : bytes(0),
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020049 bytesShift(0),
Geoff Lang5d601382014-07-22 15:14:06 -040050 specialInterpretation(false)
Geoff Langfe28ca02013-06-04 10:10:48 -040051{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000052}
53
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020054static Type GenTypeInfo(GLuint bytes, bool specialInterpretation)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000055{
Geoff Lang5d601382014-07-22 15:14:06 -040056 Type info;
57 info.bytes = bytes;
Olli Etuaho11ffe1b2015-03-24 17:28:18 +020058 GLuint i = 0;
59 while ((1u << i) < bytes)
60 {
61 ++i;
62 }
63 info.bytesShift = i;
64 ASSERT((1u << info.bytesShift) == bytes);
Geoff Lang5d601382014-07-22 15:14:06 -040065 info.specialInterpretation = specialInterpretation;
Olli Etuaho31f8f4f2015-03-25 16:03:57 +020066 return info;
Geoff Lang5d601382014-07-22 15:14:06 -040067}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000068
Geoff Lang5d601382014-07-22 15:14:06 -040069bool operator<(const Type& a, const Type& b)
70{
71 return memcmp(&a, &b, sizeof(Type)) < 0;
72}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000073
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000074// Information about internal formats
Geoff Langeb66a6e2016-10-31 13:06:12 -040075static bool AlwaysSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000076{
Geoff Lang493daf52014-07-03 13:38:44 -040077 return true;
78}
79
Geoff Langeb66a6e2016-10-31 13:06:12 -040080static bool NeverSupported(const Version &, const Extensions &)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000081{
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +000082 return false;
83}
84
Geoff Langeb66a6e2016-10-31 13:06:12 -040085template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion>
86static bool RequireES(const Version &clientVersion, const Extensions &)
Geoff Lange4a492b2014-06-19 14:14:41 -040087{
Geoff Langeb66a6e2016-10-31 13:06:12 -040088 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion);
Geoff Lange4a492b2014-06-19 14:14:41 -040089}
90
Geoff Langcec35902014-04-16 10:52:36 -040091// Pointer to a boolean memeber of the Extensions struct
92typedef bool(Extensions::*ExtensionBool);
93
94// Check support for a single extension
95template <ExtensionBool bool1>
Geoff Langeb66a6e2016-10-31 13:06:12 -040096static bool RequireExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -040097{
Geoff Lange4a492b2014-06-19 14:14:41 -040098 return extensions.*bool1;
99}
100
101// Check for a minimum client version or a single extension
Geoff Langeb66a6e2016-10-31 13:06:12 -0400102template <GLuint minCoreGLMajorVersion, GLuint minCoreGLMinorVersion, ExtensionBool bool1>
103static bool RequireESOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400104{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400105 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
106 extensions.*bool1;
Geoff Lange4a492b2014-06-19 14:14:41 -0400107}
108
109// Check for a minimum client version or two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400110template <GLuint minCoreGLMajorVersion,
111 GLuint minCoreGLMinorVersion,
112 ExtensionBool bool1,
113 ExtensionBool bool2>
114static bool RequireESOrExtAndExt(const Version &clientVersion, const Extensions &extensions)
Geoff Lange4a492b2014-06-19 14:14:41 -0400115{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400116 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
117 (extensions.*bool1 && extensions.*bool2);
Geoff Langabce7622014-09-19 16:13:00 -0400118}
119
120// Check for a minimum client version or at least one of two extensions
Geoff Langeb66a6e2016-10-31 13:06:12 -0400121template <GLuint minCoreGLMajorVersion,
122 GLuint minCoreGLMinorVersion,
123 ExtensionBool bool1,
124 ExtensionBool bool2>
125static bool RequireESOrExtOrExt(const Version &clientVersion, const Extensions &extensions)
Geoff Langabce7622014-09-19 16:13:00 -0400126{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400127 return clientVersion >= Version(minCoreGLMajorVersion, minCoreGLMinorVersion) ||
128 extensions.*bool1 || extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400129}
130
131// Check support for two extensions
132template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400133static bool RequireExtAndExt(const Version &, const Extensions &extensions)
Geoff Langcec35902014-04-16 10:52:36 -0400134{
Geoff Langabce7622014-09-19 16:13:00 -0400135 return extensions.*bool1 && extensions.*bool2;
Geoff Langcec35902014-04-16 10:52:36 -0400136}
137
Geoff Lang60ad73d2015-10-23 10:08:44 -0400138// Check support for either of two extensions
139template <ExtensionBool bool1, ExtensionBool bool2>
Geoff Langeb66a6e2016-10-31 13:06:12 -0400140static bool RequireExtOrExt(const Version &, const Extensions &extensions)
Geoff Lang60ad73d2015-10-23 10:08:44 -0400141{
142 return extensions.*bool1 || extensions.*bool2;
143}
144
Jamie Madillcd089732015-12-17 09:53:09 -0500145// Special function for half float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400146static bool HalfFloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500147{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400148 return clientVersion >= Version(3, 0) || extensions.textureHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500149}
150
Geoff Lang677bb6f2017-04-05 12:40:40 -0400151static bool HalfFloatRGBRenderableSupport(const Version &clientVersion,
152 const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500153{
154 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
155}
156
Geoff Lang677bb6f2017-04-05 12:40:40 -0400157static bool HalfFloatRGBARenderableSupport(const Version &clientVersion,
158 const Extensions &extensions)
159{
160 return HalfFloatSupport(clientVersion, extensions) &&
161 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
162}
163
Jamie Madillcd089732015-12-17 09:53:09 -0500164// Special function for half float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400165
166// R16F, RG16F
167static bool HalfFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500168{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400169 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500170}
171
Geoff Lang677bb6f2017-04-05 12:40:40 -0400172// R16F, RG16F
173static bool HalfFloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400175 // It's unclear if EXT_color_buffer_half_float gives renderability to non-OES half float
176 // textures
177 return HalfFloatRGSupport(clientVersion, extensions) &&
178 (extensions.colorBufferHalfFloat || extensions.colorBufferFloat);
179}
180
181// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
182static bool UnsizedHalfFloatOESRGSupport(const Version &, const Extensions &extensions)
183{
184 return extensions.textureHalfFloat && extensions.textureRG;
185}
186
187// RED + HALF_FLOAT_OES, RG + HALF_FLOAT_OES
188static bool UnsizedHalfFloatOESRGRenderableSupport(const Version &clientVersion,
189 const Extensions &extensions)
190{
191 return UnsizedHalfFloatOESRGSupport(clientVersion, extensions) &&
192 extensions.colorBufferHalfFloat;
193}
194
195// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
196static bool UnsizedHalfFloatOESSupport(const Version &clientVersion, const Extensions &extensions)
197{
198 return extensions.textureHalfFloat;
199}
200
201// RGB + HALF_FLOAT_OES, RGBA + HALF_FLOAT_OES
202static bool UnsizedHalfFloatOESRenderableSupport(const Version &clientVersion,
203 const Extensions &extensions)
204{
205 return UnsizedHalfFloatOESSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500206}
207
208// Special function for float formats with three or four channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400209
210// RGB32F, RGBA32F
Geoff Langeb66a6e2016-10-31 13:06:12 -0400211static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500212{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400213 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500214}
215
Geoff Lang677bb6f2017-04-05 12:40:40 -0400216// RGB32F
217static bool FloatRGBRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500218{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400219 return FloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
220}
221
222// RGBA32F
223static bool FloatRGBARenderableSupport(const Version &clientVersion, const Extensions &extensions)
224{
Jamie Madillcd089732015-12-17 09:53:09 -0500225 return FloatSupport(clientVersion, extensions) &&
Geoff Lang677bb6f2017-04-05 12:40:40 -0400226 (extensions.colorBufferFloat || extensions.colorBufferFloatRGBA);
227}
228
229// RGB + FLOAT, RGBA + FLOAT
230static bool UnsizedFloatSupport(const Version &clientVersion, const Extensions &extensions)
231{
232 return extensions.textureFloat;
233}
234
235// RGB + FLOAT
236static bool UnsizedFloatRGBRenderableSupport(const Version &clientVersion,
237 const Extensions &extensions)
238{
239 return UnsizedFloatSupport(clientVersion, extensions) && extensions.colorBufferFloatRGB;
240}
241
242// RGBA + FLOAT
243static bool UnsizedFloatRGBARenderableSupport(const Version &clientVersion,
244 const Extensions &extensions)
245{
246 return UnsizedFloatSupport(clientVersion, extensions) &&
247 (extensions.colorBufferFloatRGBA || extensions.colorBufferFloat);
Jamie Madillcd089732015-12-17 09:53:09 -0500248}
249
250// Special function for float formats with one or two channels.
Geoff Lang677bb6f2017-04-05 12:40:40 -0400251
252// R32F, RG32F
253static bool FloatRGSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500254{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400255 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500256}
257
Geoff Lang677bb6f2017-04-05 12:40:40 -0400258// R32F, RG32F
259static bool FloatRGRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500260{
Geoff Lang677bb6f2017-04-05 12:40:40 -0400261 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
262}
263
264// RED + FLOAT, RG + FLOAT
265static bool UnsizedFloatRGSupport(const Version &clientVersion, const Extensions &extensions)
266{
267 return extensions.textureFloat && extensions.textureRG;
268}
269
270// RED + FLOAT, RG + FLOAT
271static bool UnsizedFloatRGRenderableSupport(const Version &clientVersion,
272 const Extensions &extensions)
273{
274 return FloatRGSupport(clientVersion, extensions) && extensions.colorBufferFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500275}
276
Geoff Lang5d601382014-07-22 15:14:06 -0400277InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400278 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400279 sized(false),
280 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400281 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400282 greenBits(0),
283 blueBits(0),
284 luminanceBits(0),
285 alphaBits(0),
286 sharedBits(0),
287 depthBits(0),
288 stencilBits(0),
289 pixelBytes(0),
290 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400291 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400292 compressedBlockWidth(0),
293 compressedBlockHeight(0),
294 format(GL_NONE),
295 type(GL_NONE),
296 componentType(GL_NONE),
297 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400298 textureSupport(NeverSupported),
299 renderSupport(NeverSupported),
300 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000301{
Geoff Lang5d601382014-07-22 15:14:06 -0400302}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303
Jamie Madilla3944d42016-07-22 22:13:26 -0400304bool InternalFormat::isLUMA() const
305{
306 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
307 (luminanceBits + alphaBits) > 0);
308}
309
Geoff Langf607c602016-09-21 11:46:48 -0400310GLenum InternalFormat::getReadPixelsFormat() const
311{
312 return format;
313}
314
315GLenum InternalFormat::getReadPixelsType() const
316{
317 switch (type)
318 {
319 case GL_HALF_FLOAT:
320 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
321 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
322 // OES_texture_half_float
323 return GL_HALF_FLOAT_OES;
324
325 default:
326 return type;
327 }
328}
329
Geoff Langca271392017-04-05 12:30:00 -0400330Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400331{
332}
333
Geoff Langca271392017-04-05 12:30:00 -0400334Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400335{
Jamie Madilla3944d42016-07-22 22:13:26 -0400336}
337
Geoff Langca271392017-04-05 12:30:00 -0400338Format::Format(GLenum internalFormat, GLenum type)
339 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400340{
Jamie Madilla3944d42016-07-22 22:13:26 -0400341}
342
343Format::Format(const Format &other) = default;
344Format &Format::operator=(const Format &other) = default;
345
Jamie Madilla3944d42016-07-22 22:13:26 -0400346bool Format::valid() const
347{
Geoff Langca271392017-04-05 12:30:00 -0400348 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400349}
350
351// static
352bool Format::SameSized(const Format &a, const Format &b)
353{
Geoff Langca271392017-04-05 12:30:00 -0400354 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400355}
356
357// static
358Format Format::Invalid()
359{
Geoff Langca271392017-04-05 12:30:00 -0400360 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400361 return invalid;
362}
363
Yuly Novikovd73f8522017-01-13 17:48:57 -0500364std::ostream &operator<<(std::ostream &os, const Format &fmt)
365{
366 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400367 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500368}
369
Jamie Madilla3944d42016-07-22 22:13:26 -0400370bool InternalFormat::operator==(const InternalFormat &other) const
371{
Geoff Langca271392017-04-05 12:30:00 -0400372 // We assume all internal formats are unique if they have the same internal format and type
373 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400374}
375
376bool InternalFormat::operator!=(const InternalFormat &other) const
377{
Geoff Langca271392017-04-05 12:30:00 -0400378 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400379}
380
Geoff Langca271392017-04-05 12:30:00 -0400381void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400382{
Geoff Langca271392017-04-05 12:30:00 -0400383 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
384 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
385 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400386}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000387
Jamie Madilla3944d42016-07-22 22:13:26 -0400388void AddRGBAFormat(InternalFormatInfoMap *map,
389 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400390 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400391 GLuint red,
392 GLuint green,
393 GLuint blue,
394 GLuint alpha,
395 GLuint shared,
396 GLenum format,
397 GLenum type,
398 GLenum componentType,
399 bool srgb,
400 InternalFormat::SupportCheckFunction textureSupport,
401 InternalFormat::SupportCheckFunction renderSupport,
402 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400403{
404 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400405 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400406 formatInfo.sized = sized;
407 formatInfo.sizedInternalFormat =
408 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400409 formatInfo.redBits = red;
410 formatInfo.greenBits = green;
411 formatInfo.blueBits = blue;
412 formatInfo.alphaBits = alpha;
413 formatInfo.sharedBits = shared;
414 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400415 formatInfo.componentCount =
416 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400417 formatInfo.format = format;
418 formatInfo.type = type;
419 formatInfo.componentType = componentType;
420 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
421 formatInfo.textureSupport = textureSupport;
422 formatInfo.renderSupport = renderSupport;
423 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400424
425 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400426}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000427
Geoff Langca271392017-04-05 12:30:00 -0400428static void AddLUMAFormat(InternalFormatInfoMap *map,
429 GLenum internalFormat,
430 bool sized,
431 GLuint luminance,
432 GLuint alpha,
433 GLenum format,
434 GLenum type,
435 GLenum componentType,
436 InternalFormat::SupportCheckFunction textureSupport,
437 InternalFormat::SupportCheckFunction renderSupport,
438 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400439{
440 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400441 formatInfo.internalFormat = internalFormat;
442 formatInfo.sized = sized;
443 formatInfo.sizedInternalFormat =
444 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400445 formatInfo.luminanceBits = luminance;
446 formatInfo.alphaBits = alpha;
447 formatInfo.pixelBytes = (luminance + alpha) / 8;
448 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
449 formatInfo.format = format;
450 formatInfo.type = type;
451 formatInfo.componentType = componentType;
452 formatInfo.colorEncoding = GL_LINEAR;
453 formatInfo.textureSupport = textureSupport;
454 formatInfo.renderSupport = renderSupport;
455 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400456
457 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400458}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000459
Jamie Madilla3944d42016-07-22 22:13:26 -0400460void AddDepthStencilFormat(InternalFormatInfoMap *map,
461 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400462 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400463 GLuint depthBits,
464 GLuint stencilBits,
465 GLuint unusedBits,
466 GLenum format,
467 GLenum type,
468 GLenum componentType,
469 InternalFormat::SupportCheckFunction textureSupport,
470 InternalFormat::SupportCheckFunction renderSupport,
471 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400472{
473 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400474 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400475 formatInfo.sized = sized;
476 formatInfo.sizedInternalFormat =
477 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400478 formatInfo.depthBits = depthBits;
479 formatInfo.stencilBits = stencilBits;
480 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
481 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
482 formatInfo.format = format;
483 formatInfo.type = type;
484 formatInfo.componentType = componentType;
485 formatInfo.colorEncoding = GL_LINEAR;
486 formatInfo.textureSupport = textureSupport;
487 formatInfo.renderSupport = renderSupport;
488 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400489
490 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400491}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000492
Geoff Langca271392017-04-05 12:30:00 -0400493void AddCompressedFormat(InternalFormatInfoMap *map,
494 GLenum internalFormat,
495 GLuint compressedBlockWidth,
496 GLuint compressedBlockHeight,
497 GLuint compressedBlockSize,
498 GLuint componentCount,
499 GLenum format,
500 GLenum type,
501 bool srgb,
502 InternalFormat::SupportCheckFunction textureSupport,
503 InternalFormat::SupportCheckFunction renderSupport,
504 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400505{
506 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400507 formatInfo.internalFormat = internalFormat;
508 formatInfo.sized = true;
509 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400510 formatInfo.compressedBlockWidth = compressedBlockWidth;
511 formatInfo.compressedBlockHeight = compressedBlockHeight;
512 formatInfo.pixelBytes = compressedBlockSize / 8;
513 formatInfo.componentCount = componentCount;
514 formatInfo.format = format;
515 formatInfo.type = type;
516 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
517 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
518 formatInfo.compressed = true;
519 formatInfo.textureSupport = textureSupport;
520 formatInfo.renderSupport = renderSupport;
521 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400522
523 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400524}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000525
Geoff Lange4a492b2014-06-19 14:14:41 -0400526static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000527{
528 InternalFormatInfoMap map;
529
530 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400531 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000532
Jamie Madilla3944d42016-07-22 22:13:26 -0400533 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000534
Geoff Langca271392017-04-05 12:30:00 -0400535 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
536 AddRGBAFormat(&map, GL_R8, true, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
537 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
538 AddRGBAFormat(&map, GL_RG8, true, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, RequireESOrExt<3, 0, &Extensions::textureRG>, AlwaysSupported);
539 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
540 AddRGBAFormat(&map, GL_RGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
541 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
542 AddRGBAFormat(&map, GL_RGB565, true, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
543 AddRGBAFormat(&map, GL_RGBA4, true, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
544 AddRGBAFormat(&map, GL_RGB5_A1, true, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
545 AddRGBAFormat(&map, GL_RGBA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
546 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
547 AddRGBAFormat(&map, GL_RGB10_A2, true, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3, 0>, RequireES<3, 0>, AlwaysSupported);
548 AddRGBAFormat(&map, GL_RGB10_A2UI, true, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
549 AddRGBAFormat(&map, GL_SRGB8, true, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, NeverSupported, AlwaysSupported);
550 AddRGBAFormat(&map, GL_SRGB8_ALPHA8, true, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, 0, &Extensions::sRGB>, RequireESOrExt<3, 0, &Extensions::sRGB>, AlwaysSupported);
551 AddRGBAFormat(&map, GL_RGB9_E5, true, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
552 AddRGBAFormat(&map, GL_R8I, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
553 AddRGBAFormat(&map, GL_R8UI, true, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
554 AddRGBAFormat(&map, GL_R16I, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
555 AddRGBAFormat(&map, GL_R16UI, true, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
556 AddRGBAFormat(&map, GL_R32I, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
557 AddRGBAFormat(&map, GL_R32UI, true, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
558 AddRGBAFormat(&map, GL_RG8I, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
559 AddRGBAFormat(&map, GL_RG8UI, true, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
560 AddRGBAFormat(&map, GL_RG16I, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
561 AddRGBAFormat(&map, GL_RG16UI, true, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
562 AddRGBAFormat(&map, GL_RG32I, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
563 AddRGBAFormat(&map, GL_R11F_G11F_B10F, true, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3, 0>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported);
564 AddRGBAFormat(&map, GL_RG32UI, true, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
565 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
566 AddRGBAFormat(&map, GL_RGB8UI, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
567 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
568 AddRGBAFormat(&map, GL_RGB16UI, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
569 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
570 AddRGBAFormat(&map, GL_RGB32UI, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
571 AddRGBAFormat(&map, GL_RGBA8I, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
572 AddRGBAFormat(&map, GL_RGBA8UI, true, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
573 AddRGBAFormat(&map, GL_RGBA16I, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
574 AddRGBAFormat(&map, GL_RGBA16UI, true, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
575 AddRGBAFormat(&map, GL_RGBA32I, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
576 AddRGBAFormat(&map, GL_RGBA32UI, true, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, RequireES<3, 0>, NeverSupported);
Jamie Madilla3944d42016-07-22 22:13:26 -0400577
Geoff Langca271392017-04-05 12:30:00 -0400578 AddRGBAFormat(&map, GL_BGRA8_EXT, true, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
579 AddRGBAFormat(&map, GL_BGRA4_ANGLEX, true, 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);
580 AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX, true, 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 +0000581
Jamie Madillec0b5802016-07-04 13:11:59 -0400582 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400583 AddRGBAFormat(&map, GL_BGR565_ANGLEX, true, 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 -0400584
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000585 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Lang677bb6f2017-04-05 12:40:40 -0400586 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
587 // | | | | | | | type | | | | |
588 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, HalfFloatRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
589 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatRGSupport, HalfFloatRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
590 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRGBRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
591 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRGBARenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
592 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
593 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatRGSupport, FloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
594 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
595 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000596
597 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400598 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
599 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, true, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
600 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, true, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
601 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3, 0>, RequireES<3, 0>, RequireESOrExt<3, 0, &Extensions::depthTextures>);
602 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, true, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported );
603 AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, true, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::depthTextures>, RequireESOrExtOrExt<3, 0, &Extensions::depthTextures, &Extensions::packedDepthStencil>, AlwaysSupported );
604 AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, true, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3, 0>, RequireES<3, 0>, AlwaysSupported );
Corentin Walleze0902642014-11-04 12:32:15 -0800605 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000606
607 // Luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400608 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
609 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
610 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
611 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
612 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
613 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
614 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
615 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
616 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
617 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear>);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000618
619 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400620 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
621 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
622 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
623 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
624 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
625 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
626 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
627 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
628 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
629 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
630 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000631
632 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400633 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
634 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
635 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000636
637 // From GL_ANGLE_texture_compression_dxt3
Geoff Langca271392017-04-05 12:30:00 -0400638 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000639
640 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400641 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported);
Geoff Lang6ea6f942015-09-11 13:11:22 -0400642
643 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400644 AddCompressedFormat(&map, GL_ETC1_RGB8_OES, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000645
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800646 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400647 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
648 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
649 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
650 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
651 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800652
Geoff Lang60ad73d2015-10-23 10:08:44 -0400653 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400654 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
655 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
656 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
657 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
658 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
659 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
660 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
661 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
662 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
663 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
664 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
665 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
666 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
667 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
668 AddCompressedFormat(&map, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400669
Geoff Langca271392017-04-05 12:30:00 -0400670 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
671 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 5, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
672 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 5, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
673 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 6, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
674 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 6, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
675 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 8, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
676 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 8, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
677 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 8, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
678 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 10, 5, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
679 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 10, 6, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
680 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 10, 8, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
681 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
682 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
683 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported);
Geoff Lang60ad73d2015-10-23 10:08:44 -0400684
Corentin Walleze0902642014-11-04 12:32:15 -0800685 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
686 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
687 // - All other stencil formats (all depth-stencil) are either float or normalized
688 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400689 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
690 AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, true, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, NeverSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800691
692 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400693 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
694 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
695 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
696 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
697 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
698 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
Minmin Gonge3939b92015-12-01 15:36:51 -0800699
Vincent Lang25ab4512016-05-13 18:13:59 +0200700 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400701 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
702 AddRGBAFormat(&map, GL_R16_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
703 AddRGBAFormat(&map, GL_R16_SNORM_EXT, true, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
704 AddRGBAFormat(&map, GL_RG16_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
705 AddRGBAFormat(&map, GL_RG16_SNORM_EXT, true, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
706 AddRGBAFormat(&map, GL_RGB16_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
707 AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, true, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported);
708 AddRGBAFormat(&map, GL_RGBA16_EXT, true, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported);
709 AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, true, 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 +0200710
Geoff Langca271392017-04-05 12:30:00 -0400711 // Unsized formats
712 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400713 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400714 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Lang8d4db1f2017-06-02 14:32:01 -0400715 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureRG>, AlwaysSupported, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400716 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400717 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, RequireESOrExt<3, 0, &Extensions::rgb8rgba8>, AlwaysSupported);
718 AddRGBAFormat(&map, GL_RGB, false, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400719 AddRGBAFormat(&map, GL_RGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400720 AddRGBAFormat(&map, GL_RGBA, false, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
721 AddRGBAFormat(&map, GL_RGBA, false, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
722 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
723 AddRGBAFormat(&map, GL_RGBA, false, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
Geoff Langdbcced82017-06-06 15:55:54 -0400724 AddRGBAFormat(&map, GL_RGBA, false, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Langca271392017-04-05 12:30:00 -0400725 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
726 AddRGBAFormat(&map, GL_SRGB_ALPHA_EXT, false, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, RequireExt<&Extensions::sRGB>, AlwaysSupported);
727
728 AddRGBAFormat(&map, GL_BGRA_EXT, false, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported);
729
730 // Unsized integer formats
731 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
732 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
733 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
734 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
735 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
736 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
737 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
738 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
739 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
740 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
741 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
742 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
743 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
744 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
745 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
746 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
747 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
748 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
749 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
750 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
751 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
752 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
753 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
754 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
755 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
756 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
757
758 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400759 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
760 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
761 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
762 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
763 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
764 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, UnsizedHalfFloatOESRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
765 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESRGSupport, UnsizedHalfFloatOESRGRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
766 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, UnsizedHalfFloatOESRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
767 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, UnsizedHalfFloatOESSupport, UnsizedHalfFloatOESRenderableSupport, RequireESOrExt<3, 0, &Extensions::textureHalfFloatLinear>);
768 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
769 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
770 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langdbcced82017-06-06 15:55:54 -0400771 AddRGBAFormat(&map, GL_RGB, false, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
772 AddRGBAFormat(&map, GL_RGB, false, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
Geoff Lang677bb6f2017-04-05 12:40:40 -0400773 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBARenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langca271392017-04-05 12:30:00 -0400774
775 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400776 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
777 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
778 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
779 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
780 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
781 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
782 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
783 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
784 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
785 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
Geoff Langca271392017-04-05 12:30:00 -0400786
787 // Unsized depth stencil formats
788 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
789 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
790 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
791 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
792 AddDepthStencilFormat(&map, GL_DEPTH_STENCIL, false, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
793 AddDepthStencilFormat(&map, GL_DEPTH_STENCIL, false, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, RequireESOrExt<3, 0, &Extensions::packedDepthStencil>, AlwaysSupported);
794 AddDepthStencilFormat(&map, GL_STENCIL, false, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, RequireES<2, 0>, NeverSupported);
Geoff Lang9bbad182015-09-04 11:07:29 -0400795 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800796
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000797 return map;
798}
799
Geoff Lange4a492b2014-06-19 14:14:41 -0400800static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000801{
Geoff Lange4a492b2014-06-19 14:14:41 -0400802 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
803 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000804}
805
Geoff Lange4a492b2014-06-19 14:14:41 -0400806static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400807{
808 FormatSet result;
809
Geoff Langca271392017-04-05 12:30:00 -0400810 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400811 {
Geoff Langca271392017-04-05 12:30:00 -0400812 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400813 {
Geoff Langca271392017-04-05 12:30:00 -0400814 if (type.second.sized)
815 {
816 // TODO(jmadill): Fix this hack.
817 if (internalFormat.first == GL_BGR565_ANGLEX)
818 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400819
Geoff Langca271392017-04-05 12:30:00 -0400820 result.insert(internalFormat.first);
821 }
Geoff Langcec35902014-04-16 10:52:36 -0400822 }
823 }
824
825 return result;
826}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000827
Geoff Lang5d601382014-07-22 15:14:06 -0400828const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000829{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200830 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000831 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200832 case GL_UNSIGNED_BYTE:
833 case GL_BYTE:
834 {
835 static const Type info = GenTypeInfo(1, false);
836 return info;
837 }
838 case GL_UNSIGNED_SHORT:
839 case GL_SHORT:
840 case GL_HALF_FLOAT:
841 case GL_HALF_FLOAT_OES:
842 {
843 static const Type info = GenTypeInfo(2, false);
844 return info;
845 }
846 case GL_UNSIGNED_INT:
847 case GL_INT:
848 case GL_FLOAT:
849 {
850 static const Type info = GenTypeInfo(4, false);
851 return info;
852 }
853 case GL_UNSIGNED_SHORT_5_6_5:
854 case GL_UNSIGNED_SHORT_4_4_4_4:
855 case GL_UNSIGNED_SHORT_5_5_5_1:
856 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
857 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
858 {
859 static const Type info = GenTypeInfo(2, true);
860 return info;
861 }
862 case GL_UNSIGNED_INT_2_10_10_10_REV:
863 case GL_UNSIGNED_INT_24_8:
864 case GL_UNSIGNED_INT_10F_11F_11F_REV:
865 case GL_UNSIGNED_INT_5_9_9_9_REV:
866 {
867 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
868 static const Type info = GenTypeInfo(4, true);
869 return info;
870 }
871 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
872 {
873 static const Type info = GenTypeInfo(8, true);
874 return info;
875 }
876 default:
877 {
878 static const Type defaultInfo;
879 return defaultInfo;
880 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000881 }
882}
883
Geoff Langca271392017-04-05 12:30:00 -0400884const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000885{
Geoff Langca271392017-04-05 12:30:00 -0400886 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400887 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400888 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -0400889
890 // Sized internal formats only have one type per entry
891 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000892 {
Geoff Lang5d601382014-07-22 15:14:06 -0400893 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000894 }
Geoff Langca271392017-04-05 12:30:00 -0400895
896 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
897 if (!internalFormatInfo.sized)
898 {
899 return defaultInternalFormat;
900 }
901
902 return internalFormatInfo;
903}
904
905const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
906{
907 static const InternalFormat defaultInternalFormat;
908 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
909
910 auto internalFormatIter = formatMap.find(internalFormat);
911 if (internalFormatIter == formatMap.end())
912 {
913 return defaultInternalFormat;
914 }
915
916 // If the internal format is sized, simply return it without the type check.
917 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
918 {
919 return internalFormatIter->second.begin()->second;
920 }
921
922 auto typeIter = internalFormatIter->second.find(type);
923 if (typeIter == internalFormatIter->second.end())
924 {
925 return defaultInternalFormat;
926 }
927
928 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000929}
930
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400931GLuint InternalFormat::computePixelBytes(GLenum formatType) const
932{
933 const auto &typeInfo = GetTypeInfo(formatType);
934 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
935 return components * typeInfo.bytes;
936}
937
Corentin Wallez886de362016-09-27 10:49:35 -0400938ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400939 GLsizei width,
940 GLint alignment,
941 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000942{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700943 // Compressed images do not use pack/unpack parameters.
944 if (compressed)
945 {
946 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400947 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700948 }
949
Geoff Lang3f234062016-07-13 15:35:45 -0400950 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400951 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700952
953 ASSERT(alignment > 0 && isPow2(alignment));
954 CheckedNumeric<GLuint> checkedAlignment(alignment);
955 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
956 ANGLE_TRY_CHECKED_MATH(aligned);
957 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000958}
959
Corentin Wallez0e487192016-10-03 16:30:38 -0400960ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
961 GLint imageHeight,
962 GLuint rowPitch) const
963{
964 GLuint rows =
965 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
966 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
967
968 auto depthPitch = checkedRowPitch * rows;
969 ANGLE_TRY_CHECKED_MATH(depthPitch);
970 return depthPitch.ValueOrDie();
971}
972
Corentin Wallez886de362016-09-27 10:49:35 -0400973ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400974 GLsizei width,
975 GLsizei height,
976 GLint alignment,
977 GLint rowLength,
978 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000979{
Jamie Madille2e406c2016-06-02 13:04:10 -0400980 GLuint rowPitch = 0;
981 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400982 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000983}
984
Corentin Wallez886de362016-09-27 10:49:35 -0400985ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
986 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000987{
Jamie Madill513558d2016-06-02 13:04:11 -0400988 CheckedNumeric<GLuint> checkedWidth(size.width);
989 CheckedNumeric<GLuint> checkedHeight(size.height);
990 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700991 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
992 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400993
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700994 ASSERT(compressed);
995 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
996 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
997 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
998 ANGLE_TRY_CHECKED_MATH(bytes);
999 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001000}
1001
Corentin Wallez886de362016-09-27 10:49:35 -04001002ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -07001003 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -04001004 const PixelStoreStateBase &state,
1005 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001006{
Olli Etuaho989cac32016-06-08 16:18:49 -07001007 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1008 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001009 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1010 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1011 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001012 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1013 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001014 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001015 {
1016 checkedSkipImagesBytes = 0;
1017 }
1018 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1019 checkedSkipPixels * checkedPixelBytes;
1020 ANGLE_TRY_CHECKED_MATH(skipBytes);
1021 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001022}
1023
Corentin Wallez886de362016-09-27 10:49:35 -04001024ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1025 GLenum formatType,
1026 const Extents &size,
1027 const PixelStoreStateBase &state,
1028 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001029{
Corentin Wallez886de362016-09-27 10:49:35 -04001030 GLuint rowPitch = 0;
1031 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001032 rowPitch);
1033
Corentin Wallez0e487192016-10-03 16:30:38 -04001034 GLuint depthPitch = 0;
1035 if (is3D)
1036 {
1037 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1038 }
1039
Corentin Wallez886de362016-09-27 10:49:35 -04001040 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001041 if (compressed)
1042 {
Corentin Wallez886de362016-09-27 10:49:35 -04001043 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001044 }
Corentin Wallez886de362016-09-27 10:49:35 -04001045 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001046 {
Corentin Wallez886de362016-09-27 10:49:35 -04001047 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1048 checkedCopyBytes += size.width * bytes;
1049
1050 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1051 checkedCopyBytes += heightMinusOne * rowPitch;
1052
1053 if (is3D)
1054 {
1055 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1056 checkedCopyBytes += depthMinusOne * depthPitch;
1057 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001058 }
1059
Corentin Wallez886de362016-09-27 10:49:35 -04001060 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1061 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001062
1063 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1064
1065 ANGLE_TRY_CHECKED_MATH(endByte);
1066 return endByte.ValueOrDie();
1067}
1068
Geoff Langca271392017-04-05 12:30:00 -04001069GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001070{
Geoff Langca271392017-04-05 12:30:00 -04001071 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1072 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001073 {
Geoff Langca271392017-04-05 12:30:00 -04001074 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001075 }
Geoff Langca271392017-04-05 12:30:00 -04001076
1077 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001078}
1079
Geoff Lange4a492b2014-06-19 14:14:41 -04001080const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001081{
Geoff Lange4a492b2014-06-19 14:14:41 -04001082 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001083 return formatSet;
1084}
1085
Jamie Madill09e2d932015-07-14 16:40:31 -04001086AttributeType GetAttributeType(GLenum enumValue)
1087{
1088 switch (enumValue)
1089 {
1090 case GL_FLOAT:
1091 return ATTRIBUTE_FLOAT;
1092 case GL_FLOAT_VEC2:
1093 return ATTRIBUTE_VEC2;
1094 case GL_FLOAT_VEC3:
1095 return ATTRIBUTE_VEC3;
1096 case GL_FLOAT_VEC4:
1097 return ATTRIBUTE_VEC4;
1098 case GL_INT:
1099 return ATTRIBUTE_INT;
1100 case GL_INT_VEC2:
1101 return ATTRIBUTE_IVEC2;
1102 case GL_INT_VEC3:
1103 return ATTRIBUTE_IVEC3;
1104 case GL_INT_VEC4:
1105 return ATTRIBUTE_IVEC4;
1106 case GL_UNSIGNED_INT:
1107 return ATTRIBUTE_UINT;
1108 case GL_UNSIGNED_INT_VEC2:
1109 return ATTRIBUTE_UVEC2;
1110 case GL_UNSIGNED_INT_VEC3:
1111 return ATTRIBUTE_UVEC3;
1112 case GL_UNSIGNED_INT_VEC4:
1113 return ATTRIBUTE_UVEC4;
1114 case GL_FLOAT_MAT2:
1115 return ATTRIBUTE_MAT2;
1116 case GL_FLOAT_MAT3:
1117 return ATTRIBUTE_MAT3;
1118 case GL_FLOAT_MAT4:
1119 return ATTRIBUTE_MAT4;
1120 case GL_FLOAT_MAT2x3:
1121 return ATTRIBUTE_MAT2x3;
1122 case GL_FLOAT_MAT2x4:
1123 return ATTRIBUTE_MAT2x4;
1124 case GL_FLOAT_MAT3x2:
1125 return ATTRIBUTE_MAT3x2;
1126 case GL_FLOAT_MAT3x4:
1127 return ATTRIBUTE_MAT3x4;
1128 case GL_FLOAT_MAT4x2:
1129 return ATTRIBUTE_MAT4x2;
1130 case GL_FLOAT_MAT4x3:
1131 return ATTRIBUTE_MAT4x3;
1132 default:
1133 UNREACHABLE();
1134 return ATTRIBUTE_FLOAT;
1135 }
1136}
1137
Jamie Madilld3dfda22015-07-06 08:28:49 -04001138VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1139{
1140 switch (type)
1141 {
1142 case GL_BYTE:
1143 switch (components)
1144 {
1145 case 1:
1146 if (pureInteger)
1147 return VERTEX_FORMAT_SBYTE1_INT;
1148 if (normalized)
1149 return VERTEX_FORMAT_SBYTE1_NORM;
1150 return VERTEX_FORMAT_SBYTE1;
1151 case 2:
1152 if (pureInteger)
1153 return VERTEX_FORMAT_SBYTE2_INT;
1154 if (normalized)
1155 return VERTEX_FORMAT_SBYTE2_NORM;
1156 return VERTEX_FORMAT_SBYTE2;
1157 case 3:
1158 if (pureInteger)
1159 return VERTEX_FORMAT_SBYTE3_INT;
1160 if (normalized)
1161 return VERTEX_FORMAT_SBYTE3_NORM;
1162 return VERTEX_FORMAT_SBYTE3;
1163 case 4:
1164 if (pureInteger)
1165 return VERTEX_FORMAT_SBYTE4_INT;
1166 if (normalized)
1167 return VERTEX_FORMAT_SBYTE4_NORM;
1168 return VERTEX_FORMAT_SBYTE4;
1169 default:
1170 UNREACHABLE();
1171 break;
1172 }
1173 case GL_UNSIGNED_BYTE:
1174 switch (components)
1175 {
1176 case 1:
1177 if (pureInteger)
1178 return VERTEX_FORMAT_UBYTE1_INT;
1179 if (normalized)
1180 return VERTEX_FORMAT_UBYTE1_NORM;
1181 return VERTEX_FORMAT_UBYTE1;
1182 case 2:
1183 if (pureInteger)
1184 return VERTEX_FORMAT_UBYTE2_INT;
1185 if (normalized)
1186 return VERTEX_FORMAT_UBYTE2_NORM;
1187 return VERTEX_FORMAT_UBYTE2;
1188 case 3:
1189 if (pureInteger)
1190 return VERTEX_FORMAT_UBYTE3_INT;
1191 if (normalized)
1192 return VERTEX_FORMAT_UBYTE3_NORM;
1193 return VERTEX_FORMAT_UBYTE3;
1194 case 4:
1195 if (pureInteger)
1196 return VERTEX_FORMAT_UBYTE4_INT;
1197 if (normalized)
1198 return VERTEX_FORMAT_UBYTE4_NORM;
1199 return VERTEX_FORMAT_UBYTE4;
1200 default:
1201 UNREACHABLE();
1202 break;
1203 }
1204 case GL_SHORT:
1205 switch (components)
1206 {
1207 case 1:
1208 if (pureInteger)
1209 return VERTEX_FORMAT_SSHORT1_INT;
1210 if (normalized)
1211 return VERTEX_FORMAT_SSHORT1_NORM;
1212 return VERTEX_FORMAT_SSHORT1;
1213 case 2:
1214 if (pureInteger)
1215 return VERTEX_FORMAT_SSHORT2_INT;
1216 if (normalized)
1217 return VERTEX_FORMAT_SSHORT2_NORM;
1218 return VERTEX_FORMAT_SSHORT2;
1219 case 3:
1220 if (pureInteger)
1221 return VERTEX_FORMAT_SSHORT3_INT;
1222 if (normalized)
1223 return VERTEX_FORMAT_SSHORT3_NORM;
1224 return VERTEX_FORMAT_SSHORT3;
1225 case 4:
1226 if (pureInteger)
1227 return VERTEX_FORMAT_SSHORT4_INT;
1228 if (normalized)
1229 return VERTEX_FORMAT_SSHORT4_NORM;
1230 return VERTEX_FORMAT_SSHORT4;
1231 default:
1232 UNREACHABLE();
1233 break;
1234 }
1235 case GL_UNSIGNED_SHORT:
1236 switch (components)
1237 {
1238 case 1:
1239 if (pureInteger)
1240 return VERTEX_FORMAT_USHORT1_INT;
1241 if (normalized)
1242 return VERTEX_FORMAT_USHORT1_NORM;
1243 return VERTEX_FORMAT_USHORT1;
1244 case 2:
1245 if (pureInteger)
1246 return VERTEX_FORMAT_USHORT2_INT;
1247 if (normalized)
1248 return VERTEX_FORMAT_USHORT2_NORM;
1249 return VERTEX_FORMAT_USHORT2;
1250 case 3:
1251 if (pureInteger)
1252 return VERTEX_FORMAT_USHORT3_INT;
1253 if (normalized)
1254 return VERTEX_FORMAT_USHORT3_NORM;
1255 return VERTEX_FORMAT_USHORT3;
1256 case 4:
1257 if (pureInteger)
1258 return VERTEX_FORMAT_USHORT4_INT;
1259 if (normalized)
1260 return VERTEX_FORMAT_USHORT4_NORM;
1261 return VERTEX_FORMAT_USHORT4;
1262 default:
1263 UNREACHABLE();
1264 break;
1265 }
1266 case GL_INT:
1267 switch (components)
1268 {
1269 case 1:
1270 if (pureInteger)
1271 return VERTEX_FORMAT_SINT1_INT;
1272 if (normalized)
1273 return VERTEX_FORMAT_SINT1_NORM;
1274 return VERTEX_FORMAT_SINT1;
1275 case 2:
1276 if (pureInteger)
1277 return VERTEX_FORMAT_SINT2_INT;
1278 if (normalized)
1279 return VERTEX_FORMAT_SINT2_NORM;
1280 return VERTEX_FORMAT_SINT2;
1281 case 3:
1282 if (pureInteger)
1283 return VERTEX_FORMAT_SINT3_INT;
1284 if (normalized)
1285 return VERTEX_FORMAT_SINT3_NORM;
1286 return VERTEX_FORMAT_SINT3;
1287 case 4:
1288 if (pureInteger)
1289 return VERTEX_FORMAT_SINT4_INT;
1290 if (normalized)
1291 return VERTEX_FORMAT_SINT4_NORM;
1292 return VERTEX_FORMAT_SINT4;
1293 default:
1294 UNREACHABLE();
1295 break;
1296 }
1297 case GL_UNSIGNED_INT:
1298 switch (components)
1299 {
1300 case 1:
1301 if (pureInteger)
1302 return VERTEX_FORMAT_UINT1_INT;
1303 if (normalized)
1304 return VERTEX_FORMAT_UINT1_NORM;
1305 return VERTEX_FORMAT_UINT1;
1306 case 2:
1307 if (pureInteger)
1308 return VERTEX_FORMAT_UINT2_INT;
1309 if (normalized)
1310 return VERTEX_FORMAT_UINT2_NORM;
1311 return VERTEX_FORMAT_UINT2;
1312 case 3:
1313 if (pureInteger)
1314 return VERTEX_FORMAT_UINT3_INT;
1315 if (normalized)
1316 return VERTEX_FORMAT_UINT3_NORM;
1317 return VERTEX_FORMAT_UINT3;
1318 case 4:
1319 if (pureInteger)
1320 return VERTEX_FORMAT_UINT4_INT;
1321 if (normalized)
1322 return VERTEX_FORMAT_UINT4_NORM;
1323 return VERTEX_FORMAT_UINT4;
1324 default:
1325 UNREACHABLE();
1326 break;
1327 }
1328 case GL_FLOAT:
1329 switch (components)
1330 {
1331 case 1:
1332 return VERTEX_FORMAT_FLOAT1;
1333 case 2:
1334 return VERTEX_FORMAT_FLOAT2;
1335 case 3:
1336 return VERTEX_FORMAT_FLOAT3;
1337 case 4:
1338 return VERTEX_FORMAT_FLOAT4;
1339 default:
1340 UNREACHABLE();
1341 break;
1342 }
1343 case GL_HALF_FLOAT:
1344 switch (components)
1345 {
1346 case 1:
1347 return VERTEX_FORMAT_HALF1;
1348 case 2:
1349 return VERTEX_FORMAT_HALF2;
1350 case 3:
1351 return VERTEX_FORMAT_HALF3;
1352 case 4:
1353 return VERTEX_FORMAT_HALF4;
1354 default:
1355 UNREACHABLE();
1356 break;
1357 }
1358 case GL_FIXED:
1359 switch (components)
1360 {
1361 case 1:
1362 return VERTEX_FORMAT_FIXED1;
1363 case 2:
1364 return VERTEX_FORMAT_FIXED2;
1365 case 3:
1366 return VERTEX_FORMAT_FIXED3;
1367 case 4:
1368 return VERTEX_FORMAT_FIXED4;
1369 default:
1370 UNREACHABLE();
1371 break;
1372 }
1373 case GL_INT_2_10_10_10_REV:
1374 if (pureInteger)
1375 return VERTEX_FORMAT_SINT210_INT;
1376 if (normalized)
1377 return VERTEX_FORMAT_SINT210_NORM;
1378 return VERTEX_FORMAT_SINT210;
1379 case GL_UNSIGNED_INT_2_10_10_10_REV:
1380 if (pureInteger)
1381 return VERTEX_FORMAT_UINT210_INT;
1382 if (normalized)
1383 return VERTEX_FORMAT_UINT210_NORM;
1384 return VERTEX_FORMAT_UINT210;
1385 default:
1386 UNREACHABLE();
1387 break;
1388 }
1389 return VERTEX_FORMAT_UBYTE1;
1390}
1391
1392VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1393{
1394 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1395}
1396
1397VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1398{
1399 if (!attrib.enabled)
1400 {
1401 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1402 }
1403 return GetVertexFormatType(attrib);
1404}
1405
1406const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1407{
1408 switch (vertexFormatType)
1409 {
1410 case VERTEX_FORMAT_SBYTE1:
1411 {
1412 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1413 return format;
1414 }
1415 case VERTEX_FORMAT_SBYTE1_NORM:
1416 {
1417 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1418 return format;
1419 }
1420 case VERTEX_FORMAT_SBYTE2:
1421 {
1422 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1423 return format;
1424 }
1425 case VERTEX_FORMAT_SBYTE2_NORM:
1426 {
1427 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1428 return format;
1429 }
1430 case VERTEX_FORMAT_SBYTE3:
1431 {
1432 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1433 return format;
1434 }
1435 case VERTEX_FORMAT_SBYTE3_NORM:
1436 {
1437 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1438 return format;
1439 }
1440 case VERTEX_FORMAT_SBYTE4:
1441 {
1442 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1443 return format;
1444 }
1445 case VERTEX_FORMAT_SBYTE4_NORM:
1446 {
1447 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1448 return format;
1449 }
1450 case VERTEX_FORMAT_UBYTE1:
1451 {
1452 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1453 return format;
1454 }
1455 case VERTEX_FORMAT_UBYTE1_NORM:
1456 {
1457 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1458 return format;
1459 }
1460 case VERTEX_FORMAT_UBYTE2:
1461 {
1462 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1463 return format;
1464 }
1465 case VERTEX_FORMAT_UBYTE2_NORM:
1466 {
1467 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1468 return format;
1469 }
1470 case VERTEX_FORMAT_UBYTE3:
1471 {
1472 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1473 return format;
1474 }
1475 case VERTEX_FORMAT_UBYTE3_NORM:
1476 {
1477 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1478 return format;
1479 }
1480 case VERTEX_FORMAT_UBYTE4:
1481 {
1482 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1483 return format;
1484 }
1485 case VERTEX_FORMAT_UBYTE4_NORM:
1486 {
1487 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1488 return format;
1489 }
1490 case VERTEX_FORMAT_SSHORT1:
1491 {
1492 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1493 return format;
1494 }
1495 case VERTEX_FORMAT_SSHORT1_NORM:
1496 {
1497 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1498 return format;
1499 }
1500 case VERTEX_FORMAT_SSHORT2:
1501 {
1502 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1503 return format;
1504 }
1505 case VERTEX_FORMAT_SSHORT2_NORM:
1506 {
1507 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1508 return format;
1509 }
1510 case VERTEX_FORMAT_SSHORT3:
1511 {
1512 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1513 return format;
1514 }
1515 case VERTEX_FORMAT_SSHORT3_NORM:
1516 {
1517 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1518 return format;
1519 }
1520 case VERTEX_FORMAT_SSHORT4:
1521 {
1522 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1523 return format;
1524 }
1525 case VERTEX_FORMAT_SSHORT4_NORM:
1526 {
1527 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1528 return format;
1529 }
1530 case VERTEX_FORMAT_USHORT1:
1531 {
1532 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1533 return format;
1534 }
1535 case VERTEX_FORMAT_USHORT1_NORM:
1536 {
1537 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1538 return format;
1539 }
1540 case VERTEX_FORMAT_USHORT2:
1541 {
1542 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1543 return format;
1544 }
1545 case VERTEX_FORMAT_USHORT2_NORM:
1546 {
1547 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1548 return format;
1549 }
1550 case VERTEX_FORMAT_USHORT3:
1551 {
1552 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1553 return format;
1554 }
1555 case VERTEX_FORMAT_USHORT3_NORM:
1556 {
1557 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1558 return format;
1559 }
1560 case VERTEX_FORMAT_USHORT4:
1561 {
1562 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1563 return format;
1564 }
1565 case VERTEX_FORMAT_USHORT4_NORM:
1566 {
1567 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1568 return format;
1569 }
1570 case VERTEX_FORMAT_SINT1:
1571 {
1572 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1573 return format;
1574 }
1575 case VERTEX_FORMAT_SINT1_NORM:
1576 {
1577 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1578 return format;
1579 }
1580 case VERTEX_FORMAT_SINT2:
1581 {
1582 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1583 return format;
1584 }
1585 case VERTEX_FORMAT_SINT2_NORM:
1586 {
1587 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1588 return format;
1589 }
1590 case VERTEX_FORMAT_SINT3:
1591 {
1592 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1593 return format;
1594 }
1595 case VERTEX_FORMAT_SINT3_NORM:
1596 {
1597 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1598 return format;
1599 }
1600 case VERTEX_FORMAT_SINT4:
1601 {
1602 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1603 return format;
1604 }
1605 case VERTEX_FORMAT_SINT4_NORM:
1606 {
1607 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1608 return format;
1609 }
1610 case VERTEX_FORMAT_UINT1:
1611 {
1612 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1613 return format;
1614 }
1615 case VERTEX_FORMAT_UINT1_NORM:
1616 {
1617 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1618 return format;
1619 }
1620 case VERTEX_FORMAT_UINT2:
1621 {
1622 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1623 return format;
1624 }
1625 case VERTEX_FORMAT_UINT2_NORM:
1626 {
1627 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1628 return format;
1629 }
1630 case VERTEX_FORMAT_UINT3:
1631 {
1632 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1633 return format;
1634 }
1635 case VERTEX_FORMAT_UINT3_NORM:
1636 {
1637 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1638 return format;
1639 }
1640 case VERTEX_FORMAT_UINT4:
1641 {
1642 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1643 return format;
1644 }
1645 case VERTEX_FORMAT_UINT4_NORM:
1646 {
1647 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1648 return format;
1649 }
1650 case VERTEX_FORMAT_SBYTE1_INT:
1651 {
1652 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1653 return format;
1654 }
1655 case VERTEX_FORMAT_SBYTE2_INT:
1656 {
1657 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1658 return format;
1659 }
1660 case VERTEX_FORMAT_SBYTE3_INT:
1661 {
1662 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1663 return format;
1664 }
1665 case VERTEX_FORMAT_SBYTE4_INT:
1666 {
1667 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1668 return format;
1669 }
1670 case VERTEX_FORMAT_UBYTE1_INT:
1671 {
1672 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1673 return format;
1674 }
1675 case VERTEX_FORMAT_UBYTE2_INT:
1676 {
1677 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1678 return format;
1679 }
1680 case VERTEX_FORMAT_UBYTE3_INT:
1681 {
1682 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1683 return format;
1684 }
1685 case VERTEX_FORMAT_UBYTE4_INT:
1686 {
1687 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1688 return format;
1689 }
1690 case VERTEX_FORMAT_SSHORT1_INT:
1691 {
1692 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1693 return format;
1694 }
1695 case VERTEX_FORMAT_SSHORT2_INT:
1696 {
1697 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1698 return format;
1699 }
1700 case VERTEX_FORMAT_SSHORT3_INT:
1701 {
1702 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1703 return format;
1704 }
1705 case VERTEX_FORMAT_SSHORT4_INT:
1706 {
1707 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1708 return format;
1709 }
1710 case VERTEX_FORMAT_USHORT1_INT:
1711 {
1712 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1713 return format;
1714 }
1715 case VERTEX_FORMAT_USHORT2_INT:
1716 {
1717 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1718 return format;
1719 }
1720 case VERTEX_FORMAT_USHORT3_INT:
1721 {
1722 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1723 return format;
1724 }
1725 case VERTEX_FORMAT_USHORT4_INT:
1726 {
1727 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1728 return format;
1729 }
1730 case VERTEX_FORMAT_SINT1_INT:
1731 {
1732 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1733 return format;
1734 }
1735 case VERTEX_FORMAT_SINT2_INT:
1736 {
1737 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1738 return format;
1739 }
1740 case VERTEX_FORMAT_SINT3_INT:
1741 {
1742 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1743 return format;
1744 }
1745 case VERTEX_FORMAT_SINT4_INT:
1746 {
1747 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1748 return format;
1749 }
1750 case VERTEX_FORMAT_UINT1_INT:
1751 {
1752 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1753 return format;
1754 }
1755 case VERTEX_FORMAT_UINT2_INT:
1756 {
1757 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1758 return format;
1759 }
1760 case VERTEX_FORMAT_UINT3_INT:
1761 {
1762 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1763 return format;
1764 }
1765 case VERTEX_FORMAT_UINT4_INT:
1766 {
1767 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1768 return format;
1769 }
1770 case VERTEX_FORMAT_FIXED1:
1771 {
1772 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1773 return format;
1774 }
1775 case VERTEX_FORMAT_FIXED2:
1776 {
1777 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1778 return format;
1779 }
1780 case VERTEX_FORMAT_FIXED3:
1781 {
1782 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1783 return format;
1784 }
1785 case VERTEX_FORMAT_FIXED4:
1786 {
1787 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1788 return format;
1789 }
1790 case VERTEX_FORMAT_HALF1:
1791 {
1792 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1793 return format;
1794 }
1795 case VERTEX_FORMAT_HALF2:
1796 {
1797 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1798 return format;
1799 }
1800 case VERTEX_FORMAT_HALF3:
1801 {
1802 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1803 return format;
1804 }
1805 case VERTEX_FORMAT_HALF4:
1806 {
1807 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1808 return format;
1809 }
1810 case VERTEX_FORMAT_FLOAT1:
1811 {
1812 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1813 return format;
1814 }
1815 case VERTEX_FORMAT_FLOAT2:
1816 {
1817 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1818 return format;
1819 }
1820 case VERTEX_FORMAT_FLOAT3:
1821 {
1822 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1823 return format;
1824 }
1825 case VERTEX_FORMAT_FLOAT4:
1826 {
1827 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1828 return format;
1829 }
1830 case VERTEX_FORMAT_SINT210:
1831 {
1832 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1833 return format;
1834 }
1835 case VERTEX_FORMAT_UINT210:
1836 {
1837 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1838 return format;
1839 }
1840 case VERTEX_FORMAT_SINT210_NORM:
1841 {
1842 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1843 return format;
1844 }
1845 case VERTEX_FORMAT_UINT210_NORM:
1846 {
1847 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1848 return format;
1849 }
1850 case VERTEX_FORMAT_SINT210_INT:
1851 {
1852 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1853 return format;
1854 }
1855 case VERTEX_FORMAT_UINT210_INT:
1856 {
1857 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1858 return format;
1859 }
1860 default:
1861 {
1862 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1863 return format;
1864 }
1865 }
1866}
1867
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001868size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1869{
1870 switch (vertexFormatType)
1871 {
1872 case VERTEX_FORMAT_SBYTE1:
1873 case VERTEX_FORMAT_SBYTE1_NORM:
1874 case VERTEX_FORMAT_UBYTE1:
1875 case VERTEX_FORMAT_UBYTE1_NORM:
1876 case VERTEX_FORMAT_SBYTE1_INT:
1877 case VERTEX_FORMAT_UBYTE1_INT:
1878 return 1;
1879
1880 case VERTEX_FORMAT_SBYTE2:
1881 case VERTEX_FORMAT_SBYTE2_NORM:
1882 case VERTEX_FORMAT_UBYTE2:
1883 case VERTEX_FORMAT_UBYTE2_NORM:
1884 case VERTEX_FORMAT_SBYTE2_INT:
1885 case VERTEX_FORMAT_UBYTE2_INT:
1886 case VERTEX_FORMAT_SSHORT1:
1887 case VERTEX_FORMAT_SSHORT1_NORM:
1888 case VERTEX_FORMAT_USHORT1:
1889 case VERTEX_FORMAT_USHORT1_NORM:
1890 case VERTEX_FORMAT_SSHORT1_INT:
1891 case VERTEX_FORMAT_USHORT1_INT:
1892 case VERTEX_FORMAT_HALF1:
1893 return 2;
1894
1895 case VERTEX_FORMAT_SBYTE3:
1896 case VERTEX_FORMAT_SBYTE3_NORM:
1897 case VERTEX_FORMAT_UBYTE3:
1898 case VERTEX_FORMAT_UBYTE3_NORM:
1899 case VERTEX_FORMAT_SBYTE3_INT:
1900 case VERTEX_FORMAT_UBYTE3_INT:
1901 return 3;
1902
1903 case VERTEX_FORMAT_SBYTE4:
1904 case VERTEX_FORMAT_SBYTE4_NORM:
1905 case VERTEX_FORMAT_UBYTE4:
1906 case VERTEX_FORMAT_UBYTE4_NORM:
1907 case VERTEX_FORMAT_SBYTE4_INT:
1908 case VERTEX_FORMAT_UBYTE4_INT:
1909 case VERTEX_FORMAT_SSHORT2:
1910 case VERTEX_FORMAT_SSHORT2_NORM:
1911 case VERTEX_FORMAT_USHORT2:
1912 case VERTEX_FORMAT_USHORT2_NORM:
1913 case VERTEX_FORMAT_SSHORT2_INT:
1914 case VERTEX_FORMAT_USHORT2_INT:
1915 case VERTEX_FORMAT_SINT1:
1916 case VERTEX_FORMAT_SINT1_NORM:
1917 case VERTEX_FORMAT_UINT1:
1918 case VERTEX_FORMAT_UINT1_NORM:
1919 case VERTEX_FORMAT_SINT1_INT:
1920 case VERTEX_FORMAT_UINT1_INT:
1921 case VERTEX_FORMAT_HALF2:
1922 case VERTEX_FORMAT_FIXED1:
1923 case VERTEX_FORMAT_FLOAT1:
1924 case VERTEX_FORMAT_SINT210:
1925 case VERTEX_FORMAT_UINT210:
1926 case VERTEX_FORMAT_SINT210_NORM:
1927 case VERTEX_FORMAT_UINT210_NORM:
1928 case VERTEX_FORMAT_SINT210_INT:
1929 case VERTEX_FORMAT_UINT210_INT:
1930 return 4;
1931
1932 case VERTEX_FORMAT_SSHORT3:
1933 case VERTEX_FORMAT_SSHORT3_NORM:
1934 case VERTEX_FORMAT_USHORT3:
1935 case VERTEX_FORMAT_USHORT3_NORM:
1936 case VERTEX_FORMAT_SSHORT3_INT:
1937 case VERTEX_FORMAT_USHORT3_INT:
1938 case VERTEX_FORMAT_HALF3:
1939 return 6;
1940
1941 case VERTEX_FORMAT_SSHORT4:
1942 case VERTEX_FORMAT_SSHORT4_NORM:
1943 case VERTEX_FORMAT_USHORT4:
1944 case VERTEX_FORMAT_USHORT4_NORM:
1945 case VERTEX_FORMAT_SSHORT4_INT:
1946 case VERTEX_FORMAT_USHORT4_INT:
1947 case VERTEX_FORMAT_SINT2:
1948 case VERTEX_FORMAT_SINT2_NORM:
1949 case VERTEX_FORMAT_UINT2:
1950 case VERTEX_FORMAT_UINT2_NORM:
1951 case VERTEX_FORMAT_SINT2_INT:
1952 case VERTEX_FORMAT_UINT2_INT:
1953 case VERTEX_FORMAT_HALF4:
1954 case VERTEX_FORMAT_FIXED2:
1955 case VERTEX_FORMAT_FLOAT2:
1956 return 8;
1957
1958 case VERTEX_FORMAT_SINT3:
1959 case VERTEX_FORMAT_SINT3_NORM:
1960 case VERTEX_FORMAT_UINT3:
1961 case VERTEX_FORMAT_UINT3_NORM:
1962 case VERTEX_FORMAT_SINT3_INT:
1963 case VERTEX_FORMAT_UINT3_INT:
1964 case VERTEX_FORMAT_FIXED3:
1965 case VERTEX_FORMAT_FLOAT3:
1966 return 12;
1967
1968 case VERTEX_FORMAT_SINT4:
1969 case VERTEX_FORMAT_SINT4_NORM:
1970 case VERTEX_FORMAT_UINT4:
1971 case VERTEX_FORMAT_UINT4_NORM:
1972 case VERTEX_FORMAT_SINT4_INT:
1973 case VERTEX_FORMAT_UINT4_INT:
1974 case VERTEX_FORMAT_FIXED4:
1975 case VERTEX_FORMAT_FLOAT4:
1976 return 16;
1977
1978 case VERTEX_FORMAT_INVALID:
1979 default:
1980 UNREACHABLE();
1981 return 0;
1982 }
1983}
1984
Geoff Lang6d1ccf02017-04-24 14:09:58 -04001985bool ValidES3InternalFormat(GLenum internalFormat)
1986{
1987 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1988 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
1989}
1990
Jamie Madilld3dfda22015-07-06 08:28:49 -04001991VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1992 : type(typeIn),
1993 normalized(normalizedIn),
1994 components(componentsIn),
1995 pureInteger(pureIntegerIn)
1996{
1997 // float -> !normalized
1998 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1999}
2000
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00002001}