blob: 196e11be007f20f8364dba787375f6bda3bb9eb9 [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);
714 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 Langca271392017-04-05 12:30:00 -0400715 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);
716 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);
717 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);
718 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);
719 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);
720 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);
721 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
722 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);
723
724 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);
725
726 // Unsized integer formats
727 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
728 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
729 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);
730 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
731 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);
732 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
733 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);
734 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
735 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);
736 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
737 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);
738 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
739 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);
740 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
741 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);
742 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
743 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);
744 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
745 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);
746 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
747 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);
748 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
749 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);
750 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
751 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);
752 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);
753
754 // Unsized floating point formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400755 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
756 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
757 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
758 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
759 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, NeverSupported, NeverSupported, NeverSupported );
760 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>);
761 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>);
762 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>);
763 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>);
764 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
765 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, UnsizedFloatRGSupport, UnsizedFloatRGRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
766 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, UnsizedFloatSupport, UnsizedFloatRGBRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
767 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 -0400768
769 // Unsized luminance alpha formats
Geoff Lang677bb6f2017-04-05 12:40:40 -0400770 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
771 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
772 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
773 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported );
774 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
775 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
776 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireExt<&Extensions::textureHalfFloat>, NeverSupported, RequireExt<&Extensions::textureHalfFloatLinear>);
777 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
778 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExt<&Extensions::textureFloat>, NeverSupported, RequireExt<&Extensions::textureFloatLinear> );
779 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 -0400780
781 // Unsized depth stencil formats
782 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
783 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);
784 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);
785 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
786 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);
787 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);
788 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 -0400789 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800790
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000791 return map;
792}
793
Geoff Lange4a492b2014-06-19 14:14:41 -0400794static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000795{
Geoff Lange4a492b2014-06-19 14:14:41 -0400796 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
797 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000798}
799
Geoff Lange4a492b2014-06-19 14:14:41 -0400800static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400801{
802 FormatSet result;
803
Geoff Langca271392017-04-05 12:30:00 -0400804 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400805 {
Geoff Langca271392017-04-05 12:30:00 -0400806 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400807 {
Geoff Langca271392017-04-05 12:30:00 -0400808 if (type.second.sized)
809 {
810 // TODO(jmadill): Fix this hack.
811 if (internalFormat.first == GL_BGR565_ANGLEX)
812 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400813
Geoff Langca271392017-04-05 12:30:00 -0400814 result.insert(internalFormat.first);
815 }
Geoff Langcec35902014-04-16 10:52:36 -0400816 }
817 }
818
819 return result;
820}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000821
Geoff Lang5d601382014-07-22 15:14:06 -0400822const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000823{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200824 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000825 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200826 case GL_UNSIGNED_BYTE:
827 case GL_BYTE:
828 {
829 static const Type info = GenTypeInfo(1, false);
830 return info;
831 }
832 case GL_UNSIGNED_SHORT:
833 case GL_SHORT:
834 case GL_HALF_FLOAT:
835 case GL_HALF_FLOAT_OES:
836 {
837 static const Type info = GenTypeInfo(2, false);
838 return info;
839 }
840 case GL_UNSIGNED_INT:
841 case GL_INT:
842 case GL_FLOAT:
843 {
844 static const Type info = GenTypeInfo(4, false);
845 return info;
846 }
847 case GL_UNSIGNED_SHORT_5_6_5:
848 case GL_UNSIGNED_SHORT_4_4_4_4:
849 case GL_UNSIGNED_SHORT_5_5_5_1:
850 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
851 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
852 {
853 static const Type info = GenTypeInfo(2, true);
854 return info;
855 }
856 case GL_UNSIGNED_INT_2_10_10_10_REV:
857 case GL_UNSIGNED_INT_24_8:
858 case GL_UNSIGNED_INT_10F_11F_11F_REV:
859 case GL_UNSIGNED_INT_5_9_9_9_REV:
860 {
861 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
862 static const Type info = GenTypeInfo(4, true);
863 return info;
864 }
865 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
866 {
867 static const Type info = GenTypeInfo(8, true);
868 return info;
869 }
870 default:
871 {
872 static const Type defaultInfo;
873 return defaultInfo;
874 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000875 }
876}
877
Geoff Langca271392017-04-05 12:30:00 -0400878const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000879{
Geoff Langca271392017-04-05 12:30:00 -0400880 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400881 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400882 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -0400883
884 // Sized internal formats only have one type per entry
885 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000886 {
Geoff Lang5d601382014-07-22 15:14:06 -0400887 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000888 }
Geoff Langca271392017-04-05 12:30:00 -0400889
890 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
891 if (!internalFormatInfo.sized)
892 {
893 return defaultInternalFormat;
894 }
895
896 return internalFormatInfo;
897}
898
899const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
900{
901 static const InternalFormat defaultInternalFormat;
902 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
903
904 auto internalFormatIter = formatMap.find(internalFormat);
905 if (internalFormatIter == formatMap.end())
906 {
907 return defaultInternalFormat;
908 }
909
910 // If the internal format is sized, simply return it without the type check.
911 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
912 {
913 return internalFormatIter->second.begin()->second;
914 }
915
916 auto typeIter = internalFormatIter->second.find(type);
917 if (typeIter == internalFormatIter->second.end())
918 {
919 return defaultInternalFormat;
920 }
921
922 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000923}
924
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400925GLuint InternalFormat::computePixelBytes(GLenum formatType) const
926{
927 const auto &typeInfo = GetTypeInfo(formatType);
928 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
929 return components * typeInfo.bytes;
930}
931
Corentin Wallez886de362016-09-27 10:49:35 -0400932ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400933 GLsizei width,
934 GLint alignment,
935 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000936{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700937 // Compressed images do not use pack/unpack parameters.
938 if (compressed)
939 {
940 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400941 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700942 }
943
Geoff Lang3f234062016-07-13 15:35:45 -0400944 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400945 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700946
947 ASSERT(alignment > 0 && isPow2(alignment));
948 CheckedNumeric<GLuint> checkedAlignment(alignment);
949 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
950 ANGLE_TRY_CHECKED_MATH(aligned);
951 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000952}
953
Corentin Wallez0e487192016-10-03 16:30:38 -0400954ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
955 GLint imageHeight,
956 GLuint rowPitch) const
957{
958 GLuint rows =
959 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
960 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
961
962 auto depthPitch = checkedRowPitch * rows;
963 ANGLE_TRY_CHECKED_MATH(depthPitch);
964 return depthPitch.ValueOrDie();
965}
966
Corentin Wallez886de362016-09-27 10:49:35 -0400967ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400968 GLsizei width,
969 GLsizei height,
970 GLint alignment,
971 GLint rowLength,
972 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000973{
Jamie Madille2e406c2016-06-02 13:04:10 -0400974 GLuint rowPitch = 0;
975 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400976 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000977}
978
Corentin Wallez886de362016-09-27 10:49:35 -0400979ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
980 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000981{
Jamie Madill513558d2016-06-02 13:04:11 -0400982 CheckedNumeric<GLuint> checkedWidth(size.width);
983 CheckedNumeric<GLuint> checkedHeight(size.height);
984 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700985 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
986 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400987
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700988 ASSERT(compressed);
989 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
990 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
991 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
992 ANGLE_TRY_CHECKED_MATH(bytes);
993 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000994}
995
Corentin Wallez886de362016-09-27 10:49:35 -0400996ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700997 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400998 const PixelStoreStateBase &state,
999 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -04001000{
Olli Etuaho989cac32016-06-08 16:18:49 -07001001 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
1002 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -04001003 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
1004 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
1005 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -07001006 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
1007 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -04001008 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -07001009 {
1010 checkedSkipImagesBytes = 0;
1011 }
1012 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
1013 checkedSkipPixels * checkedPixelBytes;
1014 ANGLE_TRY_CHECKED_MATH(skipBytes);
1015 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -04001016}
1017
Corentin Wallez886de362016-09-27 10:49:35 -04001018ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
1019 GLenum formatType,
1020 const Extents &size,
1021 const PixelStoreStateBase &state,
1022 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001023{
Corentin Wallez886de362016-09-27 10:49:35 -04001024 GLuint rowPitch = 0;
1025 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001026 rowPitch);
1027
Corentin Wallez0e487192016-10-03 16:30:38 -04001028 GLuint depthPitch = 0;
1029 if (is3D)
1030 {
1031 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
1032 }
1033
Corentin Wallez886de362016-09-27 10:49:35 -04001034 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001035 if (compressed)
1036 {
Corentin Wallez886de362016-09-27 10:49:35 -04001037 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -07001038 }
Corentin Wallez886de362016-09-27 10:49:35 -04001039 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001040 {
Corentin Wallez886de362016-09-27 10:49:35 -04001041 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
1042 checkedCopyBytes += size.width * bytes;
1043
1044 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
1045 checkedCopyBytes += heightMinusOne * rowPitch;
1046
1047 if (is3D)
1048 {
1049 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
1050 checkedCopyBytes += depthMinusOne * depthPitch;
1051 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -04001052 }
1053
Corentin Wallez886de362016-09-27 10:49:35 -04001054 CheckedNumeric<GLuint> checkedSkipBytes = 0;
1055 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -04001056
1057 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
1058
1059 ANGLE_TRY_CHECKED_MATH(endByte);
1060 return endByte.ValueOrDie();
1061}
1062
Geoff Langca271392017-04-05 12:30:00 -04001063GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001064{
Geoff Langca271392017-04-05 12:30:00 -04001065 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
1066 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -05001067 {
Geoff Langca271392017-04-05 12:30:00 -04001068 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -05001069 }
Geoff Langca271392017-04-05 12:30:00 -04001070
1071 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001072}
1073
Geoff Lange4a492b2014-06-19 14:14:41 -04001074const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -04001075{
Geoff Lange4a492b2014-06-19 14:14:41 -04001076 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -04001077 return formatSet;
1078}
1079
Jamie Madill09e2d932015-07-14 16:40:31 -04001080AttributeType GetAttributeType(GLenum enumValue)
1081{
1082 switch (enumValue)
1083 {
1084 case GL_FLOAT:
1085 return ATTRIBUTE_FLOAT;
1086 case GL_FLOAT_VEC2:
1087 return ATTRIBUTE_VEC2;
1088 case GL_FLOAT_VEC3:
1089 return ATTRIBUTE_VEC3;
1090 case GL_FLOAT_VEC4:
1091 return ATTRIBUTE_VEC4;
1092 case GL_INT:
1093 return ATTRIBUTE_INT;
1094 case GL_INT_VEC2:
1095 return ATTRIBUTE_IVEC2;
1096 case GL_INT_VEC3:
1097 return ATTRIBUTE_IVEC3;
1098 case GL_INT_VEC4:
1099 return ATTRIBUTE_IVEC4;
1100 case GL_UNSIGNED_INT:
1101 return ATTRIBUTE_UINT;
1102 case GL_UNSIGNED_INT_VEC2:
1103 return ATTRIBUTE_UVEC2;
1104 case GL_UNSIGNED_INT_VEC3:
1105 return ATTRIBUTE_UVEC3;
1106 case GL_UNSIGNED_INT_VEC4:
1107 return ATTRIBUTE_UVEC4;
1108 case GL_FLOAT_MAT2:
1109 return ATTRIBUTE_MAT2;
1110 case GL_FLOAT_MAT3:
1111 return ATTRIBUTE_MAT3;
1112 case GL_FLOAT_MAT4:
1113 return ATTRIBUTE_MAT4;
1114 case GL_FLOAT_MAT2x3:
1115 return ATTRIBUTE_MAT2x3;
1116 case GL_FLOAT_MAT2x4:
1117 return ATTRIBUTE_MAT2x4;
1118 case GL_FLOAT_MAT3x2:
1119 return ATTRIBUTE_MAT3x2;
1120 case GL_FLOAT_MAT3x4:
1121 return ATTRIBUTE_MAT3x4;
1122 case GL_FLOAT_MAT4x2:
1123 return ATTRIBUTE_MAT4x2;
1124 case GL_FLOAT_MAT4x3:
1125 return ATTRIBUTE_MAT4x3;
1126 default:
1127 UNREACHABLE();
1128 return ATTRIBUTE_FLOAT;
1129 }
1130}
1131
Jamie Madilld3dfda22015-07-06 08:28:49 -04001132VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1133{
1134 switch (type)
1135 {
1136 case GL_BYTE:
1137 switch (components)
1138 {
1139 case 1:
1140 if (pureInteger)
1141 return VERTEX_FORMAT_SBYTE1_INT;
1142 if (normalized)
1143 return VERTEX_FORMAT_SBYTE1_NORM;
1144 return VERTEX_FORMAT_SBYTE1;
1145 case 2:
1146 if (pureInteger)
1147 return VERTEX_FORMAT_SBYTE2_INT;
1148 if (normalized)
1149 return VERTEX_FORMAT_SBYTE2_NORM;
1150 return VERTEX_FORMAT_SBYTE2;
1151 case 3:
1152 if (pureInteger)
1153 return VERTEX_FORMAT_SBYTE3_INT;
1154 if (normalized)
1155 return VERTEX_FORMAT_SBYTE3_NORM;
1156 return VERTEX_FORMAT_SBYTE3;
1157 case 4:
1158 if (pureInteger)
1159 return VERTEX_FORMAT_SBYTE4_INT;
1160 if (normalized)
1161 return VERTEX_FORMAT_SBYTE4_NORM;
1162 return VERTEX_FORMAT_SBYTE4;
1163 default:
1164 UNREACHABLE();
1165 break;
1166 }
1167 case GL_UNSIGNED_BYTE:
1168 switch (components)
1169 {
1170 case 1:
1171 if (pureInteger)
1172 return VERTEX_FORMAT_UBYTE1_INT;
1173 if (normalized)
1174 return VERTEX_FORMAT_UBYTE1_NORM;
1175 return VERTEX_FORMAT_UBYTE1;
1176 case 2:
1177 if (pureInteger)
1178 return VERTEX_FORMAT_UBYTE2_INT;
1179 if (normalized)
1180 return VERTEX_FORMAT_UBYTE2_NORM;
1181 return VERTEX_FORMAT_UBYTE2;
1182 case 3:
1183 if (pureInteger)
1184 return VERTEX_FORMAT_UBYTE3_INT;
1185 if (normalized)
1186 return VERTEX_FORMAT_UBYTE3_NORM;
1187 return VERTEX_FORMAT_UBYTE3;
1188 case 4:
1189 if (pureInteger)
1190 return VERTEX_FORMAT_UBYTE4_INT;
1191 if (normalized)
1192 return VERTEX_FORMAT_UBYTE4_NORM;
1193 return VERTEX_FORMAT_UBYTE4;
1194 default:
1195 UNREACHABLE();
1196 break;
1197 }
1198 case GL_SHORT:
1199 switch (components)
1200 {
1201 case 1:
1202 if (pureInteger)
1203 return VERTEX_FORMAT_SSHORT1_INT;
1204 if (normalized)
1205 return VERTEX_FORMAT_SSHORT1_NORM;
1206 return VERTEX_FORMAT_SSHORT1;
1207 case 2:
1208 if (pureInteger)
1209 return VERTEX_FORMAT_SSHORT2_INT;
1210 if (normalized)
1211 return VERTEX_FORMAT_SSHORT2_NORM;
1212 return VERTEX_FORMAT_SSHORT2;
1213 case 3:
1214 if (pureInteger)
1215 return VERTEX_FORMAT_SSHORT3_INT;
1216 if (normalized)
1217 return VERTEX_FORMAT_SSHORT3_NORM;
1218 return VERTEX_FORMAT_SSHORT3;
1219 case 4:
1220 if (pureInteger)
1221 return VERTEX_FORMAT_SSHORT4_INT;
1222 if (normalized)
1223 return VERTEX_FORMAT_SSHORT4_NORM;
1224 return VERTEX_FORMAT_SSHORT4;
1225 default:
1226 UNREACHABLE();
1227 break;
1228 }
1229 case GL_UNSIGNED_SHORT:
1230 switch (components)
1231 {
1232 case 1:
1233 if (pureInteger)
1234 return VERTEX_FORMAT_USHORT1_INT;
1235 if (normalized)
1236 return VERTEX_FORMAT_USHORT1_NORM;
1237 return VERTEX_FORMAT_USHORT1;
1238 case 2:
1239 if (pureInteger)
1240 return VERTEX_FORMAT_USHORT2_INT;
1241 if (normalized)
1242 return VERTEX_FORMAT_USHORT2_NORM;
1243 return VERTEX_FORMAT_USHORT2;
1244 case 3:
1245 if (pureInteger)
1246 return VERTEX_FORMAT_USHORT3_INT;
1247 if (normalized)
1248 return VERTEX_FORMAT_USHORT3_NORM;
1249 return VERTEX_FORMAT_USHORT3;
1250 case 4:
1251 if (pureInteger)
1252 return VERTEX_FORMAT_USHORT4_INT;
1253 if (normalized)
1254 return VERTEX_FORMAT_USHORT4_NORM;
1255 return VERTEX_FORMAT_USHORT4;
1256 default:
1257 UNREACHABLE();
1258 break;
1259 }
1260 case GL_INT:
1261 switch (components)
1262 {
1263 case 1:
1264 if (pureInteger)
1265 return VERTEX_FORMAT_SINT1_INT;
1266 if (normalized)
1267 return VERTEX_FORMAT_SINT1_NORM;
1268 return VERTEX_FORMAT_SINT1;
1269 case 2:
1270 if (pureInteger)
1271 return VERTEX_FORMAT_SINT2_INT;
1272 if (normalized)
1273 return VERTEX_FORMAT_SINT2_NORM;
1274 return VERTEX_FORMAT_SINT2;
1275 case 3:
1276 if (pureInteger)
1277 return VERTEX_FORMAT_SINT3_INT;
1278 if (normalized)
1279 return VERTEX_FORMAT_SINT3_NORM;
1280 return VERTEX_FORMAT_SINT3;
1281 case 4:
1282 if (pureInteger)
1283 return VERTEX_FORMAT_SINT4_INT;
1284 if (normalized)
1285 return VERTEX_FORMAT_SINT4_NORM;
1286 return VERTEX_FORMAT_SINT4;
1287 default:
1288 UNREACHABLE();
1289 break;
1290 }
1291 case GL_UNSIGNED_INT:
1292 switch (components)
1293 {
1294 case 1:
1295 if (pureInteger)
1296 return VERTEX_FORMAT_UINT1_INT;
1297 if (normalized)
1298 return VERTEX_FORMAT_UINT1_NORM;
1299 return VERTEX_FORMAT_UINT1;
1300 case 2:
1301 if (pureInteger)
1302 return VERTEX_FORMAT_UINT2_INT;
1303 if (normalized)
1304 return VERTEX_FORMAT_UINT2_NORM;
1305 return VERTEX_FORMAT_UINT2;
1306 case 3:
1307 if (pureInteger)
1308 return VERTEX_FORMAT_UINT3_INT;
1309 if (normalized)
1310 return VERTEX_FORMAT_UINT3_NORM;
1311 return VERTEX_FORMAT_UINT3;
1312 case 4:
1313 if (pureInteger)
1314 return VERTEX_FORMAT_UINT4_INT;
1315 if (normalized)
1316 return VERTEX_FORMAT_UINT4_NORM;
1317 return VERTEX_FORMAT_UINT4;
1318 default:
1319 UNREACHABLE();
1320 break;
1321 }
1322 case GL_FLOAT:
1323 switch (components)
1324 {
1325 case 1:
1326 return VERTEX_FORMAT_FLOAT1;
1327 case 2:
1328 return VERTEX_FORMAT_FLOAT2;
1329 case 3:
1330 return VERTEX_FORMAT_FLOAT3;
1331 case 4:
1332 return VERTEX_FORMAT_FLOAT4;
1333 default:
1334 UNREACHABLE();
1335 break;
1336 }
1337 case GL_HALF_FLOAT:
1338 switch (components)
1339 {
1340 case 1:
1341 return VERTEX_FORMAT_HALF1;
1342 case 2:
1343 return VERTEX_FORMAT_HALF2;
1344 case 3:
1345 return VERTEX_FORMAT_HALF3;
1346 case 4:
1347 return VERTEX_FORMAT_HALF4;
1348 default:
1349 UNREACHABLE();
1350 break;
1351 }
1352 case GL_FIXED:
1353 switch (components)
1354 {
1355 case 1:
1356 return VERTEX_FORMAT_FIXED1;
1357 case 2:
1358 return VERTEX_FORMAT_FIXED2;
1359 case 3:
1360 return VERTEX_FORMAT_FIXED3;
1361 case 4:
1362 return VERTEX_FORMAT_FIXED4;
1363 default:
1364 UNREACHABLE();
1365 break;
1366 }
1367 case GL_INT_2_10_10_10_REV:
1368 if (pureInteger)
1369 return VERTEX_FORMAT_SINT210_INT;
1370 if (normalized)
1371 return VERTEX_FORMAT_SINT210_NORM;
1372 return VERTEX_FORMAT_SINT210;
1373 case GL_UNSIGNED_INT_2_10_10_10_REV:
1374 if (pureInteger)
1375 return VERTEX_FORMAT_UINT210_INT;
1376 if (normalized)
1377 return VERTEX_FORMAT_UINT210_NORM;
1378 return VERTEX_FORMAT_UINT210;
1379 default:
1380 UNREACHABLE();
1381 break;
1382 }
1383 return VERTEX_FORMAT_UBYTE1;
1384}
1385
1386VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1387{
1388 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1389}
1390
1391VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1392{
1393 if (!attrib.enabled)
1394 {
1395 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1396 }
1397 return GetVertexFormatType(attrib);
1398}
1399
1400const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1401{
1402 switch (vertexFormatType)
1403 {
1404 case VERTEX_FORMAT_SBYTE1:
1405 {
1406 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1407 return format;
1408 }
1409 case VERTEX_FORMAT_SBYTE1_NORM:
1410 {
1411 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1412 return format;
1413 }
1414 case VERTEX_FORMAT_SBYTE2:
1415 {
1416 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1417 return format;
1418 }
1419 case VERTEX_FORMAT_SBYTE2_NORM:
1420 {
1421 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1422 return format;
1423 }
1424 case VERTEX_FORMAT_SBYTE3:
1425 {
1426 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1427 return format;
1428 }
1429 case VERTEX_FORMAT_SBYTE3_NORM:
1430 {
1431 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1432 return format;
1433 }
1434 case VERTEX_FORMAT_SBYTE4:
1435 {
1436 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1437 return format;
1438 }
1439 case VERTEX_FORMAT_SBYTE4_NORM:
1440 {
1441 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1442 return format;
1443 }
1444 case VERTEX_FORMAT_UBYTE1:
1445 {
1446 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1447 return format;
1448 }
1449 case VERTEX_FORMAT_UBYTE1_NORM:
1450 {
1451 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1452 return format;
1453 }
1454 case VERTEX_FORMAT_UBYTE2:
1455 {
1456 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1457 return format;
1458 }
1459 case VERTEX_FORMAT_UBYTE2_NORM:
1460 {
1461 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1462 return format;
1463 }
1464 case VERTEX_FORMAT_UBYTE3:
1465 {
1466 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1467 return format;
1468 }
1469 case VERTEX_FORMAT_UBYTE3_NORM:
1470 {
1471 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1472 return format;
1473 }
1474 case VERTEX_FORMAT_UBYTE4:
1475 {
1476 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1477 return format;
1478 }
1479 case VERTEX_FORMAT_UBYTE4_NORM:
1480 {
1481 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1482 return format;
1483 }
1484 case VERTEX_FORMAT_SSHORT1:
1485 {
1486 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1487 return format;
1488 }
1489 case VERTEX_FORMAT_SSHORT1_NORM:
1490 {
1491 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1492 return format;
1493 }
1494 case VERTEX_FORMAT_SSHORT2:
1495 {
1496 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1497 return format;
1498 }
1499 case VERTEX_FORMAT_SSHORT2_NORM:
1500 {
1501 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1502 return format;
1503 }
1504 case VERTEX_FORMAT_SSHORT3:
1505 {
1506 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1507 return format;
1508 }
1509 case VERTEX_FORMAT_SSHORT3_NORM:
1510 {
1511 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1512 return format;
1513 }
1514 case VERTEX_FORMAT_SSHORT4:
1515 {
1516 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1517 return format;
1518 }
1519 case VERTEX_FORMAT_SSHORT4_NORM:
1520 {
1521 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1522 return format;
1523 }
1524 case VERTEX_FORMAT_USHORT1:
1525 {
1526 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1527 return format;
1528 }
1529 case VERTEX_FORMAT_USHORT1_NORM:
1530 {
1531 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1532 return format;
1533 }
1534 case VERTEX_FORMAT_USHORT2:
1535 {
1536 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1537 return format;
1538 }
1539 case VERTEX_FORMAT_USHORT2_NORM:
1540 {
1541 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1542 return format;
1543 }
1544 case VERTEX_FORMAT_USHORT3:
1545 {
1546 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1547 return format;
1548 }
1549 case VERTEX_FORMAT_USHORT3_NORM:
1550 {
1551 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1552 return format;
1553 }
1554 case VERTEX_FORMAT_USHORT4:
1555 {
1556 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1557 return format;
1558 }
1559 case VERTEX_FORMAT_USHORT4_NORM:
1560 {
1561 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1562 return format;
1563 }
1564 case VERTEX_FORMAT_SINT1:
1565 {
1566 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1567 return format;
1568 }
1569 case VERTEX_FORMAT_SINT1_NORM:
1570 {
1571 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1572 return format;
1573 }
1574 case VERTEX_FORMAT_SINT2:
1575 {
1576 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1577 return format;
1578 }
1579 case VERTEX_FORMAT_SINT2_NORM:
1580 {
1581 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1582 return format;
1583 }
1584 case VERTEX_FORMAT_SINT3:
1585 {
1586 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1587 return format;
1588 }
1589 case VERTEX_FORMAT_SINT3_NORM:
1590 {
1591 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1592 return format;
1593 }
1594 case VERTEX_FORMAT_SINT4:
1595 {
1596 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1597 return format;
1598 }
1599 case VERTEX_FORMAT_SINT4_NORM:
1600 {
1601 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1602 return format;
1603 }
1604 case VERTEX_FORMAT_UINT1:
1605 {
1606 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1607 return format;
1608 }
1609 case VERTEX_FORMAT_UINT1_NORM:
1610 {
1611 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1612 return format;
1613 }
1614 case VERTEX_FORMAT_UINT2:
1615 {
1616 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1617 return format;
1618 }
1619 case VERTEX_FORMAT_UINT2_NORM:
1620 {
1621 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1622 return format;
1623 }
1624 case VERTEX_FORMAT_UINT3:
1625 {
1626 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1627 return format;
1628 }
1629 case VERTEX_FORMAT_UINT3_NORM:
1630 {
1631 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1632 return format;
1633 }
1634 case VERTEX_FORMAT_UINT4:
1635 {
1636 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1637 return format;
1638 }
1639 case VERTEX_FORMAT_UINT4_NORM:
1640 {
1641 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1642 return format;
1643 }
1644 case VERTEX_FORMAT_SBYTE1_INT:
1645 {
1646 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1647 return format;
1648 }
1649 case VERTEX_FORMAT_SBYTE2_INT:
1650 {
1651 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1652 return format;
1653 }
1654 case VERTEX_FORMAT_SBYTE3_INT:
1655 {
1656 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1657 return format;
1658 }
1659 case VERTEX_FORMAT_SBYTE4_INT:
1660 {
1661 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1662 return format;
1663 }
1664 case VERTEX_FORMAT_UBYTE1_INT:
1665 {
1666 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1667 return format;
1668 }
1669 case VERTEX_FORMAT_UBYTE2_INT:
1670 {
1671 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1672 return format;
1673 }
1674 case VERTEX_FORMAT_UBYTE3_INT:
1675 {
1676 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1677 return format;
1678 }
1679 case VERTEX_FORMAT_UBYTE4_INT:
1680 {
1681 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1682 return format;
1683 }
1684 case VERTEX_FORMAT_SSHORT1_INT:
1685 {
1686 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1687 return format;
1688 }
1689 case VERTEX_FORMAT_SSHORT2_INT:
1690 {
1691 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1692 return format;
1693 }
1694 case VERTEX_FORMAT_SSHORT3_INT:
1695 {
1696 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1697 return format;
1698 }
1699 case VERTEX_FORMAT_SSHORT4_INT:
1700 {
1701 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1702 return format;
1703 }
1704 case VERTEX_FORMAT_USHORT1_INT:
1705 {
1706 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1707 return format;
1708 }
1709 case VERTEX_FORMAT_USHORT2_INT:
1710 {
1711 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1712 return format;
1713 }
1714 case VERTEX_FORMAT_USHORT3_INT:
1715 {
1716 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1717 return format;
1718 }
1719 case VERTEX_FORMAT_USHORT4_INT:
1720 {
1721 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1722 return format;
1723 }
1724 case VERTEX_FORMAT_SINT1_INT:
1725 {
1726 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1727 return format;
1728 }
1729 case VERTEX_FORMAT_SINT2_INT:
1730 {
1731 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1732 return format;
1733 }
1734 case VERTEX_FORMAT_SINT3_INT:
1735 {
1736 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1737 return format;
1738 }
1739 case VERTEX_FORMAT_SINT4_INT:
1740 {
1741 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1742 return format;
1743 }
1744 case VERTEX_FORMAT_UINT1_INT:
1745 {
1746 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1747 return format;
1748 }
1749 case VERTEX_FORMAT_UINT2_INT:
1750 {
1751 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1752 return format;
1753 }
1754 case VERTEX_FORMAT_UINT3_INT:
1755 {
1756 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1757 return format;
1758 }
1759 case VERTEX_FORMAT_UINT4_INT:
1760 {
1761 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1762 return format;
1763 }
1764 case VERTEX_FORMAT_FIXED1:
1765 {
1766 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1767 return format;
1768 }
1769 case VERTEX_FORMAT_FIXED2:
1770 {
1771 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1772 return format;
1773 }
1774 case VERTEX_FORMAT_FIXED3:
1775 {
1776 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1777 return format;
1778 }
1779 case VERTEX_FORMAT_FIXED4:
1780 {
1781 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1782 return format;
1783 }
1784 case VERTEX_FORMAT_HALF1:
1785 {
1786 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1787 return format;
1788 }
1789 case VERTEX_FORMAT_HALF2:
1790 {
1791 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1792 return format;
1793 }
1794 case VERTEX_FORMAT_HALF3:
1795 {
1796 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1797 return format;
1798 }
1799 case VERTEX_FORMAT_HALF4:
1800 {
1801 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1802 return format;
1803 }
1804 case VERTEX_FORMAT_FLOAT1:
1805 {
1806 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1807 return format;
1808 }
1809 case VERTEX_FORMAT_FLOAT2:
1810 {
1811 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1812 return format;
1813 }
1814 case VERTEX_FORMAT_FLOAT3:
1815 {
1816 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1817 return format;
1818 }
1819 case VERTEX_FORMAT_FLOAT4:
1820 {
1821 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1822 return format;
1823 }
1824 case VERTEX_FORMAT_SINT210:
1825 {
1826 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1827 return format;
1828 }
1829 case VERTEX_FORMAT_UINT210:
1830 {
1831 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1832 return format;
1833 }
1834 case VERTEX_FORMAT_SINT210_NORM:
1835 {
1836 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1837 return format;
1838 }
1839 case VERTEX_FORMAT_UINT210_NORM:
1840 {
1841 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1842 return format;
1843 }
1844 case VERTEX_FORMAT_SINT210_INT:
1845 {
1846 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1847 return format;
1848 }
1849 case VERTEX_FORMAT_UINT210_INT:
1850 {
1851 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1852 return format;
1853 }
1854 default:
1855 {
1856 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1857 return format;
1858 }
1859 }
1860}
1861
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001862size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1863{
1864 switch (vertexFormatType)
1865 {
1866 case VERTEX_FORMAT_SBYTE1:
1867 case VERTEX_FORMAT_SBYTE1_NORM:
1868 case VERTEX_FORMAT_UBYTE1:
1869 case VERTEX_FORMAT_UBYTE1_NORM:
1870 case VERTEX_FORMAT_SBYTE1_INT:
1871 case VERTEX_FORMAT_UBYTE1_INT:
1872 return 1;
1873
1874 case VERTEX_FORMAT_SBYTE2:
1875 case VERTEX_FORMAT_SBYTE2_NORM:
1876 case VERTEX_FORMAT_UBYTE2:
1877 case VERTEX_FORMAT_UBYTE2_NORM:
1878 case VERTEX_FORMAT_SBYTE2_INT:
1879 case VERTEX_FORMAT_UBYTE2_INT:
1880 case VERTEX_FORMAT_SSHORT1:
1881 case VERTEX_FORMAT_SSHORT1_NORM:
1882 case VERTEX_FORMAT_USHORT1:
1883 case VERTEX_FORMAT_USHORT1_NORM:
1884 case VERTEX_FORMAT_SSHORT1_INT:
1885 case VERTEX_FORMAT_USHORT1_INT:
1886 case VERTEX_FORMAT_HALF1:
1887 return 2;
1888
1889 case VERTEX_FORMAT_SBYTE3:
1890 case VERTEX_FORMAT_SBYTE3_NORM:
1891 case VERTEX_FORMAT_UBYTE3:
1892 case VERTEX_FORMAT_UBYTE3_NORM:
1893 case VERTEX_FORMAT_SBYTE3_INT:
1894 case VERTEX_FORMAT_UBYTE3_INT:
1895 return 3;
1896
1897 case VERTEX_FORMAT_SBYTE4:
1898 case VERTEX_FORMAT_SBYTE4_NORM:
1899 case VERTEX_FORMAT_UBYTE4:
1900 case VERTEX_FORMAT_UBYTE4_NORM:
1901 case VERTEX_FORMAT_SBYTE4_INT:
1902 case VERTEX_FORMAT_UBYTE4_INT:
1903 case VERTEX_FORMAT_SSHORT2:
1904 case VERTEX_FORMAT_SSHORT2_NORM:
1905 case VERTEX_FORMAT_USHORT2:
1906 case VERTEX_FORMAT_USHORT2_NORM:
1907 case VERTEX_FORMAT_SSHORT2_INT:
1908 case VERTEX_FORMAT_USHORT2_INT:
1909 case VERTEX_FORMAT_SINT1:
1910 case VERTEX_FORMAT_SINT1_NORM:
1911 case VERTEX_FORMAT_UINT1:
1912 case VERTEX_FORMAT_UINT1_NORM:
1913 case VERTEX_FORMAT_SINT1_INT:
1914 case VERTEX_FORMAT_UINT1_INT:
1915 case VERTEX_FORMAT_HALF2:
1916 case VERTEX_FORMAT_FIXED1:
1917 case VERTEX_FORMAT_FLOAT1:
1918 case VERTEX_FORMAT_SINT210:
1919 case VERTEX_FORMAT_UINT210:
1920 case VERTEX_FORMAT_SINT210_NORM:
1921 case VERTEX_FORMAT_UINT210_NORM:
1922 case VERTEX_FORMAT_SINT210_INT:
1923 case VERTEX_FORMAT_UINT210_INT:
1924 return 4;
1925
1926 case VERTEX_FORMAT_SSHORT3:
1927 case VERTEX_FORMAT_SSHORT3_NORM:
1928 case VERTEX_FORMAT_USHORT3:
1929 case VERTEX_FORMAT_USHORT3_NORM:
1930 case VERTEX_FORMAT_SSHORT3_INT:
1931 case VERTEX_FORMAT_USHORT3_INT:
1932 case VERTEX_FORMAT_HALF3:
1933 return 6;
1934
1935 case VERTEX_FORMAT_SSHORT4:
1936 case VERTEX_FORMAT_SSHORT4_NORM:
1937 case VERTEX_FORMAT_USHORT4:
1938 case VERTEX_FORMAT_USHORT4_NORM:
1939 case VERTEX_FORMAT_SSHORT4_INT:
1940 case VERTEX_FORMAT_USHORT4_INT:
1941 case VERTEX_FORMAT_SINT2:
1942 case VERTEX_FORMAT_SINT2_NORM:
1943 case VERTEX_FORMAT_UINT2:
1944 case VERTEX_FORMAT_UINT2_NORM:
1945 case VERTEX_FORMAT_SINT2_INT:
1946 case VERTEX_FORMAT_UINT2_INT:
1947 case VERTEX_FORMAT_HALF4:
1948 case VERTEX_FORMAT_FIXED2:
1949 case VERTEX_FORMAT_FLOAT2:
1950 return 8;
1951
1952 case VERTEX_FORMAT_SINT3:
1953 case VERTEX_FORMAT_SINT3_NORM:
1954 case VERTEX_FORMAT_UINT3:
1955 case VERTEX_FORMAT_UINT3_NORM:
1956 case VERTEX_FORMAT_SINT3_INT:
1957 case VERTEX_FORMAT_UINT3_INT:
1958 case VERTEX_FORMAT_FIXED3:
1959 case VERTEX_FORMAT_FLOAT3:
1960 return 12;
1961
1962 case VERTEX_FORMAT_SINT4:
1963 case VERTEX_FORMAT_SINT4_NORM:
1964 case VERTEX_FORMAT_UINT4:
1965 case VERTEX_FORMAT_UINT4_NORM:
1966 case VERTEX_FORMAT_SINT4_INT:
1967 case VERTEX_FORMAT_UINT4_INT:
1968 case VERTEX_FORMAT_FIXED4:
1969 case VERTEX_FORMAT_FLOAT4:
1970 return 16;
1971
1972 case VERTEX_FORMAT_INVALID:
1973 default:
1974 UNREACHABLE();
1975 return 0;
1976 }
1977}
1978
Geoff Lang6d1ccf02017-04-24 14:09:58 -04001979bool ValidES3InternalFormat(GLenum internalFormat)
1980{
1981 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1982 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
1983}
1984
Jamie Madilld3dfda22015-07-06 08:28:49 -04001985VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1986 : type(typeIn),
1987 normalized(normalizedIn),
1988 components(componentsIn),
1989 pureInteger(pureIntegerIn)
1990{
1991 // float -> !normalized
1992 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1993}
1994
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001995}