blob: d0b5eb88dcd1ffb1a4230112f5eaec4d670662c9 [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 Langeb66a6e2016-10-31 13:06:12 -0400151static bool HalfFloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500152{
153 return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat;
154}
155
156// Special function for half float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400157static bool HalfFloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500158{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400159 return clientVersion >= Version(3, 0) || (extensions.textureHalfFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500160}
161
Geoff Langeb66a6e2016-10-31 13:06:12 -0400162static bool HalfFloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500163{
164 return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat;
165}
166
167// Special function for float formats with three or four channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400168static bool FloatSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500169{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400170 return clientVersion >= Version(3, 0) || extensions.textureFloat;
Jamie Madillcd089732015-12-17 09:53:09 -0500171}
172
Geoff Langeb66a6e2016-10-31 13:06:12 -0400173static bool FloatRenderableSupport(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500174{
175 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
176 return FloatSupport(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400177 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500178}
179
180// Special function for float formats with one or two channels.
Geoff Langeb66a6e2016-10-31 13:06:12 -0400181static bool FloatSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500182{
Geoff Langeb66a6e2016-10-31 13:06:12 -0400183 return clientVersion >= Version(3, 0) || (extensions.textureFloat && extensions.textureRG);
Jamie Madillcd089732015-12-17 09:53:09 -0500184}
185
Geoff Langeb66a6e2016-10-31 13:06:12 -0400186static bool FloatRenderableSupportRG(const Version &clientVersion, const Extensions &extensions)
Jamie Madillcd089732015-12-17 09:53:09 -0500187{
188 // We don't expose colorBufferFloat in ES2, but we silently support rendering to float.
189 return FloatSupportRG(clientVersion, extensions) &&
Geoff Langeb66a6e2016-10-31 13:06:12 -0400190 (extensions.colorBufferFloat || clientVersion == Version(2, 0));
Jamie Madillcd089732015-12-17 09:53:09 -0500191}
192
Geoff Lang5d601382014-07-22 15:14:06 -0400193InternalFormat::InternalFormat()
Jamie Madilla3944d42016-07-22 22:13:26 -0400194 : internalFormat(GL_NONE),
Geoff Langca271392017-04-05 12:30:00 -0400195 sized(false),
196 sizedInternalFormat(GL_NONE),
Jamie Madilla3944d42016-07-22 22:13:26 -0400197 redBits(0),
Geoff Lang5d601382014-07-22 15:14:06 -0400198 greenBits(0),
199 blueBits(0),
200 luminanceBits(0),
201 alphaBits(0),
202 sharedBits(0),
203 depthBits(0),
204 stencilBits(0),
205 pixelBytes(0),
206 componentCount(0),
Corentin Wallezbc99bb62015-05-14 17:42:20 -0400207 compressed(false),
Geoff Lang5d601382014-07-22 15:14:06 -0400208 compressedBlockWidth(0),
209 compressedBlockHeight(0),
210 format(GL_NONE),
211 type(GL_NONE),
212 componentType(GL_NONE),
213 colorEncoding(GL_NONE),
Geoff Lang5d601382014-07-22 15:14:06 -0400214 textureSupport(NeverSupported),
215 renderSupport(NeverSupported),
216 filterSupport(NeverSupported)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000217{
Geoff Lang5d601382014-07-22 15:14:06 -0400218}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000219
Jamie Madilla3944d42016-07-22 22:13:26 -0400220bool InternalFormat::isLUMA() const
221{
222 return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 &&
223 (luminanceBits + alphaBits) > 0);
224}
225
Geoff Langf607c602016-09-21 11:46:48 -0400226GLenum InternalFormat::getReadPixelsFormat() const
227{
228 return format;
229}
230
231GLenum InternalFormat::getReadPixelsType() const
232{
233 switch (type)
234 {
235 case GL_HALF_FLOAT:
236 // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as
237 // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by
238 // OES_texture_half_float
239 return GL_HALF_FLOAT_OES;
240
241 default:
242 return type;
243 }
244}
245
Geoff Langca271392017-04-05 12:30:00 -0400246Format::Format(GLenum internalFormat) : Format(GetSizedInternalFormatInfo(internalFormat))
Jamie Madilla3944d42016-07-22 22:13:26 -0400247{
248}
249
Geoff Langca271392017-04-05 12:30:00 -0400250Format::Format(const InternalFormat &internalFormat) : info(&internalFormat)
Jamie Madilla3944d42016-07-22 22:13:26 -0400251{
Jamie Madilla3944d42016-07-22 22:13:26 -0400252}
253
Geoff Langca271392017-04-05 12:30:00 -0400254Format::Format(GLenum internalFormat, GLenum type)
255 : info(&GetInternalFormatInfo(internalFormat, type))
Jamie Madilla3944d42016-07-22 22:13:26 -0400256{
Jamie Madilla3944d42016-07-22 22:13:26 -0400257}
258
259Format::Format(const Format &other) = default;
260Format &Format::operator=(const Format &other) = default;
261
Jamie Madilla3944d42016-07-22 22:13:26 -0400262bool Format::valid() const
263{
Geoff Langca271392017-04-05 12:30:00 -0400264 return info->internalFormat != GL_NONE;
Jamie Madilla3944d42016-07-22 22:13:26 -0400265}
266
267// static
268bool Format::SameSized(const Format &a, const Format &b)
269{
Geoff Langca271392017-04-05 12:30:00 -0400270 return a.info->sizedInternalFormat == b.info->sizedInternalFormat;
Jamie Madilla3944d42016-07-22 22:13:26 -0400271}
272
273// static
274Format Format::Invalid()
275{
Geoff Langca271392017-04-05 12:30:00 -0400276 static Format invalid(GL_NONE, GL_NONE);
Jamie Madilla3944d42016-07-22 22:13:26 -0400277 return invalid;
278}
279
Yuly Novikovd73f8522017-01-13 17:48:57 -0500280std::ostream &operator<<(std::ostream &os, const Format &fmt)
281{
282 // TODO(ynovikov): return string representation when available
Geoff Langca271392017-04-05 12:30:00 -0400283 return FmtHexShort(os, fmt.info->sizedInternalFormat);
Yuly Novikovd73f8522017-01-13 17:48:57 -0500284}
285
Jamie Madilla3944d42016-07-22 22:13:26 -0400286bool InternalFormat::operator==(const InternalFormat &other) const
287{
Geoff Langca271392017-04-05 12:30:00 -0400288 // We assume all internal formats are unique if they have the same internal format and type
289 return internalFormat == other.internalFormat && type == other.type;
Jamie Madilla3944d42016-07-22 22:13:26 -0400290}
291
292bool InternalFormat::operator!=(const InternalFormat &other) const
293{
Geoff Langca271392017-04-05 12:30:00 -0400294 return !(*this == other);
Jamie Madilla3944d42016-07-22 22:13:26 -0400295}
296
Geoff Langca271392017-04-05 12:30:00 -0400297void InsertFormatInfo(InternalFormatInfoMap *map, const InternalFormat &formatInfo)
Geoff Lang5d601382014-07-22 15:14:06 -0400298{
Geoff Langca271392017-04-05 12:30:00 -0400299 ASSERT(!formatInfo.sized || (*map).count(formatInfo.internalFormat) == 0);
300 ASSERT((*map)[formatInfo.internalFormat].count(formatInfo.type) == 0);
301 (*map)[formatInfo.internalFormat][formatInfo.type] = formatInfo;
Geoff Lang5d601382014-07-22 15:14:06 -0400302}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000303
Jamie Madilla3944d42016-07-22 22:13:26 -0400304void AddRGBAFormat(InternalFormatInfoMap *map,
305 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400306 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400307 GLuint red,
308 GLuint green,
309 GLuint blue,
310 GLuint alpha,
311 GLuint shared,
312 GLenum format,
313 GLenum type,
314 GLenum componentType,
315 bool srgb,
316 InternalFormat::SupportCheckFunction textureSupport,
317 InternalFormat::SupportCheckFunction renderSupport,
318 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400319{
320 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400321 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400322 formatInfo.sized = sized;
323 formatInfo.sizedInternalFormat =
324 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400325 formatInfo.redBits = red;
326 formatInfo.greenBits = green;
327 formatInfo.blueBits = blue;
328 formatInfo.alphaBits = alpha;
329 formatInfo.sharedBits = shared;
330 formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8;
Geoff Langca271392017-04-05 12:30:00 -0400331 formatInfo.componentCount =
332 ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
Geoff Lang5d601382014-07-22 15:14:06 -0400333 formatInfo.format = format;
334 formatInfo.type = type;
335 formatInfo.componentType = componentType;
336 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
337 formatInfo.textureSupport = textureSupport;
338 formatInfo.renderSupport = renderSupport;
339 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400340
341 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400342}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000343
Geoff Langca271392017-04-05 12:30:00 -0400344static void AddLUMAFormat(InternalFormatInfoMap *map,
345 GLenum internalFormat,
346 bool sized,
347 GLuint luminance,
348 GLuint alpha,
349 GLenum format,
350 GLenum type,
351 GLenum componentType,
352 InternalFormat::SupportCheckFunction textureSupport,
353 InternalFormat::SupportCheckFunction renderSupport,
354 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400355{
356 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400357 formatInfo.internalFormat = internalFormat;
358 formatInfo.sized = sized;
359 formatInfo.sizedInternalFormat =
360 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400361 formatInfo.luminanceBits = luminance;
362 formatInfo.alphaBits = alpha;
363 formatInfo.pixelBytes = (luminance + alpha) / 8;
364 formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0);
365 formatInfo.format = format;
366 formatInfo.type = type;
367 formatInfo.componentType = componentType;
368 formatInfo.colorEncoding = GL_LINEAR;
369 formatInfo.textureSupport = textureSupport;
370 formatInfo.renderSupport = renderSupport;
371 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400372
373 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400374}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000375
Jamie Madilla3944d42016-07-22 22:13:26 -0400376void AddDepthStencilFormat(InternalFormatInfoMap *map,
377 GLenum internalFormat,
Geoff Langca271392017-04-05 12:30:00 -0400378 bool sized,
Jamie Madilla3944d42016-07-22 22:13:26 -0400379 GLuint depthBits,
380 GLuint stencilBits,
381 GLuint unusedBits,
382 GLenum format,
383 GLenum type,
384 GLenum componentType,
385 InternalFormat::SupportCheckFunction textureSupport,
386 InternalFormat::SupportCheckFunction renderSupport,
387 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400388{
389 InternalFormat formatInfo;
Jamie Madilla3944d42016-07-22 22:13:26 -0400390 formatInfo.internalFormat = internalFormat;
Geoff Langca271392017-04-05 12:30:00 -0400391 formatInfo.sized = sized;
392 formatInfo.sizedInternalFormat =
393 sized ? internalFormat : GetSizedFormatInternal(internalFormat, type);
Geoff Lang5d601382014-07-22 15:14:06 -0400394 formatInfo.depthBits = depthBits;
395 formatInfo.stencilBits = stencilBits;
396 formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8;
397 formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0);
398 formatInfo.format = format;
399 formatInfo.type = type;
400 formatInfo.componentType = componentType;
401 formatInfo.colorEncoding = GL_LINEAR;
402 formatInfo.textureSupport = textureSupport;
403 formatInfo.renderSupport = renderSupport;
404 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400405
406 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400407}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000408
Geoff Langca271392017-04-05 12:30:00 -0400409void AddCompressedFormat(InternalFormatInfoMap *map,
410 GLenum internalFormat,
411 GLuint compressedBlockWidth,
412 GLuint compressedBlockHeight,
413 GLuint compressedBlockSize,
414 GLuint componentCount,
415 GLenum format,
416 GLenum type,
417 bool srgb,
418 InternalFormat::SupportCheckFunction textureSupport,
419 InternalFormat::SupportCheckFunction renderSupport,
420 InternalFormat::SupportCheckFunction filterSupport)
Geoff Lang5d601382014-07-22 15:14:06 -0400421{
422 InternalFormat formatInfo;
Geoff Langca271392017-04-05 12:30:00 -0400423 formatInfo.internalFormat = internalFormat;
424 formatInfo.sized = true;
425 formatInfo.sizedInternalFormat = internalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400426 formatInfo.compressedBlockWidth = compressedBlockWidth;
427 formatInfo.compressedBlockHeight = compressedBlockHeight;
428 formatInfo.pixelBytes = compressedBlockSize / 8;
429 formatInfo.componentCount = componentCount;
430 formatInfo.format = format;
431 formatInfo.type = type;
432 formatInfo.componentType = GL_UNSIGNED_NORMALIZED;
433 formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR);
434 formatInfo.compressed = true;
435 formatInfo.textureSupport = textureSupport;
436 formatInfo.renderSupport = renderSupport;
437 formatInfo.filterSupport = filterSupport;
Geoff Langca271392017-04-05 12:30:00 -0400438
439 InsertFormatInfo(map, formatInfo);
Geoff Lang5d601382014-07-22 15:14:06 -0400440}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000441
Geoff Lange4a492b2014-06-19 14:14:41 -0400442static InternalFormatInfoMap BuildInternalFormatInfoMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000443{
444 InternalFormatInfoMap map;
445
446 // From ES 3.0.1 spec, table 3.12
Geoff Langca271392017-04-05 12:30:00 -0400447 map[GL_NONE][GL_NONE] = InternalFormat();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000448
Jamie Madilla3944d42016-07-22 22:13:26 -0400449 // clang-format off
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000450
Geoff Langca271392017-04-05 12:30:00 -0400451 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
452 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);
453 AddRGBAFormat(&map, GL_R8_SNORM, true, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
454 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);
455 AddRGBAFormat(&map, GL_RG8_SNORM, true, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
456 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);
457 AddRGBAFormat(&map, GL_RGB8_SNORM, true, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
458 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);
459 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);
460 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);
461 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);
462 AddRGBAFormat(&map, GL_RGBA8_SNORM, true, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
463 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);
464 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);
465 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);
466 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);
467 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);
468 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);
469 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);
470 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);
471 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);
472 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);
473 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);
474 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);
475 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);
476 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);
477 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);
478 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);
479 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);
480 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);
481 AddRGBAFormat(&map, GL_RGB8I, true, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
482 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);
483 AddRGBAFormat(&map, GL_RGB16I, true, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
484 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);
485 AddRGBAFormat(&map, GL_RGB32I, true, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
486 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);
487 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);
488 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);
489 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);
490 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);
491 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);
492 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 -0400493
Geoff Langca271392017-04-05 12:30:00 -0400494 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);
495 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);
496 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 +0000497
Jamie Madillec0b5802016-07-04 13:11:59 -0400498 // Special format which is not really supported, so always false for all supports.
Geoff Langca271392017-04-05 12:30:00 -0400499 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 -0400500
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000501 // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float
Geoff Langca271392017-04-05 12:30:00 -0400502 // | Internal format |sized| D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
503 // | | | | | | | type | | | | |
504 AddRGBAFormat(&map, GL_R16F, true, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
505 AddRGBAFormat(&map, GL_RG16F, true, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>);
506 AddRGBAFormat(&map, GL_RGB16F, true, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
507 AddRGBAFormat(&map, GL_RGBA16F, true, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>);
508 AddRGBAFormat(&map, GL_R32F, true, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
509 AddRGBAFormat(&map, GL_RG32F, true, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> );
510 AddRGBAFormat(&map, GL_RGB32F, true, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
511 AddRGBAFormat(&map, GL_RGBA32F, true, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> );
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000512
513 // Depth stencil formats
Geoff Langca271392017-04-05 12:30:00 -0400514 // | Internal format |sized| D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
515 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>);
516 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>);
517 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>);
518 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 );
519 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 );
520 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 -0800521 // STENCIL_INDEX8 is special-cased, see around the bottom of the list.
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000522
523 // Luminance alpha formats
Geoff Langca271392017-04-05 12:30:00 -0400524 // | Internal format |sized| L | A | Format | Type | Component type | Supported | Renderable | Filterable |
525 AddLUMAFormat(&map, GL_ALPHA8_EXT, true, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
526 AddLUMAFormat(&map, GL_LUMINANCE8_EXT, true, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
527 AddLUMAFormat(&map, GL_ALPHA32F_EXT, true, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported);
528 AddLUMAFormat(&map, GL_LUMINANCE32F_EXT, true, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported);
529 AddLUMAFormat(&map, GL_ALPHA16F_EXT, true, 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported);
530 AddLUMAFormat(&map, GL_LUMINANCE16F_EXT, true, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported);
531 AddLUMAFormat(&map, GL_LUMINANCE8_ALPHA8_EXT, true, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported);
532 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA32F_EXT, true, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported);
533 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA16F_EXT, true, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000534
535 // Compressed formats, From ES 3.0.1 spec, table 3.16
Geoff Langca271392017-04-05 12:30:00 -0400536 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
537 AddCompressedFormat(&map, GL_COMPRESSED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
538 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_R11_EAC, 4, 4, 64, 1, GL_RED, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
539 AddCompressedFormat(&map, GL_COMPRESSED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
540 AddCompressedFormat(&map, GL_COMPRESSED_SIGNED_RG11_EAC, 4, 4, 128, 2, GL_RG, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
541 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
542 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
543 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
544 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireES<3, 0>, NeverSupported, AlwaysSupported);
545 AddCompressedFormat(&map, GL_COMPRESSED_RGBA8_ETC2_EAC, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, false, RequireES<3, 0>, NeverSupported, AlwaysSupported);
546 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 +0000547
548 // From GL_EXT_texture_compression_dxt1
Geoff Langca271392017-04-05 12:30:00 -0400549 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
550 AddCompressedFormat(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported);
551 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 +0000552
553 // From GL_ANGLE_texture_compression_dxt3
Geoff Langca271392017-04-05 12:30:00 -0400554 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 +0000555
556 // From GL_ANGLE_texture_compression_dxt5
Geoff Langca271392017-04-05 12:30:00 -0400557 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 -0400558
559 // From GL_OES_compressed_ETC1_RGB8_texture
Geoff Langca271392017-04-05 12:30:00 -0400560 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 +0000561
Kai Ninomiya02f075c2016-12-22 14:55:46 -0800562 // From GL_EXT_texture_compression_s3tc_srgb
Geoff Langca271392017-04-05 12:30:00 -0400563 // | Internal format |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
564 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
565 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 4, 4, 64, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
566 AddCompressedFormat(&map, GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 4, 4, 128, 4, GL_RGBA, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::textureCompressionS3TCsRGB>, NeverSupported, AlwaysSupported);
567 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 -0800568
Geoff Lang60ad73d2015-10-23 10:08:44 -0400569 // From KHR_texture_compression_astc_hdr
Geoff Langca271392017-04-05 12:30:00 -0400570 // | Internal format | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
571 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);
572 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);
573 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);
574 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);
575 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);
576 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);
577 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);
578 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);
579 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);
580 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);
581 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);
582 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);
583 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);
584 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 -0400585
Geoff Langca271392017-04-05 12:30:00 -0400586 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);
587 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);
588 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);
589 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);
590 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);
591 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);
592 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);
593 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);
594 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);
595 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);
596 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);
597 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);
598 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);
599 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 -0400600
Corentin Walleze0902642014-11-04 12:32:15 -0800601 // For STENCIL_INDEX8 we chose a normalized component type for the following reasons:
602 // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8
603 // - All other stencil formats (all depth-stencil) are either float or normalized
604 // - It affects only validation of internalformat in RenderbufferStorageMultisample.
Geoff Langca271392017-04-05 12:30:00 -0400605 // | Internal format |sized|D |S |X | Format | Type | Component type | Supported | Renderable | Filterable |
606 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 -0800607
608 // From GL_ANGLE_lossy_etc_decode
Geoff Langca271392017-04-05 12:30:00 -0400609 // | Internal format |W |H |BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable |
610 AddCompressedFormat(&map, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
611 AddCompressedFormat(&map, GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
612 AddCompressedFormat(&map, GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE, 4, 4, 64, 3, GL_RGB, GL_UNSIGNED_BYTE, true, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported);
613 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);
614 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 -0800615
Vincent Lang25ab4512016-05-13 18:13:59 +0200616 // From GL_EXT_texture_norm16
Geoff Langca271392017-04-05 12:30:00 -0400617 // | Internal format |sized| R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
618 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);
619 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);
620 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);
621 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);
622 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);
623 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);
624 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);
625 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 +0200626
Geoff Langca271392017-04-05 12:30:00 -0400627 // Unsized formats
628 // | Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable |
629 AddRGBAFormat(&map, GL_RED, false, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
630 AddRGBAFormat(&map, GL_RG, false, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
631 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);
632 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);
633 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);
634 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);
635 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);
636 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);
637 AddRGBAFormat(&map, GL_SRGB, false, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireExt<&Extensions::sRGB>, NeverSupported, AlwaysSupported);
638 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);
639
640 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);
641
642 // Unsized integer formats
643 // |Internal format |sized | R | G | B | A |S | Format | Type | Component type | SRGB | Texture | Renderable | Filterable |
644 AddRGBAFormat(&map, GL_RED_INTEGER, false, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
645 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);
646 AddRGBAFormat(&map, GL_RED_INTEGER, false, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
647 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);
648 AddRGBAFormat(&map, GL_RED_INTEGER, false, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
649 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);
650 AddRGBAFormat(&map, GL_RG_INTEGER, false, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
651 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);
652 AddRGBAFormat(&map, GL_RG_INTEGER, false, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
653 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);
654 AddRGBAFormat(&map, GL_RG_INTEGER, false, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
655 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);
656 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
657 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);
658 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
659 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);
660 AddRGBAFormat(&map, GL_RGB_INTEGER, false, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
661 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);
662 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
663 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);
664 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
665 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);
666 AddRGBAFormat(&map, GL_RGBA_INTEGER, false, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3, 0>, NeverSupported, NeverSupported);
667 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);
668 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);
669
670 // Unsized floating point formats
671 // |Internal format |sized | R | G | B | A |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable |
672 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
673 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
674 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
675 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
676 AddRGBAFormat(&map, GL_RED, false, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
677 AddRGBAFormat(&map, GL_RG, false, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
678 AddRGBAFormat(&map, GL_RGB, false, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
679 AddRGBAFormat(&map, GL_RGBA, false, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
680 AddRGBAFormat(&map, GL_RED, false, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
681 AddRGBAFormat(&map, GL_RG, false, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, RequireESOrExt<3, 0, &Extensions::textureRG>, NeverSupported, AlwaysSupported);
682 AddRGBAFormat(&map, GL_RGB, false, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
683 AddRGBAFormat(&map, GL_RGBA, false, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
684
685 // Unsized luminance alpha formats
686 // | Internal format |sized | L | A | Format | Type | Component type | Supported | Renderable | Filterable |
687 AddLUMAFormat(&map, GL_ALPHA, false, 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported);
688 AddLUMAFormat(&map, GL_LUMINANCE, false, 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported);
689 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2, 0>, NeverSupported, AlwaysSupported);
690 AddLUMAFormat(&map, GL_ALPHA, false, 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
691 AddLUMAFormat(&map, GL_LUMINANCE, false, 16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
692 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA ,false, 16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
693 AddLUMAFormat(&map, GL_ALPHA, false, 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
694 AddLUMAFormat(&map, GL_LUMINANCE, false, 32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
695 AddLUMAFormat(&map, GL_LUMINANCE_ALPHA, false, 32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, NeverSupported, AlwaysSupported);
696
697 // Unsized depth stencil formats
698 // | Internal format |sized | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable |
699 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);
700 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);
701 AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT, false, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<2, 0>, RequireES<2, 0>, AlwaysSupported);
702 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);
703 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);
704 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 -0400705 // clang-format on
Corentin Walleze0902642014-11-04 12:32:15 -0800706
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000707 return map;
708}
709
Geoff Lange4a492b2014-06-19 14:14:41 -0400710static const InternalFormatInfoMap &GetInternalFormatMap()
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000711{
Geoff Lange4a492b2014-06-19 14:14:41 -0400712 static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap();
713 return formatMap;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000714}
715
Geoff Lange4a492b2014-06-19 14:14:41 -0400716static FormatSet BuildAllSizedInternalFormatSet()
Geoff Langcec35902014-04-16 10:52:36 -0400717{
718 FormatSet result;
719
Geoff Langca271392017-04-05 12:30:00 -0400720 for (const auto &internalFormat : GetInternalFormatMap())
Geoff Langcec35902014-04-16 10:52:36 -0400721 {
Geoff Langca271392017-04-05 12:30:00 -0400722 for (const auto &type : internalFormat.second)
Geoff Langcec35902014-04-16 10:52:36 -0400723 {
Geoff Langca271392017-04-05 12:30:00 -0400724 if (type.second.sized)
725 {
726 // TODO(jmadill): Fix this hack.
727 if (internalFormat.first == GL_BGR565_ANGLEX)
728 continue;
Jamie Madillec0b5802016-07-04 13:11:59 -0400729
Geoff Langca271392017-04-05 12:30:00 -0400730 result.insert(internalFormat.first);
731 }
Geoff Langcec35902014-04-16 10:52:36 -0400732 }
733 }
734
735 return result;
736}
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000737
Geoff Lang5d601382014-07-22 15:14:06 -0400738const Type &GetTypeInfo(GLenum type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000739{
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200740 switch (type)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000741 {
Olli Etuaho31f8f4f2015-03-25 16:03:57 +0200742 case GL_UNSIGNED_BYTE:
743 case GL_BYTE:
744 {
745 static const Type info = GenTypeInfo(1, false);
746 return info;
747 }
748 case GL_UNSIGNED_SHORT:
749 case GL_SHORT:
750 case GL_HALF_FLOAT:
751 case GL_HALF_FLOAT_OES:
752 {
753 static const Type info = GenTypeInfo(2, false);
754 return info;
755 }
756 case GL_UNSIGNED_INT:
757 case GL_INT:
758 case GL_FLOAT:
759 {
760 static const Type info = GenTypeInfo(4, false);
761 return info;
762 }
763 case GL_UNSIGNED_SHORT_5_6_5:
764 case GL_UNSIGNED_SHORT_4_4_4_4:
765 case GL_UNSIGNED_SHORT_5_5_5_1:
766 case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
767 case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
768 {
769 static const Type info = GenTypeInfo(2, true);
770 return info;
771 }
772 case GL_UNSIGNED_INT_2_10_10_10_REV:
773 case GL_UNSIGNED_INT_24_8:
774 case GL_UNSIGNED_INT_10F_11F_11F_REV:
775 case GL_UNSIGNED_INT_5_9_9_9_REV:
776 {
777 ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8);
778 static const Type info = GenTypeInfo(4, true);
779 return info;
780 }
781 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
782 {
783 static const Type info = GenTypeInfo(8, true);
784 return info;
785 }
786 default:
787 {
788 static const Type defaultInfo;
789 return defaultInfo;
790 }
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000791 }
792}
793
Geoff Langca271392017-04-05 12:30:00 -0400794const InternalFormat &GetSizedInternalFormatInfo(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000795{
Geoff Langca271392017-04-05 12:30:00 -0400796 static const InternalFormat defaultInternalFormat;
Geoff Lang5d601382014-07-22 15:14:06 -0400797 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
Jamie Madillec0b5802016-07-04 13:11:59 -0400798 auto iter = formatMap.find(internalFormat);
Geoff Langca271392017-04-05 12:30:00 -0400799
800 // Sized internal formats only have one type per entry
801 if (iter == formatMap.end() || iter->second.size() != 1)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000802 {
Geoff Lang5d601382014-07-22 15:14:06 -0400803 return defaultInternalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000804 }
Geoff Langca271392017-04-05 12:30:00 -0400805
806 const InternalFormat &internalFormatInfo = iter->second.begin()->second;
807 if (!internalFormatInfo.sized)
808 {
809 return defaultInternalFormat;
810 }
811
812 return internalFormatInfo;
813}
814
815const InternalFormat &GetInternalFormatInfo(GLenum internalFormat, GLenum type)
816{
817 static const InternalFormat defaultInternalFormat;
818 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
819
820 auto internalFormatIter = formatMap.find(internalFormat);
821 if (internalFormatIter == formatMap.end())
822 {
823 return defaultInternalFormat;
824 }
825
826 // If the internal format is sized, simply return it without the type check.
827 if (internalFormatIter->second.size() == 1 && internalFormatIter->second.begin()->second.sized)
828 {
829 return internalFormatIter->second.begin()->second;
830 }
831
832 auto typeIter = internalFormatIter->second.find(type);
833 if (typeIter == internalFormatIter->second.end())
834 {
835 return defaultInternalFormat;
836 }
837
838 return typeIter->second;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000839}
840
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400841GLuint InternalFormat::computePixelBytes(GLenum formatType) const
842{
843 const auto &typeInfo = GetTypeInfo(formatType);
844 GLuint components = typeInfo.specialInterpretation ? 1u : componentCount;
845 return components * typeInfo.bytes;
846}
847
Corentin Wallez886de362016-09-27 10:49:35 -0400848ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400849 GLsizei width,
850 GLint alignment,
851 GLint rowLength) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000852{
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700853 // Compressed images do not use pack/unpack parameters.
854 if (compressed)
855 {
856 ASSERT(rowLength == 0);
Corentin Wallez886de362016-09-27 10:49:35 -0400857 return computeCompressedImageSize(formatType, Extents(width, 1, 1));
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700858 }
859
Geoff Lang3f234062016-07-13 15:35:45 -0400860 CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400861 CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700862
863 ASSERT(alignment > 0 && isPow2(alignment));
864 CheckedNumeric<GLuint> checkedAlignment(alignment);
865 auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment);
866 ANGLE_TRY_CHECKED_MATH(aligned);
867 return aligned.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000868}
869
Corentin Wallez0e487192016-10-03 16:30:38 -0400870ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height,
871 GLint imageHeight,
872 GLuint rowPitch) const
873{
874 GLuint rows =
875 (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height));
876 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
877
878 auto depthPitch = checkedRowPitch * rows;
879 ANGLE_TRY_CHECKED_MATH(depthPitch);
880 return depthPitch.ValueOrDie();
881}
882
Corentin Wallez886de362016-09-27 10:49:35 -0400883ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType,
Jamie Madille2e406c2016-06-02 13:04:10 -0400884 GLsizei width,
885 GLsizei height,
886 GLint alignment,
887 GLint rowLength,
888 GLint imageHeight) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000889{
Jamie Madille2e406c2016-06-02 13:04:10 -0400890 GLuint rowPitch = 0;
891 ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch);
Corentin Wallez0e487192016-10-03 16:30:38 -0400892 return computeDepthPitch(height, imageHeight, rowPitch);
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000893}
894
Corentin Wallez886de362016-09-27 10:49:35 -0400895ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType,
896 const Extents &size) const
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000897{
Jamie Madill513558d2016-06-02 13:04:11 -0400898 CheckedNumeric<GLuint> checkedWidth(size.width);
899 CheckedNumeric<GLuint> checkedHeight(size.height);
900 CheckedNumeric<GLuint> checkedDepth(size.depth);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700901 CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth);
902 CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight);
Jamie Madille2e406c2016-06-02 13:04:10 -0400903
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700904 ASSERT(compressed);
905 auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth;
906 auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight;
907 auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth;
908 ANGLE_TRY_CHECKED_MATH(bytes);
909 return bytes.ValueOrDie();
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000910}
911
Corentin Wallez886de362016-09-27 10:49:35 -0400912ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch,
Olli Etuaho989cac32016-06-08 16:18:49 -0700913 GLuint depthPitch,
Corentin Wallez886de362016-09-27 10:49:35 -0400914 const PixelStoreStateBase &state,
915 bool is3D) const
Minmin Gongadff67b2015-10-14 10:34:45 -0400916{
Olli Etuaho989cac32016-06-08 16:18:49 -0700917 CheckedNumeric<GLuint> checkedRowPitch(rowPitch);
918 CheckedNumeric<GLuint> checkedDepthPitch(depthPitch);
Corentin Wallez886de362016-09-27 10:49:35 -0400919 CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages));
920 CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows));
921 CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels));
Olli Etuaho989cac32016-06-08 16:18:49 -0700922 CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes);
923 auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch;
Corentin Wallez886de362016-09-27 10:49:35 -0400924 if (!is3D)
Olli Etuaho989cac32016-06-08 16:18:49 -0700925 {
926 checkedSkipImagesBytes = 0;
927 }
928 auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch +
929 checkedSkipPixels * checkedPixelBytes;
930 ANGLE_TRY_CHECKED_MATH(skipBytes);
931 return skipBytes.ValueOrDie();
Minmin Gongadff67b2015-10-14 10:34:45 -0400932}
933
Corentin Wallez886de362016-09-27 10:49:35 -0400934ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte(
935 GLenum formatType,
936 const Extents &size,
937 const PixelStoreStateBase &state,
938 bool is3D) const
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400939{
Corentin Wallez886de362016-09-27 10:49:35 -0400940 GLuint rowPitch = 0;
941 ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength),
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400942 rowPitch);
943
Corentin Wallez0e487192016-10-03 16:30:38 -0400944 GLuint depthPitch = 0;
945 if (is3D)
946 {
947 ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch);
948 }
949
Corentin Wallez886de362016-09-27 10:49:35 -0400950 CheckedNumeric<GLuint> checkedCopyBytes = 0;
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700951 if (compressed)
952 {
Corentin Wallez886de362016-09-27 10:49:35 -0400953 ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes);
Jamie Madill4b4cdff2016-06-06 13:53:38 -0700954 }
Corentin Wallez886de362016-09-27 10:49:35 -0400955 else if (size.height != 0 && (!is3D || size.depth != 0))
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400956 {
Corentin Wallez886de362016-09-27 10:49:35 -0400957 CheckedNumeric<GLuint> bytes = computePixelBytes(formatType);
958 checkedCopyBytes += size.width * bytes;
959
960 CheckedNumeric<GLuint> heightMinusOne = size.height - 1;
961 checkedCopyBytes += heightMinusOne * rowPitch;
962
963 if (is3D)
964 {
965 CheckedNumeric<GLuint> depthMinusOne = size.depth - 1;
966 checkedCopyBytes += depthMinusOne * depthPitch;
967 }
Corentin Wallezece7c5a2016-09-21 15:28:23 -0400968 }
969
Corentin Wallez886de362016-09-27 10:49:35 -0400970 CheckedNumeric<GLuint> checkedSkipBytes = 0;
971 ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes);
Corentin Wallezc5cacd62016-09-14 14:50:24 -0400972
973 CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes;
974
975 ANGLE_TRY_CHECKED_MATH(endByte);
976 return endByte.ValueOrDie();
977}
978
Geoff Langca271392017-04-05 12:30:00 -0400979GLenum GetUnsizedFormat(GLenum internalFormat)
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000980{
Geoff Langca271392017-04-05 12:30:00 -0400981 auto sizedFormatInfo = GetSizedInternalFormatInfo(internalFormat);
982 if (sizedFormatInfo.internalFormat != GL_NONE)
Geoff Lang051dbc72015-01-05 15:48:58 -0500983 {
Geoff Langca271392017-04-05 12:30:00 -0400984 return sizedFormatInfo.format;
Geoff Lang051dbc72015-01-05 15:48:58 -0500985 }
Geoff Langca271392017-04-05 12:30:00 -0400986
987 return internalFormat;
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +0000988}
989
Geoff Lange4a492b2014-06-19 14:14:41 -0400990const FormatSet &GetAllSizedInternalFormats()
Geoff Langcec35902014-04-16 10:52:36 -0400991{
Geoff Lange4a492b2014-06-19 14:14:41 -0400992 static FormatSet formatSet = BuildAllSizedInternalFormatSet();
Geoff Langcec35902014-04-16 10:52:36 -0400993 return formatSet;
994}
995
Jamie Madill09e2d932015-07-14 16:40:31 -0400996AttributeType GetAttributeType(GLenum enumValue)
997{
998 switch (enumValue)
999 {
1000 case GL_FLOAT:
1001 return ATTRIBUTE_FLOAT;
1002 case GL_FLOAT_VEC2:
1003 return ATTRIBUTE_VEC2;
1004 case GL_FLOAT_VEC3:
1005 return ATTRIBUTE_VEC3;
1006 case GL_FLOAT_VEC4:
1007 return ATTRIBUTE_VEC4;
1008 case GL_INT:
1009 return ATTRIBUTE_INT;
1010 case GL_INT_VEC2:
1011 return ATTRIBUTE_IVEC2;
1012 case GL_INT_VEC3:
1013 return ATTRIBUTE_IVEC3;
1014 case GL_INT_VEC4:
1015 return ATTRIBUTE_IVEC4;
1016 case GL_UNSIGNED_INT:
1017 return ATTRIBUTE_UINT;
1018 case GL_UNSIGNED_INT_VEC2:
1019 return ATTRIBUTE_UVEC2;
1020 case GL_UNSIGNED_INT_VEC3:
1021 return ATTRIBUTE_UVEC3;
1022 case GL_UNSIGNED_INT_VEC4:
1023 return ATTRIBUTE_UVEC4;
1024 case GL_FLOAT_MAT2:
1025 return ATTRIBUTE_MAT2;
1026 case GL_FLOAT_MAT3:
1027 return ATTRIBUTE_MAT3;
1028 case GL_FLOAT_MAT4:
1029 return ATTRIBUTE_MAT4;
1030 case GL_FLOAT_MAT2x3:
1031 return ATTRIBUTE_MAT2x3;
1032 case GL_FLOAT_MAT2x4:
1033 return ATTRIBUTE_MAT2x4;
1034 case GL_FLOAT_MAT3x2:
1035 return ATTRIBUTE_MAT3x2;
1036 case GL_FLOAT_MAT3x4:
1037 return ATTRIBUTE_MAT3x4;
1038 case GL_FLOAT_MAT4x2:
1039 return ATTRIBUTE_MAT4x2;
1040 case GL_FLOAT_MAT4x3:
1041 return ATTRIBUTE_MAT4x3;
1042 default:
1043 UNREACHABLE();
1044 return ATTRIBUTE_FLOAT;
1045 }
1046}
1047
Jamie Madilld3dfda22015-07-06 08:28:49 -04001048VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger)
1049{
1050 switch (type)
1051 {
1052 case GL_BYTE:
1053 switch (components)
1054 {
1055 case 1:
1056 if (pureInteger)
1057 return VERTEX_FORMAT_SBYTE1_INT;
1058 if (normalized)
1059 return VERTEX_FORMAT_SBYTE1_NORM;
1060 return VERTEX_FORMAT_SBYTE1;
1061 case 2:
1062 if (pureInteger)
1063 return VERTEX_FORMAT_SBYTE2_INT;
1064 if (normalized)
1065 return VERTEX_FORMAT_SBYTE2_NORM;
1066 return VERTEX_FORMAT_SBYTE2;
1067 case 3:
1068 if (pureInteger)
1069 return VERTEX_FORMAT_SBYTE3_INT;
1070 if (normalized)
1071 return VERTEX_FORMAT_SBYTE3_NORM;
1072 return VERTEX_FORMAT_SBYTE3;
1073 case 4:
1074 if (pureInteger)
1075 return VERTEX_FORMAT_SBYTE4_INT;
1076 if (normalized)
1077 return VERTEX_FORMAT_SBYTE4_NORM;
1078 return VERTEX_FORMAT_SBYTE4;
1079 default:
1080 UNREACHABLE();
1081 break;
1082 }
1083 case GL_UNSIGNED_BYTE:
1084 switch (components)
1085 {
1086 case 1:
1087 if (pureInteger)
1088 return VERTEX_FORMAT_UBYTE1_INT;
1089 if (normalized)
1090 return VERTEX_FORMAT_UBYTE1_NORM;
1091 return VERTEX_FORMAT_UBYTE1;
1092 case 2:
1093 if (pureInteger)
1094 return VERTEX_FORMAT_UBYTE2_INT;
1095 if (normalized)
1096 return VERTEX_FORMAT_UBYTE2_NORM;
1097 return VERTEX_FORMAT_UBYTE2;
1098 case 3:
1099 if (pureInteger)
1100 return VERTEX_FORMAT_UBYTE3_INT;
1101 if (normalized)
1102 return VERTEX_FORMAT_UBYTE3_NORM;
1103 return VERTEX_FORMAT_UBYTE3;
1104 case 4:
1105 if (pureInteger)
1106 return VERTEX_FORMAT_UBYTE4_INT;
1107 if (normalized)
1108 return VERTEX_FORMAT_UBYTE4_NORM;
1109 return VERTEX_FORMAT_UBYTE4;
1110 default:
1111 UNREACHABLE();
1112 break;
1113 }
1114 case GL_SHORT:
1115 switch (components)
1116 {
1117 case 1:
1118 if (pureInteger)
1119 return VERTEX_FORMAT_SSHORT1_INT;
1120 if (normalized)
1121 return VERTEX_FORMAT_SSHORT1_NORM;
1122 return VERTEX_FORMAT_SSHORT1;
1123 case 2:
1124 if (pureInteger)
1125 return VERTEX_FORMAT_SSHORT2_INT;
1126 if (normalized)
1127 return VERTEX_FORMAT_SSHORT2_NORM;
1128 return VERTEX_FORMAT_SSHORT2;
1129 case 3:
1130 if (pureInteger)
1131 return VERTEX_FORMAT_SSHORT3_INT;
1132 if (normalized)
1133 return VERTEX_FORMAT_SSHORT3_NORM;
1134 return VERTEX_FORMAT_SSHORT3;
1135 case 4:
1136 if (pureInteger)
1137 return VERTEX_FORMAT_SSHORT4_INT;
1138 if (normalized)
1139 return VERTEX_FORMAT_SSHORT4_NORM;
1140 return VERTEX_FORMAT_SSHORT4;
1141 default:
1142 UNREACHABLE();
1143 break;
1144 }
1145 case GL_UNSIGNED_SHORT:
1146 switch (components)
1147 {
1148 case 1:
1149 if (pureInteger)
1150 return VERTEX_FORMAT_USHORT1_INT;
1151 if (normalized)
1152 return VERTEX_FORMAT_USHORT1_NORM;
1153 return VERTEX_FORMAT_USHORT1;
1154 case 2:
1155 if (pureInteger)
1156 return VERTEX_FORMAT_USHORT2_INT;
1157 if (normalized)
1158 return VERTEX_FORMAT_USHORT2_NORM;
1159 return VERTEX_FORMAT_USHORT2;
1160 case 3:
1161 if (pureInteger)
1162 return VERTEX_FORMAT_USHORT3_INT;
1163 if (normalized)
1164 return VERTEX_FORMAT_USHORT3_NORM;
1165 return VERTEX_FORMAT_USHORT3;
1166 case 4:
1167 if (pureInteger)
1168 return VERTEX_FORMAT_USHORT4_INT;
1169 if (normalized)
1170 return VERTEX_FORMAT_USHORT4_NORM;
1171 return VERTEX_FORMAT_USHORT4;
1172 default:
1173 UNREACHABLE();
1174 break;
1175 }
1176 case GL_INT:
1177 switch (components)
1178 {
1179 case 1:
1180 if (pureInteger)
1181 return VERTEX_FORMAT_SINT1_INT;
1182 if (normalized)
1183 return VERTEX_FORMAT_SINT1_NORM;
1184 return VERTEX_FORMAT_SINT1;
1185 case 2:
1186 if (pureInteger)
1187 return VERTEX_FORMAT_SINT2_INT;
1188 if (normalized)
1189 return VERTEX_FORMAT_SINT2_NORM;
1190 return VERTEX_FORMAT_SINT2;
1191 case 3:
1192 if (pureInteger)
1193 return VERTEX_FORMAT_SINT3_INT;
1194 if (normalized)
1195 return VERTEX_FORMAT_SINT3_NORM;
1196 return VERTEX_FORMAT_SINT3;
1197 case 4:
1198 if (pureInteger)
1199 return VERTEX_FORMAT_SINT4_INT;
1200 if (normalized)
1201 return VERTEX_FORMAT_SINT4_NORM;
1202 return VERTEX_FORMAT_SINT4;
1203 default:
1204 UNREACHABLE();
1205 break;
1206 }
1207 case GL_UNSIGNED_INT:
1208 switch (components)
1209 {
1210 case 1:
1211 if (pureInteger)
1212 return VERTEX_FORMAT_UINT1_INT;
1213 if (normalized)
1214 return VERTEX_FORMAT_UINT1_NORM;
1215 return VERTEX_FORMAT_UINT1;
1216 case 2:
1217 if (pureInteger)
1218 return VERTEX_FORMAT_UINT2_INT;
1219 if (normalized)
1220 return VERTEX_FORMAT_UINT2_NORM;
1221 return VERTEX_FORMAT_UINT2;
1222 case 3:
1223 if (pureInteger)
1224 return VERTEX_FORMAT_UINT3_INT;
1225 if (normalized)
1226 return VERTEX_FORMAT_UINT3_NORM;
1227 return VERTEX_FORMAT_UINT3;
1228 case 4:
1229 if (pureInteger)
1230 return VERTEX_FORMAT_UINT4_INT;
1231 if (normalized)
1232 return VERTEX_FORMAT_UINT4_NORM;
1233 return VERTEX_FORMAT_UINT4;
1234 default:
1235 UNREACHABLE();
1236 break;
1237 }
1238 case GL_FLOAT:
1239 switch (components)
1240 {
1241 case 1:
1242 return VERTEX_FORMAT_FLOAT1;
1243 case 2:
1244 return VERTEX_FORMAT_FLOAT2;
1245 case 3:
1246 return VERTEX_FORMAT_FLOAT3;
1247 case 4:
1248 return VERTEX_FORMAT_FLOAT4;
1249 default:
1250 UNREACHABLE();
1251 break;
1252 }
1253 case GL_HALF_FLOAT:
1254 switch (components)
1255 {
1256 case 1:
1257 return VERTEX_FORMAT_HALF1;
1258 case 2:
1259 return VERTEX_FORMAT_HALF2;
1260 case 3:
1261 return VERTEX_FORMAT_HALF3;
1262 case 4:
1263 return VERTEX_FORMAT_HALF4;
1264 default:
1265 UNREACHABLE();
1266 break;
1267 }
1268 case GL_FIXED:
1269 switch (components)
1270 {
1271 case 1:
1272 return VERTEX_FORMAT_FIXED1;
1273 case 2:
1274 return VERTEX_FORMAT_FIXED2;
1275 case 3:
1276 return VERTEX_FORMAT_FIXED3;
1277 case 4:
1278 return VERTEX_FORMAT_FIXED4;
1279 default:
1280 UNREACHABLE();
1281 break;
1282 }
1283 case GL_INT_2_10_10_10_REV:
1284 if (pureInteger)
1285 return VERTEX_FORMAT_SINT210_INT;
1286 if (normalized)
1287 return VERTEX_FORMAT_SINT210_NORM;
1288 return VERTEX_FORMAT_SINT210;
1289 case GL_UNSIGNED_INT_2_10_10_10_REV:
1290 if (pureInteger)
1291 return VERTEX_FORMAT_UINT210_INT;
1292 if (normalized)
1293 return VERTEX_FORMAT_UINT210_NORM;
1294 return VERTEX_FORMAT_UINT210;
1295 default:
1296 UNREACHABLE();
1297 break;
1298 }
1299 return VERTEX_FORMAT_UBYTE1;
1300}
1301
1302VertexFormatType GetVertexFormatType(const VertexAttribute &attrib)
1303{
1304 return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger);
1305}
1306
1307VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType)
1308{
1309 if (!attrib.enabled)
1310 {
1311 return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT));
1312 }
1313 return GetVertexFormatType(attrib);
1314}
1315
1316const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType)
1317{
1318 switch (vertexFormatType)
1319 {
1320 case VERTEX_FORMAT_SBYTE1:
1321 {
1322 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false);
1323 return format;
1324 }
1325 case VERTEX_FORMAT_SBYTE1_NORM:
1326 {
1327 static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false);
1328 return format;
1329 }
1330 case VERTEX_FORMAT_SBYTE2:
1331 {
1332 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false);
1333 return format;
1334 }
1335 case VERTEX_FORMAT_SBYTE2_NORM:
1336 {
1337 static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false);
1338 return format;
1339 }
1340 case VERTEX_FORMAT_SBYTE3:
1341 {
1342 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false);
1343 return format;
1344 }
1345 case VERTEX_FORMAT_SBYTE3_NORM:
1346 {
1347 static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false);
1348 return format;
1349 }
1350 case VERTEX_FORMAT_SBYTE4:
1351 {
1352 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false);
1353 return format;
1354 }
1355 case VERTEX_FORMAT_SBYTE4_NORM:
1356 {
1357 static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false);
1358 return format;
1359 }
1360 case VERTEX_FORMAT_UBYTE1:
1361 {
1362 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false);
1363 return format;
1364 }
1365 case VERTEX_FORMAT_UBYTE1_NORM:
1366 {
1367 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false);
1368 return format;
1369 }
1370 case VERTEX_FORMAT_UBYTE2:
1371 {
1372 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false);
1373 return format;
1374 }
1375 case VERTEX_FORMAT_UBYTE2_NORM:
1376 {
1377 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false);
1378 return format;
1379 }
1380 case VERTEX_FORMAT_UBYTE3:
1381 {
1382 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false);
1383 return format;
1384 }
1385 case VERTEX_FORMAT_UBYTE3_NORM:
1386 {
1387 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false);
1388 return format;
1389 }
1390 case VERTEX_FORMAT_UBYTE4:
1391 {
1392 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false);
1393 return format;
1394 }
1395 case VERTEX_FORMAT_UBYTE4_NORM:
1396 {
1397 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false);
1398 return format;
1399 }
1400 case VERTEX_FORMAT_SSHORT1:
1401 {
1402 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false);
1403 return format;
1404 }
1405 case VERTEX_FORMAT_SSHORT1_NORM:
1406 {
1407 static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false);
1408 return format;
1409 }
1410 case VERTEX_FORMAT_SSHORT2:
1411 {
1412 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false);
1413 return format;
1414 }
1415 case VERTEX_FORMAT_SSHORT2_NORM:
1416 {
1417 static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false);
1418 return format;
1419 }
1420 case VERTEX_FORMAT_SSHORT3:
1421 {
1422 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false);
1423 return format;
1424 }
1425 case VERTEX_FORMAT_SSHORT3_NORM:
1426 {
1427 static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false);
1428 return format;
1429 }
1430 case VERTEX_FORMAT_SSHORT4:
1431 {
1432 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false);
1433 return format;
1434 }
1435 case VERTEX_FORMAT_SSHORT4_NORM:
1436 {
1437 static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false);
1438 return format;
1439 }
1440 case VERTEX_FORMAT_USHORT1:
1441 {
1442 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false);
1443 return format;
1444 }
1445 case VERTEX_FORMAT_USHORT1_NORM:
1446 {
1447 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false);
1448 return format;
1449 }
1450 case VERTEX_FORMAT_USHORT2:
1451 {
1452 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false);
1453 return format;
1454 }
1455 case VERTEX_FORMAT_USHORT2_NORM:
1456 {
1457 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false);
1458 return format;
1459 }
1460 case VERTEX_FORMAT_USHORT3:
1461 {
1462 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false);
1463 return format;
1464 }
1465 case VERTEX_FORMAT_USHORT3_NORM:
1466 {
1467 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false);
1468 return format;
1469 }
1470 case VERTEX_FORMAT_USHORT4:
1471 {
1472 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false);
1473 return format;
1474 }
1475 case VERTEX_FORMAT_USHORT4_NORM:
1476 {
1477 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false);
1478 return format;
1479 }
1480 case VERTEX_FORMAT_SINT1:
1481 {
1482 static const VertexFormat format(GL_INT, GL_FALSE, 1, false);
1483 return format;
1484 }
1485 case VERTEX_FORMAT_SINT1_NORM:
1486 {
1487 static const VertexFormat format(GL_INT, GL_TRUE, 1, false);
1488 return format;
1489 }
1490 case VERTEX_FORMAT_SINT2:
1491 {
1492 static const VertexFormat format(GL_INT, GL_FALSE, 2, false);
1493 return format;
1494 }
1495 case VERTEX_FORMAT_SINT2_NORM:
1496 {
1497 static const VertexFormat format(GL_INT, GL_TRUE, 2, false);
1498 return format;
1499 }
1500 case VERTEX_FORMAT_SINT3:
1501 {
1502 static const VertexFormat format(GL_INT, GL_FALSE, 3, false);
1503 return format;
1504 }
1505 case VERTEX_FORMAT_SINT3_NORM:
1506 {
1507 static const VertexFormat format(GL_INT, GL_TRUE, 3, false);
1508 return format;
1509 }
1510 case VERTEX_FORMAT_SINT4:
1511 {
1512 static const VertexFormat format(GL_INT, GL_FALSE, 4, false);
1513 return format;
1514 }
1515 case VERTEX_FORMAT_SINT4_NORM:
1516 {
1517 static const VertexFormat format(GL_INT, GL_TRUE, 4, false);
1518 return format;
1519 }
1520 case VERTEX_FORMAT_UINT1:
1521 {
1522 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false);
1523 return format;
1524 }
1525 case VERTEX_FORMAT_UINT1_NORM:
1526 {
1527 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false);
1528 return format;
1529 }
1530 case VERTEX_FORMAT_UINT2:
1531 {
1532 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false);
1533 return format;
1534 }
1535 case VERTEX_FORMAT_UINT2_NORM:
1536 {
1537 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false);
1538 return format;
1539 }
1540 case VERTEX_FORMAT_UINT3:
1541 {
1542 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false);
1543 return format;
1544 }
1545 case VERTEX_FORMAT_UINT3_NORM:
1546 {
1547 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false);
1548 return format;
1549 }
1550 case VERTEX_FORMAT_UINT4:
1551 {
1552 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false);
1553 return format;
1554 }
1555 case VERTEX_FORMAT_UINT4_NORM:
1556 {
1557 static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false);
1558 return format;
1559 }
1560 case VERTEX_FORMAT_SBYTE1_INT:
1561 {
1562 static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true);
1563 return format;
1564 }
1565 case VERTEX_FORMAT_SBYTE2_INT:
1566 {
1567 static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true);
1568 return format;
1569 }
1570 case VERTEX_FORMAT_SBYTE3_INT:
1571 {
1572 static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true);
1573 return format;
1574 }
1575 case VERTEX_FORMAT_SBYTE4_INT:
1576 {
1577 static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true);
1578 return format;
1579 }
1580 case VERTEX_FORMAT_UBYTE1_INT:
1581 {
1582 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true);
1583 return format;
1584 }
1585 case VERTEX_FORMAT_UBYTE2_INT:
1586 {
1587 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true);
1588 return format;
1589 }
1590 case VERTEX_FORMAT_UBYTE3_INT:
1591 {
1592 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true);
1593 return format;
1594 }
1595 case VERTEX_FORMAT_UBYTE4_INT:
1596 {
1597 static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true);
1598 return format;
1599 }
1600 case VERTEX_FORMAT_SSHORT1_INT:
1601 {
1602 static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true);
1603 return format;
1604 }
1605 case VERTEX_FORMAT_SSHORT2_INT:
1606 {
1607 static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true);
1608 return format;
1609 }
1610 case VERTEX_FORMAT_SSHORT3_INT:
1611 {
1612 static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true);
1613 return format;
1614 }
1615 case VERTEX_FORMAT_SSHORT4_INT:
1616 {
1617 static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true);
1618 return format;
1619 }
1620 case VERTEX_FORMAT_USHORT1_INT:
1621 {
1622 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true);
1623 return format;
1624 }
1625 case VERTEX_FORMAT_USHORT2_INT:
1626 {
1627 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true);
1628 return format;
1629 }
1630 case VERTEX_FORMAT_USHORT3_INT:
1631 {
1632 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true);
1633 return format;
1634 }
1635 case VERTEX_FORMAT_USHORT4_INT:
1636 {
1637 static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true);
1638 return format;
1639 }
1640 case VERTEX_FORMAT_SINT1_INT:
1641 {
1642 static const VertexFormat format(GL_INT, GL_FALSE, 1, true);
1643 return format;
1644 }
1645 case VERTEX_FORMAT_SINT2_INT:
1646 {
1647 static const VertexFormat format(GL_INT, GL_FALSE, 2, true);
1648 return format;
1649 }
1650 case VERTEX_FORMAT_SINT3_INT:
1651 {
1652 static const VertexFormat format(GL_INT, GL_FALSE, 3, true);
1653 return format;
1654 }
1655 case VERTEX_FORMAT_SINT4_INT:
1656 {
1657 static const VertexFormat format(GL_INT, GL_FALSE, 4, true);
1658 return format;
1659 }
1660 case VERTEX_FORMAT_UINT1_INT:
1661 {
1662 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true);
1663 return format;
1664 }
1665 case VERTEX_FORMAT_UINT2_INT:
1666 {
1667 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true);
1668 return format;
1669 }
1670 case VERTEX_FORMAT_UINT3_INT:
1671 {
1672 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true);
1673 return format;
1674 }
1675 case VERTEX_FORMAT_UINT4_INT:
1676 {
1677 static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true);
1678 return format;
1679 }
1680 case VERTEX_FORMAT_FIXED1:
1681 {
1682 static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false);
1683 return format;
1684 }
1685 case VERTEX_FORMAT_FIXED2:
1686 {
1687 static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false);
1688 return format;
1689 }
1690 case VERTEX_FORMAT_FIXED3:
1691 {
1692 static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false);
1693 return format;
1694 }
1695 case VERTEX_FORMAT_FIXED4:
1696 {
1697 static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false);
1698 return format;
1699 }
1700 case VERTEX_FORMAT_HALF1:
1701 {
1702 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false);
1703 return format;
1704 }
1705 case VERTEX_FORMAT_HALF2:
1706 {
1707 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false);
1708 return format;
1709 }
1710 case VERTEX_FORMAT_HALF3:
1711 {
1712 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false);
1713 return format;
1714 }
1715 case VERTEX_FORMAT_HALF4:
1716 {
1717 static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false);
1718 return format;
1719 }
1720 case VERTEX_FORMAT_FLOAT1:
1721 {
1722 static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false);
1723 return format;
1724 }
1725 case VERTEX_FORMAT_FLOAT2:
1726 {
1727 static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false);
1728 return format;
1729 }
1730 case VERTEX_FORMAT_FLOAT3:
1731 {
1732 static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false);
1733 return format;
1734 }
1735 case VERTEX_FORMAT_FLOAT4:
1736 {
1737 static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false);
1738 return format;
1739 }
1740 case VERTEX_FORMAT_SINT210:
1741 {
1742 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1743 return format;
1744 }
1745 case VERTEX_FORMAT_UINT210:
1746 {
1747 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false);
1748 return format;
1749 }
1750 case VERTEX_FORMAT_SINT210_NORM:
1751 {
1752 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1753 return format;
1754 }
1755 case VERTEX_FORMAT_UINT210_NORM:
1756 {
1757 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false);
1758 return format;
1759 }
1760 case VERTEX_FORMAT_SINT210_INT:
1761 {
1762 static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1763 return format;
1764 }
1765 case VERTEX_FORMAT_UINT210_INT:
1766 {
1767 static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true);
1768 return format;
1769 }
1770 default:
1771 {
1772 static const VertexFormat format(GL_NONE, GL_FALSE, 0, false);
1773 return format;
1774 }
1775 }
1776}
1777
Corentin Wallez0c7baf12016-12-19 15:43:10 -05001778size_t GetVertexFormatTypeSize(VertexFormatType vertexFormatType)
1779{
1780 switch (vertexFormatType)
1781 {
1782 case VERTEX_FORMAT_SBYTE1:
1783 case VERTEX_FORMAT_SBYTE1_NORM:
1784 case VERTEX_FORMAT_UBYTE1:
1785 case VERTEX_FORMAT_UBYTE1_NORM:
1786 case VERTEX_FORMAT_SBYTE1_INT:
1787 case VERTEX_FORMAT_UBYTE1_INT:
1788 return 1;
1789
1790 case VERTEX_FORMAT_SBYTE2:
1791 case VERTEX_FORMAT_SBYTE2_NORM:
1792 case VERTEX_FORMAT_UBYTE2:
1793 case VERTEX_FORMAT_UBYTE2_NORM:
1794 case VERTEX_FORMAT_SBYTE2_INT:
1795 case VERTEX_FORMAT_UBYTE2_INT:
1796 case VERTEX_FORMAT_SSHORT1:
1797 case VERTEX_FORMAT_SSHORT1_NORM:
1798 case VERTEX_FORMAT_USHORT1:
1799 case VERTEX_FORMAT_USHORT1_NORM:
1800 case VERTEX_FORMAT_SSHORT1_INT:
1801 case VERTEX_FORMAT_USHORT1_INT:
1802 case VERTEX_FORMAT_HALF1:
1803 return 2;
1804
1805 case VERTEX_FORMAT_SBYTE3:
1806 case VERTEX_FORMAT_SBYTE3_NORM:
1807 case VERTEX_FORMAT_UBYTE3:
1808 case VERTEX_FORMAT_UBYTE3_NORM:
1809 case VERTEX_FORMAT_SBYTE3_INT:
1810 case VERTEX_FORMAT_UBYTE3_INT:
1811 return 3;
1812
1813 case VERTEX_FORMAT_SBYTE4:
1814 case VERTEX_FORMAT_SBYTE4_NORM:
1815 case VERTEX_FORMAT_UBYTE4:
1816 case VERTEX_FORMAT_UBYTE4_NORM:
1817 case VERTEX_FORMAT_SBYTE4_INT:
1818 case VERTEX_FORMAT_UBYTE4_INT:
1819 case VERTEX_FORMAT_SSHORT2:
1820 case VERTEX_FORMAT_SSHORT2_NORM:
1821 case VERTEX_FORMAT_USHORT2:
1822 case VERTEX_FORMAT_USHORT2_NORM:
1823 case VERTEX_FORMAT_SSHORT2_INT:
1824 case VERTEX_FORMAT_USHORT2_INT:
1825 case VERTEX_FORMAT_SINT1:
1826 case VERTEX_FORMAT_SINT1_NORM:
1827 case VERTEX_FORMAT_UINT1:
1828 case VERTEX_FORMAT_UINT1_NORM:
1829 case VERTEX_FORMAT_SINT1_INT:
1830 case VERTEX_FORMAT_UINT1_INT:
1831 case VERTEX_FORMAT_HALF2:
1832 case VERTEX_FORMAT_FIXED1:
1833 case VERTEX_FORMAT_FLOAT1:
1834 case VERTEX_FORMAT_SINT210:
1835 case VERTEX_FORMAT_UINT210:
1836 case VERTEX_FORMAT_SINT210_NORM:
1837 case VERTEX_FORMAT_UINT210_NORM:
1838 case VERTEX_FORMAT_SINT210_INT:
1839 case VERTEX_FORMAT_UINT210_INT:
1840 return 4;
1841
1842 case VERTEX_FORMAT_SSHORT3:
1843 case VERTEX_FORMAT_SSHORT3_NORM:
1844 case VERTEX_FORMAT_USHORT3:
1845 case VERTEX_FORMAT_USHORT3_NORM:
1846 case VERTEX_FORMAT_SSHORT3_INT:
1847 case VERTEX_FORMAT_USHORT3_INT:
1848 case VERTEX_FORMAT_HALF3:
1849 return 6;
1850
1851 case VERTEX_FORMAT_SSHORT4:
1852 case VERTEX_FORMAT_SSHORT4_NORM:
1853 case VERTEX_FORMAT_USHORT4:
1854 case VERTEX_FORMAT_USHORT4_NORM:
1855 case VERTEX_FORMAT_SSHORT4_INT:
1856 case VERTEX_FORMAT_USHORT4_INT:
1857 case VERTEX_FORMAT_SINT2:
1858 case VERTEX_FORMAT_SINT2_NORM:
1859 case VERTEX_FORMAT_UINT2:
1860 case VERTEX_FORMAT_UINT2_NORM:
1861 case VERTEX_FORMAT_SINT2_INT:
1862 case VERTEX_FORMAT_UINT2_INT:
1863 case VERTEX_FORMAT_HALF4:
1864 case VERTEX_FORMAT_FIXED2:
1865 case VERTEX_FORMAT_FLOAT2:
1866 return 8;
1867
1868 case VERTEX_FORMAT_SINT3:
1869 case VERTEX_FORMAT_SINT3_NORM:
1870 case VERTEX_FORMAT_UINT3:
1871 case VERTEX_FORMAT_UINT3_NORM:
1872 case VERTEX_FORMAT_SINT3_INT:
1873 case VERTEX_FORMAT_UINT3_INT:
1874 case VERTEX_FORMAT_FIXED3:
1875 case VERTEX_FORMAT_FLOAT3:
1876 return 12;
1877
1878 case VERTEX_FORMAT_SINT4:
1879 case VERTEX_FORMAT_SINT4_NORM:
1880 case VERTEX_FORMAT_UINT4:
1881 case VERTEX_FORMAT_UINT4_NORM:
1882 case VERTEX_FORMAT_SINT4_INT:
1883 case VERTEX_FORMAT_UINT4_INT:
1884 case VERTEX_FORMAT_FIXED4:
1885 case VERTEX_FORMAT_FLOAT4:
1886 return 16;
1887
1888 case VERTEX_FORMAT_INVALID:
1889 default:
1890 UNREACHABLE();
1891 return 0;
1892 }
1893}
1894
Geoff Lang6d1ccf02017-04-24 14:09:58 -04001895bool ValidES3InternalFormat(GLenum internalFormat)
1896{
1897 const InternalFormatInfoMap &formatMap = GetInternalFormatMap();
1898 return internalFormat != GL_NONE && formatMap.find(internalFormat) != formatMap.end();
1899}
1900
Jamie Madilld3dfda22015-07-06 08:28:49 -04001901VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn)
1902 : type(typeIn),
1903 normalized(normalizedIn),
1904 components(componentsIn),
1905 pureInteger(pureIntegerIn)
1906{
1907 // float -> !normalized
1908 ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE);
1909}
1910
shannonwoods@chromium.orgb8490f32013-05-30 00:08:00 +00001911}