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