shannonwoods@chromium.org | b8490f3 | 2013-05-30 00:08:00 +0000 | [diff] [blame^] | 1 | #include "precompiled.h" |
| 2 | // |
| 3 | // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
| 4 | // Use of this source code is governed by a BSD-style license that can be |
| 5 | // found in the LICENSE file. |
| 6 | // |
| 7 | |
| 8 | // formatutils.cpp: Queries for GL image formats. |
| 9 | |
| 10 | #include "libGLESv2/formatutils.h" |
| 11 | #include "libGLESv2/Context.h" |
| 12 | #include "libGLESv2/mathutil.h" |
| 13 | #include "libGLESv2/renderer/Renderer.h" |
| 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; |
| 23 | typedef std::pair<FormatTypePair, GLint> FormatPair; |
| 24 | typedef std::map<FormatTypePair, GLint> FormatMap; |
| 25 | |
| 26 | // A helper function to insert data into the D3D11LoadFunctionMap with fewer characters. |
| 27 | static inline void insertFormatMapping(FormatMap *map, GLenum format, GLenum type, GLint internalFormat) |
| 28 | { |
| 29 | map->insert(FormatPair(FormatTypePair(format, type), internalFormat)); |
| 30 | } |
| 31 | |
| 32 | FormatMap buildES2FormatMap() |
| 33 | { |
| 34 | FormatMap map; |
| 35 | |
| 36 | // | Format | Type | Internal format | |
| 37 | insertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT ); |
| 38 | insertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT ); |
| 39 | insertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT_OES, GL_ALPHA16F_EXT ); |
| 40 | |
| 41 | insertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT ); |
| 42 | insertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT ); |
| 43 | insertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT_OES, GL_LUMINANCE16F_EXT ); |
| 44 | |
| 45 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT ); |
| 46 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT ); |
| 47 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, GL_LUMINANCE_ALPHA16F_EXT ); |
| 48 | |
| 49 | insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8_OES ); |
| 50 | insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565 ); |
| 51 | insertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F_EXT ); |
| 52 | insertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT_OES, GL_RGB16F_EXT ); |
| 53 | |
| 54 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8_OES ); |
| 55 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4 ); |
| 56 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1 ); |
| 57 | insertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F_EXT ); |
| 58 | insertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT_OES, GL_RGBA16F_EXT ); |
| 59 | |
| 60 | insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_BYTE, GL_BGRA8_EXT ); |
| 61 | insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, GL_BGRA4_ANGLEX ); |
| 62 | insertFormatMapping(&map, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, GL_BGR5_A1_ANGLEX ); |
| 63 | |
| 64 | insertFormatMapping(&map, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGB_S3TC_DXT1_EXT ); |
| 65 | insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT ); |
| 66 | insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE); |
| 67 | insertFormatMapping(&map, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE); |
| 68 | |
| 69 | insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16 ); |
| 70 | insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT32_OES ); |
| 71 | |
| 72 | insertFormatMapping(&map, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, GL_DEPTH24_STENCIL8_OES ); |
| 73 | |
| 74 | return map; |
| 75 | } |
| 76 | |
| 77 | static const FormatMap &getES2FormatMap() |
| 78 | { |
| 79 | static const FormatMap es2FormatMap = buildES2FormatMap(); |
| 80 | return es2FormatMap; |
| 81 | } |
| 82 | |
| 83 | FormatMap buildES3FormatMap() |
| 84 | { |
| 85 | FormatMap map; |
| 86 | |
| 87 | // | Format | Type | Internal format | |
| 88 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_BYTE, GL_RGBA8 ); |
| 89 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, GL_RGBA4 ); |
| 90 | insertFormatMapping(&map, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, GL_RGB5_A1 ); |
| 91 | insertFormatMapping(&map, GL_RGBA, GL_FLOAT, GL_RGBA32F ); |
| 92 | insertFormatMapping(&map, GL_RGBA, GL_HALF_FLOAT, GL_RGBA16F ); |
| 93 | |
| 94 | insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_BYTE, GL_RGB8 ); |
| 95 | insertFormatMapping(&map, GL_RGB, GL_UNSIGNED_SHORT_5_6_5, GL_RGB565 ); |
| 96 | insertFormatMapping(&map, GL_RGB, GL_FLOAT, GL_RGB32F ); |
| 97 | insertFormatMapping(&map, GL_RGB, GL_HALF_FLOAT, GL_RGB16F ); |
| 98 | |
| 99 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, GL_LUMINANCE8_ALPHA8_EXT ); |
| 100 | insertFormatMapping(&map, GL_LUMINANCE, GL_UNSIGNED_BYTE, GL_LUMINANCE8_EXT ); |
| 101 | insertFormatMapping(&map, GL_ALPHA, GL_UNSIGNED_BYTE, GL_ALPHA8_EXT ); |
| 102 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_FLOAT, GL_LUMINANCE_ALPHA32F_EXT); |
| 103 | insertFormatMapping(&map, GL_LUMINANCE, GL_FLOAT, GL_LUMINANCE32F_EXT ); |
| 104 | insertFormatMapping(&map, GL_ALPHA, GL_FLOAT, GL_ALPHA32F_EXT ); |
| 105 | insertFormatMapping(&map, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, GL_LUMINANCE_ALPHA16F_EXT); |
| 106 | insertFormatMapping(&map, GL_LUMINANCE, GL_HALF_FLOAT, GL_LUMINANCE16F_EXT ); |
| 107 | insertFormatMapping(&map, GL_ALPHA, GL_HALF_FLOAT, GL_ALPHA16F_EXT ); |
| 108 | |
| 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 ); |
| 112 | |
| 113 | insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, GL_DEPTH_COMPONENT16 ); |
| 114 | insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, GL_DEPTH_COMPONENT24 ); |
| 115 | insertFormatMapping(&map, GL_DEPTH_COMPONENT, GL_FLOAT, GL_DEPTH_COMPONENT32F ); |
| 116 | |
| 117 | insertFormatMapping(&map, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, GL_DEPTH24_STENCIL8 ); |
| 118 | insertFormatMapping(&map, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, GL_DEPTH32F_STENCIL8 ); |
| 119 | |
| 120 | return map; |
| 121 | } |
| 122 | |
| 123 | struct FormatInfo |
| 124 | { |
| 125 | GLint mInternalformat; |
| 126 | GLenum mFormat; |
| 127 | GLenum mType; |
| 128 | |
| 129 | FormatInfo(GLint internalformat, GLenum format, GLenum type) |
| 130 | : mInternalformat(internalformat), mFormat(format), mType(type) { } |
| 131 | |
| 132 | bool operator<(const FormatInfo& other) const |
| 133 | { |
| 134 | return memcmp(this, &other, sizeof(FormatInfo)) < 0; |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | // ES3 has a specific set of permutations of internal formats, formats and types which are acceptable. |
| 139 | typedef std::set<FormatInfo> ES3FormatSet; |
| 140 | |
| 141 | ES3FormatSet buildES3FormatSet() |
| 142 | { |
| 143 | ES3FormatSet set; |
| 144 | |
| 145 | // Format combinations from ES 3.0.1 spec, table 3.2 |
| 146 | |
| 147 | // | Internal format | Format | Type | |
| 148 | // | | | | |
| 149 | set.insert(FormatInfo(GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 150 | set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 151 | set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 152 | set.insert(FormatInfo(GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 153 | set.insert(FormatInfo(GL_RGBA8_SNORM, GL_RGBA, GL_BYTE )); |
| 154 | set.insert(FormatInfo(GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 )); |
| 155 | set.insert(FormatInfo(GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV )); |
| 156 | set.insert(FormatInfo(GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV )); |
| 157 | set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT )); |
| 158 | set.insert(FormatInfo(GL_RGBA32F, GL_RGBA, GL_FLOAT )); |
| 159 | set.insert(FormatInfo(GL_RGBA16F, GL_RGBA, GL_FLOAT )); |
| 160 | set.insert(FormatInfo(GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE )); |
| 161 | set.insert(FormatInfo(GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE )); |
| 162 | set.insert(FormatInfo(GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT )); |
| 163 | set.insert(FormatInfo(GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT )); |
| 164 | set.insert(FormatInfo(GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT )); |
| 165 | set.insert(FormatInfo(GL_RGBA32I, GL_RGBA_INTEGER, GL_INT )); |
| 166 | set.insert(FormatInfo(GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV )); |
| 167 | set.insert(FormatInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE )); |
| 168 | set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE )); |
| 169 | set.insert(FormatInfo(GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE )); |
| 170 | set.insert(FormatInfo(GL_RGB8_SNORM, GL_RGB, GL_BYTE )); |
| 171 | set.insert(FormatInfo(GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 )); |
| 172 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV )); |
| 173 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV )); |
| 174 | set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_HALF_FLOAT )); |
| 175 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT )); |
| 176 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT )); |
| 177 | set.insert(FormatInfo(GL_RGB32F, GL_RGB, GL_FLOAT )); |
| 178 | set.insert(FormatInfo(GL_RGB16F, GL_RGB, GL_FLOAT )); |
| 179 | set.insert(FormatInfo(GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT )); |
| 180 | set.insert(FormatInfo(GL_RGB9_E5, GL_RGB, GL_FLOAT )); |
| 181 | set.insert(FormatInfo(GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE )); |
| 182 | set.insert(FormatInfo(GL_RGB8I, GL_RGB_INTEGER, GL_BYTE )); |
| 183 | set.insert(FormatInfo(GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT )); |
| 184 | set.insert(FormatInfo(GL_RGB16I, GL_RGB_INTEGER, GL_SHORT )); |
| 185 | set.insert(FormatInfo(GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT )); |
| 186 | set.insert(FormatInfo(GL_RGB32I, GL_RGB_INTEGER, GL_INT )); |
| 187 | set.insert(FormatInfo(GL_RG8, GL_RG, GL_UNSIGNED_BYTE )); |
| 188 | set.insert(FormatInfo(GL_RG8_SNORM, GL_RG, GL_BYTE )); |
| 189 | set.insert(FormatInfo(GL_RG16F, GL_RG, GL_HALF_FLOAT )); |
| 190 | set.insert(FormatInfo(GL_RG32F, GL_RG, GL_FLOAT )); |
| 191 | set.insert(FormatInfo(GL_RG16F, GL_RG, GL_FLOAT )); |
| 192 | set.insert(FormatInfo(GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE )); |
| 193 | set.insert(FormatInfo(GL_RG8I, GL_RG_INTEGER, GL_BYTE )); |
| 194 | set.insert(FormatInfo(GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT )); |
| 195 | set.insert(FormatInfo(GL_RG16I, GL_RG_INTEGER, GL_SHORT )); |
| 196 | set.insert(FormatInfo(GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT )); |
| 197 | set.insert(FormatInfo(GL_RG32I, GL_RG_INTEGER, GL_INT )); |
| 198 | set.insert(FormatInfo(GL_R8, GL_RED, GL_UNSIGNED_BYTE )); |
| 199 | set.insert(FormatInfo(GL_R8_SNORM, GL_RED, GL_BYTE )); |
| 200 | set.insert(FormatInfo(GL_R16F, GL_RED, GL_HALF_FLOAT )); |
| 201 | set.insert(FormatInfo(GL_R32F, GL_RED, GL_FLOAT )); |
| 202 | set.insert(FormatInfo(GL_R16F, GL_RED, GL_FLOAT )); |
| 203 | set.insert(FormatInfo(GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE )); |
| 204 | set.insert(FormatInfo(GL_R8I, GL_RED_INTEGER, GL_BYTE )); |
| 205 | set.insert(FormatInfo(GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT )); |
| 206 | set.insert(FormatInfo(GL_R16I, GL_RED_INTEGER, GL_SHORT )); |
| 207 | set.insert(FormatInfo(GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT )); |
| 208 | set.insert(FormatInfo(GL_R32I, GL_RED_INTEGER, GL_INT )); |
| 209 | |
| 210 | // Unsized formats |
| 211 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE )); |
| 212 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 )); |
| 213 | set.insert(FormatInfo(GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 )); |
| 214 | set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_BYTE )); |
| 215 | set.insert(FormatInfo(GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 )); |
| 216 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE )); |
| 217 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE )); |
| 218 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE )); |
| 219 | |
| 220 | // Depth stencil formats |
| 221 | set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT )); |
| 222 | set.insert(FormatInfo(GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT )); |
| 223 | set.insert(FormatInfo(GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT )); |
| 224 | set.insert(FormatInfo(GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT )); |
| 225 | set.insert(FormatInfo(GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 )); |
| 226 | set.insert(FormatInfo(GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV)); |
| 227 | |
| 228 | // From GL_OES_texture_float |
| 229 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT )); |
| 230 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT )); |
| 231 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_FLOAT )); |
| 232 | |
| 233 | // From GL_OES_texture_half_float |
| 234 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT )); |
| 235 | set.insert(FormatInfo(GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT )); |
| 236 | set.insert(FormatInfo(GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT )); |
| 237 | |
| 238 | // From GL_EXT_texture_storage |
| 239 | // | Internal format | Format | Type | |
| 240 | // | | | | |
| 241 | set.insert(FormatInfo(GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE )); |
| 242 | set.insert(FormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE )); |
| 243 | set.insert(FormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE )); |
| 244 | set.insert(FormatInfo(GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT )); |
| 245 | set.insert(FormatInfo(GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT )); |
| 246 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT )); |
| 247 | set.insert(FormatInfo(GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT )); |
| 248 | set.insert(FormatInfo(GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT )); |
| 249 | set.insert(FormatInfo(GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT )); |
| 250 | |
| 251 | set.insert(FormatInfo(GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 252 | set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT)); |
| 253 | set.insert(FormatInfo(GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 254 | set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT)); |
| 255 | set.insert(FormatInfo(GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE )); |
| 256 | |
| 257 | // From GL_ANGLE_depth_texture |
| 258 | set.insert(FormatInfo(GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES )); |
| 259 | |
| 260 | // Compressed formats |
| 261 | // From ES 3.0.1 spec, table 3.16 |
| 262 | // | Internal format | Format | Type | |
| 263 | // | | | | |
| 264 | set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 265 | set.insert(FormatInfo(GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 266 | set.insert(FormatInfo(GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE)); |
| 267 | set.insert(FormatInfo(GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE)); |
| 268 | set.insert(FormatInfo(GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE)); |
| 269 | set.insert(FormatInfo(GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE)); |
| 270 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE)); |
| 271 | set.insert(FormatInfo(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE)); |
| 272 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE)); |
| 273 | set.insert(FormatInfo(GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE)); |
| 274 | set.insert(FormatInfo(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE)); |
| 275 | |
| 276 | |
| 277 | // From GL_EXT_texture_compression_dxt1 |
| 278 | set.insert(FormatInfo(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE)); |
| 279 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE)); |
| 280 | |
| 281 | // From GL_ANGLE_texture_compression_dxt3 |
| 282 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE)); |
| 283 | |
| 284 | // From GL_ANGLE_texture_compression_dxt5 |
| 285 | set.insert(FormatInfo(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE)); |
| 286 | |
| 287 | return set; |
| 288 | } |
| 289 | |
| 290 | static const ES3FormatSet &getES3FormatSet() |
| 291 | { |
| 292 | static const ES3FormatSet es3FormatSet = buildES3FormatSet(); |
| 293 | return es3FormatSet; |
| 294 | } |
| 295 | |
| 296 | // Map of sizes of input types |
| 297 | struct TypeInfo |
| 298 | { |
| 299 | GLuint mTypeBytes; |
| 300 | bool mSpecialInterpretation; |
| 301 | |
| 302 | TypeInfo() |
| 303 | : mTypeBytes(0), mSpecialInterpretation(false) { } |
| 304 | |
| 305 | TypeInfo(GLuint typeBytes, bool specialInterpretation) |
| 306 | : mTypeBytes(typeBytes), mSpecialInterpretation(specialInterpretation) { } |
| 307 | |
| 308 | bool operator<(const TypeInfo& other) const |
| 309 | { |
| 310 | return memcmp(this, &other, sizeof(TypeInfo)) < 0; |
| 311 | } |
| 312 | }; |
| 313 | |
| 314 | typedef std::pair<GLenum, TypeInfo> TypeInfoPair; |
| 315 | typedef std::map<GLenum, TypeInfo> TypeInfoMap; |
| 316 | |
| 317 | static TypeInfoMap buildTypeInfoMap() |
| 318 | { |
| 319 | TypeInfoMap map; |
| 320 | |
| 321 | map.insert(TypeInfoPair(GL_UNSIGNED_BYTE, TypeInfo( 1, false))); |
| 322 | map.insert(TypeInfoPair(GL_BYTE, TypeInfo( 1, false))); |
| 323 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT, TypeInfo( 2, false))); |
| 324 | map.insert(TypeInfoPair(GL_SHORT, TypeInfo( 2, false))); |
| 325 | map.insert(TypeInfoPair(GL_UNSIGNED_INT, TypeInfo( 4, false))); |
| 326 | map.insert(TypeInfoPair(GL_INT, TypeInfo( 4, false))); |
| 327 | map.insert(TypeInfoPair(GL_HALF_FLOAT, TypeInfo( 2, false))); |
| 328 | map.insert(TypeInfoPair(GL_FLOAT, TypeInfo( 4, false))); |
| 329 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_6_5, TypeInfo( 2, true ))); |
| 330 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4, TypeInfo( 2, true ))); |
| 331 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_5_5_5_1, TypeInfo( 2, true ))); |
| 332 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, TypeInfo( 2, true ))); |
| 333 | map.insert(TypeInfoPair(GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, TypeInfo( 2, true ))); |
| 334 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_2_10_10_10_REV, TypeInfo( 4, true ))); |
| 335 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8, TypeInfo( 4, true ))); |
| 336 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_10F_11F_11F_REV, TypeInfo( 4, true ))); |
| 337 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_5_9_9_9_REV, TypeInfo( 4, true ))); |
| 338 | map.insert(TypeInfoPair(GL_FLOAT_32_UNSIGNED_INT_24_8_REV, TypeInfo( 4, true ))); |
| 339 | map.insert(TypeInfoPair(GL_UNSIGNED_INT_24_8_OES, TypeInfo( 4, true ))); |
| 340 | |
| 341 | return map; |
| 342 | } |
| 343 | |
| 344 | static bool getTypeInfo(GLenum type, TypeInfo *outTypeInfo) |
| 345 | { |
| 346 | static const TypeInfoMap infoMap = buildTypeInfoMap(); |
| 347 | TypeInfoMap::const_iterator iter = infoMap.find(type); |
| 348 | if (iter != infoMap.end()) |
| 349 | { |
| 350 | if (outTypeInfo) |
| 351 | { |
| 352 | *outTypeInfo = iter->second; |
| 353 | } |
| 354 | return true; |
| 355 | } |
| 356 | else |
| 357 | { |
| 358 | return false; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | // Information about internal formats |
| 363 | typedef bool ((Context::*ContextSupportCheckMemberFunction)(void) const); |
| 364 | typedef bool (*ContextSupportCheckFunction)(const Context *context); |
| 365 | |
| 366 | typedef bool ((rx::Renderer::*RendererSupportCheckMemberFunction)(void) const); |
| 367 | typedef bool (*ContextRendererSupportCheckFunction)(const Context *context, const rx::Renderer *renderer); |
| 368 | |
| 369 | template <ContextSupportCheckMemberFunction func> |
| 370 | bool CheckSupport(const Context *context) |
| 371 | { |
| 372 | return (context->*func)(); |
| 373 | } |
| 374 | |
| 375 | template <ContextSupportCheckMemberFunction contextFunc, RendererSupportCheckMemberFunction rendererFunc> |
| 376 | bool CheckSupport(const Context *context, const rx::Renderer *renderer) |
| 377 | { |
| 378 | if (context) |
| 379 | { |
| 380 | return (context->*contextFunc)(); |
| 381 | } |
| 382 | else if (renderer) |
| 383 | { |
| 384 | return (renderer->*rendererFunc)(); |
| 385 | } |
| 386 | else |
| 387 | { |
| 388 | UNREACHABLE(); |
| 389 | return false; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | template <typename objectType> |
| 394 | bool AlwaysSupported(const objectType*) |
| 395 | { |
| 396 | return true; |
| 397 | } |
| 398 | |
| 399 | template <typename objectTypeA, typename objectTypeB> |
| 400 | bool AlwaysSupported(const objectTypeA*, const objectTypeB*) |
| 401 | { |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | template <typename objectType> |
| 406 | bool NeverSupported(const objectType*) |
| 407 | { |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | template <typename objectTypeA, typename objectTypeB> |
| 412 | bool NeverSupported(const objectTypeA *, const objectTypeB *) |
| 413 | { |
| 414 | return false; |
| 415 | } |
| 416 | |
| 417 | template <typename objectType> |
| 418 | bool UnimplementedSupport(const objectType*) |
| 419 | { |
| 420 | UNIMPLEMENTED(); |
| 421 | return false; |
| 422 | } |
| 423 | |
| 424 | template <typename objectTypeA, typename objectTypeB> |
| 425 | bool UnimplementedSupport(const objectTypeA*, const objectTypeB*) |
| 426 | { |
| 427 | UNIMPLEMENTED(); |
| 428 | return false; |
| 429 | } |
| 430 | |
| 431 | |
| 432 | struct InternalFormatInfo |
| 433 | { |
| 434 | GLuint mRedBits; |
| 435 | GLuint mGreenBits; |
| 436 | GLuint mBlueBits; |
| 437 | |
| 438 | GLuint mLuminanceBits; |
| 439 | |
| 440 | GLuint mAlphaBits; |
| 441 | GLuint mSharedBits; |
| 442 | |
| 443 | GLuint mDepthBits; |
| 444 | GLuint mStencilBits; |
| 445 | |
| 446 | GLuint mPixelBits; |
| 447 | |
| 448 | GLuint mComponentCount; |
| 449 | |
| 450 | bool mIsCompressed; |
| 451 | GLuint mCompressedBlockWidth; |
| 452 | GLuint mCompressedBlockHeight; |
| 453 | |
| 454 | GLenum mFormat; |
| 455 | GLenum mType; |
| 456 | |
| 457 | ContextRendererSupportCheckFunction mIsColorRenderable; |
| 458 | ContextRendererSupportCheckFunction mIsDepthRenderable; |
| 459 | ContextRendererSupportCheckFunction mIsStencilRenderable; |
| 460 | ContextRendererSupportCheckFunction mIsTextureFilterable; |
| 461 | |
| 462 | ContextSupportCheckFunction mSupportFunction; |
| 463 | |
| 464 | InternalFormatInfo() : mRedBits(0), mGreenBits(0), mBlueBits(0), mLuminanceBits(0), mAlphaBits(0), mSharedBits(0), mDepthBits(0), mStencilBits(0), |
| 465 | mPixelBits(0), mComponentCount(0), mIsCompressed(false), mCompressedBlockWidth(0), mCompressedBlockHeight(0), mFormat(GL_NONE), mType(GL_NONE), |
| 466 | mIsColorRenderable(NeverSupported), mIsDepthRenderable(NeverSupported), mIsStencilRenderable(NeverSupported), |
| 467 | mIsTextureFilterable(NeverSupported), mSupportFunction(NeverSupported) |
| 468 | { |
| 469 | } |
| 470 | |
| 471 | static InternalFormatInfo UnsizedFormat(GLenum format, ContextSupportCheckFunction supportFunction) |
| 472 | { |
| 473 | InternalFormatInfo formatInfo; |
| 474 | formatInfo.mFormat = format; |
| 475 | formatInfo.mSupportFunction = supportFunction; |
| 476 | return formatInfo; |
| 477 | } |
| 478 | |
| 479 | static InternalFormatInfo RGBAFormat(GLuint red, GLuint green, GLuint blue, GLuint alpha, GLuint shared, |
| 480 | GLenum format, GLenum type, ContextRendererSupportCheckFunction colorRenderable, |
| 481 | ContextRendererSupportCheckFunction textureFilterable, |
| 482 | ContextSupportCheckFunction supportFunction) |
| 483 | { |
| 484 | InternalFormatInfo formatInfo; |
| 485 | formatInfo.mRedBits = red; |
| 486 | formatInfo.mGreenBits = green; |
| 487 | formatInfo.mBlueBits = blue; |
| 488 | formatInfo.mAlphaBits = alpha; |
| 489 | formatInfo.mSharedBits = shared; |
| 490 | formatInfo.mPixelBits = red + green + blue + alpha + shared; |
| 491 | formatInfo.mComponentCount = ((red > 0) ? 1 : 0) + ((green > 0) ? 1 : 0) + ((blue > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 492 | formatInfo.mFormat = format; |
| 493 | formatInfo.mType = type; |
| 494 | formatInfo.mIsColorRenderable = colorRenderable; |
| 495 | formatInfo.mIsTextureFilterable = textureFilterable; |
| 496 | formatInfo.mSupportFunction = supportFunction; |
| 497 | return formatInfo; |
| 498 | } |
| 499 | |
| 500 | static InternalFormatInfo LUMAFormat(GLuint luminance, GLuint alpha, GLenum format, GLenum type, |
| 501 | ContextSupportCheckFunction supportFunction) |
| 502 | { |
| 503 | InternalFormatInfo formatInfo; |
| 504 | formatInfo.mLuminanceBits = luminance; |
| 505 | formatInfo.mAlphaBits = alpha; |
| 506 | formatInfo.mPixelBits = luminance + alpha; |
| 507 | formatInfo.mComponentCount = ((luminance > 0) ? 1 : 0) + ((alpha > 0) ? 1 : 0); |
| 508 | formatInfo.mFormat = format; |
| 509 | formatInfo.mType = type; |
| 510 | formatInfo.mIsTextureFilterable = AlwaysSupported; |
| 511 | formatInfo.mSupportFunction = supportFunction; |
| 512 | return formatInfo; |
| 513 | } |
| 514 | |
| 515 | static InternalFormatInfo DepthStencilFormat(GLuint depth, GLuint stencil, GLenum format, GLenum type, |
| 516 | ContextRendererSupportCheckFunction depthRenderable, |
| 517 | ContextRendererSupportCheckFunction stencilRenderable, |
| 518 | ContextSupportCheckFunction supportFunction) |
| 519 | { |
| 520 | InternalFormatInfo formatInfo; |
| 521 | formatInfo.mDepthBits = depth; |
| 522 | formatInfo.mStencilBits = stencil; |
| 523 | formatInfo.mPixelBits = depth + stencil; |
| 524 | formatInfo.mComponentCount = ((depth > 0) ? 1 : 0) + ((stencil > 0) ? 1 : 0); |
| 525 | formatInfo.mFormat = format; |
| 526 | formatInfo.mType = type; |
| 527 | formatInfo.mIsDepthRenderable = depthRenderable; |
| 528 | formatInfo.mIsStencilRenderable = stencilRenderable; |
| 529 | formatInfo.mSupportFunction = supportFunction; |
| 530 | return formatInfo; |
| 531 | } |
| 532 | |
| 533 | static InternalFormatInfo CompressedFormat(GLuint compressedBlockWidth, GLuint compressedBlockHeight, |
| 534 | GLuint compressedBlockSize, GLuint componentCount, GLenum format, GLenum type, |
| 535 | ContextSupportCheckFunction supportFunction) |
| 536 | { |
| 537 | InternalFormatInfo formatInfo; |
| 538 | formatInfo.mIsCompressed = true; |
| 539 | formatInfo.mCompressedBlockWidth = compressedBlockWidth; |
| 540 | formatInfo.mCompressedBlockHeight = compressedBlockHeight; |
| 541 | formatInfo.mPixelBits = compressedBlockSize; |
| 542 | formatInfo.mComponentCount = componentCount; |
| 543 | formatInfo.mFormat = format; |
| 544 | formatInfo.mType = type; |
| 545 | formatInfo.mIsTextureFilterable = AlwaysSupported; |
| 546 | formatInfo.mSupportFunction = supportFunction; |
| 547 | return formatInfo; |
| 548 | } |
| 549 | }; |
| 550 | |
| 551 | typedef std::pair<GLuint, InternalFormatInfo> InternalFormatInfoPair; |
| 552 | typedef std::map<GLuint, InternalFormatInfo> InternalFormatInfoMap; |
| 553 | |
| 554 | static InternalFormatInfoMap buildES3InternalFormatInfoMap() |
| 555 | { |
| 556 | InternalFormatInfoMap map; |
| 557 | |
| 558 | // From ES 3.0.1 spec, table 3.12 |
| 559 | map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo())); |
| 560 | |
| 561 | // | Internal format | | R | G | B | A |S | Format | Type | Color | Texture | Supported | |
| 562 | // | | | | | | | | | | renderable | filterable | | |
| 563 | map.insert(InternalFormatInfoPair(GL_R8, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, UnimplementedSupport))); |
| 564 | map.insert(InternalFormatInfoPair(GL_R8_SNORM, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED, GL_BYTE, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 565 | map.insert(InternalFormatInfoPair(GL_RG8, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, UnimplementedSupport))); |
| 566 | map.insert(InternalFormatInfoPair(GL_RG8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG, GL_BYTE, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 567 | map.insert(InternalFormatInfoPair(GL_RGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 568 | map.insert(InternalFormatInfoPair(GL_RGB8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_BYTE, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 569 | map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGB, GL_UNSIGNED_SHORT_5_5_5_1, NeverSupported, AlwaysSupported, AlwaysSupported ))); |
| 570 | map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, NeverSupported, AlwaysSupported, AlwaysSupported ))); |
| 571 | map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 572 | map.insert(InternalFormatInfoPair(GL_RGBA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 573 | map.insert(InternalFormatInfoPair(GL_RGBA8_SNORM, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_BYTE, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 574 | map.insert(InternalFormatInfoPair(GL_RGB10_A2, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, AlwaysSupported, AlwaysSupported, UnimplementedSupport))); |
| 575 | map.insert(InternalFormatInfoPair(GL_RGB10_A2UI, InternalFormatInfo::RGBAFormat(10, 10, 10, 2, 0, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 576 | map.insert(InternalFormatInfoPair(GL_SRGB8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, NeverSupported, AlwaysSupported, AlwaysSupported ))); |
| 577 | map.insert(InternalFormatInfoPair(GL_SRGB8_ALPHA8, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 578 | map.insert(InternalFormatInfoPair(GL_R11F_G11F_B10F, InternalFormatInfo::RGBAFormat(11, 11, 10, 0, 0, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 579 | map.insert(InternalFormatInfoPair(GL_RGB9_E5, InternalFormatInfo::RGBAFormat( 9, 9, 9, 0, 5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV, NeverSupported, AlwaysSupported, UnimplementedSupport))); |
| 580 | map.insert(InternalFormatInfoPair(GL_R8I, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 581 | map.insert(InternalFormatInfoPair(GL_R8UI, InternalFormatInfo::RGBAFormat( 8, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 582 | map.insert(InternalFormatInfoPair(GL_R16I, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 583 | map.insert(InternalFormatInfoPair(GL_R16UI, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 584 | map.insert(InternalFormatInfoPair(GL_R32I, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 585 | map.insert(InternalFormatInfoPair(GL_R32UI, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 586 | map.insert(InternalFormatInfoPair(GL_RG8I, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 587 | map.insert(InternalFormatInfoPair(GL_RG8UI, InternalFormatInfo::RGBAFormat( 8, 8, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 588 | map.insert(InternalFormatInfoPair(GL_RG16I, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 589 | map.insert(InternalFormatInfoPair(GL_RG16UI, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 590 | map.insert(InternalFormatInfoPair(GL_RG32I, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 591 | map.insert(InternalFormatInfoPair(GL_RG32UI, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG_INTEGER, GL_UNSIGNED_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 592 | map.insert(InternalFormatInfoPair(GL_RGB8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_BYTE, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 593 | map.insert(InternalFormatInfoPair(GL_RGB8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_BYTE, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 594 | map.insert(InternalFormatInfoPair(GL_RGB16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_SHORT, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 595 | map.insert(InternalFormatInfoPair(GL_RGB16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_SHORT, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 596 | map.insert(InternalFormatInfoPair(GL_RGB32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_INT, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 597 | map.insert(InternalFormatInfoPair(GL_RGB32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB_INTEGER, GL_UNSIGNED_INT, NeverSupported, NeverSupported, UnimplementedSupport))); |
| 598 | map.insert(InternalFormatInfoPair(GL_RGBA8I, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 599 | map.insert(InternalFormatInfoPair(GL_RGBA8UI, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 600 | map.insert(InternalFormatInfoPair(GL_RGBA16I, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 601 | map.insert(InternalFormatInfoPair(GL_RGBA16UI, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 602 | map.insert(InternalFormatInfoPair(GL_RGBA32I, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 603 | map.insert(InternalFormatInfoPair(GL_RGBA32UI, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA_INTEGER, GL_UNSIGNED_INT, AlwaysSupported, NeverSupported, UnimplementedSupport))); |
| 604 | |
| 605 | map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 606 | map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 607 | map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT, AlwaysSupported, AlwaysSupported, AlwaysSupported ))); |
| 608 | |
| 609 | // Floating point renderability and filtering is provided by OES_texture_float and OES_texture_half_float |
| 610 | // | Internal format | | D |S | Format | Type | Color | Texture | Supported | |
| 611 | // | | | | | | | renderable | filterable | | |
| 612 | map.insert(InternalFormatInfoPair(GL_R16F, InternalFormatInfo::RGBAFormat(16, 0, 0, 0, 0, GL_RED, GL_HALF_FLOAT, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, UnimplementedSupport))); |
| 613 | map.insert(InternalFormatInfoPair(GL_RG16F, InternalFormatInfo::RGBAFormat(16, 16, 0, 0, 0, GL_RG, GL_HALF_FLOAT, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, UnimplementedSupport))); |
| 614 | map.insert(InternalFormatInfoPair(GL_RGB16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported ))); |
| 615 | map.insert(InternalFormatInfoPair(GL_RGBA16F, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, AlwaysSupported ))); |
| 616 | map.insert(InternalFormatInfoPair(GL_R32F, InternalFormatInfo::RGBAFormat(32, 0, 0, 0, 0, GL_RED, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, UnimplementedSupport))); |
| 617 | map.insert(InternalFormatInfoPair(GL_RG32F, InternalFormatInfo::RGBAFormat(32, 32, 0, 0, 0, GL_RG, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, UnimplementedSupport))); |
| 618 | map.insert(InternalFormatInfoPair(GL_RGB32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported ))); |
| 619 | map.insert(InternalFormatInfoPair(GL_RGBA32F, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, AlwaysSupported ))); |
| 620 | |
| 621 | // Depth stencil formats |
| 622 | // | Internal format | | D |S | Format | Type | Color | Texture | Supported | |
| 623 | // | | | | | | | renderable | filterable | | |
| 624 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, AlwaysSupported, NeverSupported, AlwaysSupported))); |
| 625 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT24, InternalFormatInfo::DepthStencilFormat(24, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, AlwaysSupported, NeverSupported, AlwaysSupported))); |
| 626 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32F,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_FLOAT, AlwaysSupported, NeverSupported, AlwaysSupported))); |
| 627 | map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 628 | map.insert(InternalFormatInfoPair(GL_DEPTH32F_STENCIL8, InternalFormatInfo::DepthStencilFormat(32, 8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 629 | |
| 630 | // Luminance alpha formats |
| 631 | // | Internal format | | L | A | Format | Type | Supported | |
| 632 | // | | | | | | | | |
| 633 | map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 634 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 635 | map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, AlwaysSupported))); |
| 636 | map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, AlwaysSupported))); |
| 637 | map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT, AlwaysSupported))); |
| 638 | map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT, AlwaysSupported))); |
| 639 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 640 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, AlwaysSupported))); |
| 641 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT, AlwaysSupported))); |
| 642 | |
| 643 | // Unsized formats |
| 644 | // | Internal format | | Format | Supported | |
| 645 | // | | | | | |
| 646 | map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported))); |
| 647 | map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported))); |
| 648 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported))); |
| 649 | map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported))); |
| 650 | map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported))); |
| 651 | map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported))); |
| 652 | |
| 653 | // Compressed formats, From ES 3.0.1 spec, table 3.16 |
| 654 | // | Internal format | |W |H | B |C | Format | Type | Supported | |
| 655 | // | | | | | S |C | | | | |
| 656 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 657 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_R11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 64, 1, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 658 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 659 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SIGNED_RG11_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 2, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 660 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 661 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 662 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 663 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 664 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 665 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE, UnimplementedSupport))); |
| 666 | |
| 667 | // From GL_EXT_texture_compression_dxt1 |
| 668 | // | Internal format | |W |H | B |C | Format | Type | Supported | |
| 669 | // | | | | | S |C | | | | |
| 670 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 671 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 672 | |
| 673 | // From GL_ANGLE_texture_compression_dxt3 |
| 674 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 675 | |
| 676 | // From GL_ANGLE_texture_compression_dxt5 |
| 677 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 678 | |
| 679 | return map; |
| 680 | } |
| 681 | |
| 682 | static InternalFormatInfoMap buildES2InternalFormatInfoMap() |
| 683 | { |
| 684 | InternalFormatInfoMap map; |
| 685 | |
| 686 | // From ES 2.0.25 table 4.5 |
| 687 | map.insert(InternalFormatInfoPair(GL_NONE, InternalFormatInfo())); |
| 688 | |
| 689 | // | Internal format | | R | G | B | A |S | Format | Type | Color | Texture | Supported | |
| 690 | // | | | | | | | | | | renderable | filterable | | |
| 691 | map.insert(InternalFormatInfoPair(GL_RGBA4, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 692 | map.insert(InternalFormatInfoPair(GL_RGB5_A1, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 693 | map.insert(InternalFormatInfoPair(GL_RGB565, InternalFormatInfo::RGBAFormat( 5, 6, 5, 0, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_6_5, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 694 | |
| 695 | // Extension formats |
| 696 | map.insert(InternalFormatInfoPair(GL_RGB8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 0, 0, GL_RGB, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 697 | map.insert(InternalFormatInfoPair(GL_RGBA8_OES, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 698 | map.insert(InternalFormatInfoPair(GL_BGRA8_EXT, InternalFormatInfo::RGBAFormat( 8, 8, 8, 8, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, AlwaysSupported, AlwaysSupported, AlwaysSupported))); |
| 699 | map.insert(InternalFormatInfoPair(GL_BGRA4_ANGLEX, InternalFormatInfo::RGBAFormat( 4, 4, 4, 4, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4, NeverSupported, AlwaysSupported, AlwaysSupported))); |
| 700 | map.insert(InternalFormatInfoPair(GL_BGR5_A1_ANGLEX, InternalFormatInfo::RGBAFormat( 5, 5, 5, 1, 0, GL_BGRA_EXT, GL_UNSIGNED_SHORT_5_5_5_1, NeverSupported, AlwaysSupported, AlwaysSupported))); |
| 701 | |
| 702 | // Floating point formats have to query the renderer for support |
| 703 | // | Internal format | | R | G | B | A |S | Format | Type | Color | Texture | Supported | |
| 704 | // | | | | | | | | | | renderable | filterable | | |
| 705 | map.insert(InternalFormatInfoPair(GL_RGB16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 0, 0, GL_RGB, GL_HALF_FLOAT_OES, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>))); |
| 706 | map.insert(InternalFormatInfoPair(GL_RGB32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 0, 0, GL_RGB, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>))); |
| 707 | map.insert(InternalFormatInfoPair(GL_RGBA16F_EXT, InternalFormatInfo::RGBAFormat(16, 16, 16, 16, 0, GL_RGBA, GL_HALF_FLOAT_OES, CheckSupport<&Context::supportsFloat16RenderableTextures, &rx::Renderer::getFloat16TextureRenderingSupport>, CheckSupport<&Context::supportsFloat16LinearFilter, &rx::Renderer::getFloat16TextureFilteringSupport>, CheckSupport<&Context::supportsFloat16Textures>))); |
| 708 | map.insert(InternalFormatInfoPair(GL_RGBA32F_EXT, InternalFormatInfo::RGBAFormat(32, 32, 32, 32, 0, GL_RGBA, GL_FLOAT, CheckSupport<&Context::supportsFloat32RenderableTextures, &rx::Renderer::getFloat32TextureRenderingSupport>, CheckSupport<&Context::supportsFloat32LinearFilter, &rx::Renderer::getFloat32TextureFilteringSupport>, CheckSupport<&Context::supportsFloat32Textures>))); |
| 709 | |
| 710 | // Depth and stencil formats |
| 711 | // | Internal format | | D |S | Format | Type | Color | Texture | Supported | |
| 712 | // | | | | | | | renderable | filterable | | |
| 713 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT32_OES,InternalFormatInfo::DepthStencilFormat(32, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, AlwaysSupported, NeverSupported, CheckSupport<&Context::supportsDepthTextures>))); |
| 714 | map.insert(InternalFormatInfoPair(GL_DEPTH24_STENCIL8_OES, InternalFormatInfo::DepthStencilFormat(24, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_INT_24_8_OES, AlwaysSupported, AlwaysSupported, CheckSupport<&Context::supportsDepthTextures>))); |
| 715 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT16, InternalFormatInfo::DepthStencilFormat(16, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, AlwaysSupported, NeverSupported, AlwaysSupported))); |
| 716 | map.insert(InternalFormatInfoPair(GL_STENCIL_INDEX8, InternalFormatInfo::DepthStencilFormat( 0, 8, GL_DEPTH_STENCIL_OES, GL_UNSIGNED_BYTE, NeverSupported, AlwaysSupported, AlwaysSupported))); |
| 717 | |
| 718 | // Unsized formats |
| 719 | // | Internal format | | Format | Supported | |
| 720 | // | | | | | |
| 721 | map.insert(InternalFormatInfoPair(GL_ALPHA, InternalFormatInfo::UnsizedFormat(GL_ALPHA, AlwaysSupported))); |
| 722 | map.insert(InternalFormatInfoPair(GL_LUMINANCE, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE, AlwaysSupported))); |
| 723 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA, InternalFormatInfo::UnsizedFormat(GL_LUMINANCE_ALPHA, AlwaysSupported))); |
| 724 | map.insert(InternalFormatInfoPair(GL_RGB, InternalFormatInfo::UnsizedFormat(GL_RGB, AlwaysSupported))); |
| 725 | map.insert(InternalFormatInfoPair(GL_RGBA, InternalFormatInfo::UnsizedFormat(GL_RGBA, AlwaysSupported))); |
| 726 | map.insert(InternalFormatInfoPair(GL_BGRA_EXT, InternalFormatInfo::UnsizedFormat(GL_BGRA_EXT, AlwaysSupported))); |
| 727 | map.insert(InternalFormatInfoPair(GL_DEPTH_COMPONENT, InternalFormatInfo::UnsizedFormat(GL_DEPTH_COMPONENT, AlwaysSupported))); |
| 728 | map.insert(InternalFormatInfoPair(GL_DEPTH_STENCIL_OES, InternalFormatInfo::UnsizedFormat(GL_DEPTH_STENCIL_OES, AlwaysSupported))); |
| 729 | |
| 730 | // Luminance alpha formats from GL_EXT_texture_storage |
| 731 | // | Internal format | | L | A | Format | Type | Supported | |
| 732 | // | | | | | | | | |
| 733 | map.insert(InternalFormatInfoPair(GL_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 0, 8, GL_ALPHA, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 734 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_EXT, InternalFormatInfo::LUMAFormat( 8, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 735 | map.insert(InternalFormatInfoPair(GL_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat( 0, 32, GL_ALPHA, GL_FLOAT, AlwaysSupported))); |
| 736 | map.insert(InternalFormatInfoPair(GL_LUMINANCE32F_EXT, InternalFormatInfo::LUMAFormat(32, 0, GL_LUMINANCE, GL_FLOAT, AlwaysSupported))); |
| 737 | map.insert(InternalFormatInfoPair(GL_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat( 0, 16, GL_ALPHA, GL_HALF_FLOAT_OES, AlwaysSupported))); |
| 738 | map.insert(InternalFormatInfoPair(GL_LUMINANCE16F_EXT, InternalFormatInfo::LUMAFormat(16, 0, GL_LUMINANCE, GL_HALF_FLOAT_OES, AlwaysSupported))); |
| 739 | map.insert(InternalFormatInfoPair(GL_LUMINANCE8_ALPHA8_EXT, InternalFormatInfo::LUMAFormat( 8, 8, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, AlwaysSupported))); |
| 740 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA32F_EXT, InternalFormatInfo::LUMAFormat(32, 32, GL_LUMINANCE_ALPHA, GL_FLOAT, AlwaysSupported))); |
| 741 | map.insert(InternalFormatInfoPair(GL_LUMINANCE_ALPHA16F_EXT, InternalFormatInfo::LUMAFormat(16, 16, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES, AlwaysSupported))); |
| 742 | |
| 743 | // From GL_EXT_texture_compression_dxt1 |
| 744 | // | Internal format | |W |H | B |C |Format | Type | Supported | |
| 745 | // | | | | | S |C | | | | |
| 746 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGB_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 3, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>))); |
| 747 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, InternalFormatInfo::CompressedFormat(4, 4, 64, 4, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT1Textures>))); |
| 748 | |
| 749 | // From GL_ANGLE_texture_compression_dxt3 |
| 750 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT3Textures>))); |
| 751 | |
| 752 | // From GL_ANGLE_texture_compression_dxt5 |
| 753 | map.insert(InternalFormatInfoPair(GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, InternalFormatInfo::CompressedFormat(4, 4, 128, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE, CheckSupport<&Context::supportsDXT5Textures>))); |
| 754 | |
| 755 | return map; |
| 756 | } |
| 757 | |
| 758 | static bool getInternalFormatInfo(GLint internalFormat, GLuint clientVersion, InternalFormatInfo *outFormatInfo) |
| 759 | { |
| 760 | const InternalFormatInfoMap* map = NULL; |
| 761 | |
| 762 | if (clientVersion == 2) |
| 763 | { |
| 764 | static const InternalFormatInfoMap formatMap = buildES2InternalFormatInfoMap(); |
| 765 | map = &formatMap; |
| 766 | } |
| 767 | else if (clientVersion == 3) |
| 768 | { |
| 769 | static const InternalFormatInfoMap formatMap = buildES3InternalFormatInfoMap(); |
| 770 | map = &formatMap; |
| 771 | } |
| 772 | else |
| 773 | { |
| 774 | UNREACHABLE(); |
| 775 | } |
| 776 | |
| 777 | InternalFormatInfoMap::const_iterator iter = map->find(internalFormat); |
| 778 | if (iter != map->end()) |
| 779 | { |
| 780 | if (outFormatInfo) |
| 781 | { |
| 782 | *outFormatInfo = iter->second; |
| 783 | } |
| 784 | return true; |
| 785 | } |
| 786 | else |
| 787 | { |
| 788 | return false; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | typedef std::set<GLenum> FormatSet; |
| 793 | |
| 794 | static FormatSet buildES2ValidFormatSet() |
| 795 | { |
| 796 | static const FormatMap &formatMap = getES2FormatMap(); |
| 797 | |
| 798 | FormatSet set; |
| 799 | |
| 800 | for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++) |
| 801 | { |
| 802 | const FormatTypePair& formatPair = i->first; |
| 803 | set.insert(formatPair.first); |
| 804 | } |
| 805 | |
| 806 | return set; |
| 807 | } |
| 808 | |
| 809 | static FormatSet buildES3ValidFormatSet() |
| 810 | { |
| 811 | static const ES3FormatSet &formatSet = getES3FormatSet(); |
| 812 | |
| 813 | FormatSet set; |
| 814 | |
| 815 | for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++) |
| 816 | { |
| 817 | const FormatInfo& formatInfo = *i; |
| 818 | set.insert(formatInfo.mFormat); |
| 819 | } |
| 820 | |
| 821 | return set; |
| 822 | } |
| 823 | |
| 824 | typedef std::set<GLenum> TypeSet; |
| 825 | |
| 826 | static TypeSet buildES2ValidTypeSet() |
| 827 | { |
| 828 | static const FormatMap &formatMap = getES2FormatMap(); |
| 829 | |
| 830 | TypeSet set; |
| 831 | |
| 832 | for (FormatMap::const_iterator i = formatMap.begin(); i != formatMap.end(); i++) |
| 833 | { |
| 834 | const FormatTypePair& formatPair = i->first; |
| 835 | set.insert(formatPair.second); |
| 836 | } |
| 837 | |
| 838 | return set; |
| 839 | } |
| 840 | |
| 841 | static TypeSet buildES3ValidTypeSet() |
| 842 | { |
| 843 | static const ES3FormatSet &formatSet = getES3FormatSet(); |
| 844 | |
| 845 | TypeSet set; |
| 846 | |
| 847 | for (ES3FormatSet::const_iterator i = formatSet.begin(); i != formatSet.end(); i++) |
| 848 | { |
| 849 | const FormatInfo& formatInfo = *i; |
| 850 | set.insert(formatInfo.mType); |
| 851 | } |
| 852 | |
| 853 | return set; |
| 854 | } |
| 855 | |
| 856 | struct CopyConversion |
| 857 | { |
| 858 | GLenum mTextureFormat; |
| 859 | GLenum mFramebufferFormat; |
| 860 | |
| 861 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 862 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 863 | |
| 864 | bool operator<(const CopyConversion& other) const |
| 865 | { |
| 866 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 867 | } |
| 868 | }; |
| 869 | |
| 870 | typedef std::set<CopyConversion> CopyConversionSet; |
| 871 | |
| 872 | static CopyConversionSet buildValidES3CopyTexImageCombinations() |
| 873 | { |
| 874 | CopyConversionSet set; |
| 875 | |
| 876 | // From ES 3.0.1 spec, table 3.15 |
| 877 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 878 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 879 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 880 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 881 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 882 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 883 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 884 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 885 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 886 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 887 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 888 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 889 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 890 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 891 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 892 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 893 | |
| 894 | return set; |
| 895 | } |
| 896 | |
| 897 | bool IsValidInternalFormat(GLint internalFormat, const Context *context) |
| 898 | { |
| 899 | if (!context) |
| 900 | { |
| 901 | return false; |
| 902 | } |
| 903 | |
| 904 | InternalFormatInfo internalFormatInfo; |
| 905 | if (getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo)) |
| 906 | { |
| 907 | ASSERT(internalFormatInfo.mSupportFunction != NULL); |
| 908 | return internalFormatInfo.mSupportFunction(context); |
| 909 | } |
| 910 | else |
| 911 | { |
| 912 | return false; |
| 913 | } |
| 914 | } |
| 915 | |
| 916 | bool IsValidFormat(GLenum format, GLuint clientVersion) |
| 917 | { |
| 918 | if (clientVersion == 2) |
| 919 | { |
| 920 | static const FormatSet formatSet = buildES2ValidFormatSet(); |
| 921 | return formatSet.find(format) != formatSet.end(); |
| 922 | } |
| 923 | else if (clientVersion == 3) |
| 924 | { |
| 925 | static const FormatSet formatSet = buildES3ValidFormatSet(); |
| 926 | return formatSet.find(format) != formatSet.end(); |
| 927 | } |
| 928 | else |
| 929 | { |
| 930 | UNREACHABLE(); |
| 931 | return false; |
| 932 | } |
| 933 | } |
| 934 | |
| 935 | bool IsValidType(GLenum type, GLuint clientVersion) |
| 936 | { |
| 937 | if (clientVersion == 2) |
| 938 | { |
| 939 | static const TypeSet typeSet = buildES2ValidTypeSet(); |
| 940 | return typeSet.find(type) != typeSet.end(); |
| 941 | } |
| 942 | else if (clientVersion == 3) |
| 943 | { |
| 944 | static const TypeSet typeSet = buildES3ValidTypeSet(); |
| 945 | return typeSet.find(type) != typeSet.end(); |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | UNREACHABLE(); |
| 950 | return false; |
| 951 | } |
| 952 | } |
| 953 | |
| 954 | bool IsValidFormatCombination(GLint internalFormat, GLenum format, GLenum type, GLuint clientVersion) |
| 955 | { |
| 956 | if (clientVersion == 2) |
| 957 | { |
| 958 | static const FormatMap &formats = getES2FormatMap(); |
| 959 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 960 | |
| 961 | return (iter != formats.end()) && ((internalFormat == (GLint)type) || (internalFormat == iter->second)); |
| 962 | } |
| 963 | else if (clientVersion == 3) |
| 964 | { |
| 965 | static const ES3FormatSet &formats = getES3FormatSet(); |
| 966 | return formats.find(FormatInfo(internalFormat, format, type)) != formats.end(); |
| 967 | } |
| 968 | else |
| 969 | { |
| 970 | UNREACHABLE(); |
| 971 | return false; |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | bool IsValidCopyTexImageCombination(GLenum textureFormat, GLenum frameBufferFormat, GLuint clientVersion) |
| 976 | { |
| 977 | if (clientVersion == 2) |
| 978 | { |
| 979 | UNIMPLEMENTED(); |
| 980 | return false; |
| 981 | } |
| 982 | else if (clientVersion == 3) |
| 983 | { |
| 984 | static const CopyConversionSet conversionSet = buildValidES3CopyTexImageCombinations(); |
| 985 | return conversionSet.find(CopyConversion(textureFormat, frameBufferFormat)) != conversionSet.end(); |
| 986 | } |
| 987 | else |
| 988 | { |
| 989 | UNREACHABLE(); |
| 990 | return false; |
| 991 | } |
| 992 | } |
| 993 | |
| 994 | bool IsSizedInternalFormat(GLint internalFormat, GLuint clientVersion) |
| 995 | { |
| 996 | InternalFormatInfo internalFormatInfo; |
| 997 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 998 | { |
| 999 | return internalFormatInfo.mPixelBits > 0; |
| 1000 | } |
| 1001 | else |
| 1002 | { |
| 1003 | UNREACHABLE(); |
| 1004 | return false; |
| 1005 | } |
| 1006 | } |
| 1007 | |
| 1008 | GLint GetSizedInternalFormat(GLenum format, GLenum type, GLuint clientVersion) |
| 1009 | { |
| 1010 | if (clientVersion == 2) |
| 1011 | { |
| 1012 | static const FormatMap &formats = getES2FormatMap(); |
| 1013 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 1014 | return (iter != formats.end()) ? iter->second : GL_NONE; |
| 1015 | } |
| 1016 | else if (clientVersion == 3) |
| 1017 | { |
| 1018 | static const FormatMap formats = buildES3FormatMap(); |
| 1019 | FormatMap::const_iterator iter = formats.find(FormatTypePair(format, type)); |
| 1020 | return (iter != formats.end()) ? iter->second : GL_NONE; |
| 1021 | } |
| 1022 | else |
| 1023 | { |
| 1024 | UNREACHABLE(); |
| 1025 | return GL_NONE; |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | GLuint GetPixelBytes(GLint internalFormat, GLuint clientVersion) |
| 1030 | { |
| 1031 | InternalFormatInfo internalFormatInfo; |
| 1032 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1033 | { |
| 1034 | return internalFormatInfo.mPixelBits / 8; |
| 1035 | } |
| 1036 | else |
| 1037 | { |
| 1038 | UNREACHABLE(); |
| 1039 | return 0; |
| 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | GLuint GetAlphaBits(GLint internalFormat, GLuint clientVersion) |
| 1044 | { |
| 1045 | InternalFormatInfo internalFormatInfo; |
| 1046 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1047 | { |
| 1048 | return internalFormatInfo.mAlphaBits; |
| 1049 | } |
| 1050 | else |
| 1051 | { |
| 1052 | UNREACHABLE(); |
| 1053 | return 0; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | GLuint GetRedBits(GLint internalFormat, GLuint clientVersion) |
| 1058 | { |
| 1059 | InternalFormatInfo internalFormatInfo; |
| 1060 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1061 | { |
| 1062 | return internalFormatInfo.mRedBits; |
| 1063 | } |
| 1064 | else |
| 1065 | { |
| 1066 | UNREACHABLE(); |
| 1067 | return 0; |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | GLuint GetGreenBits(GLint internalFormat, GLuint clientVersion) |
| 1072 | { |
| 1073 | InternalFormatInfo internalFormatInfo; |
| 1074 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1075 | { |
| 1076 | return internalFormatInfo.mGreenBits; |
| 1077 | } |
| 1078 | else |
| 1079 | { |
| 1080 | UNREACHABLE(); |
| 1081 | return 0; |
| 1082 | } |
| 1083 | } |
| 1084 | |
| 1085 | GLuint GetBlueBits(GLint internalFormat, GLuint clientVersion) |
| 1086 | { |
| 1087 | InternalFormatInfo internalFormatInfo; |
| 1088 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1089 | { |
| 1090 | return internalFormatInfo.mGreenBits; |
| 1091 | } |
| 1092 | else |
| 1093 | { |
| 1094 | UNREACHABLE(); |
| 1095 | return 0; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | GLuint GetLuminanceBits(GLint internalFormat, GLuint clientVersion) |
| 1100 | { |
| 1101 | InternalFormatInfo internalFormatInfo; |
| 1102 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1103 | { |
| 1104 | return internalFormatInfo.mLuminanceBits; |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | UNREACHABLE(); |
| 1109 | return 0; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | GLuint GetDepthBits(GLint internalFormat, GLuint clientVersion) |
| 1114 | { |
| 1115 | InternalFormatInfo internalFormatInfo; |
| 1116 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1117 | { |
| 1118 | return internalFormatInfo.mDepthBits; |
| 1119 | } |
| 1120 | else |
| 1121 | { |
| 1122 | UNREACHABLE(); |
| 1123 | return 0; |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | GLuint GetStencilBits(GLint internalFormat, GLuint clientVersion) |
| 1128 | { |
| 1129 | InternalFormatInfo internalFormatInfo; |
| 1130 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1131 | { |
| 1132 | return internalFormatInfo.mStencilBits; |
| 1133 | } |
| 1134 | else |
| 1135 | { |
| 1136 | UNREACHABLE(); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | GLenum GetFormat(GLint internalFormat, GLuint clientVersion) |
| 1142 | { |
| 1143 | InternalFormatInfo internalFormatInfo; |
| 1144 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1145 | { |
| 1146 | return internalFormatInfo.mFormat; |
| 1147 | } |
| 1148 | else |
| 1149 | { |
| 1150 | UNREACHABLE(); |
| 1151 | return GL_NONE; |
| 1152 | } |
| 1153 | } |
| 1154 | |
| 1155 | GLenum GetType(GLint internalFormat, GLuint clientVersion) |
| 1156 | { |
| 1157 | InternalFormatInfo internalFormatInfo; |
| 1158 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1159 | { |
| 1160 | return internalFormatInfo.mType; |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | UNREACHABLE(); |
| 1165 | return GL_NONE; |
| 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | bool IsColorRenderingSupported(GLint internalFormat, const rx::Renderer *renderer) |
| 1170 | { |
| 1171 | InternalFormatInfo internalFormatInfo; |
| 1172 | if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo)) |
| 1173 | { |
| 1174 | return internalFormatInfo.mIsColorRenderable(NULL, renderer); |
| 1175 | } |
| 1176 | else |
| 1177 | { |
| 1178 | UNREACHABLE(); |
| 1179 | return false; |
| 1180 | } |
| 1181 | } |
| 1182 | |
| 1183 | bool IsColorRenderingSupported(GLint internalFormat, const Context *context) |
| 1184 | { |
| 1185 | InternalFormatInfo internalFormatInfo; |
| 1186 | if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo)) |
| 1187 | { |
| 1188 | return internalFormatInfo.mIsColorRenderable(context, NULL); |
| 1189 | } |
| 1190 | else |
| 1191 | { |
| 1192 | UNREACHABLE(); |
| 1193 | return false; |
| 1194 | } |
| 1195 | } |
| 1196 | |
| 1197 | bool IsTextureFilteringSupported(GLint internalFormat, const rx::Renderer *renderer) |
| 1198 | { |
| 1199 | InternalFormatInfo internalFormatInfo; |
| 1200 | if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo)) |
| 1201 | { |
| 1202 | return internalFormatInfo.mIsTextureFilterable(NULL, renderer); |
| 1203 | } |
| 1204 | else |
| 1205 | { |
| 1206 | UNREACHABLE(); |
| 1207 | return false; |
| 1208 | } |
| 1209 | } |
| 1210 | |
| 1211 | bool IsTextureFilteringSupported(GLint internalFormat, const Context *context) |
| 1212 | { |
| 1213 | InternalFormatInfo internalFormatInfo; |
| 1214 | if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo)) |
| 1215 | { |
| 1216 | return internalFormatInfo.mIsTextureFilterable(context, NULL); |
| 1217 | } |
| 1218 | else |
| 1219 | { |
| 1220 | UNREACHABLE(); |
| 1221 | return false; |
| 1222 | } |
| 1223 | } |
| 1224 | |
| 1225 | bool IsDepthRenderingSupported(GLint internalFormat, const rx::Renderer *renderer) |
| 1226 | { |
| 1227 | InternalFormatInfo internalFormatInfo; |
| 1228 | if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo)) |
| 1229 | { |
| 1230 | return internalFormatInfo.mIsDepthRenderable(NULL, renderer); |
| 1231 | } |
| 1232 | else |
| 1233 | { |
| 1234 | UNREACHABLE(); |
| 1235 | return false; |
| 1236 | } |
| 1237 | } |
| 1238 | |
| 1239 | bool IsDepthRenderingSupported(GLint internalFormat, const Context *context) |
| 1240 | { |
| 1241 | InternalFormatInfo internalFormatInfo; |
| 1242 | if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo)) |
| 1243 | { |
| 1244 | return internalFormatInfo.mIsDepthRenderable(context, NULL); |
| 1245 | } |
| 1246 | else |
| 1247 | { |
| 1248 | UNREACHABLE(); |
| 1249 | return false; |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | bool IsStencilRenderingSupported(GLint internalFormat, const rx::Renderer *renderer) |
| 1254 | { |
| 1255 | InternalFormatInfo internalFormatInfo; |
| 1256 | if (renderer && getInternalFormatInfo(internalFormat, renderer->getCurrentClientVersion(), &internalFormatInfo)) |
| 1257 | { |
| 1258 | return internalFormatInfo.mIsStencilRenderable(NULL, renderer); |
| 1259 | } |
| 1260 | else |
| 1261 | { |
| 1262 | UNREACHABLE(); |
| 1263 | return false; |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | bool IsStencilRenderingSupported(GLint internalFormat, const Context *context) |
| 1268 | { |
| 1269 | InternalFormatInfo internalFormatInfo; |
| 1270 | if (context && getInternalFormatInfo(internalFormat, context->getClientVersion(), &internalFormatInfo)) |
| 1271 | { |
| 1272 | return internalFormatInfo.mIsStencilRenderable(context, NULL); |
| 1273 | } |
| 1274 | else |
| 1275 | { |
| 1276 | UNREACHABLE(); |
| 1277 | return false; |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | GLuint GetRowPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLint alignment) |
| 1282 | { |
| 1283 | ASSERT(alignment > 0 && isPow2(alignment)); |
| 1284 | return (GetBlockSize(internalFormat, type, clientVersion, width, 1) + alignment - 1) & ~(alignment - 1); |
| 1285 | } |
| 1286 | |
| 1287 | GLuint GetDepthPitch(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height, GLint alignment) |
| 1288 | { |
| 1289 | return (GetBlockSize(internalFormat, type, clientVersion, width, height) + alignment - 1) & ~(alignment - 1); |
| 1290 | } |
| 1291 | |
| 1292 | GLuint GetBlockSize(GLint internalFormat, GLenum type, GLuint clientVersion, GLsizei width, GLsizei height) |
| 1293 | { |
| 1294 | InternalFormatInfo internalFormatInfo; |
| 1295 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1296 | { |
| 1297 | if (internalFormatInfo.mIsCompressed) |
| 1298 | { |
| 1299 | GLsizei numBlocksWide = (width + internalFormatInfo.mCompressedBlockWidth - 1) / internalFormatInfo.mCompressedBlockWidth; |
| 1300 | GLsizei numBlocksHight = (height + internalFormatInfo.mCompressedBlockHeight - 1) / internalFormatInfo.mCompressedBlockHeight; |
| 1301 | |
| 1302 | return (internalFormatInfo.mPixelBits * numBlocksWide * numBlocksHight) / 8; |
| 1303 | } |
| 1304 | else |
| 1305 | { |
| 1306 | TypeInfo typeInfo; |
| 1307 | if (getTypeInfo(type, &typeInfo)) |
| 1308 | { |
| 1309 | if (typeInfo.mSpecialInterpretation) |
| 1310 | { |
| 1311 | return typeInfo.mTypeBytes * width * height; |
| 1312 | } |
| 1313 | else |
| 1314 | { |
| 1315 | return internalFormatInfo.mComponentCount * typeInfo.mTypeBytes * width * height; |
| 1316 | } |
| 1317 | } |
| 1318 | else |
| 1319 | { |
| 1320 | UNREACHABLE(); |
| 1321 | return 0; |
| 1322 | } |
| 1323 | } |
| 1324 | } |
| 1325 | else |
| 1326 | { |
| 1327 | UNREACHABLE(); |
| 1328 | return 0; |
| 1329 | } |
| 1330 | } |
| 1331 | |
| 1332 | bool IsFormatCompressed(GLint internalFormat, GLuint clientVersion) |
| 1333 | { |
| 1334 | InternalFormatInfo internalFormatInfo; |
| 1335 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1336 | { |
| 1337 | return internalFormatInfo.mIsCompressed; |
| 1338 | } |
| 1339 | else |
| 1340 | { |
| 1341 | UNREACHABLE(); |
| 1342 | return false; |
| 1343 | } |
| 1344 | } |
| 1345 | |
| 1346 | GLuint GetCompressedBlockWidth(GLint internalFormat, GLuint clientVersion) |
| 1347 | { |
| 1348 | InternalFormatInfo internalFormatInfo; |
| 1349 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1350 | { |
| 1351 | return internalFormatInfo.mCompressedBlockWidth; |
| 1352 | } |
| 1353 | else |
| 1354 | { |
| 1355 | UNREACHABLE(); |
| 1356 | return 0; |
| 1357 | } |
| 1358 | } |
| 1359 | |
| 1360 | GLuint GetCompressedBlockHeight(GLint internalFormat, GLuint clientVersion) |
| 1361 | { |
| 1362 | InternalFormatInfo internalFormatInfo; |
| 1363 | if (getInternalFormatInfo(internalFormat, clientVersion, &internalFormatInfo)) |
| 1364 | { |
| 1365 | return internalFormatInfo.mCompressedBlockHeight; |
| 1366 | } |
| 1367 | else |
| 1368 | { |
| 1369 | UNREACHABLE(); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | } |