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 | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame^] | 26 | #include "libANGLE/validationES2_autogen.h" |
| 27 | #include "libANGLE/validationES3_autogen.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 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 232 | case GL_CLAMP_TO_BORDER: |
| 233 | if (!context->getExtensions().textureBorderClamp) |
| 234 | { |
| 235 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 236 | return false; |
| 237 | } |
| 238 | break; |
| 239 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 240 | case GL_REPEAT: |
| 241 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 242 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 243 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 244 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 245 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 246 | return false; |
| 247 | } |
| 248 | break; |
| 249 | |
| 250 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 251 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 252 | return false; |
| 253 | } |
| 254 | |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 259 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 260 | { |
| 261 | switch (ConvertToGLenum(params[0])) |
| 262 | { |
| 263 | case GL_NEAREST: |
| 264 | case GL_LINEAR: |
| 265 | break; |
| 266 | |
| 267 | case GL_NEAREST_MIPMAP_NEAREST: |
| 268 | case GL_LINEAR_MIPMAP_NEAREST: |
| 269 | case GL_NEAREST_MIPMAP_LINEAR: |
| 270 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 271 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 272 | { |
| 273 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 274 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | break; |
| 278 | |
| 279 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 280 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | template <typename ParamType> |
| 288 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 289 | { |
| 290 | switch (ConvertToGLenum(params[0])) |
| 291 | { |
| 292 | case GL_NEAREST: |
| 293 | case GL_LINEAR: |
| 294 | break; |
| 295 | |
| 296 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 297 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 298 | return false; |
| 299 | } |
| 300 | |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | template <typename ParamType> |
| 305 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 306 | { |
| 307 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 308 | switch (ConvertToGLenum(params[0])) |
| 309 | { |
| 310 | case GL_NONE: |
| 311 | case GL_COMPARE_REF_TO_TEXTURE: |
| 312 | break; |
| 313 | |
| 314 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 315 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 316 | return false; |
| 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
| 322 | template <typename ParamType> |
| 323 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 324 | { |
| 325 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 326 | switch (ConvertToGLenum(params[0])) |
| 327 | { |
| 328 | case GL_LEQUAL: |
| 329 | case GL_GEQUAL: |
| 330 | case GL_LESS: |
| 331 | case GL_GREATER: |
| 332 | case GL_EQUAL: |
| 333 | case GL_NOTEQUAL: |
| 334 | case GL_ALWAYS: |
| 335 | case GL_NEVER: |
| 336 | break; |
| 337 | |
| 338 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 339 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 340 | return false; |
| 341 | } |
| 342 | |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 347 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 348 | { |
| 349 | if (!context->getExtensions().textureSRGBDecode) |
| 350 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 351 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 352 | return false; |
| 353 | } |
| 354 | |
| 355 | switch (ConvertToGLenum(params[0])) |
| 356 | { |
| 357 | case GL_DECODE_EXT: |
| 358 | case GL_SKIP_DECODE_EXT: |
| 359 | break; |
| 360 | |
| 361 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 362 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | |
| 366 | return true; |
| 367 | } |
| 368 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 369 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 370 | { |
| 371 | if (!context->getExtensions().textureFilterAnisotropic) |
| 372 | { |
| 373 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 381 | { |
| 382 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 388 | |
| 389 | if (paramValue < 1 || paramValue > largest) |
| 390 | { |
| 391 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 392 | return false; |
| 393 | } |
| 394 | |
| 395 | return true; |
| 396 | } |
| 397 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 398 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 399 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 400 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 401 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 402 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 403 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 404 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 405 | program->getActiveOutputVariables().to_ulong(), |
| 406 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 409 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 410 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 411 | const auto &glState = context->getGLState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 412 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 413 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 414 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 415 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 416 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 417 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 418 | |
| 419 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 420 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 421 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 422 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 423 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 424 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 425 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 428 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 429 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 430 | { |
| 431 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 432 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 433 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 434 | case PrimitiveMode::Points: |
| 435 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 436 | case PrimitiveMode::Lines: |
| 437 | case PrimitiveMode::LineStrip: |
| 438 | case PrimitiveMode::LineLoop: |
| 439 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 440 | case PrimitiveMode::LinesAdjacency: |
| 441 | case PrimitiveMode::LineStripAdjacency: |
| 442 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 443 | case PrimitiveMode::Triangles: |
| 444 | case PrimitiveMode::TriangleFan: |
| 445 | case PrimitiveMode::TriangleStrip: |
| 446 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 447 | case PrimitiveMode::TrianglesAdjacency: |
| 448 | case PrimitiveMode::TriangleStripAdjacency: |
| 449 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 450 | default: |
| 451 | UNREACHABLE(); |
| 452 | return false; |
| 453 | } |
| 454 | } |
| 455 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 456 | // GLES1 texture parameters are a small subset of the others |
| 457 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 458 | { |
| 459 | switch (pname) |
| 460 | { |
| 461 | case GL_TEXTURE_MAG_FILTER: |
| 462 | case GL_TEXTURE_MIN_FILTER: |
| 463 | case GL_TEXTURE_WRAP_S: |
| 464 | case GL_TEXTURE_WRAP_T: |
| 465 | case GL_TEXTURE_WRAP_R: |
| 466 | case GL_GENERATE_MIPMAP: |
| 467 | case GL_TEXTURE_CROP_RECT_OES: |
| 468 | return true; |
| 469 | default: |
| 470 | return false; |
| 471 | } |
| 472 | } |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 473 | |
| 474 | unsigned int GetSamplerParameterCount(GLenum pname) |
| 475 | { |
| 476 | return pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1; |
| 477 | } |
| 478 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 479 | } // anonymous namespace |
| 480 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 481 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 482 | { |
| 483 | if (length) |
| 484 | { |
| 485 | *length = value; |
| 486 | } |
| 487 | } |
| 488 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 489 | bool IsETC2EACFormat(const GLenum format) |
| 490 | { |
| 491 | // ES 3.1, Table 8.19 |
| 492 | switch (format) |
| 493 | { |
| 494 | case GL_COMPRESSED_R11_EAC: |
| 495 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 496 | case GL_COMPRESSED_RG11_EAC: |
| 497 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 498 | case GL_COMPRESSED_RGB8_ETC2: |
| 499 | case GL_COMPRESSED_SRGB8_ETC2: |
| 500 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 501 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 502 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 503 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 504 | return true; |
| 505 | |
| 506 | default: |
| 507 | return false; |
| 508 | } |
| 509 | } |
| 510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 511 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 512 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 513 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 514 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 515 | case TextureType::_2D: |
| 516 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 517 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 518 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 519 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 520 | return context->getExtensions().textureRectangle; |
| 521 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 522 | case TextureType::_3D: |
| 523 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 524 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 525 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 526 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 527 | return (context->getClientVersion() >= Version(3, 1) || |
| 528 | context->getExtensions().textureMultisample); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 529 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 530 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 531 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 532 | default: |
| 533 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 534 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 537 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 538 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 539 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 540 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 541 | case TextureType::_2D: |
| 542 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 543 | return true; |
| 544 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 545 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 546 | return context->getExtensions().textureRectangle; |
| 547 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 548 | default: |
| 549 | return false; |
| 550 | } |
| 551 | } |
| 552 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 553 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 554 | { |
| 555 | switch (target) |
| 556 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 557 | case TextureType::_3D: |
| 558 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 559 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 560 | |
| 561 | default: |
| 562 | return false; |
| 563 | } |
| 564 | } |
| 565 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 566 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 567 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 568 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 569 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 570 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 571 | (context->getExtensions().eglImageExternal || |
| 572 | context->getExtensions().eglStreamConsumerExternal); |
| 573 | } |
| 574 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 575 | // This function differs from ValidTextureTarget in that the target must be |
| 576 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 577 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 578 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 579 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 580 | { |
| 581 | switch (target) |
| 582 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 583 | case TextureTarget::_2D: |
| 584 | case TextureTarget::CubeMapNegativeX: |
| 585 | case TextureTarget::CubeMapNegativeY: |
| 586 | case TextureTarget::CubeMapNegativeZ: |
| 587 | case TextureTarget::CubeMapPositiveX: |
| 588 | case TextureTarget::CubeMapPositiveY: |
| 589 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 590 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 591 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 592 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 593 | default: |
| 594 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 598 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 599 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 600 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 601 | { |
| 602 | ASSERT(context); |
| 603 | |
| 604 | if (!context->getExtensions().geometryShader) |
| 605 | { |
| 606 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 607 | // that does not match the current transform feedback object's draw mode (if transform |
| 608 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 609 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 610 | } |
| 611 | |
| 612 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 613 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 614 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 615 | case PrimitiveMode::Points: |
| 616 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 617 | case PrimitiveMode::Lines: |
| 618 | case PrimitiveMode::LineStrip: |
| 619 | case PrimitiveMode::LineLoop: |
| 620 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 621 | case PrimitiveMode::Triangles: |
| 622 | case PrimitiveMode::TriangleFan: |
| 623 | case PrimitiveMode::TriangleStrip: |
| 624 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 625 | default: |
| 626 | UNREACHABLE(); |
| 627 | return false; |
| 628 | } |
| 629 | } |
| 630 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 631 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 632 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 633 | GLsizei count, |
| 634 | GLenum type, |
| 635 | const GLvoid *indices, |
| 636 | GLsizei primcount) |
| 637 | { |
| 638 | if (primcount < 0) |
| 639 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 640 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 641 | return false; |
| 642 | } |
| 643 | |
| 644 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 645 | { |
| 646 | return false; |
| 647 | } |
| 648 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 649 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 653 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 654 | GLint first, |
| 655 | GLsizei count, |
| 656 | GLsizei primcount) |
| 657 | { |
| 658 | if (primcount < 0) |
| 659 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 660 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 661 | return false; |
| 662 | } |
| 663 | |
| 664 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 665 | { |
| 666 | return false; |
| 667 | } |
| 668 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 669 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 672 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 673 | { |
| 674 | // Verify there is at least one active attribute with a divisor of zero |
| 675 | const State &state = context->getGLState(); |
| 676 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 677 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 678 | |
| 679 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 680 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 681 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 682 | { |
| 683 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 684 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 685 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 686 | { |
| 687 | return true; |
| 688 | } |
| 689 | } |
| 690 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 691 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 692 | return false; |
| 693 | } |
| 694 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 695 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 696 | { |
| 697 | switch (target) |
| 698 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 699 | case TextureType::_3D: |
| 700 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 701 | return true; |
| 702 | default: |
| 703 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 707 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 708 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 709 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 710 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 711 | case TextureType::_2D: |
| 712 | case TextureType::_2DArray: |
| 713 | case TextureType::_2DMultisample: |
| 714 | case TextureType::CubeMap: |
| 715 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 716 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 717 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 718 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 719 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 720 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 721 | default: |
| 722 | return false; |
| 723 | } |
| 724 | } |
| 725 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 726 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 727 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 728 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 729 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 730 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 731 | |
| 732 | switch (target) |
| 733 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 734 | case GL_FRAMEBUFFER: |
| 735 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 736 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 737 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 738 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 739 | return (context->getExtensions().framebufferBlit || |
| 740 | context->getClientMajorVersion() >= 3); |
| 741 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 742 | default: |
| 743 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 747 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 748 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 749 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 750 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 751 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 752 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 753 | case TextureType::_2D: |
| 754 | case TextureType::_2DArray: |
| 755 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 756 | case TextureType::_2DMultisampleArray: |
| 757 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 758 | // 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] | 759 | maxDimension = caps.max2DTextureSize; |
| 760 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 761 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 762 | maxDimension = caps.maxCubeMapTextureSize; |
| 763 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 764 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 765 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 766 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 767 | maxDimension = caps.max3DTextureSize; |
| 768 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 769 | default: |
| 770 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 773 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 774 | } |
| 775 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 776 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 777 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 778 | GLint level, |
| 779 | GLsizei width, |
| 780 | GLsizei height, |
| 781 | GLsizei depth, |
| 782 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 783 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 784 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 785 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 786 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 787 | return false; |
| 788 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 789 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 790 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 791 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 792 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 793 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 794 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 795 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 796 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 797 | return false; |
| 798 | } |
| 799 | |
| 800 | if (!ValidMipLevel(context, target, level)) |
| 801 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 802 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 803 | return false; |
| 804 | } |
| 805 | |
| 806 | return true; |
| 807 | } |
| 808 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 809 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 810 | { |
| 811 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 812 | (size % blockSize == 0); |
| 813 | } |
| 814 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 815 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 816 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 817 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 818 | GLsizei width, |
| 819 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 820 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 821 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 822 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 823 | { |
| 824 | return false; |
| 825 | } |
| 826 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 827 | if (width < 0 || height < 0) |
| 828 | { |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 833 | { |
| 834 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 835 | // block size for level 0 but WebGL disallows this. |
| 836 | bool smallerThanBlockSizeAllowed = |
| 837 | level > 0 || !context->getExtensions().webglCompatibility; |
| 838 | |
| 839 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 840 | smallerThanBlockSizeAllowed) || |
| 841 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 842 | smallerThanBlockSizeAllowed)) |
| 843 | { |
| 844 | return false; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | return true; |
| 849 | } |
| 850 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 851 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 852 | GLenum internalFormat, |
| 853 | GLint xoffset, |
| 854 | GLint yoffset, |
| 855 | GLsizei width, |
| 856 | GLsizei height, |
| 857 | size_t textureWidth, |
| 858 | size_t textureHeight) |
| 859 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 860 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 861 | if (!formatInfo.compressed) |
| 862 | { |
| 863 | return false; |
| 864 | } |
| 865 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 866 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 867 | { |
| 868 | return false; |
| 869 | } |
| 870 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 871 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 872 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 873 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 874 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 875 | { |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 880 | // size but fills the entire mip |
| 881 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 882 | static_cast<size_t>(width) == textureWidth && |
| 883 | static_cast<size_t>(height) == textureHeight; |
| 884 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 885 | (height % formatInfo.compressedBlockHeight) == 0; |
| 886 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 887 | { |
| 888 | return false; |
| 889 | } |
| 890 | } |
| 891 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 892 | return true; |
| 893 | } |
| 894 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 895 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 896 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 897 | GLsizei width, |
| 898 | GLsizei height, |
| 899 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 900 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 901 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 902 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 903 | GLsizei imageSize) |
| 904 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 905 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 906 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 907 | { |
| 908 | // Checks are not required |
| 909 | return true; |
| 910 | } |
| 911 | |
| 912 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 913 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 914 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 915 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 916 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 917 | const auto &unpack = context->getGLState().getUnpackState(); |
| 918 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 919 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 920 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 921 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 922 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 923 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 924 | return false; |
| 925 | } |
| 926 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 927 | if (pixelUnpackBuffer) |
| 928 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 929 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 930 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 931 | checkedEndByte += checkedOffset; |
| 932 | |
| 933 | if (!checkedEndByte.IsValid() || |
| 934 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 935 | { |
| 936 | // Overflow past the end of the buffer |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 937 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 938 | return false; |
| 939 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 940 | if (context->getExtensions().webglCompatibility && |
| 941 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 942 | { |
| 943 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 944 | PixelUnpackBufferBoundForTransformFeedback); |
| 945 | return false; |
| 946 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 947 | } |
| 948 | else |
| 949 | { |
| 950 | ASSERT(imageSize >= 0); |
| 951 | if (pixels == nullptr && imageSize != 0) |
| 952 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 953 | context->handleError(InvalidOperation() |
| 954 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 955 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 956 | } |
| 957 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 958 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 959 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 960 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 961 | return false; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | return true; |
| 966 | } |
| 967 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 968 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 969 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 970 | switch (queryType) |
| 971 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 972 | case QueryType::AnySamples: |
| 973 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 974 | return context->getClientMajorVersion() >= 3 || |
| 975 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 976 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 977 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 978 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 979 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 980 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 981 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 982 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 983 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 984 | default: |
| 985 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 989 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 990 | GLenum type, |
| 991 | GLboolean normalized, |
| 992 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 993 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 994 | bool pureInteger) |
| 995 | { |
| 996 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 997 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 998 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 999 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1000 | // parameter exceeds 255. |
| 1001 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1002 | if (stride > kMaxWebGLStride) |
| 1003 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1004 | context->handleError(InvalidValue() |
| 1005 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1010 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1011 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1012 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 1013 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 1014 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1015 | |
| 1016 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1017 | size_t sizeMask = (typeSize - 1); |
| 1018 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1019 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1020 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | if ((stride & sizeMask) != 0) |
| 1025 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1026 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1027 | return false; |
| 1028 | } |
| 1029 | |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1033 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1034 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1035 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1036 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1037 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1038 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1039 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1040 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1041 | |
| 1042 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1043 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1044 | if (context->getShader(id)) |
| 1045 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1046 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1047 | } |
| 1048 | else |
| 1049 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1050 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1051 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1052 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1053 | |
| 1054 | return validProgram; |
| 1055 | } |
| 1056 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1057 | Program *GetValidProgram(Context *context, GLuint id) |
| 1058 | { |
| 1059 | Program *program = GetValidProgramNoResolve(context, id); |
| 1060 | if (program) |
| 1061 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1062 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1063 | } |
| 1064 | return program; |
| 1065 | } |
| 1066 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1067 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1068 | { |
| 1069 | // See ValidProgram for spec details. |
| 1070 | |
| 1071 | Shader *validShader = context->getShader(id); |
| 1072 | |
| 1073 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1074 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1075 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1076 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1077 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1078 | } |
| 1079 | else |
| 1080 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1081 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1082 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1083 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1084 | |
| 1085 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1086 | } |
| 1087 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1088 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1089 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1090 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1091 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1092 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1093 | { |
| 1094 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1095 | return false; |
| 1096 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1097 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1098 | // Color attachment 0 is validated below because it is always valid |
| 1099 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1100 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1101 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1102 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1103 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | switch (attachment) |
| 1109 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1110 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1111 | case GL_DEPTH_ATTACHMENT: |
| 1112 | case GL_STENCIL_ATTACHMENT: |
| 1113 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1114 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1115 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1116 | if (!context->getExtensions().webglCompatibility && |
| 1117 | context->getClientMajorVersion() < 3) |
| 1118 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1119 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | return false; |
| 1121 | } |
| 1122 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1123 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1124 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1125 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1126 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | return true; |
| 1131 | } |
| 1132 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1133 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1134 | GLenum target, |
| 1135 | GLsizei samples, |
| 1136 | GLenum internalformat, |
| 1137 | GLsizei width, |
| 1138 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1139 | { |
| 1140 | switch (target) |
| 1141 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1142 | case GL_RENDERBUFFER: |
| 1143 | break; |
| 1144 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1145 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1146 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (width < 0 || height < 0 || samples < 0) |
| 1150 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1151 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1152 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1153 | } |
| 1154 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1155 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1156 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1157 | |
| 1158 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1159 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1160 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1161 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1162 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1166 | // 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] | 1167 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1168 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1169 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1171 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1172 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1175 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1177 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1178 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1181 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1182 | if (handle == 0) |
| 1183 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1184 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1185 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | return true; |
| 1189 | } |
| 1190 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1191 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1192 | GLenum target, |
| 1193 | GLenum attachment, |
| 1194 | GLenum renderbuffertarget, |
| 1195 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1196 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1197 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1198 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1199 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1200 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1203 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1204 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1205 | ASSERT(framebuffer); |
| 1206 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1207 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1208 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1209 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1212 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1213 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1214 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1215 | } |
| 1216 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1217 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1218 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1219 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1220 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1221 | if (renderbuffer != 0) |
| 1222 | { |
| 1223 | if (!context->getRenderbuffer(renderbuffer)) |
| 1224 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1225 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1226 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1230 | return true; |
| 1231 | } |
| 1232 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1233 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1234 | GLint srcX0, |
| 1235 | GLint srcY0, |
| 1236 | GLint srcX1, |
| 1237 | GLint srcY1, |
| 1238 | GLint dstX0, |
| 1239 | GLint dstY0, |
| 1240 | GLint dstX1, |
| 1241 | GLint dstY1, |
| 1242 | GLbitfield mask, |
| 1243 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1244 | { |
| 1245 | switch (filter) |
| 1246 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1247 | case GL_NEAREST: |
| 1248 | break; |
| 1249 | case GL_LINEAR: |
| 1250 | break; |
| 1251 | default: |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1252 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), BlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1253 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1257 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1258 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1259 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1262 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1263 | // color buffer, leaving only nearest being unfiltered from above |
| 1264 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1265 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1266 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1267 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1270 | const auto &glState = context->getGLState(); |
| 1271 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1272 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1273 | |
| 1274 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1275 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1276 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1277 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1280 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1281 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1282 | return false; |
| 1283 | } |
| 1284 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1285 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1286 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1290 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1291 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1292 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1296 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1297 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1298 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1301 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1302 | // always run it in order to avoid triggering driver bugs. |
| 1303 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1304 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1305 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1306 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1307 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1308 | } |
| 1309 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1311 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1313 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1314 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1315 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1316 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1317 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1318 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1319 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1320 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1321 | for (size_t drawbufferIdx = 0; |
| 1322 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1323 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1324 | const FramebufferAttachment *attachment = |
| 1325 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1326 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1327 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1328 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1329 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1330 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1331 | // 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] | 1332 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1333 | // as well |
| 1334 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1335 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1336 | // Changes with EXT_color_buffer_float: |
| 1337 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1338 | GLenum readComponentType = readFormat.info->componentType; |
| 1339 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1340 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1341 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1342 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1343 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1344 | |
| 1345 | if (extensions.colorBufferFloat) |
| 1346 | { |
| 1347 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1348 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1349 | |
| 1350 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1351 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1352 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1353 | BlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | } |
| 1357 | else if (readFixedPoint != drawFixedPoint) |
| 1358 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1359 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1360 | BlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | if (readComponentType == GL_UNSIGNED_INT && |
| 1365 | drawComponentType != GL_UNSIGNED_INT) |
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 | BlitTypeMismatchUnsignedInteger); |
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 | } |
| 1371 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1372 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1373 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1374 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1375 | BlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1376 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1379 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1380 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1381 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1382 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1383 | BlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1384 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1385 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1386 | |
| 1387 | if (context->getExtensions().webglCompatibility && |
| 1388 | *readColorBuffer == *attachment) |
| 1389 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1390 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1391 | return false; |
| 1392 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1396 | if ((readFormat.info->componentType == GL_INT || |
| 1397 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1398 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1399 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1400 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1401 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1402 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1404 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1405 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1406 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1407 | // situation is an application error that would lead to a crash in ANGLE. |
| 1408 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1409 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1410 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1411 | return false; |
| 1412 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1415 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1416 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1417 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1419 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1421 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1422 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1423 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1424 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1426 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1427 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1428 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1429 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1430 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1431 | BlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1432 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1433 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1434 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1435 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1436 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1437 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1438 | BlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1439 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1440 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1441 | |
| 1442 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1443 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1444 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1447 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1448 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1449 | else if (drawBuffer) |
| 1450 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1451 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1457 | // ANGLE_multiview, Revision 1: |
| 1458 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1459 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1460 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1461 | // views in the current read framebuffer is more than one. |
| 1462 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1463 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1464 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1465 | return false; |
| 1466 | } |
| 1467 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1468 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1469 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1470 | return false; |
| 1471 | } |
| 1472 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1473 | return true; |
| 1474 | } |
| 1475 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1476 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1477 | GLint x, |
| 1478 | GLint y, |
| 1479 | GLsizei width, |
| 1480 | GLsizei height, |
| 1481 | GLenum format, |
| 1482 | GLenum type, |
| 1483 | GLsizei bufSize, |
| 1484 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1485 | GLsizei *columns, |
| 1486 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1487 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1488 | { |
| 1489 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1490 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1491 | return false; |
| 1492 | } |
| 1493 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1494 | GLsizei writeLength = 0; |
| 1495 | GLsizei writeColumns = 0; |
| 1496 | GLsizei writeRows = 0; |
| 1497 | |
| 1498 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1499 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1500 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1501 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1502 | } |
| 1503 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1504 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1505 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1506 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1507 | } |
| 1508 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1509 | SetRobustLengthParam(length, writeLength); |
| 1510 | SetRobustLengthParam(columns, writeColumns); |
| 1511 | SetRobustLengthParam(rows, writeRows); |
| 1512 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1513 | return true; |
| 1514 | } |
| 1515 | |
| 1516 | bool ValidateReadnPixelsEXT(Context *context, |
| 1517 | GLint x, |
| 1518 | GLint y, |
| 1519 | GLsizei width, |
| 1520 | GLsizei height, |
| 1521 | GLenum format, |
| 1522 | GLenum type, |
| 1523 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1524 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1525 | { |
| 1526 | if (bufSize < 0) |
| 1527 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1528 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1532 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1533 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1534 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1535 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1536 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1537 | GLint x, |
| 1538 | GLint y, |
| 1539 | GLsizei width, |
| 1540 | GLsizei height, |
| 1541 | GLenum format, |
| 1542 | GLenum type, |
| 1543 | GLsizei bufSize, |
| 1544 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1545 | GLsizei *columns, |
| 1546 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1547 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1548 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1549 | GLsizei writeLength = 0; |
| 1550 | GLsizei writeColumns = 0; |
| 1551 | GLsizei writeRows = 0; |
| 1552 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1553 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1554 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
| 1557 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1558 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1559 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1560 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1561 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1564 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1565 | { |
| 1566 | return false; |
| 1567 | } |
| 1568 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1569 | SetRobustLengthParam(length, writeLength); |
| 1570 | SetRobustLengthParam(columns, writeColumns); |
| 1571 | SetRobustLengthParam(rows, writeRows); |
| 1572 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1573 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1574 | } |
| 1575 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1576 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1577 | { |
| 1578 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1579 | !context->getExtensions().disjointTimerQuery) |
| 1580 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1581 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1582 | return false; |
| 1583 | } |
| 1584 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1585 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1586 | } |
| 1587 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1588 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1589 | { |
| 1590 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1591 | !context->getExtensions().disjointTimerQuery) |
| 1592 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1593 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1594 | return false; |
| 1595 | } |
| 1596 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1597 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1598 | } |
| 1599 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1600 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1601 | { |
| 1602 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1603 | !context->getExtensions().disjointTimerQuery) |
| 1604 | { |
| 1605 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
| 1609 | return true; |
| 1610 | } |
| 1611 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1612 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1613 | { |
| 1614 | if (!ValidQueryType(context, target)) |
| 1615 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1616 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1617 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | if (id == 0) |
| 1621 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1622 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1623 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1627 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1628 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1629 | // the active query for either target is non-zero), if <id> is the name of an |
| 1630 | // existing query object whose type does not match <target>, or if <id> is the |
| 1631 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1632 | // generated. |
| 1633 | |
| 1634 | // Ensure no other queries are active |
| 1635 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1636 | // separately that: |
| 1637 | // a) The query ID passed is not the current active query for any target/type |
| 1638 | // b) There are no active queries for the requested target (and in the case |
| 1639 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1640 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1641 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1642 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1643 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1644 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1645 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | Query *queryObject = context->getQuery(id, true, target); |
| 1649 | |
| 1650 | // check that name was obtained with glGenQueries |
| 1651 | if (!queryObject) |
| 1652 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1653 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1654 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | // check for type mismatch |
| 1658 | if (queryObject->getType() != target) |
| 1659 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1660 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1661 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | return true; |
| 1665 | } |
| 1666 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1667 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1668 | { |
| 1669 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1670 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1671 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1672 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1673 | return false; |
| 1674 | } |
| 1675 | |
| 1676 | return ValidateBeginQueryBase(context, target, id); |
| 1677 | } |
| 1678 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1679 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1680 | { |
| 1681 | if (!ValidQueryType(context, target)) |
| 1682 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1683 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1684 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1687 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1688 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1689 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1690 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1691 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1692 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1695 | return true; |
| 1696 | } |
| 1697 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1698 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1699 | { |
| 1700 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1701 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1702 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1703 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | return ValidateEndQueryBase(context, target); |
| 1708 | } |
| 1709 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1710 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1711 | { |
| 1712 | if (!context->getExtensions().disjointTimerQuery) |
| 1713 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1714 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1715 | return false; |
| 1716 | } |
| 1717 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1718 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1719 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1720 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1721 | return false; |
| 1722 | } |
| 1723 | |
| 1724 | Query *queryObject = context->getQuery(id, true, target); |
| 1725 | if (queryObject == nullptr) |
| 1726 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1727 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1728 | return false; |
| 1729 | } |
| 1730 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1731 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1732 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1733 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1734 | return false; |
| 1735 | } |
| 1736 | |
| 1737 | return true; |
| 1738 | } |
| 1739 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1740 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1741 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1742 | if (numParams) |
| 1743 | { |
| 1744 | *numParams = 0; |
| 1745 | } |
| 1746 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1747 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1748 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1749 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | switch (pname) |
| 1754 | { |
| 1755 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1756 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1757 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1758 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1759 | return false; |
| 1760 | } |
| 1761 | break; |
| 1762 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1763 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1764 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1765 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1766 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1767 | return false; |
| 1768 | } |
| 1769 | break; |
| 1770 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1771 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1772 | return false; |
| 1773 | } |
| 1774 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1775 | if (numParams) |
| 1776 | { |
| 1777 | // All queries return only one value |
| 1778 | *numParams = 1; |
| 1779 | } |
| 1780 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1781 | return true; |
| 1782 | } |
| 1783 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1784 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1785 | { |
| 1786 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1787 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1788 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1789 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1790 | return false; |
| 1791 | } |
| 1792 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1793 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1794 | } |
| 1795 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1796 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1797 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1798 | GLenum pname, |
| 1799 | GLsizei bufSize, |
| 1800 | GLsizei *length, |
| 1801 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1802 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1803 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1804 | { |
| 1805 | return false; |
| 1806 | } |
| 1807 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1808 | GLsizei numParams = 0; |
| 1809 | |
| 1810 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1811 | { |
| 1812 | return false; |
| 1813 | } |
| 1814 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1815 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1816 | { |
| 1817 | return false; |
| 1818 | } |
| 1819 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1820 | SetRobustLengthParam(length, numParams); |
| 1821 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1822 | return true; |
| 1823 | } |
| 1824 | |
| 1825 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1826 | { |
| 1827 | if (numParams) |
| 1828 | { |
| 1829 | *numParams = 0; |
| 1830 | } |
| 1831 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1832 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1833 | |
| 1834 | if (!queryObject) |
| 1835 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1836 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1840 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1841 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1842 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | switch (pname) |
| 1847 | { |
| 1848 | case GL_QUERY_RESULT_EXT: |
| 1849 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1850 | break; |
| 1851 | |
| 1852 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1853 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
| 1856 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1857 | if (numParams) |
| 1858 | { |
| 1859 | *numParams = 1; |
| 1860 | } |
| 1861 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1862 | return true; |
| 1863 | } |
| 1864 | |
| 1865 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, 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"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1870 | return false; |
| 1871 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1872 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1873 | } |
| 1874 | |
| 1875 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1876 | GLuint id, |
| 1877 | GLenum pname, |
| 1878 | GLsizei bufSize, |
| 1879 | GLsizei *length, |
| 1880 | GLint *params) |
| 1881 | { |
| 1882 | if (!context->getExtensions().disjointTimerQuery) |
| 1883 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1884 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1885 | return false; |
| 1886 | } |
| 1887 | |
| 1888 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1889 | { |
| 1890 | return false; |
| 1891 | } |
| 1892 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1893 | GLsizei numParams = 0; |
| 1894 | |
| 1895 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1896 | { |
| 1897 | return false; |
| 1898 | } |
| 1899 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1900 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1901 | { |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1905 | SetRobustLengthParam(length, numParams); |
| 1906 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1907 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1911 | { |
| 1912 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1913 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1914 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1915 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1916 | return false; |
| 1917 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1918 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1919 | } |
| 1920 | |
| 1921 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1922 | GLuint id, |
| 1923 | GLenum pname, |
| 1924 | GLsizei bufSize, |
| 1925 | GLsizei *length, |
| 1926 | GLuint *params) |
| 1927 | { |
| 1928 | if (!context->getExtensions().disjointTimerQuery && |
| 1929 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1930 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1931 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1932 | return false; |
| 1933 | } |
| 1934 | |
| 1935 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1936 | { |
| 1937 | return false; |
| 1938 | } |
| 1939 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1940 | GLsizei numParams = 0; |
| 1941 | |
| 1942 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1943 | { |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1947 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1948 | { |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1952 | SetRobustLengthParam(length, numParams); |
| 1953 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1954 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, 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); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1962 | return false; |
| 1963 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1964 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1965 | } |
| 1966 | |
| 1967 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1968 | GLuint id, |
| 1969 | GLenum pname, |
| 1970 | GLsizei bufSize, |
| 1971 | GLsizei *length, |
| 1972 | GLint64 *params) |
| 1973 | { |
| 1974 | if (!context->getExtensions().disjointTimerQuery) |
| 1975 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1976 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1977 | return false; |
| 1978 | } |
| 1979 | |
| 1980 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1981 | { |
| 1982 | return false; |
| 1983 | } |
| 1984 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1985 | GLsizei numParams = 0; |
| 1986 | |
| 1987 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1988 | { |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1992 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1993 | { |
| 1994 | return false; |
| 1995 | } |
| 1996 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1997 | SetRobustLengthParam(length, numParams); |
| 1998 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1999 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, 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); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2009 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2010 | } |
| 2011 | |
| 2012 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2013 | GLuint id, |
| 2014 | GLenum pname, |
| 2015 | GLsizei bufSize, |
| 2016 | GLsizei *length, |
| 2017 | GLuint64 *params) |
| 2018 | { |
| 2019 | if (!context->getExtensions().disjointTimerQuery) |
| 2020 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2021 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2022 | return false; |
| 2023 | } |
| 2024 | |
| 2025 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2026 | { |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2030 | GLsizei numParams = 0; |
| 2031 | |
| 2032 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2033 | { |
| 2034 | return false; |
| 2035 | } |
| 2036 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2037 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2038 | { |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2042 | SetRobustLengthParam(length, numParams); |
| 2043 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2044 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2045 | } |
| 2046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2047 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2048 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2049 | GLint location, |
| 2050 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2051 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2052 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2053 | // TODO(Jiajia): Add image uniform check in future. |
| 2054 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2055 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2056 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
| 2059 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2060 | if (!program) |
| 2061 | { |
| 2062 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2063 | return false; |
| 2064 | } |
| 2065 | |
| 2066 | if (!program->isLinked()) |
| 2067 | { |
| 2068 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2069 | return false; |
| 2070 | } |
| 2071 | |
| 2072 | if (location == -1) |
| 2073 | { |
| 2074 | // Silently ignore the uniform command |
| 2075 | return false; |
| 2076 | } |
| 2077 | |
| 2078 | const auto &uniformLocations = program->getUniformLocations(); |
| 2079 | size_t castedLocation = static_cast<size_t>(location); |
| 2080 | if (castedLocation >= uniformLocations.size()) |
| 2081 | { |
| 2082 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2083 | return false; |
| 2084 | } |
| 2085 | |
| 2086 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2087 | if (uniformLocation.ignored) |
| 2088 | { |
| 2089 | // Silently ignore the uniform command |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | if (!uniformLocation.used()) |
| 2094 | { |
| 2095 | context->handleError(InvalidOperation()); |
| 2096 | return false; |
| 2097 | } |
| 2098 | |
| 2099 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2100 | |
| 2101 | // 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] | 2102 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2103 | { |
| 2104 | context->handleError(InvalidOperation()); |
| 2105 | return false; |
| 2106 | } |
| 2107 | |
| 2108 | *uniformOut = &uniform; |
| 2109 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2110 | } |
| 2111 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2112 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2113 | GLenum uniformType, |
| 2114 | GLsizei count, |
| 2115 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2116 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2117 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2118 | // It is compatible with INT or BOOL. |
| 2119 | // Do these cheap tests first, for a little extra speed. |
| 2120 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2121 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2122 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2123 | } |
| 2124 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2125 | if (IsSamplerType(uniformType)) |
| 2126 | { |
| 2127 | // Check that the values are in range. |
| 2128 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2129 | for (GLsizei i = 0; i < count; ++i) |
| 2130 | { |
| 2131 | if (value[i] < 0 || value[i] >= max) |
| 2132 | { |
| 2133 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2134 | return false; |
| 2135 | } |
| 2136 | } |
| 2137 | return true; |
| 2138 | } |
| 2139 | |
| 2140 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2141 | return false; |
| 2142 | } |
| 2143 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2144 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2145 | { |
| 2146 | // Check that the value type is compatible with uniform type. |
| 2147 | if (valueType == uniformType) |
| 2148 | { |
| 2149 | return true; |
| 2150 | } |
| 2151 | |
| 2152 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2153 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2154 | } |
| 2155 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2156 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2157 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2158 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2159 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2160 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2161 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2164 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2165 | { |
| 2166 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2167 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2168 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2169 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2170 | } |
| 2171 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2172 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2173 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2174 | GLint location, |
| 2175 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2176 | GLboolean transpose) |
| 2177 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2178 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2179 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2180 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2181 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2182 | } |
| 2183 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2184 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2185 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2186 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2187 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2188 | } |
| 2189 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2190 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2191 | { |
| 2192 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2193 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2194 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2195 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2196 | } |
| 2197 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2198 | const Caps &caps = context->getCaps(); |
| 2199 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2200 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2201 | { |
| 2202 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2203 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2204 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2205 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2206 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2207 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | switch (pname) |
| 2212 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2213 | case GL_TEXTURE_BINDING_2D: |
| 2214 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2215 | case GL_TEXTURE_BINDING_3D: |
| 2216 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2217 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2218 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2219 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2220 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2221 | { |
| 2222 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 2223 | return false; |
| 2224 | } |
| 2225 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2226 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2227 | if (!context->getExtensions().textureRectangle) |
| 2228 | { |
| 2229 | context->handleError(InvalidEnum() |
| 2230 | << "ANGLE_texture_rectangle extension not present"); |
| 2231 | return false; |
| 2232 | } |
| 2233 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2234 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2235 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2236 | !context->getExtensions().eglImageExternal) |
| 2237 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2238 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2239 | "nor GL_OES_EGL_image_external " |
| 2240 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2241 | return false; |
| 2242 | } |
| 2243 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2244 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2245 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2246 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2247 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2248 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2249 | ASSERT(readFramebuffer); |
| 2250 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2251 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2252 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2253 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2254 | } |
| 2255 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2256 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2257 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2258 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2259 | return false; |
| 2260 | } |
| 2261 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2262 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2263 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2264 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2265 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2266 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | break; |
| 2270 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2271 | default: |
| 2272 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2276 | if (*numParams == 0) |
| 2277 | { |
| 2278 | return false; |
| 2279 | } |
| 2280 | |
| 2281 | return true; |
| 2282 | } |
| 2283 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2284 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2285 | GLenum pname, |
| 2286 | GLsizei bufSize, |
| 2287 | GLsizei *length, |
| 2288 | GLboolean *params) |
| 2289 | { |
| 2290 | GLenum nativeType; |
| 2291 | unsigned int numParams = 0; |
| 2292 | |
| 2293 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2294 | { |
| 2295 | return false; |
| 2296 | } |
| 2297 | |
| 2298 | SetRobustLengthParam(length, numParams); |
| 2299 | |
| 2300 | return true; |
| 2301 | } |
| 2302 | |
| 2303 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2304 | GLenum pname, |
| 2305 | GLsizei bufSize, |
| 2306 | GLsizei *length, |
| 2307 | GLfloat *params) |
| 2308 | { |
| 2309 | GLenum nativeType; |
| 2310 | unsigned int numParams = 0; |
| 2311 | |
| 2312 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2313 | { |
| 2314 | return false; |
| 2315 | } |
| 2316 | |
| 2317 | SetRobustLengthParam(length, numParams); |
| 2318 | |
| 2319 | return true; |
| 2320 | } |
| 2321 | |
| 2322 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2323 | GLenum pname, |
| 2324 | GLsizei bufSize, |
| 2325 | GLsizei *length, |
| 2326 | GLint *data) |
| 2327 | { |
| 2328 | GLenum nativeType; |
| 2329 | unsigned int numParams = 0; |
| 2330 | |
| 2331 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2332 | { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | SetRobustLengthParam(length, numParams); |
| 2337 | |
| 2338 | return true; |
| 2339 | } |
| 2340 | |
| 2341 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2342 | GLenum pname, |
| 2343 | GLsizei bufSize, |
| 2344 | GLsizei *length, |
| 2345 | GLint64 *data) |
| 2346 | { |
| 2347 | GLenum nativeType; |
| 2348 | unsigned int numParams = 0; |
| 2349 | |
| 2350 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2351 | { |
| 2352 | return false; |
| 2353 | } |
| 2354 | |
| 2355 | if (nativeType == GL_INT_64_ANGLEX) |
| 2356 | { |
| 2357 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2358 | return false; |
| 2359 | } |
| 2360 | |
| 2361 | SetRobustLengthParam(length, numParams); |
| 2362 | return true; |
| 2363 | } |
| 2364 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2365 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2366 | GLenum pname, |
| 2367 | GLsizei bufSize, |
| 2368 | GLenum *nativeType, |
| 2369 | unsigned int *numParams) |
| 2370 | { |
| 2371 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2372 | { |
| 2373 | return false; |
| 2374 | } |
| 2375 | |
| 2376 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2377 | { |
| 2378 | return false; |
| 2379 | } |
| 2380 | |
| 2381 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2382 | { |
| 2383 | return false; |
| 2384 | } |
| 2385 | |
| 2386 | return true; |
| 2387 | } |
| 2388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2389 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2390 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2391 | GLint level, |
| 2392 | GLenum internalformat, |
| 2393 | bool isSubImage, |
| 2394 | GLint xoffset, |
| 2395 | GLint yoffset, |
| 2396 | GLint zoffset, |
| 2397 | GLint x, |
| 2398 | GLint y, |
| 2399 | GLsizei width, |
| 2400 | GLsizei height, |
| 2401 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2402 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2403 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2404 | TextureType texType = TextureTargetToType(target); |
| 2405 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2406 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2407 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2408 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2409 | return false; |
| 2410 | } |
| 2411 | |
| 2412 | if (width < 0 || height < 0) |
| 2413 | { |
| 2414 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2415 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2416 | } |
| 2417 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2418 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2419 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2420 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2421 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2422 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | if (border != 0) |
| 2426 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2427 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2428 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2429 | } |
| 2430 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2431 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2432 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2433 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2434 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2435 | } |
| 2436 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2437 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2438 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2439 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2440 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2441 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2442 | } |
| 2443 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2444 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2445 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2446 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2449 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2450 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2451 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2455 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2456 | // 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] | 2457 | // 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] | 2458 | // 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] | 2459 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2460 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2461 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2462 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2463 | return false; |
| 2464 | } |
| 2465 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2466 | // ANGLE_multiview spec, Revision 1: |
| 2467 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2468 | // 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] | 2469 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2470 | // framebuffer is more than one. |
| 2471 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2472 | { |
| 2473 | context->handleError(InvalidFramebufferOperation() |
| 2474 | << "The active read framebuffer object has multiview attachments."); |
| 2475 | return false; |
| 2476 | } |
| 2477 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2478 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2479 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2480 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2481 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2482 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2483 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2484 | maxDimension = caps.max2DTextureSize; |
| 2485 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2486 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2487 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2488 | maxDimension = caps.maxCubeMapTextureSize; |
| 2489 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2490 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2491 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2492 | maxDimension = caps.maxRectangleTextureSize; |
| 2493 | break; |
| 2494 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2495 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2496 | maxDimension = caps.max2DTextureSize; |
| 2497 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2498 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2499 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2500 | maxDimension = caps.max3DTextureSize; |
| 2501 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2502 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2503 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2504 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2505 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2506 | } |
| 2507 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2508 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2509 | if (!texture) |
| 2510 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2511 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2512 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2513 | } |
| 2514 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2515 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2516 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2517 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2518 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2519 | } |
| 2520 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2521 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2522 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2523 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2524 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2525 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2526 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2527 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2528 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2529 | } |
| 2530 | |
| 2531 | if (isSubImage) |
| 2532 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2533 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2534 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2535 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2536 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2537 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2538 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2539 | } |
| 2540 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2541 | else |
| 2542 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2543 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2544 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2545 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2546 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2547 | } |
| 2548 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2549 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2550 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2551 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2552 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2556 | if (static_cast<int>(width) > maxLevelDimension || |
| 2557 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2558 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2559 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2560 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2561 | } |
| 2562 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2563 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2564 | if (textureFormatOut) |
| 2565 | { |
| 2566 | *textureFormatOut = texture->getFormat(target, level); |
| 2567 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2568 | |
| 2569 | // Detect texture copying feedback loops for WebGL. |
| 2570 | if (context->getExtensions().webglCompatibility) |
| 2571 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2572 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2573 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2574 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2575 | return false; |
| 2576 | } |
| 2577 | } |
| 2578 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2579 | return true; |
| 2580 | } |
| 2581 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2582 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2583 | // completeness check. |
| 2584 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2585 | { |
| 2586 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2587 | const State &state = context->getGLState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2588 | |
| 2589 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2590 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2591 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2592 | VertexArray *vertexArray = state.getVertexArray(); |
| 2593 | ASSERT(vertexArray); |
| 2594 | |
| 2595 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2596 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2597 | return kErrorBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2601 | // Section 6.10 of the WebGL 1.0 spec. |
| 2602 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2603 | ASSERT(framebuffer); |
| 2604 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2605 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2606 | { |
| 2607 | ASSERT(framebuffer); |
| 2608 | const FramebufferAttachment *dsAttachment = |
| 2609 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2610 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2611 | ASSERT(stencilBits <= 8); |
| 2612 | |
| 2613 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2614 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2615 | { |
| 2616 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2617 | |
| 2618 | bool differentRefs = |
| 2619 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2620 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2621 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2622 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2623 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2624 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2625 | |
| 2626 | if (differentRefs || differentWritemasks || differentMasks) |
| 2627 | { |
| 2628 | if (!extensions.webglCompatibility) |
| 2629 | { |
| 2630 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2631 | "stencil writemasks, reference values, or stencil mask values."; |
| 2632 | } |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2633 | return kErrorStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | if (!framebuffer->isComplete(context)) |
| 2639 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2640 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
| 2641 | return kErrorDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2645 | { |
| 2646 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2647 | { |
| 2648 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2649 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2650 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2651 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2652 | return kErrorVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2656 | { |
| 2657 | // This is an application error that would normally result in a crash, but we catch it |
| 2658 | // and return an error |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2659 | return kErrorVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2660 | } |
| 2661 | } |
| 2662 | |
| 2663 | // If we are running GLES1, there is no current program. |
| 2664 | if (context->getClientVersion() >= Version(2, 0)) |
| 2665 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2666 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2667 | if (!program) |
| 2668 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2669 | return kErrorProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2673 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2674 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2675 | // produce undefined result. |
| 2676 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2677 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2678 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2679 | return kErrorNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2683 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2684 | return kErrorTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2685 | } |
| 2686 | |
| 2687 | if (extensions.multiview) |
| 2688 | { |
| 2689 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2690 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2691 | if (framebufferNumViews != programNumViews) |
| 2692 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2693 | return kErrorMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2697 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2698 | framebufferNumViews > 1) |
| 2699 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2700 | return kErrorMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2701 | } |
| 2702 | |
| 2703 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2704 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2705 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2706 | return kErrorMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2707 | } |
| 2708 | } |
| 2709 | |
| 2710 | // Uniform buffer validation |
| 2711 | for (unsigned int uniformBlockIndex = 0; |
| 2712 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2713 | { |
| 2714 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2715 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2716 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2717 | state.getIndexedUniformBuffer(blockBinding); |
| 2718 | |
| 2719 | if (uniformBuffer.get() == nullptr) |
| 2720 | { |
| 2721 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2722 | return kErrorUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2726 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2727 | { |
| 2728 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2729 | return kErrorUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | if (extensions.webglCompatibility && |
| 2733 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2734 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2735 | return kErrorUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2736 | } |
| 2737 | } |
| 2738 | |
| 2739 | // Do some additonal WebGL-specific validation |
| 2740 | if (extensions.webglCompatibility) |
| 2741 | { |
| 2742 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2743 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2744 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2745 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2746 | return kErrorTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2747 | } |
| 2748 | |
| 2749 | // Detect rendering feedback loops for WebGL. |
| 2750 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2751 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2752 | return kErrorFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2753 | } |
| 2754 | |
| 2755 | // Detect that the vertex shader input types match the attribute types |
| 2756 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2757 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2758 | return kErrorVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2759 | } |
| 2760 | |
| 2761 | // Detect that the color buffer types match the fragment shader output types |
| 2762 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2763 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2764 | return kErrorDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2765 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2766 | |
| 2767 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2768 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2769 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2770 | return kErrorVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2771 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2772 | } |
| 2773 | } |
| 2774 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2775 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2776 | } |
| 2777 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2778 | bool ValidateDrawMode(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2779 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2780 | const Extensions &extensions = context->getExtensions(); |
| 2781 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2782 | switch (mode) |
| 2783 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2784 | case PrimitiveMode::Points: |
| 2785 | case PrimitiveMode::Lines: |
| 2786 | case PrimitiveMode::LineLoop: |
| 2787 | case PrimitiveMode::LineStrip: |
| 2788 | case PrimitiveMode::Triangles: |
| 2789 | case PrimitiveMode::TriangleStrip: |
| 2790 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2791 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2792 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2793 | case PrimitiveMode::LinesAdjacency: |
| 2794 | case PrimitiveMode::LineStripAdjacency: |
| 2795 | case PrimitiveMode::TrianglesAdjacency: |
| 2796 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2797 | if (!extensions.geometryShader) |
| 2798 | { |
| 2799 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2800 | return false; |
| 2801 | } |
| 2802 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2803 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2804 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2805 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2806 | } |
| 2807 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2808 | // If we are running GLES1, there is no current program. |
| 2809 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2810 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2811 | const State &state = context->getGLState(); |
| 2812 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2813 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2814 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2815 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2816 | // Do geometry shader specific validations |
| 2817 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2818 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2819 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2820 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2821 | { |
| 2822 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2823 | IncompatibleDrawModeAgainstGeometryShader); |
| 2824 | return false; |
| 2825 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2826 | } |
| 2827 | } |
| 2828 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2829 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2830 | } |
| 2831 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2832 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
| 2833 | { |
| 2834 | if (!context->getStateCache().isValidDrawMode(mode)) |
| 2835 | { |
| 2836 | return ValidateDrawMode(context, mode); |
| 2837 | } |
| 2838 | |
| 2839 | if (count < 0) |
| 2840 | { |
| 2841 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 2842 | return false; |
| 2843 | } |
| 2844 | |
| 2845 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2846 | if (drawStatesError) |
| 2847 | { |
| 2848 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2849 | |
| 2850 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2851 | // Incomplete. |
| 2852 | GLenum errorCode = |
| 2853 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2854 | : GL_INVALID_OPERATION); |
| 2855 | context->handleError(Error(errorCode, errorMessage)); |
| 2856 | return false; |
| 2857 | } |
| 2858 | |
| 2859 | return true; |
| 2860 | } |
| 2861 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2862 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2863 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2864 | GLint first, |
| 2865 | GLsizei count, |
| 2866 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2867 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2868 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2869 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2870 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2871 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2872 | } |
| 2873 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2874 | if (count < 0) |
| 2875 | { |
| 2876 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 2877 | return false; |
| 2878 | } |
| 2879 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2880 | const State &state = context->getGLState(); |
| 2881 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2882 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2883 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2884 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2885 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2886 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2887 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2888 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2889 | return false; |
| 2890 | } |
| 2891 | |
| 2892 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2893 | { |
| 2894 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2895 | return false; |
| 2896 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2897 | } |
| 2898 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2899 | if (!context->getStateCache().isValidDrawMode(mode)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2900 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2901 | return ValidateDrawMode(context, mode); |
| 2902 | } |
| 2903 | |
| 2904 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2905 | if (drawStatesError) |
| 2906 | { |
| 2907 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2908 | |
| 2909 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2910 | // Incomplete. |
| 2911 | GLenum errorCode = |
| 2912 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2913 | : GL_INVALID_OPERATION); |
| 2914 | context->handleError(Error(errorCode, errorMessage)); |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2915 | return false; |
| 2916 | } |
| 2917 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2918 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2919 | // - first < 0 has been checked as an error condition. |
| 2920 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2921 | // 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] | 2922 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2923 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2924 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2925 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2926 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2927 | { |
| 2928 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2929 | return false; |
| 2930 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2931 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2932 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2933 | { |
| 2934 | return false; |
| 2935 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | return true; |
| 2939 | } |
| 2940 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2941 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2942 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2943 | GLint first, |
| 2944 | GLsizei count, |
| 2945 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2946 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2947 | if (!context->getExtensions().instancedArrays) |
| 2948 | { |
| 2949 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2953 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2954 | { |
| 2955 | return false; |
| 2956 | } |
| 2957 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2958 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2959 | } |
| 2960 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2961 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2962 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2963 | switch (type) |
| 2964 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2965 | case GL_UNSIGNED_BYTE: |
| 2966 | case GL_UNSIGNED_SHORT: |
| 2967 | break; |
| 2968 | case GL_UNSIGNED_INT: |
| 2969 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2970 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2971 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2972 | return false; |
| 2973 | } |
| 2974 | break; |
| 2975 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2976 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2977 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2978 | } |
| 2979 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2980 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2981 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2982 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2983 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2984 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2985 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2986 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2987 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2988 | if (context->getExtensions().geometryShader) |
| 2989 | { |
| 2990 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2991 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2992 | { |
| 2993 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2994 | return false; |
| 2995 | } |
| 2996 | } |
| 2997 | else |
| 2998 | { |
| 2999 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 3000 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 3001 | // 86) |
| 3002 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3003 | UnsupportedDrawModeForTransformFeedback); |
| 3004 | return false; |
| 3005 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3008 | return true; |
| 3009 | } |
| 3010 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3011 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3012 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3013 | GLsizei count, |
| 3014 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3015 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3016 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3017 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3018 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3019 | return false; |
| 3020 | |
| 3021 | const State &state = context->getGLState(); |
| 3022 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3023 | if (!ValidateDrawBase(context, mode, count)) |
| 3024 | { |
| 3025 | return false; |
| 3026 | } |
| 3027 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3028 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 3029 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3030 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3031 | GLuint typeBytes = GetTypeInfo(type).bytes; |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3032 | |
| 3033 | if (context->getExtensions().webglCompatibility) |
| 3034 | { |
| 3035 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3036 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3037 | { |
| 3038 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3039 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3040 | // 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] | 3041 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3042 | return false; |
| 3043 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3044 | |
| 3045 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3046 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3047 | // error is generated. |
| 3048 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3049 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3050 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3051 | return false; |
| 3052 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3053 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3054 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 3055 | { |
| 3056 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3057 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3058 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3059 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3060 | return false; |
| 3061 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3062 | |
| 3063 | if (context->getExtensions().webglCompatibility || |
| 3064 | !context->getGLState().areClientArraysEnabled()) |
| 3065 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3066 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3067 | { |
| 3068 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3069 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3070 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3071 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3072 | return false; |
| 3073 | } |
| 3074 | } |
| 3075 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3076 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3077 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3078 | // This is an application error that would normally result in a crash, but we catch it and |
| 3079 | // return an error |
| 3080 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3081 | return false; |
| 3082 | } |
| 3083 | |
| 3084 | if (count > 0 && elementArrayBuffer) |
| 3085 | { |
| 3086 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3087 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3088 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3089 | constexpr uint64_t kMaxTypeSize = 8; |
| 3090 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3091 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3092 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3093 | |
| 3094 | uint64_t typeSize = typeBytes; |
| 3095 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3096 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3097 | |
| 3098 | // Doing the multiplication here is overflow-safe |
| 3099 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3100 | |
| 3101 | // The offset can be any value, check for overflows |
| 3102 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3103 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3104 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3105 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3106 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3107 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3108 | |
| 3109 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3110 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3111 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3112 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3113 | return false; |
| 3114 | } |
| 3115 | |
| 3116 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3117 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3118 | { |
| 3119 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3120 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3121 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3122 | |
| 3123 | if (context->getExtensions().webglCompatibility && |
| 3124 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3125 | { |
| 3126 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3127 | ElementArrayBufferBoundForTransformFeedback); |
| 3128 | return false; |
| 3129 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3130 | } |
| 3131 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3132 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3133 | { |
| 3134 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 3135 | IndexRange indexRange; |
| 3136 | ANGLE_VALIDATION_TRY(vao->getIndexRange(context, type, count, indices, &indexRange)); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3137 | |
| 3138 | // If we use an index greater than our maximum supported index range, return an error. |
| 3139 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3140 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3141 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3142 | { |
| 3143 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3144 | return false; |
| 3145 | } |
| 3146 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3147 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3148 | { |
| 3149 | return false; |
| 3150 | } |
| 3151 | |
| 3152 | // 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] | 3153 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3154 | } |
| 3155 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3156 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3157 | } |
| 3158 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3159 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3160 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3161 | GLsizei count, |
| 3162 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3163 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3164 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3165 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3166 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3167 | } |
| 3168 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3169 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3170 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3171 | GLsizei count, |
| 3172 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3173 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3174 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3175 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3176 | if (!context->getExtensions().instancedArrays) |
| 3177 | { |
| 3178 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3179 | return false; |
| 3180 | } |
| 3181 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3182 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3183 | { |
| 3184 | return false; |
| 3185 | } |
| 3186 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3187 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3188 | } |
| 3189 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3190 | bool ValidateFramebufferTextureBase(Context *context, |
| 3191 | GLenum target, |
| 3192 | GLenum attachment, |
| 3193 | GLuint texture, |
| 3194 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3195 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3196 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3197 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3198 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3199 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3203 | { |
| 3204 | return false; |
| 3205 | } |
| 3206 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3207 | if (texture != 0) |
| 3208 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3209 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3210 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3211 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3212 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3213 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3214 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3215 | } |
| 3216 | |
| 3217 | if (level < 0) |
| 3218 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3219 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3220 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3221 | } |
| 3222 | } |
| 3223 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3224 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3225 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3226 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3227 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3228 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3229 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3230 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3231 | } |
| 3232 | |
| 3233 | return true; |
| 3234 | } |
| 3235 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3236 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3237 | { |
| 3238 | if (program == 0) |
| 3239 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3240 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3241 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3242 | } |
| 3243 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3244 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3245 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3246 | { |
| 3247 | return false; |
| 3248 | } |
| 3249 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3250 | if (!programObject || !programObject->isLinked()) |
| 3251 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3252 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3253 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3256 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3257 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3258 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3259 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3260 | } |
| 3261 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3262 | return true; |
| 3263 | } |
| 3264 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3265 | static bool ValidateSizedGetUniform(Context *context, |
| 3266 | GLuint program, |
| 3267 | GLint location, |
| 3268 | GLsizei bufSize, |
| 3269 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3270 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3271 | if (length) |
| 3272 | { |
| 3273 | *length = 0; |
| 3274 | } |
| 3275 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3276 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3277 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3278 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3279 | } |
| 3280 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3281 | if (bufSize < 0) |
| 3282 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3283 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3284 | return false; |
| 3285 | } |
| 3286 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3287 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3288 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3289 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3290 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3291 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3292 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3293 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3294 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3295 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3296 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3297 | } |
| 3298 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3299 | if (length) |
| 3300 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3301 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3302 | } |
| 3303 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3304 | return true; |
| 3305 | } |
| 3306 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3307 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3308 | GLuint program, |
| 3309 | GLint location, |
| 3310 | GLsizei bufSize, |
| 3311 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3312 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3313 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3314 | } |
| 3315 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3316 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3317 | GLuint program, |
| 3318 | GLint location, |
| 3319 | GLsizei bufSize, |
| 3320 | GLsizei *length, |
| 3321 | GLfloat *params) |
| 3322 | { |
| 3323 | UNIMPLEMENTED(); |
| 3324 | return false; |
| 3325 | } |
| 3326 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3327 | bool ValidateGetnUniformivEXT(Context *context, |
| 3328 | GLuint program, |
| 3329 | GLint location, |
| 3330 | GLsizei bufSize, |
| 3331 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3332 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3333 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3334 | } |
| 3335 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3336 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3337 | GLuint program, |
| 3338 | GLint location, |
| 3339 | GLsizei bufSize, |
| 3340 | GLsizei *length, |
| 3341 | GLint *params) |
| 3342 | { |
| 3343 | UNIMPLEMENTED(); |
| 3344 | return false; |
| 3345 | } |
| 3346 | |
| 3347 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3348 | GLuint program, |
| 3349 | GLint location, |
| 3350 | GLsizei bufSize, |
| 3351 | GLsizei *length, |
| 3352 | GLuint *params) |
| 3353 | { |
| 3354 | UNIMPLEMENTED(); |
| 3355 | return false; |
| 3356 | } |
| 3357 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3358 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3359 | GLuint program, |
| 3360 | GLint location, |
| 3361 | GLsizei bufSize, |
| 3362 | GLsizei *length, |
| 3363 | GLfloat *params) |
| 3364 | { |
| 3365 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3366 | { |
| 3367 | return false; |
| 3368 | } |
| 3369 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3370 | GLsizei writeLength = 0; |
| 3371 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3372 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3373 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3374 | { |
| 3375 | return false; |
| 3376 | } |
| 3377 | |
| 3378 | SetRobustLengthParam(length, writeLength); |
| 3379 | |
| 3380 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3381 | } |
| 3382 | |
| 3383 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3384 | GLuint program, |
| 3385 | GLint location, |
| 3386 | GLsizei bufSize, |
| 3387 | GLsizei *length, |
| 3388 | GLint *params) |
| 3389 | { |
| 3390 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3391 | { |
| 3392 | return false; |
| 3393 | } |
| 3394 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3395 | GLsizei writeLength = 0; |
| 3396 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3397 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3398 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3399 | { |
| 3400 | return false; |
| 3401 | } |
| 3402 | |
| 3403 | SetRobustLengthParam(length, writeLength); |
| 3404 | |
| 3405 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3409 | GLuint program, |
| 3410 | GLint location, |
| 3411 | GLsizei bufSize, |
| 3412 | GLsizei *length, |
| 3413 | GLuint *params) |
| 3414 | { |
| 3415 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3416 | { |
| 3417 | return false; |
| 3418 | } |
| 3419 | |
| 3420 | if (context->getClientMajorVersion() < 3) |
| 3421 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3422 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3423 | return false; |
| 3424 | } |
| 3425 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3426 | GLsizei writeLength = 0; |
| 3427 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3428 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3429 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3430 | { |
| 3431 | return false; |
| 3432 | } |
| 3433 | |
| 3434 | SetRobustLengthParam(length, writeLength); |
| 3435 | |
| 3436 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3437 | } |
| 3438 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3439 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3440 | GLenum target, |
| 3441 | GLsizei numAttachments, |
| 3442 | const GLenum *attachments, |
| 3443 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3444 | { |
| 3445 | if (numAttachments < 0) |
| 3446 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3447 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3448 | return false; |
| 3449 | } |
| 3450 | |
| 3451 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3452 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3453 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3454 | { |
| 3455 | if (defaultFramebuffer) |
| 3456 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3457 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3458 | return false; |
| 3459 | } |
| 3460 | |
| 3461 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3462 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3463 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3464 | "greater than the maximum supported " |
| 3465 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3466 | return false; |
| 3467 | } |
| 3468 | } |
| 3469 | else |
| 3470 | { |
| 3471 | switch (attachments[i]) |
| 3472 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3473 | case GL_DEPTH_ATTACHMENT: |
| 3474 | case GL_STENCIL_ATTACHMENT: |
| 3475 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3476 | if (defaultFramebuffer) |
| 3477 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3478 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3479 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3480 | return false; |
| 3481 | } |
| 3482 | break; |
| 3483 | case GL_COLOR: |
| 3484 | case GL_DEPTH: |
| 3485 | case GL_STENCIL: |
| 3486 | if (!defaultFramebuffer) |
| 3487 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3488 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3489 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3490 | return false; |
| 3491 | } |
| 3492 | break; |
| 3493 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3494 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3495 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3496 | } |
| 3497 | } |
| 3498 | } |
| 3499 | |
| 3500 | return true; |
| 3501 | } |
| 3502 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3503 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3504 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3505 | if (!context->getExtensions().debugMarker) |
| 3506 | { |
| 3507 | // The debug marker calls should not set error state |
| 3508 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3509 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3510 | return false; |
| 3511 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3512 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3513 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3514 | if (length < 0) |
| 3515 | { |
| 3516 | return false; |
| 3517 | } |
| 3518 | |
| 3519 | if (marker == nullptr) |
| 3520 | { |
| 3521 | return false; |
| 3522 | } |
| 3523 | |
| 3524 | return true; |
| 3525 | } |
| 3526 | |
| 3527 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3528 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3529 | if (!context->getExtensions().debugMarker) |
| 3530 | { |
| 3531 | // The debug marker calls should not set error state |
| 3532 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3533 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3534 | return false; |
| 3535 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3536 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3537 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3538 | if (length < 0) |
| 3539 | { |
| 3540 | return false; |
| 3541 | } |
| 3542 | |
| 3543 | if (length > 0 && marker == nullptr) |
| 3544 | { |
| 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3551 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3552 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3553 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3554 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3555 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3556 | return false; |
| 3557 | } |
| 3558 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3559 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3560 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3561 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3562 | if (!context->getExtensions().eglImage) |
| 3563 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3564 | context->handleError(InvalidEnum() |
| 3565 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3566 | } |
| 3567 | break; |
| 3568 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3569 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3570 | if (!context->getExtensions().eglImageExternal) |
| 3571 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3572 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3573 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3574 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3575 | break; |
| 3576 | |
| 3577 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3578 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3579 | return false; |
| 3580 | } |
| 3581 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3582 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3583 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3584 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3585 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3586 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3587 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3588 | return false; |
| 3589 | } |
| 3590 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3591 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3592 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3593 | context->handleError(InvalidOperation() |
| 3594 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3595 | return false; |
| 3596 | } |
| 3597 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3598 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3599 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3600 | context->handleError(InvalidOperation() |
| 3601 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3605 | return true; |
| 3606 | } |
| 3607 | |
| 3608 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3609 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3610 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3611 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3612 | if (!context->getExtensions().eglImage) |
| 3613 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3614 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3615 | return false; |
| 3616 | } |
| 3617 | |
| 3618 | switch (target) |
| 3619 | { |
| 3620 | case GL_RENDERBUFFER: |
| 3621 | break; |
| 3622 | |
| 3623 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3624 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3625 | return false; |
| 3626 | } |
| 3627 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3628 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3629 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3630 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3631 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3632 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3633 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3634 | return false; |
| 3635 | } |
| 3636 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3637 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3638 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3639 | context->handleError(InvalidOperation() |
| 3640 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3641 | return false; |
| 3642 | } |
| 3643 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3644 | return true; |
| 3645 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3646 | |
| 3647 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3648 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3649 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3650 | { |
| 3651 | // The default VAO should always exist |
| 3652 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3653 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3654 | return false; |
| 3655 | } |
| 3656 | |
| 3657 | return true; |
| 3658 | } |
| 3659 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3660 | bool ValidateProgramBinaryBase(Context *context, |
| 3661 | GLuint program, |
| 3662 | GLenum binaryFormat, |
| 3663 | const void *binary, |
| 3664 | GLint length) |
| 3665 | { |
| 3666 | Program *programObject = GetValidProgram(context, program); |
| 3667 | if (programObject == nullptr) |
| 3668 | { |
| 3669 | return false; |
| 3670 | } |
| 3671 | |
| 3672 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3673 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3674 | programBinaryFormats.end()) |
| 3675 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3676 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3677 | return false; |
| 3678 | } |
| 3679 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3680 | if (context->hasActiveTransformFeedback(program)) |
| 3681 | { |
| 3682 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3683 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3684 | "is associated with an active transform " |
| 3685 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3686 | return false; |
| 3687 | } |
| 3688 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3689 | return true; |
| 3690 | } |
| 3691 | |
| 3692 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3693 | GLuint program, |
| 3694 | GLsizei bufSize, |
| 3695 | GLsizei *length, |
| 3696 | GLenum *binaryFormat, |
| 3697 | void *binary) |
| 3698 | { |
| 3699 | Program *programObject = GetValidProgram(context, program); |
| 3700 | if (programObject == nullptr) |
| 3701 | { |
| 3702 | return false; |
| 3703 | } |
| 3704 | |
| 3705 | if (!programObject->isLinked()) |
| 3706 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3707 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3708 | return false; |
| 3709 | } |
| 3710 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3711 | if (context->getCaps().programBinaryFormats.empty()) |
| 3712 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3713 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3714 | return false; |
| 3715 | } |
| 3716 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3717 | return true; |
| 3718 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3719 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3720 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3721 | { |
| 3722 | // 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] | 3723 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3724 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3725 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3726 | return false; |
| 3727 | } |
| 3728 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3729 | { |
| 3730 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3734 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3735 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3736 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3737 | |
| 3738 | // This should come first before the check for the default frame buffer |
| 3739 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3740 | // rather than INVALID_OPERATION |
| 3741 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3742 | { |
| 3743 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3744 | |
| 3745 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3746 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3747 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3748 | { |
| 3749 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3750 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3751 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3752 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3753 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3754 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3755 | return false; |
| 3756 | } |
| 3757 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3758 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3759 | context->handleError(InvalidOperation() |
| 3760 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3761 | return false; |
| 3762 | } |
| 3763 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3764 | frameBufferId != 0) |
| 3765 | { |
| 3766 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3767 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3768 | context->handleError(InvalidOperation() |
| 3769 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3770 | return false; |
| 3771 | } |
| 3772 | } |
| 3773 | |
| 3774 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3775 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3776 | if (frameBufferId == 0) |
| 3777 | { |
| 3778 | if (n != 1) |
| 3779 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3780 | context->handleError(InvalidOperation() |
| 3781 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3782 | return false; |
| 3783 | } |
| 3784 | |
| 3785 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3786 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3787 | context->handleError( |
| 3788 | InvalidOperation() |
| 3789 | << "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] | 3790 | return false; |
| 3791 | } |
| 3792 | } |
| 3793 | |
| 3794 | return true; |
| 3795 | } |
| 3796 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3797 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3798 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3799 | GLenum pname, |
| 3800 | GLsizei *length, |
| 3801 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3802 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3803 | if (length) |
| 3804 | { |
| 3805 | *length = 0; |
| 3806 | } |
| 3807 | |
| 3808 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3809 | { |
| 3810 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3811 | InvalidOperation() |
| 3812 | << "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] | 3813 | return false; |
| 3814 | } |
| 3815 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3816 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3817 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3818 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3819 | return false; |
| 3820 | } |
| 3821 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3822 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3823 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3824 | case GL_BUFFER_MAP_POINTER: |
| 3825 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3826 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3827 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3828 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3829 | return false; |
| 3830 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3831 | |
| 3832 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3833 | // target bound to zero generate an INVALID_OPERATION error." |
| 3834 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3835 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3836 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3837 | context->handleError(InvalidOperation() |
| 3838 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3839 | return false; |
| 3840 | } |
| 3841 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3842 | if (length) |
| 3843 | { |
| 3844 | *length = 1; |
| 3845 | } |
| 3846 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3847 | return true; |
| 3848 | } |
| 3849 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3850 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3851 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3852 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3853 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3854 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3855 | return false; |
| 3856 | } |
| 3857 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3858 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3859 | |
| 3860 | if (buffer == nullptr || !buffer->isMapped()) |
| 3861 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3862 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3863 | return false; |
| 3864 | } |
| 3865 | |
| 3866 | return true; |
| 3867 | } |
| 3868 | |
| 3869 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3870 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3871 | GLintptr offset, |
| 3872 | GLsizeiptr length, |
| 3873 | GLbitfield access) |
| 3874 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3875 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3876 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3877 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3878 | return false; |
| 3879 | } |
| 3880 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3881 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3882 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3883 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3884 | return false; |
| 3885 | } |
| 3886 | |
| 3887 | if (length < 0) |
| 3888 | { |
| 3889 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3890 | return false; |
| 3891 | } |
| 3892 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3893 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3894 | |
| 3895 | if (!buffer) |
| 3896 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3897 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3898 | return false; |
| 3899 | } |
| 3900 | |
| 3901 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3902 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3903 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3904 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3905 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3906 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3907 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3908 | return false; |
| 3909 | } |
| 3910 | |
| 3911 | // Check for invalid bits in the mask |
| 3912 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3913 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3914 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3915 | |
| 3916 | if (access & ~(allAccessBits)) |
| 3917 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3918 | context->handleError(InvalidValue() |
| 3919 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3920 | return false; |
| 3921 | } |
| 3922 | |
| 3923 | if (length == 0) |
| 3924 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3925 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3926 | return false; |
| 3927 | } |
| 3928 | |
| 3929 | if (buffer->isMapped()) |
| 3930 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3931 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3932 | return false; |
| 3933 | } |
| 3934 | |
| 3935 | // Check for invalid bit combinations |
| 3936 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3937 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3938 | context->handleError(InvalidOperation() |
| 3939 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3940 | return false; |
| 3941 | } |
| 3942 | |
| 3943 | GLbitfield writeOnlyBits = |
| 3944 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3945 | |
| 3946 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3947 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3948 | context->handleError(InvalidOperation() |
| 3949 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3950 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3951 | return false; |
| 3952 | } |
| 3953 | |
| 3954 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3955 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3956 | context->handleError( |
| 3957 | InvalidOperation() |
| 3958 | << "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] | 3959 | return false; |
| 3960 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3961 | |
| 3962 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3966 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3967 | GLintptr offset, |
| 3968 | GLsizeiptr length) |
| 3969 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3970 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3971 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3972 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3973 | return false; |
| 3974 | } |
| 3975 | |
| 3976 | if (length < 0) |
| 3977 | { |
| 3978 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3979 | return false; |
| 3980 | } |
| 3981 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3982 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3983 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3984 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3985 | return false; |
| 3986 | } |
| 3987 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3988 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3989 | |
| 3990 | if (buffer == nullptr) |
| 3991 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3992 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3993 | return false; |
| 3994 | } |
| 3995 | |
| 3996 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3997 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3998 | context->handleError(InvalidOperation() |
| 3999 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4000 | return false; |
| 4001 | } |
| 4002 | |
| 4003 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4004 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4005 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4006 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4007 | if (!checkedSize.IsValid() || |
| 4008 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4009 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4010 | context->handleError(InvalidValue() |
| 4011 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4012 | return false; |
| 4013 | } |
| 4014 | |
| 4015 | return true; |
| 4016 | } |
| 4017 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4018 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4019 | { |
| 4020 | if (n < 0) |
| 4021 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4022 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4023 | return false; |
| 4024 | } |
| 4025 | return true; |
| 4026 | } |
| 4027 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4028 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4029 | { |
| 4030 | if (!context->getExtensions().robustClientMemory) |
| 4031 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4032 | context->handleError(InvalidOperation() |
| 4033 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4034 | return false; |
| 4035 | } |
| 4036 | |
| 4037 | if (bufSize < 0) |
| 4038 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4039 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4040 | return false; |
| 4041 | } |
| 4042 | |
| 4043 | return true; |
| 4044 | } |
| 4045 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4046 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4047 | { |
| 4048 | if (bufSize < numParams) |
| 4049 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4050 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 4051 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4052 | return false; |
| 4053 | } |
| 4054 | |
| 4055 | return true; |
| 4056 | } |
| 4057 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4058 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4059 | GLenum target, |
| 4060 | GLenum attachment, |
| 4061 | GLenum pname, |
| 4062 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4063 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4064 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4065 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4066 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4067 | return false; |
| 4068 | } |
| 4069 | |
| 4070 | int clientVersion = context->getClientMajorVersion(); |
| 4071 | |
| 4072 | switch (pname) |
| 4073 | { |
| 4074 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4075 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4076 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4077 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4078 | break; |
| 4079 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4080 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4081 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4082 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4083 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4084 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4085 | { |
| 4086 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4087 | return false; |
| 4088 | } |
| 4089 | break; |
| 4090 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4091 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4092 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4093 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4094 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4095 | return false; |
| 4096 | } |
| 4097 | break; |
| 4098 | |
| 4099 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4100 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4101 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4102 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4103 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4104 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4105 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4106 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4107 | if (clientVersion < 3) |
| 4108 | { |
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 | break; |
| 4113 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4114 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4115 | if (!context->getExtensions().geometryShader) |
| 4116 | { |
| 4117 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4118 | return false; |
| 4119 | } |
| 4120 | break; |
| 4121 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4122 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4123 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4124 | return false; |
| 4125 | } |
| 4126 | |
| 4127 | // Determine if the attachment is a valid enum |
| 4128 | switch (attachment) |
| 4129 | { |
| 4130 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4131 | case GL_DEPTH: |
| 4132 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4133 | if (clientVersion < 3) |
| 4134 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4135 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4136 | return false; |
| 4137 | } |
| 4138 | break; |
| 4139 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4140 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4141 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4142 | { |
| 4143 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4144 | return false; |
| 4145 | } |
| 4146 | break; |
| 4147 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4148 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4149 | case GL_DEPTH_ATTACHMENT: |
| 4150 | case GL_STENCIL_ATTACHMENT: |
| 4151 | break; |
| 4152 | |
| 4153 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4154 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4155 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4156 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4157 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4158 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4159 | return false; |
| 4160 | } |
| 4161 | break; |
| 4162 | } |
| 4163 | |
| 4164 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4165 | ASSERT(framebuffer); |
| 4166 | |
| 4167 | if (framebuffer->id() == 0) |
| 4168 | { |
| 4169 | if (clientVersion < 3) |
| 4170 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4171 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4172 | return false; |
| 4173 | } |
| 4174 | |
| 4175 | switch (attachment) |
| 4176 | { |
| 4177 | case GL_BACK: |
| 4178 | case GL_DEPTH: |
| 4179 | case GL_STENCIL: |
| 4180 | break; |
| 4181 | |
| 4182 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4183 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4184 | return false; |
| 4185 | } |
| 4186 | } |
| 4187 | else |
| 4188 | { |
| 4189 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4190 | { |
| 4191 | // Valid attachment query |
| 4192 | } |
| 4193 | else |
| 4194 | { |
| 4195 | switch (attachment) |
| 4196 | { |
| 4197 | case GL_DEPTH_ATTACHMENT: |
| 4198 | case GL_STENCIL_ATTACHMENT: |
| 4199 | break; |
| 4200 | |
| 4201 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4202 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4203 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4204 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4205 | return false; |
| 4206 | } |
| 4207 | break; |
| 4208 | |
| 4209 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4210 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | } |
| 4214 | } |
| 4215 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4216 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4217 | if (attachmentObject) |
| 4218 | { |
| 4219 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4220 | attachmentObject->type() == GL_TEXTURE || |
| 4221 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4222 | |
| 4223 | switch (pname) |
| 4224 | { |
| 4225 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4226 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4227 | attachmentObject->type() != GL_TEXTURE) |
| 4228 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4229 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4230 | return false; |
| 4231 | } |
| 4232 | break; |
| 4233 | |
| 4234 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4235 | if (attachmentObject->type() != GL_TEXTURE) |
| 4236 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4237 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4238 | return false; |
| 4239 | } |
| 4240 | break; |
| 4241 | |
| 4242 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4243 | if (attachmentObject->type() != GL_TEXTURE) |
| 4244 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4245 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4246 | return false; |
| 4247 | } |
| 4248 | break; |
| 4249 | |
| 4250 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4251 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4252 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4253 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4254 | return false; |
| 4255 | } |
| 4256 | break; |
| 4257 | |
| 4258 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4259 | if (attachmentObject->type() != GL_TEXTURE) |
| 4260 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4261 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4262 | return false; |
| 4263 | } |
| 4264 | break; |
| 4265 | |
| 4266 | default: |
| 4267 | break; |
| 4268 | } |
| 4269 | } |
| 4270 | else |
| 4271 | { |
| 4272 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4273 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4274 | |
| 4275 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4276 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4277 | // INVALID_OPERATION for all other pnames |
| 4278 | |
| 4279 | switch (pname) |
| 4280 | { |
| 4281 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4282 | break; |
| 4283 | |
| 4284 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4285 | if (clientVersion < 3) |
| 4286 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4287 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4288 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4289 | return false; |
| 4290 | } |
| 4291 | break; |
| 4292 | |
| 4293 | default: |
| 4294 | if (clientVersion < 3) |
| 4295 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4296 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4297 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4298 | return false; |
| 4299 | } |
| 4300 | else |
| 4301 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4302 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4303 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4304 | return false; |
| 4305 | } |
| 4306 | } |
| 4307 | } |
| 4308 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4309 | if (numParams) |
| 4310 | { |
| 4311 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4312 | { |
| 4313 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4314 | // parameters. |
| 4315 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4316 | *numParams = numViews * 2; |
| 4317 | } |
| 4318 | else |
| 4319 | { |
| 4320 | // For all other queries we can have only one output parameter. |
| 4321 | *numParams = 1; |
| 4322 | } |
| 4323 | } |
| 4324 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4325 | return true; |
| 4326 | } |
| 4327 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4328 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4329 | GLenum target, |
| 4330 | GLenum attachment, |
| 4331 | GLenum pname, |
| 4332 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4333 | GLsizei *length, |
| 4334 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4335 | { |
| 4336 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4337 | { |
| 4338 | return false; |
| 4339 | } |
| 4340 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4341 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4342 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4343 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4344 | { |
| 4345 | return false; |
| 4346 | } |
| 4347 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4348 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4349 | { |
| 4350 | return false; |
| 4351 | } |
| 4352 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4353 | SetRobustLengthParam(length, numParams); |
| 4354 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4355 | return true; |
| 4356 | } |
| 4357 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4358 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4359 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4360 | GLenum pname, |
| 4361 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4362 | GLsizei *length, |
| 4363 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4364 | { |
| 4365 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4366 | { |
| 4367 | return false; |
| 4368 | } |
| 4369 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4370 | GLsizei numParams = 0; |
| 4371 | |
| 4372 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4373 | { |
| 4374 | return false; |
| 4375 | } |
| 4376 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4377 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4378 | { |
| 4379 | return false; |
| 4380 | } |
| 4381 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4382 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4383 | return true; |
| 4384 | } |
| 4385 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4386 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4387 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4388 | GLenum pname, |
| 4389 | GLsizei bufSize, |
| 4390 | GLsizei *length, |
| 4391 | GLint64 *params) |
| 4392 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4393 | GLsizei numParams = 0; |
| 4394 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4395 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4396 | { |
| 4397 | return false; |
| 4398 | } |
| 4399 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4400 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4401 | { |
| 4402 | return false; |
| 4403 | } |
| 4404 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4405 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4406 | { |
| 4407 | return false; |
| 4408 | } |
| 4409 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4410 | SetRobustLengthParam(length, numParams); |
| 4411 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4412 | return true; |
| 4413 | } |
| 4414 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4415 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4416 | { |
| 4417 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4418 | if (numParams) |
| 4419 | { |
| 4420 | *numParams = 1; |
| 4421 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4422 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4423 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4424 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4425 | ? GetValidProgramNoResolve(context, program) |
| 4426 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4427 | if (!programObject) |
| 4428 | { |
| 4429 | return false; |
| 4430 | } |
| 4431 | |
| 4432 | switch (pname) |
| 4433 | { |
| 4434 | case GL_DELETE_STATUS: |
| 4435 | case GL_LINK_STATUS: |
| 4436 | case GL_VALIDATE_STATUS: |
| 4437 | case GL_INFO_LOG_LENGTH: |
| 4438 | case GL_ATTACHED_SHADERS: |
| 4439 | case GL_ACTIVE_ATTRIBUTES: |
| 4440 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4441 | case GL_ACTIVE_UNIFORMS: |
| 4442 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4443 | break; |
| 4444 | |
| 4445 | case GL_PROGRAM_BINARY_LENGTH: |
| 4446 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4447 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4448 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4449 | "requires GL_OES_get_program_binary or " |
| 4450 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4451 | return false; |
| 4452 | } |
| 4453 | break; |
| 4454 | |
| 4455 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4456 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4457 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4458 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4459 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4460 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4461 | if (context->getClientMajorVersion() < 3) |
| 4462 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4463 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4464 | return false; |
| 4465 | } |
| 4466 | break; |
| 4467 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4468 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4469 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4470 | if (context->getClientVersion() < Version(3, 1)) |
| 4471 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4472 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4473 | return false; |
| 4474 | } |
| 4475 | break; |
| 4476 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4477 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4478 | if (context->getClientVersion() < Version(3, 1)) |
| 4479 | { |
| 4480 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4481 | return false; |
| 4482 | } |
| 4483 | |
| 4484 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4485 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4486 | // program which has not been linked successfully, or which does not contain objects to |
| 4487 | // form a compute shader. |
| 4488 | if (!programObject->isLinked()) |
| 4489 | { |
| 4490 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4491 | return false; |
| 4492 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4493 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4494 | { |
| 4495 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4496 | return false; |
| 4497 | } |
| 4498 | break; |
| 4499 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4500 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4501 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4502 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4503 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4504 | if (!context->getExtensions().geometryShader) |
| 4505 | { |
| 4506 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4507 | return false; |
| 4508 | } |
| 4509 | |
| 4510 | // [EXT_geometry_shader] Chapter 7.12 |
| 4511 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4512 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4513 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4514 | // successfully, or which does not contain objects to form a geometry shader. |
| 4515 | if (!programObject->isLinked()) |
| 4516 | { |
| 4517 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4518 | return false; |
| 4519 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4520 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4521 | { |
| 4522 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4523 | return false; |
| 4524 | } |
| 4525 | break; |
| 4526 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4527 | case GL_COMPLETION_STATUS_KHR: |
| 4528 | if (!context->getExtensions().parallelShaderCompile) |
| 4529 | { |
| 4530 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 4531 | return false; |
| 4532 | } |
| 4533 | break; |
| 4534 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4535 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4536 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | return true; |
| 4541 | } |
| 4542 | |
| 4543 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4544 | GLuint program, |
| 4545 | GLenum pname, |
| 4546 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4547 | GLsizei *length, |
| 4548 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4549 | { |
| 4550 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4551 | { |
| 4552 | return false; |
| 4553 | } |
| 4554 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4555 | GLsizei numParams = 0; |
| 4556 | |
| 4557 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4558 | { |
| 4559 | return false; |
| 4560 | } |
| 4561 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4562 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4563 | { |
| 4564 | return false; |
| 4565 | } |
| 4566 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4567 | SetRobustLengthParam(length, numParams); |
| 4568 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4569 | return true; |
| 4570 | } |
| 4571 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4572 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4573 | GLenum target, |
| 4574 | GLenum pname, |
| 4575 | GLsizei bufSize, |
| 4576 | GLsizei *length, |
| 4577 | GLint *params) |
| 4578 | { |
| 4579 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4580 | { |
| 4581 | return false; |
| 4582 | } |
| 4583 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4584 | GLsizei numParams = 0; |
| 4585 | |
| 4586 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4587 | { |
| 4588 | return false; |
| 4589 | } |
| 4590 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4591 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4592 | { |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4596 | SetRobustLengthParam(length, numParams); |
| 4597 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4598 | return true; |
| 4599 | } |
| 4600 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4601 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4602 | GLuint shader, |
| 4603 | GLenum pname, |
| 4604 | GLsizei bufSize, |
| 4605 | GLsizei *length, |
| 4606 | GLint *params) |
| 4607 | { |
| 4608 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4609 | { |
| 4610 | return false; |
| 4611 | } |
| 4612 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4613 | GLsizei numParams = 0; |
| 4614 | |
| 4615 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4616 | { |
| 4617 | return false; |
| 4618 | } |
| 4619 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4620 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4621 | { |
| 4622 | return false; |
| 4623 | } |
| 4624 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4625 | SetRobustLengthParam(length, numParams); |
| 4626 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4627 | return true; |
| 4628 | } |
| 4629 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4630 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4631 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4632 | GLenum pname, |
| 4633 | GLsizei bufSize, |
| 4634 | GLsizei *length, |
| 4635 | GLfloat *params) |
| 4636 | { |
| 4637 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4638 | { |
| 4639 | return false; |
| 4640 | } |
| 4641 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4642 | GLsizei numParams = 0; |
| 4643 | |
| 4644 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4645 | { |
| 4646 | return false; |
| 4647 | } |
| 4648 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4649 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4650 | { |
| 4651 | return false; |
| 4652 | } |
| 4653 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4654 | SetRobustLengthParam(length, numParams); |
| 4655 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4656 | return true; |
| 4657 | } |
| 4658 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4659 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4660 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4661 | GLenum pname, |
| 4662 | GLsizei bufSize, |
| 4663 | GLsizei *length, |
| 4664 | GLint *params) |
| 4665 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4666 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4667 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4668 | { |
| 4669 | return false; |
| 4670 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4671 | GLsizei numParams = 0; |
| 4672 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4673 | { |
| 4674 | return false; |
| 4675 | } |
| 4676 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4677 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4678 | { |
| 4679 | return false; |
| 4680 | } |
| 4681 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4682 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4683 | return true; |
| 4684 | } |
| 4685 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4686 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4687 | TextureType target, |
| 4688 | GLenum pname, |
| 4689 | GLsizei bufSize, |
| 4690 | GLsizei *length, |
| 4691 | GLint *params) |
| 4692 | { |
| 4693 | UNIMPLEMENTED(); |
| 4694 | return false; |
| 4695 | } |
| 4696 | |
| 4697 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4698 | TextureType target, |
| 4699 | GLenum pname, |
| 4700 | GLsizei bufSize, |
| 4701 | GLsizei *length, |
| 4702 | GLuint *params) |
| 4703 | { |
| 4704 | UNIMPLEMENTED(); |
| 4705 | return false; |
| 4706 | } |
| 4707 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4708 | bool ValidateTexParameterfvRobustANGLE(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 GLfloat *params) |
| 4713 | { |
| 4714 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4715 | { |
| 4716 | return false; |
| 4717 | } |
| 4718 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4719 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4720 | } |
| 4721 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4722 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4723 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4724 | GLenum pname, |
| 4725 | GLsizei bufSize, |
| 4726 | const GLint *params) |
| 4727 | { |
| 4728 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4729 | { |
| 4730 | return false; |
| 4731 | } |
| 4732 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4733 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4734 | } |
| 4735 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4736 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4737 | TextureType target, |
| 4738 | GLenum pname, |
| 4739 | GLsizei bufSize, |
| 4740 | const GLint *params) |
| 4741 | { |
| 4742 | UNIMPLEMENTED(); |
| 4743 | return false; |
| 4744 | } |
| 4745 | |
| 4746 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4747 | TextureType target, |
| 4748 | GLenum pname, |
| 4749 | GLsizei bufSize, |
| 4750 | const GLuint *params) |
| 4751 | { |
| 4752 | UNIMPLEMENTED(); |
| 4753 | return false; |
| 4754 | } |
| 4755 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4756 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4757 | GLuint sampler, |
| 4758 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame^] | 4759 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4760 | GLsizei *length, |
| 4761 | GLfloat *params) |
| 4762 | { |
| 4763 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4764 | { |
| 4765 | return false; |
| 4766 | } |
| 4767 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4768 | GLsizei numParams = 0; |
| 4769 | |
| 4770 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4771 | { |
| 4772 | return false; |
| 4773 | } |
| 4774 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4775 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4776 | { |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4780 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4781 | return true; |
| 4782 | } |
| 4783 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4784 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4785 | GLuint sampler, |
| 4786 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4787 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4788 | GLsizei *length, |
| 4789 | GLint *params) |
| 4790 | { |
| 4791 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4792 | { |
| 4793 | return false; |
| 4794 | } |
| 4795 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4796 | GLsizei numParams = 0; |
| 4797 | |
| 4798 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4799 | { |
| 4800 | return false; |
| 4801 | } |
| 4802 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4803 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4804 | { |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4808 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4809 | return true; |
| 4810 | } |
| 4811 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4812 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4813 | GLuint sampler, |
| 4814 | GLenum pname, |
| 4815 | GLsizei bufSize, |
| 4816 | GLsizei *length, |
| 4817 | GLint *params) |
| 4818 | { |
| 4819 | UNIMPLEMENTED(); |
| 4820 | return false; |
| 4821 | } |
| 4822 | |
| 4823 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4824 | GLuint sampler, |
| 4825 | GLenum pname, |
| 4826 | GLsizei bufSize, |
| 4827 | GLsizei *length, |
| 4828 | GLuint *params) |
| 4829 | { |
| 4830 | UNIMPLEMENTED(); |
| 4831 | return false; |
| 4832 | } |
| 4833 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4834 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4835 | GLuint sampler, |
| 4836 | GLenum pname, |
| 4837 | GLsizei bufSize, |
| 4838 | const GLfloat *params) |
| 4839 | { |
| 4840 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4841 | { |
| 4842 | return false; |
| 4843 | } |
| 4844 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4845 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4846 | } |
| 4847 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4848 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4849 | GLuint sampler, |
| 4850 | GLenum pname, |
| 4851 | GLsizei bufSize, |
| 4852 | const GLint *params) |
| 4853 | { |
| 4854 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4855 | { |
| 4856 | return false; |
| 4857 | } |
| 4858 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4859 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4860 | } |
| 4861 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4862 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4863 | GLuint sampler, |
| 4864 | GLenum pname, |
| 4865 | GLsizei bufSize, |
| 4866 | const GLint *param) |
| 4867 | { |
| 4868 | UNIMPLEMENTED(); |
| 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4873 | GLuint sampler, |
| 4874 | GLenum pname, |
| 4875 | GLsizei bufSize, |
| 4876 | const GLuint *param) |
| 4877 | { |
| 4878 | UNIMPLEMENTED(); |
| 4879 | return false; |
| 4880 | } |
| 4881 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4882 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4883 | GLuint index, |
| 4884 | GLenum pname, |
| 4885 | GLsizei bufSize, |
| 4886 | GLsizei *length, |
| 4887 | GLfloat *params) |
| 4888 | { |
| 4889 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4890 | { |
| 4891 | return false; |
| 4892 | } |
| 4893 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4894 | GLsizei writeLength = 0; |
| 4895 | |
| 4896 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4897 | { |
| 4898 | return false; |
| 4899 | } |
| 4900 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4901 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4902 | { |
| 4903 | return false; |
| 4904 | } |
| 4905 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4906 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4907 | return true; |
| 4908 | } |
| 4909 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4910 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4911 | GLuint index, |
| 4912 | GLenum pname, |
| 4913 | GLsizei bufSize, |
| 4914 | GLsizei *length, |
| 4915 | GLint *params) |
| 4916 | { |
| 4917 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4918 | { |
| 4919 | return false; |
| 4920 | } |
| 4921 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4922 | GLsizei writeLength = 0; |
| 4923 | |
| 4924 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4925 | { |
| 4926 | return false; |
| 4927 | } |
| 4928 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4929 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4930 | { |
| 4931 | return false; |
| 4932 | } |
| 4933 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4934 | SetRobustLengthParam(length, writeLength); |
| 4935 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4936 | return true; |
| 4937 | } |
| 4938 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4939 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4940 | GLuint index, |
| 4941 | GLenum pname, |
| 4942 | GLsizei bufSize, |
| 4943 | GLsizei *length, |
| 4944 | void **pointer) |
| 4945 | { |
| 4946 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4947 | { |
| 4948 | return false; |
| 4949 | } |
| 4950 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4951 | GLsizei writeLength = 0; |
| 4952 | |
| 4953 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4954 | { |
| 4955 | return false; |
| 4956 | } |
| 4957 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4958 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4959 | { |
| 4960 | return false; |
| 4961 | } |
| 4962 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4963 | SetRobustLengthParam(length, writeLength); |
| 4964 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4965 | return true; |
| 4966 | } |
| 4967 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4968 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4969 | GLuint index, |
| 4970 | GLenum pname, |
| 4971 | GLsizei bufSize, |
| 4972 | GLsizei *length, |
| 4973 | GLint *params) |
| 4974 | { |
| 4975 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4976 | { |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4980 | GLsizei writeLength = 0; |
| 4981 | |
| 4982 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4983 | { |
| 4984 | return false; |
| 4985 | } |
| 4986 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4987 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4988 | { |
| 4989 | return false; |
| 4990 | } |
| 4991 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4992 | SetRobustLengthParam(length, writeLength); |
| 4993 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4994 | return true; |
| 4995 | } |
| 4996 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4997 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4998 | GLuint index, |
| 4999 | GLenum pname, |
| 5000 | GLsizei bufSize, |
| 5001 | GLsizei *length, |
| 5002 | GLuint *params) |
| 5003 | { |
| 5004 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5005 | { |
| 5006 | return false; |
| 5007 | } |
| 5008 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5009 | GLsizei writeLength = 0; |
| 5010 | |
| 5011 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5012 | { |
| 5013 | return false; |
| 5014 | } |
| 5015 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5016 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5017 | { |
| 5018 | return false; |
| 5019 | } |
| 5020 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5021 | SetRobustLengthParam(length, writeLength); |
| 5022 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5023 | return true; |
| 5024 | } |
| 5025 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5026 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5027 | GLuint program, |
| 5028 | GLuint uniformBlockIndex, |
| 5029 | GLenum pname, |
| 5030 | GLsizei bufSize, |
| 5031 | GLsizei *length, |
| 5032 | GLint *params) |
| 5033 | { |
| 5034 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5035 | { |
| 5036 | return false; |
| 5037 | } |
| 5038 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5039 | GLsizei writeLength = 0; |
| 5040 | |
| 5041 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5042 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5043 | { |
| 5044 | return false; |
| 5045 | } |
| 5046 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5047 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5048 | { |
| 5049 | return false; |
| 5050 | } |
| 5051 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5052 | SetRobustLengthParam(length, writeLength); |
| 5053 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5054 | return true; |
| 5055 | } |
| 5056 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5057 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5058 | GLenum target, |
| 5059 | GLenum internalformat, |
| 5060 | GLenum pname, |
| 5061 | GLsizei bufSize, |
| 5062 | GLsizei *length, |
| 5063 | GLint *params) |
| 5064 | { |
| 5065 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5066 | { |
| 5067 | return false; |
| 5068 | } |
| 5069 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5070 | GLsizei numParams = 0; |
| 5071 | |
| 5072 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5073 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5074 | { |
| 5075 | return false; |
| 5076 | } |
| 5077 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5078 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5079 | { |
| 5080 | return false; |
| 5081 | } |
| 5082 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5083 | SetRobustLengthParam(length, numParams); |
| 5084 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5085 | return true; |
| 5086 | } |
| 5087 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5088 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5089 | GLuint attribIndex, |
| 5090 | GLint size, |
| 5091 | GLenum type, |
| 5092 | GLboolean pureInteger) |
| 5093 | { |
| 5094 | const Caps &caps = context->getCaps(); |
| 5095 | if (attribIndex >= caps.maxVertexAttributes) |
| 5096 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5097 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5098 | return false; |
| 5099 | } |
| 5100 | |
| 5101 | if (size < 1 || size > 4) |
| 5102 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5103 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5104 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | switch (type) |
| 5108 | { |
| 5109 | case GL_BYTE: |
| 5110 | case GL_UNSIGNED_BYTE: |
| 5111 | case GL_SHORT: |
| 5112 | case GL_UNSIGNED_SHORT: |
| 5113 | break; |
| 5114 | |
| 5115 | case GL_INT: |
| 5116 | case GL_UNSIGNED_INT: |
| 5117 | if (context->getClientMajorVersion() < 3) |
| 5118 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5119 | context->handleError(InvalidEnum() |
| 5120 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5121 | return false; |
| 5122 | } |
| 5123 | break; |
| 5124 | |
| 5125 | case GL_FIXED: |
| 5126 | case GL_FLOAT: |
| 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_HALF_FLOAT: |
| 5135 | if (context->getClientMajorVersion() < 3) |
| 5136 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5137 | context->handleError(InvalidEnum() |
| 5138 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5139 | return false; |
| 5140 | } |
| 5141 | if (pureInteger) |
| 5142 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5143 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5144 | return false; |
| 5145 | } |
| 5146 | break; |
| 5147 | |
| 5148 | case GL_INT_2_10_10_10_REV: |
| 5149 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5150 | if (context->getClientMajorVersion() < 3) |
| 5151 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5152 | context->handleError(InvalidEnum() |
| 5153 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5154 | return false; |
| 5155 | } |
| 5156 | if (pureInteger) |
| 5157 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5158 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5159 | return false; |
| 5160 | } |
| 5161 | if (size != 4) |
| 5162 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5163 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5164 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5165 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5166 | return false; |
| 5167 | } |
| 5168 | break; |
| 5169 | |
| 5170 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5171 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5172 | return false; |
| 5173 | } |
| 5174 | |
| 5175 | return true; |
| 5176 | } |
| 5177 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5178 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5179 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5180 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5181 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5182 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5183 | GLint drawbuffer, |
| 5184 | const GLenum *validComponentTypes, |
| 5185 | size_t validComponentTypeCount) |
| 5186 | { |
| 5187 | const FramebufferAttachment *attachment = |
| 5188 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5189 | if (attachment) |
| 5190 | { |
| 5191 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5192 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5193 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5194 | { |
| 5195 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5196 | InvalidOperation() |
| 5197 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5198 | return false; |
| 5199 | } |
| 5200 | } |
| 5201 | |
| 5202 | return true; |
| 5203 | } |
| 5204 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5205 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5206 | { |
| 5207 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5208 | { |
| 5209 | return false; |
| 5210 | } |
| 5211 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5212 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5213 | if (pixelUnpackBuffer == nullptr) |
| 5214 | { |
| 5215 | if (dataSize < imageSize) |
| 5216 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5217 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5218 | } |
| 5219 | } |
| 5220 | return true; |
| 5221 | } |
| 5222 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5223 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5224 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5225 | GLenum pname, |
| 5226 | bool pointerVersion, |
| 5227 | GLsizei *numParams) |
| 5228 | { |
| 5229 | if (numParams) |
| 5230 | { |
| 5231 | *numParams = 0; |
| 5232 | } |
| 5233 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5234 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5235 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5236 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5237 | return false; |
| 5238 | } |
| 5239 | |
| 5240 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5241 | if (!buffer) |
| 5242 | { |
| 5243 | // 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] | 5244 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5245 | return false; |
| 5246 | } |
| 5247 | |
| 5248 | const Extensions &extensions = context->getExtensions(); |
| 5249 | |
| 5250 | switch (pname) |
| 5251 | { |
| 5252 | case GL_BUFFER_USAGE: |
| 5253 | case GL_BUFFER_SIZE: |
| 5254 | break; |
| 5255 | |
| 5256 | case GL_BUFFER_ACCESS_OES: |
| 5257 | if (!extensions.mapBuffer) |
| 5258 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5259 | context->handleError(InvalidEnum() |
| 5260 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5261 | return false; |
| 5262 | } |
| 5263 | break; |
| 5264 | |
| 5265 | case GL_BUFFER_MAPPED: |
| 5266 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5267 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5268 | !extensions.mapBufferRange) |
| 5269 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5270 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5271 | "GL_OES_mapbuffer or " |
| 5272 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5273 | return false; |
| 5274 | } |
| 5275 | break; |
| 5276 | |
| 5277 | case GL_BUFFER_MAP_POINTER: |
| 5278 | if (!pointerVersion) |
| 5279 | { |
| 5280 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5281 | InvalidEnum() |
| 5282 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5283 | return false; |
| 5284 | } |
| 5285 | break; |
| 5286 | |
| 5287 | case GL_BUFFER_ACCESS_FLAGS: |
| 5288 | case GL_BUFFER_MAP_OFFSET: |
| 5289 | case GL_BUFFER_MAP_LENGTH: |
| 5290 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5291 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5292 | context->handleError(InvalidEnum() |
| 5293 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5294 | return false; |
| 5295 | } |
| 5296 | break; |
| 5297 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5298 | case GL_MEMORY_SIZE_ANGLE: |
| 5299 | if (!context->getExtensions().memorySize) |
| 5300 | { |
| 5301 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5302 | return false; |
| 5303 | } |
| 5304 | break; |
| 5305 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5306 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5307 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5308 | return false; |
| 5309 | } |
| 5310 | |
| 5311 | // All buffer parameter queries return one value. |
| 5312 | if (numParams) |
| 5313 | { |
| 5314 | *numParams = 1; |
| 5315 | } |
| 5316 | |
| 5317 | return true; |
| 5318 | } |
| 5319 | |
| 5320 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5321 | GLenum target, |
| 5322 | GLenum pname, |
| 5323 | GLsizei *length) |
| 5324 | { |
| 5325 | if (length) |
| 5326 | { |
| 5327 | *length = 0; |
| 5328 | } |
| 5329 | |
| 5330 | if (target != GL_RENDERBUFFER) |
| 5331 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5332 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5333 | return false; |
| 5334 | } |
| 5335 | |
| 5336 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5337 | if (renderbuffer == nullptr) |
| 5338 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5339 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5340 | return false; |
| 5341 | } |
| 5342 | |
| 5343 | switch (pname) |
| 5344 | { |
| 5345 | case GL_RENDERBUFFER_WIDTH: |
| 5346 | case GL_RENDERBUFFER_HEIGHT: |
| 5347 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5348 | case GL_RENDERBUFFER_RED_SIZE: |
| 5349 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5350 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5351 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5352 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5353 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5354 | break; |
| 5355 | |
| 5356 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5357 | if (!context->getExtensions().framebufferMultisample) |
| 5358 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5359 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5360 | return false; |
| 5361 | } |
| 5362 | break; |
| 5363 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5364 | case GL_MEMORY_SIZE_ANGLE: |
| 5365 | if (!context->getExtensions().memorySize) |
| 5366 | { |
| 5367 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5368 | return false; |
| 5369 | } |
| 5370 | break; |
| 5371 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5372 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5373 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5374 | return false; |
| 5375 | } |
| 5376 | |
| 5377 | if (length) |
| 5378 | { |
| 5379 | *length = 1; |
| 5380 | } |
| 5381 | return true; |
| 5382 | } |
| 5383 | |
| 5384 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5385 | { |
| 5386 | if (length) |
| 5387 | { |
| 5388 | *length = 0; |
| 5389 | } |
| 5390 | |
| 5391 | if (GetValidShader(context, shader) == nullptr) |
| 5392 | { |
| 5393 | return false; |
| 5394 | } |
| 5395 | |
| 5396 | switch (pname) |
| 5397 | { |
| 5398 | case GL_SHADER_TYPE: |
| 5399 | case GL_DELETE_STATUS: |
| 5400 | case GL_COMPILE_STATUS: |
| 5401 | case GL_INFO_LOG_LENGTH: |
| 5402 | case GL_SHADER_SOURCE_LENGTH: |
| 5403 | break; |
| 5404 | |
| 5405 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5406 | if (!context->getExtensions().translatedShaderSource) |
| 5407 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5408 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5409 | return false; |
| 5410 | } |
| 5411 | break; |
| 5412 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5413 | case GL_COMPLETION_STATUS_KHR: |
| 5414 | if (!context->getExtensions().parallelShaderCompile) |
| 5415 | { |
| 5416 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 5417 | return false; |
| 5418 | } |
| 5419 | break; |
| 5420 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5421 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5422 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5423 | return false; |
| 5424 | } |
| 5425 | |
| 5426 | if (length) |
| 5427 | { |
| 5428 | *length = 1; |
| 5429 | } |
| 5430 | return true; |
| 5431 | } |
| 5432 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5433 | bool ValidateGetTexParameterBase(Context *context, |
| 5434 | TextureType target, |
| 5435 | GLenum pname, |
| 5436 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5437 | { |
| 5438 | if (length) |
| 5439 | { |
| 5440 | *length = 0; |
| 5441 | } |
| 5442 | |
| 5443 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5444 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5445 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5446 | return false; |
| 5447 | } |
| 5448 | |
| 5449 | if (context->getTargetTexture(target) == nullptr) |
| 5450 | { |
| 5451 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5452 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5453 | return false; |
| 5454 | } |
| 5455 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5456 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5457 | { |
| 5458 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5459 | return false; |
| 5460 | } |
| 5461 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5462 | switch (pname) |
| 5463 | { |
| 5464 | case GL_TEXTURE_MAG_FILTER: |
| 5465 | case GL_TEXTURE_MIN_FILTER: |
| 5466 | case GL_TEXTURE_WRAP_S: |
| 5467 | case GL_TEXTURE_WRAP_T: |
| 5468 | break; |
| 5469 | |
| 5470 | case GL_TEXTURE_USAGE_ANGLE: |
| 5471 | if (!context->getExtensions().textureUsage) |
| 5472 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5473 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5474 | return false; |
| 5475 | } |
| 5476 | break; |
| 5477 | |
| 5478 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5479 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5480 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5481 | return false; |
| 5482 | } |
| 5483 | break; |
| 5484 | |
| 5485 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5486 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5487 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5488 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5489 | return false; |
| 5490 | } |
| 5491 | break; |
| 5492 | |
| 5493 | case GL_TEXTURE_WRAP_R: |
| 5494 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5495 | case GL_TEXTURE_SWIZZLE_R: |
| 5496 | case GL_TEXTURE_SWIZZLE_G: |
| 5497 | case GL_TEXTURE_SWIZZLE_B: |
| 5498 | case GL_TEXTURE_SWIZZLE_A: |
| 5499 | case GL_TEXTURE_BASE_LEVEL: |
| 5500 | case GL_TEXTURE_MAX_LEVEL: |
| 5501 | case GL_TEXTURE_MIN_LOD: |
| 5502 | case GL_TEXTURE_MAX_LOD: |
| 5503 | case GL_TEXTURE_COMPARE_MODE: |
| 5504 | case GL_TEXTURE_COMPARE_FUNC: |
| 5505 | if (context->getClientMajorVersion() < 3) |
| 5506 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5507 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5508 | return false; |
| 5509 | } |
| 5510 | break; |
| 5511 | |
| 5512 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5513 | if (!context->getExtensions().textureSRGBDecode) |
| 5514 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5515 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5516 | return false; |
| 5517 | } |
| 5518 | break; |
| 5519 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5520 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5521 | if (context->getClientVersion() < Version(3, 1)) |
| 5522 | { |
| 5523 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5524 | return false; |
| 5525 | } |
| 5526 | break; |
| 5527 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5528 | case GL_GENERATE_MIPMAP: |
| 5529 | case GL_TEXTURE_CROP_RECT_OES: |
| 5530 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5531 | // after GL_OES_draw_texture functionality implemented |
| 5532 | if (context->getClientMajorVersion() > 1) |
| 5533 | { |
| 5534 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5535 | return false; |
| 5536 | } |
| 5537 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5538 | |
| 5539 | case GL_MEMORY_SIZE_ANGLE: |
| 5540 | if (!context->getExtensions().memorySize) |
| 5541 | { |
| 5542 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5543 | return false; |
| 5544 | } |
| 5545 | break; |
| 5546 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5547 | case GL_TEXTURE_BORDER_COLOR: |
| 5548 | if (!context->getExtensions().textureBorderClamp) |
| 5549 | { |
| 5550 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 5551 | return false; |
| 5552 | } |
| 5553 | break; |
| 5554 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5555 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5556 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5557 | return false; |
| 5558 | } |
| 5559 | |
| 5560 | if (length) |
| 5561 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5562 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5563 | } |
| 5564 | return true; |
| 5565 | } |
| 5566 | |
| 5567 | bool ValidateGetVertexAttribBase(Context *context, |
| 5568 | GLuint index, |
| 5569 | GLenum pname, |
| 5570 | GLsizei *length, |
| 5571 | bool pointer, |
| 5572 | bool pureIntegerEntryPoint) |
| 5573 | { |
| 5574 | if (length) |
| 5575 | { |
| 5576 | *length = 0; |
| 5577 | } |
| 5578 | |
| 5579 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5580 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5581 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5582 | return false; |
| 5583 | } |
| 5584 | |
| 5585 | if (index >= context->getCaps().maxVertexAttributes) |
| 5586 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5587 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5588 | return false; |
| 5589 | } |
| 5590 | |
| 5591 | if (pointer) |
| 5592 | { |
| 5593 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5594 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5595 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5596 | return false; |
| 5597 | } |
| 5598 | } |
| 5599 | else |
| 5600 | { |
| 5601 | switch (pname) |
| 5602 | { |
| 5603 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5604 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5605 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5606 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5607 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5608 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5609 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5610 | break; |
| 5611 | |
| 5612 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5613 | static_assert( |
| 5614 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5615 | "ANGLE extension enums not equal to GL enums."); |
| 5616 | if (context->getClientMajorVersion() < 3 && |
| 5617 | !context->getExtensions().instancedArrays) |
| 5618 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5619 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5620 | "requires OpenGL ES 3.0 or " |
| 5621 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5622 | return false; |
| 5623 | } |
| 5624 | break; |
| 5625 | |
| 5626 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5627 | if (context->getClientMajorVersion() < 3) |
| 5628 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5629 | context->handleError( |
| 5630 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5631 | return false; |
| 5632 | } |
| 5633 | break; |
| 5634 | |
| 5635 | case GL_VERTEX_ATTRIB_BINDING: |
| 5636 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5637 | if (context->getClientVersion() < ES_3_1) |
| 5638 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5639 | context->handleError(InvalidEnum() |
| 5640 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5641 | return false; |
| 5642 | } |
| 5643 | break; |
| 5644 | |
| 5645 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5646 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5647 | return false; |
| 5648 | } |
| 5649 | } |
| 5650 | |
| 5651 | if (length) |
| 5652 | { |
| 5653 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5654 | { |
| 5655 | *length = 4; |
| 5656 | } |
| 5657 | else |
| 5658 | { |
| 5659 | *length = 1; |
| 5660 | } |
| 5661 | } |
| 5662 | |
| 5663 | return true; |
| 5664 | } |
| 5665 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5666 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5667 | GLint x, |
| 5668 | GLint y, |
| 5669 | GLsizei width, |
| 5670 | GLsizei height, |
| 5671 | GLenum format, |
| 5672 | GLenum type, |
| 5673 | GLsizei bufSize, |
| 5674 | GLsizei *length, |
| 5675 | GLsizei *columns, |
| 5676 | GLsizei *rows, |
| 5677 | void *pixels) |
| 5678 | { |
| 5679 | if (length != nullptr) |
| 5680 | { |
| 5681 | *length = 0; |
| 5682 | } |
| 5683 | if (rows != nullptr) |
| 5684 | { |
| 5685 | *rows = 0; |
| 5686 | } |
| 5687 | if (columns != nullptr) |
| 5688 | { |
| 5689 | *columns = 0; |
| 5690 | } |
| 5691 | |
| 5692 | if (width < 0 || height < 0) |
| 5693 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5694 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5695 | return false; |
| 5696 | } |
| 5697 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5698 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5699 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5700 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5701 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5702 | return false; |
| 5703 | } |
| 5704 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5705 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5706 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5707 | return false; |
| 5708 | } |
| 5709 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5710 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5711 | ASSERT(framebuffer); |
| 5712 | |
| 5713 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5714 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5715 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5716 | return false; |
| 5717 | } |
| 5718 | |
| 5719 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5720 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5721 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5722 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5723 | // situation is an application error that would lead to a crash in ANGLE. |
| 5724 | if (readBuffer == nullptr) |
| 5725 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5726 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5727 | return false; |
| 5728 | } |
| 5729 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5730 | // ANGLE_multiview, Revision 1: |
| 5731 | // 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] | 5732 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5733 | // in the current read framebuffer is more than one. |
| 5734 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5735 | { |
| 5736 | context->handleError(InvalidFramebufferOperation() |
| 5737 | << "Attempting to read from a multi-view framebuffer."); |
| 5738 | return false; |
| 5739 | } |
| 5740 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5741 | if (context->getExtensions().webglCompatibility) |
| 5742 | { |
| 5743 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5744 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5745 | // and type before validating the combination of format and type. However, the |
| 5746 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5747 | // verifies that GL_INVALID_OPERATION is generated. |
| 5748 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5749 | // dEQP/WebGL. |
| 5750 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5751 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5752 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5753 | return false; |
| 5754 | } |
| 5755 | |
| 5756 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5757 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5758 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5759 | return false; |
| 5760 | } |
| 5761 | } |
| 5762 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5763 | GLenum currentFormat = GL_NONE; |
| 5764 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5765 | |
| 5766 | GLenum currentType = GL_NONE; |
| 5767 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5768 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5769 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5770 | |
| 5771 | bool validFormatTypeCombination = |
| 5772 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5773 | |
| 5774 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5775 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5776 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5777 | return false; |
| 5778 | } |
| 5779 | |
| 5780 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5781 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5782 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5783 | { |
| 5784 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5785 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5786 | return false; |
| 5787 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5788 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5789 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5790 | { |
| 5791 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5792 | return false; |
| 5793 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5794 | |
| 5795 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5796 | // would exceed the data store size. |
| 5797 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5798 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5799 | const auto &pack = context->getGLState().getPackState(); |
| 5800 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5801 | GLuint endByte = 0; |
| 5802 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5803 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5804 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5805 | return false; |
| 5806 | } |
| 5807 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5808 | if (bufSize >= 0) |
| 5809 | { |
| 5810 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5811 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5812 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5813 | return false; |
| 5814 | } |
| 5815 | } |
| 5816 | |
| 5817 | if (pixelPackBuffer != nullptr) |
| 5818 | { |
| 5819 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5820 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5821 | checkedEndByte += checkedOffset; |
| 5822 | |
| 5823 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5824 | { |
| 5825 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5826 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5827 | return false; |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5832 | { |
| 5833 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5834 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5835 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5836 | return false; |
| 5837 | } |
| 5838 | |
| 5839 | *length = static_cast<GLsizei>(endByte); |
| 5840 | } |
| 5841 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5842 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5843 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5844 | if (start < 0) |
| 5845 | { |
| 5846 | // "subtract" the area that is less than 0 |
| 5847 | clippedExtent += start; |
| 5848 | } |
| 5849 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5850 | angle::CheckedNumeric<int> readExtent = start; |
| 5851 | readExtent += length; |
| 5852 | if (!readExtent.IsValid()) |
| 5853 | { |
| 5854 | return false; |
| 5855 | } |
| 5856 | |
| 5857 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5858 | { |
| 5859 | // Subtract the region to the right of the read buffer |
| 5860 | clippedExtent -= (readExtent - bufferSize); |
| 5861 | } |
| 5862 | |
| 5863 | if (!clippedExtent.IsValid()) |
| 5864 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5865 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5866 | } |
| 5867 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5868 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5869 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5870 | }; |
| 5871 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5872 | GLsizei writtenColumns = 0; |
| 5873 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5874 | { |
| 5875 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5876 | return false; |
| 5877 | } |
| 5878 | |
| 5879 | GLsizei writtenRows = 0; |
| 5880 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5881 | { |
| 5882 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5883 | return false; |
| 5884 | } |
| 5885 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5886 | if (columns != nullptr) |
| 5887 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5888 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | if (rows != nullptr) |
| 5892 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5893 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5894 | } |
| 5895 | |
| 5896 | return true; |
| 5897 | } |
| 5898 | |
| 5899 | template <typename ParamType> |
| 5900 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5901 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5902 | GLenum pname, |
| 5903 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5904 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5905 | const ParamType *params) |
| 5906 | { |
| 5907 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5908 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5909 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5910 | return false; |
| 5911 | } |
| 5912 | |
| 5913 | if (context->getTargetTexture(target) == nullptr) |
| 5914 | { |
| 5915 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5916 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5917 | return false; |
| 5918 | } |
| 5919 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5920 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5921 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5922 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5923 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5924 | return false; |
| 5925 | } |
| 5926 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5927 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5928 | { |
| 5929 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5930 | return false; |
| 5931 | } |
| 5932 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5933 | switch (pname) |
| 5934 | { |
| 5935 | case GL_TEXTURE_WRAP_R: |
| 5936 | case GL_TEXTURE_SWIZZLE_R: |
| 5937 | case GL_TEXTURE_SWIZZLE_G: |
| 5938 | case GL_TEXTURE_SWIZZLE_B: |
| 5939 | case GL_TEXTURE_SWIZZLE_A: |
| 5940 | case GL_TEXTURE_BASE_LEVEL: |
| 5941 | case GL_TEXTURE_MAX_LEVEL: |
| 5942 | case GL_TEXTURE_COMPARE_MODE: |
| 5943 | case GL_TEXTURE_COMPARE_FUNC: |
| 5944 | case GL_TEXTURE_MIN_LOD: |
| 5945 | case GL_TEXTURE_MAX_LOD: |
| 5946 | if (context->getClientMajorVersion() < 3) |
| 5947 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5948 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5949 | return false; |
| 5950 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5951 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5952 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5953 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5954 | "available without " |
| 5955 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5956 | return false; |
| 5957 | } |
| 5958 | break; |
| 5959 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5960 | case GL_GENERATE_MIPMAP: |
| 5961 | case GL_TEXTURE_CROP_RECT_OES: |
| 5962 | if (context->getClientMajorVersion() > 1) |
| 5963 | { |
| 5964 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5965 | return false; |
| 5966 | } |
| 5967 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5968 | default: |
| 5969 | break; |
| 5970 | } |
| 5971 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5972 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5973 | { |
| 5974 | switch (pname) |
| 5975 | { |
| 5976 | case GL_TEXTURE_MIN_FILTER: |
| 5977 | case GL_TEXTURE_MAG_FILTER: |
| 5978 | case GL_TEXTURE_WRAP_S: |
| 5979 | case GL_TEXTURE_WRAP_T: |
| 5980 | case GL_TEXTURE_WRAP_R: |
| 5981 | case GL_TEXTURE_MIN_LOD: |
| 5982 | case GL_TEXTURE_MAX_LOD: |
| 5983 | case GL_TEXTURE_COMPARE_MODE: |
| 5984 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5985 | case GL_TEXTURE_BORDER_COLOR: |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5986 | context->handleError(InvalidEnum() |
| 5987 | << "Invalid parameter for 2D multisampled textures."); |
| 5988 | return false; |
| 5989 | } |
| 5990 | } |
| 5991 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5992 | switch (pname) |
| 5993 | { |
| 5994 | case GL_TEXTURE_WRAP_S: |
| 5995 | case GL_TEXTURE_WRAP_T: |
| 5996 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5997 | { |
| 5998 | bool restrictedWrapModes = |
| 5999 | target == TextureType::External || target == TextureType::Rectangle; |
| 6000 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6001 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6002 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6003 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6004 | } |
| 6005 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6006 | |
| 6007 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6008 | { |
| 6009 | bool restrictedMinFilter = |
| 6010 | target == TextureType::External || target == TextureType::Rectangle; |
| 6011 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6012 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6013 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6014 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6015 | } |
| 6016 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6017 | |
| 6018 | case GL_TEXTURE_MAG_FILTER: |
| 6019 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6020 | { |
| 6021 | return false; |
| 6022 | } |
| 6023 | break; |
| 6024 | |
| 6025 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6026 | if (!context->getExtensions().textureUsage) |
| 6027 | { |
| 6028 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6029 | return false; |
| 6030 | } |
| 6031 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6032 | switch (ConvertToGLenum(params[0])) |
| 6033 | { |
| 6034 | case GL_NONE: |
| 6035 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6036 | break; |
| 6037 | |
| 6038 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6039 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6040 | return false; |
| 6041 | } |
| 6042 | break; |
| 6043 | |
| 6044 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6045 | { |
| 6046 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6047 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6048 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6049 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6050 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6051 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6052 | } |
| 6053 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6054 | |
| 6055 | case GL_TEXTURE_MIN_LOD: |
| 6056 | case GL_TEXTURE_MAX_LOD: |
| 6057 | // any value is permissible |
| 6058 | break; |
| 6059 | |
| 6060 | case GL_TEXTURE_COMPARE_MODE: |
| 6061 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6062 | { |
| 6063 | return false; |
| 6064 | } |
| 6065 | break; |
| 6066 | |
| 6067 | case GL_TEXTURE_COMPARE_FUNC: |
| 6068 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6069 | { |
| 6070 | return false; |
| 6071 | } |
| 6072 | break; |
| 6073 | |
| 6074 | case GL_TEXTURE_SWIZZLE_R: |
| 6075 | case GL_TEXTURE_SWIZZLE_G: |
| 6076 | case GL_TEXTURE_SWIZZLE_B: |
| 6077 | case GL_TEXTURE_SWIZZLE_A: |
| 6078 | switch (ConvertToGLenum(params[0])) |
| 6079 | { |
| 6080 | case GL_RED: |
| 6081 | case GL_GREEN: |
| 6082 | case GL_BLUE: |
| 6083 | case GL_ALPHA: |
| 6084 | case GL_ZERO: |
| 6085 | case GL_ONE: |
| 6086 | break; |
| 6087 | |
| 6088 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6089 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6090 | return false; |
| 6091 | } |
| 6092 | break; |
| 6093 | |
| 6094 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6095 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6096 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6097 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6098 | return false; |
| 6099 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6100 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6101 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6102 | context->handleError(InvalidOperation() |
| 6103 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6104 | return false; |
| 6105 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6106 | if ((target == TextureType::_2DMultisample || |
| 6107 | target == TextureType::_2DMultisampleArray) && |
| 6108 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6109 | { |
| 6110 | context->handleError(InvalidOperation() |
| 6111 | << "Base level must be 0 for multisampled textures."); |
| 6112 | return false; |
| 6113 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6114 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6115 | { |
| 6116 | context->handleError(InvalidOperation() |
| 6117 | << "Base level must be 0 for rectangle textures."); |
| 6118 | return false; |
| 6119 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6120 | break; |
| 6121 | |
| 6122 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6123 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6124 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6125 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6126 | return false; |
| 6127 | } |
| 6128 | break; |
| 6129 | |
| 6130 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6131 | if (context->getClientVersion() < Version(3, 1)) |
| 6132 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6133 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6134 | return false; |
| 6135 | } |
| 6136 | switch (ConvertToGLenum(params[0])) |
| 6137 | { |
| 6138 | case GL_DEPTH_COMPONENT: |
| 6139 | case GL_STENCIL_INDEX: |
| 6140 | break; |
| 6141 | |
| 6142 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6143 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6144 | return false; |
| 6145 | } |
| 6146 | break; |
| 6147 | |
| 6148 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6149 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6150 | { |
| 6151 | return false; |
| 6152 | } |
| 6153 | break; |
| 6154 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6155 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6156 | if (context->getClientMajorVersion() > 1) |
| 6157 | { |
| 6158 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6159 | return false; |
| 6160 | } |
| 6161 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6162 | |
| 6163 | case GL_TEXTURE_CROP_RECT_OES: |
| 6164 | if (context->getClientMajorVersion() > 1) |
| 6165 | { |
| 6166 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6167 | return false; |
| 6168 | } |
| 6169 | if (!vectorParams) |
| 6170 | { |
| 6171 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6172 | return false; |
| 6173 | } |
| 6174 | break; |
| 6175 | |
| 6176 | case GL_TEXTURE_BORDER_COLOR: |
| 6177 | if (!context->getExtensions().textureBorderClamp) |
| 6178 | { |
| 6179 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 6180 | return false; |
| 6181 | } |
| 6182 | if (!vectorParams) |
| 6183 | { |
| 6184 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InsufficientBufferSize); |
| 6185 | return false; |
| 6186 | } |
| 6187 | break; |
| 6188 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6189 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6190 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6191 | return false; |
| 6192 | } |
| 6193 | |
| 6194 | return true; |
| 6195 | } |
| 6196 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6197 | template bool ValidateTexParameterBase(Context *, |
| 6198 | TextureType, |
| 6199 | GLenum, |
| 6200 | GLsizei, |
| 6201 | bool, |
| 6202 | const GLfloat *); |
| 6203 | template bool ValidateTexParameterBase(Context *, |
| 6204 | TextureType, |
| 6205 | GLenum, |
| 6206 | GLsizei, |
| 6207 | bool, |
| 6208 | const GLint *); |
| 6209 | template bool ValidateTexParameterBase(Context *, |
| 6210 | TextureType, |
| 6211 | GLenum, |
| 6212 | GLsizei, |
| 6213 | bool, |
| 6214 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6215 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6216 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6217 | { |
| 6218 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6219 | { |
| 6220 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6221 | return false; |
| 6222 | } |
| 6223 | |
| 6224 | return true; |
| 6225 | } |
| 6226 | |
| 6227 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6228 | GLuint program, |
| 6229 | GLuint uniformBlockIndex, |
| 6230 | GLenum pname, |
| 6231 | GLsizei *length) |
| 6232 | { |
| 6233 | if (length) |
| 6234 | { |
| 6235 | *length = 0; |
| 6236 | } |
| 6237 | |
| 6238 | if (context->getClientMajorVersion() < 3) |
| 6239 | { |
| 6240 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6241 | return false; |
| 6242 | } |
| 6243 | |
| 6244 | Program *programObject = GetValidProgram(context, program); |
| 6245 | if (!programObject) |
| 6246 | { |
| 6247 | return false; |
| 6248 | } |
| 6249 | |
| 6250 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6251 | { |
| 6252 | context->handleError(InvalidValue() |
| 6253 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6254 | return false; |
| 6255 | } |
| 6256 | |
| 6257 | switch (pname) |
| 6258 | { |
| 6259 | case GL_UNIFORM_BLOCK_BINDING: |
| 6260 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6261 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6262 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6263 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6264 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6265 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6266 | break; |
| 6267 | |
| 6268 | default: |
| 6269 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6270 | return false; |
| 6271 | } |
| 6272 | |
| 6273 | if (length) |
| 6274 | { |
| 6275 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6276 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6277 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6278 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6279 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6280 | } |
| 6281 | else |
| 6282 | { |
| 6283 | *length = 1; |
| 6284 | } |
| 6285 | } |
| 6286 | |
| 6287 | return true; |
| 6288 | } |
| 6289 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6290 | template <typename ParamType> |
| 6291 | bool ValidateSamplerParameterBase(Context *context, |
| 6292 | GLuint sampler, |
| 6293 | GLenum pname, |
| 6294 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6295 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6296 | ParamType *params) |
| 6297 | { |
| 6298 | if (context->getClientMajorVersion() < 3) |
| 6299 | { |
| 6300 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6301 | return false; |
| 6302 | } |
| 6303 | |
| 6304 | if (!context->isSampler(sampler)) |
| 6305 | { |
| 6306 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6307 | return false; |
| 6308 | } |
| 6309 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6310 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6311 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6312 | { |
| 6313 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6314 | return false; |
| 6315 | } |
| 6316 | |
| 6317 | switch (pname) |
| 6318 | { |
| 6319 | case GL_TEXTURE_WRAP_S: |
| 6320 | case GL_TEXTURE_WRAP_T: |
| 6321 | case GL_TEXTURE_WRAP_R: |
| 6322 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6323 | { |
| 6324 | return false; |
| 6325 | } |
| 6326 | break; |
| 6327 | |
| 6328 | case GL_TEXTURE_MIN_FILTER: |
| 6329 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6330 | { |
| 6331 | return false; |
| 6332 | } |
| 6333 | break; |
| 6334 | |
| 6335 | case GL_TEXTURE_MAG_FILTER: |
| 6336 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6337 | { |
| 6338 | return false; |
| 6339 | } |
| 6340 | break; |
| 6341 | |
| 6342 | case GL_TEXTURE_MIN_LOD: |
| 6343 | case GL_TEXTURE_MAX_LOD: |
| 6344 | // any value is permissible |
| 6345 | break; |
| 6346 | |
| 6347 | case GL_TEXTURE_COMPARE_MODE: |
| 6348 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6349 | { |
| 6350 | return false; |
| 6351 | } |
| 6352 | break; |
| 6353 | |
| 6354 | case GL_TEXTURE_COMPARE_FUNC: |
| 6355 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6356 | { |
| 6357 | return false; |
| 6358 | } |
| 6359 | break; |
| 6360 | |
| 6361 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6362 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6363 | { |
| 6364 | return false; |
| 6365 | } |
| 6366 | break; |
| 6367 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6368 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6369 | { |
| 6370 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6371 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6372 | { |
| 6373 | return false; |
| 6374 | } |
| 6375 | } |
| 6376 | break; |
| 6377 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6378 | case GL_TEXTURE_BORDER_COLOR: |
| 6379 | if (!context->getExtensions().textureBorderClamp) |
| 6380 | { |
| 6381 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 6382 | return false; |
| 6383 | } |
| 6384 | if (!vectorParams) |
| 6385 | { |
| 6386 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InsufficientBufferSize); |
| 6387 | return false; |
| 6388 | } |
| 6389 | break; |
| 6390 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6391 | default: |
| 6392 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6393 | return false; |
| 6394 | } |
| 6395 | |
| 6396 | return true; |
| 6397 | } |
| 6398 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6399 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6400 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6401 | template bool ValidateSamplerParameterBase(Context *, |
| 6402 | GLuint, |
| 6403 | GLenum, |
| 6404 | GLsizei, |
| 6405 | bool, |
| 6406 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6407 | |
| 6408 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6409 | GLuint sampler, |
| 6410 | GLenum pname, |
| 6411 | GLsizei *length) |
| 6412 | { |
| 6413 | if (length) |
| 6414 | { |
| 6415 | *length = 0; |
| 6416 | } |
| 6417 | |
| 6418 | if (context->getClientMajorVersion() < 3) |
| 6419 | { |
| 6420 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6421 | return false; |
| 6422 | } |
| 6423 | |
| 6424 | if (!context->isSampler(sampler)) |
| 6425 | { |
| 6426 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6427 | return false; |
| 6428 | } |
| 6429 | |
| 6430 | switch (pname) |
| 6431 | { |
| 6432 | case GL_TEXTURE_WRAP_S: |
| 6433 | case GL_TEXTURE_WRAP_T: |
| 6434 | case GL_TEXTURE_WRAP_R: |
| 6435 | case GL_TEXTURE_MIN_FILTER: |
| 6436 | case GL_TEXTURE_MAG_FILTER: |
| 6437 | case GL_TEXTURE_MIN_LOD: |
| 6438 | case GL_TEXTURE_MAX_LOD: |
| 6439 | case GL_TEXTURE_COMPARE_MODE: |
| 6440 | case GL_TEXTURE_COMPARE_FUNC: |
| 6441 | break; |
| 6442 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6443 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6444 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6445 | { |
| 6446 | return false; |
| 6447 | } |
| 6448 | break; |
| 6449 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6450 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6451 | if (!context->getExtensions().textureSRGBDecode) |
| 6452 | { |
| 6453 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6454 | return false; |
| 6455 | } |
| 6456 | break; |
| 6457 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6458 | case GL_TEXTURE_BORDER_COLOR: |
| 6459 | if (!context->getExtensions().textureBorderClamp) |
| 6460 | { |
| 6461 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 6462 | return false; |
| 6463 | } |
| 6464 | break; |
| 6465 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6466 | default: |
| 6467 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6468 | return false; |
| 6469 | } |
| 6470 | |
| 6471 | if (length) |
| 6472 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6473 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6474 | } |
| 6475 | return true; |
| 6476 | } |
| 6477 | |
| 6478 | bool ValidateGetInternalFormativBase(Context *context, |
| 6479 | GLenum target, |
| 6480 | GLenum internalformat, |
| 6481 | GLenum pname, |
| 6482 | GLsizei bufSize, |
| 6483 | GLsizei *numParams) |
| 6484 | { |
| 6485 | if (numParams) |
| 6486 | { |
| 6487 | *numParams = 0; |
| 6488 | } |
| 6489 | |
| 6490 | if (context->getClientMajorVersion() < 3) |
| 6491 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6492 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6493 | return false; |
| 6494 | } |
| 6495 | |
| 6496 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6497 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6498 | { |
| 6499 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6500 | return false; |
| 6501 | } |
| 6502 | |
| 6503 | switch (target) |
| 6504 | { |
| 6505 | case GL_RENDERBUFFER: |
| 6506 | break; |
| 6507 | |
| 6508 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6509 | if (context->getClientVersion() < ES_3_1 && |
| 6510 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6511 | { |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6512 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 6513 | MultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6514 | return false; |
| 6515 | } |
| 6516 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6517 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6518 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6519 | { |
| 6520 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 6521 | return false; |
| 6522 | } |
| 6523 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6524 | default: |
| 6525 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6526 | return false; |
| 6527 | } |
| 6528 | |
| 6529 | if (bufSize < 0) |
| 6530 | { |
| 6531 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6532 | return false; |
| 6533 | } |
| 6534 | |
| 6535 | GLsizei maxWriteParams = 0; |
| 6536 | switch (pname) |
| 6537 | { |
| 6538 | case GL_NUM_SAMPLE_COUNTS: |
| 6539 | maxWriteParams = 1; |
| 6540 | break; |
| 6541 | |
| 6542 | case GL_SAMPLES: |
| 6543 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6544 | break; |
| 6545 | |
| 6546 | default: |
| 6547 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6548 | return false; |
| 6549 | } |
| 6550 | |
| 6551 | if (numParams) |
| 6552 | { |
| 6553 | // glGetInternalFormativ will not overflow bufSize |
| 6554 | *numParams = std::min(bufSize, maxWriteParams); |
| 6555 | } |
| 6556 | |
| 6557 | return true; |
| 6558 | } |
| 6559 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6560 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6561 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6562 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6563 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 6564 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6565 | return false; |
| 6566 | } |
| 6567 | return true; |
| 6568 | } |
| 6569 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6570 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6571 | { |
| 6572 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6573 | { |
| 6574 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6575 | return false; |
| 6576 | } |
| 6577 | return true; |
| 6578 | } |
| 6579 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6580 | bool ValidateTexStorageMultisample(Context *context, |
| 6581 | TextureType target, |
| 6582 | GLsizei samples, |
| 6583 | GLint internalFormat, |
| 6584 | GLsizei width, |
| 6585 | GLsizei height) |
| 6586 | { |
| 6587 | const Caps &caps = context->getCaps(); |
| 6588 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6589 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6590 | { |
| 6591 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureWidthOrHeightOutOfRange); |
| 6592 | return false; |
| 6593 | } |
| 6594 | |
| 6595 | if (samples == 0) |
| 6596 | { |
| 6597 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SamplesZero); |
| 6598 | return false; |
| 6599 | } |
| 6600 | |
| 6601 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6602 | if (!formatCaps.textureAttachment) |
| 6603 | { |
| 6604 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), RenderableInternalFormat); |
| 6605 | return false; |
| 6606 | } |
| 6607 | |
| 6608 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6609 | // is one of the unsized base internalformats listed in table 8.11. |
| 6610 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6611 | if (formatInfo.internalFormat == GL_NONE) |
| 6612 | { |
| 6613 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnsizedInternalFormatUnsupported); |
| 6614 | return false; |
| 6615 | } |
| 6616 | |
| 6617 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6618 | { |
| 6619 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), SamplesOutOfRange); |
| 6620 | return false; |
| 6621 | } |
| 6622 | |
| 6623 | Texture *texture = context->getTargetTexture(target); |
| 6624 | if (!texture || texture->id() == 0) |
| 6625 | { |
| 6626 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ZeroBoundToTarget); |
| 6627 | return false; |
| 6628 | } |
| 6629 | |
| 6630 | if (texture->getImmutableFormat()) |
| 6631 | { |
| 6632 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ImmutableTextureBound); |
| 6633 | return false; |
| 6634 | } |
| 6635 | return true; |
| 6636 | } |
| 6637 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6638 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6639 | TextureType target, |
| 6640 | GLsizei samples, |
| 6641 | GLint internalFormat, |
| 6642 | GLsizei width, |
| 6643 | GLsizei height) |
| 6644 | { |
| 6645 | if (target != TextureType::_2DMultisample) |
| 6646 | { |
| 6647 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6648 | return false; |
| 6649 | } |
| 6650 | |
| 6651 | if (width < 1 || height < 1) |
| 6652 | { |
| 6653 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
| 6654 | return false; |
| 6655 | } |
| 6656 | |
| 6657 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6658 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6659 | |
| 6660 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6661 | TextureTarget target, |
| 6662 | GLint level, |
| 6663 | GLenum pname, |
| 6664 | GLsizei *length) |
| 6665 | { |
| 6666 | |
| 6667 | if (length) |
| 6668 | { |
| 6669 | *length = 0; |
| 6670 | } |
| 6671 | |
| 6672 | TextureType type = TextureTargetToType(target); |
| 6673 | |
| 6674 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6675 | { |
| 6676 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 6677 | return false; |
| 6678 | } |
| 6679 | |
| 6680 | if (context->getTargetTexture(type) == nullptr) |
| 6681 | { |
| 6682 | context->handleError(InvalidEnum() << "No texture bound."); |
| 6683 | return false; |
| 6684 | } |
| 6685 | |
| 6686 | if (!ValidMipLevel(context, type, level)) |
| 6687 | { |
| 6688 | context->handleError(InvalidValue()); |
| 6689 | return false; |
| 6690 | } |
| 6691 | |
| 6692 | switch (pname) |
| 6693 | { |
| 6694 | case GL_TEXTURE_RED_TYPE: |
| 6695 | case GL_TEXTURE_GREEN_TYPE: |
| 6696 | case GL_TEXTURE_BLUE_TYPE: |
| 6697 | case GL_TEXTURE_ALPHA_TYPE: |
| 6698 | case GL_TEXTURE_DEPTH_TYPE: |
| 6699 | break; |
| 6700 | case GL_TEXTURE_RED_SIZE: |
| 6701 | case GL_TEXTURE_GREEN_SIZE: |
| 6702 | case GL_TEXTURE_BLUE_SIZE: |
| 6703 | case GL_TEXTURE_ALPHA_SIZE: |
| 6704 | case GL_TEXTURE_DEPTH_SIZE: |
| 6705 | case GL_TEXTURE_STENCIL_SIZE: |
| 6706 | case GL_TEXTURE_SHARED_SIZE: |
| 6707 | break; |
| 6708 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6709 | case GL_TEXTURE_WIDTH: |
| 6710 | case GL_TEXTURE_HEIGHT: |
| 6711 | case GL_TEXTURE_DEPTH: |
| 6712 | break; |
| 6713 | case GL_TEXTURE_SAMPLES: |
| 6714 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6715 | break; |
| 6716 | case GL_TEXTURE_COMPRESSED: |
| 6717 | break; |
| 6718 | default: |
| 6719 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
| 6720 | return false; |
| 6721 | } |
| 6722 | |
| 6723 | if (length) |
| 6724 | { |
| 6725 | *length = 1; |
| 6726 | } |
| 6727 | return true; |
| 6728 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6729 | } // namespace gl |