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