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