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 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 12 | #include "libANGLE/Display.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 13 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Query.h" |
| 19 | #include "libANGLE/Texture.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 24 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 25 | #include "libANGLE/queryutils.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 26 | #include "libANGLE/validationES2.h" |
| 27 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 28 | |
| 29 | #include "common/mathutil.h" |
| 30 | #include "common/utilities.h" |
| 31 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 32 | using namespace angle; |
| 33 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 36 | namespace |
| 37 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 38 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 39 | { |
| 40 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 41 | // the compressed block size. |
| 42 | switch (internalFormat) |
| 43 | { |
| 44 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 48 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 52 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 53 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 59 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 60 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 61 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 62 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 63 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 64 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 65 | default: |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 70 | { |
| 71 | // Compressed sub textures have additional formats that requires exact size. |
| 72 | // ES 3.1, Section 8.7, Page 171 |
| 73 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 74 | IsETC2EACFormat(internalFormat); |
| 75 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 76 | |
| 77 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 78 | { |
| 79 | CheckedNumeric<GLint> checkedA(a); |
| 80 | checkedA -= b; |
| 81 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 82 | checkedA = -checkedA; |
| 83 | return !checkedA.IsValid(); |
| 84 | } |
| 85 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 86 | bool ValidateDrawAttribsImpl(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 87 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 88 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 89 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 90 | |
Jamie Madill | 88602e6 | 2018-08-08 12:49:30 -0400 | [diff] [blame] | 91 | // An overflow can happen when adding the offset. Check against a special constant. |
| 92 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 93 | VertexAttribute::kIntegerOverflow || |
| 94 | context->getStateCache().getInstancedVertexElementLimit() == |
| 95 | VertexAttribute::kIntegerOverflow) |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 96 | { |
| 97 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 102 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
| 103 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
| 104 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 107 | ANGLE_INLINE bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
| 108 | { |
| 109 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 110 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
| 111 | { |
| 112 | return true; |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | return ValidateDrawAttribsImpl(context, primcount, maxVertex); |
| 117 | } |
| 118 | } |
| 119 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 120 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 121 | { |
| 122 | switch (type) |
| 123 | { |
| 124 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 125 | case GL_UNSIGNED_BYTE: |
| 126 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 127 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 128 | case GL_UNSIGNED_SHORT_5_6_5: |
| 129 | return context->getClientVersion() >= ES_2_0; |
| 130 | |
| 131 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 132 | case GL_BYTE: |
| 133 | case GL_INT: |
| 134 | case GL_SHORT: |
| 135 | case GL_UNSIGNED_INT: |
| 136 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 137 | case GL_UNSIGNED_INT_24_8: |
| 138 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 139 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 140 | case GL_UNSIGNED_SHORT: |
| 141 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 142 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 143 | return context->getClientVersion() >= ES_3_0; |
| 144 | |
| 145 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 146 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 147 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 148 | |
| 149 | case GL_HALF_FLOAT: |
| 150 | return context->getClientVersion() >= ES_3_0 || |
| 151 | context->getExtensions().textureHalfFloat; |
| 152 | |
| 153 | case GL_HALF_FLOAT_OES: |
| 154 | return context->getExtensions().colorBufferHalfFloat; |
| 155 | |
| 156 | default: |
| 157 | return false; |
| 158 | } |
| 159 | } |
| 160 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 161 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 162 | { |
| 163 | switch (format) |
| 164 | { |
| 165 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 166 | case GL_RGBA: |
| 167 | case GL_RGB: |
| 168 | case GL_ALPHA: |
| 169 | return context->getClientVersion() >= ES_2_0; |
| 170 | |
| 171 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 172 | case GL_RG: |
| 173 | case GL_RED: |
| 174 | case GL_RGBA_INTEGER: |
| 175 | case GL_RGB_INTEGER: |
| 176 | case GL_RG_INTEGER: |
| 177 | case GL_RED_INTEGER: |
| 178 | return context->getClientVersion() >= ES_3_0; |
| 179 | |
| 180 | case GL_SRGB_ALPHA_EXT: |
| 181 | case GL_SRGB_EXT: |
| 182 | return context->getExtensions().sRGB; |
| 183 | |
| 184 | case GL_BGRA_EXT: |
| 185 | return context->getExtensions().readFormatBGRA; |
| 186 | |
| 187 | default: |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 192 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 193 | GLenum framebufferComponentType, |
| 194 | GLenum format, |
| 195 | GLenum type) |
| 196 | { |
| 197 | switch (framebufferComponentType) |
| 198 | { |
| 199 | case GL_UNSIGNED_NORMALIZED: |
| 200 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 201 | // ReadPixels with BGRA even if the extension is not present |
| 202 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 203 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 204 | type == GL_UNSIGNED_BYTE); |
| 205 | |
| 206 | case GL_SIGNED_NORMALIZED: |
| 207 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 208 | |
| 209 | case GL_INT: |
| 210 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 211 | |
| 212 | case GL_UNSIGNED_INT: |
| 213 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 214 | |
| 215 | case GL_FLOAT: |
| 216 | return (format == GL_RGBA && type == GL_FLOAT); |
| 217 | |
| 218 | default: |
| 219 | UNREACHABLE(); |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 224 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 225 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 226 | { |
| 227 | switch (ConvertToGLenum(params[0])) |
| 228 | { |
| 229 | case GL_CLAMP_TO_EDGE: |
| 230 | break; |
| 231 | |
| 232 | case GL_REPEAT: |
| 233 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 234 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 235 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 236 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 237 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | break; |
| 241 | |
| 242 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 243 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 244 | return false; |
| 245 | } |
| 246 | |
| 247 | return true; |
| 248 | } |
| 249 | |
| 250 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 251 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 252 | { |
| 253 | switch (ConvertToGLenum(params[0])) |
| 254 | { |
| 255 | case GL_NEAREST: |
| 256 | case GL_LINEAR: |
| 257 | break; |
| 258 | |
| 259 | case GL_NEAREST_MIPMAP_NEAREST: |
| 260 | case GL_LINEAR_MIPMAP_NEAREST: |
| 261 | case GL_NEAREST_MIPMAP_LINEAR: |
| 262 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 263 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 264 | { |
| 265 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 266 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 267 | return false; |
| 268 | } |
| 269 | break; |
| 270 | |
| 271 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 272 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 273 | return false; |
| 274 | } |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | template <typename ParamType> |
| 280 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 281 | { |
| 282 | switch (ConvertToGLenum(params[0])) |
| 283 | { |
| 284 | case GL_NEAREST: |
| 285 | case GL_LINEAR: |
| 286 | break; |
| 287 | |
| 288 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 289 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 290 | return false; |
| 291 | } |
| 292 | |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | template <typename ParamType> |
| 297 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 298 | { |
| 299 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 300 | switch (ConvertToGLenum(params[0])) |
| 301 | { |
| 302 | case GL_NONE: |
| 303 | case GL_COMPARE_REF_TO_TEXTURE: |
| 304 | break; |
| 305 | |
| 306 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 307 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | |
| 311 | return true; |
| 312 | } |
| 313 | |
| 314 | template <typename ParamType> |
| 315 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 316 | { |
| 317 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 318 | switch (ConvertToGLenum(params[0])) |
| 319 | { |
| 320 | case GL_LEQUAL: |
| 321 | case GL_GEQUAL: |
| 322 | case GL_LESS: |
| 323 | case GL_GREATER: |
| 324 | case GL_EQUAL: |
| 325 | case GL_NOTEQUAL: |
| 326 | case GL_ALWAYS: |
| 327 | case GL_NEVER: |
| 328 | break; |
| 329 | |
| 330 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 331 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 332 | return false; |
| 333 | } |
| 334 | |
| 335 | return true; |
| 336 | } |
| 337 | |
| 338 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 339 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 340 | { |
| 341 | if (!context->getExtensions().textureSRGBDecode) |
| 342 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 343 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 344 | return false; |
| 345 | } |
| 346 | |
| 347 | switch (ConvertToGLenum(params[0])) |
| 348 | { |
| 349 | case GL_DECODE_EXT: |
| 350 | case GL_SKIP_DECODE_EXT: |
| 351 | break; |
| 352 | |
| 353 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 354 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 355 | return false; |
| 356 | } |
| 357 | |
| 358 | return true; |
| 359 | } |
| 360 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 361 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 362 | { |
| 363 | if (!context->getExtensions().textureFilterAnisotropic) |
| 364 | { |
| 365 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 366 | return false; |
| 367 | } |
| 368 | |
| 369 | return true; |
| 370 | } |
| 371 | |
| 372 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 373 | { |
| 374 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 375 | { |
| 376 | return false; |
| 377 | } |
| 378 | |
| 379 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 380 | |
| 381 | if (paramValue < 1 || paramValue > largest) |
| 382 | { |
| 383 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | return true; |
| 388 | } |
| 389 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 390 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 391 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 392 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 393 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 394 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 395 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 396 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 397 | program->getActiveOutputVariables().to_ulong(), |
| 398 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 399 | } |
| 400 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 401 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 402 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 403 | const auto &glState = context->getGLState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 404 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 405 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 406 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 407 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 408 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 409 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 410 | |
| 411 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 412 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 413 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 414 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 415 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 416 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 417 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 420 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 421 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 422 | { |
| 423 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 424 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 425 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 426 | case PrimitiveMode::Points: |
| 427 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 428 | case PrimitiveMode::Lines: |
| 429 | case PrimitiveMode::LineStrip: |
| 430 | case PrimitiveMode::LineLoop: |
| 431 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 432 | case PrimitiveMode::LinesAdjacency: |
| 433 | case PrimitiveMode::LineStripAdjacency: |
| 434 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 435 | case PrimitiveMode::Triangles: |
| 436 | case PrimitiveMode::TriangleFan: |
| 437 | case PrimitiveMode::TriangleStrip: |
| 438 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 439 | case PrimitiveMode::TrianglesAdjacency: |
| 440 | case PrimitiveMode::TriangleStripAdjacency: |
| 441 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 442 | default: |
| 443 | UNREACHABLE(); |
| 444 | return false; |
| 445 | } |
| 446 | } |
| 447 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 448 | // GLES1 texture parameters are a small subset of the others |
| 449 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 450 | { |
| 451 | switch (pname) |
| 452 | { |
| 453 | case GL_TEXTURE_MAG_FILTER: |
| 454 | case GL_TEXTURE_MIN_FILTER: |
| 455 | case GL_TEXTURE_WRAP_S: |
| 456 | case GL_TEXTURE_WRAP_T: |
| 457 | case GL_TEXTURE_WRAP_R: |
| 458 | case GL_GENERATE_MIPMAP: |
| 459 | case GL_TEXTURE_CROP_RECT_OES: |
| 460 | return true; |
| 461 | default: |
| 462 | return false; |
| 463 | } |
| 464 | } |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 465 | } // anonymous namespace |
| 466 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 467 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 468 | { |
| 469 | if (length) |
| 470 | { |
| 471 | *length = value; |
| 472 | } |
| 473 | } |
| 474 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 475 | bool IsETC2EACFormat(const GLenum format) |
| 476 | { |
| 477 | // ES 3.1, Table 8.19 |
| 478 | switch (format) |
| 479 | { |
| 480 | case GL_COMPRESSED_R11_EAC: |
| 481 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 482 | case GL_COMPRESSED_RG11_EAC: |
| 483 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 484 | case GL_COMPRESSED_RGB8_ETC2: |
| 485 | case GL_COMPRESSED_SRGB8_ETC2: |
| 486 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 487 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 488 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 489 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 490 | return true; |
| 491 | |
| 492 | default: |
| 493 | return false; |
| 494 | } |
| 495 | } |
| 496 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 497 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 498 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 499 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 500 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 501 | case TextureType::_2D: |
| 502 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 503 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 504 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 505 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 506 | return context->getExtensions().textureRectangle; |
| 507 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 508 | case TextureType::_3D: |
| 509 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 510 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 511 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 512 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 513 | return (context->getClientVersion() >= Version(3, 1)); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 514 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 515 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 516 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 517 | default: |
| 518 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 519 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 520 | } |
| 521 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 522 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 523 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 524 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 525 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 526 | case TextureType::_2D: |
| 527 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 528 | return true; |
| 529 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 530 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 531 | return context->getExtensions().textureRectangle; |
| 532 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 533 | default: |
| 534 | return false; |
| 535 | } |
| 536 | } |
| 537 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 538 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 539 | { |
| 540 | switch (target) |
| 541 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 542 | case TextureType::_3D: |
| 543 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 544 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 545 | |
| 546 | default: |
| 547 | return false; |
| 548 | } |
| 549 | } |
| 550 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 551 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 552 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 553 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 554 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 555 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 556 | (context->getExtensions().eglImageExternal || |
| 557 | context->getExtensions().eglStreamConsumerExternal); |
| 558 | } |
| 559 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 560 | // This function differs from ValidTextureTarget in that the target must be |
| 561 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 562 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 563 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 564 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 565 | { |
| 566 | switch (target) |
| 567 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 568 | case TextureTarget::_2D: |
| 569 | case TextureTarget::CubeMapNegativeX: |
| 570 | case TextureTarget::CubeMapNegativeY: |
| 571 | case TextureTarget::CubeMapNegativeZ: |
| 572 | case TextureTarget::CubeMapPositiveX: |
| 573 | case TextureTarget::CubeMapPositiveY: |
| 574 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 575 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 576 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 577 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 578 | default: |
| 579 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 580 | } |
| 581 | } |
| 582 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 583 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 584 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 585 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 586 | { |
| 587 | ASSERT(context); |
| 588 | |
| 589 | if (!context->getExtensions().geometryShader) |
| 590 | { |
| 591 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 592 | // that does not match the current transform feedback object's draw mode (if transform |
| 593 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 594 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 595 | } |
| 596 | |
| 597 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 598 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 599 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 600 | case PrimitiveMode::Points: |
| 601 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 602 | case PrimitiveMode::Lines: |
| 603 | case PrimitiveMode::LineStrip: |
| 604 | case PrimitiveMode::LineLoop: |
| 605 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 606 | case PrimitiveMode::Triangles: |
| 607 | case PrimitiveMode::TriangleFan: |
| 608 | case PrimitiveMode::TriangleStrip: |
| 609 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 610 | default: |
| 611 | UNREACHABLE(); |
| 612 | return false; |
| 613 | } |
| 614 | } |
| 615 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 616 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 617 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 618 | GLsizei count, |
| 619 | GLenum type, |
| 620 | const GLvoid *indices, |
| 621 | GLsizei primcount) |
| 622 | { |
| 623 | if (primcount < 0) |
| 624 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 625 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 626 | return false; |
| 627 | } |
| 628 | |
| 629 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 630 | { |
| 631 | return false; |
| 632 | } |
| 633 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 634 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 638 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 639 | GLint first, |
| 640 | GLsizei count, |
| 641 | GLsizei primcount) |
| 642 | { |
| 643 | if (primcount < 0) |
| 644 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 645 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 646 | return false; |
| 647 | } |
| 648 | |
| 649 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 654 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 655 | } |
| 656 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 657 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 658 | { |
| 659 | // Verify there is at least one active attribute with a divisor of zero |
| 660 | const State &state = context->getGLState(); |
| 661 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 662 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 663 | |
| 664 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 665 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 666 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 667 | { |
| 668 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 669 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 670 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 671 | { |
| 672 | return true; |
| 673 | } |
| 674 | } |
| 675 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 676 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 677 | return false; |
| 678 | } |
| 679 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 680 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 681 | { |
| 682 | switch (target) |
| 683 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 684 | case TextureType::_3D: |
| 685 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 686 | return true; |
| 687 | default: |
| 688 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 689 | } |
| 690 | } |
| 691 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 692 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 693 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 694 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 695 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 696 | case TextureType::_2D: |
| 697 | case TextureType::_2DArray: |
| 698 | case TextureType::_2DMultisample: |
| 699 | case TextureType::CubeMap: |
| 700 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 701 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 702 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 703 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 704 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 705 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 706 | default: |
| 707 | return false; |
| 708 | } |
| 709 | } |
| 710 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 711 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 712 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 713 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 714 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 715 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 716 | |
| 717 | switch (target) |
| 718 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 719 | case GL_FRAMEBUFFER: |
| 720 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 721 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 722 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 723 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 724 | return (context->getExtensions().framebufferBlit || |
| 725 | context->getClientMajorVersion() >= 3); |
| 726 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 727 | default: |
| 728 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 732 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 733 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 734 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 735 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 736 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 737 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 738 | case TextureType::_2D: |
| 739 | case TextureType::_2DArray: |
| 740 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 741 | case TextureType::_2DMultisampleArray: |
| 742 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 743 | // level-of-detail" for multisample textures should be. Could maybe make it zero. |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 744 | maxDimension = caps.max2DTextureSize; |
| 745 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 746 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 747 | maxDimension = caps.maxCubeMapTextureSize; |
| 748 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 749 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 750 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 751 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 752 | maxDimension = caps.max3DTextureSize; |
| 753 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 754 | default: |
| 755 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 756 | } |
| 757 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 758 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 759 | } |
| 760 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 761 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 762 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 763 | GLint level, |
| 764 | GLsizei width, |
| 765 | GLsizei height, |
| 766 | GLsizei depth, |
| 767 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 768 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 769 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 770 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 771 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 772 | return false; |
| 773 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 774 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 775 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 776 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 777 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 778 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 779 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 780 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 781 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 782 | return false; |
| 783 | } |
| 784 | |
| 785 | if (!ValidMipLevel(context, target, level)) |
| 786 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 787 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 788 | return false; |
| 789 | } |
| 790 | |
| 791 | return true; |
| 792 | } |
| 793 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 794 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 795 | { |
| 796 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 797 | (size % blockSize == 0); |
| 798 | } |
| 799 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 800 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 801 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 802 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 803 | GLsizei width, |
| 804 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 805 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 806 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 807 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 808 | { |
| 809 | return false; |
| 810 | } |
| 811 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 812 | if (width < 0 || height < 0) |
| 813 | { |
| 814 | return false; |
| 815 | } |
| 816 | |
| 817 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 818 | { |
| 819 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 820 | // block size for level 0 but WebGL disallows this. |
| 821 | bool smallerThanBlockSizeAllowed = |
| 822 | level > 0 || !context->getExtensions().webglCompatibility; |
| 823 | |
| 824 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 825 | smallerThanBlockSizeAllowed) || |
| 826 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 827 | smallerThanBlockSizeAllowed)) |
| 828 | { |
| 829 | return false; |
| 830 | } |
| 831 | } |
| 832 | |
| 833 | return true; |
| 834 | } |
| 835 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 836 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 837 | GLenum internalFormat, |
| 838 | GLint xoffset, |
| 839 | GLint yoffset, |
| 840 | GLsizei width, |
| 841 | GLsizei height, |
| 842 | size_t textureWidth, |
| 843 | size_t textureHeight) |
| 844 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 845 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 846 | if (!formatInfo.compressed) |
| 847 | { |
| 848 | return false; |
| 849 | } |
| 850 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 851 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 852 | { |
| 853 | return false; |
| 854 | } |
| 855 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 856 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 857 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 858 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 859 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 860 | { |
| 861 | return false; |
| 862 | } |
| 863 | |
| 864 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 865 | // size but fills the entire mip |
| 866 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 867 | static_cast<size_t>(width) == textureWidth && |
| 868 | static_cast<size_t>(height) == textureHeight; |
| 869 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 870 | (height % formatInfo.compressedBlockHeight) == 0; |
| 871 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 872 | { |
| 873 | return false; |
| 874 | } |
| 875 | } |
| 876 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 877 | return true; |
| 878 | } |
| 879 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 880 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 881 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 882 | GLsizei width, |
| 883 | GLsizei height, |
| 884 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 885 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 886 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 887 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 888 | GLsizei imageSize) |
| 889 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 890 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 891 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 892 | { |
| 893 | // Checks are not required |
| 894 | return true; |
| 895 | } |
| 896 | |
| 897 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 898 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 899 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 900 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 901 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 902 | const auto &unpack = context->getGLState().getUnpackState(); |
| 903 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 904 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 905 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 906 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 907 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 908 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 909 | return false; |
| 910 | } |
| 911 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 912 | if (pixelUnpackBuffer) |
| 913 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 914 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 915 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 916 | checkedEndByte += checkedOffset; |
| 917 | |
| 918 | if (!checkedEndByte.IsValid() || |
| 919 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 920 | { |
| 921 | // Overflow past the end of the buffer |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 922 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 923 | return false; |
| 924 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 925 | if (context->getExtensions().webglCompatibility && |
| 926 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 927 | { |
| 928 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 929 | PixelUnpackBufferBoundForTransformFeedback); |
| 930 | return false; |
| 931 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 932 | } |
| 933 | else |
| 934 | { |
| 935 | ASSERT(imageSize >= 0); |
| 936 | if (pixels == nullptr && imageSize != 0) |
| 937 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 938 | context->handleError(InvalidOperation() |
| 939 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 940 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 941 | } |
| 942 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 943 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 944 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 945 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 946 | return false; |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | return true; |
| 951 | } |
| 952 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 953 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 954 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 955 | switch (queryType) |
| 956 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 957 | case QueryType::AnySamples: |
| 958 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 959 | return context->getClientMajorVersion() >= 3 || |
| 960 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 961 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 962 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 963 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 964 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 965 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 966 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 967 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 968 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 969 | default: |
| 970 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 974 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 975 | GLenum type, |
| 976 | GLboolean normalized, |
| 977 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 978 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 979 | bool pureInteger) |
| 980 | { |
| 981 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 982 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 983 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 984 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 985 | // parameter exceeds 255. |
| 986 | constexpr GLsizei kMaxWebGLStride = 255; |
| 987 | if (stride > kMaxWebGLStride) |
| 988 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 989 | context->handleError(InvalidValue() |
| 990 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 991 | return false; |
| 992 | } |
| 993 | |
| 994 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 995 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 996 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 997 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 998 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 999 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1000 | |
| 1001 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1002 | size_t sizeMask = (typeSize - 1); |
| 1003 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1004 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1005 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | if ((stride & sizeMask) != 0) |
| 1010 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1011 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | return true; |
| 1016 | } |
| 1017 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1018 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1019 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1020 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1021 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1022 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1023 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1024 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1025 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1026 | |
| 1027 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1028 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1029 | if (context->getShader(id)) |
| 1030 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1031 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1032 | } |
| 1033 | else |
| 1034 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1035 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1036 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1037 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1038 | |
| 1039 | return validProgram; |
| 1040 | } |
| 1041 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1042 | Program *GetValidProgram(Context *context, GLuint id) |
| 1043 | { |
| 1044 | Program *program = GetValidProgramNoResolve(context, id); |
| 1045 | if (program) |
| 1046 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1047 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1048 | } |
| 1049 | return program; |
| 1050 | } |
| 1051 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1052 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1053 | { |
| 1054 | // See ValidProgram for spec details. |
| 1055 | |
| 1056 | Shader *validShader = context->getShader(id); |
| 1057 | |
| 1058 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1059 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1060 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1061 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1062 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1063 | } |
| 1064 | else |
| 1065 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1066 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1067 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1068 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1069 | |
| 1070 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1071 | } |
| 1072 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1073 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1074 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1075 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1076 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1077 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1078 | { |
| 1079 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1080 | return false; |
| 1081 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1082 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1083 | // Color attachment 0 is validated below because it is always valid |
| 1084 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1085 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1086 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1087 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1088 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | else |
| 1092 | { |
| 1093 | switch (attachment) |
| 1094 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1095 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1096 | case GL_DEPTH_ATTACHMENT: |
| 1097 | case GL_STENCIL_ATTACHMENT: |
| 1098 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1099 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1100 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1101 | if (!context->getExtensions().webglCompatibility && |
| 1102 | context->getClientMajorVersion() < 3) |
| 1103 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1104 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1105 | return false; |
| 1106 | } |
| 1107 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1108 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1109 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1110 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1111 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | return true; |
| 1116 | } |
| 1117 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1118 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1119 | GLenum target, |
| 1120 | GLsizei samples, |
| 1121 | GLenum internalformat, |
| 1122 | GLsizei width, |
| 1123 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1124 | { |
| 1125 | switch (target) |
| 1126 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1127 | case GL_RENDERBUFFER: |
| 1128 | break; |
| 1129 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1130 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1131 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1132 | } |
| 1133 | |
| 1134 | if (width < 0 || height < 0 || samples < 0) |
| 1135 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1136 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1137 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1140 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1141 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1142 | |
| 1143 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1144 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1145 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1146 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1147 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1151 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1152 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1153 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1154 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1155 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1156 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1157 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1160 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1161 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1162 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1163 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1164 | } |
| 1165 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1166 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1167 | if (handle == 0) |
| 1168 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1169 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1170 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | return true; |
| 1174 | } |
| 1175 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1176 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1177 | GLenum target, |
| 1178 | GLenum attachment, |
| 1179 | GLenum renderbuffertarget, |
| 1180 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1181 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1182 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1183 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1184 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1185 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1188 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1189 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1190 | ASSERT(framebuffer); |
| 1191 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1192 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1193 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1194 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1195 | } |
| 1196 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1197 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1198 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1199 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1200 | } |
| 1201 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1202 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1203 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1204 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1205 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1206 | if (renderbuffer != 0) |
| 1207 | { |
| 1208 | if (!context->getRenderbuffer(renderbuffer)) |
| 1209 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1210 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1211 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1212 | } |
| 1213 | } |
| 1214 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1215 | return true; |
| 1216 | } |
| 1217 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1218 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1219 | GLint srcX0, |
| 1220 | GLint srcY0, |
| 1221 | GLint srcX1, |
| 1222 | GLint srcY1, |
| 1223 | GLint dstX0, |
| 1224 | GLint dstY0, |
| 1225 | GLint dstX1, |
| 1226 | GLint dstY1, |
| 1227 | GLbitfield mask, |
| 1228 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1229 | { |
| 1230 | switch (filter) |
| 1231 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1232 | case GL_NEAREST: |
| 1233 | break; |
| 1234 | case GL_LINEAR: |
| 1235 | break; |
| 1236 | default: |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1237 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), BlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1238 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1239 | } |
| 1240 | |
| 1241 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1242 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1243 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1244 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1247 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1248 | // color buffer, leaving only nearest being unfiltered from above |
| 1249 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1250 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1251 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1252 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1253 | } |
| 1254 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1255 | const auto &glState = context->getGLState(); |
| 1256 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1257 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1258 | |
| 1259 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1260 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1261 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1262 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1265 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1266 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1267 | return false; |
| 1268 | } |
| 1269 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1270 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1271 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1272 | return false; |
| 1273 | } |
| 1274 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1275 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1276 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1277 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1278 | return false; |
| 1279 | } |
| 1280 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1281 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1282 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1283 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1284 | } |
| 1285 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1286 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1287 | // always run it in order to avoid triggering driver bugs. |
| 1288 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1289 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1290 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1291 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1292 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1293 | } |
| 1294 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1295 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1296 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1297 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1298 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1299 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1300 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1301 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1302 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1303 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1304 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1305 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1306 | for (size_t drawbufferIdx = 0; |
| 1307 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1308 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1309 | const FramebufferAttachment *attachment = |
| 1310 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1311 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1313 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1314 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1315 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1316 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1317 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1318 | // as well |
| 1319 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1320 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1321 | // Changes with EXT_color_buffer_float: |
| 1322 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1323 | GLenum readComponentType = readFormat.info->componentType; |
| 1324 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1325 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1326 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1327 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1328 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1329 | |
| 1330 | if (extensions.colorBufferFloat) |
| 1331 | { |
| 1332 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1333 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1334 | |
| 1335 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1336 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1338 | BlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1339 | return false; |
| 1340 | } |
| 1341 | } |
| 1342 | else if (readFixedPoint != drawFixedPoint) |
| 1343 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1344 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1345 | BlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1346 | return false; |
| 1347 | } |
| 1348 | |
| 1349 | if (readComponentType == GL_UNSIGNED_INT && |
| 1350 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1351 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1352 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1353 | BlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1354 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1357 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1358 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1359 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1360 | BlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1361 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1362 | } |
| 1363 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1364 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1365 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1366 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1367 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1368 | BlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1369 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1370 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1371 | |
| 1372 | if (context->getExtensions().webglCompatibility && |
| 1373 | *readColorBuffer == *attachment) |
| 1374 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1375 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1376 | return false; |
| 1377 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1381 | if ((readFormat.info->componentType == GL_INT || |
| 1382 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1383 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1384 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1385 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1386 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1387 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1388 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1389 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1390 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1391 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1392 | // situation is an application error that would lead to a crash in ANGLE. |
| 1393 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1394 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1395 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1396 | return false; |
| 1397 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1398 | } |
| 1399 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1400 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1401 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1402 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1404 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1405 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1406 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1407 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1408 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1409 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1410 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1411 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1412 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1413 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1414 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1415 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1416 | BlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1417 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1419 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1420 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1421 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1422 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1423 | BlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1424 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1426 | |
| 1427 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1428 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1429 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1430 | return false; |
| 1431 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1432 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1433 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1434 | else if (drawBuffer) |
| 1435 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1436 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1442 | // ANGLE_multiview, Revision 1: |
| 1443 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1444 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1445 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1446 | // views in the current read framebuffer is more than one. |
| 1447 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1448 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1449 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1453 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1454 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1455 | return false; |
| 1456 | } |
| 1457 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1458 | return true; |
| 1459 | } |
| 1460 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1461 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1462 | GLint x, |
| 1463 | GLint y, |
| 1464 | GLsizei width, |
| 1465 | GLsizei height, |
| 1466 | GLenum format, |
| 1467 | GLenum type, |
| 1468 | GLsizei bufSize, |
| 1469 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1470 | GLsizei *columns, |
| 1471 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1472 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1473 | { |
| 1474 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1475 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1476 | return false; |
| 1477 | } |
| 1478 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1479 | GLsizei writeLength = 0; |
| 1480 | GLsizei writeColumns = 0; |
| 1481 | GLsizei writeRows = 0; |
| 1482 | |
| 1483 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1484 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1485 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1486 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1489 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1490 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1491 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1492 | } |
| 1493 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1494 | SetRobustLengthParam(length, writeLength); |
| 1495 | SetRobustLengthParam(columns, writeColumns); |
| 1496 | SetRobustLengthParam(rows, writeRows); |
| 1497 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1498 | return true; |
| 1499 | } |
| 1500 | |
| 1501 | bool ValidateReadnPixelsEXT(Context *context, |
| 1502 | GLint x, |
| 1503 | GLint y, |
| 1504 | GLsizei width, |
| 1505 | GLsizei height, |
| 1506 | GLenum format, |
| 1507 | GLenum type, |
| 1508 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1509 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1510 | { |
| 1511 | if (bufSize < 0) |
| 1512 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1513 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1514 | return false; |
| 1515 | } |
| 1516 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1517 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1518 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1519 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1520 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1521 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1522 | GLint x, |
| 1523 | GLint y, |
| 1524 | GLsizei width, |
| 1525 | GLsizei height, |
| 1526 | GLenum format, |
| 1527 | GLenum type, |
| 1528 | GLsizei bufSize, |
| 1529 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1530 | GLsizei *columns, |
| 1531 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1532 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1533 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1534 | GLsizei writeLength = 0; |
| 1535 | GLsizei writeColumns = 0; |
| 1536 | GLsizei writeRows = 0; |
| 1537 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1538 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1539 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1540 | return false; |
| 1541 | } |
| 1542 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1543 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1544 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1545 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1546 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1547 | } |
| 1548 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1549 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1550 | { |
| 1551 | return false; |
| 1552 | } |
| 1553 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1554 | SetRobustLengthParam(length, writeLength); |
| 1555 | SetRobustLengthParam(columns, writeColumns); |
| 1556 | SetRobustLengthParam(rows, writeRows); |
| 1557 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1558 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1559 | } |
| 1560 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1561 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1562 | { |
| 1563 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1564 | !context->getExtensions().disjointTimerQuery) |
| 1565 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1566 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1567 | return false; |
| 1568 | } |
| 1569 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1570 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1571 | } |
| 1572 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1573 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1574 | { |
| 1575 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1576 | !context->getExtensions().disjointTimerQuery) |
| 1577 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1578 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
| 1581 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1582 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1583 | } |
| 1584 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1585 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1586 | { |
| 1587 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1588 | !context->getExtensions().disjointTimerQuery) |
| 1589 | { |
| 1590 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1591 | return false; |
| 1592 | } |
| 1593 | |
| 1594 | return true; |
| 1595 | } |
| 1596 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1597 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1598 | { |
| 1599 | if (!ValidQueryType(context, target)) |
| 1600 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1601 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1602 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | if (id == 0) |
| 1606 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1607 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1608 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1609 | } |
| 1610 | |
| 1611 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1612 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1613 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1614 | // the active query for either target is non-zero), if <id> is the name of an |
| 1615 | // existing query object whose type does not match <target>, or if <id> is the |
| 1616 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1617 | // generated. |
| 1618 | |
| 1619 | // Ensure no other queries are active |
| 1620 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1621 | // separately that: |
| 1622 | // a) The query ID passed is not the current active query for any target/type |
| 1623 | // b) There are no active queries for the requested target (and in the case |
| 1624 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1625 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1626 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1627 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1628 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1629 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1630 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1631 | } |
| 1632 | |
| 1633 | Query *queryObject = context->getQuery(id, true, target); |
| 1634 | |
| 1635 | // check that name was obtained with glGenQueries |
| 1636 | if (!queryObject) |
| 1637 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1638 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1639 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1640 | } |
| 1641 | |
| 1642 | // check for type mismatch |
| 1643 | if (queryObject->getType() != target) |
| 1644 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1645 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1646 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | return true; |
| 1650 | } |
| 1651 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1652 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1653 | { |
| 1654 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1655 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1656 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1657 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1658 | return false; |
| 1659 | } |
| 1660 | |
| 1661 | return ValidateBeginQueryBase(context, target, id); |
| 1662 | } |
| 1663 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1664 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1665 | { |
| 1666 | if (!ValidQueryType(context, target)) |
| 1667 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1668 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1669 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1670 | } |
| 1671 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1672 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1673 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1674 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1675 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1676 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1677 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1680 | return true; |
| 1681 | } |
| 1682 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1683 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1684 | { |
| 1685 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1686 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1687 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1688 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1689 | return false; |
| 1690 | } |
| 1691 | |
| 1692 | return ValidateEndQueryBase(context, target); |
| 1693 | } |
| 1694 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1695 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1696 | { |
| 1697 | if (!context->getExtensions().disjointTimerQuery) |
| 1698 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1699 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1700 | return false; |
| 1701 | } |
| 1702 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1703 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1704 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1705 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1706 | return false; |
| 1707 | } |
| 1708 | |
| 1709 | Query *queryObject = context->getQuery(id, true, target); |
| 1710 | if (queryObject == nullptr) |
| 1711 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1712 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1713 | return false; |
| 1714 | } |
| 1715 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1716 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1717 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1718 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1719 | return false; |
| 1720 | } |
| 1721 | |
| 1722 | return true; |
| 1723 | } |
| 1724 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1725 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1726 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1727 | if (numParams) |
| 1728 | { |
| 1729 | *numParams = 0; |
| 1730 | } |
| 1731 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1732 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1733 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1734 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1735 | return false; |
| 1736 | } |
| 1737 | |
| 1738 | switch (pname) |
| 1739 | { |
| 1740 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1741 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1742 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1743 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1744 | return false; |
| 1745 | } |
| 1746 | break; |
| 1747 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1748 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1749 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1750 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1751 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
| 1754 | break; |
| 1755 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1756 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1757 | return false; |
| 1758 | } |
| 1759 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1760 | if (numParams) |
| 1761 | { |
| 1762 | // All queries return only one value |
| 1763 | *numParams = 1; |
| 1764 | } |
| 1765 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1766 | return true; |
| 1767 | } |
| 1768 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1769 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1770 | { |
| 1771 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1772 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1773 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1774 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1778 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1779 | } |
| 1780 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1781 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1782 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1783 | GLenum pname, |
| 1784 | GLsizei bufSize, |
| 1785 | GLsizei *length, |
| 1786 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1787 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1788 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1789 | { |
| 1790 | return false; |
| 1791 | } |
| 1792 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1793 | GLsizei numParams = 0; |
| 1794 | |
| 1795 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1796 | { |
| 1797 | return false; |
| 1798 | } |
| 1799 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1800 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1801 | { |
| 1802 | return false; |
| 1803 | } |
| 1804 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1805 | SetRobustLengthParam(length, numParams); |
| 1806 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1807 | return true; |
| 1808 | } |
| 1809 | |
| 1810 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1811 | { |
| 1812 | if (numParams) |
| 1813 | { |
| 1814 | *numParams = 0; |
| 1815 | } |
| 1816 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1817 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1818 | |
| 1819 | if (!queryObject) |
| 1820 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1821 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1822 | return false; |
| 1823 | } |
| 1824 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1825 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1826 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1827 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1828 | return false; |
| 1829 | } |
| 1830 | |
| 1831 | switch (pname) |
| 1832 | { |
| 1833 | case GL_QUERY_RESULT_EXT: |
| 1834 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1835 | break; |
| 1836 | |
| 1837 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1838 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1839 | return false; |
| 1840 | } |
| 1841 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1842 | if (numParams) |
| 1843 | { |
| 1844 | *numParams = 1; |
| 1845 | } |
| 1846 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1847 | return true; |
| 1848 | } |
| 1849 | |
| 1850 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1851 | { |
| 1852 | if (!context->getExtensions().disjointTimerQuery) |
| 1853 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1854 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1855 | return false; |
| 1856 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1857 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1858 | } |
| 1859 | |
| 1860 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1861 | GLuint id, |
| 1862 | GLenum pname, |
| 1863 | GLsizei bufSize, |
| 1864 | GLsizei *length, |
| 1865 | GLint *params) |
| 1866 | { |
| 1867 | if (!context->getExtensions().disjointTimerQuery) |
| 1868 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1869 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1870 | return false; |
| 1871 | } |
| 1872 | |
| 1873 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1874 | { |
| 1875 | return false; |
| 1876 | } |
| 1877 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1878 | GLsizei numParams = 0; |
| 1879 | |
| 1880 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1881 | { |
| 1882 | return false; |
| 1883 | } |
| 1884 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1885 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1886 | { |
| 1887 | return false; |
| 1888 | } |
| 1889 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1890 | SetRobustLengthParam(length, numParams); |
| 1891 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1892 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1896 | { |
| 1897 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1898 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1899 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1900 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1901 | return false; |
| 1902 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1903 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1904 | } |
| 1905 | |
| 1906 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1907 | GLuint id, |
| 1908 | GLenum pname, |
| 1909 | GLsizei bufSize, |
| 1910 | GLsizei *length, |
| 1911 | GLuint *params) |
| 1912 | { |
| 1913 | if (!context->getExtensions().disjointTimerQuery && |
| 1914 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1915 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1916 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1917 | return false; |
| 1918 | } |
| 1919 | |
| 1920 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1921 | { |
| 1922 | return false; |
| 1923 | } |
| 1924 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1925 | GLsizei numParams = 0; |
| 1926 | |
| 1927 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1928 | { |
| 1929 | return false; |
| 1930 | } |
| 1931 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1932 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1933 | { |
| 1934 | return false; |
| 1935 | } |
| 1936 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1937 | SetRobustLengthParam(length, numParams); |
| 1938 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1939 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1940 | } |
| 1941 | |
| 1942 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1943 | { |
| 1944 | if (!context->getExtensions().disjointTimerQuery) |
| 1945 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1946 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1947 | return false; |
| 1948 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1949 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1950 | } |
| 1951 | |
| 1952 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1953 | GLuint id, |
| 1954 | GLenum pname, |
| 1955 | GLsizei bufSize, |
| 1956 | GLsizei *length, |
| 1957 | GLint64 *params) |
| 1958 | { |
| 1959 | if (!context->getExtensions().disjointTimerQuery) |
| 1960 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1961 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1962 | return false; |
| 1963 | } |
| 1964 | |
| 1965 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1966 | { |
| 1967 | return false; |
| 1968 | } |
| 1969 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1970 | GLsizei numParams = 0; |
| 1971 | |
| 1972 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1973 | { |
| 1974 | return false; |
| 1975 | } |
| 1976 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1977 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1978 | { |
| 1979 | return false; |
| 1980 | } |
| 1981 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1982 | SetRobustLengthParam(length, numParams); |
| 1983 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1984 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 1988 | { |
| 1989 | if (!context->getExtensions().disjointTimerQuery) |
| 1990 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1991 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1992 | return false; |
| 1993 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1994 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1995 | } |
| 1996 | |
| 1997 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 1998 | GLuint id, |
| 1999 | GLenum pname, |
| 2000 | GLsizei bufSize, |
| 2001 | GLsizei *length, |
| 2002 | GLuint64 *params) |
| 2003 | { |
| 2004 | if (!context->getExtensions().disjointTimerQuery) |
| 2005 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2006 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
| 2009 | |
| 2010 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2011 | { |
| 2012 | return false; |
| 2013 | } |
| 2014 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2015 | GLsizei numParams = 0; |
| 2016 | |
| 2017 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2018 | { |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2022 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2023 | { |
| 2024 | return false; |
| 2025 | } |
| 2026 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2027 | SetRobustLengthParam(length, numParams); |
| 2028 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2029 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2030 | } |
| 2031 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2032 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2033 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2034 | GLint location, |
| 2035 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2036 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2037 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2038 | // TODO(Jiajia): Add image uniform check in future. |
| 2039 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2040 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2041 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2042 | return false; |
| 2043 | } |
| 2044 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2045 | if (!program) |
| 2046 | { |
| 2047 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2048 | return false; |
| 2049 | } |
| 2050 | |
| 2051 | if (!program->isLinked()) |
| 2052 | { |
| 2053 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | if (location == -1) |
| 2058 | { |
| 2059 | // Silently ignore the uniform command |
| 2060 | return false; |
| 2061 | } |
| 2062 | |
| 2063 | const auto &uniformLocations = program->getUniformLocations(); |
| 2064 | size_t castedLocation = static_cast<size_t>(location); |
| 2065 | if (castedLocation >= uniformLocations.size()) |
| 2066 | { |
| 2067 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2068 | return false; |
| 2069 | } |
| 2070 | |
| 2071 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2072 | if (uniformLocation.ignored) |
| 2073 | { |
| 2074 | // Silently ignore the uniform command |
| 2075 | return false; |
| 2076 | } |
| 2077 | |
| 2078 | if (!uniformLocation.used()) |
| 2079 | { |
| 2080 | context->handleError(InvalidOperation()); |
| 2081 | return false; |
| 2082 | } |
| 2083 | |
| 2084 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2085 | |
| 2086 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
Jamie Madill | 2fc0806 | 2018-05-10 15:10:55 -0400 | [diff] [blame] | 2087 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2088 | { |
| 2089 | context->handleError(InvalidOperation()); |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | *uniformOut = &uniform; |
| 2094 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2095 | } |
| 2096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2097 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2098 | GLenum uniformType, |
| 2099 | GLsizei count, |
| 2100 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2101 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2102 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2103 | // It is compatible with INT or BOOL. |
| 2104 | // Do these cheap tests first, for a little extra speed. |
| 2105 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2106 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2107 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2108 | } |
| 2109 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2110 | if (IsSamplerType(uniformType)) |
| 2111 | { |
| 2112 | // Check that the values are in range. |
| 2113 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2114 | for (GLsizei i = 0; i < count; ++i) |
| 2115 | { |
| 2116 | if (value[i] < 0 || value[i] >= max) |
| 2117 | { |
| 2118 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2119 | return false; |
| 2120 | } |
| 2121 | } |
| 2122 | return true; |
| 2123 | } |
| 2124 | |
| 2125 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2126 | return false; |
| 2127 | } |
| 2128 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2129 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2130 | { |
| 2131 | // Check that the value type is compatible with uniform type. |
| 2132 | if (valueType == uniformType) |
| 2133 | { |
| 2134 | return true; |
| 2135 | } |
| 2136 | |
| 2137 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2138 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2141 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2142 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2143 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2144 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2145 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2146 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2147 | } |
| 2148 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2149 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2150 | { |
| 2151 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2152 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2153 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2154 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2155 | } |
| 2156 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2157 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2158 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2159 | GLint location, |
| 2160 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2161 | GLboolean transpose) |
| 2162 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2163 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2164 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2165 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2166 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2167 | } |
| 2168 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2169 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2170 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2171 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2172 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2173 | } |
| 2174 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2175 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2176 | { |
| 2177 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2178 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2179 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2180 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2181 | } |
| 2182 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2183 | const Caps &caps = context->getCaps(); |
| 2184 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2185 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2186 | { |
| 2187 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2188 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2189 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2190 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2191 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2192 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2193 | } |
| 2194 | } |
| 2195 | |
| 2196 | switch (pname) |
| 2197 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2198 | case GL_TEXTURE_BINDING_2D: |
| 2199 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2200 | case GL_TEXTURE_BINDING_3D: |
| 2201 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2202 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2203 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2204 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2205 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2206 | { |
| 2207 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 2208 | return false; |
| 2209 | } |
| 2210 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2211 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2212 | if (!context->getExtensions().textureRectangle) |
| 2213 | { |
| 2214 | context->handleError(InvalidEnum() |
| 2215 | << "ANGLE_texture_rectangle extension not present"); |
| 2216 | return false; |
| 2217 | } |
| 2218 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2219 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2220 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2221 | !context->getExtensions().eglImageExternal) |
| 2222 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2223 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2224 | "nor GL_OES_EGL_image_external " |
| 2225 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2226 | return false; |
| 2227 | } |
| 2228 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2229 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2230 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2231 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2232 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2233 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2234 | ASSERT(readFramebuffer); |
| 2235 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2236 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2237 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2238 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2239 | } |
| 2240 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2241 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2242 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2243 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2244 | return false; |
| 2245 | } |
| 2246 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2247 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2248 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2249 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2250 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2251 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2252 | } |
| 2253 | } |
| 2254 | break; |
| 2255 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2256 | default: |
| 2257 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2258 | } |
| 2259 | |
| 2260 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2261 | if (*numParams == 0) |
| 2262 | { |
| 2263 | return false; |
| 2264 | } |
| 2265 | |
| 2266 | return true; |
| 2267 | } |
| 2268 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2269 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2270 | GLenum pname, |
| 2271 | GLsizei bufSize, |
| 2272 | GLsizei *length, |
| 2273 | GLboolean *params) |
| 2274 | { |
| 2275 | GLenum nativeType; |
| 2276 | unsigned int numParams = 0; |
| 2277 | |
| 2278 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2279 | { |
| 2280 | return false; |
| 2281 | } |
| 2282 | |
| 2283 | SetRobustLengthParam(length, numParams); |
| 2284 | |
| 2285 | return true; |
| 2286 | } |
| 2287 | |
| 2288 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2289 | GLenum pname, |
| 2290 | GLsizei bufSize, |
| 2291 | GLsizei *length, |
| 2292 | GLfloat *params) |
| 2293 | { |
| 2294 | GLenum nativeType; |
| 2295 | unsigned int numParams = 0; |
| 2296 | |
| 2297 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2298 | { |
| 2299 | return false; |
| 2300 | } |
| 2301 | |
| 2302 | SetRobustLengthParam(length, numParams); |
| 2303 | |
| 2304 | return true; |
| 2305 | } |
| 2306 | |
| 2307 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2308 | GLenum pname, |
| 2309 | GLsizei bufSize, |
| 2310 | GLsizei *length, |
| 2311 | GLint *data) |
| 2312 | { |
| 2313 | GLenum nativeType; |
| 2314 | unsigned int numParams = 0; |
| 2315 | |
| 2316 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2317 | { |
| 2318 | return false; |
| 2319 | } |
| 2320 | |
| 2321 | SetRobustLengthParam(length, numParams); |
| 2322 | |
| 2323 | return true; |
| 2324 | } |
| 2325 | |
| 2326 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2327 | GLenum pname, |
| 2328 | GLsizei bufSize, |
| 2329 | GLsizei *length, |
| 2330 | GLint64 *data) |
| 2331 | { |
| 2332 | GLenum nativeType; |
| 2333 | unsigned int numParams = 0; |
| 2334 | |
| 2335 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2336 | { |
| 2337 | return false; |
| 2338 | } |
| 2339 | |
| 2340 | if (nativeType == GL_INT_64_ANGLEX) |
| 2341 | { |
| 2342 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2343 | return false; |
| 2344 | } |
| 2345 | |
| 2346 | SetRobustLengthParam(length, numParams); |
| 2347 | return true; |
| 2348 | } |
| 2349 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2350 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2351 | GLenum pname, |
| 2352 | GLsizei bufSize, |
| 2353 | GLenum *nativeType, |
| 2354 | unsigned int *numParams) |
| 2355 | { |
| 2356 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2357 | { |
| 2358 | return false; |
| 2359 | } |
| 2360 | |
| 2361 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2362 | { |
| 2363 | return false; |
| 2364 | } |
| 2365 | |
| 2366 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2367 | { |
| 2368 | return false; |
| 2369 | } |
| 2370 | |
| 2371 | return true; |
| 2372 | } |
| 2373 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2374 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2375 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2376 | GLint level, |
| 2377 | GLenum internalformat, |
| 2378 | bool isSubImage, |
| 2379 | GLint xoffset, |
| 2380 | GLint yoffset, |
| 2381 | GLint zoffset, |
| 2382 | GLint x, |
| 2383 | GLint y, |
| 2384 | GLsizei width, |
| 2385 | GLsizei height, |
| 2386 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2387 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2388 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2389 | TextureType texType = TextureTargetToType(target); |
| 2390 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2391 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2392 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2393 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2394 | return false; |
| 2395 | } |
| 2396 | |
| 2397 | if (width < 0 || height < 0) |
| 2398 | { |
| 2399 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2400 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2403 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2404 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2405 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2406 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2407 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2408 | } |
| 2409 | |
| 2410 | if (border != 0) |
| 2411 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2412 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2413 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2414 | } |
| 2415 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2416 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2417 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2418 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2419 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2420 | } |
| 2421 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2422 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2423 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2424 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2425 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2426 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2427 | } |
| 2428 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2429 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2430 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2431 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2432 | } |
| 2433 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2434 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2435 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2436 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2437 | return false; |
| 2438 | } |
| 2439 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2440 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2441 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2442 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2443 | // situation is an application error that would lead to a crash in ANGLE. |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2444 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2445 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2446 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2447 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2448 | return false; |
| 2449 | } |
| 2450 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2451 | // ANGLE_multiview spec, Revision 1: |
| 2452 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2453 | // INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the current read framebuffer |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2454 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2455 | // framebuffer is more than one. |
| 2456 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2457 | { |
| 2458 | context->handleError(InvalidFramebufferOperation() |
| 2459 | << "The active read framebuffer object has multiview attachments."); |
| 2460 | return false; |
| 2461 | } |
| 2462 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2463 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2464 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2465 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2466 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2467 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2468 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2469 | maxDimension = caps.max2DTextureSize; |
| 2470 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2471 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2472 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2473 | maxDimension = caps.maxCubeMapTextureSize; |
| 2474 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2475 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2476 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2477 | maxDimension = caps.maxRectangleTextureSize; |
| 2478 | break; |
| 2479 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2480 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2481 | maxDimension = caps.max2DTextureSize; |
| 2482 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2483 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2484 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2485 | maxDimension = caps.max3DTextureSize; |
| 2486 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2487 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2488 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2489 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2490 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2491 | } |
| 2492 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2493 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2494 | if (!texture) |
| 2495 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2496 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2497 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2498 | } |
| 2499 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2500 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2501 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2502 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2503 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2504 | } |
| 2505 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2506 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2507 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2508 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2509 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2510 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2511 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2512 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2513 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
| 2516 | if (isSubImage) |
| 2517 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2518 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2519 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2520 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2521 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2522 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2523 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2524 | } |
| 2525 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2526 | else |
| 2527 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2528 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2529 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2530 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2531 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2532 | } |
| 2533 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2534 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2535 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2536 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2537 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2538 | } |
| 2539 | |
| 2540 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2541 | if (static_cast<int>(width) > maxLevelDimension || |
| 2542 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2543 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2544 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2545 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2546 | } |
| 2547 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2548 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2549 | if (textureFormatOut) |
| 2550 | { |
| 2551 | *textureFormatOut = texture->getFormat(target, level); |
| 2552 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2553 | |
| 2554 | // Detect texture copying feedback loops for WebGL. |
| 2555 | if (context->getExtensions().webglCompatibility) |
| 2556 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2557 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2558 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2559 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2560 | return false; |
| 2561 | } |
| 2562 | } |
| 2563 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2564 | return true; |
| 2565 | } |
| 2566 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2567 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2568 | // completeness check. |
| 2569 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2570 | { |
| 2571 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2572 | const State &state = context->getGLState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2573 | |
| 2574 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2575 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2576 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2577 | VertexArray *vertexArray = state.getVertexArray(); |
| 2578 | ASSERT(vertexArray); |
| 2579 | |
| 2580 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2581 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2582 | return kErrorBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2583 | } |
| 2584 | |
| 2585 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2586 | // Section 6.10 of the WebGL 1.0 spec. |
| 2587 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2588 | ASSERT(framebuffer); |
| 2589 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2590 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2591 | { |
| 2592 | ASSERT(framebuffer); |
| 2593 | const FramebufferAttachment *dsAttachment = |
| 2594 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2595 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2596 | ASSERT(stencilBits <= 8); |
| 2597 | |
| 2598 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2599 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2600 | { |
| 2601 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2602 | |
| 2603 | bool differentRefs = |
| 2604 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2605 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2606 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2607 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2608 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2609 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2610 | |
| 2611 | if (differentRefs || differentWritemasks || differentMasks) |
| 2612 | { |
| 2613 | if (!extensions.webglCompatibility) |
| 2614 | { |
| 2615 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2616 | "stencil writemasks, reference values, or stencil mask values."; |
| 2617 | } |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2618 | return kErrorStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2619 | } |
| 2620 | } |
| 2621 | } |
| 2622 | |
| 2623 | if (!framebuffer->isComplete(context)) |
| 2624 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2625 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
| 2626 | return kErrorDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2630 | { |
| 2631 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2632 | { |
| 2633 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2634 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2635 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2636 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2637 | return kErrorVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2638 | } |
| 2639 | |
| 2640 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2641 | { |
| 2642 | // This is an application error that would normally result in a crash, but we catch it |
| 2643 | // and return an error |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2644 | return kErrorVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2645 | } |
| 2646 | } |
| 2647 | |
| 2648 | // If we are running GLES1, there is no current program. |
| 2649 | if (context->getClientVersion() >= Version(2, 0)) |
| 2650 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2651 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2652 | if (!program) |
| 2653 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2654 | return kErrorProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2658 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2659 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2660 | // produce undefined result. |
| 2661 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2662 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2663 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2664 | return kErrorNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2668 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2669 | return kErrorTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | if (extensions.multiview) |
| 2673 | { |
| 2674 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2675 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2676 | if (framebufferNumViews != programNumViews) |
| 2677 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2678 | return kErrorMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2682 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2683 | framebufferNumViews > 1) |
| 2684 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2685 | return kErrorMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2689 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2690 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2691 | return kErrorMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2692 | } |
| 2693 | } |
| 2694 | |
| 2695 | // Uniform buffer validation |
| 2696 | for (unsigned int uniformBlockIndex = 0; |
| 2697 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2698 | { |
| 2699 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2700 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2701 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2702 | state.getIndexedUniformBuffer(blockBinding); |
| 2703 | |
| 2704 | if (uniformBuffer.get() == nullptr) |
| 2705 | { |
| 2706 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2707 | return kErrorUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2708 | } |
| 2709 | |
| 2710 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2711 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2712 | { |
| 2713 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2714 | return kErrorUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2715 | } |
| 2716 | |
| 2717 | if (extensions.webglCompatibility && |
| 2718 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2719 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2720 | return kErrorUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2721 | } |
| 2722 | } |
| 2723 | |
| 2724 | // Do some additonal WebGL-specific validation |
| 2725 | if (extensions.webglCompatibility) |
| 2726 | { |
| 2727 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2728 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2729 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2730 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2731 | return kErrorTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | // Detect rendering feedback loops for WebGL. |
| 2735 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2736 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2737 | return kErrorFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | // Detect that the vertex shader input types match the attribute types |
| 2741 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2742 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2743 | return kErrorVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | // Detect that the color buffer types match the fragment shader output types |
| 2747 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2748 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2749 | return kErrorDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2750 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2751 | |
| 2752 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2753 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2754 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2755 | return kErrorVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2756 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2757 | } |
| 2758 | } |
| 2759 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2760 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2761 | } |
| 2762 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2763 | bool ValidateDrawMode(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2764 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2765 | const Extensions &extensions = context->getExtensions(); |
| 2766 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2767 | switch (mode) |
| 2768 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2769 | case PrimitiveMode::Points: |
| 2770 | case PrimitiveMode::Lines: |
| 2771 | case PrimitiveMode::LineLoop: |
| 2772 | case PrimitiveMode::LineStrip: |
| 2773 | case PrimitiveMode::Triangles: |
| 2774 | case PrimitiveMode::TriangleStrip: |
| 2775 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2776 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2777 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2778 | case PrimitiveMode::LinesAdjacency: |
| 2779 | case PrimitiveMode::LineStripAdjacency: |
| 2780 | case PrimitiveMode::TrianglesAdjacency: |
| 2781 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2782 | if (!extensions.geometryShader) |
| 2783 | { |
| 2784 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2785 | return false; |
| 2786 | } |
| 2787 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2788 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2789 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2790 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2791 | } |
| 2792 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2793 | // If we are running GLES1, there is no current program. |
| 2794 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2795 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2796 | const State &state = context->getGLState(); |
| 2797 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2798 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2799 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2800 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2801 | // Do geometry shader specific validations |
| 2802 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2803 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2804 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2805 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2806 | { |
| 2807 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2808 | IncompatibleDrawModeAgainstGeometryShader); |
| 2809 | return false; |
| 2810 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2811 | } |
| 2812 | } |
| 2813 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2814 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2815 | } |
| 2816 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2817 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
| 2818 | { |
| 2819 | if (!context->getStateCache().isValidDrawMode(mode)) |
| 2820 | { |
| 2821 | return ValidateDrawMode(context, mode); |
| 2822 | } |
| 2823 | |
| 2824 | if (count < 0) |
| 2825 | { |
| 2826 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 2827 | return false; |
| 2828 | } |
| 2829 | |
| 2830 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2831 | if (drawStatesError) |
| 2832 | { |
| 2833 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2834 | |
| 2835 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2836 | // Incomplete. |
| 2837 | GLenum errorCode = |
| 2838 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2839 | : GL_INVALID_OPERATION); |
| 2840 | context->handleError(Error(errorCode, errorMessage)); |
| 2841 | return false; |
| 2842 | } |
| 2843 | |
| 2844 | return true; |
| 2845 | } |
| 2846 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2847 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2848 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2849 | GLint first, |
| 2850 | GLsizei count, |
| 2851 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2852 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2853 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2854 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2855 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2856 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2857 | } |
| 2858 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2859 | if (count < 0) |
| 2860 | { |
| 2861 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 2862 | return false; |
| 2863 | } |
| 2864 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2865 | const State &state = context->getGLState(); |
| 2866 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2867 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2868 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2869 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2870 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2871 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2872 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2873 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2874 | return false; |
| 2875 | } |
| 2876 | |
| 2877 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2878 | { |
| 2879 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2880 | return false; |
| 2881 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2882 | } |
| 2883 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2884 | if (!context->getStateCache().isValidDrawMode(mode)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2885 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2886 | return ValidateDrawMode(context, mode); |
| 2887 | } |
| 2888 | |
| 2889 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2890 | if (drawStatesError) |
| 2891 | { |
| 2892 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2893 | |
| 2894 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2895 | // Incomplete. |
| 2896 | GLenum errorCode = |
| 2897 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2898 | : GL_INVALID_OPERATION); |
| 2899 | context->handleError(Error(errorCode, errorMessage)); |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2900 | return false; |
| 2901 | } |
| 2902 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2903 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2904 | // - first < 0 has been checked as an error condition. |
| 2905 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2906 | // From this we know maxVertex will be positive, and only need to check if it overflows GLint. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2907 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2908 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2909 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2910 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2911 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2912 | { |
| 2913 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2914 | return false; |
| 2915 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2916 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2917 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2918 | { |
| 2919 | return false; |
| 2920 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | return true; |
| 2924 | } |
| 2925 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2926 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2927 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2928 | GLint first, |
| 2929 | GLsizei count, |
| 2930 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2931 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2932 | if (!context->getExtensions().instancedArrays) |
| 2933 | { |
| 2934 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2935 | return false; |
| 2936 | } |
| 2937 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2938 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2939 | { |
| 2940 | return false; |
| 2941 | } |
| 2942 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2943 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2944 | } |
| 2945 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2946 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2947 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2948 | switch (type) |
| 2949 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2950 | case GL_UNSIGNED_BYTE: |
| 2951 | case GL_UNSIGNED_SHORT: |
| 2952 | break; |
| 2953 | case GL_UNSIGNED_INT: |
| 2954 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2955 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2956 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2957 | return false; |
| 2958 | } |
| 2959 | break; |
| 2960 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2961 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2962 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2963 | } |
| 2964 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2965 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2966 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2967 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2968 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2969 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2970 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2971 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2972 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2973 | if (context->getExtensions().geometryShader) |
| 2974 | { |
| 2975 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2976 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2977 | { |
| 2978 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2979 | return false; |
| 2980 | } |
| 2981 | } |
| 2982 | else |
| 2983 | { |
| 2984 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2985 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2986 | // 86) |
| 2987 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2988 | UnsupportedDrawModeForTransformFeedback); |
| 2989 | return false; |
| 2990 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2991 | } |
| 2992 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2993 | return true; |
| 2994 | } |
| 2995 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2996 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2997 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2998 | GLsizei count, |
| 2999 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3000 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3001 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3002 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3003 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3004 | return false; |
| 3005 | |
| 3006 | const State &state = context->getGLState(); |
| 3007 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3008 | if (!ValidateDrawBase(context, mode, count)) |
| 3009 | { |
| 3010 | return false; |
| 3011 | } |
| 3012 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3013 | const VertexArray *vao = state.getVertexArray(); |
| 3014 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3015 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3016 | GLuint typeBytes = GetTypeInfo(type).bytes; |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3017 | |
| 3018 | if (context->getExtensions().webglCompatibility) |
| 3019 | { |
| 3020 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3021 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3022 | { |
| 3023 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3024 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3025 | // data type passed to the call, or an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3026 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3027 | return false; |
| 3028 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3029 | |
| 3030 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3031 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3032 | // error is generated. |
| 3033 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3034 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3035 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3036 | return false; |
| 3037 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3038 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3039 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 3040 | { |
| 3041 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3042 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3043 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3044 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3045 | return false; |
| 3046 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3047 | |
| 3048 | if (context->getExtensions().webglCompatibility || |
| 3049 | !context->getGLState().areClientArraysEnabled()) |
| 3050 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3051 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3052 | { |
| 3053 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3054 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3055 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3056 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3057 | return false; |
| 3058 | } |
| 3059 | } |
| 3060 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3061 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3062 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3063 | // This is an application error that would normally result in a crash, but we catch it and |
| 3064 | // return an error |
| 3065 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3066 | return false; |
| 3067 | } |
| 3068 | |
| 3069 | if (count > 0 && elementArrayBuffer) |
| 3070 | { |
| 3071 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3072 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3073 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3074 | constexpr uint64_t kMaxTypeSize = 8; |
| 3075 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3076 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3077 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3078 | |
| 3079 | uint64_t typeSize = typeBytes; |
| 3080 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3081 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3082 | |
| 3083 | // Doing the multiplication here is overflow-safe |
| 3084 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3085 | |
| 3086 | // The offset can be any value, check for overflows |
| 3087 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3088 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3089 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3090 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3091 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3092 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3093 | |
| 3094 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3095 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3096 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3097 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3098 | return false; |
| 3099 | } |
| 3100 | |
| 3101 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3102 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3103 | { |
| 3104 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3105 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3106 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3107 | |
| 3108 | if (context->getExtensions().webglCompatibility && |
| 3109 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3110 | { |
| 3111 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3112 | ElementArrayBufferBoundForTransformFeedback); |
| 3113 | return false; |
| 3114 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3117 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3118 | { |
| 3119 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3120 | const DrawCallParams ¶ms = context->getParams<DrawCallParams>(); |
| 3121 | ANGLE_VALIDATION_TRY(params.ensureIndexRangeResolved(context)); |
| 3122 | const IndexRange &indexRange = params.getIndexRange(); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3123 | |
| 3124 | // If we use an index greater than our maximum supported index range, return an error. |
| 3125 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3126 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3127 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3128 | { |
| 3129 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3130 | return false; |
| 3131 | } |
| 3132 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3133 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3134 | { |
| 3135 | return false; |
| 3136 | } |
| 3137 | |
| 3138 | // No op if there are no real indices in the index data (all are primitive restart). |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3139 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3140 | } |
| 3141 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3142 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3145 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3146 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3147 | GLsizei count, |
| 3148 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3149 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3150 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3151 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3152 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3153 | } |
| 3154 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3155 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3156 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3157 | GLsizei count, |
| 3158 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3159 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3160 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3161 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3162 | if (!context->getExtensions().instancedArrays) |
| 3163 | { |
| 3164 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3165 | return false; |
| 3166 | } |
| 3167 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3168 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3169 | { |
| 3170 | return false; |
| 3171 | } |
| 3172 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3173 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3174 | } |
| 3175 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3176 | bool ValidateFramebufferTextureBase(Context *context, |
| 3177 | GLenum target, |
| 3178 | GLenum attachment, |
| 3179 | GLuint texture, |
| 3180 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3181 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3182 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3183 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3184 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3185 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3189 | { |
| 3190 | return false; |
| 3191 | } |
| 3192 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3193 | if (texture != 0) |
| 3194 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3195 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3196 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3197 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3198 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3199 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3200 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | if (level < 0) |
| 3204 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3205 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3206 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3207 | } |
| 3208 | } |
| 3209 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3210 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3211 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3212 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3213 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3214 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3215 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3216 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | return true; |
| 3220 | } |
| 3221 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3222 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3223 | { |
| 3224 | if (program == 0) |
| 3225 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3226 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3227 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3228 | } |
| 3229 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3230 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3231 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3232 | { |
| 3233 | return false; |
| 3234 | } |
| 3235 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3236 | if (!programObject || !programObject->isLinked()) |
| 3237 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3238 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3239 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3240 | } |
| 3241 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3242 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3243 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3244 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3245 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3246 | } |
| 3247 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3248 | return true; |
| 3249 | } |
| 3250 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3251 | static bool ValidateSizedGetUniform(Context *context, |
| 3252 | GLuint program, |
| 3253 | GLint location, |
| 3254 | GLsizei bufSize, |
| 3255 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3256 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3257 | if (length) |
| 3258 | { |
| 3259 | *length = 0; |
| 3260 | } |
| 3261 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3262 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3263 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3264 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3265 | } |
| 3266 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3267 | if (bufSize < 0) |
| 3268 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3269 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3270 | return false; |
| 3271 | } |
| 3272 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3273 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3274 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3275 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3276 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3277 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3278 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3279 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3280 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3281 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3282 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3283 | } |
| 3284 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3285 | if (length) |
| 3286 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3287 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3288 | } |
| 3289 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3290 | return true; |
| 3291 | } |
| 3292 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3293 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3294 | GLuint program, |
| 3295 | GLint location, |
| 3296 | GLsizei bufSize, |
| 3297 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3298 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3299 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3302 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3303 | GLuint program, |
| 3304 | GLint location, |
| 3305 | GLsizei bufSize, |
| 3306 | GLsizei *length, |
| 3307 | GLfloat *params) |
| 3308 | { |
| 3309 | UNIMPLEMENTED(); |
| 3310 | return false; |
| 3311 | } |
| 3312 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3313 | bool ValidateGetnUniformivEXT(Context *context, |
| 3314 | GLuint program, |
| 3315 | GLint location, |
| 3316 | GLsizei bufSize, |
| 3317 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3318 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3319 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3320 | } |
| 3321 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3322 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3323 | GLuint program, |
| 3324 | GLint location, |
| 3325 | GLsizei bufSize, |
| 3326 | GLsizei *length, |
| 3327 | GLint *params) |
| 3328 | { |
| 3329 | UNIMPLEMENTED(); |
| 3330 | return false; |
| 3331 | } |
| 3332 | |
| 3333 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3334 | GLuint program, |
| 3335 | GLint location, |
| 3336 | GLsizei bufSize, |
| 3337 | GLsizei *length, |
| 3338 | GLuint *params) |
| 3339 | { |
| 3340 | UNIMPLEMENTED(); |
| 3341 | return false; |
| 3342 | } |
| 3343 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3344 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3345 | GLuint program, |
| 3346 | GLint location, |
| 3347 | GLsizei bufSize, |
| 3348 | GLsizei *length, |
| 3349 | GLfloat *params) |
| 3350 | { |
| 3351 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3352 | { |
| 3353 | return false; |
| 3354 | } |
| 3355 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3356 | GLsizei writeLength = 0; |
| 3357 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3358 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3359 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3360 | { |
| 3361 | return false; |
| 3362 | } |
| 3363 | |
| 3364 | SetRobustLengthParam(length, writeLength); |
| 3365 | |
| 3366 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3367 | } |
| 3368 | |
| 3369 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3370 | GLuint program, |
| 3371 | GLint location, |
| 3372 | GLsizei bufSize, |
| 3373 | GLsizei *length, |
| 3374 | GLint *params) |
| 3375 | { |
| 3376 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3377 | { |
| 3378 | return false; |
| 3379 | } |
| 3380 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3381 | GLsizei writeLength = 0; |
| 3382 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3383 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3384 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3385 | { |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
| 3389 | SetRobustLengthParam(length, writeLength); |
| 3390 | |
| 3391 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3392 | } |
| 3393 | |
| 3394 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3395 | GLuint program, |
| 3396 | GLint location, |
| 3397 | GLsizei bufSize, |
| 3398 | GLsizei *length, |
| 3399 | GLuint *params) |
| 3400 | { |
| 3401 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3402 | { |
| 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | if (context->getClientMajorVersion() < 3) |
| 3407 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3408 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3409 | return false; |
| 3410 | } |
| 3411 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3412 | GLsizei writeLength = 0; |
| 3413 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3414 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3415 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3416 | { |
| 3417 | return false; |
| 3418 | } |
| 3419 | |
| 3420 | SetRobustLengthParam(length, writeLength); |
| 3421 | |
| 3422 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3423 | } |
| 3424 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3425 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3426 | GLenum target, |
| 3427 | GLsizei numAttachments, |
| 3428 | const GLenum *attachments, |
| 3429 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3430 | { |
| 3431 | if (numAttachments < 0) |
| 3432 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3433 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3434 | return false; |
| 3435 | } |
| 3436 | |
| 3437 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3438 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3439 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3440 | { |
| 3441 | if (defaultFramebuffer) |
| 3442 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3443 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3444 | return false; |
| 3445 | } |
| 3446 | |
| 3447 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3448 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3449 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3450 | "greater than the maximum supported " |
| 3451 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3452 | return false; |
| 3453 | } |
| 3454 | } |
| 3455 | else |
| 3456 | { |
| 3457 | switch (attachments[i]) |
| 3458 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3459 | case GL_DEPTH_ATTACHMENT: |
| 3460 | case GL_STENCIL_ATTACHMENT: |
| 3461 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3462 | if (defaultFramebuffer) |
| 3463 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3464 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3465 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3466 | return false; |
| 3467 | } |
| 3468 | break; |
| 3469 | case GL_COLOR: |
| 3470 | case GL_DEPTH: |
| 3471 | case GL_STENCIL: |
| 3472 | if (!defaultFramebuffer) |
| 3473 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3474 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3475 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3476 | return false; |
| 3477 | } |
| 3478 | break; |
| 3479 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3480 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3481 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3482 | } |
| 3483 | } |
| 3484 | } |
| 3485 | |
| 3486 | return true; |
| 3487 | } |
| 3488 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3489 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3490 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3491 | if (!context->getExtensions().debugMarker) |
| 3492 | { |
| 3493 | // The debug marker calls should not set error state |
| 3494 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3495 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3496 | return false; |
| 3497 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3498 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3499 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3500 | if (length < 0) |
| 3501 | { |
| 3502 | return false; |
| 3503 | } |
| 3504 | |
| 3505 | if (marker == nullptr) |
| 3506 | { |
| 3507 | return false; |
| 3508 | } |
| 3509 | |
| 3510 | return true; |
| 3511 | } |
| 3512 | |
| 3513 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3514 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3515 | if (!context->getExtensions().debugMarker) |
| 3516 | { |
| 3517 | // The debug marker calls should not set error state |
| 3518 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3519 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3520 | return false; |
| 3521 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3522 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3523 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3524 | if (length < 0) |
| 3525 | { |
| 3526 | return false; |
| 3527 | } |
| 3528 | |
| 3529 | if (length > 0 && marker == nullptr) |
| 3530 | { |
| 3531 | return false; |
| 3532 | } |
| 3533 | |
| 3534 | return true; |
| 3535 | } |
| 3536 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3537 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3538 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3539 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3540 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3541 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3542 | return false; |
| 3543 | } |
| 3544 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3545 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3546 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3547 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3548 | if (!context->getExtensions().eglImage) |
| 3549 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3550 | context->handleError(InvalidEnum() |
| 3551 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3552 | } |
| 3553 | break; |
| 3554 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3555 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3556 | if (!context->getExtensions().eglImageExternal) |
| 3557 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3558 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3559 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3560 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3561 | break; |
| 3562 | |
| 3563 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3564 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3565 | return false; |
| 3566 | } |
| 3567 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3568 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3569 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3570 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3571 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3572 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3573 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3574 | return false; |
| 3575 | } |
| 3576 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3577 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3578 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3579 | context->handleError(InvalidOperation() |
| 3580 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3584 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3585 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3586 | context->handleError(InvalidOperation() |
| 3587 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3588 | return false; |
| 3589 | } |
| 3590 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3591 | return true; |
| 3592 | } |
| 3593 | |
| 3594 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3595 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3596 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3597 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3598 | if (!context->getExtensions().eglImage) |
| 3599 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3600 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3601 | return false; |
| 3602 | } |
| 3603 | |
| 3604 | switch (target) |
| 3605 | { |
| 3606 | case GL_RENDERBUFFER: |
| 3607 | break; |
| 3608 | |
| 3609 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3610 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3611 | return false; |
| 3612 | } |
| 3613 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3614 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3615 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3616 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3617 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3618 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3619 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3620 | return false; |
| 3621 | } |
| 3622 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3623 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3624 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3625 | context->handleError(InvalidOperation() |
| 3626 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3627 | return false; |
| 3628 | } |
| 3629 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3630 | return true; |
| 3631 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3632 | |
| 3633 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3634 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3635 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3636 | { |
| 3637 | // The default VAO should always exist |
| 3638 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3639 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3640 | return false; |
| 3641 | } |
| 3642 | |
| 3643 | return true; |
| 3644 | } |
| 3645 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3646 | bool ValidateProgramBinaryBase(Context *context, |
| 3647 | GLuint program, |
| 3648 | GLenum binaryFormat, |
| 3649 | const void *binary, |
| 3650 | GLint length) |
| 3651 | { |
| 3652 | Program *programObject = GetValidProgram(context, program); |
| 3653 | if (programObject == nullptr) |
| 3654 | { |
| 3655 | return false; |
| 3656 | } |
| 3657 | |
| 3658 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3659 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3660 | programBinaryFormats.end()) |
| 3661 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3662 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3663 | return false; |
| 3664 | } |
| 3665 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3666 | if (context->hasActiveTransformFeedback(program)) |
| 3667 | { |
| 3668 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3669 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3670 | "is associated with an active transform " |
| 3671 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3672 | return false; |
| 3673 | } |
| 3674 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3675 | return true; |
| 3676 | } |
| 3677 | |
| 3678 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3679 | GLuint program, |
| 3680 | GLsizei bufSize, |
| 3681 | GLsizei *length, |
| 3682 | GLenum *binaryFormat, |
| 3683 | void *binary) |
| 3684 | { |
| 3685 | Program *programObject = GetValidProgram(context, program); |
| 3686 | if (programObject == nullptr) |
| 3687 | { |
| 3688 | return false; |
| 3689 | } |
| 3690 | |
| 3691 | if (!programObject->isLinked()) |
| 3692 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3693 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3694 | return false; |
| 3695 | } |
| 3696 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3697 | if (context->getCaps().programBinaryFormats.empty()) |
| 3698 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3699 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3700 | return false; |
| 3701 | } |
| 3702 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3703 | return true; |
| 3704 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3705 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3706 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3707 | { |
| 3708 | // INVALID_VALUE is generated if n is negative or greater than value of MAX_DRAW_BUFFERS |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3709 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3710 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3711 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3712 | return false; |
| 3713 | } |
| 3714 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3715 | { |
| 3716 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3717 | return false; |
| 3718 | } |
| 3719 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3720 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3721 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3722 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3723 | |
| 3724 | // This should come first before the check for the default frame buffer |
| 3725 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3726 | // rather than INVALID_OPERATION |
| 3727 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3728 | { |
| 3729 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3730 | |
| 3731 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3732 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3733 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3734 | { |
| 3735 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3736 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3737 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3738 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3739 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3740 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3741 | return false; |
| 3742 | } |
| 3743 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3744 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3745 | context->handleError(InvalidOperation() |
| 3746 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3747 | return false; |
| 3748 | } |
| 3749 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3750 | frameBufferId != 0) |
| 3751 | { |
| 3752 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3753 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3754 | context->handleError(InvalidOperation() |
| 3755 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3756 | return false; |
| 3757 | } |
| 3758 | } |
| 3759 | |
| 3760 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3761 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3762 | if (frameBufferId == 0) |
| 3763 | { |
| 3764 | if (n != 1) |
| 3765 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3766 | context->handleError(InvalidOperation() |
| 3767 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | |
| 3771 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3772 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3773 | context->handleError( |
| 3774 | InvalidOperation() |
| 3775 | << "Only NONE or BACK are valid values when drawing to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3776 | return false; |
| 3777 | } |
| 3778 | } |
| 3779 | |
| 3780 | return true; |
| 3781 | } |
| 3782 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3783 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3784 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3785 | GLenum pname, |
| 3786 | GLsizei *length, |
| 3787 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3788 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3789 | if (length) |
| 3790 | { |
| 3791 | *length = 0; |
| 3792 | } |
| 3793 | |
| 3794 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3795 | { |
| 3796 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3797 | InvalidOperation() |
| 3798 | << "Context does not support OpenGL ES 3.0 or GL_OES_mapbuffer is not enabled."); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3799 | return false; |
| 3800 | } |
| 3801 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3802 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3803 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3804 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3805 | return false; |
| 3806 | } |
| 3807 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3808 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3809 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3810 | case GL_BUFFER_MAP_POINTER: |
| 3811 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3812 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3813 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3814 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3815 | return false; |
| 3816 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3817 | |
| 3818 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3819 | // target bound to zero generate an INVALID_OPERATION error." |
| 3820 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3821 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3822 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3823 | context->handleError(InvalidOperation() |
| 3824 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3828 | if (length) |
| 3829 | { |
| 3830 | *length = 1; |
| 3831 | } |
| 3832 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3833 | return true; |
| 3834 | } |
| 3835 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3836 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3837 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3838 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3839 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3840 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3841 | return false; |
| 3842 | } |
| 3843 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3844 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3845 | |
| 3846 | if (buffer == nullptr || !buffer->isMapped()) |
| 3847 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3848 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3849 | return false; |
| 3850 | } |
| 3851 | |
| 3852 | return true; |
| 3853 | } |
| 3854 | |
| 3855 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3856 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3857 | GLintptr offset, |
| 3858 | GLsizeiptr length, |
| 3859 | GLbitfield access) |
| 3860 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3861 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3862 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3863 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3864 | return false; |
| 3865 | } |
| 3866 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3867 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3868 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3869 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3870 | return false; |
| 3871 | } |
| 3872 | |
| 3873 | if (length < 0) |
| 3874 | { |
| 3875 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3879 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3880 | |
| 3881 | if (!buffer) |
| 3882 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3883 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3884 | return false; |
| 3885 | } |
| 3886 | |
| 3887 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3888 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3889 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3890 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3891 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3892 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3893 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3894 | return false; |
| 3895 | } |
| 3896 | |
| 3897 | // Check for invalid bits in the mask |
| 3898 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3899 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3900 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3901 | |
| 3902 | if (access & ~(allAccessBits)) |
| 3903 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3904 | context->handleError(InvalidValue() |
| 3905 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3906 | return false; |
| 3907 | } |
| 3908 | |
| 3909 | if (length == 0) |
| 3910 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3911 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3912 | return false; |
| 3913 | } |
| 3914 | |
| 3915 | if (buffer->isMapped()) |
| 3916 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3917 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3918 | return false; |
| 3919 | } |
| 3920 | |
| 3921 | // Check for invalid bit combinations |
| 3922 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3923 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3924 | context->handleError(InvalidOperation() |
| 3925 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3926 | return false; |
| 3927 | } |
| 3928 | |
| 3929 | GLbitfield writeOnlyBits = |
| 3930 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3931 | |
| 3932 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3933 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3934 | context->handleError(InvalidOperation() |
| 3935 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3936 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3941 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3942 | context->handleError( |
| 3943 | InvalidOperation() |
| 3944 | << "The explicit flushing bit may only be set if the buffer is mapped for writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3945 | return false; |
| 3946 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3947 | |
| 3948 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3949 | } |
| 3950 | |
| 3951 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3952 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3953 | GLintptr offset, |
| 3954 | GLsizeiptr length) |
| 3955 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3956 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3957 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3958 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3959 | return false; |
| 3960 | } |
| 3961 | |
| 3962 | if (length < 0) |
| 3963 | { |
| 3964 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3965 | return false; |
| 3966 | } |
| 3967 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3968 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3969 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3970 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3971 | return false; |
| 3972 | } |
| 3973 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3974 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3975 | |
| 3976 | if (buffer == nullptr) |
| 3977 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3978 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3979 | return false; |
| 3980 | } |
| 3981 | |
| 3982 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3983 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3984 | context->handleError(InvalidOperation() |
| 3985 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3986 | return false; |
| 3987 | } |
| 3988 | |
| 3989 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3990 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3991 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3992 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3993 | if (!checkedSize.IsValid() || |
| 3994 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3995 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3996 | context->handleError(InvalidValue() |
| 3997 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3998 | return false; |
| 3999 | } |
| 4000 | |
| 4001 | return true; |
| 4002 | } |
| 4003 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4004 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4005 | { |
| 4006 | if (n < 0) |
| 4007 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4008 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4009 | return false; |
| 4010 | } |
| 4011 | return true; |
| 4012 | } |
| 4013 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4014 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4015 | { |
| 4016 | if (!context->getExtensions().robustClientMemory) |
| 4017 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4018 | context->handleError(InvalidOperation() |
| 4019 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4020 | return false; |
| 4021 | } |
| 4022 | |
| 4023 | if (bufSize < 0) |
| 4024 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4025 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4026 | return false; |
| 4027 | } |
| 4028 | |
| 4029 | return true; |
| 4030 | } |
| 4031 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4032 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4033 | { |
| 4034 | if (bufSize < numParams) |
| 4035 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4036 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 4037 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4038 | return false; |
| 4039 | } |
| 4040 | |
| 4041 | return true; |
| 4042 | } |
| 4043 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4044 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4045 | GLenum target, |
| 4046 | GLenum attachment, |
| 4047 | GLenum pname, |
| 4048 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4049 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4050 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4051 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4052 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4053 | return false; |
| 4054 | } |
| 4055 | |
| 4056 | int clientVersion = context->getClientMajorVersion(); |
| 4057 | |
| 4058 | switch (pname) |
| 4059 | { |
| 4060 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4061 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4062 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4063 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4064 | break; |
| 4065 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4066 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4067 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4068 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4069 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4070 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4071 | { |
| 4072 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4073 | return false; |
| 4074 | } |
| 4075 | break; |
| 4076 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4077 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4078 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4079 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4080 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4081 | return false; |
| 4082 | } |
| 4083 | break; |
| 4084 | |
| 4085 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4086 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4087 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4088 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4089 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4090 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4091 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4092 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4093 | if (clientVersion < 3) |
| 4094 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4095 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4096 | return false; |
| 4097 | } |
| 4098 | break; |
| 4099 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4100 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4101 | if (!context->getExtensions().geometryShader) |
| 4102 | { |
| 4103 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4104 | return false; |
| 4105 | } |
| 4106 | break; |
| 4107 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4108 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4109 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4110 | return false; |
| 4111 | } |
| 4112 | |
| 4113 | // Determine if the attachment is a valid enum |
| 4114 | switch (attachment) |
| 4115 | { |
| 4116 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4117 | case GL_DEPTH: |
| 4118 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4119 | if (clientVersion < 3) |
| 4120 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4121 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | break; |
| 4125 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4126 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4127 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4128 | { |
| 4129 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4130 | return false; |
| 4131 | } |
| 4132 | break; |
| 4133 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4134 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4135 | case GL_DEPTH_ATTACHMENT: |
| 4136 | case GL_STENCIL_ATTACHMENT: |
| 4137 | break; |
| 4138 | |
| 4139 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4140 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4141 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4142 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4143 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4144 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4145 | return false; |
| 4146 | } |
| 4147 | break; |
| 4148 | } |
| 4149 | |
| 4150 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4151 | ASSERT(framebuffer); |
| 4152 | |
| 4153 | if (framebuffer->id() == 0) |
| 4154 | { |
| 4155 | if (clientVersion < 3) |
| 4156 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4157 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4158 | return false; |
| 4159 | } |
| 4160 | |
| 4161 | switch (attachment) |
| 4162 | { |
| 4163 | case GL_BACK: |
| 4164 | case GL_DEPTH: |
| 4165 | case GL_STENCIL: |
| 4166 | break; |
| 4167 | |
| 4168 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4169 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4170 | return false; |
| 4171 | } |
| 4172 | } |
| 4173 | else |
| 4174 | { |
| 4175 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4176 | { |
| 4177 | // Valid attachment query |
| 4178 | } |
| 4179 | else |
| 4180 | { |
| 4181 | switch (attachment) |
| 4182 | { |
| 4183 | case GL_DEPTH_ATTACHMENT: |
| 4184 | case GL_STENCIL_ATTACHMENT: |
| 4185 | break; |
| 4186 | |
| 4187 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4188 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4189 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4190 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | break; |
| 4194 | |
| 4195 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4196 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4197 | return false; |
| 4198 | } |
| 4199 | } |
| 4200 | } |
| 4201 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4202 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4203 | if (attachmentObject) |
| 4204 | { |
| 4205 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4206 | attachmentObject->type() == GL_TEXTURE || |
| 4207 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4208 | |
| 4209 | switch (pname) |
| 4210 | { |
| 4211 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4212 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4213 | attachmentObject->type() != GL_TEXTURE) |
| 4214 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4215 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4216 | return false; |
| 4217 | } |
| 4218 | break; |
| 4219 | |
| 4220 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4221 | if (attachmentObject->type() != GL_TEXTURE) |
| 4222 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4223 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4224 | return false; |
| 4225 | } |
| 4226 | break; |
| 4227 | |
| 4228 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4229 | if (attachmentObject->type() != GL_TEXTURE) |
| 4230 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4231 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4232 | return false; |
| 4233 | } |
| 4234 | break; |
| 4235 | |
| 4236 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4237 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4238 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4239 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4240 | return false; |
| 4241 | } |
| 4242 | break; |
| 4243 | |
| 4244 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4245 | if (attachmentObject->type() != GL_TEXTURE) |
| 4246 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4247 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4248 | return false; |
| 4249 | } |
| 4250 | break; |
| 4251 | |
| 4252 | default: |
| 4253 | break; |
| 4254 | } |
| 4255 | } |
| 4256 | else |
| 4257 | { |
| 4258 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4259 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4260 | |
| 4261 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4262 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4263 | // INVALID_OPERATION for all other pnames |
| 4264 | |
| 4265 | switch (pname) |
| 4266 | { |
| 4267 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4268 | break; |
| 4269 | |
| 4270 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4271 | if (clientVersion < 3) |
| 4272 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4273 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4274 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4275 | return false; |
| 4276 | } |
| 4277 | break; |
| 4278 | |
| 4279 | default: |
| 4280 | if (clientVersion < 3) |
| 4281 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4282 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4283 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4284 | return false; |
| 4285 | } |
| 4286 | else |
| 4287 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4288 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4289 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4290 | return false; |
| 4291 | } |
| 4292 | } |
| 4293 | } |
| 4294 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4295 | if (numParams) |
| 4296 | { |
| 4297 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4298 | { |
| 4299 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4300 | // parameters. |
| 4301 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4302 | *numParams = numViews * 2; |
| 4303 | } |
| 4304 | else |
| 4305 | { |
| 4306 | // For all other queries we can have only one output parameter. |
| 4307 | *numParams = 1; |
| 4308 | } |
| 4309 | } |
| 4310 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4311 | return true; |
| 4312 | } |
| 4313 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4314 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4315 | GLenum target, |
| 4316 | GLenum attachment, |
| 4317 | GLenum pname, |
| 4318 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4319 | GLsizei *length, |
| 4320 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4321 | { |
| 4322 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4323 | { |
| 4324 | return false; |
| 4325 | } |
| 4326 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4327 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4328 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4329 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4330 | { |
| 4331 | return false; |
| 4332 | } |
| 4333 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4334 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4335 | { |
| 4336 | return false; |
| 4337 | } |
| 4338 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4339 | SetRobustLengthParam(length, numParams); |
| 4340 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4341 | return true; |
| 4342 | } |
| 4343 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4344 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4345 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4346 | GLenum pname, |
| 4347 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4348 | GLsizei *length, |
| 4349 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4350 | { |
| 4351 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4352 | { |
| 4353 | return false; |
| 4354 | } |
| 4355 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4356 | GLsizei numParams = 0; |
| 4357 | |
| 4358 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4359 | { |
| 4360 | return false; |
| 4361 | } |
| 4362 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4363 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4364 | { |
| 4365 | return false; |
| 4366 | } |
| 4367 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4368 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4369 | return true; |
| 4370 | } |
| 4371 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4372 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4373 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4374 | GLenum pname, |
| 4375 | GLsizei bufSize, |
| 4376 | GLsizei *length, |
| 4377 | GLint64 *params) |
| 4378 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4379 | GLsizei numParams = 0; |
| 4380 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4381 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4382 | { |
| 4383 | return false; |
| 4384 | } |
| 4385 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4386 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4387 | { |
| 4388 | return false; |
| 4389 | } |
| 4390 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4391 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4392 | { |
| 4393 | return false; |
| 4394 | } |
| 4395 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4396 | SetRobustLengthParam(length, numParams); |
| 4397 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4398 | return true; |
| 4399 | } |
| 4400 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4401 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4402 | { |
| 4403 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4404 | if (numParams) |
| 4405 | { |
| 4406 | *numParams = 1; |
| 4407 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4408 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4409 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4410 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4411 | ? GetValidProgramNoResolve(context, program) |
| 4412 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4413 | if (!programObject) |
| 4414 | { |
| 4415 | return false; |
| 4416 | } |
| 4417 | |
| 4418 | switch (pname) |
| 4419 | { |
| 4420 | case GL_DELETE_STATUS: |
| 4421 | case GL_LINK_STATUS: |
| 4422 | case GL_VALIDATE_STATUS: |
| 4423 | case GL_INFO_LOG_LENGTH: |
| 4424 | case GL_ATTACHED_SHADERS: |
| 4425 | case GL_ACTIVE_ATTRIBUTES: |
| 4426 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4427 | case GL_ACTIVE_UNIFORMS: |
| 4428 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4429 | break; |
| 4430 | |
| 4431 | case GL_PROGRAM_BINARY_LENGTH: |
| 4432 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4433 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4434 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4435 | "requires GL_OES_get_program_binary or " |
| 4436 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4437 | return false; |
| 4438 | } |
| 4439 | break; |
| 4440 | |
| 4441 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4442 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4443 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4444 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4445 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4446 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4447 | if (context->getClientMajorVersion() < 3) |
| 4448 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4449 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4450 | return false; |
| 4451 | } |
| 4452 | break; |
| 4453 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4454 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4455 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4456 | if (context->getClientVersion() < Version(3, 1)) |
| 4457 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4458 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4459 | return false; |
| 4460 | } |
| 4461 | break; |
| 4462 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4463 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4464 | if (context->getClientVersion() < Version(3, 1)) |
| 4465 | { |
| 4466 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4467 | return false; |
| 4468 | } |
| 4469 | |
| 4470 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4471 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4472 | // program which has not been linked successfully, or which does not contain objects to |
| 4473 | // form a compute shader. |
| 4474 | if (!programObject->isLinked()) |
| 4475 | { |
| 4476 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4477 | return false; |
| 4478 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4479 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4480 | { |
| 4481 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4482 | return false; |
| 4483 | } |
| 4484 | break; |
| 4485 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4486 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4487 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4488 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4489 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4490 | if (!context->getExtensions().geometryShader) |
| 4491 | { |
| 4492 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4493 | return false; |
| 4494 | } |
| 4495 | |
| 4496 | // [EXT_geometry_shader] Chapter 7.12 |
| 4497 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4498 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4499 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4500 | // successfully, or which does not contain objects to form a geometry shader. |
| 4501 | if (!programObject->isLinked()) |
| 4502 | { |
| 4503 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4504 | return false; |
| 4505 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4506 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4507 | { |
| 4508 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4509 | return false; |
| 4510 | } |
| 4511 | break; |
| 4512 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4513 | case GL_COMPLETION_STATUS_KHR: |
| 4514 | if (!context->getExtensions().parallelShaderCompile) |
| 4515 | { |
| 4516 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 4517 | return false; |
| 4518 | } |
| 4519 | break; |
| 4520 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4521 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4522 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4523 | return false; |
| 4524 | } |
| 4525 | |
| 4526 | return true; |
| 4527 | } |
| 4528 | |
| 4529 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4530 | GLuint program, |
| 4531 | GLenum pname, |
| 4532 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4533 | GLsizei *length, |
| 4534 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4535 | { |
| 4536 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4537 | { |
| 4538 | return false; |
| 4539 | } |
| 4540 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4541 | GLsizei numParams = 0; |
| 4542 | |
| 4543 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4544 | { |
| 4545 | return false; |
| 4546 | } |
| 4547 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4548 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4549 | { |
| 4550 | return false; |
| 4551 | } |
| 4552 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4553 | SetRobustLengthParam(length, numParams); |
| 4554 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4555 | return true; |
| 4556 | } |
| 4557 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4558 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4559 | GLenum target, |
| 4560 | GLenum pname, |
| 4561 | GLsizei bufSize, |
| 4562 | GLsizei *length, |
| 4563 | GLint *params) |
| 4564 | { |
| 4565 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4566 | { |
| 4567 | return false; |
| 4568 | } |
| 4569 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4570 | GLsizei numParams = 0; |
| 4571 | |
| 4572 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4573 | { |
| 4574 | return false; |
| 4575 | } |
| 4576 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4577 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4578 | { |
| 4579 | return false; |
| 4580 | } |
| 4581 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4582 | SetRobustLengthParam(length, numParams); |
| 4583 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4584 | return true; |
| 4585 | } |
| 4586 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4587 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4588 | GLuint shader, |
| 4589 | GLenum pname, |
| 4590 | GLsizei bufSize, |
| 4591 | GLsizei *length, |
| 4592 | GLint *params) |
| 4593 | { |
| 4594 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4595 | { |
| 4596 | return false; |
| 4597 | } |
| 4598 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4599 | GLsizei numParams = 0; |
| 4600 | |
| 4601 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4602 | { |
| 4603 | return false; |
| 4604 | } |
| 4605 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4606 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4607 | { |
| 4608 | return false; |
| 4609 | } |
| 4610 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4611 | SetRobustLengthParam(length, numParams); |
| 4612 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4613 | return true; |
| 4614 | } |
| 4615 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4616 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4617 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4618 | GLenum pname, |
| 4619 | GLsizei bufSize, |
| 4620 | GLsizei *length, |
| 4621 | GLfloat *params) |
| 4622 | { |
| 4623 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4624 | { |
| 4625 | return false; |
| 4626 | } |
| 4627 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4628 | GLsizei numParams = 0; |
| 4629 | |
| 4630 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4631 | { |
| 4632 | return false; |
| 4633 | } |
| 4634 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4635 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4636 | { |
| 4637 | return false; |
| 4638 | } |
| 4639 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4640 | SetRobustLengthParam(length, numParams); |
| 4641 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4642 | return true; |
| 4643 | } |
| 4644 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4645 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4646 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4647 | GLenum pname, |
| 4648 | GLsizei bufSize, |
| 4649 | GLsizei *length, |
| 4650 | GLint *params) |
| 4651 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4652 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4653 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4654 | { |
| 4655 | return false; |
| 4656 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4657 | GLsizei numParams = 0; |
| 4658 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4659 | { |
| 4660 | return false; |
| 4661 | } |
| 4662 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4663 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4664 | { |
| 4665 | return false; |
| 4666 | } |
| 4667 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4668 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4669 | return true; |
| 4670 | } |
| 4671 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4672 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4673 | TextureType target, |
| 4674 | GLenum pname, |
| 4675 | GLsizei bufSize, |
| 4676 | GLsizei *length, |
| 4677 | GLint *params) |
| 4678 | { |
| 4679 | UNIMPLEMENTED(); |
| 4680 | return false; |
| 4681 | } |
| 4682 | |
| 4683 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4684 | TextureType target, |
| 4685 | GLenum pname, |
| 4686 | GLsizei bufSize, |
| 4687 | GLsizei *length, |
| 4688 | GLuint *params) |
| 4689 | { |
| 4690 | UNIMPLEMENTED(); |
| 4691 | return false; |
| 4692 | } |
| 4693 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4694 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4695 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4696 | GLenum pname, |
| 4697 | GLsizei bufSize, |
| 4698 | const GLfloat *params) |
| 4699 | { |
| 4700 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4701 | { |
| 4702 | return false; |
| 4703 | } |
| 4704 | |
| 4705 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4706 | } |
| 4707 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4708 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4709 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4710 | GLenum pname, |
| 4711 | GLsizei bufSize, |
| 4712 | const GLint *params) |
| 4713 | { |
| 4714 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4715 | { |
| 4716 | return false; |
| 4717 | } |
| 4718 | |
| 4719 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4720 | } |
| 4721 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4722 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4723 | TextureType target, |
| 4724 | GLenum pname, |
| 4725 | GLsizei bufSize, |
| 4726 | const GLint *params) |
| 4727 | { |
| 4728 | UNIMPLEMENTED(); |
| 4729 | return false; |
| 4730 | } |
| 4731 | |
| 4732 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4733 | TextureType target, |
| 4734 | GLenum pname, |
| 4735 | GLsizei bufSize, |
| 4736 | const GLuint *params) |
| 4737 | { |
| 4738 | UNIMPLEMENTED(); |
| 4739 | return false; |
| 4740 | } |
| 4741 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4742 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4743 | GLuint sampler, |
| 4744 | GLenum pname, |
| 4745 | GLuint bufSize, |
| 4746 | GLsizei *length, |
| 4747 | GLfloat *params) |
| 4748 | { |
| 4749 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4750 | { |
| 4751 | return false; |
| 4752 | } |
| 4753 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4754 | GLsizei numParams = 0; |
| 4755 | |
| 4756 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4757 | { |
| 4758 | return false; |
| 4759 | } |
| 4760 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4761 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4762 | { |
| 4763 | return false; |
| 4764 | } |
| 4765 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4766 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4767 | return true; |
| 4768 | } |
| 4769 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4770 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4771 | GLuint sampler, |
| 4772 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4773 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4774 | GLsizei *length, |
| 4775 | GLint *params) |
| 4776 | { |
| 4777 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4778 | { |
| 4779 | return false; |
| 4780 | } |
| 4781 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4782 | GLsizei numParams = 0; |
| 4783 | |
| 4784 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4785 | { |
| 4786 | return false; |
| 4787 | } |
| 4788 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4789 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4790 | { |
| 4791 | return false; |
| 4792 | } |
| 4793 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4794 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4795 | return true; |
| 4796 | } |
| 4797 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4798 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4799 | GLuint sampler, |
| 4800 | GLenum pname, |
| 4801 | GLsizei bufSize, |
| 4802 | GLsizei *length, |
| 4803 | GLint *params) |
| 4804 | { |
| 4805 | UNIMPLEMENTED(); |
| 4806 | return false; |
| 4807 | } |
| 4808 | |
| 4809 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4810 | GLuint sampler, |
| 4811 | GLenum pname, |
| 4812 | GLsizei bufSize, |
| 4813 | GLsizei *length, |
| 4814 | GLuint *params) |
| 4815 | { |
| 4816 | UNIMPLEMENTED(); |
| 4817 | return false; |
| 4818 | } |
| 4819 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4820 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4821 | GLuint sampler, |
| 4822 | GLenum pname, |
| 4823 | GLsizei bufSize, |
| 4824 | const GLfloat *params) |
| 4825 | { |
| 4826 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4827 | { |
| 4828 | return false; |
| 4829 | } |
| 4830 | |
| 4831 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4832 | } |
| 4833 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4834 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4835 | GLuint sampler, |
| 4836 | GLenum pname, |
| 4837 | GLsizei bufSize, |
| 4838 | const GLint *params) |
| 4839 | { |
| 4840 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4841 | { |
| 4842 | return false; |
| 4843 | } |
| 4844 | |
| 4845 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4846 | } |
| 4847 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4848 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4849 | GLuint sampler, |
| 4850 | GLenum pname, |
| 4851 | GLsizei bufSize, |
| 4852 | const GLint *param) |
| 4853 | { |
| 4854 | UNIMPLEMENTED(); |
| 4855 | return false; |
| 4856 | } |
| 4857 | |
| 4858 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4859 | GLuint sampler, |
| 4860 | GLenum pname, |
| 4861 | GLsizei bufSize, |
| 4862 | const GLuint *param) |
| 4863 | { |
| 4864 | UNIMPLEMENTED(); |
| 4865 | return false; |
| 4866 | } |
| 4867 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4868 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4869 | GLuint index, |
| 4870 | GLenum pname, |
| 4871 | GLsizei bufSize, |
| 4872 | GLsizei *length, |
| 4873 | GLfloat *params) |
| 4874 | { |
| 4875 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4876 | { |
| 4877 | return false; |
| 4878 | } |
| 4879 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4880 | GLsizei writeLength = 0; |
| 4881 | |
| 4882 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4883 | { |
| 4884 | return false; |
| 4885 | } |
| 4886 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4887 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4888 | { |
| 4889 | return false; |
| 4890 | } |
| 4891 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4892 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4893 | return true; |
| 4894 | } |
| 4895 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4896 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4897 | GLuint index, |
| 4898 | GLenum pname, |
| 4899 | GLsizei bufSize, |
| 4900 | GLsizei *length, |
| 4901 | GLint *params) |
| 4902 | { |
| 4903 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4904 | { |
| 4905 | return false; |
| 4906 | } |
| 4907 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4908 | GLsizei writeLength = 0; |
| 4909 | |
| 4910 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4911 | { |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4915 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4916 | { |
| 4917 | return false; |
| 4918 | } |
| 4919 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4920 | SetRobustLengthParam(length, writeLength); |
| 4921 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4922 | return true; |
| 4923 | } |
| 4924 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4925 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4926 | GLuint index, |
| 4927 | GLenum pname, |
| 4928 | GLsizei bufSize, |
| 4929 | GLsizei *length, |
| 4930 | void **pointer) |
| 4931 | { |
| 4932 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4933 | { |
| 4934 | return false; |
| 4935 | } |
| 4936 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4937 | GLsizei writeLength = 0; |
| 4938 | |
| 4939 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4940 | { |
| 4941 | return false; |
| 4942 | } |
| 4943 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4944 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4945 | { |
| 4946 | return false; |
| 4947 | } |
| 4948 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4949 | SetRobustLengthParam(length, writeLength); |
| 4950 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4951 | return true; |
| 4952 | } |
| 4953 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4954 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4955 | GLuint index, |
| 4956 | GLenum pname, |
| 4957 | GLsizei bufSize, |
| 4958 | GLsizei *length, |
| 4959 | GLint *params) |
| 4960 | { |
| 4961 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4962 | { |
| 4963 | return false; |
| 4964 | } |
| 4965 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4966 | GLsizei writeLength = 0; |
| 4967 | |
| 4968 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4969 | { |
| 4970 | return false; |
| 4971 | } |
| 4972 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4973 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4974 | { |
| 4975 | return false; |
| 4976 | } |
| 4977 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4978 | SetRobustLengthParam(length, writeLength); |
| 4979 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4980 | return true; |
| 4981 | } |
| 4982 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4983 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4984 | GLuint index, |
| 4985 | GLenum pname, |
| 4986 | GLsizei bufSize, |
| 4987 | GLsizei *length, |
| 4988 | GLuint *params) |
| 4989 | { |
| 4990 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4991 | { |
| 4992 | return false; |
| 4993 | } |
| 4994 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4995 | GLsizei writeLength = 0; |
| 4996 | |
| 4997 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4998 | { |
| 4999 | return false; |
| 5000 | } |
| 5001 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5002 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5003 | { |
| 5004 | return false; |
| 5005 | } |
| 5006 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5007 | SetRobustLengthParam(length, writeLength); |
| 5008 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5009 | return true; |
| 5010 | } |
| 5011 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5012 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5013 | GLuint program, |
| 5014 | GLuint uniformBlockIndex, |
| 5015 | GLenum pname, |
| 5016 | GLsizei bufSize, |
| 5017 | GLsizei *length, |
| 5018 | GLint *params) |
| 5019 | { |
| 5020 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5021 | { |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5025 | GLsizei writeLength = 0; |
| 5026 | |
| 5027 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5028 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5029 | { |
| 5030 | return false; |
| 5031 | } |
| 5032 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5033 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5034 | { |
| 5035 | return false; |
| 5036 | } |
| 5037 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5038 | SetRobustLengthParam(length, writeLength); |
| 5039 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5040 | return true; |
| 5041 | } |
| 5042 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5043 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5044 | GLenum target, |
| 5045 | GLenum internalformat, |
| 5046 | GLenum pname, |
| 5047 | GLsizei bufSize, |
| 5048 | GLsizei *length, |
| 5049 | GLint *params) |
| 5050 | { |
| 5051 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5052 | { |
| 5053 | return false; |
| 5054 | } |
| 5055 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5056 | GLsizei numParams = 0; |
| 5057 | |
| 5058 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5059 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5060 | { |
| 5061 | return false; |
| 5062 | } |
| 5063 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5064 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5065 | { |
| 5066 | return false; |
| 5067 | } |
| 5068 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5069 | SetRobustLengthParam(length, numParams); |
| 5070 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5071 | return true; |
| 5072 | } |
| 5073 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5074 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5075 | GLuint attribIndex, |
| 5076 | GLint size, |
| 5077 | GLenum type, |
| 5078 | GLboolean pureInteger) |
| 5079 | { |
| 5080 | const Caps &caps = context->getCaps(); |
| 5081 | if (attribIndex >= caps.maxVertexAttributes) |
| 5082 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5083 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5084 | return false; |
| 5085 | } |
| 5086 | |
| 5087 | if (size < 1 || size > 4) |
| 5088 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5089 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5090 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | switch (type) |
| 5094 | { |
| 5095 | case GL_BYTE: |
| 5096 | case GL_UNSIGNED_BYTE: |
| 5097 | case GL_SHORT: |
| 5098 | case GL_UNSIGNED_SHORT: |
| 5099 | break; |
| 5100 | |
| 5101 | case GL_INT: |
| 5102 | case GL_UNSIGNED_INT: |
| 5103 | if (context->getClientMajorVersion() < 3) |
| 5104 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5105 | context->handleError(InvalidEnum() |
| 5106 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5107 | return false; |
| 5108 | } |
| 5109 | break; |
| 5110 | |
| 5111 | case GL_FIXED: |
| 5112 | case GL_FLOAT: |
| 5113 | if (pureInteger) |
| 5114 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5115 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5116 | return false; |
| 5117 | } |
| 5118 | break; |
| 5119 | |
| 5120 | case GL_HALF_FLOAT: |
| 5121 | if (context->getClientMajorVersion() < 3) |
| 5122 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5123 | context->handleError(InvalidEnum() |
| 5124 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5125 | return false; |
| 5126 | } |
| 5127 | if (pureInteger) |
| 5128 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5129 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5130 | return false; |
| 5131 | } |
| 5132 | break; |
| 5133 | |
| 5134 | case GL_INT_2_10_10_10_REV: |
| 5135 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5136 | if (context->getClientMajorVersion() < 3) |
| 5137 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5138 | context->handleError(InvalidEnum() |
| 5139 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5140 | return false; |
| 5141 | } |
| 5142 | if (pureInteger) |
| 5143 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5144 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5145 | return false; |
| 5146 | } |
| 5147 | if (size != 4) |
| 5148 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5149 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5150 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5151 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5152 | return false; |
| 5153 | } |
| 5154 | break; |
| 5155 | |
| 5156 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5157 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5158 | return false; |
| 5159 | } |
| 5160 | |
| 5161 | return true; |
| 5162 | } |
| 5163 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5164 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5165 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5166 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5167 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5168 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5169 | GLint drawbuffer, |
| 5170 | const GLenum *validComponentTypes, |
| 5171 | size_t validComponentTypeCount) |
| 5172 | { |
| 5173 | const FramebufferAttachment *attachment = |
| 5174 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5175 | if (attachment) |
| 5176 | { |
| 5177 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5178 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5179 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5180 | { |
| 5181 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5182 | InvalidOperation() |
| 5183 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5184 | return false; |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | return true; |
| 5189 | } |
| 5190 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5191 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5192 | { |
| 5193 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5194 | { |
| 5195 | return false; |
| 5196 | } |
| 5197 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5198 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5199 | if (pixelUnpackBuffer == nullptr) |
| 5200 | { |
| 5201 | if (dataSize < imageSize) |
| 5202 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5203 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5204 | } |
| 5205 | } |
| 5206 | return true; |
| 5207 | } |
| 5208 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5209 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5210 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5211 | GLenum pname, |
| 5212 | bool pointerVersion, |
| 5213 | GLsizei *numParams) |
| 5214 | { |
| 5215 | if (numParams) |
| 5216 | { |
| 5217 | *numParams = 0; |
| 5218 | } |
| 5219 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5220 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5221 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5222 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5223 | return false; |
| 5224 | } |
| 5225 | |
| 5226 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5227 | if (!buffer) |
| 5228 | { |
| 5229 | // A null buffer means that "0" is bound to the requested buffer target |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5230 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5231 | return false; |
| 5232 | } |
| 5233 | |
| 5234 | const Extensions &extensions = context->getExtensions(); |
| 5235 | |
| 5236 | switch (pname) |
| 5237 | { |
| 5238 | case GL_BUFFER_USAGE: |
| 5239 | case GL_BUFFER_SIZE: |
| 5240 | break; |
| 5241 | |
| 5242 | case GL_BUFFER_ACCESS_OES: |
| 5243 | if (!extensions.mapBuffer) |
| 5244 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5245 | context->handleError(InvalidEnum() |
| 5246 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5247 | return false; |
| 5248 | } |
| 5249 | break; |
| 5250 | |
| 5251 | case GL_BUFFER_MAPPED: |
| 5252 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5253 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5254 | !extensions.mapBufferRange) |
| 5255 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5256 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5257 | "GL_OES_mapbuffer or " |
| 5258 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5259 | return false; |
| 5260 | } |
| 5261 | break; |
| 5262 | |
| 5263 | case GL_BUFFER_MAP_POINTER: |
| 5264 | if (!pointerVersion) |
| 5265 | { |
| 5266 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5267 | InvalidEnum() |
| 5268 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5269 | return false; |
| 5270 | } |
| 5271 | break; |
| 5272 | |
| 5273 | case GL_BUFFER_ACCESS_FLAGS: |
| 5274 | case GL_BUFFER_MAP_OFFSET: |
| 5275 | case GL_BUFFER_MAP_LENGTH: |
| 5276 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5278 | context->handleError(InvalidEnum() |
| 5279 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5280 | return false; |
| 5281 | } |
| 5282 | break; |
| 5283 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5284 | case GL_MEMORY_SIZE_ANGLE: |
| 5285 | if (!context->getExtensions().memorySize) |
| 5286 | { |
| 5287 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5288 | return false; |
| 5289 | } |
| 5290 | break; |
| 5291 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5292 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5293 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5294 | return false; |
| 5295 | } |
| 5296 | |
| 5297 | // All buffer parameter queries return one value. |
| 5298 | if (numParams) |
| 5299 | { |
| 5300 | *numParams = 1; |
| 5301 | } |
| 5302 | |
| 5303 | return true; |
| 5304 | } |
| 5305 | |
| 5306 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5307 | GLenum target, |
| 5308 | GLenum pname, |
| 5309 | GLsizei *length) |
| 5310 | { |
| 5311 | if (length) |
| 5312 | { |
| 5313 | *length = 0; |
| 5314 | } |
| 5315 | |
| 5316 | if (target != GL_RENDERBUFFER) |
| 5317 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5318 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5319 | return false; |
| 5320 | } |
| 5321 | |
| 5322 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5323 | if (renderbuffer == nullptr) |
| 5324 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5325 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5326 | return false; |
| 5327 | } |
| 5328 | |
| 5329 | switch (pname) |
| 5330 | { |
| 5331 | case GL_RENDERBUFFER_WIDTH: |
| 5332 | case GL_RENDERBUFFER_HEIGHT: |
| 5333 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5334 | case GL_RENDERBUFFER_RED_SIZE: |
| 5335 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5336 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5337 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5338 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5339 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5340 | break; |
| 5341 | |
| 5342 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5343 | if (!context->getExtensions().framebufferMultisample) |
| 5344 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5345 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5346 | return false; |
| 5347 | } |
| 5348 | break; |
| 5349 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5350 | case GL_MEMORY_SIZE_ANGLE: |
| 5351 | if (!context->getExtensions().memorySize) |
| 5352 | { |
| 5353 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5354 | return false; |
| 5355 | } |
| 5356 | break; |
| 5357 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5358 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5359 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5360 | return false; |
| 5361 | } |
| 5362 | |
| 5363 | if (length) |
| 5364 | { |
| 5365 | *length = 1; |
| 5366 | } |
| 5367 | return true; |
| 5368 | } |
| 5369 | |
| 5370 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5371 | { |
| 5372 | if (length) |
| 5373 | { |
| 5374 | *length = 0; |
| 5375 | } |
| 5376 | |
| 5377 | if (GetValidShader(context, shader) == nullptr) |
| 5378 | { |
| 5379 | return false; |
| 5380 | } |
| 5381 | |
| 5382 | switch (pname) |
| 5383 | { |
| 5384 | case GL_SHADER_TYPE: |
| 5385 | case GL_DELETE_STATUS: |
| 5386 | case GL_COMPILE_STATUS: |
| 5387 | case GL_INFO_LOG_LENGTH: |
| 5388 | case GL_SHADER_SOURCE_LENGTH: |
| 5389 | break; |
| 5390 | |
| 5391 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5392 | if (!context->getExtensions().translatedShaderSource) |
| 5393 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5394 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5395 | return false; |
| 5396 | } |
| 5397 | break; |
| 5398 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5399 | case GL_COMPLETION_STATUS_KHR: |
| 5400 | if (!context->getExtensions().parallelShaderCompile) |
| 5401 | { |
| 5402 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 5403 | return false; |
| 5404 | } |
| 5405 | break; |
| 5406 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5407 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5408 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5409 | return false; |
| 5410 | } |
| 5411 | |
| 5412 | if (length) |
| 5413 | { |
| 5414 | *length = 1; |
| 5415 | } |
| 5416 | return true; |
| 5417 | } |
| 5418 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5419 | bool ValidateGetTexParameterBase(Context *context, |
| 5420 | TextureType target, |
| 5421 | GLenum pname, |
| 5422 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5423 | { |
| 5424 | if (length) |
| 5425 | { |
| 5426 | *length = 0; |
| 5427 | } |
| 5428 | |
| 5429 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5430 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5431 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5432 | return false; |
| 5433 | } |
| 5434 | |
| 5435 | if (context->getTargetTexture(target) == nullptr) |
| 5436 | { |
| 5437 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5438 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5439 | return false; |
| 5440 | } |
| 5441 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5442 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5443 | { |
| 5444 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5445 | return false; |
| 5446 | } |
| 5447 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5448 | switch (pname) |
| 5449 | { |
| 5450 | case GL_TEXTURE_MAG_FILTER: |
| 5451 | case GL_TEXTURE_MIN_FILTER: |
| 5452 | case GL_TEXTURE_WRAP_S: |
| 5453 | case GL_TEXTURE_WRAP_T: |
| 5454 | break; |
| 5455 | |
| 5456 | case GL_TEXTURE_USAGE_ANGLE: |
| 5457 | if (!context->getExtensions().textureUsage) |
| 5458 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5459 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5460 | return false; |
| 5461 | } |
| 5462 | break; |
| 5463 | |
| 5464 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5465 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5466 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5467 | return false; |
| 5468 | } |
| 5469 | break; |
| 5470 | |
| 5471 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5472 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5473 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5474 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5475 | return false; |
| 5476 | } |
| 5477 | break; |
| 5478 | |
| 5479 | case GL_TEXTURE_WRAP_R: |
| 5480 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5481 | case GL_TEXTURE_SWIZZLE_R: |
| 5482 | case GL_TEXTURE_SWIZZLE_G: |
| 5483 | case GL_TEXTURE_SWIZZLE_B: |
| 5484 | case GL_TEXTURE_SWIZZLE_A: |
| 5485 | case GL_TEXTURE_BASE_LEVEL: |
| 5486 | case GL_TEXTURE_MAX_LEVEL: |
| 5487 | case GL_TEXTURE_MIN_LOD: |
| 5488 | case GL_TEXTURE_MAX_LOD: |
| 5489 | case GL_TEXTURE_COMPARE_MODE: |
| 5490 | case GL_TEXTURE_COMPARE_FUNC: |
| 5491 | if (context->getClientMajorVersion() < 3) |
| 5492 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5493 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5494 | return false; |
| 5495 | } |
| 5496 | break; |
| 5497 | |
| 5498 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5499 | if (!context->getExtensions().textureSRGBDecode) |
| 5500 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5501 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5502 | return false; |
| 5503 | } |
| 5504 | break; |
| 5505 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5506 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5507 | if (context->getClientVersion() < Version(3, 1)) |
| 5508 | { |
| 5509 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5510 | return false; |
| 5511 | } |
| 5512 | break; |
| 5513 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5514 | case GL_GENERATE_MIPMAP: |
| 5515 | case GL_TEXTURE_CROP_RECT_OES: |
| 5516 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5517 | // after GL_OES_draw_texture functionality implemented |
| 5518 | if (context->getClientMajorVersion() > 1) |
| 5519 | { |
| 5520 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5521 | return false; |
| 5522 | } |
| 5523 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5524 | |
| 5525 | case GL_MEMORY_SIZE_ANGLE: |
| 5526 | if (!context->getExtensions().memorySize) |
| 5527 | { |
| 5528 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5529 | return false; |
| 5530 | } |
| 5531 | break; |
| 5532 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5533 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5534 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | |
| 5538 | if (length) |
| 5539 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5540 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5541 | } |
| 5542 | return true; |
| 5543 | } |
| 5544 | |
| 5545 | bool ValidateGetVertexAttribBase(Context *context, |
| 5546 | GLuint index, |
| 5547 | GLenum pname, |
| 5548 | GLsizei *length, |
| 5549 | bool pointer, |
| 5550 | bool pureIntegerEntryPoint) |
| 5551 | { |
| 5552 | if (length) |
| 5553 | { |
| 5554 | *length = 0; |
| 5555 | } |
| 5556 | |
| 5557 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5559 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | if (index >= context->getCaps().maxVertexAttributes) |
| 5564 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5565 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5566 | return false; |
| 5567 | } |
| 5568 | |
| 5569 | if (pointer) |
| 5570 | { |
| 5571 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5572 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5573 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5574 | return false; |
| 5575 | } |
| 5576 | } |
| 5577 | else |
| 5578 | { |
| 5579 | switch (pname) |
| 5580 | { |
| 5581 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5582 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5583 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5584 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5585 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5586 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5587 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5588 | break; |
| 5589 | |
| 5590 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5591 | static_assert( |
| 5592 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5593 | "ANGLE extension enums not equal to GL enums."); |
| 5594 | if (context->getClientMajorVersion() < 3 && |
| 5595 | !context->getExtensions().instancedArrays) |
| 5596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5597 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5598 | "requires OpenGL ES 3.0 or " |
| 5599 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5600 | return false; |
| 5601 | } |
| 5602 | break; |
| 5603 | |
| 5604 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5605 | if (context->getClientMajorVersion() < 3) |
| 5606 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5607 | context->handleError( |
| 5608 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5609 | return false; |
| 5610 | } |
| 5611 | break; |
| 5612 | |
| 5613 | case GL_VERTEX_ATTRIB_BINDING: |
| 5614 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5615 | if (context->getClientVersion() < ES_3_1) |
| 5616 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5617 | context->handleError(InvalidEnum() |
| 5618 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5619 | return false; |
| 5620 | } |
| 5621 | break; |
| 5622 | |
| 5623 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5624 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5625 | return false; |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | if (length) |
| 5630 | { |
| 5631 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5632 | { |
| 5633 | *length = 4; |
| 5634 | } |
| 5635 | else |
| 5636 | { |
| 5637 | *length = 1; |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | return true; |
| 5642 | } |
| 5643 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5644 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5645 | GLint x, |
| 5646 | GLint y, |
| 5647 | GLsizei width, |
| 5648 | GLsizei height, |
| 5649 | GLenum format, |
| 5650 | GLenum type, |
| 5651 | GLsizei bufSize, |
| 5652 | GLsizei *length, |
| 5653 | GLsizei *columns, |
| 5654 | GLsizei *rows, |
| 5655 | void *pixels) |
| 5656 | { |
| 5657 | if (length != nullptr) |
| 5658 | { |
| 5659 | *length = 0; |
| 5660 | } |
| 5661 | if (rows != nullptr) |
| 5662 | { |
| 5663 | *rows = 0; |
| 5664 | } |
| 5665 | if (columns != nullptr) |
| 5666 | { |
| 5667 | *columns = 0; |
| 5668 | } |
| 5669 | |
| 5670 | if (width < 0 || height < 0) |
| 5671 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5672 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5673 | return false; |
| 5674 | } |
| 5675 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5676 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5677 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5678 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5679 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5680 | return false; |
| 5681 | } |
| 5682 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5683 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5684 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5685 | return false; |
| 5686 | } |
| 5687 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5688 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5689 | ASSERT(framebuffer); |
| 5690 | |
| 5691 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5692 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5693 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5694 | return false; |
| 5695 | } |
| 5696 | |
| 5697 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5698 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5699 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5700 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5701 | // situation is an application error that would lead to a crash in ANGLE. |
| 5702 | if (readBuffer == nullptr) |
| 5703 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5704 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5705 | return false; |
| 5706 | } |
| 5707 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5708 | // ANGLE_multiview, Revision 1: |
| 5709 | // ReadPixels generates an INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 5710 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5711 | // in the current read framebuffer is more than one. |
| 5712 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5713 | { |
| 5714 | context->handleError(InvalidFramebufferOperation() |
| 5715 | << "Attempting to read from a multi-view framebuffer."); |
| 5716 | return false; |
| 5717 | } |
| 5718 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5719 | if (context->getExtensions().webglCompatibility) |
| 5720 | { |
| 5721 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5722 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5723 | // and type before validating the combination of format and type. However, the |
| 5724 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5725 | // verifies that GL_INVALID_OPERATION is generated. |
| 5726 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5727 | // dEQP/WebGL. |
| 5728 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5729 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5730 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5731 | return false; |
| 5732 | } |
| 5733 | |
| 5734 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5735 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5736 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5737 | return false; |
| 5738 | } |
| 5739 | } |
| 5740 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5741 | GLenum currentFormat = GL_NONE; |
| 5742 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5743 | |
| 5744 | GLenum currentType = GL_NONE; |
| 5745 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5746 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5747 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5748 | |
| 5749 | bool validFormatTypeCombination = |
| 5750 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5751 | |
| 5752 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5753 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5754 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5755 | return false; |
| 5756 | } |
| 5757 | |
| 5758 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5759 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5760 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5761 | { |
| 5762 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5763 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5764 | return false; |
| 5765 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5766 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5767 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5768 | { |
| 5769 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5770 | return false; |
| 5771 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5772 | |
| 5773 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5774 | // would exceed the data store size. |
| 5775 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5776 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5777 | const auto &pack = context->getGLState().getPackState(); |
| 5778 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5779 | GLuint endByte = 0; |
| 5780 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5781 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5782 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5783 | return false; |
| 5784 | } |
| 5785 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5786 | if (bufSize >= 0) |
| 5787 | { |
| 5788 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5789 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5790 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5791 | return false; |
| 5792 | } |
| 5793 | } |
| 5794 | |
| 5795 | if (pixelPackBuffer != nullptr) |
| 5796 | { |
| 5797 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5798 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5799 | checkedEndByte += checkedOffset; |
| 5800 | |
| 5801 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5802 | { |
| 5803 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5804 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5805 | return false; |
| 5806 | } |
| 5807 | } |
| 5808 | |
| 5809 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5810 | { |
| 5811 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5812 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5813 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5814 | return false; |
| 5815 | } |
| 5816 | |
| 5817 | *length = static_cast<GLsizei>(endByte); |
| 5818 | } |
| 5819 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5820 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5821 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5822 | if (start < 0) |
| 5823 | { |
| 5824 | // "subtract" the area that is less than 0 |
| 5825 | clippedExtent += start; |
| 5826 | } |
| 5827 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5828 | angle::CheckedNumeric<int> readExtent = start; |
| 5829 | readExtent += length; |
| 5830 | if (!readExtent.IsValid()) |
| 5831 | { |
| 5832 | return false; |
| 5833 | } |
| 5834 | |
| 5835 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5836 | { |
| 5837 | // Subtract the region to the right of the read buffer |
| 5838 | clippedExtent -= (readExtent - bufferSize); |
| 5839 | } |
| 5840 | |
| 5841 | if (!clippedExtent.IsValid()) |
| 5842 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5843 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5844 | } |
| 5845 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5846 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5847 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5848 | }; |
| 5849 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5850 | GLsizei writtenColumns = 0; |
| 5851 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5852 | { |
| 5853 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5854 | return false; |
| 5855 | } |
| 5856 | |
| 5857 | GLsizei writtenRows = 0; |
| 5858 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5859 | { |
| 5860 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5861 | return false; |
| 5862 | } |
| 5863 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5864 | if (columns != nullptr) |
| 5865 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5866 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5867 | } |
| 5868 | |
| 5869 | if (rows != nullptr) |
| 5870 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5871 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5872 | } |
| 5873 | |
| 5874 | return true; |
| 5875 | } |
| 5876 | |
| 5877 | template <typename ParamType> |
| 5878 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5879 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5880 | GLenum pname, |
| 5881 | GLsizei bufSize, |
| 5882 | const ParamType *params) |
| 5883 | { |
| 5884 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5885 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5886 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5887 | return false; |
| 5888 | } |
| 5889 | |
| 5890 | if (context->getTargetTexture(target) == nullptr) |
| 5891 | { |
| 5892 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5893 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5894 | return false; |
| 5895 | } |
| 5896 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5897 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5898 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5899 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5900 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5901 | return false; |
| 5902 | } |
| 5903 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5904 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5905 | { |
| 5906 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5907 | return false; |
| 5908 | } |
| 5909 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5910 | switch (pname) |
| 5911 | { |
| 5912 | case GL_TEXTURE_WRAP_R: |
| 5913 | case GL_TEXTURE_SWIZZLE_R: |
| 5914 | case GL_TEXTURE_SWIZZLE_G: |
| 5915 | case GL_TEXTURE_SWIZZLE_B: |
| 5916 | case GL_TEXTURE_SWIZZLE_A: |
| 5917 | case GL_TEXTURE_BASE_LEVEL: |
| 5918 | case GL_TEXTURE_MAX_LEVEL: |
| 5919 | case GL_TEXTURE_COMPARE_MODE: |
| 5920 | case GL_TEXTURE_COMPARE_FUNC: |
| 5921 | case GL_TEXTURE_MIN_LOD: |
| 5922 | case GL_TEXTURE_MAX_LOD: |
| 5923 | if (context->getClientMajorVersion() < 3) |
| 5924 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5925 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5926 | return false; |
| 5927 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5928 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5929 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5930 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5931 | "available without " |
| 5932 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | break; |
| 5936 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5937 | case GL_GENERATE_MIPMAP: |
| 5938 | case GL_TEXTURE_CROP_RECT_OES: |
| 5939 | if (context->getClientMajorVersion() > 1) |
| 5940 | { |
| 5941 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5942 | return false; |
| 5943 | } |
| 5944 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5945 | default: |
| 5946 | break; |
| 5947 | } |
| 5948 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5949 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5950 | { |
| 5951 | switch (pname) |
| 5952 | { |
| 5953 | case GL_TEXTURE_MIN_FILTER: |
| 5954 | case GL_TEXTURE_MAG_FILTER: |
| 5955 | case GL_TEXTURE_WRAP_S: |
| 5956 | case GL_TEXTURE_WRAP_T: |
| 5957 | case GL_TEXTURE_WRAP_R: |
| 5958 | case GL_TEXTURE_MIN_LOD: |
| 5959 | case GL_TEXTURE_MAX_LOD: |
| 5960 | case GL_TEXTURE_COMPARE_MODE: |
| 5961 | case GL_TEXTURE_COMPARE_FUNC: |
| 5962 | context->handleError(InvalidEnum() |
| 5963 | << "Invalid parameter for 2D multisampled textures."); |
| 5964 | return false; |
| 5965 | } |
| 5966 | } |
| 5967 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5968 | switch (pname) |
| 5969 | { |
| 5970 | case GL_TEXTURE_WRAP_S: |
| 5971 | case GL_TEXTURE_WRAP_T: |
| 5972 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5973 | { |
| 5974 | bool restrictedWrapModes = |
| 5975 | target == TextureType::External || target == TextureType::Rectangle; |
| 5976 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5977 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5978 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5979 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5980 | } |
| 5981 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5982 | |
| 5983 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5984 | { |
| 5985 | bool restrictedMinFilter = |
| 5986 | target == TextureType::External || target == TextureType::Rectangle; |
| 5987 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5988 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5989 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5990 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5991 | } |
| 5992 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5993 | |
| 5994 | case GL_TEXTURE_MAG_FILTER: |
| 5995 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5996 | { |
| 5997 | return false; |
| 5998 | } |
| 5999 | break; |
| 6000 | |
| 6001 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6002 | if (!context->getExtensions().textureUsage) |
| 6003 | { |
| 6004 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6005 | return false; |
| 6006 | } |
| 6007 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6008 | switch (ConvertToGLenum(params[0])) |
| 6009 | { |
| 6010 | case GL_NONE: |
| 6011 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6012 | break; |
| 6013 | |
| 6014 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6015 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6016 | return false; |
| 6017 | } |
| 6018 | break; |
| 6019 | |
| 6020 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6021 | { |
| 6022 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6023 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6024 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6025 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6026 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6027 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6028 | } |
| 6029 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6030 | |
| 6031 | case GL_TEXTURE_MIN_LOD: |
| 6032 | case GL_TEXTURE_MAX_LOD: |
| 6033 | // any value is permissible |
| 6034 | break; |
| 6035 | |
| 6036 | case GL_TEXTURE_COMPARE_MODE: |
| 6037 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6038 | { |
| 6039 | return false; |
| 6040 | } |
| 6041 | break; |
| 6042 | |
| 6043 | case GL_TEXTURE_COMPARE_FUNC: |
| 6044 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6045 | { |
| 6046 | return false; |
| 6047 | } |
| 6048 | break; |
| 6049 | |
| 6050 | case GL_TEXTURE_SWIZZLE_R: |
| 6051 | case GL_TEXTURE_SWIZZLE_G: |
| 6052 | case GL_TEXTURE_SWIZZLE_B: |
| 6053 | case GL_TEXTURE_SWIZZLE_A: |
| 6054 | switch (ConvertToGLenum(params[0])) |
| 6055 | { |
| 6056 | case GL_RED: |
| 6057 | case GL_GREEN: |
| 6058 | case GL_BLUE: |
| 6059 | case GL_ALPHA: |
| 6060 | case GL_ZERO: |
| 6061 | case GL_ONE: |
| 6062 | break; |
| 6063 | |
| 6064 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6065 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6066 | return false; |
| 6067 | } |
| 6068 | break; |
| 6069 | |
| 6070 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6071 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6072 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6073 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6074 | return false; |
| 6075 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6076 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6077 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6078 | context->handleError(InvalidOperation() |
| 6079 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6080 | return false; |
| 6081 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6082 | if ((target == TextureType::_2DMultisample || |
| 6083 | target == TextureType::_2DMultisampleArray) && |
| 6084 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6085 | { |
| 6086 | context->handleError(InvalidOperation() |
| 6087 | << "Base level must be 0 for multisampled textures."); |
| 6088 | return false; |
| 6089 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6090 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6091 | { |
| 6092 | context->handleError(InvalidOperation() |
| 6093 | << "Base level must be 0 for rectangle textures."); |
| 6094 | return false; |
| 6095 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6096 | break; |
| 6097 | |
| 6098 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6099 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6100 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6101 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6102 | return false; |
| 6103 | } |
| 6104 | break; |
| 6105 | |
| 6106 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6107 | if (context->getClientVersion() < Version(3, 1)) |
| 6108 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6109 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6110 | return false; |
| 6111 | } |
| 6112 | switch (ConvertToGLenum(params[0])) |
| 6113 | { |
| 6114 | case GL_DEPTH_COMPONENT: |
| 6115 | case GL_STENCIL_INDEX: |
| 6116 | break; |
| 6117 | |
| 6118 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6119 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6120 | return false; |
| 6121 | } |
| 6122 | break; |
| 6123 | |
| 6124 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6125 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6126 | { |
| 6127 | return false; |
| 6128 | } |
| 6129 | break; |
| 6130 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6131 | case GL_GENERATE_MIPMAP: |
| 6132 | case GL_TEXTURE_CROP_RECT_OES: |
| 6133 | if (context->getClientMajorVersion() > 1) |
| 6134 | { |
| 6135 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6136 | return false; |
| 6137 | } |
| 6138 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6139 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6140 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6141 | return false; |
| 6142 | } |
| 6143 | |
| 6144 | return true; |
| 6145 | } |
| 6146 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6147 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 6148 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6149 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6150 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6151 | { |
| 6152 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6153 | { |
| 6154 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6155 | return false; |
| 6156 | } |
| 6157 | |
| 6158 | return true; |
| 6159 | } |
| 6160 | |
| 6161 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6162 | GLuint program, |
| 6163 | GLuint uniformBlockIndex, |
| 6164 | GLenum pname, |
| 6165 | GLsizei *length) |
| 6166 | { |
| 6167 | if (length) |
| 6168 | { |
| 6169 | *length = 0; |
| 6170 | } |
| 6171 | |
| 6172 | if (context->getClientMajorVersion() < 3) |
| 6173 | { |
| 6174 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6175 | return false; |
| 6176 | } |
| 6177 | |
| 6178 | Program *programObject = GetValidProgram(context, program); |
| 6179 | if (!programObject) |
| 6180 | { |
| 6181 | return false; |
| 6182 | } |
| 6183 | |
| 6184 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6185 | { |
| 6186 | context->handleError(InvalidValue() |
| 6187 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6188 | return false; |
| 6189 | } |
| 6190 | |
| 6191 | switch (pname) |
| 6192 | { |
| 6193 | case GL_UNIFORM_BLOCK_BINDING: |
| 6194 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6195 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6196 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6197 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6198 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6199 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6200 | break; |
| 6201 | |
| 6202 | default: |
| 6203 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6204 | return false; |
| 6205 | } |
| 6206 | |
| 6207 | if (length) |
| 6208 | { |
| 6209 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6210 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6211 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6212 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6213 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6214 | } |
| 6215 | else |
| 6216 | { |
| 6217 | *length = 1; |
| 6218 | } |
| 6219 | } |
| 6220 | |
| 6221 | return true; |
| 6222 | } |
| 6223 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6224 | template <typename ParamType> |
| 6225 | bool ValidateSamplerParameterBase(Context *context, |
| 6226 | GLuint sampler, |
| 6227 | GLenum pname, |
| 6228 | GLsizei bufSize, |
| 6229 | ParamType *params) |
| 6230 | { |
| 6231 | if (context->getClientMajorVersion() < 3) |
| 6232 | { |
| 6233 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6234 | return false; |
| 6235 | } |
| 6236 | |
| 6237 | if (!context->isSampler(sampler)) |
| 6238 | { |
| 6239 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6240 | return false; |
| 6241 | } |
| 6242 | |
| 6243 | const GLsizei minBufSize = 1; |
| 6244 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6245 | { |
| 6246 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | switch (pname) |
| 6251 | { |
| 6252 | case GL_TEXTURE_WRAP_S: |
| 6253 | case GL_TEXTURE_WRAP_T: |
| 6254 | case GL_TEXTURE_WRAP_R: |
| 6255 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6256 | { |
| 6257 | return false; |
| 6258 | } |
| 6259 | break; |
| 6260 | |
| 6261 | case GL_TEXTURE_MIN_FILTER: |
| 6262 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6263 | { |
| 6264 | return false; |
| 6265 | } |
| 6266 | break; |
| 6267 | |
| 6268 | case GL_TEXTURE_MAG_FILTER: |
| 6269 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6270 | { |
| 6271 | return false; |
| 6272 | } |
| 6273 | break; |
| 6274 | |
| 6275 | case GL_TEXTURE_MIN_LOD: |
| 6276 | case GL_TEXTURE_MAX_LOD: |
| 6277 | // any value is permissible |
| 6278 | break; |
| 6279 | |
| 6280 | case GL_TEXTURE_COMPARE_MODE: |
| 6281 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6282 | { |
| 6283 | return false; |
| 6284 | } |
| 6285 | break; |
| 6286 | |
| 6287 | case GL_TEXTURE_COMPARE_FUNC: |
| 6288 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6289 | { |
| 6290 | return false; |
| 6291 | } |
| 6292 | break; |
| 6293 | |
| 6294 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6295 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6296 | { |
| 6297 | return false; |
| 6298 | } |
| 6299 | break; |
| 6300 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6301 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6302 | { |
| 6303 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6304 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6305 | { |
| 6306 | return false; |
| 6307 | } |
| 6308 | } |
| 6309 | break; |
| 6310 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6311 | default: |
| 6312 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6313 | return false; |
| 6314 | } |
| 6315 | |
| 6316 | return true; |
| 6317 | } |
| 6318 | |
| 6319 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 6320 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 6321 | |
| 6322 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6323 | GLuint sampler, |
| 6324 | GLenum pname, |
| 6325 | GLsizei *length) |
| 6326 | { |
| 6327 | if (length) |
| 6328 | { |
| 6329 | *length = 0; |
| 6330 | } |
| 6331 | |
| 6332 | if (context->getClientMajorVersion() < 3) |
| 6333 | { |
| 6334 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6335 | return false; |
| 6336 | } |
| 6337 | |
| 6338 | if (!context->isSampler(sampler)) |
| 6339 | { |
| 6340 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6341 | return false; |
| 6342 | } |
| 6343 | |
| 6344 | switch (pname) |
| 6345 | { |
| 6346 | case GL_TEXTURE_WRAP_S: |
| 6347 | case GL_TEXTURE_WRAP_T: |
| 6348 | case GL_TEXTURE_WRAP_R: |
| 6349 | case GL_TEXTURE_MIN_FILTER: |
| 6350 | case GL_TEXTURE_MAG_FILTER: |
| 6351 | case GL_TEXTURE_MIN_LOD: |
| 6352 | case GL_TEXTURE_MAX_LOD: |
| 6353 | case GL_TEXTURE_COMPARE_MODE: |
| 6354 | case GL_TEXTURE_COMPARE_FUNC: |
| 6355 | break; |
| 6356 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6357 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6358 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6359 | { |
| 6360 | return false; |
| 6361 | } |
| 6362 | break; |
| 6363 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6364 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6365 | if (!context->getExtensions().textureSRGBDecode) |
| 6366 | { |
| 6367 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6368 | return false; |
| 6369 | } |
| 6370 | break; |
| 6371 | |
| 6372 | default: |
| 6373 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6374 | return false; |
| 6375 | } |
| 6376 | |
| 6377 | if (length) |
| 6378 | { |
| 6379 | *length = 1; |
| 6380 | } |
| 6381 | return true; |
| 6382 | } |
| 6383 | |
| 6384 | bool ValidateGetInternalFormativBase(Context *context, |
| 6385 | GLenum target, |
| 6386 | GLenum internalformat, |
| 6387 | GLenum pname, |
| 6388 | GLsizei bufSize, |
| 6389 | GLsizei *numParams) |
| 6390 | { |
| 6391 | if (numParams) |
| 6392 | { |
| 6393 | *numParams = 0; |
| 6394 | } |
| 6395 | |
| 6396 | if (context->getClientMajorVersion() < 3) |
| 6397 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6398 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6399 | return false; |
| 6400 | } |
| 6401 | |
| 6402 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6403 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6404 | { |
| 6405 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6406 | return false; |
| 6407 | } |
| 6408 | |
| 6409 | switch (target) |
| 6410 | { |
| 6411 | case GL_RENDERBUFFER: |
| 6412 | break; |
| 6413 | |
| 6414 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 6415 | if (context->getClientVersion() < ES_3_1) |
| 6416 | { |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6417 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureTargetRequiresES31); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6418 | return false; |
| 6419 | } |
| 6420 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6421 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6422 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6423 | { |
| 6424 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 6425 | return false; |
| 6426 | } |
| 6427 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6428 | default: |
| 6429 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6430 | return false; |
| 6431 | } |
| 6432 | |
| 6433 | if (bufSize < 0) |
| 6434 | { |
| 6435 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6436 | return false; |
| 6437 | } |
| 6438 | |
| 6439 | GLsizei maxWriteParams = 0; |
| 6440 | switch (pname) |
| 6441 | { |
| 6442 | case GL_NUM_SAMPLE_COUNTS: |
| 6443 | maxWriteParams = 1; |
| 6444 | break; |
| 6445 | |
| 6446 | case GL_SAMPLES: |
| 6447 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6448 | break; |
| 6449 | |
| 6450 | default: |
| 6451 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6452 | return false; |
| 6453 | } |
| 6454 | |
| 6455 | if (numParams) |
| 6456 | { |
| 6457 | // glGetInternalFormativ will not overflow bufSize |
| 6458 | *numParams = std::min(bufSize, maxWriteParams); |
| 6459 | } |
| 6460 | |
| 6461 | return true; |
| 6462 | } |
| 6463 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6464 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6465 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6466 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6467 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 6468 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6469 | return false; |
| 6470 | } |
| 6471 | return true; |
| 6472 | } |
| 6473 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6474 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6475 | { |
| 6476 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6477 | { |
| 6478 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6479 | return false; |
| 6480 | } |
| 6481 | return true; |
| 6482 | } |
| 6483 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6484 | bool ValidateTexStorageMultisample(Context *context, |
| 6485 | TextureType target, |
| 6486 | GLsizei samples, |
| 6487 | GLint internalFormat, |
| 6488 | GLsizei width, |
| 6489 | GLsizei height) |
| 6490 | { |
| 6491 | const Caps &caps = context->getCaps(); |
| 6492 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6493 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6494 | { |
| 6495 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureWidthOrHeightOutOfRange); |
| 6496 | return false; |
| 6497 | } |
| 6498 | |
| 6499 | if (samples == 0) |
| 6500 | { |
| 6501 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SamplesZero); |
| 6502 | return false; |
| 6503 | } |
| 6504 | |
| 6505 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6506 | if (!formatCaps.textureAttachment) |
| 6507 | { |
| 6508 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), RenderableInternalFormat); |
| 6509 | return false; |
| 6510 | } |
| 6511 | |
| 6512 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6513 | // is one of the unsized base internalformats listed in table 8.11. |
| 6514 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6515 | if (formatInfo.internalFormat == GL_NONE) |
| 6516 | { |
| 6517 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnsizedInternalFormatUnsupported); |
| 6518 | return false; |
| 6519 | } |
| 6520 | |
| 6521 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6522 | { |
| 6523 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), SamplesOutOfRange); |
| 6524 | return false; |
| 6525 | } |
| 6526 | |
| 6527 | Texture *texture = context->getTargetTexture(target); |
| 6528 | if (!texture || texture->id() == 0) |
| 6529 | { |
| 6530 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ZeroBoundToTarget); |
| 6531 | return false; |
| 6532 | } |
| 6533 | |
| 6534 | if (texture->getImmutableFormat()) |
| 6535 | { |
| 6536 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ImmutableTextureBound); |
| 6537 | return false; |
| 6538 | } |
| 6539 | return true; |
| 6540 | } |
| 6541 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6542 | } // namespace gl |