Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 12 | #include "libANGLE/Display.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 13 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Query.h" |
| 19 | #include "libANGLE/Texture.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 24 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 25 | #include "libANGLE/queryutils.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 26 | #include "libANGLE/validationES2.h" |
| 27 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 28 | |
| 29 | #include "common/mathutil.h" |
| 30 | #include "common/utilities.h" |
| 31 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 32 | using namespace angle; |
| 33 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 36 | namespace |
| 37 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 38 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 39 | { |
| 40 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 41 | // the compressed block size. |
| 42 | switch (internalFormat) |
| 43 | { |
| 44 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 48 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 52 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 53 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 59 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 60 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 61 | default: |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 66 | { |
| 67 | // Compressed sub textures have additional formats that requires exact size. |
| 68 | // ES 3.1, Section 8.7, Page 171 |
| 69 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 70 | IsETC2EACFormat(internalFormat); |
| 71 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 72 | |
| 73 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 74 | { |
| 75 | CheckedNumeric<GLint> checkedA(a); |
| 76 | checkedA -= b; |
| 77 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 78 | checkedA = -checkedA; |
| 79 | return !checkedA.IsValid(); |
| 80 | } |
| 81 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 82 | bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 83 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 84 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 85 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 86 | |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 87 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 88 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 89 | { |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 90 | return true; |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 91 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 92 | |
Jamie Madill | 88602e6 | 2018-08-08 12:49:30 -0400 | [diff] [blame] | 93 | // An overflow can happen when adding the offset. Check against a special constant. |
| 94 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 95 | VertexAttribute::kIntegerOverflow || |
| 96 | context->getStateCache().getInstancedVertexElementLimit() == |
| 97 | VertexAttribute::kIntegerOverflow) |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 98 | { |
| 99 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 104 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
| 105 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
| 106 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 109 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 110 | { |
| 111 | switch (type) |
| 112 | { |
| 113 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 114 | case GL_UNSIGNED_BYTE: |
| 115 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 116 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 117 | case GL_UNSIGNED_SHORT_5_6_5: |
| 118 | return context->getClientVersion() >= ES_2_0; |
| 119 | |
| 120 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 121 | case GL_BYTE: |
| 122 | case GL_INT: |
| 123 | case GL_SHORT: |
| 124 | case GL_UNSIGNED_INT: |
| 125 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 126 | case GL_UNSIGNED_INT_24_8: |
| 127 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 128 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 129 | case GL_UNSIGNED_SHORT: |
| 130 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 131 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 132 | return context->getClientVersion() >= ES_3_0; |
| 133 | |
| 134 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 135 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 136 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 137 | |
| 138 | case GL_HALF_FLOAT: |
| 139 | return context->getClientVersion() >= ES_3_0 || |
| 140 | context->getExtensions().textureHalfFloat; |
| 141 | |
| 142 | case GL_HALF_FLOAT_OES: |
| 143 | return context->getExtensions().colorBufferHalfFloat; |
| 144 | |
| 145 | default: |
| 146 | return false; |
| 147 | } |
| 148 | } |
| 149 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 150 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 151 | { |
| 152 | switch (format) |
| 153 | { |
| 154 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 155 | case GL_RGBA: |
| 156 | case GL_RGB: |
| 157 | case GL_ALPHA: |
| 158 | return context->getClientVersion() >= ES_2_0; |
| 159 | |
| 160 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 161 | case GL_RG: |
| 162 | case GL_RED: |
| 163 | case GL_RGBA_INTEGER: |
| 164 | case GL_RGB_INTEGER: |
| 165 | case GL_RG_INTEGER: |
| 166 | case GL_RED_INTEGER: |
| 167 | return context->getClientVersion() >= ES_3_0; |
| 168 | |
| 169 | case GL_SRGB_ALPHA_EXT: |
| 170 | case GL_SRGB_EXT: |
| 171 | return context->getExtensions().sRGB; |
| 172 | |
| 173 | case GL_BGRA_EXT: |
| 174 | return context->getExtensions().readFormatBGRA; |
| 175 | |
| 176 | default: |
| 177 | return false; |
| 178 | } |
| 179 | } |
| 180 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 181 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 182 | GLenum framebufferComponentType, |
| 183 | GLenum format, |
| 184 | GLenum type) |
| 185 | { |
| 186 | switch (framebufferComponentType) |
| 187 | { |
| 188 | case GL_UNSIGNED_NORMALIZED: |
| 189 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 190 | // ReadPixels with BGRA even if the extension is not present |
| 191 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 192 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 193 | type == GL_UNSIGNED_BYTE); |
| 194 | |
| 195 | case GL_SIGNED_NORMALIZED: |
| 196 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 197 | |
| 198 | case GL_INT: |
| 199 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 200 | |
| 201 | case GL_UNSIGNED_INT: |
| 202 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 203 | |
| 204 | case GL_FLOAT: |
| 205 | return (format == GL_RGBA && type == GL_FLOAT); |
| 206 | |
| 207 | default: |
| 208 | UNREACHABLE(); |
| 209 | return false; |
| 210 | } |
| 211 | } |
| 212 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 213 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 214 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 215 | { |
| 216 | switch (ConvertToGLenum(params[0])) |
| 217 | { |
| 218 | case GL_CLAMP_TO_EDGE: |
| 219 | break; |
| 220 | |
| 221 | case GL_REPEAT: |
| 222 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 223 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 224 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 225 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 226 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 227 | return false; |
| 228 | } |
| 229 | break; |
| 230 | |
| 231 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 232 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 233 | return false; |
| 234 | } |
| 235 | |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 240 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 241 | { |
| 242 | switch (ConvertToGLenum(params[0])) |
| 243 | { |
| 244 | case GL_NEAREST: |
| 245 | case GL_LINEAR: |
| 246 | break; |
| 247 | |
| 248 | case GL_NEAREST_MIPMAP_NEAREST: |
| 249 | case GL_LINEAR_MIPMAP_NEAREST: |
| 250 | case GL_NEAREST_MIPMAP_LINEAR: |
| 251 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 252 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 253 | { |
| 254 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 255 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 256 | return false; |
| 257 | } |
| 258 | break; |
| 259 | |
| 260 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 261 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 262 | return false; |
| 263 | } |
| 264 | |
| 265 | return true; |
| 266 | } |
| 267 | |
| 268 | template <typename ParamType> |
| 269 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 270 | { |
| 271 | switch (ConvertToGLenum(params[0])) |
| 272 | { |
| 273 | case GL_NEAREST: |
| 274 | case GL_LINEAR: |
| 275 | break; |
| 276 | |
| 277 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 278 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 279 | return false; |
| 280 | } |
| 281 | |
| 282 | return true; |
| 283 | } |
| 284 | |
| 285 | template <typename ParamType> |
| 286 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 287 | { |
| 288 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 289 | switch (ConvertToGLenum(params[0])) |
| 290 | { |
| 291 | case GL_NONE: |
| 292 | case GL_COMPARE_REF_TO_TEXTURE: |
| 293 | break; |
| 294 | |
| 295 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 296 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 297 | return false; |
| 298 | } |
| 299 | |
| 300 | return true; |
| 301 | } |
| 302 | |
| 303 | template <typename ParamType> |
| 304 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 305 | { |
| 306 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 307 | switch (ConvertToGLenum(params[0])) |
| 308 | { |
| 309 | case GL_LEQUAL: |
| 310 | case GL_GEQUAL: |
| 311 | case GL_LESS: |
| 312 | case GL_GREATER: |
| 313 | case GL_EQUAL: |
| 314 | case GL_NOTEQUAL: |
| 315 | case GL_ALWAYS: |
| 316 | case GL_NEVER: |
| 317 | break; |
| 318 | |
| 319 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 320 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 321 | return false; |
| 322 | } |
| 323 | |
| 324 | return true; |
| 325 | } |
| 326 | |
| 327 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 328 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 329 | { |
| 330 | if (!context->getExtensions().textureSRGBDecode) |
| 331 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 332 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 333 | return false; |
| 334 | } |
| 335 | |
| 336 | switch (ConvertToGLenum(params[0])) |
| 337 | { |
| 338 | case GL_DECODE_EXT: |
| 339 | case GL_SKIP_DECODE_EXT: |
| 340 | break; |
| 341 | |
| 342 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 343 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 344 | return false; |
| 345 | } |
| 346 | |
| 347 | return true; |
| 348 | } |
| 349 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 350 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 351 | { |
| 352 | if (!context->getExtensions().textureFilterAnisotropic) |
| 353 | { |
| 354 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 355 | return false; |
| 356 | } |
| 357 | |
| 358 | return true; |
| 359 | } |
| 360 | |
| 361 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 362 | { |
| 363 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 364 | { |
| 365 | return false; |
| 366 | } |
| 367 | |
| 368 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 369 | |
| 370 | if (paramValue < 1 || paramValue > largest) |
| 371 | { |
| 372 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 373 | return false; |
| 374 | } |
| 375 | |
| 376 | return true; |
| 377 | } |
| 378 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 379 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 380 | { |
| 381 | const Program *program = context->getGLState().getProgram(); |
| 382 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 383 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 384 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 385 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 386 | program->getActiveOutputVariables().to_ulong(), |
| 387 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 388 | } |
| 389 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 390 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 391 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 392 | const auto &glState = context->getGLState(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 393 | const Program *program = context->getGLState().getProgram(); |
| 394 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 395 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 396 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 397 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 398 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 399 | |
| 400 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 401 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 402 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 403 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 404 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 405 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 406 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 409 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 410 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 411 | { |
| 412 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 413 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 414 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 415 | case PrimitiveMode::Points: |
| 416 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 417 | case PrimitiveMode::Lines: |
| 418 | case PrimitiveMode::LineStrip: |
| 419 | case PrimitiveMode::LineLoop: |
| 420 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 421 | case PrimitiveMode::LinesAdjacency: |
| 422 | case PrimitiveMode::LineStripAdjacency: |
| 423 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 424 | case PrimitiveMode::Triangles: |
| 425 | case PrimitiveMode::TriangleFan: |
| 426 | case PrimitiveMode::TriangleStrip: |
| 427 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 428 | case PrimitiveMode::TrianglesAdjacency: |
| 429 | case PrimitiveMode::TriangleStripAdjacency: |
| 430 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 431 | default: |
| 432 | UNREACHABLE(); |
| 433 | return false; |
| 434 | } |
| 435 | } |
| 436 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 437 | // GLES1 texture parameters are a small subset of the others |
| 438 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 439 | { |
| 440 | switch (pname) |
| 441 | { |
| 442 | case GL_TEXTURE_MAG_FILTER: |
| 443 | case GL_TEXTURE_MIN_FILTER: |
| 444 | case GL_TEXTURE_WRAP_S: |
| 445 | case GL_TEXTURE_WRAP_T: |
| 446 | case GL_TEXTURE_WRAP_R: |
| 447 | case GL_GENERATE_MIPMAP: |
| 448 | case GL_TEXTURE_CROP_RECT_OES: |
| 449 | return true; |
| 450 | default: |
| 451 | return false; |
| 452 | } |
| 453 | } |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 454 | } // anonymous namespace |
| 455 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 456 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 457 | { |
| 458 | if (length) |
| 459 | { |
| 460 | *length = value; |
| 461 | } |
| 462 | } |
| 463 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 464 | bool IsETC2EACFormat(const GLenum format) |
| 465 | { |
| 466 | // ES 3.1, Table 8.19 |
| 467 | switch (format) |
| 468 | { |
| 469 | case GL_COMPRESSED_R11_EAC: |
| 470 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 471 | case GL_COMPRESSED_RG11_EAC: |
| 472 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 473 | case GL_COMPRESSED_RGB8_ETC2: |
| 474 | case GL_COMPRESSED_SRGB8_ETC2: |
| 475 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 476 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 477 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 478 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 479 | return true; |
| 480 | |
| 481 | default: |
| 482 | return false; |
| 483 | } |
| 484 | } |
| 485 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 486 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 487 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 488 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 489 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 490 | case TextureType::_2D: |
| 491 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 492 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 493 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 494 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 495 | return context->getExtensions().textureRectangle; |
| 496 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 497 | case TextureType::_3D: |
| 498 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 499 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 500 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 501 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 502 | return (context->getClientVersion() >= Version(3, 1)); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 503 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 504 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 505 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 506 | default: |
| 507 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 508 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 509 | } |
| 510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 511 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 512 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 513 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 514 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 515 | case TextureType::_2D: |
| 516 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 517 | return true; |
| 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 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 522 | default: |
| 523 | return false; |
| 524 | } |
| 525 | } |
| 526 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 527 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 528 | { |
| 529 | switch (target) |
| 530 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 531 | case TextureType::_3D: |
| 532 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 533 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 534 | |
| 535 | default: |
| 536 | return false; |
| 537 | } |
| 538 | } |
| 539 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 540 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 541 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 542 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 543 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 544 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 545 | (context->getExtensions().eglImageExternal || |
| 546 | context->getExtensions().eglStreamConsumerExternal); |
| 547 | } |
| 548 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 549 | // This function differs from ValidTextureTarget in that the target must be |
| 550 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 551 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 552 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 553 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 554 | { |
| 555 | switch (target) |
| 556 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 557 | case TextureTarget::_2D: |
| 558 | case TextureTarget::CubeMapNegativeX: |
| 559 | case TextureTarget::CubeMapNegativeY: |
| 560 | case TextureTarget::CubeMapNegativeZ: |
| 561 | case TextureTarget::CubeMapPositiveX: |
| 562 | case TextureTarget::CubeMapPositiveY: |
| 563 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 564 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 565 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 566 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 567 | default: |
| 568 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 572 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 573 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 574 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 575 | { |
| 576 | ASSERT(context); |
| 577 | |
| 578 | if (!context->getExtensions().geometryShader) |
| 579 | { |
| 580 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 581 | // that does not match the current transform feedback object's draw mode (if transform |
| 582 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 583 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 584 | } |
| 585 | |
| 586 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 587 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 588 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 589 | case PrimitiveMode::Points: |
| 590 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 591 | case PrimitiveMode::Lines: |
| 592 | case PrimitiveMode::LineStrip: |
| 593 | case PrimitiveMode::LineLoop: |
| 594 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 595 | case PrimitiveMode::Triangles: |
| 596 | case PrimitiveMode::TriangleFan: |
| 597 | case PrimitiveMode::TriangleStrip: |
| 598 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 599 | default: |
| 600 | UNREACHABLE(); |
| 601 | return false; |
| 602 | } |
| 603 | } |
| 604 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 605 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 606 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 607 | GLsizei count, |
| 608 | GLenum type, |
| 609 | const GLvoid *indices, |
| 610 | GLsizei primcount) |
| 611 | { |
| 612 | if (primcount < 0) |
| 613 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 614 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 615 | return false; |
| 616 | } |
| 617 | |
| 618 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 619 | { |
| 620 | return false; |
| 621 | } |
| 622 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 623 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 627 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 628 | GLint first, |
| 629 | GLsizei count, |
| 630 | GLsizei primcount) |
| 631 | { |
| 632 | if (primcount < 0) |
| 633 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 634 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | return false; |
| 636 | } |
| 637 | |
| 638 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 639 | { |
| 640 | return false; |
| 641 | } |
| 642 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 643 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 644 | } |
| 645 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 646 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 647 | { |
| 648 | // Verify there is at least one active attribute with a divisor of zero |
| 649 | const State &state = context->getGLState(); |
| 650 | |
| 651 | Program *program = state.getProgram(); |
| 652 | |
| 653 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 654 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 655 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 656 | { |
| 657 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 658 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 659 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 660 | { |
| 661 | return true; |
| 662 | } |
| 663 | } |
| 664 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 665 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 666 | return false; |
| 667 | } |
| 668 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 669 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 670 | { |
| 671 | switch (target) |
| 672 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 673 | case TextureType::_3D: |
| 674 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 675 | return true; |
| 676 | default: |
| 677 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 678 | } |
| 679 | } |
| 680 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 681 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 682 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 683 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 684 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 685 | case TextureType::_2D: |
| 686 | case TextureType::_2DArray: |
| 687 | case TextureType::_2DMultisample: |
| 688 | case TextureType::CubeMap: |
| 689 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 690 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 691 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 692 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 693 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 694 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 695 | default: |
| 696 | return false; |
| 697 | } |
| 698 | } |
| 699 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 700 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 701 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 702 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 703 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 704 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 705 | |
| 706 | switch (target) |
| 707 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 708 | case GL_FRAMEBUFFER: |
| 709 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 710 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 711 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 712 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 713 | return (context->getExtensions().framebufferBlit || |
| 714 | context->getClientMajorVersion() >= 3); |
| 715 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 716 | default: |
| 717 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 721 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 722 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 723 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 724 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 725 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 726 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 727 | case TextureType::_2D: |
| 728 | case TextureType::_2DArray: |
| 729 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 730 | case TextureType::_2DMultisampleArray: |
| 731 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 732 | // 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] | 733 | maxDimension = caps.max2DTextureSize; |
| 734 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 735 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 736 | maxDimension = caps.maxCubeMapTextureSize; |
| 737 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 738 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 739 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 740 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 741 | maxDimension = caps.max3DTextureSize; |
| 742 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 743 | default: |
| 744 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 745 | } |
| 746 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 747 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 748 | } |
| 749 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 750 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 751 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 752 | GLint level, |
| 753 | GLsizei width, |
| 754 | GLsizei height, |
| 755 | GLsizei depth, |
| 756 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 757 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 758 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 759 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 760 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 761 | return false; |
| 762 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 763 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 764 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 765 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 766 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 767 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 768 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 769 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 770 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 771 | return false; |
| 772 | } |
| 773 | |
| 774 | if (!ValidMipLevel(context, target, level)) |
| 775 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 776 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 777 | return false; |
| 778 | } |
| 779 | |
| 780 | return true; |
| 781 | } |
| 782 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 783 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 784 | { |
| 785 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 786 | (size % blockSize == 0); |
| 787 | } |
| 788 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 789 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 790 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 791 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 792 | GLsizei width, |
| 793 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 794 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 795 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 796 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 797 | { |
| 798 | return false; |
| 799 | } |
| 800 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 801 | if (width < 0 || height < 0) |
| 802 | { |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 807 | { |
| 808 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 809 | // block size for level 0 but WebGL disallows this. |
| 810 | bool smallerThanBlockSizeAllowed = |
| 811 | level > 0 || !context->getExtensions().webglCompatibility; |
| 812 | |
| 813 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 814 | smallerThanBlockSizeAllowed) || |
| 815 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 816 | smallerThanBlockSizeAllowed)) |
| 817 | { |
| 818 | return false; |
| 819 | } |
| 820 | } |
| 821 | |
| 822 | return true; |
| 823 | } |
| 824 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 825 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 826 | GLenum internalFormat, |
| 827 | GLint xoffset, |
| 828 | GLint yoffset, |
| 829 | GLsizei width, |
| 830 | GLsizei height, |
| 831 | size_t textureWidth, |
| 832 | size_t textureHeight) |
| 833 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 834 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 835 | if (!formatInfo.compressed) |
| 836 | { |
| 837 | return false; |
| 838 | } |
| 839 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 840 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 841 | { |
| 842 | return false; |
| 843 | } |
| 844 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 845 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 846 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 847 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 848 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 849 | { |
| 850 | return false; |
| 851 | } |
| 852 | |
| 853 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 854 | // size but fills the entire mip |
| 855 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 856 | static_cast<size_t>(width) == textureWidth && |
| 857 | static_cast<size_t>(height) == textureHeight; |
| 858 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 859 | (height % formatInfo.compressedBlockHeight) == 0; |
| 860 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 861 | { |
| 862 | return false; |
| 863 | } |
| 864 | } |
| 865 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 866 | return true; |
| 867 | } |
| 868 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 869 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 870 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 871 | GLsizei width, |
| 872 | GLsizei height, |
| 873 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 874 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 875 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 876 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 877 | GLsizei imageSize) |
| 878 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 879 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 880 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 881 | { |
| 882 | // Checks are not required |
| 883 | return true; |
| 884 | } |
| 885 | |
| 886 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 887 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 888 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 889 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 890 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 891 | const auto &unpack = context->getGLState().getUnpackState(); |
| 892 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 893 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 894 | GLuint endByte = 0; |
| 895 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 896 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 897 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 898 | return false; |
| 899 | } |
| 900 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 901 | if (pixelUnpackBuffer) |
| 902 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 903 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 904 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 905 | checkedEndByte += checkedOffset; |
| 906 | |
| 907 | if (!checkedEndByte.IsValid() || |
| 908 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 909 | { |
| 910 | // Overflow past the end of the buffer |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 911 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 912 | return false; |
| 913 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 914 | if (context->getExtensions().webglCompatibility && |
| 915 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 916 | { |
| 917 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 918 | PixelUnpackBufferBoundForTransformFeedback); |
| 919 | return false; |
| 920 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 921 | } |
| 922 | else |
| 923 | { |
| 924 | ASSERT(imageSize >= 0); |
| 925 | if (pixels == nullptr && imageSize != 0) |
| 926 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 927 | context->handleError(InvalidOperation() |
| 928 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 929 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 932 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 933 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 934 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 935 | return false; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | return true; |
| 940 | } |
| 941 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 942 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 943 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 944 | switch (queryType) |
| 945 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 946 | case QueryType::AnySamples: |
| 947 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 948 | return context->getClientMajorVersion() >= 3 || |
| 949 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 950 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 951 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 952 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 953 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 954 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 955 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 956 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 957 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 958 | default: |
| 959 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 960 | } |
| 961 | } |
| 962 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 963 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 964 | GLenum type, |
| 965 | GLboolean normalized, |
| 966 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 967 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 968 | bool pureInteger) |
| 969 | { |
| 970 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 971 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 972 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 973 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 974 | // parameter exceeds 255. |
| 975 | constexpr GLsizei kMaxWebGLStride = 255; |
| 976 | if (stride > kMaxWebGLStride) |
| 977 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 978 | context->handleError(InvalidValue() |
| 979 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 980 | return false; |
| 981 | } |
| 982 | |
| 983 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 984 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 985 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 986 | // or an INVALID_OPERATION error is generated. |
| 987 | VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger); |
| 988 | size_t typeSize = GetVertexFormatTypeSize(internalType); |
| 989 | |
| 990 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 991 | size_t sizeMask = (typeSize - 1); |
| 992 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 993 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 994 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 995 | return false; |
| 996 | } |
| 997 | |
| 998 | if ((stride & sizeMask) != 0) |
| 999 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1000 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1001 | return false; |
| 1002 | } |
| 1003 | |
| 1004 | return true; |
| 1005 | } |
| 1006 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1007 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1008 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1009 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1010 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1011 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1012 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1013 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1014 | Program *validProgram = context->getProgram(id); |
| 1015 | |
| 1016 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1017 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1018 | if (context->getShader(id)) |
| 1019 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1020 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1021 | } |
| 1022 | else |
| 1023 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1024 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1025 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1026 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1027 | |
| 1028 | return validProgram; |
| 1029 | } |
| 1030 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1031 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1032 | { |
| 1033 | // See ValidProgram for spec details. |
| 1034 | |
| 1035 | Shader *validShader = context->getShader(id); |
| 1036 | |
| 1037 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1038 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1039 | if (context->getProgram(id)) |
| 1040 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1041 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1042 | } |
| 1043 | else |
| 1044 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1045 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1046 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1047 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1048 | |
| 1049 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1052 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1053 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1054 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1055 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1056 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1057 | { |
| 1058 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1059 | return false; |
| 1060 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1061 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1062 | // Color attachment 0 is validated below because it is always valid |
| 1063 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1064 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1065 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1066 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1067 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1068 | } |
| 1069 | } |
| 1070 | else |
| 1071 | { |
| 1072 | switch (attachment) |
| 1073 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1074 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1075 | case GL_DEPTH_ATTACHMENT: |
| 1076 | case GL_STENCIL_ATTACHMENT: |
| 1077 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1078 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1079 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1080 | if (!context->getExtensions().webglCompatibility && |
| 1081 | context->getClientMajorVersion() < 3) |
| 1082 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1083 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1084 | return false; |
| 1085 | } |
| 1086 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1087 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1088 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1089 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1090 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | return true; |
| 1095 | } |
| 1096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1097 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1098 | GLenum target, |
| 1099 | GLsizei samples, |
| 1100 | GLenum internalformat, |
| 1101 | GLsizei width, |
| 1102 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1103 | { |
| 1104 | switch (target) |
| 1105 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1106 | case GL_RENDERBUFFER: |
| 1107 | break; |
| 1108 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1109 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1110 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1111 | } |
| 1112 | |
| 1113 | if (width < 0 || height < 0 || samples < 0) |
| 1114 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1115 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1116 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1119 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1120 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1121 | |
| 1122 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1123 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1124 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1125 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1126 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1130 | // 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] | 1131 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1132 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1133 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1134 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1135 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1136 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1137 | } |
| 1138 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1139 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1140 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1141 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1142 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1145 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1146 | if (handle == 0) |
| 1147 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1148 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1149 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | return true; |
| 1153 | } |
| 1154 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1155 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1156 | GLenum target, |
| 1157 | GLenum attachment, |
| 1158 | GLenum renderbuffertarget, |
| 1159 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1160 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1161 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1162 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1163 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1164 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1167 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1168 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1169 | ASSERT(framebuffer); |
| 1170 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1171 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1172 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1173 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1174 | } |
| 1175 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1176 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1177 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1178 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1179 | } |
| 1180 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1181 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1182 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1183 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1184 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1185 | if (renderbuffer != 0) |
| 1186 | { |
| 1187 | if (!context->getRenderbuffer(renderbuffer)) |
| 1188 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1189 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1190 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1191 | } |
| 1192 | } |
| 1193 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1194 | return true; |
| 1195 | } |
| 1196 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1197 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1198 | GLint srcX0, |
| 1199 | GLint srcY0, |
| 1200 | GLint srcX1, |
| 1201 | GLint srcY1, |
| 1202 | GLint dstX0, |
| 1203 | GLint dstY0, |
| 1204 | GLint dstX1, |
| 1205 | GLint dstY1, |
| 1206 | GLbitfield mask, |
| 1207 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1208 | { |
| 1209 | switch (filter) |
| 1210 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1211 | case GL_NEAREST: |
| 1212 | break; |
| 1213 | case GL_LINEAR: |
| 1214 | break; |
| 1215 | default: |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1216 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), BlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1217 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1221 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1222 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1223 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1224 | } |
| 1225 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1226 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1227 | // color buffer, leaving only nearest being unfiltered from above |
| 1228 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1229 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1230 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1231 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1234 | const auto &glState = context->getGLState(); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1235 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1236 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1237 | |
| 1238 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1239 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1240 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1241 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1244 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1245 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1246 | return false; |
| 1247 | } |
| 1248 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1249 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1250 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1251 | return false; |
| 1252 | } |
| 1253 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1254 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1255 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1256 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1257 | return false; |
| 1258 | } |
| 1259 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1260 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1261 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1262 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1263 | } |
| 1264 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1265 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1266 | // always run it in order to avoid triggering driver bugs. |
| 1267 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1268 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1269 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1270 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1271 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1272 | } |
| 1273 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1274 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1275 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1276 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1277 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1278 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1279 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1280 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1281 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1282 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1283 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1284 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1285 | for (size_t drawbufferIdx = 0; |
| 1286 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1287 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1288 | const FramebufferAttachment *attachment = |
| 1289 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1290 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1291 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1292 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1293 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1294 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1295 | // 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] | 1296 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1297 | // as well |
| 1298 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1299 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1300 | // Changes with EXT_color_buffer_float: |
| 1301 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1302 | GLenum readComponentType = readFormat.info->componentType; |
| 1303 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1304 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1305 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1306 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1307 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1308 | |
| 1309 | if (extensions.colorBufferFloat) |
| 1310 | { |
| 1311 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1312 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1313 | |
| 1314 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1315 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1316 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1317 | BlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1318 | return false; |
| 1319 | } |
| 1320 | } |
| 1321 | else if (readFixedPoint != drawFixedPoint) |
| 1322 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1323 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1324 | BlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1325 | return false; |
| 1326 | } |
| 1327 | |
| 1328 | if (readComponentType == GL_UNSIGNED_INT && |
| 1329 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1330 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1331 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1332 | BlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1333 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1334 | } |
| 1335 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1336 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1337 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1338 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1339 | BlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1340 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1341 | } |
| 1342 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1343 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1344 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1345 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1346 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1347 | BlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1348 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1349 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1350 | |
| 1351 | if (context->getExtensions().webglCompatibility && |
| 1352 | *readColorBuffer == *attachment) |
| 1353 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1354 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1355 | return false; |
| 1356 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1357 | } |
| 1358 | } |
| 1359 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1360 | if ((readFormat.info->componentType == GL_INT || |
| 1361 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1362 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1363 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1364 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1365 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1366 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1367 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1368 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1369 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1370 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1371 | // situation is an application error that would lead to a crash in ANGLE. |
| 1372 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1373 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1374 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1375 | return false; |
| 1376 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1379 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1380 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1381 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1382 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1383 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1384 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1385 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1386 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1387 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1388 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1389 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1390 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1391 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1392 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1393 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1394 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1395 | BlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1396 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1397 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1398 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1399 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1400 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1401 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1402 | BlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1403 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1404 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1405 | |
| 1406 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1407 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1408 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1409 | return false; |
| 1410 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1411 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1412 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1413 | else if (drawBuffer) |
| 1414 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1415 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1416 | return false; |
| 1417 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1421 | // ANGLE_multiview, Revision 1: |
| 1422 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1423 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1424 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1425 | // views in the current read framebuffer is more than one. |
| 1426 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1427 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1428 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
| 1431 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1432 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 1433 | ANGLE_VALIDATION_ERR(context, InvalidFramebufferOperation(), BlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1434 | return false; |
| 1435 | } |
| 1436 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1437 | return true; |
| 1438 | } |
| 1439 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1440 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1441 | GLint x, |
| 1442 | GLint y, |
| 1443 | GLsizei width, |
| 1444 | GLsizei height, |
| 1445 | GLenum format, |
| 1446 | GLenum type, |
| 1447 | GLsizei bufSize, |
| 1448 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1449 | GLsizei *columns, |
| 1450 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1451 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1452 | { |
| 1453 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1454 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1455 | return false; |
| 1456 | } |
| 1457 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1458 | GLsizei writeLength = 0; |
| 1459 | GLsizei writeColumns = 0; |
| 1460 | GLsizei writeRows = 0; |
| 1461 | |
| 1462 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1463 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1464 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1465 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1466 | } |
| 1467 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1468 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1469 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1470 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1471 | } |
| 1472 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1473 | SetRobustLengthParam(length, writeLength); |
| 1474 | SetRobustLengthParam(columns, writeColumns); |
| 1475 | SetRobustLengthParam(rows, writeRows); |
| 1476 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1477 | return true; |
| 1478 | } |
| 1479 | |
| 1480 | bool ValidateReadnPixelsEXT(Context *context, |
| 1481 | GLint x, |
| 1482 | GLint y, |
| 1483 | GLsizei width, |
| 1484 | GLsizei height, |
| 1485 | GLenum format, |
| 1486 | GLenum type, |
| 1487 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1488 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1489 | { |
| 1490 | if (bufSize < 0) |
| 1491 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1492 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
| 1495 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1496 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1497 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1498 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1499 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1500 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1501 | GLint x, |
| 1502 | GLint y, |
| 1503 | GLsizei width, |
| 1504 | GLsizei height, |
| 1505 | GLenum format, |
| 1506 | GLenum type, |
| 1507 | GLsizei bufSize, |
| 1508 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1509 | GLsizei *columns, |
| 1510 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1511 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1512 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1513 | GLsizei writeLength = 0; |
| 1514 | GLsizei writeColumns = 0; |
| 1515 | GLsizei writeRows = 0; |
| 1516 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1517 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1518 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1519 | return false; |
| 1520 | } |
| 1521 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1522 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1523 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1524 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1525 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1526 | } |
| 1527 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1528 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1529 | { |
| 1530 | return false; |
| 1531 | } |
| 1532 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1533 | SetRobustLengthParam(length, writeLength); |
| 1534 | SetRobustLengthParam(columns, writeColumns); |
| 1535 | SetRobustLengthParam(rows, writeRows); |
| 1536 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1537 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1538 | } |
| 1539 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1540 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1541 | { |
| 1542 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1543 | !context->getExtensions().disjointTimerQuery) |
| 1544 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1545 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1546 | return false; |
| 1547 | } |
| 1548 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1549 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1550 | } |
| 1551 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1552 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1553 | { |
| 1554 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1555 | !context->getExtensions().disjointTimerQuery) |
| 1556 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1557 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1558 | return false; |
| 1559 | } |
| 1560 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1561 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1564 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1565 | { |
| 1566 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1567 | !context->getExtensions().disjointTimerQuery) |
| 1568 | { |
| 1569 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1570 | return false; |
| 1571 | } |
| 1572 | |
| 1573 | return true; |
| 1574 | } |
| 1575 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1576 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1577 | { |
| 1578 | if (!ValidQueryType(context, target)) |
| 1579 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1580 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1581 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | if (id == 0) |
| 1585 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1586 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1587 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1591 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1592 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1593 | // the active query for either target is non-zero), if <id> is the name of an |
| 1594 | // existing query object whose type does not match <target>, or if <id> is the |
| 1595 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1596 | // generated. |
| 1597 | |
| 1598 | // Ensure no other queries are active |
| 1599 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1600 | // separately that: |
| 1601 | // a) The query ID passed is not the current active query for any target/type |
| 1602 | // b) There are no active queries for the requested target (and in the case |
| 1603 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1604 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1605 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1606 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1607 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1608 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1609 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | Query *queryObject = context->getQuery(id, true, target); |
| 1613 | |
| 1614 | // check that name was obtained with glGenQueries |
| 1615 | if (!queryObject) |
| 1616 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1617 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1618 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | // check for type mismatch |
| 1622 | if (queryObject->getType() != target) |
| 1623 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1624 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1625 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1626 | } |
| 1627 | |
| 1628 | return true; |
| 1629 | } |
| 1630 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1631 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1632 | { |
| 1633 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1634 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1635 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1636 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1637 | return false; |
| 1638 | } |
| 1639 | |
| 1640 | return ValidateBeginQueryBase(context, target, id); |
| 1641 | } |
| 1642 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1643 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1644 | { |
| 1645 | if (!ValidQueryType(context, target)) |
| 1646 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1647 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1648 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1651 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1652 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1653 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1654 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1655 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1656 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1657 | } |
| 1658 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1659 | return true; |
| 1660 | } |
| 1661 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1662 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1663 | { |
| 1664 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1665 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1666 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1667 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1668 | return false; |
| 1669 | } |
| 1670 | |
| 1671 | return ValidateEndQueryBase(context, target); |
| 1672 | } |
| 1673 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1674 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1675 | { |
| 1676 | if (!context->getExtensions().disjointTimerQuery) |
| 1677 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1678 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1679 | return false; |
| 1680 | } |
| 1681 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1682 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1683 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1684 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1685 | return false; |
| 1686 | } |
| 1687 | |
| 1688 | Query *queryObject = context->getQuery(id, true, target); |
| 1689 | if (queryObject == nullptr) |
| 1690 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1691 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1692 | return false; |
| 1693 | } |
| 1694 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1695 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1696 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1697 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1698 | return false; |
| 1699 | } |
| 1700 | |
| 1701 | return true; |
| 1702 | } |
| 1703 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1704 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1705 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1706 | if (numParams) |
| 1707 | { |
| 1708 | *numParams = 0; |
| 1709 | } |
| 1710 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1711 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1712 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1713 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1714 | return false; |
| 1715 | } |
| 1716 | |
| 1717 | switch (pname) |
| 1718 | { |
| 1719 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1720 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1721 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1722 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
| 1725 | break; |
| 1726 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1727 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1728 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1729 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1730 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1731 | return false; |
| 1732 | } |
| 1733 | break; |
| 1734 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1735 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1736 | return false; |
| 1737 | } |
| 1738 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1739 | if (numParams) |
| 1740 | { |
| 1741 | // All queries return only one value |
| 1742 | *numParams = 1; |
| 1743 | } |
| 1744 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1745 | return true; |
| 1746 | } |
| 1747 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1748 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1749 | { |
| 1750 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1751 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1752 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1753 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1757 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1758 | } |
| 1759 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1760 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1761 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1762 | GLenum pname, |
| 1763 | GLsizei bufSize, |
| 1764 | GLsizei *length, |
| 1765 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1766 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1767 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1768 | { |
| 1769 | return false; |
| 1770 | } |
| 1771 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1772 | GLsizei numParams = 0; |
| 1773 | |
| 1774 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1775 | { |
| 1776 | return false; |
| 1777 | } |
| 1778 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1779 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1780 | { |
| 1781 | return false; |
| 1782 | } |
| 1783 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1784 | SetRobustLengthParam(length, numParams); |
| 1785 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1786 | return true; |
| 1787 | } |
| 1788 | |
| 1789 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1790 | { |
| 1791 | if (numParams) |
| 1792 | { |
| 1793 | *numParams = 0; |
| 1794 | } |
| 1795 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1796 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1797 | |
| 1798 | if (!queryObject) |
| 1799 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1800 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1801 | return false; |
| 1802 | } |
| 1803 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1804 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1805 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1806 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1807 | return false; |
| 1808 | } |
| 1809 | |
| 1810 | switch (pname) |
| 1811 | { |
| 1812 | case GL_QUERY_RESULT_EXT: |
| 1813 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1814 | break; |
| 1815 | |
| 1816 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1817 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1818 | return false; |
| 1819 | } |
| 1820 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1821 | if (numParams) |
| 1822 | { |
| 1823 | *numParams = 1; |
| 1824 | } |
| 1825 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1826 | return true; |
| 1827 | } |
| 1828 | |
| 1829 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1830 | { |
| 1831 | if (!context->getExtensions().disjointTimerQuery) |
| 1832 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1833 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1834 | return false; |
| 1835 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1836 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1837 | } |
| 1838 | |
| 1839 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1840 | GLuint id, |
| 1841 | GLenum pname, |
| 1842 | GLsizei bufSize, |
| 1843 | GLsizei *length, |
| 1844 | GLint *params) |
| 1845 | { |
| 1846 | if (!context->getExtensions().disjointTimerQuery) |
| 1847 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1848 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1849 | return false; |
| 1850 | } |
| 1851 | |
| 1852 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1853 | { |
| 1854 | return false; |
| 1855 | } |
| 1856 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1857 | GLsizei numParams = 0; |
| 1858 | |
| 1859 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1860 | { |
| 1861 | return false; |
| 1862 | } |
| 1863 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1864 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1865 | { |
| 1866 | return false; |
| 1867 | } |
| 1868 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1869 | SetRobustLengthParam(length, numParams); |
| 1870 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1871 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1875 | { |
| 1876 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1877 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1878 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1879 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1880 | return false; |
| 1881 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1882 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1883 | } |
| 1884 | |
| 1885 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1886 | GLuint id, |
| 1887 | GLenum pname, |
| 1888 | GLsizei bufSize, |
| 1889 | GLsizei *length, |
| 1890 | GLuint *params) |
| 1891 | { |
| 1892 | if (!context->getExtensions().disjointTimerQuery && |
| 1893 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1894 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1895 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1896 | return false; |
| 1897 | } |
| 1898 | |
| 1899 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1900 | { |
| 1901 | return false; |
| 1902 | } |
| 1903 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1904 | GLsizei numParams = 0; |
| 1905 | |
| 1906 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1907 | { |
| 1908 | return false; |
| 1909 | } |
| 1910 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1911 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1912 | { |
| 1913 | return false; |
| 1914 | } |
| 1915 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1916 | SetRobustLengthParam(length, numParams); |
| 1917 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1918 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1919 | } |
| 1920 | |
| 1921 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1922 | { |
| 1923 | if (!context->getExtensions().disjointTimerQuery) |
| 1924 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1925 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1926 | return false; |
| 1927 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1928 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1929 | } |
| 1930 | |
| 1931 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1932 | GLuint id, |
| 1933 | GLenum pname, |
| 1934 | GLsizei bufSize, |
| 1935 | GLsizei *length, |
| 1936 | GLint64 *params) |
| 1937 | { |
| 1938 | if (!context->getExtensions().disjointTimerQuery) |
| 1939 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1940 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1941 | return false; |
| 1942 | } |
| 1943 | |
| 1944 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1945 | { |
| 1946 | return false; |
| 1947 | } |
| 1948 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1949 | GLsizei numParams = 0; |
| 1950 | |
| 1951 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1952 | { |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1956 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1957 | { |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1961 | SetRobustLengthParam(length, numParams); |
| 1962 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1963 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 1967 | { |
| 1968 | if (!context->getExtensions().disjointTimerQuery) |
| 1969 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1970 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1971 | return false; |
| 1972 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1973 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1974 | } |
| 1975 | |
| 1976 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 1977 | GLuint id, |
| 1978 | GLenum pname, |
| 1979 | GLsizei bufSize, |
| 1980 | GLsizei *length, |
| 1981 | GLuint64 *params) |
| 1982 | { |
| 1983 | if (!context->getExtensions().disjointTimerQuery) |
| 1984 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1985 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1986 | return false; |
| 1987 | } |
| 1988 | |
| 1989 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1990 | { |
| 1991 | return false; |
| 1992 | } |
| 1993 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1994 | GLsizei numParams = 0; |
| 1995 | |
| 1996 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1997 | { |
| 1998 | return false; |
| 1999 | } |
| 2000 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2001 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2002 | { |
| 2003 | return false; |
| 2004 | } |
| 2005 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2006 | SetRobustLengthParam(length, numParams); |
| 2007 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2008 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2009 | } |
| 2010 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2011 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2012 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2013 | GLint location, |
| 2014 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2015 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2016 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2017 | // TODO(Jiajia): Add image uniform check in future. |
| 2018 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2019 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2020 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2021 | return false; |
| 2022 | } |
| 2023 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2024 | if (!program) |
| 2025 | { |
| 2026 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
| 2030 | if (!program->isLinked()) |
| 2031 | { |
| 2032 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2033 | return false; |
| 2034 | } |
| 2035 | |
| 2036 | if (location == -1) |
| 2037 | { |
| 2038 | // Silently ignore the uniform command |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
| 2042 | const auto &uniformLocations = program->getUniformLocations(); |
| 2043 | size_t castedLocation = static_cast<size_t>(location); |
| 2044 | if (castedLocation >= uniformLocations.size()) |
| 2045 | { |
| 2046 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2047 | return false; |
| 2048 | } |
| 2049 | |
| 2050 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2051 | if (uniformLocation.ignored) |
| 2052 | { |
| 2053 | // Silently ignore the uniform command |
| 2054 | return false; |
| 2055 | } |
| 2056 | |
| 2057 | if (!uniformLocation.used()) |
| 2058 | { |
| 2059 | context->handleError(InvalidOperation()); |
| 2060 | return false; |
| 2061 | } |
| 2062 | |
| 2063 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2064 | |
| 2065 | // 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] | 2066 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2067 | { |
| 2068 | context->handleError(InvalidOperation()); |
| 2069 | return false; |
| 2070 | } |
| 2071 | |
| 2072 | *uniformOut = &uniform; |
| 2073 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2074 | } |
| 2075 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2076 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2077 | GLenum uniformType, |
| 2078 | GLsizei count, |
| 2079 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2080 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2081 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2082 | // It is compatible with INT or BOOL. |
| 2083 | // Do these cheap tests first, for a little extra speed. |
| 2084 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2085 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2086 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2087 | } |
| 2088 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2089 | if (IsSamplerType(uniformType)) |
| 2090 | { |
| 2091 | // Check that the values are in range. |
| 2092 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2093 | for (GLsizei i = 0; i < count; ++i) |
| 2094 | { |
| 2095 | if (value[i] < 0 || value[i] >= max) |
| 2096 | { |
| 2097 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2098 | return false; |
| 2099 | } |
| 2100 | } |
| 2101 | return true; |
| 2102 | } |
| 2103 | |
| 2104 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2105 | return false; |
| 2106 | } |
| 2107 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2108 | bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2109 | { |
| 2110 | // Check that the value type is compatible with uniform type. |
| 2111 | // Do the cheaper test first, for a little extra speed. |
| 2112 | if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType) |
| 2113 | { |
| 2114 | return true; |
| 2115 | } |
| 2116 | |
| 2117 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch); |
| 2118 | return false; |
| 2119 | } |
| 2120 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2121 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2122 | { |
| 2123 | // Check that the value type is compatible with uniform type. |
| 2124 | if (valueType == uniformType) |
| 2125 | { |
| 2126 | return true; |
| 2127 | } |
| 2128 | |
| 2129 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2130 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2131 | } |
| 2132 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2133 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2134 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2135 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2136 | Program *programObject = context->getGLState().getProgram(); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2137 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2138 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2139 | } |
| 2140 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2141 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2142 | { |
| 2143 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2144 | Program *programObject = context->getGLState().getProgram(); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2145 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2146 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2147 | } |
| 2148 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2149 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2150 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2151 | GLint location, |
| 2152 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2153 | GLboolean transpose) |
| 2154 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2155 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2156 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2157 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2158 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2159 | } |
| 2160 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2161 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2162 | Program *programObject = context->getGLState().getProgram(); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2163 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2164 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2167 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2168 | { |
| 2169 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2170 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2171 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2172 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2173 | } |
| 2174 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2175 | const Caps &caps = context->getCaps(); |
| 2176 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2177 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2178 | { |
| 2179 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2180 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2181 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2182 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2183 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2184 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | switch (pname) |
| 2189 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2190 | case GL_TEXTURE_BINDING_2D: |
| 2191 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2192 | case GL_TEXTURE_BINDING_3D: |
| 2193 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2194 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2195 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2196 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2197 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2198 | { |
| 2199 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 2200 | return false; |
| 2201 | } |
| 2202 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2203 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2204 | if (!context->getExtensions().textureRectangle) |
| 2205 | { |
| 2206 | context->handleError(InvalidEnum() |
| 2207 | << "ANGLE_texture_rectangle extension not present"); |
| 2208 | return false; |
| 2209 | } |
| 2210 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2211 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2212 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2213 | !context->getExtensions().eglImageExternal) |
| 2214 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2215 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2216 | "nor GL_OES_EGL_image_external " |
| 2217 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2218 | return false; |
| 2219 | } |
| 2220 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2221 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2222 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2223 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2224 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2225 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2226 | ASSERT(readFramebuffer); |
| 2227 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2228 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2229 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2230 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2231 | } |
| 2232 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2233 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2234 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2235 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2236 | return false; |
| 2237 | } |
| 2238 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2239 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2240 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2241 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2242 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2243 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2244 | } |
| 2245 | } |
| 2246 | break; |
| 2247 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2248 | default: |
| 2249 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2250 | } |
| 2251 | |
| 2252 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2253 | if (*numParams == 0) |
| 2254 | { |
| 2255 | return false; |
| 2256 | } |
| 2257 | |
| 2258 | return true; |
| 2259 | } |
| 2260 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2261 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2262 | GLenum pname, |
| 2263 | GLsizei bufSize, |
| 2264 | GLsizei *length, |
| 2265 | GLboolean *params) |
| 2266 | { |
| 2267 | GLenum nativeType; |
| 2268 | unsigned int numParams = 0; |
| 2269 | |
| 2270 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2271 | { |
| 2272 | return false; |
| 2273 | } |
| 2274 | |
| 2275 | SetRobustLengthParam(length, numParams); |
| 2276 | |
| 2277 | return true; |
| 2278 | } |
| 2279 | |
| 2280 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2281 | GLenum pname, |
| 2282 | GLsizei bufSize, |
| 2283 | GLsizei *length, |
| 2284 | GLfloat *params) |
| 2285 | { |
| 2286 | GLenum nativeType; |
| 2287 | unsigned int numParams = 0; |
| 2288 | |
| 2289 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2290 | { |
| 2291 | return false; |
| 2292 | } |
| 2293 | |
| 2294 | SetRobustLengthParam(length, numParams); |
| 2295 | |
| 2296 | return true; |
| 2297 | } |
| 2298 | |
| 2299 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2300 | GLenum pname, |
| 2301 | GLsizei bufSize, |
| 2302 | GLsizei *length, |
| 2303 | GLint *data) |
| 2304 | { |
| 2305 | GLenum nativeType; |
| 2306 | unsigned int numParams = 0; |
| 2307 | |
| 2308 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2309 | { |
| 2310 | return false; |
| 2311 | } |
| 2312 | |
| 2313 | SetRobustLengthParam(length, numParams); |
| 2314 | |
| 2315 | return true; |
| 2316 | } |
| 2317 | |
| 2318 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2319 | GLenum pname, |
| 2320 | GLsizei bufSize, |
| 2321 | GLsizei *length, |
| 2322 | GLint64 *data) |
| 2323 | { |
| 2324 | GLenum nativeType; |
| 2325 | unsigned int numParams = 0; |
| 2326 | |
| 2327 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2328 | { |
| 2329 | return false; |
| 2330 | } |
| 2331 | |
| 2332 | if (nativeType == GL_INT_64_ANGLEX) |
| 2333 | { |
| 2334 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2335 | return false; |
| 2336 | } |
| 2337 | |
| 2338 | SetRobustLengthParam(length, numParams); |
| 2339 | return true; |
| 2340 | } |
| 2341 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2342 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2343 | GLenum pname, |
| 2344 | GLsizei bufSize, |
| 2345 | GLenum *nativeType, |
| 2346 | unsigned int *numParams) |
| 2347 | { |
| 2348 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2349 | { |
| 2350 | return false; |
| 2351 | } |
| 2352 | |
| 2353 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2354 | { |
| 2355 | return false; |
| 2356 | } |
| 2357 | |
| 2358 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2359 | { |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| 2363 | return true; |
| 2364 | } |
| 2365 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2366 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2367 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2368 | GLint level, |
| 2369 | GLenum internalformat, |
| 2370 | bool isSubImage, |
| 2371 | GLint xoffset, |
| 2372 | GLint yoffset, |
| 2373 | GLint zoffset, |
| 2374 | GLint x, |
| 2375 | GLint y, |
| 2376 | GLsizei width, |
| 2377 | GLsizei height, |
| 2378 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2379 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2380 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2381 | TextureType texType = TextureTargetToType(target); |
| 2382 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2383 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2384 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2385 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2386 | return false; |
| 2387 | } |
| 2388 | |
| 2389 | if (width < 0 || height < 0) |
| 2390 | { |
| 2391 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2392 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2393 | } |
| 2394 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2395 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2396 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2397 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2398 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2399 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | if (border != 0) |
| 2403 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2404 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2405 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2406 | } |
| 2407 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2408 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2409 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2410 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2411 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2412 | } |
| 2413 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2414 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2415 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2416 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2417 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2418 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2419 | } |
| 2420 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2421 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2422 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2423 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2424 | } |
| 2425 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2426 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2427 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2428 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2429 | return false; |
| 2430 | } |
| 2431 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2432 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2433 | // 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] | 2434 | // 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] | 2435 | // 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] | 2436 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2437 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2438 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2439 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2440 | return false; |
| 2441 | } |
| 2442 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2443 | // ANGLE_multiview spec, Revision 1: |
| 2444 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2445 | // 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] | 2446 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2447 | // framebuffer is more than one. |
| 2448 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2449 | { |
| 2450 | context->handleError(InvalidFramebufferOperation() |
| 2451 | << "The active read framebuffer object has multiview attachments."); |
| 2452 | return false; |
| 2453 | } |
| 2454 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2455 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2456 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2457 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2458 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2459 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2460 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2461 | maxDimension = caps.max2DTextureSize; |
| 2462 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2463 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2464 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2465 | maxDimension = caps.maxCubeMapTextureSize; |
| 2466 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2467 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2468 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2469 | maxDimension = caps.maxRectangleTextureSize; |
| 2470 | break; |
| 2471 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2472 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2473 | maxDimension = caps.max2DTextureSize; |
| 2474 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2475 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2476 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2477 | maxDimension = caps.max3DTextureSize; |
| 2478 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2479 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2480 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2481 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2482 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2483 | } |
| 2484 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2485 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2486 | if (!texture) |
| 2487 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2488 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2489 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2492 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2493 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2494 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2495 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2496 | } |
| 2497 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2498 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2499 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2500 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2501 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2502 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2503 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2504 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2505 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | if (isSubImage) |
| 2509 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2510 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2511 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2512 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2513 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2514 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2515 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2516 | } |
| 2517 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2518 | else |
| 2519 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2520 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2521 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2522 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2523 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2524 | } |
| 2525 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2526 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2527 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2528 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2529 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2533 | if (static_cast<int>(width) > maxLevelDimension || |
| 2534 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2535 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2536 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2537 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2538 | } |
| 2539 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2540 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2541 | if (textureFormatOut) |
| 2542 | { |
| 2543 | *textureFormatOut = texture->getFormat(target, level); |
| 2544 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2545 | |
| 2546 | // Detect texture copying feedback loops for WebGL. |
| 2547 | if (context->getExtensions().webglCompatibility) |
| 2548 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2549 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2550 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2551 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2552 | return false; |
| 2553 | } |
| 2554 | } |
| 2555 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2556 | return true; |
| 2557 | } |
| 2558 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2559 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2560 | // completeness check. |
| 2561 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2562 | { |
| 2563 | const Extensions &extensions = context->getExtensions(); |
| 2564 | const State &state = context->getGLState(); |
| 2565 | |
| 2566 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2567 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2568 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2569 | if (!extensions.webglCompatibility && state.getVertexArray()->hasMappedEnabledArrayBuffer()) |
| 2570 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2571 | return kErrorBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2575 | // Section 6.10 of the WebGL 1.0 spec. |
| 2576 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
| 2577 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2578 | { |
| 2579 | ASSERT(framebuffer); |
| 2580 | const FramebufferAttachment *dsAttachment = |
| 2581 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2582 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2583 | ASSERT(stencilBits <= 8); |
| 2584 | |
| 2585 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2586 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2587 | { |
| 2588 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2589 | |
| 2590 | bool differentRefs = |
| 2591 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2592 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2593 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2594 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2595 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2596 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2597 | |
| 2598 | if (differentRefs || differentWritemasks || differentMasks) |
| 2599 | { |
| 2600 | if (!extensions.webglCompatibility) |
| 2601 | { |
| 2602 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2603 | "stencil writemasks, reference values, or stencil mask values."; |
| 2604 | } |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2605 | return kErrorStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2606 | } |
| 2607 | } |
| 2608 | } |
| 2609 | |
| 2610 | if (!framebuffer->isComplete(context)) |
| 2611 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2612 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
| 2613 | return kErrorDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
| 2616 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2617 | { |
| 2618 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2619 | { |
| 2620 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2621 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2622 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2623 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2624 | return kErrorVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2625 | } |
| 2626 | |
| 2627 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2628 | { |
| 2629 | // This is an application error that would normally result in a crash, but we catch it |
| 2630 | // and return an error |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2631 | return kErrorVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | // If we are running GLES1, there is no current program. |
| 2636 | if (context->getClientVersion() >= Version(2, 0)) |
| 2637 | { |
| 2638 | Program *program = state.getProgram(); |
| 2639 | if (!program) |
| 2640 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2641 | return kErrorProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2645 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2646 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2647 | // produce undefined result. |
| 2648 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2649 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2650 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2651 | return kErrorNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2655 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2656 | return kErrorTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | if (extensions.multiview) |
| 2660 | { |
| 2661 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2662 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2663 | if (framebufferNumViews != programNumViews) |
| 2664 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2665 | return kErrorMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2669 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2670 | framebufferNumViews > 1) |
| 2671 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2672 | return kErrorMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2676 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2677 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2678 | return kErrorMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | // Uniform buffer validation |
| 2683 | for (unsigned int uniformBlockIndex = 0; |
| 2684 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2685 | { |
| 2686 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
| 2687 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
| 2688 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2689 | state.getIndexedUniformBuffer(blockBinding); |
| 2690 | |
| 2691 | if (uniformBuffer.get() == nullptr) |
| 2692 | { |
| 2693 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2694 | return kErrorUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2698 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2699 | { |
| 2700 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2701 | return kErrorUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | if (extensions.webglCompatibility && |
| 2705 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2706 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2707 | return kErrorUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | |
| 2711 | // Do some additonal WebGL-specific validation |
| 2712 | if (extensions.webglCompatibility) |
| 2713 | { |
| 2714 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2715 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2716 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2717 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2718 | return kErrorTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | // Detect rendering feedback loops for WebGL. |
| 2722 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2723 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2724 | return kErrorFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | // Detect that the vertex shader input types match the attribute types |
| 2728 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2729 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2730 | return kErrorVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | // Detect that the color buffer types match the fragment shader output types |
| 2734 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2735 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2736 | return kErrorDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2737 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2738 | |
| 2739 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2740 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2741 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2742 | return kErrorVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2743 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2744 | } |
| 2745 | } |
| 2746 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2747 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2748 | } |
| 2749 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2750 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2751 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2752 | const Extensions &extensions = context->getExtensions(); |
| 2753 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2754 | switch (mode) |
| 2755 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2756 | case PrimitiveMode::Points: |
| 2757 | case PrimitiveMode::Lines: |
| 2758 | case PrimitiveMode::LineLoop: |
| 2759 | case PrimitiveMode::LineStrip: |
| 2760 | case PrimitiveMode::Triangles: |
| 2761 | case PrimitiveMode::TriangleStrip: |
| 2762 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2763 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2764 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2765 | case PrimitiveMode::LinesAdjacency: |
| 2766 | case PrimitiveMode::LineStripAdjacency: |
| 2767 | case PrimitiveMode::TrianglesAdjacency: |
| 2768 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2769 | if (!extensions.geometryShader) |
| 2770 | { |
| 2771 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2772 | return false; |
| 2773 | } |
| 2774 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2775 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2776 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2777 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2778 | } |
| 2779 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2780 | if (count < 0) |
| 2781 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2782 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2783 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2784 | } |
| 2785 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2786 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2787 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2788 | const char *errorMessage = ValidateDrawStates(context); |
| 2789 | if (errorMessage) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2790 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2791 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2792 | // Incomplete. |
| 2793 | GLenum errorCode = |
| 2794 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2795 | : GL_INVALID_OPERATION); |
| 2796 | context->handleError(Error(errorCode, errorMessage)); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2797 | return false; |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2798 | } |
| 2799 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2800 | // If we are running GLES1, there is no current program. |
| 2801 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2802 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2803 | Program *program = state.getProgram(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2804 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2805 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2806 | // Do geometry shader specific validations |
| 2807 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2808 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2809 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2810 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2811 | { |
| 2812 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2813 | IncompatibleDrawModeAgainstGeometryShader); |
| 2814 | return false; |
| 2815 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2816 | } |
| 2817 | } |
| 2818 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2819 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2820 | } |
| 2821 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2822 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2823 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2824 | GLint first, |
| 2825 | GLsizei count, |
| 2826 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2827 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2828 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2829 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2830 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2831 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2834 | const State &state = context->getGLState(); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2835 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2836 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2837 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2838 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2839 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2840 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2841 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2842 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2843 | return false; |
| 2844 | } |
| 2845 | |
| 2846 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2847 | { |
| 2848 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2849 | return false; |
| 2850 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2851 | } |
| 2852 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2853 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2854 | { |
| 2855 | return false; |
| 2856 | } |
| 2857 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2858 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2859 | // - first < 0 has been checked as an error condition. |
| 2860 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2861 | // 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] | 2862 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2863 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2864 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2865 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2866 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2867 | { |
| 2868 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2869 | return false; |
| 2870 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2871 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2872 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2873 | { |
| 2874 | return false; |
| 2875 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2876 | } |
| 2877 | |
| 2878 | return true; |
| 2879 | } |
| 2880 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2881 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2882 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2883 | GLint first, |
| 2884 | GLsizei count, |
| 2885 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2886 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2887 | if (!context->getExtensions().instancedArrays) |
| 2888 | { |
| 2889 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2890 | return false; |
| 2891 | } |
| 2892 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2893 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2894 | { |
| 2895 | return false; |
| 2896 | } |
| 2897 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2898 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2899 | } |
| 2900 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2901 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2902 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2903 | switch (type) |
| 2904 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2905 | case GL_UNSIGNED_BYTE: |
| 2906 | case GL_UNSIGNED_SHORT: |
| 2907 | break; |
| 2908 | case GL_UNSIGNED_INT: |
| 2909 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2910 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2911 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2912 | return false; |
| 2913 | } |
| 2914 | break; |
| 2915 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2916 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2917 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2918 | } |
| 2919 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2920 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2921 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2922 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2923 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2924 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2925 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2926 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2927 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2928 | if (context->getExtensions().geometryShader) |
| 2929 | { |
| 2930 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2931 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2932 | { |
| 2933 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2934 | return false; |
| 2935 | } |
| 2936 | } |
| 2937 | else |
| 2938 | { |
| 2939 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2940 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2941 | // 86) |
| 2942 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2943 | UnsupportedDrawModeForTransformFeedback); |
| 2944 | return false; |
| 2945 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2946 | } |
| 2947 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2948 | return true; |
| 2949 | } |
| 2950 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2951 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2952 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2953 | GLsizei count, |
| 2954 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2955 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2956 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2957 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2958 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2959 | return false; |
| 2960 | |
| 2961 | const State &state = context->getGLState(); |
| 2962 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2963 | if (!ValidateDrawBase(context, mode, count)) |
| 2964 | { |
| 2965 | return false; |
| 2966 | } |
| 2967 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2968 | const VertexArray *vao = state.getVertexArray(); |
| 2969 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2970 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2971 | GLuint typeBytes = GetTypeInfo(type).bytes; |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2972 | |
| 2973 | if (context->getExtensions().webglCompatibility) |
| 2974 | { |
| 2975 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 2976 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 2977 | { |
| 2978 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 2979 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 2980 | // 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] | 2981 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2982 | return false; |
| 2983 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 2984 | |
| 2985 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 2986 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 2987 | // error is generated. |
| 2988 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 2989 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2990 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 2991 | return false; |
| 2992 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 2993 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 2994 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 2995 | { |
| 2996 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 2997 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2998 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2999 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3000 | return false; |
| 3001 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3002 | |
| 3003 | if (context->getExtensions().webglCompatibility || |
| 3004 | !context->getGLState().areClientArraysEnabled()) |
| 3005 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3006 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3007 | { |
| 3008 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3009 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3010 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3011 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3012 | return false; |
| 3013 | } |
| 3014 | } |
| 3015 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3016 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3017 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3018 | // This is an application error that would normally result in a crash, but we catch it and |
| 3019 | // return an error |
| 3020 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3021 | return false; |
| 3022 | } |
| 3023 | |
| 3024 | if (count > 0 && elementArrayBuffer) |
| 3025 | { |
| 3026 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3027 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3028 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3029 | constexpr uint64_t kMaxTypeSize = 8; |
| 3030 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3031 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3032 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3033 | |
| 3034 | uint64_t typeSize = typeBytes; |
| 3035 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3036 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3037 | |
| 3038 | // Doing the multiplication here is overflow-safe |
| 3039 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3040 | |
| 3041 | // The offset can be any value, check for overflows |
| 3042 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3043 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3044 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3045 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3046 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3047 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3048 | |
| 3049 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3050 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3051 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3052 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3053 | return false; |
| 3054 | } |
| 3055 | |
| 3056 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3057 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3058 | { |
| 3059 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3060 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3061 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3062 | |
| 3063 | if (context->getExtensions().webglCompatibility && |
| 3064 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3065 | { |
| 3066 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3067 | ElementArrayBufferBoundForTransformFeedback); |
| 3068 | return false; |
| 3069 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3070 | } |
| 3071 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3072 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3073 | { |
| 3074 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3075 | const DrawCallParams ¶ms = context->getParams<DrawCallParams>(); |
| 3076 | ANGLE_VALIDATION_TRY(params.ensureIndexRangeResolved(context)); |
| 3077 | const IndexRange &indexRange = params.getIndexRange(); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3078 | |
| 3079 | // If we use an index greater than our maximum supported index range, return an error. |
| 3080 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3081 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3082 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3083 | { |
| 3084 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3085 | return false; |
| 3086 | } |
| 3087 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3088 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3089 | { |
| 3090 | return false; |
| 3091 | } |
| 3092 | |
| 3093 | // 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] | 3094 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3095 | } |
| 3096 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3097 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3098 | } |
| 3099 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3100 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3101 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3102 | GLsizei count, |
| 3103 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3104 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3105 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3106 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3107 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3108 | } |
| 3109 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3110 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3111 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3112 | GLsizei count, |
| 3113 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3114 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3115 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3116 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3117 | if (!context->getExtensions().instancedArrays) |
| 3118 | { |
| 3119 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3120 | return false; |
| 3121 | } |
| 3122 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3123 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3124 | { |
| 3125 | return false; |
| 3126 | } |
| 3127 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3128 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3129 | } |
| 3130 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3131 | bool ValidateFramebufferTextureBase(Context *context, |
| 3132 | GLenum target, |
| 3133 | GLenum attachment, |
| 3134 | GLuint texture, |
| 3135 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3136 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3137 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3138 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3139 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3140 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3144 | { |
| 3145 | return false; |
| 3146 | } |
| 3147 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3148 | if (texture != 0) |
| 3149 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3150 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3151 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3152 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3153 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3154 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3155 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | if (level < 0) |
| 3159 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3160 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3161 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3162 | } |
| 3163 | } |
| 3164 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3165 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3166 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3167 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3168 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3169 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3170 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3171 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3172 | } |
| 3173 | |
| 3174 | return true; |
| 3175 | } |
| 3176 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3177 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3178 | { |
| 3179 | if (program == 0) |
| 3180 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3181 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3182 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3183 | } |
| 3184 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3185 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3186 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3187 | { |
| 3188 | return false; |
| 3189 | } |
| 3190 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3191 | if (!programObject || !programObject->isLinked()) |
| 3192 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3193 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3194 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3195 | } |
| 3196 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3197 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3198 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3199 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3200 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3203 | return true; |
| 3204 | } |
| 3205 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3206 | static bool ValidateSizedGetUniform(Context *context, |
| 3207 | GLuint program, |
| 3208 | GLint location, |
| 3209 | GLsizei bufSize, |
| 3210 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3211 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3212 | if (length) |
| 3213 | { |
| 3214 | *length = 0; |
| 3215 | } |
| 3216 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3217 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3218 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3219 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3220 | } |
| 3221 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3222 | if (bufSize < 0) |
| 3223 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3224 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3225 | return false; |
| 3226 | } |
| 3227 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3228 | Program *programObject = context->getProgram(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3229 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3230 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3231 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3232 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3233 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3234 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3235 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3236 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3237 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3238 | } |
| 3239 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3240 | if (length) |
| 3241 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3242 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3243 | } |
| 3244 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3245 | return true; |
| 3246 | } |
| 3247 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3248 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3249 | GLuint program, |
| 3250 | GLint location, |
| 3251 | GLsizei bufSize, |
| 3252 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3253 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3254 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3255 | } |
| 3256 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3257 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3258 | GLuint program, |
| 3259 | GLint location, |
| 3260 | GLsizei bufSize, |
| 3261 | GLsizei *length, |
| 3262 | GLfloat *params) |
| 3263 | { |
| 3264 | UNIMPLEMENTED(); |
| 3265 | return false; |
| 3266 | } |
| 3267 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3268 | bool ValidateGetnUniformivEXT(Context *context, |
| 3269 | GLuint program, |
| 3270 | GLint location, |
| 3271 | GLsizei bufSize, |
| 3272 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3273 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3274 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3275 | } |
| 3276 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3277 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3278 | GLuint program, |
| 3279 | GLint location, |
| 3280 | GLsizei bufSize, |
| 3281 | GLsizei *length, |
| 3282 | GLint *params) |
| 3283 | { |
| 3284 | UNIMPLEMENTED(); |
| 3285 | return false; |
| 3286 | } |
| 3287 | |
| 3288 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3289 | GLuint program, |
| 3290 | GLint location, |
| 3291 | GLsizei bufSize, |
| 3292 | GLsizei *length, |
| 3293 | GLuint *params) |
| 3294 | { |
| 3295 | UNIMPLEMENTED(); |
| 3296 | return false; |
| 3297 | } |
| 3298 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3299 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3300 | GLuint program, |
| 3301 | GLint location, |
| 3302 | GLsizei bufSize, |
| 3303 | GLsizei *length, |
| 3304 | GLfloat *params) |
| 3305 | { |
| 3306 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3307 | { |
| 3308 | return false; |
| 3309 | } |
| 3310 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3311 | GLsizei writeLength = 0; |
| 3312 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3313 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3314 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3315 | { |
| 3316 | return false; |
| 3317 | } |
| 3318 | |
| 3319 | SetRobustLengthParam(length, writeLength); |
| 3320 | |
| 3321 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3322 | } |
| 3323 | |
| 3324 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3325 | GLuint program, |
| 3326 | GLint location, |
| 3327 | GLsizei bufSize, |
| 3328 | GLsizei *length, |
| 3329 | GLint *params) |
| 3330 | { |
| 3331 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3332 | { |
| 3333 | return false; |
| 3334 | } |
| 3335 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3336 | GLsizei writeLength = 0; |
| 3337 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3338 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3339 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3340 | { |
| 3341 | return false; |
| 3342 | } |
| 3343 | |
| 3344 | SetRobustLengthParam(length, writeLength); |
| 3345 | |
| 3346 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3350 | GLuint program, |
| 3351 | GLint location, |
| 3352 | GLsizei bufSize, |
| 3353 | GLsizei *length, |
| 3354 | GLuint *params) |
| 3355 | { |
| 3356 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3357 | { |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
| 3361 | if (context->getClientMajorVersion() < 3) |
| 3362 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3363 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3364 | return false; |
| 3365 | } |
| 3366 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3367 | GLsizei writeLength = 0; |
| 3368 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3369 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3370 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3371 | { |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
| 3375 | SetRobustLengthParam(length, writeLength); |
| 3376 | |
| 3377 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3378 | } |
| 3379 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3380 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3381 | GLenum target, |
| 3382 | GLsizei numAttachments, |
| 3383 | const GLenum *attachments, |
| 3384 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3385 | { |
| 3386 | if (numAttachments < 0) |
| 3387 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3388 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3389 | return false; |
| 3390 | } |
| 3391 | |
| 3392 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3393 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3394 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3395 | { |
| 3396 | if (defaultFramebuffer) |
| 3397 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3398 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3399 | return false; |
| 3400 | } |
| 3401 | |
| 3402 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3403 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3404 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3405 | "greater than the maximum supported " |
| 3406 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3407 | return false; |
| 3408 | } |
| 3409 | } |
| 3410 | else |
| 3411 | { |
| 3412 | switch (attachments[i]) |
| 3413 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3414 | case GL_DEPTH_ATTACHMENT: |
| 3415 | case GL_STENCIL_ATTACHMENT: |
| 3416 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3417 | if (defaultFramebuffer) |
| 3418 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3419 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3420 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3421 | return false; |
| 3422 | } |
| 3423 | break; |
| 3424 | case GL_COLOR: |
| 3425 | case GL_DEPTH: |
| 3426 | case GL_STENCIL: |
| 3427 | if (!defaultFramebuffer) |
| 3428 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3429 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3430 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3431 | return false; |
| 3432 | } |
| 3433 | break; |
| 3434 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3435 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3436 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | |
| 3441 | return true; |
| 3442 | } |
| 3443 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3444 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3445 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3446 | if (!context->getExtensions().debugMarker) |
| 3447 | { |
| 3448 | // The debug marker calls should not set error state |
| 3449 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3450 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3451 | return false; |
| 3452 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3453 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3454 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3455 | if (length < 0) |
| 3456 | { |
| 3457 | return false; |
| 3458 | } |
| 3459 | |
| 3460 | if (marker == nullptr) |
| 3461 | { |
| 3462 | return false; |
| 3463 | } |
| 3464 | |
| 3465 | return true; |
| 3466 | } |
| 3467 | |
| 3468 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3469 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3470 | if (!context->getExtensions().debugMarker) |
| 3471 | { |
| 3472 | // The debug marker calls should not set error state |
| 3473 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3474 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3475 | return false; |
| 3476 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3477 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3478 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3479 | if (length < 0) |
| 3480 | { |
| 3481 | return false; |
| 3482 | } |
| 3483 | |
| 3484 | if (length > 0 && marker == nullptr) |
| 3485 | { |
| 3486 | return false; |
| 3487 | } |
| 3488 | |
| 3489 | return true; |
| 3490 | } |
| 3491 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3492 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3493 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3494 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3495 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3496 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3497 | return false; |
| 3498 | } |
| 3499 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3500 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3501 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3502 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3503 | if (!context->getExtensions().eglImage) |
| 3504 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3505 | context->handleError(InvalidEnum() |
| 3506 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3507 | } |
| 3508 | break; |
| 3509 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3510 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3511 | if (!context->getExtensions().eglImageExternal) |
| 3512 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3513 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3514 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3515 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3516 | break; |
| 3517 | |
| 3518 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3519 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3520 | return false; |
| 3521 | } |
| 3522 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3523 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3524 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3525 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3526 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3527 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3528 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3529 | return false; |
| 3530 | } |
| 3531 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3532 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3533 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3534 | context->handleError(InvalidOperation() |
| 3535 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3536 | return false; |
| 3537 | } |
| 3538 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3539 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3540 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3541 | if (!textureCaps.texturable) |
| 3542 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3543 | context->handleError(InvalidOperation() |
| 3544 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3548 | return true; |
| 3549 | } |
| 3550 | |
| 3551 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3552 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3553 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3554 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3555 | if (!context->getExtensions().eglImage) |
| 3556 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3557 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3558 | return false; |
| 3559 | } |
| 3560 | |
| 3561 | switch (target) |
| 3562 | { |
| 3563 | case GL_RENDERBUFFER: |
| 3564 | break; |
| 3565 | |
| 3566 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3567 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3568 | return false; |
| 3569 | } |
| 3570 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3571 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3572 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3573 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3574 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3575 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3576 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3577 | return false; |
| 3578 | } |
| 3579 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3580 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3581 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 3582 | if (!textureCaps.renderbuffer) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3583 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3584 | context->handleError(InvalidOperation() |
| 3585 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3586 | return false; |
| 3587 | } |
| 3588 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3589 | return true; |
| 3590 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3591 | |
| 3592 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3593 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3594 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3595 | { |
| 3596 | // The default VAO should always exist |
| 3597 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3598 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3599 | return false; |
| 3600 | } |
| 3601 | |
| 3602 | return true; |
| 3603 | } |
| 3604 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3605 | bool ValidateProgramBinaryBase(Context *context, |
| 3606 | GLuint program, |
| 3607 | GLenum binaryFormat, |
| 3608 | const void *binary, |
| 3609 | GLint length) |
| 3610 | { |
| 3611 | Program *programObject = GetValidProgram(context, program); |
| 3612 | if (programObject == nullptr) |
| 3613 | { |
| 3614 | return false; |
| 3615 | } |
| 3616 | |
| 3617 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3618 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3619 | programBinaryFormats.end()) |
| 3620 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3621 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3622 | return false; |
| 3623 | } |
| 3624 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3625 | if (context->hasActiveTransformFeedback(program)) |
| 3626 | { |
| 3627 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3628 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3629 | "is associated with an active transform " |
| 3630 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3631 | return false; |
| 3632 | } |
| 3633 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3634 | return true; |
| 3635 | } |
| 3636 | |
| 3637 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3638 | GLuint program, |
| 3639 | GLsizei bufSize, |
| 3640 | GLsizei *length, |
| 3641 | GLenum *binaryFormat, |
| 3642 | void *binary) |
| 3643 | { |
| 3644 | Program *programObject = GetValidProgram(context, program); |
| 3645 | if (programObject == nullptr) |
| 3646 | { |
| 3647 | return false; |
| 3648 | } |
| 3649 | |
| 3650 | if (!programObject->isLinked()) |
| 3651 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3652 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3653 | return false; |
| 3654 | } |
| 3655 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3656 | if (context->getCaps().programBinaryFormats.empty()) |
| 3657 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3658 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3659 | return false; |
| 3660 | } |
| 3661 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3662 | return true; |
| 3663 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3664 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3665 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3666 | { |
| 3667 | // 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] | 3668 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3669 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3670 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3671 | return false; |
| 3672 | } |
| 3673 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3674 | { |
| 3675 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3676 | return false; |
| 3677 | } |
| 3678 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3679 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3680 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3681 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3682 | |
| 3683 | // This should come first before the check for the default frame buffer |
| 3684 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3685 | // rather than INVALID_OPERATION |
| 3686 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3687 | { |
| 3688 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3689 | |
| 3690 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3691 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3692 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3693 | { |
| 3694 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3695 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3696 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3697 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3698 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3699 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3700 | return false; |
| 3701 | } |
| 3702 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3703 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3704 | context->handleError(InvalidOperation() |
| 3705 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3706 | return false; |
| 3707 | } |
| 3708 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3709 | frameBufferId != 0) |
| 3710 | { |
| 3711 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3712 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3713 | context->handleError(InvalidOperation() |
| 3714 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3715 | return false; |
| 3716 | } |
| 3717 | } |
| 3718 | |
| 3719 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3720 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3721 | if (frameBufferId == 0) |
| 3722 | { |
| 3723 | if (n != 1) |
| 3724 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3725 | context->handleError(InvalidOperation() |
| 3726 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3727 | return false; |
| 3728 | } |
| 3729 | |
| 3730 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3731 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3732 | context->handleError( |
| 3733 | InvalidOperation() |
| 3734 | << "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] | 3735 | return false; |
| 3736 | } |
| 3737 | } |
| 3738 | |
| 3739 | return true; |
| 3740 | } |
| 3741 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3742 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3743 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3744 | GLenum pname, |
| 3745 | GLsizei *length, |
| 3746 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3747 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3748 | if (length) |
| 3749 | { |
| 3750 | *length = 0; |
| 3751 | } |
| 3752 | |
| 3753 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3754 | { |
| 3755 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3756 | InvalidOperation() |
| 3757 | << "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] | 3758 | return false; |
| 3759 | } |
| 3760 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3761 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3762 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3763 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3764 | return false; |
| 3765 | } |
| 3766 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3767 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3768 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3769 | case GL_BUFFER_MAP_POINTER: |
| 3770 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3771 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3772 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3773 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3774 | return false; |
| 3775 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3776 | |
| 3777 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3778 | // target bound to zero generate an INVALID_OPERATION error." |
| 3779 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3780 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3781 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3782 | context->handleError(InvalidOperation() |
| 3783 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3784 | return false; |
| 3785 | } |
| 3786 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3787 | if (length) |
| 3788 | { |
| 3789 | *length = 1; |
| 3790 | } |
| 3791 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3792 | return true; |
| 3793 | } |
| 3794 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3795 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3796 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3797 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3798 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3799 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3800 | return false; |
| 3801 | } |
| 3802 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3803 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3804 | |
| 3805 | if (buffer == nullptr || !buffer->isMapped()) |
| 3806 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3807 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3808 | return false; |
| 3809 | } |
| 3810 | |
| 3811 | return true; |
| 3812 | } |
| 3813 | |
| 3814 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3815 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3816 | GLintptr offset, |
| 3817 | GLsizeiptr length, |
| 3818 | GLbitfield access) |
| 3819 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3820 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3821 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3822 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3823 | return false; |
| 3824 | } |
| 3825 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3826 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3827 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3828 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3829 | return false; |
| 3830 | } |
| 3831 | |
| 3832 | if (length < 0) |
| 3833 | { |
| 3834 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3838 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3839 | |
| 3840 | if (!buffer) |
| 3841 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3842 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3843 | return false; |
| 3844 | } |
| 3845 | |
| 3846 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3847 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3848 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3849 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3850 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3851 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3852 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3853 | return false; |
| 3854 | } |
| 3855 | |
| 3856 | // Check for invalid bits in the mask |
| 3857 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3858 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3859 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3860 | |
| 3861 | if (access & ~(allAccessBits)) |
| 3862 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3863 | context->handleError(InvalidValue() |
| 3864 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3865 | return false; |
| 3866 | } |
| 3867 | |
| 3868 | if (length == 0) |
| 3869 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3870 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3871 | return false; |
| 3872 | } |
| 3873 | |
| 3874 | if (buffer->isMapped()) |
| 3875 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3876 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3877 | return false; |
| 3878 | } |
| 3879 | |
| 3880 | // Check for invalid bit combinations |
| 3881 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3882 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3883 | context->handleError(InvalidOperation() |
| 3884 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3885 | return false; |
| 3886 | } |
| 3887 | |
| 3888 | GLbitfield writeOnlyBits = |
| 3889 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3890 | |
| 3891 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3892 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3893 | context->handleError(InvalidOperation() |
| 3894 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3895 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3896 | return false; |
| 3897 | } |
| 3898 | |
| 3899 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3900 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3901 | context->handleError( |
| 3902 | InvalidOperation() |
| 3903 | << "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] | 3904 | return false; |
| 3905 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3906 | |
| 3907 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3911 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3912 | GLintptr offset, |
| 3913 | GLsizeiptr length) |
| 3914 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3915 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3916 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3917 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3918 | return false; |
| 3919 | } |
| 3920 | |
| 3921 | if (length < 0) |
| 3922 | { |
| 3923 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3924 | return false; |
| 3925 | } |
| 3926 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3927 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3928 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3929 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3930 | return false; |
| 3931 | } |
| 3932 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3933 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3934 | |
| 3935 | if (buffer == nullptr) |
| 3936 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3937 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3938 | return false; |
| 3939 | } |
| 3940 | |
| 3941 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3942 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3943 | context->handleError(InvalidOperation() |
| 3944 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3945 | return false; |
| 3946 | } |
| 3947 | |
| 3948 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3949 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3950 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3951 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3952 | if (!checkedSize.IsValid() || |
| 3953 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3954 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3955 | context->handleError(InvalidValue() |
| 3956 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3957 | return false; |
| 3958 | } |
| 3959 | |
| 3960 | return true; |
| 3961 | } |
| 3962 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3963 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3964 | { |
| 3965 | if (n < 0) |
| 3966 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3967 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3968 | return false; |
| 3969 | } |
| 3970 | return true; |
| 3971 | } |
| 3972 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3973 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3974 | { |
| 3975 | if (!context->getExtensions().robustClientMemory) |
| 3976 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3977 | context->handleError(InvalidOperation() |
| 3978 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3979 | return false; |
| 3980 | } |
| 3981 | |
| 3982 | if (bufSize < 0) |
| 3983 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3984 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3985 | return false; |
| 3986 | } |
| 3987 | |
| 3988 | return true; |
| 3989 | } |
| 3990 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3991 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3992 | { |
| 3993 | if (bufSize < numParams) |
| 3994 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3995 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 3996 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3997 | return false; |
| 3998 | } |
| 3999 | |
| 4000 | return true; |
| 4001 | } |
| 4002 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4003 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4004 | GLenum target, |
| 4005 | GLenum attachment, |
| 4006 | GLenum pname, |
| 4007 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4008 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4009 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4010 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4011 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4012 | return false; |
| 4013 | } |
| 4014 | |
| 4015 | int clientVersion = context->getClientMajorVersion(); |
| 4016 | |
| 4017 | switch (pname) |
| 4018 | { |
| 4019 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4020 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4021 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4022 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4023 | break; |
| 4024 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4025 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4026 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4027 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4028 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4029 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4030 | { |
| 4031 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4032 | return false; |
| 4033 | } |
| 4034 | break; |
| 4035 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4036 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4037 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4038 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4039 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4040 | return false; |
| 4041 | } |
| 4042 | break; |
| 4043 | |
| 4044 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4045 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4046 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4047 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4048 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4049 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4050 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4051 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4052 | if (clientVersion < 3) |
| 4053 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4054 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4055 | return false; |
| 4056 | } |
| 4057 | break; |
| 4058 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4059 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4060 | if (!context->getExtensions().geometryShader) |
| 4061 | { |
| 4062 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4063 | return false; |
| 4064 | } |
| 4065 | break; |
| 4066 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4067 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4068 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4069 | return false; |
| 4070 | } |
| 4071 | |
| 4072 | // Determine if the attachment is a valid enum |
| 4073 | switch (attachment) |
| 4074 | { |
| 4075 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4076 | case GL_DEPTH: |
| 4077 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4078 | if (clientVersion < 3) |
| 4079 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4080 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4081 | return false; |
| 4082 | } |
| 4083 | break; |
| 4084 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4085 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4086 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4087 | { |
| 4088 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4089 | return false; |
| 4090 | } |
| 4091 | break; |
| 4092 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4093 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4094 | case GL_DEPTH_ATTACHMENT: |
| 4095 | case GL_STENCIL_ATTACHMENT: |
| 4096 | break; |
| 4097 | |
| 4098 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4099 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4100 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4101 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4102 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4103 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4104 | return false; |
| 4105 | } |
| 4106 | break; |
| 4107 | } |
| 4108 | |
| 4109 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4110 | ASSERT(framebuffer); |
| 4111 | |
| 4112 | if (framebuffer->id() == 0) |
| 4113 | { |
| 4114 | if (clientVersion < 3) |
| 4115 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4116 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4117 | return false; |
| 4118 | } |
| 4119 | |
| 4120 | switch (attachment) |
| 4121 | { |
| 4122 | case GL_BACK: |
| 4123 | case GL_DEPTH: |
| 4124 | case GL_STENCIL: |
| 4125 | break; |
| 4126 | |
| 4127 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4128 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4129 | return false; |
| 4130 | } |
| 4131 | } |
| 4132 | else |
| 4133 | { |
| 4134 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4135 | { |
| 4136 | // Valid attachment query |
| 4137 | } |
| 4138 | else |
| 4139 | { |
| 4140 | switch (attachment) |
| 4141 | { |
| 4142 | case GL_DEPTH_ATTACHMENT: |
| 4143 | case GL_STENCIL_ATTACHMENT: |
| 4144 | break; |
| 4145 | |
| 4146 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4147 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4148 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4149 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4150 | return false; |
| 4151 | } |
| 4152 | break; |
| 4153 | |
| 4154 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4155 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4156 | return false; |
| 4157 | } |
| 4158 | } |
| 4159 | } |
| 4160 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4161 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4162 | if (attachmentObject) |
| 4163 | { |
| 4164 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4165 | attachmentObject->type() == GL_TEXTURE || |
| 4166 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4167 | |
| 4168 | switch (pname) |
| 4169 | { |
| 4170 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4171 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4172 | attachmentObject->type() != GL_TEXTURE) |
| 4173 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4174 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4175 | return false; |
| 4176 | } |
| 4177 | break; |
| 4178 | |
| 4179 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4180 | if (attachmentObject->type() != GL_TEXTURE) |
| 4181 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4182 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4183 | return false; |
| 4184 | } |
| 4185 | break; |
| 4186 | |
| 4187 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4188 | if (attachmentObject->type() != GL_TEXTURE) |
| 4189 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4190 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | break; |
| 4194 | |
| 4195 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4196 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4197 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4198 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4199 | return false; |
| 4200 | } |
| 4201 | break; |
| 4202 | |
| 4203 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4204 | if (attachmentObject->type() != GL_TEXTURE) |
| 4205 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4206 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4207 | return false; |
| 4208 | } |
| 4209 | break; |
| 4210 | |
| 4211 | default: |
| 4212 | break; |
| 4213 | } |
| 4214 | } |
| 4215 | else |
| 4216 | { |
| 4217 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4218 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4219 | |
| 4220 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4221 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4222 | // INVALID_OPERATION for all other pnames |
| 4223 | |
| 4224 | switch (pname) |
| 4225 | { |
| 4226 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4227 | break; |
| 4228 | |
| 4229 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4230 | if (clientVersion < 3) |
| 4231 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4232 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4233 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4234 | return false; |
| 4235 | } |
| 4236 | break; |
| 4237 | |
| 4238 | default: |
| 4239 | if (clientVersion < 3) |
| 4240 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4241 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4242 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4243 | return false; |
| 4244 | } |
| 4245 | else |
| 4246 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4247 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4248 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4249 | return false; |
| 4250 | } |
| 4251 | } |
| 4252 | } |
| 4253 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4254 | if (numParams) |
| 4255 | { |
| 4256 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4257 | { |
| 4258 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4259 | // parameters. |
| 4260 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4261 | *numParams = numViews * 2; |
| 4262 | } |
| 4263 | else |
| 4264 | { |
| 4265 | // For all other queries we can have only one output parameter. |
| 4266 | *numParams = 1; |
| 4267 | } |
| 4268 | } |
| 4269 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4270 | return true; |
| 4271 | } |
| 4272 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4273 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4274 | GLenum target, |
| 4275 | GLenum attachment, |
| 4276 | GLenum pname, |
| 4277 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4278 | GLsizei *length, |
| 4279 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4280 | { |
| 4281 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4282 | { |
| 4283 | return false; |
| 4284 | } |
| 4285 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4286 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4287 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4288 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4289 | { |
| 4290 | return false; |
| 4291 | } |
| 4292 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4293 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4294 | { |
| 4295 | return false; |
| 4296 | } |
| 4297 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4298 | SetRobustLengthParam(length, numParams); |
| 4299 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4300 | return true; |
| 4301 | } |
| 4302 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4303 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4304 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4305 | GLenum pname, |
| 4306 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4307 | GLsizei *length, |
| 4308 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4309 | { |
| 4310 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4311 | { |
| 4312 | return false; |
| 4313 | } |
| 4314 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4315 | GLsizei numParams = 0; |
| 4316 | |
| 4317 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4318 | { |
| 4319 | return false; |
| 4320 | } |
| 4321 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4322 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4323 | { |
| 4324 | return false; |
| 4325 | } |
| 4326 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4327 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4328 | return true; |
| 4329 | } |
| 4330 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4331 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4332 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4333 | GLenum pname, |
| 4334 | GLsizei bufSize, |
| 4335 | GLsizei *length, |
| 4336 | GLint64 *params) |
| 4337 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4338 | GLsizei numParams = 0; |
| 4339 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4340 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4341 | { |
| 4342 | return false; |
| 4343 | } |
| 4344 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4345 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4346 | { |
| 4347 | return false; |
| 4348 | } |
| 4349 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4350 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4351 | { |
| 4352 | return false; |
| 4353 | } |
| 4354 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4355 | SetRobustLengthParam(length, numParams); |
| 4356 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4357 | return true; |
| 4358 | } |
| 4359 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4360 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4361 | { |
| 4362 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4363 | if (numParams) |
| 4364 | { |
| 4365 | *numParams = 1; |
| 4366 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4367 | |
| 4368 | Program *programObject = GetValidProgram(context, program); |
| 4369 | if (!programObject) |
| 4370 | { |
| 4371 | return false; |
| 4372 | } |
| 4373 | |
| 4374 | switch (pname) |
| 4375 | { |
| 4376 | case GL_DELETE_STATUS: |
| 4377 | case GL_LINK_STATUS: |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 4378 | case GL_COMPLETION_STATUS_KHR: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4379 | case GL_VALIDATE_STATUS: |
| 4380 | case GL_INFO_LOG_LENGTH: |
| 4381 | case GL_ATTACHED_SHADERS: |
| 4382 | case GL_ACTIVE_ATTRIBUTES: |
| 4383 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4384 | case GL_ACTIVE_UNIFORMS: |
| 4385 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4386 | break; |
| 4387 | |
| 4388 | case GL_PROGRAM_BINARY_LENGTH: |
| 4389 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4390 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4391 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4392 | "requires GL_OES_get_program_binary or " |
| 4393 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4394 | return false; |
| 4395 | } |
| 4396 | break; |
| 4397 | |
| 4398 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4399 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4400 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4401 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4402 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4403 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4404 | if (context->getClientMajorVersion() < 3) |
| 4405 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4406 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4407 | return false; |
| 4408 | } |
| 4409 | break; |
| 4410 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4411 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4412 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4413 | if (context->getClientVersion() < Version(3, 1)) |
| 4414 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4415 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
| 4418 | break; |
| 4419 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4420 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4421 | if (context->getClientVersion() < Version(3, 1)) |
| 4422 | { |
| 4423 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4424 | return false; |
| 4425 | } |
| 4426 | |
| 4427 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4428 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4429 | // program which has not been linked successfully, or which does not contain objects to |
| 4430 | // form a compute shader. |
| 4431 | if (!programObject->isLinked()) |
| 4432 | { |
| 4433 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4434 | return false; |
| 4435 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4436 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4437 | { |
| 4438 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4439 | return false; |
| 4440 | } |
| 4441 | break; |
| 4442 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4443 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4444 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4445 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4446 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4447 | if (!context->getExtensions().geometryShader) |
| 4448 | { |
| 4449 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4450 | return false; |
| 4451 | } |
| 4452 | |
| 4453 | // [EXT_geometry_shader] Chapter 7.12 |
| 4454 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4455 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4456 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4457 | // successfully, or which does not contain objects to form a geometry shader. |
| 4458 | if (!programObject->isLinked()) |
| 4459 | { |
| 4460 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4461 | return false; |
| 4462 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4463 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4464 | { |
| 4465 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4466 | return false; |
| 4467 | } |
| 4468 | break; |
| 4469 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4470 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4471 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4472 | return false; |
| 4473 | } |
| 4474 | |
| 4475 | return true; |
| 4476 | } |
| 4477 | |
| 4478 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4479 | GLuint program, |
| 4480 | GLenum pname, |
| 4481 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4482 | GLsizei *length, |
| 4483 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4484 | { |
| 4485 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4486 | { |
| 4487 | return false; |
| 4488 | } |
| 4489 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4490 | GLsizei numParams = 0; |
| 4491 | |
| 4492 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4493 | { |
| 4494 | return false; |
| 4495 | } |
| 4496 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4497 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4498 | { |
| 4499 | return false; |
| 4500 | } |
| 4501 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4502 | SetRobustLengthParam(length, numParams); |
| 4503 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4504 | return true; |
| 4505 | } |
| 4506 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4507 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4508 | GLenum target, |
| 4509 | GLenum pname, |
| 4510 | GLsizei bufSize, |
| 4511 | GLsizei *length, |
| 4512 | GLint *params) |
| 4513 | { |
| 4514 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4515 | { |
| 4516 | return false; |
| 4517 | } |
| 4518 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4519 | GLsizei numParams = 0; |
| 4520 | |
| 4521 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4522 | { |
| 4523 | return false; |
| 4524 | } |
| 4525 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4526 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4527 | { |
| 4528 | return false; |
| 4529 | } |
| 4530 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4531 | SetRobustLengthParam(length, numParams); |
| 4532 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4533 | return true; |
| 4534 | } |
| 4535 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4536 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4537 | GLuint shader, |
| 4538 | GLenum pname, |
| 4539 | GLsizei bufSize, |
| 4540 | GLsizei *length, |
| 4541 | GLint *params) |
| 4542 | { |
| 4543 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4544 | { |
| 4545 | return false; |
| 4546 | } |
| 4547 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4548 | GLsizei numParams = 0; |
| 4549 | |
| 4550 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4551 | { |
| 4552 | return false; |
| 4553 | } |
| 4554 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4555 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4556 | { |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4560 | SetRobustLengthParam(length, numParams); |
| 4561 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4562 | return true; |
| 4563 | } |
| 4564 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4565 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4566 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4567 | GLenum pname, |
| 4568 | GLsizei bufSize, |
| 4569 | GLsizei *length, |
| 4570 | GLfloat *params) |
| 4571 | { |
| 4572 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4573 | { |
| 4574 | return false; |
| 4575 | } |
| 4576 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4577 | GLsizei numParams = 0; |
| 4578 | |
| 4579 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4580 | { |
| 4581 | return false; |
| 4582 | } |
| 4583 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4584 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4585 | { |
| 4586 | return false; |
| 4587 | } |
| 4588 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4589 | SetRobustLengthParam(length, numParams); |
| 4590 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4591 | return true; |
| 4592 | } |
| 4593 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4594 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4595 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4596 | GLenum pname, |
| 4597 | GLsizei bufSize, |
| 4598 | GLsizei *length, |
| 4599 | GLint *params) |
| 4600 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4601 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4602 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4603 | { |
| 4604 | return false; |
| 4605 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4606 | GLsizei numParams = 0; |
| 4607 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4608 | { |
| 4609 | return false; |
| 4610 | } |
| 4611 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4612 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4613 | { |
| 4614 | return false; |
| 4615 | } |
| 4616 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4617 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4618 | return true; |
| 4619 | } |
| 4620 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4621 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4622 | TextureType target, |
| 4623 | GLenum pname, |
| 4624 | GLsizei bufSize, |
| 4625 | GLsizei *length, |
| 4626 | GLint *params) |
| 4627 | { |
| 4628 | UNIMPLEMENTED(); |
| 4629 | return false; |
| 4630 | } |
| 4631 | |
| 4632 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4633 | TextureType target, |
| 4634 | GLenum pname, |
| 4635 | GLsizei bufSize, |
| 4636 | GLsizei *length, |
| 4637 | GLuint *params) |
| 4638 | { |
| 4639 | UNIMPLEMENTED(); |
| 4640 | return false; |
| 4641 | } |
| 4642 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4643 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4644 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4645 | GLenum pname, |
| 4646 | GLsizei bufSize, |
| 4647 | const GLfloat *params) |
| 4648 | { |
| 4649 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4650 | { |
| 4651 | return false; |
| 4652 | } |
| 4653 | |
| 4654 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4655 | } |
| 4656 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4657 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4658 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4659 | GLenum pname, |
| 4660 | GLsizei bufSize, |
| 4661 | const GLint *params) |
| 4662 | { |
| 4663 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4664 | { |
| 4665 | return false; |
| 4666 | } |
| 4667 | |
| 4668 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4669 | } |
| 4670 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4671 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4672 | TextureType target, |
| 4673 | GLenum pname, |
| 4674 | GLsizei bufSize, |
| 4675 | const GLint *params) |
| 4676 | { |
| 4677 | UNIMPLEMENTED(); |
| 4678 | return false; |
| 4679 | } |
| 4680 | |
| 4681 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4682 | TextureType target, |
| 4683 | GLenum pname, |
| 4684 | GLsizei bufSize, |
| 4685 | const GLuint *params) |
| 4686 | { |
| 4687 | UNIMPLEMENTED(); |
| 4688 | return false; |
| 4689 | } |
| 4690 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4691 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4692 | GLuint sampler, |
| 4693 | GLenum pname, |
| 4694 | GLuint bufSize, |
| 4695 | GLsizei *length, |
| 4696 | GLfloat *params) |
| 4697 | { |
| 4698 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4699 | { |
| 4700 | return false; |
| 4701 | } |
| 4702 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4703 | GLsizei numParams = 0; |
| 4704 | |
| 4705 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4706 | { |
| 4707 | return false; |
| 4708 | } |
| 4709 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4710 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4711 | { |
| 4712 | return false; |
| 4713 | } |
| 4714 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4715 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4716 | return true; |
| 4717 | } |
| 4718 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4719 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4720 | GLuint sampler, |
| 4721 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4722 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4723 | GLsizei *length, |
| 4724 | GLint *params) |
| 4725 | { |
| 4726 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4727 | { |
| 4728 | return false; |
| 4729 | } |
| 4730 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4731 | GLsizei numParams = 0; |
| 4732 | |
| 4733 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4734 | { |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4738 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4739 | { |
| 4740 | return false; |
| 4741 | } |
| 4742 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4743 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4744 | return true; |
| 4745 | } |
| 4746 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4747 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4748 | GLuint sampler, |
| 4749 | GLenum pname, |
| 4750 | GLsizei bufSize, |
| 4751 | GLsizei *length, |
| 4752 | GLint *params) |
| 4753 | { |
| 4754 | UNIMPLEMENTED(); |
| 4755 | return false; |
| 4756 | } |
| 4757 | |
| 4758 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4759 | GLuint sampler, |
| 4760 | GLenum pname, |
| 4761 | GLsizei bufSize, |
| 4762 | GLsizei *length, |
| 4763 | GLuint *params) |
| 4764 | { |
| 4765 | UNIMPLEMENTED(); |
| 4766 | return false; |
| 4767 | } |
| 4768 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4769 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4770 | GLuint sampler, |
| 4771 | GLenum pname, |
| 4772 | GLsizei bufSize, |
| 4773 | const GLfloat *params) |
| 4774 | { |
| 4775 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4776 | { |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
| 4780 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4781 | } |
| 4782 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4783 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4784 | GLuint sampler, |
| 4785 | GLenum pname, |
| 4786 | GLsizei bufSize, |
| 4787 | const GLint *params) |
| 4788 | { |
| 4789 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4790 | { |
| 4791 | return false; |
| 4792 | } |
| 4793 | |
| 4794 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4795 | } |
| 4796 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4797 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4798 | GLuint sampler, |
| 4799 | GLenum pname, |
| 4800 | GLsizei bufSize, |
| 4801 | const GLint *param) |
| 4802 | { |
| 4803 | UNIMPLEMENTED(); |
| 4804 | return false; |
| 4805 | } |
| 4806 | |
| 4807 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4808 | GLuint sampler, |
| 4809 | GLenum pname, |
| 4810 | GLsizei bufSize, |
| 4811 | const GLuint *param) |
| 4812 | { |
| 4813 | UNIMPLEMENTED(); |
| 4814 | return false; |
| 4815 | } |
| 4816 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4817 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4818 | GLuint index, |
| 4819 | GLenum pname, |
| 4820 | GLsizei bufSize, |
| 4821 | GLsizei *length, |
| 4822 | GLfloat *params) |
| 4823 | { |
| 4824 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4825 | { |
| 4826 | return false; |
| 4827 | } |
| 4828 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4829 | GLsizei writeLength = 0; |
| 4830 | |
| 4831 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4832 | { |
| 4833 | return false; |
| 4834 | } |
| 4835 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4836 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4837 | { |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4841 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4842 | return true; |
| 4843 | } |
| 4844 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4845 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4846 | GLuint index, |
| 4847 | GLenum pname, |
| 4848 | GLsizei bufSize, |
| 4849 | GLsizei *length, |
| 4850 | GLint *params) |
| 4851 | { |
| 4852 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4853 | { |
| 4854 | return false; |
| 4855 | } |
| 4856 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4857 | GLsizei writeLength = 0; |
| 4858 | |
| 4859 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4860 | { |
| 4861 | return false; |
| 4862 | } |
| 4863 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4864 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4865 | { |
| 4866 | return false; |
| 4867 | } |
| 4868 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4869 | SetRobustLengthParam(length, writeLength); |
| 4870 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4871 | return true; |
| 4872 | } |
| 4873 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4874 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4875 | GLuint index, |
| 4876 | GLenum pname, |
| 4877 | GLsizei bufSize, |
| 4878 | GLsizei *length, |
| 4879 | void **pointer) |
| 4880 | { |
| 4881 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4882 | { |
| 4883 | return false; |
| 4884 | } |
| 4885 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4886 | GLsizei writeLength = 0; |
| 4887 | |
| 4888 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4889 | { |
| 4890 | return false; |
| 4891 | } |
| 4892 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4893 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4894 | { |
| 4895 | return false; |
| 4896 | } |
| 4897 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4898 | SetRobustLengthParam(length, writeLength); |
| 4899 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4900 | return true; |
| 4901 | } |
| 4902 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4903 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4904 | GLuint index, |
| 4905 | GLenum pname, |
| 4906 | GLsizei bufSize, |
| 4907 | GLsizei *length, |
| 4908 | GLint *params) |
| 4909 | { |
| 4910 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4911 | { |
| 4912 | return false; |
| 4913 | } |
| 4914 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4915 | GLsizei writeLength = 0; |
| 4916 | |
| 4917 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4918 | { |
| 4919 | return false; |
| 4920 | } |
| 4921 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4922 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4923 | { |
| 4924 | return false; |
| 4925 | } |
| 4926 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4927 | SetRobustLengthParam(length, writeLength); |
| 4928 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4929 | return true; |
| 4930 | } |
| 4931 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4932 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4933 | GLuint index, |
| 4934 | GLenum pname, |
| 4935 | GLsizei bufSize, |
| 4936 | GLsizei *length, |
| 4937 | GLuint *params) |
| 4938 | { |
| 4939 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4940 | { |
| 4941 | return false; |
| 4942 | } |
| 4943 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4944 | GLsizei writeLength = 0; |
| 4945 | |
| 4946 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4947 | { |
| 4948 | return false; |
| 4949 | } |
| 4950 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4951 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4952 | { |
| 4953 | return false; |
| 4954 | } |
| 4955 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4956 | SetRobustLengthParam(length, writeLength); |
| 4957 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4958 | return true; |
| 4959 | } |
| 4960 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4961 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 4962 | GLuint program, |
| 4963 | GLuint uniformBlockIndex, |
| 4964 | GLenum pname, |
| 4965 | GLsizei bufSize, |
| 4966 | GLsizei *length, |
| 4967 | GLint *params) |
| 4968 | { |
| 4969 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4970 | { |
| 4971 | return false; |
| 4972 | } |
| 4973 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4974 | GLsizei writeLength = 0; |
| 4975 | |
| 4976 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 4977 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4978 | { |
| 4979 | return false; |
| 4980 | } |
| 4981 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4982 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4983 | { |
| 4984 | return false; |
| 4985 | } |
| 4986 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4987 | SetRobustLengthParam(length, writeLength); |
| 4988 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4989 | return true; |
| 4990 | } |
| 4991 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 4992 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4993 | GLenum target, |
| 4994 | GLenum internalformat, |
| 4995 | GLenum pname, |
| 4996 | GLsizei bufSize, |
| 4997 | GLsizei *length, |
| 4998 | GLint *params) |
| 4999 | { |
| 5000 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5001 | { |
| 5002 | return false; |
| 5003 | } |
| 5004 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5005 | GLsizei numParams = 0; |
| 5006 | |
| 5007 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5008 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5009 | { |
| 5010 | return false; |
| 5011 | } |
| 5012 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5013 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5014 | { |
| 5015 | return false; |
| 5016 | } |
| 5017 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5018 | SetRobustLengthParam(length, numParams); |
| 5019 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5020 | return true; |
| 5021 | } |
| 5022 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5023 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5024 | GLuint attribIndex, |
| 5025 | GLint size, |
| 5026 | GLenum type, |
| 5027 | GLboolean pureInteger) |
| 5028 | { |
| 5029 | const Caps &caps = context->getCaps(); |
| 5030 | if (attribIndex >= caps.maxVertexAttributes) |
| 5031 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5032 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5033 | return false; |
| 5034 | } |
| 5035 | |
| 5036 | if (size < 1 || size > 4) |
| 5037 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5038 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5039 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5040 | } |
| 5041 | |
| 5042 | switch (type) |
| 5043 | { |
| 5044 | case GL_BYTE: |
| 5045 | case GL_UNSIGNED_BYTE: |
| 5046 | case GL_SHORT: |
| 5047 | case GL_UNSIGNED_SHORT: |
| 5048 | break; |
| 5049 | |
| 5050 | case GL_INT: |
| 5051 | case GL_UNSIGNED_INT: |
| 5052 | if (context->getClientMajorVersion() < 3) |
| 5053 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5054 | context->handleError(InvalidEnum() |
| 5055 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5056 | return false; |
| 5057 | } |
| 5058 | break; |
| 5059 | |
| 5060 | case GL_FIXED: |
| 5061 | case GL_FLOAT: |
| 5062 | if (pureInteger) |
| 5063 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5064 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5065 | return false; |
| 5066 | } |
| 5067 | break; |
| 5068 | |
| 5069 | case GL_HALF_FLOAT: |
| 5070 | if (context->getClientMajorVersion() < 3) |
| 5071 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5072 | context->handleError(InvalidEnum() |
| 5073 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5074 | return false; |
| 5075 | } |
| 5076 | if (pureInteger) |
| 5077 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5078 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5079 | return false; |
| 5080 | } |
| 5081 | break; |
| 5082 | |
| 5083 | case GL_INT_2_10_10_10_REV: |
| 5084 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5085 | if (context->getClientMajorVersion() < 3) |
| 5086 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5087 | context->handleError(InvalidEnum() |
| 5088 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5089 | return false; |
| 5090 | } |
| 5091 | if (pureInteger) |
| 5092 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5093 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5094 | return false; |
| 5095 | } |
| 5096 | if (size != 4) |
| 5097 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5098 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5099 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5100 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5101 | return false; |
| 5102 | } |
| 5103 | break; |
| 5104 | |
| 5105 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5106 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5107 | return false; |
| 5108 | } |
| 5109 | |
| 5110 | return true; |
| 5111 | } |
| 5112 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5113 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5114 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5115 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5116 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5117 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5118 | GLint drawbuffer, |
| 5119 | const GLenum *validComponentTypes, |
| 5120 | size_t validComponentTypeCount) |
| 5121 | { |
| 5122 | const FramebufferAttachment *attachment = |
| 5123 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5124 | if (attachment) |
| 5125 | { |
| 5126 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5127 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5128 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5129 | { |
| 5130 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5131 | InvalidOperation() |
| 5132 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5133 | return false; |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | return true; |
| 5138 | } |
| 5139 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5140 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5141 | { |
| 5142 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5143 | { |
| 5144 | return false; |
| 5145 | } |
| 5146 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5147 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5148 | if (pixelUnpackBuffer == nullptr) |
| 5149 | { |
| 5150 | if (dataSize < imageSize) |
| 5151 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5152 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5153 | } |
| 5154 | } |
| 5155 | return true; |
| 5156 | } |
| 5157 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5158 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5159 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5160 | GLenum pname, |
| 5161 | bool pointerVersion, |
| 5162 | GLsizei *numParams) |
| 5163 | { |
| 5164 | if (numParams) |
| 5165 | { |
| 5166 | *numParams = 0; |
| 5167 | } |
| 5168 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5169 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5170 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5171 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5172 | return false; |
| 5173 | } |
| 5174 | |
| 5175 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5176 | if (!buffer) |
| 5177 | { |
| 5178 | // 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] | 5179 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5180 | return false; |
| 5181 | } |
| 5182 | |
| 5183 | const Extensions &extensions = context->getExtensions(); |
| 5184 | |
| 5185 | switch (pname) |
| 5186 | { |
| 5187 | case GL_BUFFER_USAGE: |
| 5188 | case GL_BUFFER_SIZE: |
| 5189 | break; |
| 5190 | |
| 5191 | case GL_BUFFER_ACCESS_OES: |
| 5192 | if (!extensions.mapBuffer) |
| 5193 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5194 | context->handleError(InvalidEnum() |
| 5195 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5196 | return false; |
| 5197 | } |
| 5198 | break; |
| 5199 | |
| 5200 | case GL_BUFFER_MAPPED: |
| 5201 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5202 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5203 | !extensions.mapBufferRange) |
| 5204 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5205 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5206 | "GL_OES_mapbuffer or " |
| 5207 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5208 | return false; |
| 5209 | } |
| 5210 | break; |
| 5211 | |
| 5212 | case GL_BUFFER_MAP_POINTER: |
| 5213 | if (!pointerVersion) |
| 5214 | { |
| 5215 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5216 | InvalidEnum() |
| 5217 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5218 | return false; |
| 5219 | } |
| 5220 | break; |
| 5221 | |
| 5222 | case GL_BUFFER_ACCESS_FLAGS: |
| 5223 | case GL_BUFFER_MAP_OFFSET: |
| 5224 | case GL_BUFFER_MAP_LENGTH: |
| 5225 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5226 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5227 | context->handleError(InvalidEnum() |
| 5228 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5229 | return false; |
| 5230 | } |
| 5231 | break; |
| 5232 | |
| 5233 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5234 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5235 | return false; |
| 5236 | } |
| 5237 | |
| 5238 | // All buffer parameter queries return one value. |
| 5239 | if (numParams) |
| 5240 | { |
| 5241 | *numParams = 1; |
| 5242 | } |
| 5243 | |
| 5244 | return true; |
| 5245 | } |
| 5246 | |
| 5247 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5248 | GLenum target, |
| 5249 | GLenum pname, |
| 5250 | GLsizei *length) |
| 5251 | { |
| 5252 | if (length) |
| 5253 | { |
| 5254 | *length = 0; |
| 5255 | } |
| 5256 | |
| 5257 | if (target != GL_RENDERBUFFER) |
| 5258 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5259 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5264 | if (renderbuffer == nullptr) |
| 5265 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5266 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | |
| 5270 | switch (pname) |
| 5271 | { |
| 5272 | case GL_RENDERBUFFER_WIDTH: |
| 5273 | case GL_RENDERBUFFER_HEIGHT: |
| 5274 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5275 | case GL_RENDERBUFFER_RED_SIZE: |
| 5276 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5277 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5278 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5279 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5280 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5281 | break; |
| 5282 | |
| 5283 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5284 | if (!context->getExtensions().framebufferMultisample) |
| 5285 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5286 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5287 | return false; |
| 5288 | } |
| 5289 | break; |
| 5290 | |
| 5291 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5292 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5293 | return false; |
| 5294 | } |
| 5295 | |
| 5296 | if (length) |
| 5297 | { |
| 5298 | *length = 1; |
| 5299 | } |
| 5300 | return true; |
| 5301 | } |
| 5302 | |
| 5303 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5304 | { |
| 5305 | if (length) |
| 5306 | { |
| 5307 | *length = 0; |
| 5308 | } |
| 5309 | |
| 5310 | if (GetValidShader(context, shader) == nullptr) |
| 5311 | { |
| 5312 | return false; |
| 5313 | } |
| 5314 | |
| 5315 | switch (pname) |
| 5316 | { |
| 5317 | case GL_SHADER_TYPE: |
| 5318 | case GL_DELETE_STATUS: |
| 5319 | case GL_COMPILE_STATUS: |
jchen10 | 7ae70d8 | 2018-07-06 13:47:01 +0800 | [diff] [blame] | 5320 | case GL_COMPLETION_STATUS_KHR: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5321 | case GL_INFO_LOG_LENGTH: |
| 5322 | case GL_SHADER_SOURCE_LENGTH: |
| 5323 | break; |
| 5324 | |
| 5325 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5326 | if (!context->getExtensions().translatedShaderSource) |
| 5327 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5328 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5329 | return false; |
| 5330 | } |
| 5331 | break; |
| 5332 | |
| 5333 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5334 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5335 | return false; |
| 5336 | } |
| 5337 | |
| 5338 | if (length) |
| 5339 | { |
| 5340 | *length = 1; |
| 5341 | } |
| 5342 | return true; |
| 5343 | } |
| 5344 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5345 | bool ValidateGetTexParameterBase(Context *context, |
| 5346 | TextureType target, |
| 5347 | GLenum pname, |
| 5348 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5349 | { |
| 5350 | if (length) |
| 5351 | { |
| 5352 | *length = 0; |
| 5353 | } |
| 5354 | |
| 5355 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5356 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5357 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5358 | return false; |
| 5359 | } |
| 5360 | |
| 5361 | if (context->getTargetTexture(target) == nullptr) |
| 5362 | { |
| 5363 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5364 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5365 | return false; |
| 5366 | } |
| 5367 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5368 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5369 | { |
| 5370 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5371 | return false; |
| 5372 | } |
| 5373 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5374 | switch (pname) |
| 5375 | { |
| 5376 | case GL_TEXTURE_MAG_FILTER: |
| 5377 | case GL_TEXTURE_MIN_FILTER: |
| 5378 | case GL_TEXTURE_WRAP_S: |
| 5379 | case GL_TEXTURE_WRAP_T: |
| 5380 | break; |
| 5381 | |
| 5382 | case GL_TEXTURE_USAGE_ANGLE: |
| 5383 | if (!context->getExtensions().textureUsage) |
| 5384 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5385 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5386 | return false; |
| 5387 | } |
| 5388 | break; |
| 5389 | |
| 5390 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5391 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5392 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5393 | return false; |
| 5394 | } |
| 5395 | break; |
| 5396 | |
| 5397 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5398 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5399 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5400 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5401 | return false; |
| 5402 | } |
| 5403 | break; |
| 5404 | |
| 5405 | case GL_TEXTURE_WRAP_R: |
| 5406 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5407 | case GL_TEXTURE_SWIZZLE_R: |
| 5408 | case GL_TEXTURE_SWIZZLE_G: |
| 5409 | case GL_TEXTURE_SWIZZLE_B: |
| 5410 | case GL_TEXTURE_SWIZZLE_A: |
| 5411 | case GL_TEXTURE_BASE_LEVEL: |
| 5412 | case GL_TEXTURE_MAX_LEVEL: |
| 5413 | case GL_TEXTURE_MIN_LOD: |
| 5414 | case GL_TEXTURE_MAX_LOD: |
| 5415 | case GL_TEXTURE_COMPARE_MODE: |
| 5416 | case GL_TEXTURE_COMPARE_FUNC: |
| 5417 | if (context->getClientMajorVersion() < 3) |
| 5418 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5419 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5420 | return false; |
| 5421 | } |
| 5422 | break; |
| 5423 | |
| 5424 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5425 | if (!context->getExtensions().textureSRGBDecode) |
| 5426 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5427 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5428 | return false; |
| 5429 | } |
| 5430 | break; |
| 5431 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5432 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5433 | if (context->getClientVersion() < Version(3, 1)) |
| 5434 | { |
| 5435 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5436 | return false; |
| 5437 | } |
| 5438 | break; |
| 5439 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5440 | case GL_GENERATE_MIPMAP: |
| 5441 | case GL_TEXTURE_CROP_RECT_OES: |
| 5442 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5443 | // after GL_OES_draw_texture functionality implemented |
| 5444 | if (context->getClientMajorVersion() > 1) |
| 5445 | { |
| 5446 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5447 | return false; |
| 5448 | } |
| 5449 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5450 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5451 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5452 | return false; |
| 5453 | } |
| 5454 | |
| 5455 | if (length) |
| 5456 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5457 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5458 | } |
| 5459 | return true; |
| 5460 | } |
| 5461 | |
| 5462 | bool ValidateGetVertexAttribBase(Context *context, |
| 5463 | GLuint index, |
| 5464 | GLenum pname, |
| 5465 | GLsizei *length, |
| 5466 | bool pointer, |
| 5467 | bool pureIntegerEntryPoint) |
| 5468 | { |
| 5469 | if (length) |
| 5470 | { |
| 5471 | *length = 0; |
| 5472 | } |
| 5473 | |
| 5474 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5475 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5476 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5477 | return false; |
| 5478 | } |
| 5479 | |
| 5480 | if (index >= context->getCaps().maxVertexAttributes) |
| 5481 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5482 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5483 | return false; |
| 5484 | } |
| 5485 | |
| 5486 | if (pointer) |
| 5487 | { |
| 5488 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5489 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5490 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5491 | return false; |
| 5492 | } |
| 5493 | } |
| 5494 | else |
| 5495 | { |
| 5496 | switch (pname) |
| 5497 | { |
| 5498 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5499 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5500 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5501 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5502 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5503 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5504 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5505 | break; |
| 5506 | |
| 5507 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5508 | static_assert( |
| 5509 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5510 | "ANGLE extension enums not equal to GL enums."); |
| 5511 | if (context->getClientMajorVersion() < 3 && |
| 5512 | !context->getExtensions().instancedArrays) |
| 5513 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5514 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5515 | "requires OpenGL ES 3.0 or " |
| 5516 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5517 | return false; |
| 5518 | } |
| 5519 | break; |
| 5520 | |
| 5521 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5522 | if (context->getClientMajorVersion() < 3) |
| 5523 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5524 | context->handleError( |
| 5525 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5526 | return false; |
| 5527 | } |
| 5528 | break; |
| 5529 | |
| 5530 | case GL_VERTEX_ATTRIB_BINDING: |
| 5531 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5532 | if (context->getClientVersion() < ES_3_1) |
| 5533 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5534 | context->handleError(InvalidEnum() |
| 5535 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5536 | return false; |
| 5537 | } |
| 5538 | break; |
| 5539 | |
| 5540 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5541 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5542 | return false; |
| 5543 | } |
| 5544 | } |
| 5545 | |
| 5546 | if (length) |
| 5547 | { |
| 5548 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5549 | { |
| 5550 | *length = 4; |
| 5551 | } |
| 5552 | else |
| 5553 | { |
| 5554 | *length = 1; |
| 5555 | } |
| 5556 | } |
| 5557 | |
| 5558 | return true; |
| 5559 | } |
| 5560 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5561 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5562 | GLint x, |
| 5563 | GLint y, |
| 5564 | GLsizei width, |
| 5565 | GLsizei height, |
| 5566 | GLenum format, |
| 5567 | GLenum type, |
| 5568 | GLsizei bufSize, |
| 5569 | GLsizei *length, |
| 5570 | GLsizei *columns, |
| 5571 | GLsizei *rows, |
| 5572 | void *pixels) |
| 5573 | { |
| 5574 | if (length != nullptr) |
| 5575 | { |
| 5576 | *length = 0; |
| 5577 | } |
| 5578 | if (rows != nullptr) |
| 5579 | { |
| 5580 | *rows = 0; |
| 5581 | } |
| 5582 | if (columns != nullptr) |
| 5583 | { |
| 5584 | *columns = 0; |
| 5585 | } |
| 5586 | |
| 5587 | if (width < 0 || height < 0) |
| 5588 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5589 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5590 | return false; |
| 5591 | } |
| 5592 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5593 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5594 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5595 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5596 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5597 | return false; |
| 5598 | } |
| 5599 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5600 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5601 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5602 | return false; |
| 5603 | } |
| 5604 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5605 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5606 | ASSERT(framebuffer); |
| 5607 | |
| 5608 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5609 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5610 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5611 | return false; |
| 5612 | } |
| 5613 | |
| 5614 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5615 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5616 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5617 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5618 | // situation is an application error that would lead to a crash in ANGLE. |
| 5619 | if (readBuffer == nullptr) |
| 5620 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5621 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5622 | return false; |
| 5623 | } |
| 5624 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5625 | // ANGLE_multiview, Revision 1: |
| 5626 | // 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] | 5627 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5628 | // in the current read framebuffer is more than one. |
| 5629 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5630 | { |
| 5631 | context->handleError(InvalidFramebufferOperation() |
| 5632 | << "Attempting to read from a multi-view framebuffer."); |
| 5633 | return false; |
| 5634 | } |
| 5635 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5636 | if (context->getExtensions().webglCompatibility) |
| 5637 | { |
| 5638 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5639 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5640 | // and type before validating the combination of format and type. However, the |
| 5641 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5642 | // verifies that GL_INVALID_OPERATION is generated. |
| 5643 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5644 | // dEQP/WebGL. |
| 5645 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5646 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5647 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5648 | return false; |
| 5649 | } |
| 5650 | |
| 5651 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5652 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5653 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5654 | return false; |
| 5655 | } |
| 5656 | } |
| 5657 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5658 | GLenum currentFormat = GL_NONE; |
| 5659 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5660 | |
| 5661 | GLenum currentType = GL_NONE; |
| 5662 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5663 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5664 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5665 | |
| 5666 | bool validFormatTypeCombination = |
| 5667 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5668 | |
| 5669 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5670 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5671 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | |
| 5675 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5676 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5677 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5678 | { |
| 5679 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5680 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5681 | return false; |
| 5682 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5683 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5684 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5685 | { |
| 5686 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5687 | return false; |
| 5688 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5689 | |
| 5690 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5691 | // would exceed the data store size. |
| 5692 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5693 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5694 | const auto &pack = context->getGLState().getPackState(); |
| 5695 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5696 | GLuint endByte = 0; |
| 5697 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5698 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5699 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5700 | return false; |
| 5701 | } |
| 5702 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5703 | if (bufSize >= 0) |
| 5704 | { |
| 5705 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5706 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5707 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5708 | return false; |
| 5709 | } |
| 5710 | } |
| 5711 | |
| 5712 | if (pixelPackBuffer != nullptr) |
| 5713 | { |
| 5714 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5715 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5716 | checkedEndByte += checkedOffset; |
| 5717 | |
| 5718 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5719 | { |
| 5720 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5721 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5722 | return false; |
| 5723 | } |
| 5724 | } |
| 5725 | |
| 5726 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5727 | { |
| 5728 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5729 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5730 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5731 | return false; |
| 5732 | } |
| 5733 | |
| 5734 | *length = static_cast<GLsizei>(endByte); |
| 5735 | } |
| 5736 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5737 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5738 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5739 | if (start < 0) |
| 5740 | { |
| 5741 | // "subtract" the area that is less than 0 |
| 5742 | clippedExtent += start; |
| 5743 | } |
| 5744 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5745 | angle::CheckedNumeric<int> readExtent = start; |
| 5746 | readExtent += length; |
| 5747 | if (!readExtent.IsValid()) |
| 5748 | { |
| 5749 | return false; |
| 5750 | } |
| 5751 | |
| 5752 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5753 | { |
| 5754 | // Subtract the region to the right of the read buffer |
| 5755 | clippedExtent -= (readExtent - bufferSize); |
| 5756 | } |
| 5757 | |
| 5758 | if (!clippedExtent.IsValid()) |
| 5759 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5760 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5761 | } |
| 5762 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5763 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5764 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5765 | }; |
| 5766 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5767 | GLsizei writtenColumns = 0; |
| 5768 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5769 | { |
| 5770 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5771 | return false; |
| 5772 | } |
| 5773 | |
| 5774 | GLsizei writtenRows = 0; |
| 5775 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5776 | { |
| 5777 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5778 | return false; |
| 5779 | } |
| 5780 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5781 | if (columns != nullptr) |
| 5782 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5783 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5784 | } |
| 5785 | |
| 5786 | if (rows != nullptr) |
| 5787 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5788 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | return true; |
| 5792 | } |
| 5793 | |
| 5794 | template <typename ParamType> |
| 5795 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5796 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5797 | GLenum pname, |
| 5798 | GLsizei bufSize, |
| 5799 | const ParamType *params) |
| 5800 | { |
| 5801 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5802 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5803 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5804 | return false; |
| 5805 | } |
| 5806 | |
| 5807 | if (context->getTargetTexture(target) == nullptr) |
| 5808 | { |
| 5809 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5810 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5811 | return false; |
| 5812 | } |
| 5813 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5814 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5815 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5816 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5817 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5818 | return false; |
| 5819 | } |
| 5820 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5821 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5822 | { |
| 5823 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5824 | return false; |
| 5825 | } |
| 5826 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5827 | switch (pname) |
| 5828 | { |
| 5829 | case GL_TEXTURE_WRAP_R: |
| 5830 | case GL_TEXTURE_SWIZZLE_R: |
| 5831 | case GL_TEXTURE_SWIZZLE_G: |
| 5832 | case GL_TEXTURE_SWIZZLE_B: |
| 5833 | case GL_TEXTURE_SWIZZLE_A: |
| 5834 | case GL_TEXTURE_BASE_LEVEL: |
| 5835 | case GL_TEXTURE_MAX_LEVEL: |
| 5836 | case GL_TEXTURE_COMPARE_MODE: |
| 5837 | case GL_TEXTURE_COMPARE_FUNC: |
| 5838 | case GL_TEXTURE_MIN_LOD: |
| 5839 | case GL_TEXTURE_MAX_LOD: |
| 5840 | if (context->getClientMajorVersion() < 3) |
| 5841 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5842 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5843 | return false; |
| 5844 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5845 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5846 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5847 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5848 | "available without " |
| 5849 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5850 | return false; |
| 5851 | } |
| 5852 | break; |
| 5853 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5854 | case GL_GENERATE_MIPMAP: |
| 5855 | case GL_TEXTURE_CROP_RECT_OES: |
| 5856 | if (context->getClientMajorVersion() > 1) |
| 5857 | { |
| 5858 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5859 | return false; |
| 5860 | } |
| 5861 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5862 | default: |
| 5863 | break; |
| 5864 | } |
| 5865 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5866 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5867 | { |
| 5868 | switch (pname) |
| 5869 | { |
| 5870 | case GL_TEXTURE_MIN_FILTER: |
| 5871 | case GL_TEXTURE_MAG_FILTER: |
| 5872 | case GL_TEXTURE_WRAP_S: |
| 5873 | case GL_TEXTURE_WRAP_T: |
| 5874 | case GL_TEXTURE_WRAP_R: |
| 5875 | case GL_TEXTURE_MIN_LOD: |
| 5876 | case GL_TEXTURE_MAX_LOD: |
| 5877 | case GL_TEXTURE_COMPARE_MODE: |
| 5878 | case GL_TEXTURE_COMPARE_FUNC: |
| 5879 | context->handleError(InvalidEnum() |
| 5880 | << "Invalid parameter for 2D multisampled textures."); |
| 5881 | return false; |
| 5882 | } |
| 5883 | } |
| 5884 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5885 | switch (pname) |
| 5886 | { |
| 5887 | case GL_TEXTURE_WRAP_S: |
| 5888 | case GL_TEXTURE_WRAP_T: |
| 5889 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5890 | { |
| 5891 | bool restrictedWrapModes = |
| 5892 | target == TextureType::External || target == TextureType::Rectangle; |
| 5893 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5894 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5895 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5896 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5897 | } |
| 5898 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5899 | |
| 5900 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5901 | { |
| 5902 | bool restrictedMinFilter = |
| 5903 | target == TextureType::External || target == TextureType::Rectangle; |
| 5904 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5905 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5906 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5907 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5908 | } |
| 5909 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5910 | |
| 5911 | case GL_TEXTURE_MAG_FILTER: |
| 5912 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5913 | { |
| 5914 | return false; |
| 5915 | } |
| 5916 | break; |
| 5917 | |
| 5918 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5919 | if (!context->getExtensions().textureUsage) |
| 5920 | { |
| 5921 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5922 | return false; |
| 5923 | } |
| 5924 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5925 | switch (ConvertToGLenum(params[0])) |
| 5926 | { |
| 5927 | case GL_NONE: |
| 5928 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5929 | break; |
| 5930 | |
| 5931 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5932 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | break; |
| 5936 | |
| 5937 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5938 | { |
| 5939 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5940 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5941 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5942 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5943 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5944 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 5945 | } |
| 5946 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5947 | |
| 5948 | case GL_TEXTURE_MIN_LOD: |
| 5949 | case GL_TEXTURE_MAX_LOD: |
| 5950 | // any value is permissible |
| 5951 | break; |
| 5952 | |
| 5953 | case GL_TEXTURE_COMPARE_MODE: |
| 5954 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5955 | { |
| 5956 | return false; |
| 5957 | } |
| 5958 | break; |
| 5959 | |
| 5960 | case GL_TEXTURE_COMPARE_FUNC: |
| 5961 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5962 | { |
| 5963 | return false; |
| 5964 | } |
| 5965 | break; |
| 5966 | |
| 5967 | case GL_TEXTURE_SWIZZLE_R: |
| 5968 | case GL_TEXTURE_SWIZZLE_G: |
| 5969 | case GL_TEXTURE_SWIZZLE_B: |
| 5970 | case GL_TEXTURE_SWIZZLE_A: |
| 5971 | switch (ConvertToGLenum(params[0])) |
| 5972 | { |
| 5973 | case GL_RED: |
| 5974 | case GL_GREEN: |
| 5975 | case GL_BLUE: |
| 5976 | case GL_ALPHA: |
| 5977 | case GL_ZERO: |
| 5978 | case GL_ONE: |
| 5979 | break; |
| 5980 | |
| 5981 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5982 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5983 | return false; |
| 5984 | } |
| 5985 | break; |
| 5986 | |
| 5987 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5988 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5989 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5990 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5991 | return false; |
| 5992 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5993 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5994 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5995 | context->handleError(InvalidOperation() |
| 5996 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5997 | return false; |
| 5998 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5999 | if ((target == TextureType::_2DMultisample || |
| 6000 | target == TextureType::_2DMultisampleArray) && |
| 6001 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6002 | { |
| 6003 | context->handleError(InvalidOperation() |
| 6004 | << "Base level must be 0 for multisampled textures."); |
| 6005 | return false; |
| 6006 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6007 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6008 | { |
| 6009 | context->handleError(InvalidOperation() |
| 6010 | << "Base level must be 0 for rectangle textures."); |
| 6011 | return false; |
| 6012 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6013 | break; |
| 6014 | |
| 6015 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6016 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6017 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6018 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6019 | return false; |
| 6020 | } |
| 6021 | break; |
| 6022 | |
| 6023 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6024 | if (context->getClientVersion() < Version(3, 1)) |
| 6025 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6026 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6027 | return false; |
| 6028 | } |
| 6029 | switch (ConvertToGLenum(params[0])) |
| 6030 | { |
| 6031 | case GL_DEPTH_COMPONENT: |
| 6032 | case GL_STENCIL_INDEX: |
| 6033 | break; |
| 6034 | |
| 6035 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6036 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6037 | return false; |
| 6038 | } |
| 6039 | break; |
| 6040 | |
| 6041 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6042 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6043 | { |
| 6044 | return false; |
| 6045 | } |
| 6046 | break; |
| 6047 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6048 | case GL_GENERATE_MIPMAP: |
| 6049 | case GL_TEXTURE_CROP_RECT_OES: |
| 6050 | if (context->getClientMajorVersion() > 1) |
| 6051 | { |
| 6052 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6053 | return false; |
| 6054 | } |
| 6055 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6056 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6057 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6058 | return false; |
| 6059 | } |
| 6060 | |
| 6061 | return true; |
| 6062 | } |
| 6063 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6064 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 6065 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6066 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6067 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6068 | { |
| 6069 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6070 | { |
| 6071 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6072 | return false; |
| 6073 | } |
| 6074 | |
| 6075 | return true; |
| 6076 | } |
| 6077 | |
| 6078 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6079 | GLuint program, |
| 6080 | GLuint uniformBlockIndex, |
| 6081 | GLenum pname, |
| 6082 | GLsizei *length) |
| 6083 | { |
| 6084 | if (length) |
| 6085 | { |
| 6086 | *length = 0; |
| 6087 | } |
| 6088 | |
| 6089 | if (context->getClientMajorVersion() < 3) |
| 6090 | { |
| 6091 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6092 | return false; |
| 6093 | } |
| 6094 | |
| 6095 | Program *programObject = GetValidProgram(context, program); |
| 6096 | if (!programObject) |
| 6097 | { |
| 6098 | return false; |
| 6099 | } |
| 6100 | |
| 6101 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6102 | { |
| 6103 | context->handleError(InvalidValue() |
| 6104 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6105 | return false; |
| 6106 | } |
| 6107 | |
| 6108 | switch (pname) |
| 6109 | { |
| 6110 | case GL_UNIFORM_BLOCK_BINDING: |
| 6111 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6112 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6113 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6114 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6115 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6116 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6117 | break; |
| 6118 | |
| 6119 | default: |
| 6120 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6121 | return false; |
| 6122 | } |
| 6123 | |
| 6124 | if (length) |
| 6125 | { |
| 6126 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6127 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6128 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6129 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6130 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6131 | } |
| 6132 | else |
| 6133 | { |
| 6134 | *length = 1; |
| 6135 | } |
| 6136 | } |
| 6137 | |
| 6138 | return true; |
| 6139 | } |
| 6140 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6141 | template <typename ParamType> |
| 6142 | bool ValidateSamplerParameterBase(Context *context, |
| 6143 | GLuint sampler, |
| 6144 | GLenum pname, |
| 6145 | GLsizei bufSize, |
| 6146 | ParamType *params) |
| 6147 | { |
| 6148 | if (context->getClientMajorVersion() < 3) |
| 6149 | { |
| 6150 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6151 | return false; |
| 6152 | } |
| 6153 | |
| 6154 | if (!context->isSampler(sampler)) |
| 6155 | { |
| 6156 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6157 | return false; |
| 6158 | } |
| 6159 | |
| 6160 | const GLsizei minBufSize = 1; |
| 6161 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6162 | { |
| 6163 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6164 | return false; |
| 6165 | } |
| 6166 | |
| 6167 | switch (pname) |
| 6168 | { |
| 6169 | case GL_TEXTURE_WRAP_S: |
| 6170 | case GL_TEXTURE_WRAP_T: |
| 6171 | case GL_TEXTURE_WRAP_R: |
| 6172 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6173 | { |
| 6174 | return false; |
| 6175 | } |
| 6176 | break; |
| 6177 | |
| 6178 | case GL_TEXTURE_MIN_FILTER: |
| 6179 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6180 | { |
| 6181 | return false; |
| 6182 | } |
| 6183 | break; |
| 6184 | |
| 6185 | case GL_TEXTURE_MAG_FILTER: |
| 6186 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6187 | { |
| 6188 | return false; |
| 6189 | } |
| 6190 | break; |
| 6191 | |
| 6192 | case GL_TEXTURE_MIN_LOD: |
| 6193 | case GL_TEXTURE_MAX_LOD: |
| 6194 | // any value is permissible |
| 6195 | break; |
| 6196 | |
| 6197 | case GL_TEXTURE_COMPARE_MODE: |
| 6198 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6199 | { |
| 6200 | return false; |
| 6201 | } |
| 6202 | break; |
| 6203 | |
| 6204 | case GL_TEXTURE_COMPARE_FUNC: |
| 6205 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6206 | { |
| 6207 | return false; |
| 6208 | } |
| 6209 | break; |
| 6210 | |
| 6211 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6212 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6213 | { |
| 6214 | return false; |
| 6215 | } |
| 6216 | break; |
| 6217 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6218 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6219 | { |
| 6220 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6221 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6222 | { |
| 6223 | return false; |
| 6224 | } |
| 6225 | } |
| 6226 | break; |
| 6227 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6228 | default: |
| 6229 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6230 | return false; |
| 6231 | } |
| 6232 | |
| 6233 | return true; |
| 6234 | } |
| 6235 | |
| 6236 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 6237 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 6238 | |
| 6239 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6240 | GLuint sampler, |
| 6241 | GLenum pname, |
| 6242 | GLsizei *length) |
| 6243 | { |
| 6244 | if (length) |
| 6245 | { |
| 6246 | *length = 0; |
| 6247 | } |
| 6248 | |
| 6249 | if (context->getClientMajorVersion() < 3) |
| 6250 | { |
| 6251 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6252 | return false; |
| 6253 | } |
| 6254 | |
| 6255 | if (!context->isSampler(sampler)) |
| 6256 | { |
| 6257 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6258 | return false; |
| 6259 | } |
| 6260 | |
| 6261 | switch (pname) |
| 6262 | { |
| 6263 | case GL_TEXTURE_WRAP_S: |
| 6264 | case GL_TEXTURE_WRAP_T: |
| 6265 | case GL_TEXTURE_WRAP_R: |
| 6266 | case GL_TEXTURE_MIN_FILTER: |
| 6267 | case GL_TEXTURE_MAG_FILTER: |
| 6268 | case GL_TEXTURE_MIN_LOD: |
| 6269 | case GL_TEXTURE_MAX_LOD: |
| 6270 | case GL_TEXTURE_COMPARE_MODE: |
| 6271 | case GL_TEXTURE_COMPARE_FUNC: |
| 6272 | break; |
| 6273 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6274 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6275 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6276 | { |
| 6277 | return false; |
| 6278 | } |
| 6279 | break; |
| 6280 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6281 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6282 | if (!context->getExtensions().textureSRGBDecode) |
| 6283 | { |
| 6284 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6285 | return false; |
| 6286 | } |
| 6287 | break; |
| 6288 | |
| 6289 | default: |
| 6290 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6291 | return false; |
| 6292 | } |
| 6293 | |
| 6294 | if (length) |
| 6295 | { |
| 6296 | *length = 1; |
| 6297 | } |
| 6298 | return true; |
| 6299 | } |
| 6300 | |
| 6301 | bool ValidateGetInternalFormativBase(Context *context, |
| 6302 | GLenum target, |
| 6303 | GLenum internalformat, |
| 6304 | GLenum pname, |
| 6305 | GLsizei bufSize, |
| 6306 | GLsizei *numParams) |
| 6307 | { |
| 6308 | if (numParams) |
| 6309 | { |
| 6310 | *numParams = 0; |
| 6311 | } |
| 6312 | |
| 6313 | if (context->getClientMajorVersion() < 3) |
| 6314 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6315 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6316 | return false; |
| 6317 | } |
| 6318 | |
| 6319 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6320 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6321 | { |
| 6322 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6323 | return false; |
| 6324 | } |
| 6325 | |
| 6326 | switch (target) |
| 6327 | { |
| 6328 | case GL_RENDERBUFFER: |
| 6329 | break; |
| 6330 | |
| 6331 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 6332 | if (context->getClientVersion() < ES_3_1) |
| 6333 | { |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6334 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureTargetRequiresES31); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6335 | return false; |
| 6336 | } |
| 6337 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6338 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6339 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6340 | { |
| 6341 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), MultisampleArrayExtensionRequired); |
| 6342 | return false; |
| 6343 | } |
| 6344 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6345 | default: |
| 6346 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6347 | return false; |
| 6348 | } |
| 6349 | |
| 6350 | if (bufSize < 0) |
| 6351 | { |
| 6352 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6353 | return false; |
| 6354 | } |
| 6355 | |
| 6356 | GLsizei maxWriteParams = 0; |
| 6357 | switch (pname) |
| 6358 | { |
| 6359 | case GL_NUM_SAMPLE_COUNTS: |
| 6360 | maxWriteParams = 1; |
| 6361 | break; |
| 6362 | |
| 6363 | case GL_SAMPLES: |
| 6364 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6365 | break; |
| 6366 | |
| 6367 | default: |
| 6368 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6369 | return false; |
| 6370 | } |
| 6371 | |
| 6372 | if (numParams) |
| 6373 | { |
| 6374 | // glGetInternalFormativ will not overflow bufSize |
| 6375 | *numParams = std::min(bufSize, maxWriteParams); |
| 6376 | } |
| 6377 | |
| 6378 | return true; |
| 6379 | } |
| 6380 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6381 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6382 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6383 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6384 | { |
Olli Etuaho | f0e3c19 | 2018-08-15 13:37:21 +0300 | [diff] [blame] | 6385 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6386 | return false; |
| 6387 | } |
| 6388 | return true; |
| 6389 | } |
| 6390 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6391 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6392 | { |
| 6393 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6394 | { |
| 6395 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6396 | return false; |
| 6397 | } |
| 6398 | return true; |
| 6399 | } |
| 6400 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6401 | bool ValidateTexStorageMultisample(Context *context, |
| 6402 | TextureType target, |
| 6403 | GLsizei samples, |
| 6404 | GLint internalFormat, |
| 6405 | GLsizei width, |
| 6406 | GLsizei height) |
| 6407 | { |
| 6408 | const Caps &caps = context->getCaps(); |
| 6409 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6410 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6411 | { |
| 6412 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureWidthOrHeightOutOfRange); |
| 6413 | return false; |
| 6414 | } |
| 6415 | |
| 6416 | if (samples == 0) |
| 6417 | { |
| 6418 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SamplesZero); |
| 6419 | return false; |
| 6420 | } |
| 6421 | |
| 6422 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6423 | if (!formatCaps.textureAttachment) |
| 6424 | { |
| 6425 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), RenderableInternalFormat); |
| 6426 | return false; |
| 6427 | } |
| 6428 | |
| 6429 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6430 | // is one of the unsized base internalformats listed in table 8.11. |
| 6431 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6432 | if (formatInfo.internalFormat == GL_NONE) |
| 6433 | { |
| 6434 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnsizedInternalFormatUnsupported); |
| 6435 | return false; |
| 6436 | } |
| 6437 | |
| 6438 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6439 | { |
| 6440 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), SamplesOutOfRange); |
| 6441 | return false; |
| 6442 | } |
| 6443 | |
| 6444 | Texture *texture = context->getTargetTexture(target); |
| 6445 | if (!texture || texture->id() == 0) |
| 6446 | { |
| 6447 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ZeroBoundToTarget); |
| 6448 | return false; |
| 6449 | } |
| 6450 | |
| 6451 | if (texture->getImmutableFormat()) |
| 6452 | { |
| 6453 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ImmutableTextureBound); |
| 6454 | return false; |
| 6455 | } |
| 6456 | return true; |
| 6457 | } |
| 6458 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6459 | } // namespace gl |