shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // formatutils.cpp: Queries for GL image formats. |
| 8 | |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 9 | #include "common/mathutil.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/formatutils.h" |
| 11 | #include "libANGLE/Context.h" |
| 12 | #include "libANGLE/Framebuffer.h" |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 13 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 14 | using namespace angle; |
| 15 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 16 | namespace gl |
| 17 | { |
| 18 | |
| 19 | // ES2 requires that format is equal to internal format at all glTex*Image2D entry points and the implementation |
| 20 | // can decide the true, sized, internal format. The ES2FormatMap determines the internal format for all valid |
| 21 | // format and type combinations. |
Jamie Madill | ed4d342 | 2016-10-03 15:45:35 -0400 | [diff] [blame^] | 22 | GLenum GetSizedFormatInternal(GLenum format, GLenum type); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 23 | |
Jamie Madill | ed4d342 | 2016-10-03 15:45:35 -0400 | [diff] [blame^] | 24 | namespace |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 25 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 26 | typedef std::pair<GLenum, InternalFormat> InternalFormatInfoPair; |
| 27 | typedef std::map<GLenum, InternalFormat> InternalFormatInfoMap; |
| 28 | |
| 29 | } // anonymous namespace |
| 30 | |
| 31 | FormatType::FormatType() : format(GL_NONE), type(GL_NONE) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | FormatType::FormatType(GLenum format_, GLenum type_) : format(format_), type(type_) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | bool FormatType::operator<(const FormatType &other) const |
| 40 | { |
| 41 | if (format != other.format) |
| 42 | return format < other.format; |
| 43 | return type < other.type; |
| 44 | } |
| 45 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 46 | Type::Type() |
| 47 | : bytes(0), |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 48 | bytesShift(0), |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 49 | specialInterpretation(false) |
Geoff Lang | fe28ca0 | 2013-06-04 10:10:48 -0400 | [diff] [blame] | 50 | { |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 51 | } |
| 52 | |
Olli Etuaho | 31f8f4f | 2015-03-25 16:03:57 +0200 | [diff] [blame] | 53 | static Type GenTypeInfo(GLuint bytes, bool specialInterpretation) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 54 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 55 | Type info; |
| 56 | info.bytes = bytes; |
Olli Etuaho | 11ffe1b | 2015-03-24 17:28:18 +0200 | [diff] [blame] | 57 | GLuint i = 0; |
| 58 | while ((1u << i) < bytes) |
| 59 | { |
| 60 | ++i; |
| 61 | } |
| 62 | info.bytesShift = i; |
| 63 | ASSERT((1u << info.bytesShift) == bytes); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 64 | info.specialInterpretation = specialInterpretation; |
Olli Etuaho | 31f8f4f | 2015-03-25 16:03:57 +0200 | [diff] [blame] | 65 | return info; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 66 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 67 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 68 | bool operator<(const Type& a, const Type& b) |
| 69 | { |
| 70 | return memcmp(&a, &b, sizeof(Type)) < 0; |
| 71 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 72 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 73 | // Information about internal formats |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 74 | static bool AlwaysSupported(GLuint, const Extensions &) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 75 | { |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 76 | return true; |
| 77 | } |
| 78 | |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 79 | static bool NeverSupported(GLuint, const Extensions &) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 80 | { |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 81 | return false; |
| 82 | } |
| 83 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 84 | template <GLuint minCoreGLVersion> |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 85 | static bool RequireES(GLuint clientVersion, const Extensions &) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 86 | { |
| 87 | return clientVersion >= minCoreGLVersion; |
| 88 | } |
| 89 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 90 | // Pointer to a boolean memeber of the Extensions struct |
| 91 | typedef bool(Extensions::*ExtensionBool); |
| 92 | |
| 93 | // Check support for a single extension |
| 94 | template <ExtensionBool bool1> |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 95 | static bool RequireExt(GLuint, const Extensions & extensions) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 96 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 97 | return extensions.*bool1; |
| 98 | } |
| 99 | |
| 100 | // Check for a minimum client version or a single extension |
| 101 | template <GLuint minCoreGLVersion, ExtensionBool bool1> |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 102 | static bool RequireESOrExt(GLuint clientVersion, const Extensions &extensions) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 103 | { |
| 104 | return clientVersion >= minCoreGLVersion || extensions.*bool1; |
| 105 | } |
| 106 | |
| 107 | // Check for a minimum client version or two extensions |
| 108 | template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2> |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 109 | static bool RequireESOrExtAndExt(GLuint clientVersion, const Extensions &extensions) |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 110 | { |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 111 | return clientVersion >= minCoreGLVersion || (extensions.*bool1 && extensions.*bool2); |
| 112 | } |
| 113 | |
| 114 | // Check for a minimum client version or at least one of two extensions |
| 115 | template <GLuint minCoreGLVersion, ExtensionBool bool1, ExtensionBool bool2> |
| 116 | static bool RequireESOrExtOrExt(GLuint clientVersion, const Extensions &extensions) |
| 117 | { |
| 118 | return clientVersion >= minCoreGLVersion || extensions.*bool1 || extensions.*bool2; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | // Check support for two extensions |
| 122 | template <ExtensionBool bool1, ExtensionBool bool2> |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 123 | static bool RequireExtAndExt(GLuint, const Extensions &extensions) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 124 | { |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 125 | return extensions.*bool1 && extensions.*bool2; |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 126 | } |
| 127 | |
Geoff Lang | 60ad73d | 2015-10-23 10:08:44 -0400 | [diff] [blame] | 128 | // Check support for either of two extensions |
| 129 | template <ExtensionBool bool1, ExtensionBool bool2> |
| 130 | static bool RequireExtOrExt(GLuint, const Extensions &extensions) |
| 131 | { |
| 132 | return extensions.*bool1 || extensions.*bool2; |
| 133 | } |
| 134 | |
Jamie Madill | cd08973 | 2015-12-17 09:53:09 -0500 | [diff] [blame] | 135 | // Special function for half float formats with three or four channels. |
| 136 | static bool HalfFloatSupport(GLuint clientVersion, const Extensions &extensions) |
| 137 | { |
| 138 | return clientVersion >= 3 || extensions.textureHalfFloat; |
| 139 | } |
| 140 | |
| 141 | static bool HalfFloatRenderableSupport(GLuint clientVersion, const Extensions &extensions) |
| 142 | { |
| 143 | return HalfFloatSupport(clientVersion, extensions) && extensions.colorBufferHalfFloat; |
| 144 | } |
| 145 | |
| 146 | // Special function for half float formats with one or two channels. |
| 147 | static bool HalfFloatSupportRG(GLuint clientVersion, const Extensions &extensions) |
| 148 | { |
| 149 | return clientVersion >= 3 || (extensions.textureHalfFloat && extensions.textureRG); |
| 150 | } |
| 151 | |
| 152 | static bool HalfFloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions) |
| 153 | { |
| 154 | return HalfFloatSupportRG(clientVersion, extensions) && extensions.colorBufferHalfFloat; |
| 155 | } |
| 156 | |
| 157 | // Special function for float formats with three or four channels. |
| 158 | static bool FloatSupport(GLuint clientVersion, const Extensions &extensions) |
| 159 | { |
| 160 | return clientVersion >= 3 || extensions.textureFloat; |
| 161 | } |
| 162 | |
| 163 | static bool FloatRenderableSupport(GLuint clientVersion, const Extensions &extensions) |
| 164 | { |
| 165 | // We don't expose colorBufferFloat in ES2, but we silently support rendering to float. |
| 166 | return FloatSupport(clientVersion, extensions) && |
| 167 | (extensions.colorBufferFloat || clientVersion == 2); |
| 168 | } |
| 169 | |
| 170 | // Special function for float formats with one or two channels. |
| 171 | static bool FloatSupportRG(GLuint clientVersion, const Extensions &extensions) |
| 172 | { |
| 173 | return clientVersion >= 3 || (extensions.textureFloat && extensions.textureRG); |
| 174 | } |
| 175 | |
| 176 | static bool FloatRenderableSupportRG(GLuint clientVersion, const Extensions &extensions) |
| 177 | { |
| 178 | // We don't expose colorBufferFloat in ES2, but we silently support rendering to float. |
| 179 | return FloatSupportRG(clientVersion, extensions) && |
| 180 | (extensions.colorBufferFloat || clientVersion == 2); |
| 181 | } |
| 182 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 183 | InternalFormat::InternalFormat() |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 184 | : internalFormat(GL_NONE), |
| 185 | redBits(0), |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 186 | greenBits(0), |
| 187 | blueBits(0), |
| 188 | luminanceBits(0), |
| 189 | alphaBits(0), |
| 190 | sharedBits(0), |
| 191 | depthBits(0), |
| 192 | stencilBits(0), |
| 193 | pixelBytes(0), |
| 194 | componentCount(0), |
Corentin Wallez | bc99bb6 | 2015-05-14 17:42:20 -0400 | [diff] [blame] | 195 | compressed(false), |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 196 | compressedBlockWidth(0), |
| 197 | compressedBlockHeight(0), |
| 198 | format(GL_NONE), |
| 199 | type(GL_NONE), |
| 200 | componentType(GL_NONE), |
| 201 | colorEncoding(GL_NONE), |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 202 | textureSupport(NeverSupported), |
| 203 | renderSupport(NeverSupported), |
| 204 | filterSupport(NeverSupported) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 205 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 206 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 207 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 208 | bool InternalFormat::isLUMA() const |
| 209 | { |
| 210 | return ((redBits + greenBits + blueBits + depthBits + stencilBits) == 0 && |
| 211 | (luminanceBits + alphaBits) > 0); |
| 212 | } |
| 213 | |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 214 | GLenum InternalFormat::getReadPixelsFormat() const |
| 215 | { |
| 216 | return format; |
| 217 | } |
| 218 | |
| 219 | GLenum InternalFormat::getReadPixelsType() const |
| 220 | { |
| 221 | switch (type) |
| 222 | { |
| 223 | case GL_HALF_FLOAT: |
| 224 | // The internal format may have a type of GL_HALF_FLOAT but when exposing this type as |
| 225 | // the IMPLEMENTATION_READ_TYPE, only HALF_FLOAT_OES is allowed by |
| 226 | // OES_texture_half_float |
| 227 | return GL_HALF_FLOAT_OES; |
| 228 | |
| 229 | default: |
| 230 | return type; |
| 231 | } |
| 232 | } |
| 233 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 234 | Format::Format(GLenum internalFormat) : Format(GetInternalFormatInfo(internalFormat)) |
| 235 | { |
| 236 | } |
| 237 | |
| 238 | Format::Format(const InternalFormat &internalFormat) |
| 239 | : info(&internalFormat), format(info->format), type(info->type), sized(true) |
| 240 | { |
| 241 | ASSERT((info->pixelBytes > 0 && format != GL_NONE && type != GL_NONE) || |
| 242 | internalFormat.format == GL_NONE); |
| 243 | } |
| 244 | |
| 245 | Format::Format(GLenum internalFormat, GLenum format, GLenum type) |
| 246 | : info(nullptr), format(format), type(type), sized(false) |
| 247 | { |
| 248 | const auto &plainInfo = GetInternalFormatInfo(internalFormat); |
| 249 | sized = plainInfo.pixelBytes > 0; |
| 250 | info = (sized ? &plainInfo : &GetInternalFormatInfo(GetSizedFormatInternal(format, type))); |
| 251 | ASSERT(format == GL_NONE || info->pixelBytes > 0); |
| 252 | } |
| 253 | |
| 254 | Format::Format(const Format &other) = default; |
| 255 | Format &Format::operator=(const Format &other) = default; |
| 256 | |
| 257 | GLenum Format::asSized() const |
| 258 | { |
| 259 | return sized ? info->internalFormat : GetSizedFormatInternal(format, type); |
| 260 | } |
| 261 | |
| 262 | bool Format::valid() const |
| 263 | { |
| 264 | return info->format != GL_NONE; |
| 265 | } |
| 266 | |
| 267 | // static |
| 268 | bool Format::SameSized(const Format &a, const Format &b) |
| 269 | { |
| 270 | return (a.info == b.info); |
| 271 | } |
| 272 | |
| 273 | // static |
| 274 | Format Format::Invalid() |
| 275 | { |
| 276 | static Format invalid(GL_NONE, GL_NONE, GL_NONE); |
| 277 | return invalid; |
| 278 | } |
| 279 | |
| 280 | bool InternalFormat::operator==(const InternalFormat &other) const |
| 281 | { |
| 282 | // We assume there are no duplicates. |
| 283 | ASSERT((this == &other) == (internalFormat == other.internalFormat)); |
| 284 | return internalFormat == other.internalFormat; |
| 285 | } |
| 286 | |
| 287 | bool InternalFormat::operator!=(const InternalFormat &other) const |
| 288 | { |
| 289 | // We assume there are no duplicates. |
| 290 | ASSERT((this != &other) == (internalFormat != other.internalFormat)); |
| 291 | return internalFormat != other.internalFormat; |
| 292 | } |
| 293 | |
| 294 | static void AddUnsizedFormat(InternalFormatInfoMap *map, |
| 295 | GLenum internalFormat, |
| 296 | GLenum format, |
| 297 | InternalFormat::SupportCheckFunction textureSupport, |
| 298 | InternalFormat::SupportCheckFunction renderSupport, |
| 299 | InternalFormat::SupportCheckFunction filterSupport) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 300 | { |
| 301 | InternalFormat formatInfo; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 302 | formatInfo.internalFormat = internalFormat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 303 | formatInfo.format = format; |
| 304 | formatInfo.textureSupport = textureSupport; |
| 305 | formatInfo.renderSupport = renderSupport; |
| 306 | formatInfo.filterSupport = filterSupport; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 307 | ASSERT(map->count(internalFormat) == 0); |
| 308 | (*map)[internalFormat] = formatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 309 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 310 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 311 | void AddRGBAFormat(InternalFormatInfoMap *map, |
| 312 | GLenum internalFormat, |
| 313 | GLuint red, |
| 314 | GLuint green, |
| 315 | GLuint blue, |
| 316 | GLuint alpha, |
| 317 | GLuint shared, |
| 318 | GLenum format, |
| 319 | GLenum type, |
| 320 | GLenum componentType, |
| 321 | bool srgb, |
| 322 | InternalFormat::SupportCheckFunction textureSupport, |
| 323 | InternalFormat::SupportCheckFunction renderSupport, |
| 324 | InternalFormat::SupportCheckFunction filterSupport) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 325 | { |
| 326 | InternalFormat formatInfo; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 327 | formatInfo.internalFormat = internalFormat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 328 | formatInfo.redBits = red; |
| 329 | formatInfo.greenBits = green; |
| 330 | formatInfo.blueBits = blue; |
| 331 | formatInfo.alphaBits = alpha; |
| 332 | formatInfo.sharedBits = shared; |
| 333 | formatInfo.pixelBytes = (red + green + blue + alpha + shared) / 8; |
| 334 | formatInfo.componentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 335 | formatInfo.format = format; |
| 336 | formatInfo.type = type; |
| 337 | formatInfo.componentType = componentType; |
| 338 | formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR); |
| 339 | formatInfo.textureSupport = textureSupport; |
| 340 | formatInfo.renderSupport = renderSupport; |
| 341 | formatInfo.filterSupport = filterSupport; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 342 | ASSERT(map->count(internalFormat) == 0); |
| 343 | (*map)[internalFormat] = formatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 344 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 345 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 346 | static InternalFormat LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, GLenum componentType, |
| 347 | InternalFormat::SupportCheckFunction textureSupport, |
| 348 | InternalFormat::SupportCheckFunction renderSupport, |
| 349 | InternalFormat::SupportCheckFunction filterSupport) |
| 350 | { |
| 351 | InternalFormat formatInfo; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 352 | formatInfo.internalFormat = GetSizedFormatInternal(format, type); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 353 | formatInfo.luminanceBits = luminance; |
| 354 | formatInfo.alphaBits = alpha; |
| 355 | formatInfo.pixelBytes = (luminance + alpha) / 8; |
| 356 | formatInfo.componentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 357 | formatInfo.format = format; |
| 358 | formatInfo.type = type; |
| 359 | formatInfo.componentType = componentType; |
| 360 | formatInfo.colorEncoding = GL_LINEAR; |
| 361 | formatInfo.textureSupport = textureSupport; |
| 362 | formatInfo.renderSupport = renderSupport; |
| 363 | formatInfo.filterSupport = filterSupport; |
| 364 | return formatInfo; |
| 365 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 366 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 367 | void AddDepthStencilFormat(InternalFormatInfoMap *map, |
| 368 | GLenum internalFormat, |
| 369 | GLuint depthBits, |
| 370 | GLuint stencilBits, |
| 371 | GLuint unusedBits, |
| 372 | GLenum format, |
| 373 | GLenum type, |
| 374 | GLenum componentType, |
| 375 | InternalFormat::SupportCheckFunction textureSupport, |
| 376 | InternalFormat::SupportCheckFunction renderSupport, |
| 377 | InternalFormat::SupportCheckFunction filterSupport) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 378 | { |
| 379 | InternalFormat formatInfo; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 380 | formatInfo.internalFormat = internalFormat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 381 | formatInfo.depthBits = depthBits; |
| 382 | formatInfo.stencilBits = stencilBits; |
| 383 | formatInfo.pixelBytes = (depthBits + stencilBits + unusedBits) / 8; |
| 384 | formatInfo.componentCount = ((depthBits > 0) ? 1 : 0) + ((stencilBits > 0) ? 1 : 0); |
| 385 | formatInfo.format = format; |
| 386 | formatInfo.type = type; |
| 387 | formatInfo.componentType = componentType; |
| 388 | formatInfo.colorEncoding = GL_LINEAR; |
| 389 | formatInfo.textureSupport = textureSupport; |
| 390 | formatInfo.renderSupport = renderSupport; |
| 391 | formatInfo.filterSupport = filterSupport; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 392 | ASSERT(map->count(internalFormat) == 0); |
| 393 | (*map)[internalFormat] = formatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 394 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 395 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 396 | static InternalFormat CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, GLuint compressedBlockSize, |
| 397 | GLuint componentCount, GLenum format, GLenum type, bool srgb, |
| 398 | InternalFormat::SupportCheckFunction textureSupport, |
| 399 | InternalFormat::SupportCheckFunction renderSupport, |
| 400 | InternalFormat::SupportCheckFunction filterSupport) |
| 401 | { |
| 402 | InternalFormat formatInfo; |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 403 | formatInfo.internalFormat = format; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 404 | formatInfo.compressedBlockWidth = compressedBlockWidth; |
| 405 | formatInfo.compressedBlockHeight = compressedBlockHeight; |
| 406 | formatInfo.pixelBytes = compressedBlockSize / 8; |
| 407 | formatInfo.componentCount = componentCount; |
| 408 | formatInfo.format = format; |
| 409 | formatInfo.type = type; |
| 410 | formatInfo.componentType = GL_UNSIGNED_NORMALIZED; |
| 411 | formatInfo.colorEncoding = (srgb ? GL_SRGB : GL_LINEAR); |
| 412 | formatInfo.compressed = true; |
| 413 | formatInfo.textureSupport = textureSupport; |
| 414 | formatInfo.renderSupport = renderSupport; |
| 415 | formatInfo.filterSupport = filterSupport; |
| 416 | return formatInfo; |
| 417 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 418 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 419 | static InternalFormatInfoMap BuildInternalFormatInfoMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 420 | { |
| 421 | InternalFormatInfoMap map; |
| 422 | |
| 423 | // From ES 3.0.1 spec, table 3.12 |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 424 | map.insert(InternalFormatInfoPair(GL_NONE, InternalFormat())); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 425 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 426 | // clang-format off |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 427 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 428 | // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable | |
| 429 | AddRGBAFormat(&map, GL_R8, 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported); |
| 430 | AddRGBAFormat(&map, GL_R8_SNORM, 8, 0, 0, 0, 0, GL_RED, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported); |
| 431 | AddRGBAFormat(&map, GL_RG8, 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::textureRG>, RequireESOrExt<3, &Extensions::textureRG>, AlwaysSupported); |
| 432 | AddRGBAFormat(&map, GL_RG8_SNORM, 8, 8, 0, 0, 0, GL_RG, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported); |
| 433 | AddRGBAFormat(&map, GL_RGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported); |
| 434 | AddRGBAFormat(&map, GL_RGB8_SNORM, 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported); |
| 435 | AddRGBAFormat(&map, GL_RGB565, 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 436 | AddRGBAFormat(&map, GL_RGBA4, 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 437 | AddRGBAFormat(&map, GL_RGB5_A1, 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_UNSIGNED_NORMALIZED, false, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 438 | AddRGBAFormat(&map, GL_RGBA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireESOrExt<3, &Extensions::rgb8rgba8>, RequireESOrExt<3, &Extensions::rgb8rgba8>, AlwaysSupported); |
| 439 | AddRGBAFormat(&map, GL_RGBA8_SNORM, 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, GL_SIGNED_NORMALIZED, false, RequireES<3>, NeverSupported, AlwaysSupported); |
| 440 | AddRGBAFormat(&map, GL_RGB10_A2, 10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_NORMALIZED, false, RequireES<3>, RequireES<3>, AlwaysSupported); |
| 441 | AddRGBAFormat(&map, GL_RGB10_A2UI, 10, 10, 10, 2, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 442 | AddRGBAFormat(&map, GL_SRGB8, 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported); |
| 443 | AddRGBAFormat(&map, GL_SRGB8_ALPHA8, 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, true, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported); |
| 444 | AddRGBAFormat(&map, GL_RGB9_E5, 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, GL_FLOAT, false, RequireES<3>, NeverSupported, AlwaysSupported); |
| 445 | AddRGBAFormat(&map, GL_R8I, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 446 | AddRGBAFormat(&map, GL_R8UI, 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 447 | AddRGBAFormat(&map, GL_R16I, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 448 | AddRGBAFormat(&map, GL_R16UI, 16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 449 | AddRGBAFormat(&map, GL_R32I, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 450 | AddRGBAFormat(&map, GL_R32UI, 32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 451 | AddRGBAFormat(&map, GL_RG8I, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 452 | AddRGBAFormat(&map, GL_RG8UI, 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 453 | AddRGBAFormat(&map, GL_RG16I, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 454 | AddRGBAFormat(&map, GL_RG16UI, 16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 455 | AddRGBAFormat(&map, GL_RG32I, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 456 | AddRGBAFormat(&map, GL_R11F_G11F_B10F, 11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, GL_FLOAT, false, RequireES<3>, RequireExt<&Extensions::colorBufferFloat>, AlwaysSupported); |
| 457 | AddRGBAFormat(&map, GL_RG32UI, 32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 458 | AddRGBAFormat(&map, GL_RGB8I, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 459 | AddRGBAFormat(&map, GL_RGB8UI, 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 460 | AddRGBAFormat(&map, GL_RGB16I, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 461 | AddRGBAFormat(&map, GL_RGB16UI, 16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 462 | AddRGBAFormat(&map, GL_RGB32I, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, GL_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 463 | AddRGBAFormat(&map, GL_RGB32UI, 32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, NeverSupported, NeverSupported); |
| 464 | AddRGBAFormat(&map, GL_RGBA8I, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 465 | AddRGBAFormat(&map, GL_RGBA8UI, 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 466 | AddRGBAFormat(&map, GL_RGBA16I, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 467 | AddRGBAFormat(&map, GL_RGBA16UI, 16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 468 | AddRGBAFormat(&map, GL_RGBA32I, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, GL_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 469 | AddRGBAFormat(&map, GL_RGBA32UI, 32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, GL_UNSIGNED_INT, false, RequireES<3>, RequireES<3>, NeverSupported); |
| 470 | |
| 471 | AddRGBAFormat(&map, GL_BGRA8_EXT, 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported); |
| 472 | AddRGBAFormat(&map, GL_BGRA4_ANGLEX, 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported); |
| 473 | AddRGBAFormat(&map, GL_BGR5_A1_ANGLEX, 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 474 | |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 475 | // Special format which is not really supported, so always false for all supports. |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 476 | AddRGBAFormat(&map, GL_BGR565_ANGLEX, 5, 6, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_NORMALIZED, false, NeverSupported, NeverSupported, NeverSupported); |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 477 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 478 | // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 479 | // | Internal format | D |S | Format | Type | Comp | SRGB | Texture supported | Renderable | Filterable | |
| 480 | // | | | | | | type | | | | | |
| 481 | AddRGBAFormat(&map, GL_R16F, 16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>); |
| 482 | AddRGBAFormat(&map, GL_RG16F, 16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupportRG, HalfFloatRenderableSupportRG, RequireExt<&Extensions::textureHalfFloatLinear>); |
| 483 | AddRGBAFormat(&map, GL_RGB16F, 16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>); |
| 484 | AddRGBAFormat(&map, GL_RGBA16F, 16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, GL_FLOAT, false, HalfFloatSupport, HalfFloatRenderableSupport, RequireExt<&Extensions::textureHalfFloatLinear>); |
| 485 | AddRGBAFormat(&map, GL_R32F, 32, 0, 0, 0, 0, GL_RED, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> ); |
| 486 | AddRGBAFormat(&map, GL_RG32F, 32, 32, 0, 0, 0, GL_RG, GL_FLOAT, GL_FLOAT, false, FloatSupportRG, FloatRenderableSupportRG, RequireExt<&Extensions::textureFloatLinear> ); |
| 487 | AddRGBAFormat(&map, GL_RGB32F, 32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); |
| 488 | AddRGBAFormat(&map, GL_RGBA32F, 32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, GL_FLOAT, false, FloatSupport, FloatRenderableSupport, RequireExt<&Extensions::textureFloatLinear> ); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 489 | |
| 490 | // Depth stencil formats |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 491 | // | Internal format | D |S | X | Format | Type | Component type | Supported | Renderable | Filterable | |
| 492 | AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT16, 16, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, RequireESOrExt<3, &Extensions::depthTextures>); |
| 493 | AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT24, 24, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>); |
| 494 | AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32F, 32, 0, 0, GL_DEPTH_COMPONENT, GL_FLOAT, GL_FLOAT, RequireES<3>, RequireES<3>, RequireESOrExt<3, &Extensions::depthTextures>); |
| 495 | AddDepthStencilFormat(&map, GL_DEPTH_COMPONENT32_OES, 32, 0, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_UNSIGNED_NORMALIZED, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, RequireExtOrExt<&Extensions::depthTextures, &Extensions::depth32>, AlwaysSupported ); |
| 496 | AddDepthStencilFormat(&map, GL_DEPTH24_STENCIL8, 24, 8, 0, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_UNSIGNED_NORMALIZED, RequireESOrExt<3, &Extensions::depthTextures>, RequireESOrExtOrExt<3, &Extensions::depthTextures, &Extensions::packedDepthStencil>, AlwaysSupported ); |
| 497 | AddDepthStencilFormat(&map, GL_DEPTH32F_STENCIL8, 32, 8, 24, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_FLOAT, RequireES<3>, RequireES<3>, AlwaysSupported ); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 498 | // STENCIL_INDEX8 is special-cased, see around the bottom of the list. |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 499 | |
| 500 | // Luminance alpha formats |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 501 | // | Internal format | | L | A | Format | Type | Component type | Supported | Renderable | Filterable | |
Geoff Lang | abce762 | 2014-09-19 16:13:00 -0400 | [diff] [blame] | 502 | map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported))); |
| 503 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported))); |
| 504 | map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported))); |
| 505 | map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported))); |
| 506 | map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported))); |
| 507 | map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported))); |
| 508 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireExt<&Extensions::textureStorage>, NeverSupported, AlwaysSupported))); |
| 509 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureFloat>, NeverSupported, AlwaysSupported))); |
| 510 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_FLOAT, RequireExtAndExt<&Extensions::textureStorage, &Extensions::textureHalfFloat>, NeverSupported, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 511 | |
| 512 | // Unsized formats |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 513 | // | Internal format | Format | Supported | Renderable | Filterable | |
| 514 | AddUnsizedFormat(&map, GL_ALPHA, GL_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported); |
| 515 | AddUnsizedFormat(&map, GL_LUMINANCE, GL_LUMINANCE, RequireES<2>, NeverSupported, AlwaysSupported); |
| 516 | AddUnsizedFormat(&map, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, RequireES<2>, NeverSupported, AlwaysSupported); |
| 517 | AddUnsizedFormat(&map, GL_RED, GL_RED, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported); |
| 518 | AddUnsizedFormat(&map, GL_RG, GL_RG, RequireESOrExt<3, &Extensions::textureRG>, NeverSupported, AlwaysSupported); |
| 519 | AddUnsizedFormat(&map, GL_RGB, GL_RGB, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 520 | AddUnsizedFormat(&map, GL_RGBA, GL_RGBA, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 521 | AddUnsizedFormat(&map, GL_RED_INTEGER, GL_RED_INTEGER, RequireES<3>, NeverSupported, NeverSupported ); |
| 522 | AddUnsizedFormat(&map, GL_RG_INTEGER, GL_RG_INTEGER, RequireES<3>, NeverSupported, NeverSupported ); |
| 523 | AddUnsizedFormat(&map, GL_RGB_INTEGER, GL_RGB_INTEGER, RequireES<3>, NeverSupported, NeverSupported ); |
| 524 | AddUnsizedFormat(&map, GL_RGBA_INTEGER, GL_RGBA_INTEGER, RequireES<3>, NeverSupported, NeverSupported ); |
| 525 | AddUnsizedFormat(&map, GL_BGRA_EXT, GL_BGRA_EXT, RequireExt<&Extensions::textureFormatBGRA8888>, RequireExt<&Extensions::textureFormatBGRA8888>, AlwaysSupported); |
| 526 | AddUnsizedFormat(&map, GL_DEPTH_COMPONENT, GL_DEPTH_COMPONENT, RequireES<2>, RequireES<2>, AlwaysSupported); |
| 527 | AddUnsizedFormat(&map, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, RequireESOrExt<3, &Extensions::packedDepthStencil>, RequireESOrExt<3, &Extensions::packedDepthStencil>, AlwaysSupported); |
| 528 | AddUnsizedFormat(&map, GL_SRGB_EXT, GL_RGB, RequireESOrExt<3, &Extensions::sRGB>, NeverSupported, AlwaysSupported); |
| 529 | AddUnsizedFormat(&map, GL_SRGB_ALPHA_EXT, GL_RGBA, RequireESOrExt<3, &Extensions::sRGB>, RequireESOrExt<3, &Extensions::sRGB>, AlwaysSupported); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 530 | |
| 531 | // Compressed formats, From ES 3.0.1 spec, table 3.16 |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 532 | // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable | |
| 533 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 534 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 535 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 536 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 537 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 538 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 539 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 540 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 541 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, false, RequireES<3>, NeverSupported, AlwaysSupported))); |
| 542 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, true, RequireES<3>, NeverSupported, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 543 | |
| 544 | // From GL_EXT_texture_compression_dxt1 |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 545 | // | Internal format | |W |H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable | |
| 546 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported))); |
| 547 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT1>, NeverSupported, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 548 | |
| 549 | // From GL_ANGLE_texture_compression_dxt3 |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 550 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 551 | |
| 552 | // From GL_ANGLE_texture_compression_dxt5 |
Geoff Lang | 6ea6f94 | 2015-09-11 13:11:22 -0400 | [diff] [blame] | 553 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::textureCompressionDXT5>, NeverSupported, AlwaysSupported))); |
| 554 | |
| 555 | // From GL_OES_compressed_ETC1_RGB8_texture |
| 556 | map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_OES, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_OES, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::compressedETC1RGB8Texture>, NeverSupported, AlwaysSupported))); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 557 | |
Geoff Lang | 60ad73d | 2015-10-23 10:08:44 -0400 | [diff] [blame] | 558 | // From KHR_texture_compression_astc_hdr |
| 559 | // | Internal format | | W | H | BS |CC| Format | Type | SRGB | Supported | Renderable | Filterable | |
| 560 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 561 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 562 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 563 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 564 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 565 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 566 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 567 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 568 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 569 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 570 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 571 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 572 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 573 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_RGBA_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, false, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 574 | |
| 575 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, CompressedFormat( 4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 576 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, CompressedFormat( 5, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 577 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, CompressedFormat( 5, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 578 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, CompressedFormat( 6, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 579 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, CompressedFormat( 6, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 580 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, CompressedFormat( 8, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 581 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, CompressedFormat( 8, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 582 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, CompressedFormat( 8, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 583 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, CompressedFormat(10, 5, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 584 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, CompressedFormat(10, 6, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 585 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, CompressedFormat(10, 8, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 586 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, CompressedFormat(10, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 587 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, CompressedFormat(12, 10, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 588 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, CompressedFormat(12, 12, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, GL_UNSIGNED_BYTE, true, RequireExtOrExt<&Extensions::textureCompressionASTCHDR, &Extensions::textureCompressionASTCLDR>, NeverSupported, AlwaysSupported))); |
| 589 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 590 | // For STENCIL_INDEX8 we chose a normalized component type for the following reasons: |
| 591 | // - Multisampled buffer are disallowed for non-normalized integer component types and we want to support it for STENCIL_INDEX8 |
| 592 | // - All other stencil formats (all depth-stencil) are either float or normalized |
| 593 | // - It affects only validation of internalformat in RenderbufferStorageMultisample. |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 594 | // | Internal format |D |S |X | Format | Type | Component type | Supported | Renderable | Filterable | |
| 595 | AddDepthStencilFormat(&map, GL_STENCIL_INDEX8, 0, 8, 0, GL_STENCIL, GL_UNSIGNED_BYTE, GL_UNSIGNED_NORMALIZED, RequireES<2>, RequireES<2>, NeverSupported); |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 596 | |
| 597 | // From GL_ANGLE_lossy_etc_decode |
Geoff Lang | d13ca30 | 2016-09-08 09:35:57 -0400 | [diff] [blame] | 598 | map.insert(InternalFormatInfoPair(GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, CompressedFormat(4, 4, 64, 3, GL_ETC1_RGB8_LOSSY_DECODE_ANGLE, GL_UNSIGNED_BYTE, false, RequireExt<&Extensions::lossyETCDecode>, NeverSupported, AlwaysSupported))); |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 599 | |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 600 | // From GL_EXT_texture_norm16 |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 601 | // | Internal format | R | G | B | A |S | Format | Type | Component type | SRGB | Texture supported | Renderable | Filterable | |
| 602 | AddRGBAFormat(&map, GL_R16_EXT, 16, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported); |
| 603 | AddRGBAFormat(&map, GL_R16_SNORM_EXT, 16, 0, 0, 0, 0, GL_RED, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported); |
| 604 | AddRGBAFormat(&map, GL_RG16_EXT, 16, 16, 0, 0, 0, GL_RG, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported); |
| 605 | AddRGBAFormat(&map, GL_RG16_SNORM_EXT, 16, 16, 0, 0, 0, GL_RG, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported); |
| 606 | AddRGBAFormat(&map, GL_RGB16_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported); |
| 607 | AddRGBAFormat(&map, GL_RGB16_SNORM_EXT, 16, 16, 16, 0, 0, GL_RGB, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported); |
| 608 | AddRGBAFormat(&map, GL_RGBA16_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_UNSIGNED_SHORT, GL_UNSIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, RequireExt<&Extensions::textureNorm16>, AlwaysSupported); |
| 609 | AddRGBAFormat(&map, GL_RGBA16_SNORM_EXT, 16, 16, 16, 16, 0, GL_RGBA, GL_SHORT, GL_SIGNED_NORMALIZED, false, RequireExt<&Extensions::textureNorm16>, NeverSupported, AlwaysSupported); |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 610 | |
Geoff Lang | 9bbad18 | 2015-09-04 11:07:29 -0400 | [diff] [blame] | 611 | // clang-format on |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 612 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 613 | return map; |
| 614 | } |
| 615 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 616 | static const InternalFormatInfoMap &GetInternalFormatMap() |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 617 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 618 | static const InternalFormatInfoMap formatMap = BuildInternalFormatInfoMap(); |
| 619 | return formatMap; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 620 | } |
| 621 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 622 | static FormatSet BuildAllSizedInternalFormatSet() |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 623 | { |
| 624 | FormatSet result; |
| 625 | |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 626 | for (auto iter : GetInternalFormatMap()) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 627 | { |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 628 | if (iter.second.pixelBytes > 0) |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 629 | { |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 630 | // TODO(jmadill): Fix this hack. |
| 631 | if (iter.first == GL_BGR565_ANGLEX) |
| 632 | continue; |
| 633 | |
| 634 | result.insert(iter.first); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | |
| 638 | return result; |
| 639 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 640 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 641 | const Type &GetTypeInfo(GLenum type) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 642 | { |
Olli Etuaho | 31f8f4f | 2015-03-25 16:03:57 +0200 | [diff] [blame] | 643 | switch (type) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 644 | { |
Olli Etuaho | 31f8f4f | 2015-03-25 16:03:57 +0200 | [diff] [blame] | 645 | case GL_UNSIGNED_BYTE: |
| 646 | case GL_BYTE: |
| 647 | { |
| 648 | static const Type info = GenTypeInfo(1, false); |
| 649 | return info; |
| 650 | } |
| 651 | case GL_UNSIGNED_SHORT: |
| 652 | case GL_SHORT: |
| 653 | case GL_HALF_FLOAT: |
| 654 | case GL_HALF_FLOAT_OES: |
| 655 | { |
| 656 | static const Type info = GenTypeInfo(2, false); |
| 657 | return info; |
| 658 | } |
| 659 | case GL_UNSIGNED_INT: |
| 660 | case GL_INT: |
| 661 | case GL_FLOAT: |
| 662 | { |
| 663 | static const Type info = GenTypeInfo(4, false); |
| 664 | return info; |
| 665 | } |
| 666 | case GL_UNSIGNED_SHORT_5_6_5: |
| 667 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 668 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 669 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 670 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 671 | { |
| 672 | static const Type info = GenTypeInfo(2, true); |
| 673 | return info; |
| 674 | } |
| 675 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 676 | case GL_UNSIGNED_INT_24_8: |
| 677 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 678 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 679 | { |
| 680 | ASSERT(GL_UNSIGNED_INT_24_8_OES == GL_UNSIGNED_INT_24_8); |
| 681 | static const Type info = GenTypeInfo(4, true); |
| 682 | return info; |
| 683 | } |
| 684 | case GL_FLOAT_32_UNSIGNED_INT_24_8_REV: |
| 685 | { |
| 686 | static const Type info = GenTypeInfo(8, true); |
| 687 | return info; |
| 688 | } |
| 689 | default: |
| 690 | { |
| 691 | static const Type defaultInfo; |
| 692 | return defaultInfo; |
| 693 | } |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 697 | const InternalFormat &GetInternalFormatInfo(GLenum internalFormat) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 698 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 699 | const InternalFormatInfoMap &formatMap = GetInternalFormatMap(); |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 700 | auto iter = formatMap.find(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 701 | if (iter != formatMap.end()) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 702 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 703 | return iter->second; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 704 | } |
| 705 | else |
| 706 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 707 | static const InternalFormat defaultInternalFormat; |
Jamie Madill | ec0b580 | 2016-07-04 13:11:59 -0400 | [diff] [blame] | 708 | UNREACHABLE(); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 709 | return defaultInternalFormat; |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Corentin Wallez | c5cacd6 | 2016-09-14 14:50:24 -0400 | [diff] [blame] | 713 | GLuint InternalFormat::computePixelBytes(GLenum formatType) const |
| 714 | { |
| 715 | const auto &typeInfo = GetTypeInfo(formatType); |
| 716 | GLuint components = typeInfo.specialInterpretation ? 1u : componentCount; |
| 717 | return components * typeInfo.bytes; |
| 718 | } |
| 719 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 720 | ErrorOrResult<GLuint> InternalFormat::computeRowPitch(GLenum formatType, |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 721 | GLsizei width, |
| 722 | GLint alignment, |
| 723 | GLint rowLength) const |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 724 | { |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 725 | // Compressed images do not use pack/unpack parameters. |
| 726 | if (compressed) |
| 727 | { |
| 728 | ASSERT(rowLength == 0); |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 729 | return computeCompressedImageSize(formatType, Extents(width, 1, 1)); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 730 | } |
| 731 | |
Geoff Lang | 3f23406 | 2016-07-13 15:35:45 -0400 | [diff] [blame] | 732 | CheckedNumeric<GLuint> checkedWidth(rowLength > 0 ? rowLength : width); |
Corentin Wallez | c5cacd6 | 2016-09-14 14:50:24 -0400 | [diff] [blame] | 733 | CheckedNumeric<GLuint> checkedRowBytes = checkedWidth * computePixelBytes(formatType); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 734 | |
| 735 | ASSERT(alignment > 0 && isPow2(alignment)); |
| 736 | CheckedNumeric<GLuint> checkedAlignment(alignment); |
| 737 | auto aligned = rx::roundUp(checkedRowBytes, checkedAlignment); |
| 738 | ANGLE_TRY_CHECKED_MATH(aligned); |
| 739 | return aligned.ValueOrDie(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 740 | } |
| 741 | |
Corentin Wallez | 0e48719 | 2016-10-03 16:30:38 -0400 | [diff] [blame] | 742 | ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLsizei height, |
| 743 | GLint imageHeight, |
| 744 | GLuint rowPitch) const |
| 745 | { |
| 746 | GLuint rows = |
| 747 | (imageHeight > 0 ? static_cast<GLuint>(imageHeight) : static_cast<GLuint>(height)); |
| 748 | CheckedNumeric<GLuint> checkedRowPitch(rowPitch); |
| 749 | |
| 750 | auto depthPitch = checkedRowPitch * rows; |
| 751 | ANGLE_TRY_CHECKED_MATH(depthPitch); |
| 752 | return depthPitch.ValueOrDie(); |
| 753 | } |
| 754 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 755 | ErrorOrResult<GLuint> InternalFormat::computeDepthPitch(GLenum formatType, |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 756 | GLsizei width, |
| 757 | GLsizei height, |
| 758 | GLint alignment, |
| 759 | GLint rowLength, |
| 760 | GLint imageHeight) const |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 761 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 762 | GLuint rowPitch = 0; |
| 763 | ANGLE_TRY_RESULT(computeRowPitch(formatType, width, alignment, rowLength), rowPitch); |
Corentin Wallez | 0e48719 | 2016-10-03 16:30:38 -0400 | [diff] [blame] | 764 | return computeDepthPitch(height, imageHeight, rowPitch); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 765 | } |
| 766 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 767 | ErrorOrResult<GLuint> InternalFormat::computeCompressedImageSize(GLenum formatType, |
| 768 | const Extents &size) const |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 769 | { |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 770 | CheckedNumeric<GLuint> checkedWidth(size.width); |
| 771 | CheckedNumeric<GLuint> checkedHeight(size.height); |
| 772 | CheckedNumeric<GLuint> checkedDepth(size.depth); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 773 | CheckedNumeric<GLuint> checkedBlockWidth(compressedBlockWidth); |
| 774 | CheckedNumeric<GLuint> checkedBlockHeight(compressedBlockHeight); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 775 | |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 776 | ASSERT(compressed); |
| 777 | auto numBlocksWide = (checkedWidth + checkedBlockWidth - 1u) / checkedBlockWidth; |
| 778 | auto numBlocksHigh = (checkedHeight + checkedBlockHeight - 1u) / checkedBlockHeight; |
| 779 | auto bytes = numBlocksWide * numBlocksHigh * pixelBytes * checkedDepth; |
| 780 | ANGLE_TRY_CHECKED_MATH(bytes); |
| 781 | return bytes.ValueOrDie(); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 782 | } |
| 783 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 784 | ErrorOrResult<GLuint> InternalFormat::computeSkipBytes(GLuint rowPitch, |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 785 | GLuint depthPitch, |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 786 | const PixelStoreStateBase &state, |
| 787 | bool is3D) const |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 788 | { |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 789 | CheckedNumeric<GLuint> checkedRowPitch(rowPitch); |
| 790 | CheckedNumeric<GLuint> checkedDepthPitch(depthPitch); |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 791 | CheckedNumeric<GLuint> checkedSkipImages(static_cast<GLuint>(state.skipImages)); |
| 792 | CheckedNumeric<GLuint> checkedSkipRows(static_cast<GLuint>(state.skipRows)); |
| 793 | CheckedNumeric<GLuint> checkedSkipPixels(static_cast<GLuint>(state.skipPixels)); |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 794 | CheckedNumeric<GLuint> checkedPixelBytes(pixelBytes); |
| 795 | auto checkedSkipImagesBytes = checkedSkipImages * checkedDepthPitch; |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 796 | if (!is3D) |
Olli Etuaho | 989cac3 | 2016-06-08 16:18:49 -0700 | [diff] [blame] | 797 | { |
| 798 | checkedSkipImagesBytes = 0; |
| 799 | } |
| 800 | auto skipBytes = checkedSkipImagesBytes + checkedSkipRows * checkedRowPitch + |
| 801 | checkedSkipPixels * checkedPixelBytes; |
| 802 | ANGLE_TRY_CHECKED_MATH(skipBytes); |
| 803 | return skipBytes.ValueOrDie(); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 804 | } |
| 805 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 806 | ErrorOrResult<GLuint> InternalFormat::computePackUnpackEndByte( |
| 807 | GLenum formatType, |
| 808 | const Extents &size, |
| 809 | const PixelStoreStateBase &state, |
| 810 | bool is3D) const |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 811 | { |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 812 | GLuint rowPitch = 0; |
| 813 | ANGLE_TRY_RESULT(computeRowPitch(formatType, size.width, state.alignment, state.rowLength), |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 814 | rowPitch); |
| 815 | |
Corentin Wallez | 0e48719 | 2016-10-03 16:30:38 -0400 | [diff] [blame] | 816 | GLuint depthPitch = 0; |
| 817 | if (is3D) |
| 818 | { |
| 819 | ANGLE_TRY_RESULT(computeDepthPitch(size.height, state.imageHeight, rowPitch), depthPitch); |
| 820 | } |
| 821 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 822 | CheckedNumeric<GLuint> checkedCopyBytes = 0; |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 823 | if (compressed) |
| 824 | { |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 825 | ANGLE_TRY_RESULT(computeCompressedImageSize(formatType, size), checkedCopyBytes); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 826 | } |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 827 | else if (size.height != 0 && (!is3D || size.depth != 0)) |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 828 | { |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 829 | CheckedNumeric<GLuint> bytes = computePixelBytes(formatType); |
| 830 | checkedCopyBytes += size.width * bytes; |
| 831 | |
| 832 | CheckedNumeric<GLuint> heightMinusOne = size.height - 1; |
| 833 | checkedCopyBytes += heightMinusOne * rowPitch; |
| 834 | |
| 835 | if (is3D) |
| 836 | { |
| 837 | CheckedNumeric<GLuint> depthMinusOne = size.depth - 1; |
| 838 | checkedCopyBytes += depthMinusOne * depthPitch; |
| 839 | } |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 840 | } |
| 841 | |
Corentin Wallez | 886de36 | 2016-09-27 10:49:35 -0400 | [diff] [blame] | 842 | CheckedNumeric<GLuint> checkedSkipBytes = 0; |
| 843 | ANGLE_TRY_RESULT(computeSkipBytes(rowPitch, depthPitch, state, is3D), checkedSkipBytes); |
Corentin Wallez | c5cacd6 | 2016-09-14 14:50:24 -0400 | [diff] [blame] | 844 | |
| 845 | CheckedNumeric<GLuint> endByte = checkedCopyBytes + checkedSkipBytes; |
| 846 | |
| 847 | ANGLE_TRY_CHECKED_MATH(endByte); |
| 848 | return endByte.ValueOrDie(); |
| 849 | } |
| 850 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 851 | GLenum GetSizedInternalFormat(GLenum internalFormat, GLenum type) |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 852 | { |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 853 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalFormat); |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 854 | if (formatInfo.pixelBytes > 0) |
| 855 | { |
| 856 | return internalFormat; |
| 857 | } |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 858 | return GetSizedFormatInternal(internalFormat, type); |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 861 | const FormatSet &GetAllSizedInternalFormats() |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 862 | { |
Geoff Lang | e4a492b | 2014-06-19 14:14:41 -0400 | [diff] [blame] | 863 | static FormatSet formatSet = BuildAllSizedInternalFormatSet(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 864 | return formatSet; |
| 865 | } |
| 866 | |
Jamie Madill | 09e2d93 | 2015-07-14 16:40:31 -0400 | [diff] [blame] | 867 | AttributeType GetAttributeType(GLenum enumValue) |
| 868 | { |
| 869 | switch (enumValue) |
| 870 | { |
| 871 | case GL_FLOAT: |
| 872 | return ATTRIBUTE_FLOAT; |
| 873 | case GL_FLOAT_VEC2: |
| 874 | return ATTRIBUTE_VEC2; |
| 875 | case GL_FLOAT_VEC3: |
| 876 | return ATTRIBUTE_VEC3; |
| 877 | case GL_FLOAT_VEC4: |
| 878 | return ATTRIBUTE_VEC4; |
| 879 | case GL_INT: |
| 880 | return ATTRIBUTE_INT; |
| 881 | case GL_INT_VEC2: |
| 882 | return ATTRIBUTE_IVEC2; |
| 883 | case GL_INT_VEC3: |
| 884 | return ATTRIBUTE_IVEC3; |
| 885 | case GL_INT_VEC4: |
| 886 | return ATTRIBUTE_IVEC4; |
| 887 | case GL_UNSIGNED_INT: |
| 888 | return ATTRIBUTE_UINT; |
| 889 | case GL_UNSIGNED_INT_VEC2: |
| 890 | return ATTRIBUTE_UVEC2; |
| 891 | case GL_UNSIGNED_INT_VEC3: |
| 892 | return ATTRIBUTE_UVEC3; |
| 893 | case GL_UNSIGNED_INT_VEC4: |
| 894 | return ATTRIBUTE_UVEC4; |
| 895 | case GL_FLOAT_MAT2: |
| 896 | return ATTRIBUTE_MAT2; |
| 897 | case GL_FLOAT_MAT3: |
| 898 | return ATTRIBUTE_MAT3; |
| 899 | case GL_FLOAT_MAT4: |
| 900 | return ATTRIBUTE_MAT4; |
| 901 | case GL_FLOAT_MAT2x3: |
| 902 | return ATTRIBUTE_MAT2x3; |
| 903 | case GL_FLOAT_MAT2x4: |
| 904 | return ATTRIBUTE_MAT2x4; |
| 905 | case GL_FLOAT_MAT3x2: |
| 906 | return ATTRIBUTE_MAT3x2; |
| 907 | case GL_FLOAT_MAT3x4: |
| 908 | return ATTRIBUTE_MAT3x4; |
| 909 | case GL_FLOAT_MAT4x2: |
| 910 | return ATTRIBUTE_MAT4x2; |
| 911 | case GL_FLOAT_MAT4x3: |
| 912 | return ATTRIBUTE_MAT4x3; |
| 913 | default: |
| 914 | UNREACHABLE(); |
| 915 | return ATTRIBUTE_FLOAT; |
| 916 | } |
| 917 | } |
| 918 | |
Jamie Madill | d3dfda2 | 2015-07-06 08:28:49 -0400 | [diff] [blame] | 919 | VertexFormatType GetVertexFormatType(GLenum type, GLboolean normalized, GLuint components, bool pureInteger) |
| 920 | { |
| 921 | switch (type) |
| 922 | { |
| 923 | case GL_BYTE: |
| 924 | switch (components) |
| 925 | { |
| 926 | case 1: |
| 927 | if (pureInteger) |
| 928 | return VERTEX_FORMAT_SBYTE1_INT; |
| 929 | if (normalized) |
| 930 | return VERTEX_FORMAT_SBYTE1_NORM; |
| 931 | return VERTEX_FORMAT_SBYTE1; |
| 932 | case 2: |
| 933 | if (pureInteger) |
| 934 | return VERTEX_FORMAT_SBYTE2_INT; |
| 935 | if (normalized) |
| 936 | return VERTEX_FORMAT_SBYTE2_NORM; |
| 937 | return VERTEX_FORMAT_SBYTE2; |
| 938 | case 3: |
| 939 | if (pureInteger) |
| 940 | return VERTEX_FORMAT_SBYTE3_INT; |
| 941 | if (normalized) |
| 942 | return VERTEX_FORMAT_SBYTE3_NORM; |
| 943 | return VERTEX_FORMAT_SBYTE3; |
| 944 | case 4: |
| 945 | if (pureInteger) |
| 946 | return VERTEX_FORMAT_SBYTE4_INT; |
| 947 | if (normalized) |
| 948 | return VERTEX_FORMAT_SBYTE4_NORM; |
| 949 | return VERTEX_FORMAT_SBYTE4; |
| 950 | default: |
| 951 | UNREACHABLE(); |
| 952 | break; |
| 953 | } |
| 954 | case GL_UNSIGNED_BYTE: |
| 955 | switch (components) |
| 956 | { |
| 957 | case 1: |
| 958 | if (pureInteger) |
| 959 | return VERTEX_FORMAT_UBYTE1_INT; |
| 960 | if (normalized) |
| 961 | return VERTEX_FORMAT_UBYTE1_NORM; |
| 962 | return VERTEX_FORMAT_UBYTE1; |
| 963 | case 2: |
| 964 | if (pureInteger) |
| 965 | return VERTEX_FORMAT_UBYTE2_INT; |
| 966 | if (normalized) |
| 967 | return VERTEX_FORMAT_UBYTE2_NORM; |
| 968 | return VERTEX_FORMAT_UBYTE2; |
| 969 | case 3: |
| 970 | if (pureInteger) |
| 971 | return VERTEX_FORMAT_UBYTE3_INT; |
| 972 | if (normalized) |
| 973 | return VERTEX_FORMAT_UBYTE3_NORM; |
| 974 | return VERTEX_FORMAT_UBYTE3; |
| 975 | case 4: |
| 976 | if (pureInteger) |
| 977 | return VERTEX_FORMAT_UBYTE4_INT; |
| 978 | if (normalized) |
| 979 | return VERTEX_FORMAT_UBYTE4_NORM; |
| 980 | return VERTEX_FORMAT_UBYTE4; |
| 981 | default: |
| 982 | UNREACHABLE(); |
| 983 | break; |
| 984 | } |
| 985 | case GL_SHORT: |
| 986 | switch (components) |
| 987 | { |
| 988 | case 1: |
| 989 | if (pureInteger) |
| 990 | return VERTEX_FORMAT_SSHORT1_INT; |
| 991 | if (normalized) |
| 992 | return VERTEX_FORMAT_SSHORT1_NORM; |
| 993 | return VERTEX_FORMAT_SSHORT1; |
| 994 | case 2: |
| 995 | if (pureInteger) |
| 996 | return VERTEX_FORMAT_SSHORT2_INT; |
| 997 | if (normalized) |
| 998 | return VERTEX_FORMAT_SSHORT2_NORM; |
| 999 | return VERTEX_FORMAT_SSHORT2; |
| 1000 | case 3: |
| 1001 | if (pureInteger) |
| 1002 | return VERTEX_FORMAT_SSHORT3_INT; |
| 1003 | if (normalized) |
| 1004 | return VERTEX_FORMAT_SSHORT3_NORM; |
| 1005 | return VERTEX_FORMAT_SSHORT3; |
| 1006 | case 4: |
| 1007 | if (pureInteger) |
| 1008 | return VERTEX_FORMAT_SSHORT4_INT; |
| 1009 | if (normalized) |
| 1010 | return VERTEX_FORMAT_SSHORT4_NORM; |
| 1011 | return VERTEX_FORMAT_SSHORT4; |
| 1012 | default: |
| 1013 | UNREACHABLE(); |
| 1014 | break; |
| 1015 | } |
| 1016 | case GL_UNSIGNED_SHORT: |
| 1017 | switch (components) |
| 1018 | { |
| 1019 | case 1: |
| 1020 | if (pureInteger) |
| 1021 | return VERTEX_FORMAT_USHORT1_INT; |
| 1022 | if (normalized) |
| 1023 | return VERTEX_FORMAT_USHORT1_NORM; |
| 1024 | return VERTEX_FORMAT_USHORT1; |
| 1025 | case 2: |
| 1026 | if (pureInteger) |
| 1027 | return VERTEX_FORMAT_USHORT2_INT; |
| 1028 | if (normalized) |
| 1029 | return VERTEX_FORMAT_USHORT2_NORM; |
| 1030 | return VERTEX_FORMAT_USHORT2; |
| 1031 | case 3: |
| 1032 | if (pureInteger) |
| 1033 | return VERTEX_FORMAT_USHORT3_INT; |
| 1034 | if (normalized) |
| 1035 | return VERTEX_FORMAT_USHORT3_NORM; |
| 1036 | return VERTEX_FORMAT_USHORT3; |
| 1037 | case 4: |
| 1038 | if (pureInteger) |
| 1039 | return VERTEX_FORMAT_USHORT4_INT; |
| 1040 | if (normalized) |
| 1041 | return VERTEX_FORMAT_USHORT4_NORM; |
| 1042 | return VERTEX_FORMAT_USHORT4; |
| 1043 | default: |
| 1044 | UNREACHABLE(); |
| 1045 | break; |
| 1046 | } |
| 1047 | case GL_INT: |
| 1048 | switch (components) |
| 1049 | { |
| 1050 | case 1: |
| 1051 | if (pureInteger) |
| 1052 | return VERTEX_FORMAT_SINT1_INT; |
| 1053 | if (normalized) |
| 1054 | return VERTEX_FORMAT_SINT1_NORM; |
| 1055 | return VERTEX_FORMAT_SINT1; |
| 1056 | case 2: |
| 1057 | if (pureInteger) |
| 1058 | return VERTEX_FORMAT_SINT2_INT; |
| 1059 | if (normalized) |
| 1060 | return VERTEX_FORMAT_SINT2_NORM; |
| 1061 | return VERTEX_FORMAT_SINT2; |
| 1062 | case 3: |
| 1063 | if (pureInteger) |
| 1064 | return VERTEX_FORMAT_SINT3_INT; |
| 1065 | if (normalized) |
| 1066 | return VERTEX_FORMAT_SINT3_NORM; |
| 1067 | return VERTEX_FORMAT_SINT3; |
| 1068 | case 4: |
| 1069 | if (pureInteger) |
| 1070 | return VERTEX_FORMAT_SINT4_INT; |
| 1071 | if (normalized) |
| 1072 | return VERTEX_FORMAT_SINT4_NORM; |
| 1073 | return VERTEX_FORMAT_SINT4; |
| 1074 | default: |
| 1075 | UNREACHABLE(); |
| 1076 | break; |
| 1077 | } |
| 1078 | case GL_UNSIGNED_INT: |
| 1079 | switch (components) |
| 1080 | { |
| 1081 | case 1: |
| 1082 | if (pureInteger) |
| 1083 | return VERTEX_FORMAT_UINT1_INT; |
| 1084 | if (normalized) |
| 1085 | return VERTEX_FORMAT_UINT1_NORM; |
| 1086 | return VERTEX_FORMAT_UINT1; |
| 1087 | case 2: |
| 1088 | if (pureInteger) |
| 1089 | return VERTEX_FORMAT_UINT2_INT; |
| 1090 | if (normalized) |
| 1091 | return VERTEX_FORMAT_UINT2_NORM; |
| 1092 | return VERTEX_FORMAT_UINT2; |
| 1093 | case 3: |
| 1094 | if (pureInteger) |
| 1095 | return VERTEX_FORMAT_UINT3_INT; |
| 1096 | if (normalized) |
| 1097 | return VERTEX_FORMAT_UINT3_NORM; |
| 1098 | return VERTEX_FORMAT_UINT3; |
| 1099 | case 4: |
| 1100 | if (pureInteger) |
| 1101 | return VERTEX_FORMAT_UINT4_INT; |
| 1102 | if (normalized) |
| 1103 | return VERTEX_FORMAT_UINT4_NORM; |
| 1104 | return VERTEX_FORMAT_UINT4; |
| 1105 | default: |
| 1106 | UNREACHABLE(); |
| 1107 | break; |
| 1108 | } |
| 1109 | case GL_FLOAT: |
| 1110 | switch (components) |
| 1111 | { |
| 1112 | case 1: |
| 1113 | return VERTEX_FORMAT_FLOAT1; |
| 1114 | case 2: |
| 1115 | return VERTEX_FORMAT_FLOAT2; |
| 1116 | case 3: |
| 1117 | return VERTEX_FORMAT_FLOAT3; |
| 1118 | case 4: |
| 1119 | return VERTEX_FORMAT_FLOAT4; |
| 1120 | default: |
| 1121 | UNREACHABLE(); |
| 1122 | break; |
| 1123 | } |
| 1124 | case GL_HALF_FLOAT: |
| 1125 | switch (components) |
| 1126 | { |
| 1127 | case 1: |
| 1128 | return VERTEX_FORMAT_HALF1; |
| 1129 | case 2: |
| 1130 | return VERTEX_FORMAT_HALF2; |
| 1131 | case 3: |
| 1132 | return VERTEX_FORMAT_HALF3; |
| 1133 | case 4: |
| 1134 | return VERTEX_FORMAT_HALF4; |
| 1135 | default: |
| 1136 | UNREACHABLE(); |
| 1137 | break; |
| 1138 | } |
| 1139 | case GL_FIXED: |
| 1140 | switch (components) |
| 1141 | { |
| 1142 | case 1: |
| 1143 | return VERTEX_FORMAT_FIXED1; |
| 1144 | case 2: |
| 1145 | return VERTEX_FORMAT_FIXED2; |
| 1146 | case 3: |
| 1147 | return VERTEX_FORMAT_FIXED3; |
| 1148 | case 4: |
| 1149 | return VERTEX_FORMAT_FIXED4; |
| 1150 | default: |
| 1151 | UNREACHABLE(); |
| 1152 | break; |
| 1153 | } |
| 1154 | case GL_INT_2_10_10_10_REV: |
| 1155 | if (pureInteger) |
| 1156 | return VERTEX_FORMAT_SINT210_INT; |
| 1157 | if (normalized) |
| 1158 | return VERTEX_FORMAT_SINT210_NORM; |
| 1159 | return VERTEX_FORMAT_SINT210; |
| 1160 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1161 | if (pureInteger) |
| 1162 | return VERTEX_FORMAT_UINT210_INT; |
| 1163 | if (normalized) |
| 1164 | return VERTEX_FORMAT_UINT210_NORM; |
| 1165 | return VERTEX_FORMAT_UINT210; |
| 1166 | default: |
| 1167 | UNREACHABLE(); |
| 1168 | break; |
| 1169 | } |
| 1170 | return VERTEX_FORMAT_UBYTE1; |
| 1171 | } |
| 1172 | |
| 1173 | VertexFormatType GetVertexFormatType(const VertexAttribute &attrib) |
| 1174 | { |
| 1175 | return GetVertexFormatType(attrib.type, attrib.normalized, attrib.size, attrib.pureInteger); |
| 1176 | } |
| 1177 | |
| 1178 | VertexFormatType GetVertexFormatType(const VertexAttribute &attrib, GLenum currentValueType) |
| 1179 | { |
| 1180 | if (!attrib.enabled) |
| 1181 | { |
| 1182 | return GetVertexFormatType(currentValueType, GL_FALSE, 4, (currentValueType != GL_FLOAT)); |
| 1183 | } |
| 1184 | return GetVertexFormatType(attrib); |
| 1185 | } |
| 1186 | |
| 1187 | const VertexFormat &GetVertexFormatFromType(VertexFormatType vertexFormatType) |
| 1188 | { |
| 1189 | switch (vertexFormatType) |
| 1190 | { |
| 1191 | case VERTEX_FORMAT_SBYTE1: |
| 1192 | { |
| 1193 | static const VertexFormat format(GL_BYTE, GL_FALSE, 1, false); |
| 1194 | return format; |
| 1195 | } |
| 1196 | case VERTEX_FORMAT_SBYTE1_NORM: |
| 1197 | { |
| 1198 | static const VertexFormat format(GL_BYTE, GL_TRUE, 1, false); |
| 1199 | return format; |
| 1200 | } |
| 1201 | case VERTEX_FORMAT_SBYTE2: |
| 1202 | { |
| 1203 | static const VertexFormat format(GL_BYTE, GL_FALSE, 2, false); |
| 1204 | return format; |
| 1205 | } |
| 1206 | case VERTEX_FORMAT_SBYTE2_NORM: |
| 1207 | { |
| 1208 | static const VertexFormat format(GL_BYTE, GL_TRUE, 2, false); |
| 1209 | return format; |
| 1210 | } |
| 1211 | case VERTEX_FORMAT_SBYTE3: |
| 1212 | { |
| 1213 | static const VertexFormat format(GL_BYTE, GL_FALSE, 3, false); |
| 1214 | return format; |
| 1215 | } |
| 1216 | case VERTEX_FORMAT_SBYTE3_NORM: |
| 1217 | { |
| 1218 | static const VertexFormat format(GL_BYTE, GL_TRUE, 3, false); |
| 1219 | return format; |
| 1220 | } |
| 1221 | case VERTEX_FORMAT_SBYTE4: |
| 1222 | { |
| 1223 | static const VertexFormat format(GL_BYTE, GL_FALSE, 4, false); |
| 1224 | return format; |
| 1225 | } |
| 1226 | case VERTEX_FORMAT_SBYTE4_NORM: |
| 1227 | { |
| 1228 | static const VertexFormat format(GL_BYTE, GL_TRUE, 4, false); |
| 1229 | return format; |
| 1230 | } |
| 1231 | case VERTEX_FORMAT_UBYTE1: |
| 1232 | { |
| 1233 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, false); |
| 1234 | return format; |
| 1235 | } |
| 1236 | case VERTEX_FORMAT_UBYTE1_NORM: |
| 1237 | { |
| 1238 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 1, false); |
| 1239 | return format; |
| 1240 | } |
| 1241 | case VERTEX_FORMAT_UBYTE2: |
| 1242 | { |
| 1243 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, false); |
| 1244 | return format; |
| 1245 | } |
| 1246 | case VERTEX_FORMAT_UBYTE2_NORM: |
| 1247 | { |
| 1248 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 2, false); |
| 1249 | return format; |
| 1250 | } |
| 1251 | case VERTEX_FORMAT_UBYTE3: |
| 1252 | { |
| 1253 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, false); |
| 1254 | return format; |
| 1255 | } |
| 1256 | case VERTEX_FORMAT_UBYTE3_NORM: |
| 1257 | { |
| 1258 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 3, false); |
| 1259 | return format; |
| 1260 | } |
| 1261 | case VERTEX_FORMAT_UBYTE4: |
| 1262 | { |
| 1263 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, false); |
| 1264 | return format; |
| 1265 | } |
| 1266 | case VERTEX_FORMAT_UBYTE4_NORM: |
| 1267 | { |
| 1268 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_TRUE, 4, false); |
| 1269 | return format; |
| 1270 | } |
| 1271 | case VERTEX_FORMAT_SSHORT1: |
| 1272 | { |
| 1273 | static const VertexFormat format(GL_SHORT, GL_FALSE, 1, false); |
| 1274 | return format; |
| 1275 | } |
| 1276 | case VERTEX_FORMAT_SSHORT1_NORM: |
| 1277 | { |
| 1278 | static const VertexFormat format(GL_SHORT, GL_TRUE, 1, false); |
| 1279 | return format; |
| 1280 | } |
| 1281 | case VERTEX_FORMAT_SSHORT2: |
| 1282 | { |
| 1283 | static const VertexFormat format(GL_SHORT, GL_FALSE, 2, false); |
| 1284 | return format; |
| 1285 | } |
| 1286 | case VERTEX_FORMAT_SSHORT2_NORM: |
| 1287 | { |
| 1288 | static const VertexFormat format(GL_SHORT, GL_TRUE, 2, false); |
| 1289 | return format; |
| 1290 | } |
| 1291 | case VERTEX_FORMAT_SSHORT3: |
| 1292 | { |
| 1293 | static const VertexFormat format(GL_SHORT, GL_FALSE, 3, false); |
| 1294 | return format; |
| 1295 | } |
| 1296 | case VERTEX_FORMAT_SSHORT3_NORM: |
| 1297 | { |
| 1298 | static const VertexFormat format(GL_SHORT, GL_TRUE, 3, false); |
| 1299 | return format; |
| 1300 | } |
| 1301 | case VERTEX_FORMAT_SSHORT4: |
| 1302 | { |
| 1303 | static const VertexFormat format(GL_SHORT, GL_FALSE, 4, false); |
| 1304 | return format; |
| 1305 | } |
| 1306 | case VERTEX_FORMAT_SSHORT4_NORM: |
| 1307 | { |
| 1308 | static const VertexFormat format(GL_SHORT, GL_TRUE, 4, false); |
| 1309 | return format; |
| 1310 | } |
| 1311 | case VERTEX_FORMAT_USHORT1: |
| 1312 | { |
| 1313 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, false); |
| 1314 | return format; |
| 1315 | } |
| 1316 | case VERTEX_FORMAT_USHORT1_NORM: |
| 1317 | { |
| 1318 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 1, false); |
| 1319 | return format; |
| 1320 | } |
| 1321 | case VERTEX_FORMAT_USHORT2: |
| 1322 | { |
| 1323 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, false); |
| 1324 | return format; |
| 1325 | } |
| 1326 | case VERTEX_FORMAT_USHORT2_NORM: |
| 1327 | { |
| 1328 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 2, false); |
| 1329 | return format; |
| 1330 | } |
| 1331 | case VERTEX_FORMAT_USHORT3: |
| 1332 | { |
| 1333 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, false); |
| 1334 | return format; |
| 1335 | } |
| 1336 | case VERTEX_FORMAT_USHORT3_NORM: |
| 1337 | { |
| 1338 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 3, false); |
| 1339 | return format; |
| 1340 | } |
| 1341 | case VERTEX_FORMAT_USHORT4: |
| 1342 | { |
| 1343 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, false); |
| 1344 | return format; |
| 1345 | } |
| 1346 | case VERTEX_FORMAT_USHORT4_NORM: |
| 1347 | { |
| 1348 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_TRUE, 4, false); |
| 1349 | return format; |
| 1350 | } |
| 1351 | case VERTEX_FORMAT_SINT1: |
| 1352 | { |
| 1353 | static const VertexFormat format(GL_INT, GL_FALSE, 1, false); |
| 1354 | return format; |
| 1355 | } |
| 1356 | case VERTEX_FORMAT_SINT1_NORM: |
| 1357 | { |
| 1358 | static const VertexFormat format(GL_INT, GL_TRUE, 1, false); |
| 1359 | return format; |
| 1360 | } |
| 1361 | case VERTEX_FORMAT_SINT2: |
| 1362 | { |
| 1363 | static const VertexFormat format(GL_INT, GL_FALSE, 2, false); |
| 1364 | return format; |
| 1365 | } |
| 1366 | case VERTEX_FORMAT_SINT2_NORM: |
| 1367 | { |
| 1368 | static const VertexFormat format(GL_INT, GL_TRUE, 2, false); |
| 1369 | return format; |
| 1370 | } |
| 1371 | case VERTEX_FORMAT_SINT3: |
| 1372 | { |
| 1373 | static const VertexFormat format(GL_INT, GL_FALSE, 3, false); |
| 1374 | return format; |
| 1375 | } |
| 1376 | case VERTEX_FORMAT_SINT3_NORM: |
| 1377 | { |
| 1378 | static const VertexFormat format(GL_INT, GL_TRUE, 3, false); |
| 1379 | return format; |
| 1380 | } |
| 1381 | case VERTEX_FORMAT_SINT4: |
| 1382 | { |
| 1383 | static const VertexFormat format(GL_INT, GL_FALSE, 4, false); |
| 1384 | return format; |
| 1385 | } |
| 1386 | case VERTEX_FORMAT_SINT4_NORM: |
| 1387 | { |
| 1388 | static const VertexFormat format(GL_INT, GL_TRUE, 4, false); |
| 1389 | return format; |
| 1390 | } |
| 1391 | case VERTEX_FORMAT_UINT1: |
| 1392 | { |
| 1393 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, false); |
| 1394 | return format; |
| 1395 | } |
| 1396 | case VERTEX_FORMAT_UINT1_NORM: |
| 1397 | { |
| 1398 | static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 1, false); |
| 1399 | return format; |
| 1400 | } |
| 1401 | case VERTEX_FORMAT_UINT2: |
| 1402 | { |
| 1403 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, false); |
| 1404 | return format; |
| 1405 | } |
| 1406 | case VERTEX_FORMAT_UINT2_NORM: |
| 1407 | { |
| 1408 | static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 2, false); |
| 1409 | return format; |
| 1410 | } |
| 1411 | case VERTEX_FORMAT_UINT3: |
| 1412 | { |
| 1413 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, false); |
| 1414 | return format; |
| 1415 | } |
| 1416 | case VERTEX_FORMAT_UINT3_NORM: |
| 1417 | { |
| 1418 | static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 3, false); |
| 1419 | return format; |
| 1420 | } |
| 1421 | case VERTEX_FORMAT_UINT4: |
| 1422 | { |
| 1423 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, false); |
| 1424 | return format; |
| 1425 | } |
| 1426 | case VERTEX_FORMAT_UINT4_NORM: |
| 1427 | { |
| 1428 | static const VertexFormat format(GL_UNSIGNED_INT, GL_TRUE, 4, false); |
| 1429 | return format; |
| 1430 | } |
| 1431 | case VERTEX_FORMAT_SBYTE1_INT: |
| 1432 | { |
| 1433 | static const VertexFormat format(GL_BYTE, GL_FALSE, 1, true); |
| 1434 | return format; |
| 1435 | } |
| 1436 | case VERTEX_FORMAT_SBYTE2_INT: |
| 1437 | { |
| 1438 | static const VertexFormat format(GL_BYTE, GL_FALSE, 2, true); |
| 1439 | return format; |
| 1440 | } |
| 1441 | case VERTEX_FORMAT_SBYTE3_INT: |
| 1442 | { |
| 1443 | static const VertexFormat format(GL_BYTE, GL_FALSE, 3, true); |
| 1444 | return format; |
| 1445 | } |
| 1446 | case VERTEX_FORMAT_SBYTE4_INT: |
| 1447 | { |
| 1448 | static const VertexFormat format(GL_BYTE, GL_FALSE, 4, true); |
| 1449 | return format; |
| 1450 | } |
| 1451 | case VERTEX_FORMAT_UBYTE1_INT: |
| 1452 | { |
| 1453 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 1, true); |
| 1454 | return format; |
| 1455 | } |
| 1456 | case VERTEX_FORMAT_UBYTE2_INT: |
| 1457 | { |
| 1458 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 2, true); |
| 1459 | return format; |
| 1460 | } |
| 1461 | case VERTEX_FORMAT_UBYTE3_INT: |
| 1462 | { |
| 1463 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 3, true); |
| 1464 | return format; |
| 1465 | } |
| 1466 | case VERTEX_FORMAT_UBYTE4_INT: |
| 1467 | { |
| 1468 | static const VertexFormat format(GL_UNSIGNED_BYTE, GL_FALSE, 4, true); |
| 1469 | return format; |
| 1470 | } |
| 1471 | case VERTEX_FORMAT_SSHORT1_INT: |
| 1472 | { |
| 1473 | static const VertexFormat format(GL_SHORT, GL_FALSE, 1, true); |
| 1474 | return format; |
| 1475 | } |
| 1476 | case VERTEX_FORMAT_SSHORT2_INT: |
| 1477 | { |
| 1478 | static const VertexFormat format(GL_SHORT, GL_FALSE, 2, true); |
| 1479 | return format; |
| 1480 | } |
| 1481 | case VERTEX_FORMAT_SSHORT3_INT: |
| 1482 | { |
| 1483 | static const VertexFormat format(GL_SHORT, GL_FALSE, 3, true); |
| 1484 | return format; |
| 1485 | } |
| 1486 | case VERTEX_FORMAT_SSHORT4_INT: |
| 1487 | { |
| 1488 | static const VertexFormat format(GL_SHORT, GL_FALSE, 4, true); |
| 1489 | return format; |
| 1490 | } |
| 1491 | case VERTEX_FORMAT_USHORT1_INT: |
| 1492 | { |
| 1493 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 1, true); |
| 1494 | return format; |
| 1495 | } |
| 1496 | case VERTEX_FORMAT_USHORT2_INT: |
| 1497 | { |
| 1498 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 2, true); |
| 1499 | return format; |
| 1500 | } |
| 1501 | case VERTEX_FORMAT_USHORT3_INT: |
| 1502 | { |
| 1503 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 3, true); |
| 1504 | return format; |
| 1505 | } |
| 1506 | case VERTEX_FORMAT_USHORT4_INT: |
| 1507 | { |
| 1508 | static const VertexFormat format(GL_UNSIGNED_SHORT, GL_FALSE, 4, true); |
| 1509 | return format; |
| 1510 | } |
| 1511 | case VERTEX_FORMAT_SINT1_INT: |
| 1512 | { |
| 1513 | static const VertexFormat format(GL_INT, GL_FALSE, 1, true); |
| 1514 | return format; |
| 1515 | } |
| 1516 | case VERTEX_FORMAT_SINT2_INT: |
| 1517 | { |
| 1518 | static const VertexFormat format(GL_INT, GL_FALSE, 2, true); |
| 1519 | return format; |
| 1520 | } |
| 1521 | case VERTEX_FORMAT_SINT3_INT: |
| 1522 | { |
| 1523 | static const VertexFormat format(GL_INT, GL_FALSE, 3, true); |
| 1524 | return format; |
| 1525 | } |
| 1526 | case VERTEX_FORMAT_SINT4_INT: |
| 1527 | { |
| 1528 | static const VertexFormat format(GL_INT, GL_FALSE, 4, true); |
| 1529 | return format; |
| 1530 | } |
| 1531 | case VERTEX_FORMAT_UINT1_INT: |
| 1532 | { |
| 1533 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 1, true); |
| 1534 | return format; |
| 1535 | } |
| 1536 | case VERTEX_FORMAT_UINT2_INT: |
| 1537 | { |
| 1538 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 2, true); |
| 1539 | return format; |
| 1540 | } |
| 1541 | case VERTEX_FORMAT_UINT3_INT: |
| 1542 | { |
| 1543 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 3, true); |
| 1544 | return format; |
| 1545 | } |
| 1546 | case VERTEX_FORMAT_UINT4_INT: |
| 1547 | { |
| 1548 | static const VertexFormat format(GL_UNSIGNED_INT, GL_FALSE, 4, true); |
| 1549 | return format; |
| 1550 | } |
| 1551 | case VERTEX_FORMAT_FIXED1: |
| 1552 | { |
| 1553 | static const VertexFormat format(GL_FIXED, GL_FALSE, 1, false); |
| 1554 | return format; |
| 1555 | } |
| 1556 | case VERTEX_FORMAT_FIXED2: |
| 1557 | { |
| 1558 | static const VertexFormat format(GL_FIXED, GL_FALSE, 2, false); |
| 1559 | return format; |
| 1560 | } |
| 1561 | case VERTEX_FORMAT_FIXED3: |
| 1562 | { |
| 1563 | static const VertexFormat format(GL_FIXED, GL_FALSE, 3, false); |
| 1564 | return format; |
| 1565 | } |
| 1566 | case VERTEX_FORMAT_FIXED4: |
| 1567 | { |
| 1568 | static const VertexFormat format(GL_FIXED, GL_FALSE, 4, false); |
| 1569 | return format; |
| 1570 | } |
| 1571 | case VERTEX_FORMAT_HALF1: |
| 1572 | { |
| 1573 | static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 1, false); |
| 1574 | return format; |
| 1575 | } |
| 1576 | case VERTEX_FORMAT_HALF2: |
| 1577 | { |
| 1578 | static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 2, false); |
| 1579 | return format; |
| 1580 | } |
| 1581 | case VERTEX_FORMAT_HALF3: |
| 1582 | { |
| 1583 | static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 3, false); |
| 1584 | return format; |
| 1585 | } |
| 1586 | case VERTEX_FORMAT_HALF4: |
| 1587 | { |
| 1588 | static const VertexFormat format(GL_HALF_FLOAT, GL_FALSE, 4, false); |
| 1589 | return format; |
| 1590 | } |
| 1591 | case VERTEX_FORMAT_FLOAT1: |
| 1592 | { |
| 1593 | static const VertexFormat format(GL_FLOAT, GL_FALSE, 1, false); |
| 1594 | return format; |
| 1595 | } |
| 1596 | case VERTEX_FORMAT_FLOAT2: |
| 1597 | { |
| 1598 | static const VertexFormat format(GL_FLOAT, GL_FALSE, 2, false); |
| 1599 | return format; |
| 1600 | } |
| 1601 | case VERTEX_FORMAT_FLOAT3: |
| 1602 | { |
| 1603 | static const VertexFormat format(GL_FLOAT, GL_FALSE, 3, false); |
| 1604 | return format; |
| 1605 | } |
| 1606 | case VERTEX_FORMAT_FLOAT4: |
| 1607 | { |
| 1608 | static const VertexFormat format(GL_FLOAT, GL_FALSE, 4, false); |
| 1609 | return format; |
| 1610 | } |
| 1611 | case VERTEX_FORMAT_SINT210: |
| 1612 | { |
| 1613 | static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, false); |
| 1614 | return format; |
| 1615 | } |
| 1616 | case VERTEX_FORMAT_UINT210: |
| 1617 | { |
| 1618 | static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, false); |
| 1619 | return format; |
| 1620 | } |
| 1621 | case VERTEX_FORMAT_SINT210_NORM: |
| 1622 | { |
| 1623 | static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_TRUE, 4, false); |
| 1624 | return format; |
| 1625 | } |
| 1626 | case VERTEX_FORMAT_UINT210_NORM: |
| 1627 | { |
| 1628 | static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_TRUE, 4, false); |
| 1629 | return format; |
| 1630 | } |
| 1631 | case VERTEX_FORMAT_SINT210_INT: |
| 1632 | { |
| 1633 | static const VertexFormat format(GL_INT_2_10_10_10_REV, GL_FALSE, 4, true); |
| 1634 | return format; |
| 1635 | } |
| 1636 | case VERTEX_FORMAT_UINT210_INT: |
| 1637 | { |
| 1638 | static const VertexFormat format(GL_UNSIGNED_INT_2_10_10_10_REV, GL_FALSE, 4, true); |
| 1639 | return format; |
| 1640 | } |
| 1641 | default: |
| 1642 | { |
| 1643 | static const VertexFormat format(GL_NONE, GL_FALSE, 0, false); |
| 1644 | return format; |
| 1645 | } |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | VertexFormat::VertexFormat(GLenum typeIn, GLboolean normalizedIn, GLuint componentsIn, bool pureIntegerIn) |
| 1650 | : type(typeIn), |
| 1651 | normalized(normalizedIn), |
| 1652 | components(componentsIn), |
| 1653 | pureInteger(pureIntegerIn) |
| 1654 | { |
| 1655 | // float -> !normalized |
| 1656 | ASSERT(!(type == GL_FLOAT || type == GL_HALF_FLOAT || type == GL_FIXED) || normalized == GL_FALSE); |
| 1657 | } |
| 1658 | |
shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame] | 1659 | } |