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