Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
| 10 | #include "libANGLE/validationES.h" |
| 11 | #include "libANGLE/Context.h" |
| 12 | #include "libANGLE/Texture.h" |
| 13 | #include "libANGLE/Framebuffer.h" |
| 14 | #include "libANGLE/Renderbuffer.h" |
| 15 | #include "libANGLE/formatutils.h" |
| 16 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 17 | |
| 18 | #include "common/mathutil.h" |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 19 | #include "common/utilities.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 20 | |
| 21 | namespace gl |
| 22 | { |
| 23 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 24 | struct ES3FormatCombination |
| 25 | { |
| 26 | GLenum internalFormat; |
| 27 | GLenum format; |
| 28 | GLenum type; |
| 29 | }; |
| 30 | |
| 31 | bool operator<(const ES3FormatCombination& a, const ES3FormatCombination& b) |
| 32 | { |
| 33 | return memcmp(&a, &b, sizeof(ES3FormatCombination)) < 0; |
| 34 | } |
| 35 | |
| 36 | typedef std::set<ES3FormatCombination> ES3FormatCombinationSet; |
| 37 | |
| 38 | static inline void InsertES3FormatCombo(ES3FormatCombinationSet *set, GLenum internalFormat, GLenum format, GLenum type) |
| 39 | { |
| 40 | ES3FormatCombination info; |
| 41 | info.internalFormat = internalFormat; |
| 42 | info.format = format; |
| 43 | info.type = type; |
| 44 | set->insert(info); |
| 45 | } |
| 46 | |
| 47 | ES3FormatCombinationSet BuildES3FormatSet() |
| 48 | { |
| 49 | ES3FormatCombinationSet set; |
| 50 | |
| 51 | // Format combinations from ES 3.0.1 spec, table 3.2 |
| 52 | |
| 53 | // | Internal format | Format | Type | |
| 54 | // | | | | |
| 55 | InsertES3FormatCombo(&set, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 56 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 57 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 58 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 59 | InsertES3FormatCombo(&set, GL_RGBA8_SNORM, GL_RGBA, GL_BYTE ); |
| 60 | InsertES3FormatCombo(&set, GL_RGBA4, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 61 | InsertES3FormatCombo(&set, GL_RGB10_A2, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 62 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 63 | InsertES3FormatCombo(&set, GL_RGB5_A1, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 64 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT ); |
| 65 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_HALF_FLOAT_OES ); |
| 66 | InsertES3FormatCombo(&set, GL_RGBA32F, GL_RGBA, GL_FLOAT ); |
| 67 | InsertES3FormatCombo(&set, GL_RGBA16F, GL_RGBA, GL_FLOAT ); |
| 68 | InsertES3FormatCombo(&set, GL_RGBA8UI, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE ); |
| 69 | InsertES3FormatCombo(&set, GL_RGBA8I, GL_RGBA_INTEGER, GL_BYTE ); |
| 70 | InsertES3FormatCombo(&set, GL_RGBA16UI, GL_RGBA_INTEGER, GL_UNSIGNED_SHORT ); |
| 71 | InsertES3FormatCombo(&set, GL_RGBA16I, GL_RGBA_INTEGER, GL_SHORT ); |
| 72 | InsertES3FormatCombo(&set, GL_RGBA32UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT ); |
| 73 | InsertES3FormatCombo(&set, GL_RGBA32I, GL_RGBA_INTEGER, GL_INT ); |
| 74 | InsertES3FormatCombo(&set, GL_RGB10_A2UI, GL_RGBA_INTEGER, GL_UNSIGNED_INT_2_10_10_10_REV ); |
| 75 | InsertES3FormatCombo(&set, GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 76 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_BYTE ); |
| 77 | InsertES3FormatCombo(&set, GL_SRGB8, GL_RGB, GL_UNSIGNED_BYTE ); |
| 78 | InsertES3FormatCombo(&set, GL_RGB8_SNORM, GL_RGB, GL_BYTE ); |
| 79 | InsertES3FormatCombo(&set, GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 80 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV ); |
| 81 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_UNSIGNED_INT_5_9_9_9_REV ); |
| 82 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT ); |
| 83 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 84 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT ); |
| 85 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_HALF_FLOAT_OES ); |
| 86 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT ); |
| 87 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_HALF_FLOAT_OES ); |
| 88 | InsertES3FormatCombo(&set, GL_RGB32F, GL_RGB, GL_FLOAT ); |
| 89 | InsertES3FormatCombo(&set, GL_RGB16F, GL_RGB, GL_FLOAT ); |
| 90 | InsertES3FormatCombo(&set, GL_R11F_G11F_B10F, GL_RGB, GL_FLOAT ); |
| 91 | InsertES3FormatCombo(&set, GL_RGB9_E5, GL_RGB, GL_FLOAT ); |
| 92 | InsertES3FormatCombo(&set, GL_RGB8UI, GL_RGB_INTEGER, GL_UNSIGNED_BYTE ); |
| 93 | InsertES3FormatCombo(&set, GL_RGB8I, GL_RGB_INTEGER, GL_BYTE ); |
| 94 | InsertES3FormatCombo(&set, GL_RGB16UI, GL_RGB_INTEGER, GL_UNSIGNED_SHORT ); |
| 95 | InsertES3FormatCombo(&set, GL_RGB16I, GL_RGB_INTEGER, GL_SHORT ); |
| 96 | InsertES3FormatCombo(&set, GL_RGB32UI, GL_RGB_INTEGER, GL_UNSIGNED_INT ); |
| 97 | InsertES3FormatCombo(&set, GL_RGB32I, GL_RGB_INTEGER, GL_INT ); |
| 98 | InsertES3FormatCombo(&set, GL_RG8, GL_RG, GL_UNSIGNED_BYTE ); |
| 99 | InsertES3FormatCombo(&set, GL_RG8_SNORM, GL_RG, GL_BYTE ); |
| 100 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT ); |
| 101 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_HALF_FLOAT_OES ); |
| 102 | InsertES3FormatCombo(&set, GL_RG32F, GL_RG, GL_FLOAT ); |
| 103 | InsertES3FormatCombo(&set, GL_RG16F, GL_RG, GL_FLOAT ); |
| 104 | InsertES3FormatCombo(&set, GL_RG8UI, GL_RG_INTEGER, GL_UNSIGNED_BYTE ); |
| 105 | InsertES3FormatCombo(&set, GL_RG8I, GL_RG_INTEGER, GL_BYTE ); |
| 106 | InsertES3FormatCombo(&set, GL_RG16UI, GL_RG_INTEGER, GL_UNSIGNED_SHORT ); |
| 107 | InsertES3FormatCombo(&set, GL_RG16I, GL_RG_INTEGER, GL_SHORT ); |
| 108 | InsertES3FormatCombo(&set, GL_RG32UI, GL_RG_INTEGER, GL_UNSIGNED_INT ); |
| 109 | InsertES3FormatCombo(&set, GL_RG32I, GL_RG_INTEGER, GL_INT ); |
| 110 | InsertES3FormatCombo(&set, GL_R8, GL_RED, GL_UNSIGNED_BYTE ); |
| 111 | InsertES3FormatCombo(&set, GL_R8_SNORM, GL_RED, GL_BYTE ); |
| 112 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT ); |
| 113 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_HALF_FLOAT_OES ); |
| 114 | InsertES3FormatCombo(&set, GL_R32F, GL_RED, GL_FLOAT ); |
| 115 | InsertES3FormatCombo(&set, GL_R16F, GL_RED, GL_FLOAT ); |
| 116 | InsertES3FormatCombo(&set, GL_R8UI, GL_RED_INTEGER, GL_UNSIGNED_BYTE ); |
| 117 | InsertES3FormatCombo(&set, GL_R8I, GL_RED_INTEGER, GL_BYTE ); |
| 118 | InsertES3FormatCombo(&set, GL_R16UI, GL_RED_INTEGER, GL_UNSIGNED_SHORT ); |
| 119 | InsertES3FormatCombo(&set, GL_R16I, GL_RED_INTEGER, GL_SHORT ); |
| 120 | InsertES3FormatCombo(&set, GL_R32UI, GL_RED_INTEGER, GL_UNSIGNED_INT ); |
| 121 | InsertES3FormatCombo(&set, GL_R32I, GL_RED_INTEGER, GL_INT ); |
| 122 | |
| 123 | // Unsized formats |
| 124 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE ); |
| 125 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4 ); |
| 126 | InsertES3FormatCombo(&set, GL_RGBA, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1 ); |
| 127 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_BYTE ); |
| 128 | InsertES3FormatCombo(&set, GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5 ); |
| 129 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 130 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 131 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 132 | InsertES3FormatCombo(&set, GL_SRGB_ALPHA_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 133 | InsertES3FormatCombo(&set, GL_SRGB_EXT, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
Jamie Madill | 689325c | 2015-07-20 14:36:53 -0400 | [diff] [blame] | 134 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_UNSIGNED_BYTE ); |
| 135 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_FLOAT ); |
| 136 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT ); |
| 137 | InsertES3FormatCombo(&set, GL_RG, GL_RG, GL_HALF_FLOAT_OES ); |
| 138 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_UNSIGNED_BYTE ); |
| 139 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_FLOAT ); |
| 140 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT ); |
| 141 | InsertES3FormatCombo(&set, GL_RED, GL_RED, GL_HALF_FLOAT_OES ); |
| 142 | InsertES3FormatCombo(&set, GL_DEPTH_STENCIL, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 143 | |
| 144 | // Depth stencil formats |
| 145 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT ); |
| 146 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 147 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT ); |
| 148 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32F, GL_DEPTH_COMPONENT, GL_FLOAT ); |
| 149 | InsertES3FormatCombo(&set, GL_DEPTH24_STENCIL8, GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8 ); |
| 150 | InsertES3FormatCombo(&set, GL_DEPTH32F_STENCIL8, GL_DEPTH_STENCIL, GL_FLOAT_32_UNSIGNED_INT_24_8_REV); |
| 151 | |
| 152 | // From GL_EXT_sRGB |
| 153 | InsertES3FormatCombo(&set, GL_SRGB8_ALPHA8_EXT, GL_SRGB_ALPHA_EXT, GL_UNSIGNED_BYTE ); |
| 154 | InsertES3FormatCombo(&set, GL_SRGB8, GL_SRGB_EXT, GL_UNSIGNED_BYTE ); |
| 155 | |
| 156 | // From GL_OES_texture_float |
| 157 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 158 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_FLOAT ); |
| 159 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_FLOAT ); |
| 160 | |
| 161 | // From GL_OES_texture_half_float |
| 162 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 163 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 164 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 165 | InsertES3FormatCombo(&set, GL_LUMINANCE, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 166 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT ); |
| 167 | InsertES3FormatCombo(&set, GL_ALPHA, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 168 | |
| 169 | // From GL_EXT_texture_format_BGRA8888 |
| 170 | InsertES3FormatCombo(&set, GL_BGRA_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 171 | |
| 172 | // From GL_EXT_texture_storage |
| 173 | // | Internal format | Format | Type | |
| 174 | // | | | | |
| 175 | InsertES3FormatCombo(&set, GL_ALPHA8_EXT, GL_ALPHA, GL_UNSIGNED_BYTE ); |
| 176 | InsertES3FormatCombo(&set, GL_LUMINANCE8_EXT, GL_LUMINANCE, GL_UNSIGNED_BYTE ); |
| 177 | InsertES3FormatCombo(&set, GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE ); |
| 178 | InsertES3FormatCombo(&set, GL_ALPHA32F_EXT, GL_ALPHA, GL_FLOAT ); |
| 179 | InsertES3FormatCombo(&set, GL_LUMINANCE32F_EXT, GL_LUMINANCE, GL_FLOAT ); |
| 180 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA32F_EXT, GL_LUMINANCE_ALPHA, GL_FLOAT ); |
| 181 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT ); |
| 182 | InsertES3FormatCombo(&set, GL_ALPHA16F_EXT, GL_ALPHA, GL_HALF_FLOAT_OES ); |
| 183 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT ); |
| 184 | InsertES3FormatCombo(&set, GL_LUMINANCE16F_EXT, GL_LUMINANCE, GL_HALF_FLOAT_OES ); |
| 185 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT ); |
| 186 | InsertES3FormatCombo(&set, GL_LUMINANCE_ALPHA16F_EXT, GL_LUMINANCE_ALPHA, GL_HALF_FLOAT_OES ); |
| 187 | |
| 188 | // From GL_EXT_texture_storage and GL_EXT_texture_format_BGRA8888 |
| 189 | InsertES3FormatCombo(&set, GL_BGRA8_EXT, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 190 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT); |
| 191 | InsertES3FormatCombo(&set, GL_BGRA4_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 192 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT); |
| 193 | InsertES3FormatCombo(&set, GL_BGR5_A1_ANGLEX, GL_BGRA_EXT, GL_UNSIGNED_BYTE ); |
| 194 | |
| 195 | // From GL_ANGLE_depth_texture |
| 196 | InsertES3FormatCombo(&set, GL_DEPTH_COMPONENT32_OES, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT_24_8_OES ); |
| 197 | |
| 198 | // Compressed formats |
| 199 | // From ES 3.0.1 spec, table 3.16 |
| 200 | // | Internal format | Format | Type | |
| 201 | // | | | | |
| 202 | InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE); |
| 203 | InsertES3FormatCombo(&set, GL_COMPRESSED_R11_EAC, GL_COMPRESSED_R11_EAC, GL_UNSIGNED_BYTE); |
| 204 | InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_R11_EAC, GL_COMPRESSED_SIGNED_R11_EAC, GL_UNSIGNED_BYTE); |
| 205 | InsertES3FormatCombo(&set, GL_COMPRESSED_RG11_EAC, GL_COMPRESSED_RG11_EAC, GL_UNSIGNED_BYTE); |
| 206 | InsertES3FormatCombo(&set, GL_COMPRESSED_SIGNED_RG11_EAC, GL_COMPRESSED_SIGNED_RG11_EAC, GL_UNSIGNED_BYTE); |
| 207 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_ETC2, GL_COMPRESSED_RGB8_ETC2, GL_UNSIGNED_BYTE); |
| 208 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ETC2, GL_COMPRESSED_SRGB8_ETC2, GL_UNSIGNED_BYTE); |
| 209 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE); |
| 210 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, GL_UNSIGNED_BYTE); |
| 211 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_COMPRESSED_RGBA8_ETC2_EAC, GL_UNSIGNED_BYTE); |
| 212 | InsertES3FormatCombo(&set, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, GL_UNSIGNED_BYTE); |
| 213 | |
| 214 | |
| 215 | // From GL_EXT_texture_compression_dxt1 |
| 216 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE); |
| 217 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, GL_UNSIGNED_BYTE); |
| 218 | |
| 219 | // From GL_ANGLE_texture_compression_dxt3 |
| 220 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE, GL_UNSIGNED_BYTE); |
| 221 | |
| 222 | // From GL_ANGLE_texture_compression_dxt5 |
| 223 | InsertES3FormatCombo(&set, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE, GL_UNSIGNED_BYTE); |
| 224 | |
| 225 | return set; |
| 226 | } |
| 227 | |
| 228 | static bool ValidateTexImageFormatCombination(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type) |
| 229 | { |
| 230 | // Note: dEQP 2013.4 expects an INVALID_VALUE error for TexImage3D with an invalid |
| 231 | // internal format. (dEQP-GLES3.functional.negative_api.texture.teximage3d) |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 232 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 233 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 234 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 235 | context->recordError(Error(GL_INVALID_ENUM)); |
| 236 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | // The type and format are valid if any supported internal format has that type and format |
| 240 | bool formatSupported = false; |
| 241 | bool typeSupported = false; |
| 242 | |
| 243 | static const ES3FormatCombinationSet es3FormatSet = BuildES3FormatSet(); |
| 244 | for (ES3FormatCombinationSet::const_iterator i = es3FormatSet.begin(); i != es3FormatSet.end(); i++) |
| 245 | { |
| 246 | if (i->format == format || i->type == type) |
| 247 | { |
| 248 | const gl::InternalFormat &info = gl::GetInternalFormatInfo(i->internalFormat); |
| 249 | bool supported = info.textureSupport(context->getClientVersion(), context->getExtensions()); |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 250 | if (supported && i->type == type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 251 | { |
| 252 | typeSupported = true; |
| 253 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 254 | if (supported && i->format == format) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 255 | { |
| 256 | formatSupported = true; |
| 257 | } |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 258 | |
| 259 | // Early-out if both type and format are supported now |
| 260 | if (typeSupported && formatSupported) |
| 261 | { |
| 262 | break; |
| 263 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 264 | } |
| 265 | } |
| 266 | |
| 267 | if (!typeSupported || !formatSupported) |
| 268 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 269 | context->recordError(Error(GL_INVALID_ENUM)); |
| 270 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | // Check if this is a valid format combination to load texture data |
| 274 | ES3FormatCombination searchFormat; |
| 275 | searchFormat.internalFormat = internalFormat; |
| 276 | searchFormat.format = format; |
| 277 | searchFormat.type = type; |
| 278 | |
| 279 | if (es3FormatSet.find(searchFormat) == es3FormatSet.end()) |
| 280 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 281 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 282 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | return true; |
| 286 | } |
| 287 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 288 | bool ValidateES3TexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, bool isCompressed, bool isSubImage, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 289 | GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 290 | GLint border, GLenum format, GLenum type, const GLvoid *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 291 | { |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 292 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 293 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 294 | context->recordError(Error(GL_INVALID_ENUM)); |
| 295 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 296 | } |
| 297 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 298 | // Validate image size |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 299 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 300 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 301 | context->recordError(Error(GL_INVALID_VALUE)); |
| 302 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 303 | } |
| 304 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 305 | // Verify zero border |
| 306 | if (border != 0) |
| 307 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 308 | context->recordError(Error(GL_INVALID_VALUE)); |
| 309 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 310 | } |
| 311 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 312 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 313 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 314 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 315 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 316 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 317 | context->recordError(Error(GL_INVALID_VALUE)); |
| 318 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 319 | } |
| 320 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 321 | const gl::Caps &caps = context->getCaps(); |
| 322 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 323 | switch (target) |
| 324 | { |
| 325 | case GL_TEXTURE_2D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 326 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 327 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 328 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 329 | context->recordError(Error(GL_INVALID_VALUE)); |
| 330 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 331 | } |
| 332 | break; |
| 333 | |
| 334 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 335 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 336 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 337 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 338 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 339 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 340 | if (!isSubImage && width != height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 341 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 342 | context->recordError(Error(GL_INVALID_VALUE)); |
| 343 | return false; |
| 344 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 345 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 346 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 347 | { |
| 348 | context->recordError(Error(GL_INVALID_VALUE)); |
| 349 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 350 | } |
| 351 | break; |
| 352 | |
| 353 | case GL_TEXTURE_3D: |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 354 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 355 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 356 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 357 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 358 | context->recordError(Error(GL_INVALID_VALUE)); |
| 359 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 360 | } |
| 361 | break; |
| 362 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 363 | case GL_TEXTURE_2D_ARRAY: |
| 364 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 365 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 366 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 367 | { |
| 368 | context->recordError(Error(GL_INVALID_VALUE)); |
| 369 | return false; |
| 370 | } |
| 371 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 372 | |
| 373 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 374 | context->recordError(Error(GL_INVALID_ENUM)); |
| 375 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 376 | } |
| 377 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 378 | gl::Texture *texture = context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 379 | if (!texture) |
| 380 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 381 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 382 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 383 | } |
| 384 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 385 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 386 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 387 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 388 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | // Validate texture formats |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 392 | GLenum actualInternalFormat = isSubImage ? texture->getInternalFormat(target, level) : internalformat; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 393 | const gl::InternalFormat &actualFormatInfo = gl::GetInternalFormatInfo(actualInternalFormat); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 394 | if (isCompressed) |
| 395 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 396 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 397 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 398 | context->recordError(Error( |
| 399 | GL_INVALID_ENUM, "internalformat is not a supported compressed internal format.")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 400 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 401 | } |
| 402 | |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 403 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 404 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 405 | context->recordError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 406 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | if (target == GL_TEXTURE_3D) |
| 410 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 411 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 412 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 413 | } |
| 414 | } |
| 415 | else |
| 416 | { |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 417 | if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 418 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 419 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 423 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 424 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 425 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
| 429 | // Validate sub image parameters |
| 430 | if (isSubImage) |
| 431 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 432 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 433 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 434 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 435 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 436 | } |
| 437 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 438 | if (width == 0 || height == 0 || depth == 0) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 444 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 445 | context->recordError(Error(GL_INVALID_VALUE)); |
| 446 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 450 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 451 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 452 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 453 | context->recordError(Error(GL_INVALID_VALUE)); |
| 454 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 457 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 458 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 459 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 460 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 461 | context->recordError(Error(GL_INVALID_VALUE)); |
| 462 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 463 | } |
| 464 | } |
| 465 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 466 | // Check for pixel unpack buffer related API errors |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 467 | gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 468 | if (pixelUnpackBuffer != NULL) |
| 469 | { |
| 470 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 471 | // would exceed the data store size. |
| 472 | size_t widthSize = static_cast<size_t>(width); |
| 473 | size_t heightSize = static_cast<size_t>(height); |
| 474 | size_t depthSize = static_cast<size_t>(depth); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 475 | GLenum sizedFormat = GetSizedInternalFormat(actualInternalFormat, type); |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 476 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 477 | size_t pixelBytes = static_cast<size_t>(gl::GetInternalFormatInfo(sizedFormat).pixelBytes); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 478 | |
| 479 | if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) || |
| 480 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) || |
| 481 | !rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes)) |
| 482 | { |
| 483 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 484 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 485 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 486 | } |
| 487 | |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 488 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); |
| 489 | size_t copyBytes = formatInfo.computeBlockSize(type, width, height); |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 490 | size_t offset = reinterpret_cast<size_t>(pixels); |
| 491 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 492 | if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) || |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 493 | ((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 494 | { |
| 495 | // Overflow past the end of the buffer |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 496 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 497 | return false; |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | // ...data is not evenly divisible into the number of bytes needed to store in memory a datum |
| 501 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 502 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 503 | { |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 504 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 505 | |
| 506 | if ((offset % dataBytesPerPixel) != 0) |
| 507 | { |
| 508 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 509 | return false; |
| 510 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 511 | } |
| 512 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 513 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 514 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 515 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 516 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 517 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 518 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 519 | } |
| 520 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 521 | return true; |
| 522 | } |
| 523 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 524 | struct EffectiveInternalFormatInfo |
| 525 | { |
| 526 | GLenum mEffectiveFormat; |
| 527 | GLenum mDestFormat; |
| 528 | GLuint mMinRedBits; |
| 529 | GLuint mMaxRedBits; |
| 530 | GLuint mMinGreenBits; |
| 531 | GLuint mMaxGreenBits; |
| 532 | GLuint mMinBlueBits; |
| 533 | GLuint mMaxBlueBits; |
| 534 | GLuint mMinAlphaBits; |
| 535 | GLuint mMaxAlphaBits; |
| 536 | |
| 537 | EffectiveInternalFormatInfo(GLenum effectiveFormat, GLenum destFormat, GLuint minRedBits, GLuint maxRedBits, |
| 538 | GLuint minGreenBits, GLuint maxGreenBits, GLuint minBlueBits, GLuint maxBlueBits, |
| 539 | GLuint minAlphaBits, GLuint maxAlphaBits) |
| 540 | : mEffectiveFormat(effectiveFormat), mDestFormat(destFormat), mMinRedBits(minRedBits), |
| 541 | mMaxRedBits(maxRedBits), mMinGreenBits(minGreenBits), mMaxGreenBits(maxGreenBits), |
| 542 | mMinBlueBits(minBlueBits), mMaxBlueBits(maxBlueBits), mMinAlphaBits(minAlphaBits), |
| 543 | mMaxAlphaBits(maxAlphaBits) {}; |
| 544 | }; |
| 545 | |
| 546 | typedef std::vector<EffectiveInternalFormatInfo> EffectiveInternalFormatList; |
| 547 | |
| 548 | static EffectiveInternalFormatList BuildSizedEffectiveInternalFormatList() |
| 549 | { |
| 550 | EffectiveInternalFormatList list; |
| 551 | |
| 552 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 553 | // linear source buffer component sizes. |
| 554 | // | Source channel min/max sizes | |
| 555 | // Effective Internal Format | N/A | R | G | B | A | |
| 556 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8)); |
| 557 | list.push_back(EffectiveInternalFormatInfo(GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0)); |
| 558 | list.push_back(EffectiveInternalFormatInfo(GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0)); |
| 559 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0)); |
| 560 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0)); |
| 561 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 562 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 563 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8)); |
| 564 | list.push_back(EffectiveInternalFormatInfo(GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2)); |
| 565 | |
| 566 | return list; |
| 567 | } |
| 568 | |
| 569 | static EffectiveInternalFormatList BuildUnsizedEffectiveInternalFormatList() |
| 570 | { |
| 571 | EffectiveInternalFormatList list; |
| 572 | |
| 573 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: Effective internal format coresponding to destination internal format and |
| 574 | // linear source buffer component sizes. |
| 575 | // | Source channel min/max sizes | |
| 576 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 577 | list.push_back(EffectiveInternalFormatInfo(GL_ALPHA8_EXT, GL_ALPHA, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 578 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 0, UINT_MAX)); |
| 579 | list.push_back(EffectiveInternalFormatInfo(GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, UINT_MAX, 0, UINT_MAX, 1, 8)); |
| 580 | list.push_back(EffectiveInternalFormatInfo(GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, UINT_MAX)); |
| 581 | list.push_back(EffectiveInternalFormatInfo(GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, UINT_MAX)); |
| 582 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4)); |
| 583 | list.push_back(EffectiveInternalFormatInfo(GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1)); |
| 584 | list.push_back(EffectiveInternalFormatInfo(GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8)); |
| 585 | |
| 586 | return list; |
| 587 | } |
| 588 | |
| 589 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, const InternalFormat &destFormat, |
| 590 | GLenum *outEffectiveFormat) |
| 591 | { |
| 592 | const EffectiveInternalFormatList *list = NULL; |
| 593 | GLenum targetFormat = GL_NONE; |
| 594 | |
| 595 | if (destFormat.pixelBytes > 0) |
| 596 | { |
| 597 | static const EffectiveInternalFormatList sizedList = BuildSizedEffectiveInternalFormatList(); |
| 598 | list = &sizedList; |
| 599 | } |
| 600 | else |
| 601 | { |
| 602 | static const EffectiveInternalFormatList unsizedList = BuildUnsizedEffectiveInternalFormatList(); |
| 603 | list = &unsizedList; |
| 604 | targetFormat = destFormat.format; |
| 605 | } |
| 606 | |
| 607 | for (size_t curFormat = 0; curFormat < list->size(); ++curFormat) |
| 608 | { |
| 609 | const EffectiveInternalFormatInfo& formatInfo = list->at(curFormat); |
| 610 | if ((formatInfo.mDestFormat == targetFormat) && |
| 611 | (formatInfo.mMinRedBits <= srcFormat.redBits && formatInfo.mMaxRedBits >= srcFormat.redBits) && |
| 612 | (formatInfo.mMinGreenBits <= srcFormat.greenBits && formatInfo.mMaxGreenBits >= srcFormat.greenBits) && |
| 613 | (formatInfo.mMinBlueBits <= srcFormat.blueBits && formatInfo.mMaxBlueBits >= srcFormat.blueBits) && |
| 614 | (formatInfo.mMinAlphaBits <= srcFormat.alphaBits && formatInfo.mMaxAlphaBits >= srcFormat.alphaBits)) |
| 615 | { |
| 616 | *outEffectiveFormat = formatInfo.mEffectiveFormat; |
| 617 | return true; |
| 618 | } |
| 619 | } |
| 620 | |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | struct CopyConversion |
| 625 | { |
| 626 | GLenum mTextureFormat; |
| 627 | GLenum mFramebufferFormat; |
| 628 | |
| 629 | CopyConversion(GLenum textureFormat, GLenum framebufferFormat) |
| 630 | : mTextureFormat(textureFormat), mFramebufferFormat(framebufferFormat) { } |
| 631 | |
| 632 | bool operator<(const CopyConversion& other) const |
| 633 | { |
| 634 | return memcmp(this, &other, sizeof(CopyConversion)) < 0; |
| 635 | } |
| 636 | }; |
| 637 | |
| 638 | typedef std::set<CopyConversion> CopyConversionSet; |
| 639 | |
| 640 | static CopyConversionSet BuildValidES3CopyTexImageCombinations() |
| 641 | { |
| 642 | CopyConversionSet set; |
| 643 | |
| 644 | // From ES 3.0.1 spec, table 3.15 |
| 645 | set.insert(CopyConversion(GL_ALPHA, GL_RGBA)); |
| 646 | set.insert(CopyConversion(GL_LUMINANCE, GL_RED)); |
| 647 | set.insert(CopyConversion(GL_LUMINANCE, GL_RG)); |
| 648 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGB)); |
| 649 | set.insert(CopyConversion(GL_LUMINANCE, GL_RGBA)); |
| 650 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_RGBA)); |
| 651 | set.insert(CopyConversion(GL_RED, GL_RED)); |
| 652 | set.insert(CopyConversion(GL_RED, GL_RG)); |
| 653 | set.insert(CopyConversion(GL_RED, GL_RGB)); |
| 654 | set.insert(CopyConversion(GL_RED, GL_RGBA)); |
| 655 | set.insert(CopyConversion(GL_RG, GL_RG)); |
| 656 | set.insert(CopyConversion(GL_RG, GL_RGB)); |
| 657 | set.insert(CopyConversion(GL_RG, GL_RGBA)); |
| 658 | set.insert(CopyConversion(GL_RGB, GL_RGB)); |
| 659 | set.insert(CopyConversion(GL_RGB, GL_RGBA)); |
| 660 | set.insert(CopyConversion(GL_RGBA, GL_RGBA)); |
| 661 | |
| 662 | // Necessary for ANGLE back-buffers |
| 663 | set.insert(CopyConversion(GL_ALPHA, GL_BGRA_EXT)); |
| 664 | set.insert(CopyConversion(GL_LUMINANCE, GL_BGRA_EXT)); |
| 665 | set.insert(CopyConversion(GL_LUMINANCE_ALPHA, GL_BGRA_EXT)); |
| 666 | set.insert(CopyConversion(GL_RED, GL_BGRA_EXT)); |
| 667 | set.insert(CopyConversion(GL_RG, GL_BGRA_EXT)); |
| 668 | set.insert(CopyConversion(GL_RGB, GL_BGRA_EXT)); |
| 669 | set.insert(CopyConversion(GL_RGBA, GL_BGRA_EXT)); |
| 670 | |
| 671 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RED_INTEGER)); |
| 672 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RG_INTEGER)); |
| 673 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGB_INTEGER)); |
| 674 | set.insert(CopyConversion(GL_RED_INTEGER, GL_RGBA_INTEGER)); |
| 675 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RG_INTEGER)); |
| 676 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGB_INTEGER)); |
| 677 | set.insert(CopyConversion(GL_RG_INTEGER, GL_RGBA_INTEGER)); |
| 678 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGB_INTEGER)); |
| 679 | set.insert(CopyConversion(GL_RGB_INTEGER, GL_RGBA_INTEGER)); |
| 680 | set.insert(CopyConversion(GL_RGBA_INTEGER, GL_RGBA_INTEGER)); |
| 681 | |
| 682 | return set; |
| 683 | } |
| 684 | |
| 685 | static bool IsValidES3CopyTexImageCombination(GLenum textureInternalFormat, GLenum frameBufferInternalFormat, GLuint readBufferHandle) |
| 686 | { |
| 687 | const InternalFormat &textureInternalFormatInfo = GetInternalFormatInfo(textureInternalFormat); |
| 688 | const InternalFormat &framebufferInternalFormatInfo = GetInternalFormatInfo(frameBufferInternalFormat); |
| 689 | |
| 690 | static const CopyConversionSet conversionSet = BuildValidES3CopyTexImageCombinations(); |
| 691 | if (conversionSet.find(CopyConversion(textureInternalFormatInfo.format, framebufferInternalFormatInfo.format)) != conversionSet.end()) |
| 692 | { |
| 693 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 694 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 695 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 696 | // conversion between fixed and floating point. |
| 697 | |
| 698 | if ((textureInternalFormatInfo.colorEncoding == GL_SRGB) != (framebufferInternalFormatInfo.colorEncoding == GL_SRGB)) |
| 699 | { |
| 700 | return false; |
| 701 | } |
| 702 | |
| 703 | if (((textureInternalFormatInfo.componentType == GL_INT) != (framebufferInternalFormatInfo.componentType == GL_INT )) || |
| 704 | ((textureInternalFormatInfo.componentType == GL_UNSIGNED_INT) != (framebufferInternalFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 705 | { |
| 706 | return false; |
| 707 | } |
| 708 | |
| 709 | if ((textureInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 710 | textureInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 711 | textureInternalFormatInfo.componentType == GL_FLOAT) && |
| 712 | !(framebufferInternalFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 713 | framebufferInternalFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 714 | framebufferInternalFormatInfo.componentType == GL_FLOAT)) |
| 715 | { |
| 716 | return false; |
| 717 | } |
| 718 | |
| 719 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 720 | // The effective internal format of the source buffer is determined with the following rules applied in order: |
| 721 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal format then the |
| 722 | // effective internal format is the source buffer's sized internal format. |
| 723 | // * If the source buffer is a texture that was created with an unsized base internal format, then the |
| 724 | // effective internal format is the source image array's effective internal format, as specified by table |
| 725 | // 3.12, which is determined from the <format> and <type> that were used when the source image array was |
| 726 | // specified by TexImage*. |
| 727 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 where |
| 728 | // Destination Internal Format matches internalformat and where the [source channel sizes] are consistent |
| 729 | // with the values of the source buffer's [channel sizes]. Table 3.17 is used if the |
| 730 | // FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the FRAMEBUFFER_ATTACHMENT_ENCODING |
| 731 | // is SRGB. |
| 732 | const InternalFormat *sourceEffectiveFormat = NULL; |
| 733 | if (readBufferHandle != 0) |
| 734 | { |
| 735 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or renderbuffer |
| 736 | if (framebufferInternalFormatInfo.pixelBytes > 0) |
| 737 | { |
| 738 | sourceEffectiveFormat = &framebufferInternalFormatInfo; |
| 739 | } |
| 740 | else |
| 741 | { |
| 742 | // Renderbuffers cannot be created with an unsized internal format, so this must be an unsized-format |
| 743 | // texture. We can use the same table we use when creating textures to get its effective sized format. |
Geoff Lang | 051dbc7 | 2015-01-05 15:48:58 -0500 | [diff] [blame] | 744 | GLenum sizedInternalFormat = GetSizedInternalFormat(framebufferInternalFormatInfo.format, framebufferInternalFormatInfo.type); |
| 745 | sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | else |
| 749 | { |
| 750 | // The effective internal format must be derived from the source framebuffer's channel sizes. |
| 751 | // This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 752 | if (framebufferInternalFormatInfo.colorEncoding == GL_LINEAR) |
| 753 | { |
| 754 | GLenum effectiveFormat; |
| 755 | if (GetEffectiveInternalFormat(framebufferInternalFormatInfo, textureInternalFormatInfo, &effectiveFormat)) |
| 756 | { |
| 757 | sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat); |
| 758 | } |
| 759 | else |
| 760 | { |
| 761 | return false; |
| 762 | } |
| 763 | } |
| 764 | else if (framebufferInternalFormatInfo.colorEncoding == GL_SRGB) |
| 765 | { |
| 766 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 767 | if ((textureInternalFormatInfo.pixelBytes > 0) && |
| 768 | (framebufferInternalFormatInfo.redBits >= 1 && framebufferInternalFormatInfo.redBits <= 8) && |
| 769 | (framebufferInternalFormatInfo.greenBits >= 1 && framebufferInternalFormatInfo.greenBits <= 8) && |
| 770 | (framebufferInternalFormatInfo.blueBits >= 1 && framebufferInternalFormatInfo.blueBits <= 8) && |
| 771 | (framebufferInternalFormatInfo.alphaBits >= 1 && framebufferInternalFormatInfo.alphaBits <= 8)) |
| 772 | { |
| 773 | sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8); |
| 774 | } |
| 775 | else |
| 776 | { |
| 777 | return false; |
| 778 | } |
| 779 | } |
| 780 | else |
| 781 | { |
| 782 | UNREACHABLE(); |
| 783 | return false; |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | if (textureInternalFormatInfo.pixelBytes > 0) |
| 788 | { |
| 789 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is sized, |
| 790 | // component sizes of the source and destination formats must exactly match |
| 791 | if (textureInternalFormatInfo.redBits != sourceEffectiveFormat->redBits || |
| 792 | textureInternalFormatInfo.greenBits != sourceEffectiveFormat->greenBits || |
| 793 | textureInternalFormatInfo.blueBits != sourceEffectiveFormat->blueBits || |
| 794 | textureInternalFormatInfo.alphaBits != sourceEffectiveFormat->alphaBits) |
| 795 | { |
| 796 | return false; |
| 797 | } |
| 798 | } |
| 799 | |
| 800 | |
| 801 | return true; // A conversion function exists, and no rule in the specification has precluded conversion |
| 802 | // between these formats. |
| 803 | } |
| 804 | |
| 805 | return false; |
| 806 | } |
| 807 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 808 | bool ValidateES3CopyTexImageParameters(Context *context, GLenum target, GLint level, GLenum internalformat, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 809 | bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset, |
| 810 | GLint x, GLint y, GLsizei width, GLsizei height, GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 811 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 812 | GLenum textureInternalFormat; |
| 813 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 814 | xoffset, yoffset, zoffset, x, y, width, height, |
| 815 | border, &textureInternalFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 816 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 817 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 818 | } |
| 819 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 820 | gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 821 | |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 822 | if (framebuffer->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 823 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 824 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 825 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 826 | } |
| 827 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 828 | if (context->getState().getReadFramebuffer()->id() != 0 && |
| 829 | framebuffer->getSamples(context->getData()) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 830 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 831 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 832 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 833 | } |
| 834 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 835 | const gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 836 | GLenum colorbufferInternalFormat = source->getInternalFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 837 | |
| 838 | if (isSubImage) |
| 839 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 840 | if (!IsValidES3CopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat, |
| 841 | context->getState().getReadFramebuffer()->id())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 842 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 843 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 844 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 845 | } |
| 846 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 847 | else |
| 848 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 849 | if (!gl::IsValidES3CopyTexImageCombination(internalformat, colorbufferInternalFormat, |
| 850 | context->getState().getReadFramebuffer()->id())) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 851 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 852 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 853 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 854 | } |
| 855 | } |
| 856 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 857 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 858 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 859 | } |
| 860 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 861 | bool ValidateES3TexStorageParameters(Context *context, GLenum target, GLsizei levels, GLenum internalformat, |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 862 | GLsizei width, GLsizei height, GLsizei depth) |
| 863 | { |
| 864 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 865 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 866 | context->recordError(Error(GL_INVALID_VALUE)); |
| 867 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 868 | } |
| 869 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 870 | GLsizei maxDim = std::max(width, height); |
| 871 | if (target != GL_TEXTURE_2D_ARRAY) |
| 872 | { |
| 873 | maxDim = std::max(maxDim, depth); |
| 874 | } |
| 875 | |
| 876 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 877 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 878 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 879 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 880 | } |
| 881 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 882 | const gl::Caps &caps = context->getCaps(); |
| 883 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 884 | switch (target) |
| 885 | { |
| 886 | case GL_TEXTURE_2D: |
| 887 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 888 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 889 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 890 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 891 | context->recordError(Error(GL_INVALID_VALUE)); |
| 892 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 893 | } |
| 894 | } |
| 895 | break; |
| 896 | |
Geoff Lang | 01c21d2 | 2013-09-24 11:52:16 -0400 | [diff] [blame] | 897 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 898 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 899 | if (width != height) |
| 900 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 901 | context->recordError(Error(GL_INVALID_VALUE)); |
| 902 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 903 | } |
| 904 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 905 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 906 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 907 | context->recordError(Error(GL_INVALID_VALUE)); |
| 908 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | break; |
| 912 | |
| 913 | case GL_TEXTURE_3D: |
| 914 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 915 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 916 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 917 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 918 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 919 | context->recordError(Error(GL_INVALID_VALUE)); |
| 920 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | break; |
| 924 | |
| 925 | case GL_TEXTURE_2D_ARRAY: |
| 926 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 927 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 928 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 929 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 930 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 931 | context->recordError(Error(GL_INVALID_VALUE)); |
| 932 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 933 | } |
| 934 | } |
| 935 | break; |
| 936 | |
| 937 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 938 | context->recordError(Error(GL_INVALID_ENUM)); |
| 939 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 940 | } |
| 941 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 942 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 943 | if (!texture || texture->id() == 0) |
| 944 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 945 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 946 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 947 | } |
| 948 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 949 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 950 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 951 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 952 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 953 | } |
| 954 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 955 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 956 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 957 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 958 | context->recordError(Error(GL_INVALID_ENUM)); |
| 959 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 962 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 963 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 964 | context->recordError(Error(GL_INVALID_ENUM)); |
| 965 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | return true; |
| 969 | } |
| 970 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 971 | bool ValidateFramebufferTextureLayer(Context *context, GLenum target, GLenum attachment, |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 972 | GLuint texture, GLint level, GLint layer) |
| 973 | { |
| 974 | if (context->getClientVersion() < 3) |
| 975 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 976 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 977 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 978 | } |
| 979 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 980 | if (layer < 0) |
| 981 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 982 | context->recordError(Error(GL_INVALID_VALUE)); |
| 983 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 987 | { |
| 988 | return false; |
| 989 | } |
| 990 | |
| 991 | const gl::Caps &caps = context->getCaps(); |
| 992 | if (texture != 0) |
| 993 | { |
| 994 | gl::Texture *tex = context->getTexture(texture); |
| 995 | ASSERT(tex); |
| 996 | |
| 997 | switch (tex->getTarget()) |
| 998 | { |
| 999 | case GL_TEXTURE_2D_ARRAY: |
| 1000 | { |
| 1001 | if (level > gl::log2(caps.max2DTextureSize)) |
| 1002 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1003 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1004 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1008 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1009 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1010 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1011 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1012 | } |
| 1013 | break; |
| 1014 | |
| 1015 | case GL_TEXTURE_3D: |
| 1016 | { |
| 1017 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1018 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1019 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1020 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1024 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1025 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1026 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1027 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1028 | } |
| 1029 | break; |
| 1030 | |
| 1031 | default: |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1032 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1033 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1034 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1035 | |
| 1036 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(tex->getInternalFormat(tex->getTarget(), level)); |
| 1037 | if (internalFormatInfo.compressed) |
| 1038 | { |
| 1039 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1040 | return false; |
| 1041 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1045 | } |
| 1046 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1047 | bool ValidES3ReadFormatType(Context *context, GLenum internalFormat, GLenum format, GLenum type) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1048 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1049 | const gl::InternalFormat &internalFormatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 1050 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1051 | switch (format) |
| 1052 | { |
| 1053 | case GL_RGBA: |
| 1054 | switch (type) |
| 1055 | { |
| 1056 | case GL_UNSIGNED_BYTE: |
| 1057 | break; |
| 1058 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 1059 | if (internalFormat != GL_RGB10_A2) |
| 1060 | { |
| 1061 | return false; |
| 1062 | } |
| 1063 | break; |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1064 | case GL_FLOAT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1065 | if (internalFormatInfo.componentType != GL_FLOAT) |
Geoff Lang | 1ec57f8 | 2013-10-16 11:43:23 -0400 | [diff] [blame] | 1066 | { |
| 1067 | return false; |
| 1068 | } |
| 1069 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1070 | default: |
| 1071 | return false; |
| 1072 | } |
| 1073 | break; |
| 1074 | case GL_RGBA_INTEGER: |
| 1075 | switch (type) |
| 1076 | { |
| 1077 | case GL_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1078 | if (internalFormatInfo.componentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1079 | { |
| 1080 | return false; |
| 1081 | } |
| 1082 | break; |
| 1083 | case GL_UNSIGNED_INT: |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1084 | if (internalFormatInfo.componentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1085 | { |
| 1086 | return false; |
| 1087 | } |
| 1088 | break; |
| 1089 | default: |
| 1090 | return false; |
| 1091 | } |
| 1092 | break; |
| 1093 | case GL_BGRA_EXT: |
| 1094 | switch (type) |
| 1095 | { |
| 1096 | case GL_UNSIGNED_BYTE: |
| 1097 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 1098 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 1099 | break; |
| 1100 | default: |
| 1101 | return false; |
| 1102 | } |
| 1103 | break; |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1104 | case GL_RG_EXT: |
| 1105 | case GL_RED_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1106 | if (!context->getExtensions().textureRG) |
Geoff Lang | bdc9b2f | 2014-04-16 14:41:54 -0400 | [diff] [blame] | 1107 | { |
| 1108 | return false; |
| 1109 | } |
| 1110 | switch (type) |
| 1111 | { |
| 1112 | case GL_UNSIGNED_BYTE: |
| 1113 | break; |
| 1114 | default: |
| 1115 | return false; |
| 1116 | } |
| 1117 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1118 | default: |
| 1119 | return false; |
| 1120 | } |
| 1121 | return true; |
| 1122 | } |
| 1123 | |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1124 | bool ValidateES3RenderbufferStorageParameters(gl::Context *context, GLenum target, GLsizei samples, |
| 1125 | GLenum internalformat, GLsizei width, GLsizei height) |
| 1126 | { |
| 1127 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, height)) |
| 1128 | { |
| 1129 | return false; |
| 1130 | } |
| 1131 | |
| 1132 | //The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer format if samples is greater than zero. |
| 1133 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 1134 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && samples > 0) |
| 1135 | { |
| 1136 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1137 | return false; |
| 1138 | } |
| 1139 | |
| 1140 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 1141 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1142 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1143 | { |
| 1144 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1145 | return false; |
| 1146 | } |
| 1147 | |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1151 | bool ValidateInvalidateFramebuffer(Context *context, GLenum target, GLsizei numAttachments, |
| 1152 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1153 | { |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1154 | if (context->getClientVersion() < 3) |
| 1155 | { |
| 1156 | context->recordError(Error(GL_INVALID_OPERATION, "Operation only supported on ES 3.0 and above")); |
| 1157 | return false; |
| 1158 | } |
| 1159 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1160 | bool defaultFramebuffer = false; |
| 1161 | |
| 1162 | switch (target) |
| 1163 | { |
| 1164 | case GL_DRAW_FRAMEBUFFER: |
| 1165 | case GL_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1166 | defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1167 | break; |
| 1168 | case GL_READ_FRAMEBUFFER: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1169 | defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | break; |
| 1171 | default: |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1172 | context->recordError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
| 1173 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1176 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1177 | } |
| 1178 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1179 | bool ValidateClearBuffer(Context *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1180 | { |
| 1181 | if (context->getClientVersion() < 3) |
| 1182 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1184 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1187 | const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer(); |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1188 | if (!fbo || fbo->checkStatus(context->getData()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1189 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1190 | context->recordError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
| 1191 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1192 | } |
| 1193 | |
| 1194 | return true; |
| 1195 | } |
| 1196 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1197 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint* params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1198 | { |
| 1199 | if (context->getClientVersion() < 3) |
| 1200 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1201 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1202 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1205 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1208 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1209 | { |
| 1210 | if (context->getClientVersion() < 3) |
| 1211 | { |
| 1212 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1213 | return false; |
| 1214 | } |
| 1215 | |
| 1216 | Framebuffer *readFBO = context->getState().getReadFramebuffer(); |
| 1217 | |
| 1218 | if (readFBO == nullptr) |
| 1219 | { |
| 1220 | context->recordError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer.")); |
| 1221 | return false; |
| 1222 | } |
| 1223 | |
| 1224 | if (src == GL_NONE) |
| 1225 | { |
| 1226 | return true; |
| 1227 | } |
| 1228 | |
| 1229 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT15)) |
| 1230 | { |
| 1231 | context->recordError(gl::Error(GL_INVALID_ENUM, "Unknown enum for 'src' in ReadBuffer")); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | if (readFBO->id() == 0) |
| 1236 | { |
| 1237 | if (src != GL_BACK) |
| 1238 | { |
| 1239 | const char *errorMsg = "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."; |
| 1240 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1241 | return false; |
| 1242 | } |
| 1243 | } |
| 1244 | else |
| 1245 | { |
| 1246 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1247 | |
| 1248 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1249 | { |
| 1250 | const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS."; |
| 1251 | context->recordError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
| 1252 | return false; |
| 1253 | } |
| 1254 | } |
| 1255 | |
| 1256 | return true; |
| 1257 | } |
| 1258 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1259 | bool ValidateCompressedTexImage3D(Context *context, |
| 1260 | GLenum target, |
| 1261 | GLint level, |
| 1262 | GLenum internalformat, |
| 1263 | GLsizei width, |
| 1264 | GLsizei height, |
| 1265 | GLsizei depth, |
| 1266 | GLint border, |
| 1267 | GLsizei imageSize, |
| 1268 | const GLvoid *data) |
| 1269 | { |
| 1270 | if (context->getClientVersion() < 3) |
| 1271 | { |
| 1272 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1273 | return false; |
| 1274 | } |
| 1275 | |
| 1276 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
| 1277 | if (imageSize < 0 || |
| 1278 | static_cast<GLuint>(imageSize) != |
| 1279 | formatInfo.computeBlockSize(GL_UNSIGNED_BYTE, width, height)) |
| 1280 | { |
| 1281 | context->recordError(Error(GL_INVALID_VALUE)); |
| 1282 | return false; |
| 1283 | } |
| 1284 | |
| 1285 | // 3D texture target validation |
| 1286 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1287 | { |
| 1288 | context->recordError( |
| 1289 | Error(GL_INVALID_ENUM, "Must specify a valid 3D texture destination target")); |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
| 1293 | // validateES3TexImageFormat sets the error code if there is an error |
| 1294 | if (!ValidateES3TexImageParameters(context, target, level, internalformat, true, false, 0, 0, 0, |
| 1295 | width, height, depth, border, GL_NONE, GL_NONE, data)) |
| 1296 | { |
| 1297 | return false; |
| 1298 | } |
| 1299 | |
| 1300 | return true; |
| 1301 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame^] | 1302 | |
| 1303 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1304 | { |
| 1305 | if (context->getClientVersion() < 3) |
| 1306 | { |
| 1307 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1308 | return false; |
| 1309 | } |
| 1310 | |
| 1311 | return ValidateBindVertexArrayBase(context, array); |
| 1312 | } |
| 1313 | |
| 1314 | bool ValidateDeleteVertexArrays(Context *context, GLsizei n) |
| 1315 | { |
| 1316 | if (context->getClientVersion() < 3) |
| 1317 | { |
| 1318 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1319 | return false; |
| 1320 | } |
| 1321 | |
| 1322 | return ValidateDeleteVertexArraysBase(context, n); |
| 1323 | } |
| 1324 | |
| 1325 | bool ValidateGenVertexArrays(Context *context, GLsizei n) |
| 1326 | { |
| 1327 | if (context->getClientVersion() < 3) |
| 1328 | { |
| 1329 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1330 | return false; |
| 1331 | } |
| 1332 | |
| 1333 | return ValidateGenVertexArraysBase(context, n); |
| 1334 | } |
| 1335 | |
| 1336 | bool ValidateIsVertexArray(Context *context) |
| 1337 | { |
| 1338 | if (context->getClientVersion() < 3) |
| 1339 | { |
| 1340 | context->recordError(Error(GL_INVALID_OPERATION)); |
| 1341 | return false; |
| 1342 | } |
| 1343 | |
| 1344 | return true; |
| 1345 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1346 | } |