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 | ac43aaa | 2018-07-31 11:22:13 -0400 | [diff] [blame] | 82 | bool ValidateDrawClientAttribs(Context *context) |
| 83 | { |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 84 | ASSERT(context->getStateCache().hasAnyEnabledClientAttrib()); |
Jamie Madill | ac43aaa | 2018-07-31 11:22:13 -0400 | [diff] [blame] | 85 | |
| 86 | const gl::State &state = context->getGLState(); |
| 87 | |
| 88 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 89 | { |
| 90 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 91 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 92 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 93 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
| 94 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBuffer); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 99 | { |
| 100 | // This is an application error that would normally result in a crash, but we catch it |
| 101 | // and return an error |
| 102 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBufferPointer); |
| 103 | return false; |
| 104 | } |
| 105 | |
| 106 | return true; |
| 107 | } |
| 108 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 109 | bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 110 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 111 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 112 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 113 | |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 114 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 115 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 116 | { |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 117 | return true; |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 118 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 119 | |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 120 | // An overflow can happen when adding the offset. Negative indicates overflow. |
| 121 | if (context->getStateCache().getNonInstancedVertexElementLimit() < 0 || |
| 122 | context->getStateCache().getInstancedVertexElementLimit() < 0) |
| 123 | { |
| 124 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 125 | return false; |
| 126 | } |
| 127 | |
| 128 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 129 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
| 130 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
| 131 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 132 | } |
| 133 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 134 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 135 | { |
| 136 | switch (type) |
| 137 | { |
| 138 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 139 | case GL_UNSIGNED_BYTE: |
| 140 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 141 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 142 | case GL_UNSIGNED_SHORT_5_6_5: |
| 143 | return context->getClientVersion() >= ES_2_0; |
| 144 | |
| 145 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 146 | case GL_BYTE: |
| 147 | case GL_INT: |
| 148 | case GL_SHORT: |
| 149 | case GL_UNSIGNED_INT: |
| 150 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 151 | case GL_UNSIGNED_INT_24_8: |
| 152 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 153 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 154 | case GL_UNSIGNED_SHORT: |
| 155 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 156 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 157 | return context->getClientVersion() >= ES_3_0; |
| 158 | |
| 159 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 160 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 161 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 162 | |
| 163 | case GL_HALF_FLOAT: |
| 164 | return context->getClientVersion() >= ES_3_0 || |
| 165 | context->getExtensions().textureHalfFloat; |
| 166 | |
| 167 | case GL_HALF_FLOAT_OES: |
| 168 | return context->getExtensions().colorBufferHalfFloat; |
| 169 | |
| 170 | default: |
| 171 | return false; |
| 172 | } |
| 173 | } |
| 174 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 175 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 176 | { |
| 177 | switch (format) |
| 178 | { |
| 179 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 180 | case GL_RGBA: |
| 181 | case GL_RGB: |
| 182 | case GL_ALPHA: |
| 183 | return context->getClientVersion() >= ES_2_0; |
| 184 | |
| 185 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 186 | case GL_RG: |
| 187 | case GL_RED: |
| 188 | case GL_RGBA_INTEGER: |
| 189 | case GL_RGB_INTEGER: |
| 190 | case GL_RG_INTEGER: |
| 191 | case GL_RED_INTEGER: |
| 192 | return context->getClientVersion() >= ES_3_0; |
| 193 | |
| 194 | case GL_SRGB_ALPHA_EXT: |
| 195 | case GL_SRGB_EXT: |
| 196 | return context->getExtensions().sRGB; |
| 197 | |
| 198 | case GL_BGRA_EXT: |
| 199 | return context->getExtensions().readFormatBGRA; |
| 200 | |
| 201 | default: |
| 202 | return false; |
| 203 | } |
| 204 | } |
| 205 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 206 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 207 | GLenum framebufferComponentType, |
| 208 | GLenum format, |
| 209 | GLenum type) |
| 210 | { |
| 211 | switch (framebufferComponentType) |
| 212 | { |
| 213 | case GL_UNSIGNED_NORMALIZED: |
| 214 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 215 | // ReadPixels with BGRA even if the extension is not present |
| 216 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 217 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 218 | type == GL_UNSIGNED_BYTE); |
| 219 | |
| 220 | case GL_SIGNED_NORMALIZED: |
| 221 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 222 | |
| 223 | case GL_INT: |
| 224 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 225 | |
| 226 | case GL_UNSIGNED_INT: |
| 227 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 228 | |
| 229 | case GL_FLOAT: |
| 230 | return (format == GL_RGBA && type == GL_FLOAT); |
| 231 | |
| 232 | default: |
| 233 | UNREACHABLE(); |
| 234 | return false; |
| 235 | } |
| 236 | } |
| 237 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 238 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 239 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 240 | { |
| 241 | switch (ConvertToGLenum(params[0])) |
| 242 | { |
| 243 | case GL_CLAMP_TO_EDGE: |
| 244 | break; |
| 245 | |
| 246 | case GL_REPEAT: |
| 247 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 248 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 249 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 250 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 251 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 252 | return false; |
| 253 | } |
| 254 | break; |
| 255 | |
| 256 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 257 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 258 | return false; |
| 259 | } |
| 260 | |
| 261 | return true; |
| 262 | } |
| 263 | |
| 264 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 265 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 266 | { |
| 267 | switch (ConvertToGLenum(params[0])) |
| 268 | { |
| 269 | case GL_NEAREST: |
| 270 | case GL_LINEAR: |
| 271 | break; |
| 272 | |
| 273 | case GL_NEAREST_MIPMAP_NEAREST: |
| 274 | case GL_LINEAR_MIPMAP_NEAREST: |
| 275 | case GL_NEAREST_MIPMAP_LINEAR: |
| 276 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 277 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 278 | { |
| 279 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 280 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | break; |
| 284 | |
| 285 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 286 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 287 | return false; |
| 288 | } |
| 289 | |
| 290 | return true; |
| 291 | } |
| 292 | |
| 293 | template <typename ParamType> |
| 294 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 295 | { |
| 296 | switch (ConvertToGLenum(params[0])) |
| 297 | { |
| 298 | case GL_NEAREST: |
| 299 | case GL_LINEAR: |
| 300 | break; |
| 301 | |
| 302 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 303 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 304 | return false; |
| 305 | } |
| 306 | |
| 307 | return true; |
| 308 | } |
| 309 | |
| 310 | template <typename ParamType> |
| 311 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 312 | { |
| 313 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 314 | switch (ConvertToGLenum(params[0])) |
| 315 | { |
| 316 | case GL_NONE: |
| 317 | case GL_COMPARE_REF_TO_TEXTURE: |
| 318 | break; |
| 319 | |
| 320 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 321 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 322 | return false; |
| 323 | } |
| 324 | |
| 325 | return true; |
| 326 | } |
| 327 | |
| 328 | template <typename ParamType> |
| 329 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 330 | { |
| 331 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 332 | switch (ConvertToGLenum(params[0])) |
| 333 | { |
| 334 | case GL_LEQUAL: |
| 335 | case GL_GEQUAL: |
| 336 | case GL_LESS: |
| 337 | case GL_GREATER: |
| 338 | case GL_EQUAL: |
| 339 | case GL_NOTEQUAL: |
| 340 | case GL_ALWAYS: |
| 341 | case GL_NEVER: |
| 342 | break; |
| 343 | |
| 344 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 345 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 346 | return false; |
| 347 | } |
| 348 | |
| 349 | return true; |
| 350 | } |
| 351 | |
| 352 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 353 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 354 | { |
| 355 | if (!context->getExtensions().textureSRGBDecode) |
| 356 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 357 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 358 | return false; |
| 359 | } |
| 360 | |
| 361 | switch (ConvertToGLenum(params[0])) |
| 362 | { |
| 363 | case GL_DECODE_EXT: |
| 364 | case GL_SKIP_DECODE_EXT: |
| 365 | break; |
| 366 | |
| 367 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 368 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 369 | return false; |
| 370 | } |
| 371 | |
| 372 | return true; |
| 373 | } |
| 374 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 375 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 376 | { |
| 377 | if (!context->getExtensions().textureFilterAnisotropic) |
| 378 | { |
| 379 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 380 | return false; |
| 381 | } |
| 382 | |
| 383 | return true; |
| 384 | } |
| 385 | |
| 386 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 387 | { |
| 388 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 389 | { |
| 390 | return false; |
| 391 | } |
| 392 | |
| 393 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 394 | |
| 395 | if (paramValue < 1 || paramValue > largest) |
| 396 | { |
| 397 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 398 | return false; |
| 399 | } |
| 400 | |
| 401 | return true; |
| 402 | } |
| 403 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 404 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 405 | { |
| 406 | const Program *program = context->getGLState().getProgram(); |
| 407 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 408 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 409 | if (!ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 410 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 411 | program->getActiveOutputVariables().to_ulong(), |
| 412 | framebuffer->getDrawBufferMask().to_ulong())) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 413 | { |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 414 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DrawBufferTypeMismatch); |
| 415 | return false; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | return true; |
| 419 | } |
| 420 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 421 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 422 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 423 | const auto &glState = context->getGLState(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 424 | const Program *program = context->getGLState().getProgram(); |
| 425 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 426 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 427 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 428 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 429 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 430 | |
| 431 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 432 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 433 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 434 | |
| 435 | if (!ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), vaoAttribTypeBits, |
| 436 | program->getAttributesMask().to_ulong(), 0xFFFF)) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 437 | { |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 438 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexShaderTypeMismatch); |
| 439 | return false; |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 440 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 441 | return true; |
| 442 | } |
| 443 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 444 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 445 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 446 | { |
| 447 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 448 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 449 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 450 | case PrimitiveMode::Points: |
| 451 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 452 | case PrimitiveMode::Lines: |
| 453 | case PrimitiveMode::LineStrip: |
| 454 | case PrimitiveMode::LineLoop: |
| 455 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 456 | case PrimitiveMode::LinesAdjacency: |
| 457 | case PrimitiveMode::LineStripAdjacency: |
| 458 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 459 | case PrimitiveMode::Triangles: |
| 460 | case PrimitiveMode::TriangleFan: |
| 461 | case PrimitiveMode::TriangleStrip: |
| 462 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 463 | case PrimitiveMode::TrianglesAdjacency: |
| 464 | case PrimitiveMode::TriangleStripAdjacency: |
| 465 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 466 | default: |
| 467 | UNREACHABLE(); |
| 468 | return false; |
| 469 | } |
| 470 | } |
| 471 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 472 | // GLES1 texture parameters are a small subset of the others |
| 473 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 474 | { |
| 475 | switch (pname) |
| 476 | { |
| 477 | case GL_TEXTURE_MAG_FILTER: |
| 478 | case GL_TEXTURE_MIN_FILTER: |
| 479 | case GL_TEXTURE_WRAP_S: |
| 480 | case GL_TEXTURE_WRAP_T: |
| 481 | case GL_TEXTURE_WRAP_R: |
| 482 | case GL_GENERATE_MIPMAP: |
| 483 | case GL_TEXTURE_CROP_RECT_OES: |
| 484 | return true; |
| 485 | default: |
| 486 | return false; |
| 487 | } |
| 488 | } |
| 489 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 490 | } // anonymous namespace |
| 491 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 492 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 493 | { |
| 494 | if (length) |
| 495 | { |
| 496 | *length = value; |
| 497 | } |
| 498 | } |
| 499 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 500 | bool IsETC2EACFormat(const GLenum format) |
| 501 | { |
| 502 | // ES 3.1, Table 8.19 |
| 503 | switch (format) |
| 504 | { |
| 505 | case GL_COMPRESSED_R11_EAC: |
| 506 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 507 | case GL_COMPRESSED_RG11_EAC: |
| 508 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 509 | case GL_COMPRESSED_RGB8_ETC2: |
| 510 | case GL_COMPRESSED_SRGB8_ETC2: |
| 511 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 512 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 513 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 514 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 515 | return true; |
| 516 | |
| 517 | default: |
| 518 | return false; |
| 519 | } |
| 520 | } |
| 521 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 522 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 523 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 524 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 525 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 526 | case TextureType::_2D: |
| 527 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 528 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 529 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 530 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 531 | return context->getExtensions().textureRectangle; |
| 532 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 533 | case TextureType::_3D: |
| 534 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 535 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 536 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 537 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 538 | return (context->getClientVersion() >= Version(3, 1)); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 539 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 540 | default: |
| 541 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 542 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 543 | } |
| 544 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 545 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 546 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 547 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 548 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 549 | case TextureType::_2D: |
| 550 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 551 | return true; |
| 552 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 553 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 554 | return context->getExtensions().textureRectangle; |
| 555 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 556 | default: |
| 557 | return false; |
| 558 | } |
| 559 | } |
| 560 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 561 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 562 | { |
| 563 | switch (target) |
| 564 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 565 | case TextureType::_3D: |
| 566 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 567 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 568 | |
| 569 | default: |
| 570 | return false; |
| 571 | } |
| 572 | } |
| 573 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 574 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 575 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 576 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 577 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 578 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 579 | (context->getExtensions().eglImageExternal || |
| 580 | context->getExtensions().eglStreamConsumerExternal); |
| 581 | } |
| 582 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 583 | // This function differs from ValidTextureTarget in that the target must be |
| 584 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 585 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 586 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 587 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 588 | { |
| 589 | switch (target) |
| 590 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 591 | case TextureTarget::_2D: |
| 592 | case TextureTarget::CubeMapNegativeX: |
| 593 | case TextureTarget::CubeMapNegativeY: |
| 594 | case TextureTarget::CubeMapNegativeZ: |
| 595 | case TextureTarget::CubeMapPositiveX: |
| 596 | case TextureTarget::CubeMapPositiveY: |
| 597 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 598 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 599 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 600 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 601 | default: |
| 602 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 603 | } |
| 604 | } |
| 605 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 606 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 607 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 608 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 609 | { |
| 610 | ASSERT(context); |
| 611 | |
| 612 | if (!context->getExtensions().geometryShader) |
| 613 | { |
| 614 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 615 | // that does not match the current transform feedback object's draw mode (if transform |
| 616 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 617 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 618 | } |
| 619 | |
| 620 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 621 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 622 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 623 | case PrimitiveMode::Points: |
| 624 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 625 | case PrimitiveMode::Lines: |
| 626 | case PrimitiveMode::LineStrip: |
| 627 | case PrimitiveMode::LineLoop: |
| 628 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 629 | case PrimitiveMode::Triangles: |
| 630 | case PrimitiveMode::TriangleFan: |
| 631 | case PrimitiveMode::TriangleStrip: |
| 632 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 633 | default: |
| 634 | UNREACHABLE(); |
| 635 | return false; |
| 636 | } |
| 637 | } |
| 638 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 639 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 640 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 641 | GLsizei count, |
| 642 | GLenum type, |
| 643 | const GLvoid *indices, |
| 644 | GLsizei primcount) |
| 645 | { |
| 646 | if (primcount < 0) |
| 647 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 648 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 649 | return false; |
| 650 | } |
| 651 | |
| 652 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 653 | { |
| 654 | return false; |
| 655 | } |
| 656 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 657 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 661 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | GLint first, |
| 663 | GLsizei count, |
| 664 | GLsizei primcount) |
| 665 | { |
| 666 | if (primcount < 0) |
| 667 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 668 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 669 | return false; |
| 670 | } |
| 671 | |
| 672 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 673 | { |
| 674 | return false; |
| 675 | } |
| 676 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 677 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 678 | } |
| 679 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 680 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 681 | { |
| 682 | // Verify there is at least one active attribute with a divisor of zero |
| 683 | const State &state = context->getGLState(); |
| 684 | |
| 685 | Program *program = state.getProgram(); |
| 686 | |
| 687 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 688 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 689 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 690 | { |
| 691 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 692 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 693 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | { |
| 695 | return true; |
| 696 | } |
| 697 | } |
| 698 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 699 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 700 | return false; |
| 701 | } |
| 702 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 703 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 704 | { |
| 705 | switch (target) |
| 706 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 707 | case TextureType::_3D: |
| 708 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 709 | return true; |
| 710 | default: |
| 711 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 712 | } |
| 713 | } |
| 714 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 715 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 716 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 717 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 718 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 719 | case TextureType::_2D: |
| 720 | case TextureType::_2DArray: |
| 721 | case TextureType::_2DMultisample: |
| 722 | case TextureType::CubeMap: |
| 723 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 724 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 725 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 726 | return context->getExtensions().textureRectangle; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 727 | default: |
| 728 | return false; |
| 729 | } |
| 730 | } |
| 731 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 732 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 733 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 734 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 735 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 736 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 737 | |
| 738 | switch (target) |
| 739 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 740 | case GL_FRAMEBUFFER: |
| 741 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 742 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 743 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 744 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 745 | return (context->getExtensions().framebufferBlit || |
| 746 | context->getClientMajorVersion() >= 3); |
| 747 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 748 | default: |
| 749 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 753 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 754 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 755 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 756 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 757 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 758 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 759 | case TextureType::_2D: |
| 760 | case TextureType::_2DArray: |
| 761 | case TextureType::_2DMultisample: |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 762 | maxDimension = caps.max2DTextureSize; |
| 763 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 764 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 765 | maxDimension = caps.maxCubeMapTextureSize; |
| 766 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 767 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 768 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 769 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 770 | maxDimension = caps.max3DTextureSize; |
| 771 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 772 | default: |
| 773 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 774 | } |
| 775 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 776 | return level <= gl::log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 779 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 780 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 781 | GLint level, |
| 782 | GLsizei width, |
| 783 | GLsizei height, |
| 784 | GLsizei depth, |
| 785 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 786 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 787 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 788 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 789 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 790 | return false; |
| 791 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 792 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 793 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 794 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 795 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 796 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 797 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 798 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 799 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 800 | return false; |
| 801 | } |
| 802 | |
| 803 | if (!ValidMipLevel(context, target, level)) |
| 804 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 805 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 806 | return false; |
| 807 | } |
| 808 | |
| 809 | return true; |
| 810 | } |
| 811 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 812 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 813 | { |
| 814 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 815 | (size % blockSize == 0); |
| 816 | } |
| 817 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 818 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 819 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 820 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 821 | GLsizei width, |
| 822 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 823 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 824 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 825 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 826 | { |
| 827 | return false; |
| 828 | } |
| 829 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 830 | if (width < 0 || height < 0) |
| 831 | { |
| 832 | return false; |
| 833 | } |
| 834 | |
| 835 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 836 | { |
| 837 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 838 | // block size for level 0 but WebGL disallows this. |
| 839 | bool smallerThanBlockSizeAllowed = |
| 840 | level > 0 || !context->getExtensions().webglCompatibility; |
| 841 | |
| 842 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 843 | smallerThanBlockSizeAllowed) || |
| 844 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 845 | smallerThanBlockSizeAllowed)) |
| 846 | { |
| 847 | return false; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | return true; |
| 852 | } |
| 853 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 854 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 855 | GLenum internalFormat, |
| 856 | GLint xoffset, |
| 857 | GLint yoffset, |
| 858 | GLsizei width, |
| 859 | GLsizei height, |
| 860 | size_t textureWidth, |
| 861 | size_t textureHeight) |
| 862 | { |
| 863 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
| 864 | if (!formatInfo.compressed) |
| 865 | { |
| 866 | return false; |
| 867 | } |
| 868 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 869 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 870 | { |
| 871 | return false; |
| 872 | } |
| 873 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 874 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 875 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 876 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 877 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 878 | { |
| 879 | return false; |
| 880 | } |
| 881 | |
| 882 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 883 | // size but fills the entire mip |
| 884 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 885 | static_cast<size_t>(width) == textureWidth && |
| 886 | static_cast<size_t>(height) == textureHeight; |
| 887 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 888 | (height % formatInfo.compressedBlockHeight) == 0; |
| 889 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 890 | { |
| 891 | return false; |
| 892 | } |
| 893 | } |
| 894 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 895 | return true; |
| 896 | } |
| 897 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 898 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 899 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 900 | GLsizei width, |
| 901 | GLsizei height, |
| 902 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 903 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 904 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 905 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 906 | GLsizei imageSize) |
| 907 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 908 | gl::Buffer *pixelUnpackBuffer = |
| 909 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 910 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 911 | { |
| 912 | // Checks are not required |
| 913 | return true; |
| 914 | } |
| 915 | |
| 916 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 917 | // would exceed the data store size. |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 918 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format, type); |
| 919 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 920 | const gl::Extents size(width, height, depth); |
| 921 | const auto &unpack = context->getGLState().getUnpackState(); |
| 922 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 923 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 924 | GLuint endByte = 0; |
| 925 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 926 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 927 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 928 | return false; |
| 929 | } |
| 930 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 931 | if (pixelUnpackBuffer) |
| 932 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 933 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 934 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 935 | checkedEndByte += checkedOffset; |
| 936 | |
| 937 | if (!checkedEndByte.IsValid() || |
| 938 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 939 | { |
| 940 | // Overflow past the end of the buffer |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 941 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 942 | return false; |
| 943 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 944 | if (context->getExtensions().webglCompatibility && |
| 945 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 946 | { |
| 947 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 948 | PixelUnpackBufferBoundForTransformFeedback); |
| 949 | return false; |
| 950 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 951 | } |
| 952 | else |
| 953 | { |
| 954 | ASSERT(imageSize >= 0); |
| 955 | if (pixels == nullptr && imageSize != 0) |
| 956 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 957 | context->handleError(InvalidOperation() |
| 958 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 959 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 960 | } |
| 961 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 962 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 963 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 964 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 965 | return false; |
| 966 | } |
| 967 | } |
| 968 | |
| 969 | return true; |
| 970 | } |
| 971 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 972 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 973 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 974 | switch (queryType) |
| 975 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 976 | case QueryType::AnySamples: |
| 977 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 978 | return context->getClientMajorVersion() >= 3 || |
| 979 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 980 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 981 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 982 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 983 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 984 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 985 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 986 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 987 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 988 | default: |
| 989 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 990 | } |
| 991 | } |
| 992 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 993 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 994 | GLenum type, |
| 995 | GLboolean normalized, |
| 996 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 997 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 998 | bool pureInteger) |
| 999 | { |
| 1000 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1001 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1002 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1003 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1004 | // parameter exceeds 255. |
| 1005 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1006 | if (stride > kMaxWebGLStride) |
| 1007 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1008 | context->handleError(InvalidValue() |
| 1009 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1010 | return false; |
| 1011 | } |
| 1012 | |
| 1013 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1014 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1015 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1016 | // or an INVALID_OPERATION error is generated. |
| 1017 | VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger); |
| 1018 | size_t typeSize = GetVertexFormatTypeSize(internalType); |
| 1019 | |
| 1020 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1021 | size_t sizeMask = (typeSize - 1); |
| 1022 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1023 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1024 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1025 | return false; |
| 1026 | } |
| 1027 | |
| 1028 | if ((stride & sizeMask) != 0) |
| 1029 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1030 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | return true; |
| 1035 | } |
| 1036 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1037 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1038 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1039 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1040 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1041 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1042 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1043 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1044 | Program *validProgram = context->getProgram(id); |
| 1045 | |
| 1046 | if (!validProgram) |
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 | if (context->getShader(id)) |
| 1049 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1050 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1051 | } |
| 1052 | else |
| 1053 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1054 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1055 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1056 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1057 | |
| 1058 | return validProgram; |
| 1059 | } |
| 1060 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1061 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1062 | { |
| 1063 | // See ValidProgram for spec details. |
| 1064 | |
| 1065 | Shader *validShader = context->getShader(id); |
| 1066 | |
| 1067 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1068 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1069 | if (context->getProgram(id)) |
| 1070 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1071 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1072 | } |
| 1073 | else |
| 1074 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1075 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1076 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1077 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1078 | |
| 1079 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1080 | } |
| 1081 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1082 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1083 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1084 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1085 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1086 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1087 | { |
| 1088 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1089 | return false; |
| 1090 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1091 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1092 | // Color attachment 0 is validated below because it is always valid |
| 1093 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1094 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1095 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1096 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1097 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | else |
| 1101 | { |
| 1102 | switch (attachment) |
| 1103 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1104 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1105 | case GL_DEPTH_ATTACHMENT: |
| 1106 | case GL_STENCIL_ATTACHMENT: |
| 1107 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1108 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1109 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1110 | if (!context->getExtensions().webglCompatibility && |
| 1111 | context->getClientMajorVersion() < 3) |
| 1112 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1113 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1114 | return false; |
| 1115 | } |
| 1116 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1117 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1118 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1119 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | return true; |
| 1125 | } |
| 1126 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1127 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1128 | GLenum target, |
| 1129 | GLsizei samples, |
| 1130 | GLenum internalformat, |
| 1131 | GLsizei width, |
| 1132 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1133 | { |
| 1134 | switch (target) |
| 1135 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1136 | case GL_RENDERBUFFER: |
| 1137 | break; |
| 1138 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1139 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1140 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | if (width < 0 || height < 0 || samples < 0) |
| 1144 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1145 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1146 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1149 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1150 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1151 | |
| 1152 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1153 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1154 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1155 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1156 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1160 | // 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] | 1161 | // only sized internal formats. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1162 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(convertedInternalFormat); |
| 1163 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1164 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1165 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1166 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1169 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1171 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1172 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1175 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | if (handle == 0) |
| 1177 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1178 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1179 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | return true; |
| 1183 | } |
| 1184 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1185 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, |
| 1186 | GLenum target, |
| 1187 | GLenum attachment, |
| 1188 | GLenum renderbuffertarget, |
| 1189 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1190 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1191 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1192 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1193 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1194 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1197 | gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1198 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1199 | ASSERT(framebuffer); |
| 1200 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1201 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1202 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1203 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1206 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1207 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1208 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1209 | } |
| 1210 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1211 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1212 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1213 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1214 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1215 | if (renderbuffer != 0) |
| 1216 | { |
| 1217 | if (!context->getRenderbuffer(renderbuffer)) |
| 1218 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1219 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1220 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1224 | return true; |
| 1225 | } |
| 1226 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1227 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1228 | GLint srcX0, |
| 1229 | GLint srcY0, |
| 1230 | GLint srcX1, |
| 1231 | GLint srcY1, |
| 1232 | GLint dstX0, |
| 1233 | GLint dstY0, |
| 1234 | GLint dstX1, |
| 1235 | GLint dstY1, |
| 1236 | GLbitfield mask, |
| 1237 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1238 | { |
| 1239 | switch (filter) |
| 1240 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1241 | case GL_NEAREST: |
| 1242 | break; |
| 1243 | case GL_LINEAR: |
| 1244 | break; |
| 1245 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1246 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1247 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1251 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1252 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1253 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1256 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1257 | // color buffer, leaving only nearest being unfiltered from above |
| 1258 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1259 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1260 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1261 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1264 | const auto &glState = context->getGLState(); |
| 1265 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1266 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1267 | |
| 1268 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1269 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1270 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1271 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1274 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1275 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1276 | return false; |
| 1277 | } |
| 1278 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1279 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1280 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1281 | return false; |
| 1282 | } |
| 1283 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1284 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1285 | { |
| 1286 | context->handleError(InvalidOperation()); |
| 1287 | return false; |
| 1288 | } |
| 1289 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1290 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1291 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1292 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1295 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1296 | // always run it in order to avoid triggering driver bugs. |
| 1297 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1298 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1299 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1300 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1301 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1302 | } |
| 1303 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1304 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1305 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1307 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1308 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1309 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1311 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1313 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1314 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1315 | for (size_t drawbufferIdx = 0; |
| 1316 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1317 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1318 | const FramebufferAttachment *attachment = |
| 1319 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1320 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1321 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1322 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1323 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1324 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1325 | // 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] | 1326 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1327 | // as well |
| 1328 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1329 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1330 | // Changes with EXT_color_buffer_float: |
| 1331 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1332 | GLenum readComponentType = readFormat.info->componentType; |
| 1333 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1334 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1335 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1336 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1337 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1338 | |
| 1339 | if (extensions.colorBufferFloat) |
| 1340 | { |
| 1341 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1342 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1343 | |
| 1344 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1345 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1346 | context->handleError(InvalidOperation() |
| 1347 | << "If the read buffer contains fixed-point or " |
| 1348 | "floating-point values, the draw buffer must " |
| 1349 | "as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1350 | return false; |
| 1351 | } |
| 1352 | } |
| 1353 | else if (readFixedPoint != drawFixedPoint) |
| 1354 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1355 | context->handleError(InvalidOperation() |
| 1356 | << "If the read buffer contains fixed-point values, " |
| 1357 | "the draw buffer must as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1358 | return false; |
| 1359 | } |
| 1360 | |
| 1361 | if (readComponentType == GL_UNSIGNED_INT && |
| 1362 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1363 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1364 | context->handleError(InvalidOperation()); |
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 | } |
| 1367 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1368 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1369 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1370 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1371 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1372 | } |
| 1373 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1374 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1375 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1376 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1377 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1378 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1379 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1380 | |
| 1381 | if (context->getExtensions().webglCompatibility && |
| 1382 | *readColorBuffer == *attachment) |
| 1383 | { |
| 1384 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1385 | InvalidOperation() |
| 1386 | << "Read and write color attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1387 | return false; |
| 1388 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1389 | } |
| 1390 | } |
| 1391 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1392 | if ((readFormat.info->componentType == GL_INT || |
| 1393 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1394 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1395 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1396 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1397 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1398 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1399 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1400 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1401 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1402 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1403 | // situation is an application error that would lead to a crash in ANGLE. |
| 1404 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1405 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1406 | context->handleError( |
| 1407 | InvalidOperation() |
| 1408 | << "Attempt to read from a missing color attachment of a complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1409 | return false; |
| 1410 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1411 | } |
| 1412 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1413 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1414 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1415 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1416 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1417 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1419 | const gl::FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1420 | readFramebuffer->getAttachment(context, attachments[i]); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1421 | const gl::FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1422 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1423 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1424 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1426 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1427 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1428 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1429 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1430 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1431 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1432 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1433 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1434 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1435 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1436 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1437 | |
| 1438 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1439 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1440 | context->handleError( |
| 1441 | InvalidOperation() |
| 1442 | << "Read and write depth stencil attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1443 | return false; |
| 1444 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1445 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1446 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1447 | else if (drawBuffer) |
| 1448 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1449 | context->handleError(InvalidOperation() << "Attempt to read from a missing " |
| 1450 | "depth/stencil attachment of a " |
| 1451 | "complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1457 | // ANGLE_multiview, Revision 1: |
| 1458 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1459 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1460 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1461 | // views in the current read framebuffer is more than one. |
| 1462 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1463 | { |
| 1464 | context->handleError(InvalidFramebufferOperation() |
| 1465 | << "Attempt to read from a multi-view framebuffer."); |
| 1466 | return false; |
| 1467 | } |
| 1468 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1469 | { |
| 1470 | context->handleError(InvalidFramebufferOperation() |
| 1471 | << "Attempt to write to a multi-view framebuffer."); |
| 1472 | return false; |
| 1473 | } |
| 1474 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1475 | return true; |
| 1476 | } |
| 1477 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1478 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1479 | GLint x, |
| 1480 | GLint y, |
| 1481 | GLsizei width, |
| 1482 | GLsizei height, |
| 1483 | GLenum format, |
| 1484 | GLenum type, |
| 1485 | GLsizei bufSize, |
| 1486 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1487 | GLsizei *columns, |
| 1488 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1489 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1490 | { |
| 1491 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1492 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
| 1495 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1496 | GLsizei writeLength = 0; |
| 1497 | GLsizei writeColumns = 0; |
| 1498 | GLsizei writeRows = 0; |
| 1499 | |
| 1500 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1501 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1502 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1503 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1504 | } |
| 1505 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1506 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1507 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1508 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1509 | } |
| 1510 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1511 | SetRobustLengthParam(length, writeLength); |
| 1512 | SetRobustLengthParam(columns, writeColumns); |
| 1513 | SetRobustLengthParam(rows, writeRows); |
| 1514 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1515 | return true; |
| 1516 | } |
| 1517 | |
| 1518 | bool ValidateReadnPixelsEXT(Context *context, |
| 1519 | GLint x, |
| 1520 | GLint y, |
| 1521 | GLsizei width, |
| 1522 | GLsizei height, |
| 1523 | GLenum format, |
| 1524 | GLenum type, |
| 1525 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1526 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1527 | { |
| 1528 | if (bufSize < 0) |
| 1529 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1530 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1531 | return false; |
| 1532 | } |
| 1533 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1534 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1535 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1536 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1537 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1538 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1539 | GLint x, |
| 1540 | GLint y, |
| 1541 | GLsizei width, |
| 1542 | GLsizei height, |
| 1543 | GLenum format, |
| 1544 | GLenum type, |
| 1545 | GLsizei bufSize, |
| 1546 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1547 | GLsizei *columns, |
| 1548 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1549 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1550 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1551 | GLsizei writeLength = 0; |
| 1552 | GLsizei writeColumns = 0; |
| 1553 | GLsizei writeRows = 0; |
| 1554 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1555 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1556 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1557 | return false; |
| 1558 | } |
| 1559 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1560 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1561 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1562 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1563 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1564 | } |
| 1565 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1566 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1567 | { |
| 1568 | return false; |
| 1569 | } |
| 1570 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1571 | SetRobustLengthParam(length, writeLength); |
| 1572 | SetRobustLengthParam(columns, writeColumns); |
| 1573 | SetRobustLengthParam(rows, writeRows); |
| 1574 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1575 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1576 | } |
| 1577 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1578 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1579 | { |
| 1580 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1581 | !context->getExtensions().disjointTimerQuery) |
| 1582 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1583 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1584 | return false; |
| 1585 | } |
| 1586 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1587 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1588 | } |
| 1589 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1590 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1591 | { |
| 1592 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1593 | !context->getExtensions().disjointTimerQuery) |
| 1594 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1595 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1596 | return false; |
| 1597 | } |
| 1598 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1599 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1600 | } |
| 1601 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1602 | bool ValidateIsQueryEXT(gl::Context *context, GLuint id) |
| 1603 | { |
| 1604 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1605 | !context->getExtensions().disjointTimerQuery) |
| 1606 | { |
| 1607 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1608 | return false; |
| 1609 | } |
| 1610 | |
| 1611 | return true; |
| 1612 | } |
| 1613 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1614 | bool ValidateBeginQueryBase(gl::Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1615 | { |
| 1616 | if (!ValidQueryType(context, target)) |
| 1617 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1618 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1619 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | if (id == 0) |
| 1623 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1624 | context->handleError(InvalidOperation() << "Query id is 0"); |
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 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1629 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1630 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1631 | // the active query for either target is non-zero), if <id> is the name of an |
| 1632 | // existing query object whose type does not match <target>, or if <id> is the |
| 1633 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1634 | // generated. |
| 1635 | |
| 1636 | // Ensure no other queries are active |
| 1637 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1638 | // separately that: |
| 1639 | // a) The query ID passed is not the current active query for any target/type |
| 1640 | // b) There are no active queries for the requested target (and in the case |
| 1641 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1642 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1643 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1644 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1645 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1646 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1647 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1648 | } |
| 1649 | |
| 1650 | Query *queryObject = context->getQuery(id, true, target); |
| 1651 | |
| 1652 | // check that name was obtained with glGenQueries |
| 1653 | if (!queryObject) |
| 1654 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1655 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1656 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1657 | } |
| 1658 | |
| 1659 | // check for type mismatch |
| 1660 | if (queryObject->getType() != target) |
| 1661 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1662 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1663 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | return true; |
| 1667 | } |
| 1668 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1669 | bool ValidateBeginQueryEXT(gl::Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1670 | { |
| 1671 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1672 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1673 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1674 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1675 | return false; |
| 1676 | } |
| 1677 | |
| 1678 | return ValidateBeginQueryBase(context, target, id); |
| 1679 | } |
| 1680 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1681 | bool ValidateEndQueryBase(gl::Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1682 | { |
| 1683 | if (!ValidQueryType(context, target)) |
| 1684 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1685 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1686 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1687 | } |
| 1688 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1689 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1690 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1691 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1692 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1693 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1694 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1695 | } |
| 1696 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1697 | return true; |
| 1698 | } |
| 1699 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1700 | bool ValidateEndQueryEXT(gl::Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1701 | { |
| 1702 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1703 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1704 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1705 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1706 | return false; |
| 1707 | } |
| 1708 | |
| 1709 | return ValidateEndQueryBase(context, target); |
| 1710 | } |
| 1711 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1712 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1713 | { |
| 1714 | if (!context->getExtensions().disjointTimerQuery) |
| 1715 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1716 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1717 | return false; |
| 1718 | } |
| 1719 | |
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 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1722 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
| 1725 | |
| 1726 | Query *queryObject = context->getQuery(id, true, target); |
| 1727 | if (queryObject == nullptr) |
| 1728 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1729 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
| 1732 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1733 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1734 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1735 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1736 | return false; |
| 1737 | } |
| 1738 | |
| 1739 | return true; |
| 1740 | } |
| 1741 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1742 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1743 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1744 | if (numParams) |
| 1745 | { |
| 1746 | *numParams = 0; |
| 1747 | } |
| 1748 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1749 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1750 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1751 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
| 1754 | |
| 1755 | switch (pname) |
| 1756 | { |
| 1757 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1758 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1759 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1760 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1761 | return false; |
| 1762 | } |
| 1763 | break; |
| 1764 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1765 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1766 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1767 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1768 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1769 | return false; |
| 1770 | } |
| 1771 | break; |
| 1772 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1773 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1774 | return false; |
| 1775 | } |
| 1776 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1777 | if (numParams) |
| 1778 | { |
| 1779 | // All queries return only one value |
| 1780 | *numParams = 1; |
| 1781 | } |
| 1782 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1783 | return true; |
| 1784 | } |
| 1785 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1786 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1787 | { |
| 1788 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1789 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1790 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1791 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1792 | return false; |
| 1793 | } |
| 1794 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1795 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1796 | } |
| 1797 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1798 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1799 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1800 | GLenum pname, |
| 1801 | GLsizei bufSize, |
| 1802 | GLsizei *length, |
| 1803 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1804 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1805 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1806 | { |
| 1807 | return false; |
| 1808 | } |
| 1809 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1810 | GLsizei numParams = 0; |
| 1811 | |
| 1812 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1813 | { |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1817 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1818 | { |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1822 | SetRobustLengthParam(length, numParams); |
| 1823 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1824 | return true; |
| 1825 | } |
| 1826 | |
| 1827 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1828 | { |
| 1829 | if (numParams) |
| 1830 | { |
| 1831 | *numParams = 0; |
| 1832 | } |
| 1833 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1834 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1835 | |
| 1836 | if (!queryObject) |
| 1837 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1838 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1839 | return false; |
| 1840 | } |
| 1841 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1842 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1843 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1844 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1845 | return false; |
| 1846 | } |
| 1847 | |
| 1848 | switch (pname) |
| 1849 | { |
| 1850 | case GL_QUERY_RESULT_EXT: |
| 1851 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1852 | break; |
| 1853 | |
| 1854 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1855 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1856 | return false; |
| 1857 | } |
| 1858 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1859 | if (numParams) |
| 1860 | { |
| 1861 | *numParams = 1; |
| 1862 | } |
| 1863 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1864 | return true; |
| 1865 | } |
| 1866 | |
| 1867 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1868 | { |
| 1869 | if (!context->getExtensions().disjointTimerQuery) |
| 1870 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1871 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1872 | return false; |
| 1873 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1874 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1875 | } |
| 1876 | |
| 1877 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1878 | GLuint id, |
| 1879 | GLenum pname, |
| 1880 | GLsizei bufSize, |
| 1881 | GLsizei *length, |
| 1882 | GLint *params) |
| 1883 | { |
| 1884 | if (!context->getExtensions().disjointTimerQuery) |
| 1885 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1886 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1887 | return false; |
| 1888 | } |
| 1889 | |
| 1890 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1891 | { |
| 1892 | return false; |
| 1893 | } |
| 1894 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1895 | GLsizei numParams = 0; |
| 1896 | |
| 1897 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1898 | { |
| 1899 | return false; |
| 1900 | } |
| 1901 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1902 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1903 | { |
| 1904 | return false; |
| 1905 | } |
| 1906 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1907 | SetRobustLengthParam(length, numParams); |
| 1908 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1909 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1910 | } |
| 1911 | |
| 1912 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1913 | { |
| 1914 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1915 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1916 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1917 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1918 | return false; |
| 1919 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1920 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1921 | } |
| 1922 | |
| 1923 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1924 | GLuint id, |
| 1925 | GLenum pname, |
| 1926 | GLsizei bufSize, |
| 1927 | GLsizei *length, |
| 1928 | GLuint *params) |
| 1929 | { |
| 1930 | if (!context->getExtensions().disjointTimerQuery && |
| 1931 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1932 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1933 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1934 | return false; |
| 1935 | } |
| 1936 | |
| 1937 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1938 | { |
| 1939 | return false; |
| 1940 | } |
| 1941 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1942 | GLsizei numParams = 0; |
| 1943 | |
| 1944 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1945 | { |
| 1946 | return false; |
| 1947 | } |
| 1948 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1949 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1950 | { |
| 1951 | return false; |
| 1952 | } |
| 1953 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1954 | SetRobustLengthParam(length, numParams); |
| 1955 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1956 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1960 | { |
| 1961 | if (!context->getExtensions().disjointTimerQuery) |
| 1962 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1963 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1964 | return false; |
| 1965 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1966 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1967 | } |
| 1968 | |
| 1969 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1970 | GLuint id, |
| 1971 | GLenum pname, |
| 1972 | GLsizei bufSize, |
| 1973 | GLsizei *length, |
| 1974 | GLint64 *params) |
| 1975 | { |
| 1976 | if (!context->getExtensions().disjointTimerQuery) |
| 1977 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1978 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1979 | return false; |
| 1980 | } |
| 1981 | |
| 1982 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1983 | { |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1987 | GLsizei numParams = 0; |
| 1988 | |
| 1989 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1990 | { |
| 1991 | return false; |
| 1992 | } |
| 1993 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1994 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1995 | { |
| 1996 | return false; |
| 1997 | } |
| 1998 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1999 | SetRobustLengthParam(length, numParams); |
| 2000 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2001 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2002 | } |
| 2003 | |
| 2004 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2005 | { |
| 2006 | if (!context->getExtensions().disjointTimerQuery) |
| 2007 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2008 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2009 | return false; |
| 2010 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2011 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2012 | } |
| 2013 | |
| 2014 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2015 | GLuint id, |
| 2016 | GLenum pname, |
| 2017 | GLsizei bufSize, |
| 2018 | GLsizei *length, |
| 2019 | GLuint64 *params) |
| 2020 | { |
| 2021 | if (!context->getExtensions().disjointTimerQuery) |
| 2022 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2023 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2024 | return false; |
| 2025 | } |
| 2026 | |
| 2027 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2028 | { |
| 2029 | return false; |
| 2030 | } |
| 2031 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2032 | GLsizei numParams = 0; |
| 2033 | |
| 2034 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2035 | { |
| 2036 | return false; |
| 2037 | } |
| 2038 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2039 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2040 | { |
| 2041 | return false; |
| 2042 | } |
| 2043 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2044 | SetRobustLengthParam(length, numParams); |
| 2045 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2046 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2047 | } |
| 2048 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2049 | bool ValidateUniformCommonBase(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2050 | gl::Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2051 | GLint location, |
| 2052 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2053 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2054 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2055 | // TODO(Jiajia): Add image uniform check in future. |
| 2056 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2057 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2058 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2059 | return false; |
| 2060 | } |
| 2061 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2062 | if (!program) |
| 2063 | { |
| 2064 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2065 | return false; |
| 2066 | } |
| 2067 | |
| 2068 | if (!program->isLinked()) |
| 2069 | { |
| 2070 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2071 | return false; |
| 2072 | } |
| 2073 | |
| 2074 | if (location == -1) |
| 2075 | { |
| 2076 | // Silently ignore the uniform command |
| 2077 | return false; |
| 2078 | } |
| 2079 | |
| 2080 | const auto &uniformLocations = program->getUniformLocations(); |
| 2081 | size_t castedLocation = static_cast<size_t>(location); |
| 2082 | if (castedLocation >= uniformLocations.size()) |
| 2083 | { |
| 2084 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2085 | return false; |
| 2086 | } |
| 2087 | |
| 2088 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2089 | if (uniformLocation.ignored) |
| 2090 | { |
| 2091 | // Silently ignore the uniform command |
| 2092 | return false; |
| 2093 | } |
| 2094 | |
| 2095 | if (!uniformLocation.used()) |
| 2096 | { |
| 2097 | context->handleError(InvalidOperation()); |
| 2098 | return false; |
| 2099 | } |
| 2100 | |
| 2101 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2102 | |
| 2103 | // 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] | 2104 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2105 | { |
| 2106 | context->handleError(InvalidOperation()); |
| 2107 | return false; |
| 2108 | } |
| 2109 | |
| 2110 | *uniformOut = &uniform; |
| 2111 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2112 | } |
| 2113 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2114 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2115 | GLenum uniformType, |
| 2116 | GLsizei count, |
| 2117 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2118 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2119 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2120 | // It is compatible with INT or BOOL. |
| 2121 | // Do these cheap tests first, for a little extra speed. |
| 2122 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2123 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2124 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2125 | } |
| 2126 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2127 | if (IsSamplerType(uniformType)) |
| 2128 | { |
| 2129 | // Check that the values are in range. |
| 2130 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2131 | for (GLsizei i = 0; i < count; ++i) |
| 2132 | { |
| 2133 | if (value[i] < 0 || value[i] >= max) |
| 2134 | { |
| 2135 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2136 | return false; |
| 2137 | } |
| 2138 | } |
| 2139 | return true; |
| 2140 | } |
| 2141 | |
| 2142 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2143 | return false; |
| 2144 | } |
| 2145 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2146 | bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2147 | { |
| 2148 | // Check that the value type is compatible with uniform type. |
| 2149 | // Do the cheaper test first, for a little extra speed. |
| 2150 | if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType) |
| 2151 | { |
| 2152 | return true; |
| 2153 | } |
| 2154 | |
| 2155 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch); |
| 2156 | return false; |
| 2157 | } |
| 2158 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2159 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2160 | { |
| 2161 | // Check that the value type is compatible with uniform type. |
| 2162 | if (valueType == uniformType) |
| 2163 | { |
| 2164 | return true; |
| 2165 | } |
| 2166 | |
| 2167 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2168 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2169 | } |
| 2170 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2171 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2172 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2173 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2174 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2175 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2176 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2177 | } |
| 2178 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2179 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2180 | { |
| 2181 | const LinkedUniform *uniform = nullptr; |
| 2182 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2183 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2184 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2185 | } |
| 2186 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2187 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2188 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2189 | GLint location, |
| 2190 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2191 | GLboolean transpose) |
| 2192 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2193 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2194 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2195 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2196 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2197 | } |
| 2198 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2199 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2200 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2201 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2202 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2203 | } |
| 2204 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2205 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2206 | { |
| 2207 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2208 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2209 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2210 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2211 | } |
| 2212 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2213 | const Caps &caps = context->getCaps(); |
| 2214 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2215 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2216 | { |
| 2217 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2218 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2219 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2220 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2221 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2222 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2223 | } |
| 2224 | } |
| 2225 | |
| 2226 | switch (pname) |
| 2227 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2228 | case GL_TEXTURE_BINDING_2D: |
| 2229 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2230 | case GL_TEXTURE_BINDING_3D: |
| 2231 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2232 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2233 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2234 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2235 | if (!context->getExtensions().textureRectangle) |
| 2236 | { |
| 2237 | context->handleError(InvalidEnum() |
| 2238 | << "ANGLE_texture_rectangle extension not present"); |
| 2239 | return false; |
| 2240 | } |
| 2241 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2242 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2243 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2244 | !context->getExtensions().eglImageExternal) |
| 2245 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2246 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2247 | "nor GL_OES_EGL_image_external " |
| 2248 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2249 | return false; |
| 2250 | } |
| 2251 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2252 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2253 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2254 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2255 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2256 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2257 | ASSERT(readFramebuffer); |
| 2258 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2259 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2260 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2261 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2262 | } |
| 2263 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2264 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2265 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2266 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2267 | return false; |
| 2268 | } |
| 2269 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2270 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2271 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2272 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2273 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2274 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | break; |
| 2278 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2279 | default: |
| 2280 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2284 | if (*numParams == 0) |
| 2285 | { |
| 2286 | return false; |
| 2287 | } |
| 2288 | |
| 2289 | return true; |
| 2290 | } |
| 2291 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2292 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2293 | GLenum pname, |
| 2294 | GLsizei bufSize, |
| 2295 | GLsizei *length, |
| 2296 | GLboolean *params) |
| 2297 | { |
| 2298 | GLenum nativeType; |
| 2299 | unsigned int numParams = 0; |
| 2300 | |
| 2301 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2302 | { |
| 2303 | return false; |
| 2304 | } |
| 2305 | |
| 2306 | SetRobustLengthParam(length, numParams); |
| 2307 | |
| 2308 | return true; |
| 2309 | } |
| 2310 | |
| 2311 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2312 | GLenum pname, |
| 2313 | GLsizei bufSize, |
| 2314 | GLsizei *length, |
| 2315 | GLfloat *params) |
| 2316 | { |
| 2317 | GLenum nativeType; |
| 2318 | unsigned int numParams = 0; |
| 2319 | |
| 2320 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2321 | { |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | SetRobustLengthParam(length, numParams); |
| 2326 | |
| 2327 | return true; |
| 2328 | } |
| 2329 | |
| 2330 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2331 | GLenum pname, |
| 2332 | GLsizei bufSize, |
| 2333 | GLsizei *length, |
| 2334 | GLint *data) |
| 2335 | { |
| 2336 | GLenum nativeType; |
| 2337 | unsigned int numParams = 0; |
| 2338 | |
| 2339 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2340 | { |
| 2341 | return false; |
| 2342 | } |
| 2343 | |
| 2344 | SetRobustLengthParam(length, numParams); |
| 2345 | |
| 2346 | return true; |
| 2347 | } |
| 2348 | |
| 2349 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2350 | GLenum pname, |
| 2351 | GLsizei bufSize, |
| 2352 | GLsizei *length, |
| 2353 | GLint64 *data) |
| 2354 | { |
| 2355 | GLenum nativeType; |
| 2356 | unsigned int numParams = 0; |
| 2357 | |
| 2358 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2359 | { |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| 2363 | if (nativeType == GL_INT_64_ANGLEX) |
| 2364 | { |
| 2365 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2366 | return false; |
| 2367 | } |
| 2368 | |
| 2369 | SetRobustLengthParam(length, numParams); |
| 2370 | return true; |
| 2371 | } |
| 2372 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2373 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2374 | GLenum pname, |
| 2375 | GLsizei bufSize, |
| 2376 | GLenum *nativeType, |
| 2377 | unsigned int *numParams) |
| 2378 | { |
| 2379 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2380 | { |
| 2381 | return false; |
| 2382 | } |
| 2383 | |
| 2384 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2385 | { |
| 2386 | return false; |
| 2387 | } |
| 2388 | |
| 2389 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2390 | { |
| 2391 | return false; |
| 2392 | } |
| 2393 | |
| 2394 | return true; |
| 2395 | } |
| 2396 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2397 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2398 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2399 | GLint level, |
| 2400 | GLenum internalformat, |
| 2401 | bool isSubImage, |
| 2402 | GLint xoffset, |
| 2403 | GLint yoffset, |
| 2404 | GLint zoffset, |
| 2405 | GLint x, |
| 2406 | GLint y, |
| 2407 | GLsizei width, |
| 2408 | GLsizei height, |
| 2409 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2410 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2411 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2412 | TextureType texType = TextureTargetToType(target); |
| 2413 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2414 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2415 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2416 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2417 | return false; |
| 2418 | } |
| 2419 | |
| 2420 | if (width < 0 || height < 0) |
| 2421 | { |
| 2422 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
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 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2426 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2427 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2428 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2429 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2430 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | if (border != 0) |
| 2434 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2435 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2436 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2437 | } |
| 2438 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2439 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2440 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2441 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2442 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2443 | } |
| 2444 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2445 | const gl::State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2446 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2447 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2448 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2449 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2450 | } |
| 2451 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2452 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2453 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2454 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2455 | } |
| 2456 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2457 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2458 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2459 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2460 | return false; |
| 2461 | } |
| 2462 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2463 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2464 | // 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] | 2465 | // 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] | 2466 | // 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] | 2467 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2468 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2469 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2470 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2471 | return false; |
| 2472 | } |
| 2473 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2474 | // ANGLE_multiview spec, Revision 1: |
| 2475 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2476 | // 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] | 2477 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2478 | // framebuffer is more than one. |
| 2479 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2480 | { |
| 2481 | context->handleError(InvalidFramebufferOperation() |
| 2482 | << "The active read framebuffer object has multiview attachments."); |
| 2483 | return false; |
| 2484 | } |
| 2485 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2486 | const gl::Caps &caps = context->getCaps(); |
| 2487 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2488 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2489 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2490 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2491 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2492 | maxDimension = caps.max2DTextureSize; |
| 2493 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2494 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2495 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2496 | maxDimension = caps.maxCubeMapTextureSize; |
| 2497 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2498 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2499 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2500 | maxDimension = caps.maxRectangleTextureSize; |
| 2501 | break; |
| 2502 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2503 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2504 | maxDimension = caps.max2DTextureSize; |
| 2505 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2506 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2507 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2508 | maxDimension = caps.max3DTextureSize; |
| 2509 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2510 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2511 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2512 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2513 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2516 | gl::Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2517 | if (!texture) |
| 2518 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2519 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2520 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2521 | } |
| 2522 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2523 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2524 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2525 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2526 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2527 | } |
| 2528 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2529 | const gl::InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2530 | isSubImage ? *texture->getFormat(target, level).info |
| 2531 | : gl::GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2532 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2533 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2534 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2535 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2536 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | if (isSubImage) |
| 2540 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2541 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2542 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2543 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2544 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2545 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2546 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2547 | } |
| 2548 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2549 | else |
| 2550 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2551 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2552 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2553 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2554 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2557 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2558 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2559 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2560 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2561 | } |
| 2562 | |
| 2563 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2564 | if (static_cast<int>(width) > maxLevelDimension || |
| 2565 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2566 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2567 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2568 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2569 | } |
| 2570 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2571 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2572 | if (textureFormatOut) |
| 2573 | { |
| 2574 | *textureFormatOut = texture->getFormat(target, level); |
| 2575 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2576 | |
| 2577 | // Detect texture copying feedback loops for WebGL. |
| 2578 | if (context->getExtensions().webglCompatibility) |
| 2579 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2580 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2581 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2582 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2583 | return false; |
| 2584 | } |
| 2585 | } |
| 2586 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2587 | return true; |
| 2588 | } |
| 2589 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2590 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2591 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2592 | const Extensions &extensions = context->getExtensions(); |
| 2593 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2594 | switch (mode) |
| 2595 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2596 | case PrimitiveMode::Points: |
| 2597 | case PrimitiveMode::Lines: |
| 2598 | case PrimitiveMode::LineLoop: |
| 2599 | case PrimitiveMode::LineStrip: |
| 2600 | case PrimitiveMode::Triangles: |
| 2601 | case PrimitiveMode::TriangleStrip: |
| 2602 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2603 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2604 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2605 | case PrimitiveMode::LinesAdjacency: |
| 2606 | case PrimitiveMode::LineStripAdjacency: |
| 2607 | case PrimitiveMode::TrianglesAdjacency: |
| 2608 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2609 | if (!extensions.geometryShader) |
| 2610 | { |
| 2611 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2612 | return false; |
| 2613 | } |
| 2614 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2615 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2616 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2617 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2618 | } |
| 2619 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2620 | if (count < 0) |
| 2621 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2622 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2623 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2624 | } |
| 2625 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2626 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2627 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2628 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2629 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2630 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 2631 | if (!extensions.webglCompatibility && state.getVertexArray()->hasMappedEnabledArrayBuffer()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2632 | { |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 2633 | context->handleError(InvalidOperation()); |
| 2634 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2635 | } |
| 2636 | |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2637 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2638 | // Section 6.10 of the WebGL 1.0 spec. |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2639 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2640 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2641 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2642 | ASSERT(framebuffer); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 2643 | const FramebufferAttachment *dsAttachment = |
| 2644 | framebuffer->getStencilOrDepthStencilAttachment(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2645 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2646 | ASSERT(stencilBits <= 8); |
| 2647 | |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 2648 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2649 | if (depthStencilState.stencilTest && stencilBits > 0) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2650 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2651 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2652 | |
| 2653 | bool differentRefs = |
| 2654 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2655 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2656 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2657 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2658 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2659 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2660 | |
| 2661 | if (differentRefs || differentWritemasks || differentMasks) |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2662 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2663 | if (!extensions.webglCompatibility) |
| 2664 | { |
Jamie Madill | a2f043d | 2018-07-10 17:21:20 -0400 | [diff] [blame] | 2665 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2666 | "stencil writemasks, reference values, or stencil mask values."; |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2667 | } |
| 2668 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StencilReferenceMaskOrMismatch); |
| 2669 | return false; |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2670 | } |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2671 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2672 | } |
| 2673 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2674 | if (!ValidateFramebufferComplete(context, framebuffer)) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2675 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2676 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2677 | } |
| 2678 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2679 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2680 | { |
| 2681 | if (!ValidateDrawClientAttribs(context)) |
| 2682 | { |
| 2683 | return false; |
| 2684 | } |
| 2685 | } |
| 2686 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2687 | // If we are running GLES1, there is no current program. |
| 2688 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2689 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2690 | gl::Program *program = state.getProgram(); |
| 2691 | if (!program) |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2692 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2693 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2694 | return false; |
| 2695 | } |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2696 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2697 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2698 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2699 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2700 | // produce undefined result. |
| 2701 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2702 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2703 | { |
| 2704 | context->handleError(InvalidOperation() |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2705 | << "It is a undefined behaviour to render without " |
| 2706 | "vertex shader stage or fragment shader stage."); |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2707 | return false; |
| 2708 | } |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2709 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2710 | if (!program->validateSamplers(nullptr, context->getCaps())) |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2711 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2712 | context->handleError(InvalidOperation()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2713 | return false; |
| 2714 | } |
| 2715 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2716 | if (extensions.multiview) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2717 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2718 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2719 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2720 | if (framebufferNumViews != programNumViews) |
| 2721 | { |
| 2722 | context->handleError(InvalidOperation() |
| 2723 | << "The number of views in the active program " |
| 2724 | "and draw framebuffer does not match."); |
| 2725 | return false; |
| 2726 | } |
| 2727 | |
| 2728 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2729 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2730 | framebufferNumViews > 1) |
| 2731 | { |
| 2732 | context->handleError(InvalidOperation() |
| 2733 | << "There is an active transform feedback object " |
| 2734 | "when the number of views in the active draw " |
| 2735 | "framebuffer is greater than 1."); |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
| 2739 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2740 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2741 | { |
| 2742 | context->handleError(InvalidOperation() |
| 2743 | << "There is an active query for target " |
| 2744 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2745 | "views in the active draw framebuffer is " |
| 2746 | "greater than 1."); |
| 2747 | return false; |
| 2748 | } |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2749 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2750 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2751 | // Do geometry shader specific validations |
| 2752 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2753 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2754 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2755 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2756 | { |
| 2757 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2758 | IncompatibleDrawModeAgainstGeometryShader); |
| 2759 | return false; |
| 2760 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2761 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2762 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2763 | // Uniform buffer validation |
| 2764 | for (unsigned int uniformBlockIndex = 0; |
| 2765 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2766 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2767 | const gl::InterfaceBlock &uniformBlock = |
| 2768 | program->getUniformBlockByIndex(uniformBlockIndex); |
| 2769 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
| 2770 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2771 | state.getIndexedUniformBuffer(blockBinding); |
| 2772 | |
| 2773 | if (uniformBuffer.get() == nullptr) |
| 2774 | { |
| 2775 | // undefined behaviour |
| 2776 | context->handleError( |
| 2777 | InvalidOperation() |
| 2778 | << "It is undefined behaviour to have a used but unbound uniform buffer."); |
| 2779 | return false; |
| 2780 | } |
| 2781 | |
| 2782 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2783 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2784 | { |
| 2785 | // undefined behaviour |
| 2786 | context->handleError( |
| 2787 | InvalidOperation() |
| 2788 | << "It is undefined behaviour to use a uniform buffer that is too small."); |
| 2789 | return false; |
| 2790 | } |
| 2791 | |
| 2792 | if (extensions.webglCompatibility && |
| 2793 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2794 | { |
| 2795 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2796 | UniformBufferBoundForTransformFeedback); |
| 2797 | return false; |
| 2798 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2799 | } |
| 2800 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2801 | // Do some additonal WebGL-specific validation |
| 2802 | if (extensions.webglCompatibility) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2803 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2804 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2805 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2806 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2807 | { |
| 2808 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2809 | TransformFeedbackBufferDoubleBound); |
| 2810 | return false; |
| 2811 | } |
| 2812 | // Detect rendering feedback loops for WebGL. |
| 2813 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2814 | { |
| 2815 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
| 2816 | return false; |
| 2817 | } |
| 2818 | |
| 2819 | // Detect that the vertex shader input types match the attribute types |
| 2820 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2821 | { |
| 2822 | return false; |
| 2823 | } |
| 2824 | |
| 2825 | // Detect that the color buffer types match the fragment shader output types |
| 2826 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2827 | { |
| 2828 | return false; |
| 2829 | } |
Jamie Madill | ac43aaa | 2018-07-31 11:22:13 -0400 | [diff] [blame] | 2830 | |
| 2831 | if (count > 0) |
| 2832 | { |
| 2833 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2834 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2835 | { |
| 2836 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2837 | VertexBufferBoundForTransformFeedback); |
| 2838 | return false; |
| 2839 | } |
| 2840 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2841 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2842 | } |
| 2843 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2844 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2845 | } |
| 2846 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2847 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2848 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2849 | GLint first, |
| 2850 | GLsizei count, |
| 2851 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2852 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2853 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2854 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2855 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2856 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2857 | } |
| 2858 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2859 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2860 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2861 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2862 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2863 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2864 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2865 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2866 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2867 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2868 | return false; |
| 2869 | } |
| 2870 | |
| 2871 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2872 | { |
| 2873 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2874 | return false; |
| 2875 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2876 | } |
| 2877 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2878 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2879 | { |
| 2880 | return false; |
| 2881 | } |
| 2882 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2883 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2884 | // - first < 0 has been checked as an error condition. |
| 2885 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2886 | // 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] | 2887 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2888 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2889 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2890 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2891 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2892 | { |
| 2893 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2894 | return false; |
| 2895 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2896 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2897 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2898 | { |
| 2899 | return false; |
| 2900 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | return true; |
| 2904 | } |
| 2905 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2906 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2907 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2908 | GLint first, |
| 2909 | GLsizei count, |
| 2910 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2911 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2912 | if (!context->getExtensions().instancedArrays) |
| 2913 | { |
| 2914 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2915 | return false; |
| 2916 | } |
| 2917 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2918 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2919 | { |
| 2920 | return false; |
| 2921 | } |
| 2922 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2923 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2924 | } |
| 2925 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2926 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2927 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2928 | switch (type) |
| 2929 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2930 | case GL_UNSIGNED_BYTE: |
| 2931 | case GL_UNSIGNED_SHORT: |
| 2932 | break; |
| 2933 | case GL_UNSIGNED_INT: |
| 2934 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2935 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2936 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2937 | return false; |
| 2938 | } |
| 2939 | break; |
| 2940 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2941 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2942 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2943 | } |
| 2944 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2945 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2946 | |
| 2947 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2948 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2949 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2950 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2951 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2952 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2953 | if (context->getExtensions().geometryShader) |
| 2954 | { |
| 2955 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2956 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2957 | { |
| 2958 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2959 | return false; |
| 2960 | } |
| 2961 | } |
| 2962 | else |
| 2963 | { |
| 2964 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2965 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2966 | // 86) |
| 2967 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2968 | UnsupportedDrawModeForTransformFeedback); |
| 2969 | return false; |
| 2970 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2971 | } |
| 2972 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2973 | return true; |
| 2974 | } |
| 2975 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2976 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2977 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2978 | GLsizei count, |
| 2979 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2980 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2981 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2982 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2983 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2984 | return false; |
| 2985 | |
| 2986 | const State &state = context->getGLState(); |
| 2987 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2988 | if (!ValidateDrawBase(context, mode, count)) |
| 2989 | { |
| 2990 | return false; |
| 2991 | } |
| 2992 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2993 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2994 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2995 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2996 | GLuint typeBytes = gl::GetTypeInfo(type).bytes; |
| 2997 | |
| 2998 | if (context->getExtensions().webglCompatibility) |
| 2999 | { |
| 3000 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3001 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3002 | { |
| 3003 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3004 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3005 | // 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] | 3006 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3007 | return false; |
| 3008 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3009 | |
| 3010 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3011 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3012 | // error is generated. |
| 3013 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3014 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3015 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3016 | return false; |
| 3017 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3018 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3019 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 3020 | { |
| 3021 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3022 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3023 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3024 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3025 | return false; |
| 3026 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3027 | |
| 3028 | if (context->getExtensions().webglCompatibility || |
| 3029 | !context->getGLState().areClientArraysEnabled()) |
| 3030 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3031 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3032 | { |
| 3033 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3034 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3035 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3036 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3037 | return false; |
| 3038 | } |
| 3039 | } |
| 3040 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3041 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3042 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3043 | // This is an application error that would normally result in a crash, but we catch it and |
| 3044 | // return an error |
| 3045 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3046 | return false; |
| 3047 | } |
| 3048 | |
| 3049 | if (count > 0 && elementArrayBuffer) |
| 3050 | { |
| 3051 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3052 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3053 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3054 | constexpr uint64_t kMaxTypeSize = 8; |
| 3055 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3056 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3057 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3058 | |
| 3059 | uint64_t typeSize = typeBytes; |
| 3060 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3061 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3062 | |
| 3063 | // Doing the multiplication here is overflow-safe |
| 3064 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3065 | |
| 3066 | // The offset can be any value, check for overflows |
| 3067 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3068 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3069 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3070 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3071 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3072 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3073 | |
| 3074 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3075 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3076 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3077 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3078 | return false; |
| 3079 | } |
| 3080 | |
| 3081 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3082 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3083 | { |
| 3084 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3085 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3086 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3087 | |
| 3088 | if (context->getExtensions().webglCompatibility && |
| 3089 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3090 | { |
| 3091 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3092 | ElementArrayBufferBoundForTransformFeedback); |
| 3093 | return false; |
| 3094 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3095 | } |
| 3096 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3097 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3098 | { |
| 3099 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3100 | const DrawCallParams ¶ms = context->getParams<DrawCallParams>(); |
| 3101 | ANGLE_VALIDATION_TRY(params.ensureIndexRangeResolved(context)); |
| 3102 | const IndexRange &indexRange = params.getIndexRange(); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3103 | |
| 3104 | // If we use an index greater than our maximum supported index range, return an error. |
| 3105 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3106 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3107 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3108 | { |
| 3109 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3110 | return false; |
| 3111 | } |
| 3112 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3113 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3114 | { |
| 3115 | return false; |
| 3116 | } |
| 3117 | |
| 3118 | // 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] | 3119 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3120 | } |
| 3121 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3122 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3123 | } |
| 3124 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3125 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3126 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3127 | GLsizei count, |
| 3128 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3129 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3130 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3131 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3132 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3133 | } |
| 3134 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3135 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3136 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3137 | GLsizei count, |
| 3138 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3139 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3140 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3141 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3142 | if (!context->getExtensions().instancedArrays) |
| 3143 | { |
| 3144 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3145 | return false; |
| 3146 | } |
| 3147 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3148 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3149 | { |
| 3150 | return false; |
| 3151 | } |
| 3152 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3153 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3154 | } |
| 3155 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3156 | bool ValidateFramebufferTextureBase(Context *context, |
| 3157 | GLenum target, |
| 3158 | GLenum attachment, |
| 3159 | GLuint texture, |
| 3160 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3161 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3162 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3163 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3164 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3165 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3166 | } |
| 3167 | |
| 3168 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3169 | { |
| 3170 | return false; |
| 3171 | } |
| 3172 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3173 | if (texture != 0) |
| 3174 | { |
| 3175 | gl::Texture *tex = context->getTexture(texture); |
| 3176 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3177 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3178 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3179 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3180 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3181 | } |
| 3182 | |
| 3183 | if (level < 0) |
| 3184 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3185 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3186 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3187 | } |
| 3188 | } |
| 3189 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3190 | const gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3191 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3192 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3193 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3194 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3195 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3196 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3197 | } |
| 3198 | |
| 3199 | return true; |
| 3200 | } |
| 3201 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3202 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3203 | { |
| 3204 | if (program == 0) |
| 3205 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3206 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3207 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3208 | } |
| 3209 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3210 | gl::Program *programObject = GetValidProgram(context, program); |
| 3211 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3212 | { |
| 3213 | return false; |
| 3214 | } |
| 3215 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3216 | if (!programObject || !programObject->isLinked()) |
| 3217 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3218 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3219 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3220 | } |
| 3221 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3222 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3223 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3224 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3225 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3226 | } |
| 3227 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3228 | return true; |
| 3229 | } |
| 3230 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3231 | static bool ValidateSizedGetUniform(Context *context, |
| 3232 | GLuint program, |
| 3233 | GLint location, |
| 3234 | GLsizei bufSize, |
| 3235 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3236 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3237 | if (length) |
| 3238 | { |
| 3239 | *length = 0; |
| 3240 | } |
| 3241 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3242 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3243 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3244 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3245 | } |
| 3246 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3247 | if (bufSize < 0) |
| 3248 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3249 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3250 | return false; |
| 3251 | } |
| 3252 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3253 | gl::Program *programObject = context->getProgram(program); |
| 3254 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3255 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3256 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3257 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3258 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3259 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3260 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3261 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3262 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3263 | } |
| 3264 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3265 | if (length) |
| 3266 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3267 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3268 | } |
| 3269 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3270 | return true; |
| 3271 | } |
| 3272 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3273 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3274 | GLuint program, |
| 3275 | GLint location, |
| 3276 | GLsizei bufSize, |
| 3277 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3278 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3279 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3280 | } |
| 3281 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3282 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3283 | GLuint program, |
| 3284 | GLint location, |
| 3285 | GLsizei bufSize, |
| 3286 | GLsizei *length, |
| 3287 | GLfloat *params) |
| 3288 | { |
| 3289 | UNIMPLEMENTED(); |
| 3290 | return false; |
| 3291 | } |
| 3292 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3293 | bool ValidateGetnUniformivEXT(Context *context, |
| 3294 | GLuint program, |
| 3295 | GLint location, |
| 3296 | GLsizei bufSize, |
| 3297 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3298 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3299 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3300 | } |
| 3301 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3302 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3303 | GLuint program, |
| 3304 | GLint location, |
| 3305 | GLsizei bufSize, |
| 3306 | GLsizei *length, |
| 3307 | GLint *params) |
| 3308 | { |
| 3309 | UNIMPLEMENTED(); |
| 3310 | return false; |
| 3311 | } |
| 3312 | |
| 3313 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3314 | GLuint program, |
| 3315 | GLint location, |
| 3316 | GLsizei bufSize, |
| 3317 | GLsizei *length, |
| 3318 | GLuint *params) |
| 3319 | { |
| 3320 | UNIMPLEMENTED(); |
| 3321 | return false; |
| 3322 | } |
| 3323 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3324 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3325 | GLuint program, |
| 3326 | GLint location, |
| 3327 | GLsizei bufSize, |
| 3328 | GLsizei *length, |
| 3329 | GLfloat *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 ValidateGetUniformivRobustANGLE(Context *context, |
| 3350 | GLuint program, |
| 3351 | GLint location, |
| 3352 | GLsizei bufSize, |
| 3353 | GLsizei *length, |
| 3354 | GLint *params) |
| 3355 | { |
| 3356 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3357 | { |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3361 | GLsizei writeLength = 0; |
| 3362 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3363 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3364 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3365 | { |
| 3366 | return false; |
| 3367 | } |
| 3368 | |
| 3369 | SetRobustLengthParam(length, writeLength); |
| 3370 | |
| 3371 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3372 | } |
| 3373 | |
| 3374 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3375 | GLuint program, |
| 3376 | GLint location, |
| 3377 | GLsizei bufSize, |
| 3378 | GLsizei *length, |
| 3379 | GLuint *params) |
| 3380 | { |
| 3381 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3382 | { |
| 3383 | return false; |
| 3384 | } |
| 3385 | |
| 3386 | if (context->getClientMajorVersion() < 3) |
| 3387 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3388 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3389 | return false; |
| 3390 | } |
| 3391 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3392 | GLsizei writeLength = 0; |
| 3393 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3394 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3395 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3396 | { |
| 3397 | return false; |
| 3398 | } |
| 3399 | |
| 3400 | SetRobustLengthParam(length, writeLength); |
| 3401 | |
| 3402 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3403 | } |
| 3404 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3405 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3406 | GLenum target, |
| 3407 | GLsizei numAttachments, |
| 3408 | const GLenum *attachments, |
| 3409 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3410 | { |
| 3411 | if (numAttachments < 0) |
| 3412 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3413 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3414 | return false; |
| 3415 | } |
| 3416 | |
| 3417 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3418 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3419 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3420 | { |
| 3421 | if (defaultFramebuffer) |
| 3422 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3423 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3424 | return false; |
| 3425 | } |
| 3426 | |
| 3427 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3428 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3429 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3430 | "greater than the maximum supported " |
| 3431 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3432 | return false; |
| 3433 | } |
| 3434 | } |
| 3435 | else |
| 3436 | { |
| 3437 | switch (attachments[i]) |
| 3438 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3439 | case GL_DEPTH_ATTACHMENT: |
| 3440 | case GL_STENCIL_ATTACHMENT: |
| 3441 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3442 | if (defaultFramebuffer) |
| 3443 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3444 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3445 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3446 | return false; |
| 3447 | } |
| 3448 | break; |
| 3449 | case GL_COLOR: |
| 3450 | case GL_DEPTH: |
| 3451 | case GL_STENCIL: |
| 3452 | if (!defaultFramebuffer) |
| 3453 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3454 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3455 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3456 | return false; |
| 3457 | } |
| 3458 | break; |
| 3459 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3460 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3461 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3462 | } |
| 3463 | } |
| 3464 | } |
| 3465 | |
| 3466 | return true; |
| 3467 | } |
| 3468 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3469 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3470 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3471 | if (!context->getExtensions().debugMarker) |
| 3472 | { |
| 3473 | // The debug marker calls should not set error state |
| 3474 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3475 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3476 | return false; |
| 3477 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3478 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3479 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3480 | if (length < 0) |
| 3481 | { |
| 3482 | return false; |
| 3483 | } |
| 3484 | |
| 3485 | if (marker == nullptr) |
| 3486 | { |
| 3487 | return false; |
| 3488 | } |
| 3489 | |
| 3490 | return true; |
| 3491 | } |
| 3492 | |
| 3493 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3494 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3495 | if (!context->getExtensions().debugMarker) |
| 3496 | { |
| 3497 | // The debug marker calls should not set error state |
| 3498 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3499 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3500 | return false; |
| 3501 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3502 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3503 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3504 | if (length < 0) |
| 3505 | { |
| 3506 | return false; |
| 3507 | } |
| 3508 | |
| 3509 | if (length > 0 && marker == nullptr) |
| 3510 | { |
| 3511 | return false; |
| 3512 | } |
| 3513 | |
| 3514 | return true; |
| 3515 | } |
| 3516 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3517 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3518 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3519 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3520 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3521 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3522 | return false; |
| 3523 | } |
| 3524 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3525 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3526 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3527 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3528 | if (!context->getExtensions().eglImage) |
| 3529 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3530 | context->handleError(InvalidEnum() |
| 3531 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3532 | } |
| 3533 | break; |
| 3534 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3535 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3536 | if (!context->getExtensions().eglImageExternal) |
| 3537 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3538 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3539 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3540 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3541 | break; |
| 3542 | |
| 3543 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3544 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3548 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3549 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3550 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3551 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3552 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3553 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3554 | return false; |
| 3555 | } |
| 3556 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3557 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3559 | context->handleError(InvalidOperation() |
| 3560 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3561 | return false; |
| 3562 | } |
| 3563 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3564 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3565 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3566 | if (!textureCaps.texturable) |
| 3567 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3568 | context->handleError(InvalidOperation() |
| 3569 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3570 | return false; |
| 3571 | } |
| 3572 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3573 | return true; |
| 3574 | } |
| 3575 | |
| 3576 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3577 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3578 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3579 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3580 | if (!context->getExtensions().eglImage) |
| 3581 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3582 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3583 | return false; |
| 3584 | } |
| 3585 | |
| 3586 | switch (target) |
| 3587 | { |
| 3588 | case GL_RENDERBUFFER: |
| 3589 | break; |
| 3590 | |
| 3591 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3592 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3593 | return false; |
| 3594 | } |
| 3595 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3596 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3597 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3598 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3599 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3600 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3601 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3605 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3606 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 3607 | if (!textureCaps.renderbuffer) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3608 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3609 | context->handleError(InvalidOperation() |
| 3610 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3611 | return false; |
| 3612 | } |
| 3613 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3614 | return true; |
| 3615 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3616 | |
| 3617 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3618 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3619 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3620 | { |
| 3621 | // The default VAO should always exist |
| 3622 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3623 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3624 | return false; |
| 3625 | } |
| 3626 | |
| 3627 | return true; |
| 3628 | } |
| 3629 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3630 | bool ValidateProgramBinaryBase(Context *context, |
| 3631 | GLuint program, |
| 3632 | GLenum binaryFormat, |
| 3633 | const void *binary, |
| 3634 | GLint length) |
| 3635 | { |
| 3636 | Program *programObject = GetValidProgram(context, program); |
| 3637 | if (programObject == nullptr) |
| 3638 | { |
| 3639 | return false; |
| 3640 | } |
| 3641 | |
| 3642 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3643 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3644 | programBinaryFormats.end()) |
| 3645 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3646 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3650 | if (context->hasActiveTransformFeedback(program)) |
| 3651 | { |
| 3652 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3653 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3654 | "is associated with an active transform " |
| 3655 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3656 | return false; |
| 3657 | } |
| 3658 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3659 | return true; |
| 3660 | } |
| 3661 | |
| 3662 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3663 | GLuint program, |
| 3664 | GLsizei bufSize, |
| 3665 | GLsizei *length, |
| 3666 | GLenum *binaryFormat, |
| 3667 | void *binary) |
| 3668 | { |
| 3669 | Program *programObject = GetValidProgram(context, program); |
| 3670 | if (programObject == nullptr) |
| 3671 | { |
| 3672 | return false; |
| 3673 | } |
| 3674 | |
| 3675 | if (!programObject->isLinked()) |
| 3676 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3677 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3678 | return false; |
| 3679 | } |
| 3680 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3681 | if (context->getCaps().programBinaryFormats.empty()) |
| 3682 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3683 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3684 | return false; |
| 3685 | } |
| 3686 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3687 | return true; |
| 3688 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3689 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3690 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3691 | { |
| 3692 | // 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] | 3693 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3694 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3695 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3696 | return false; |
| 3697 | } |
| 3698 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3699 | { |
| 3700 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3701 | return false; |
| 3702 | } |
| 3703 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3704 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3705 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3706 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3707 | |
| 3708 | // This should come first before the check for the default frame buffer |
| 3709 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3710 | // rather than INVALID_OPERATION |
| 3711 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3712 | { |
| 3713 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3714 | |
| 3715 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3716 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3717 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3718 | { |
| 3719 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3720 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3721 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3722 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3723 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3724 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3725 | return false; |
| 3726 | } |
| 3727 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3728 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3729 | context->handleError(InvalidOperation() |
| 3730 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3734 | frameBufferId != 0) |
| 3735 | { |
| 3736 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3737 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3738 | context->handleError(InvalidOperation() |
| 3739 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3740 | return false; |
| 3741 | } |
| 3742 | } |
| 3743 | |
| 3744 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3745 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3746 | if (frameBufferId == 0) |
| 3747 | { |
| 3748 | if (n != 1) |
| 3749 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3750 | context->handleError(InvalidOperation() |
| 3751 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3752 | return false; |
| 3753 | } |
| 3754 | |
| 3755 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3756 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3757 | context->handleError( |
| 3758 | InvalidOperation() |
| 3759 | << "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] | 3760 | return false; |
| 3761 | } |
| 3762 | } |
| 3763 | |
| 3764 | return true; |
| 3765 | } |
| 3766 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3767 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3768 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3769 | GLenum pname, |
| 3770 | GLsizei *length, |
| 3771 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3772 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3773 | if (length) |
| 3774 | { |
| 3775 | *length = 0; |
| 3776 | } |
| 3777 | |
| 3778 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3779 | { |
| 3780 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3781 | InvalidOperation() |
| 3782 | << "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] | 3783 | return false; |
| 3784 | } |
| 3785 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3786 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3787 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3788 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3789 | return false; |
| 3790 | } |
| 3791 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3792 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3793 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3794 | case GL_BUFFER_MAP_POINTER: |
| 3795 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3796 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3797 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3798 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3799 | return false; |
| 3800 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3801 | |
| 3802 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3803 | // target bound to zero generate an INVALID_OPERATION error." |
| 3804 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3805 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3806 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3807 | context->handleError(InvalidOperation() |
| 3808 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3809 | return false; |
| 3810 | } |
| 3811 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3812 | if (length) |
| 3813 | { |
| 3814 | *length = 1; |
| 3815 | } |
| 3816 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3817 | return true; |
| 3818 | } |
| 3819 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3820 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3821 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3822 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3823 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3824 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3825 | return false; |
| 3826 | } |
| 3827 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3828 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3829 | |
| 3830 | if (buffer == nullptr || !buffer->isMapped()) |
| 3831 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3832 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3833 | return false; |
| 3834 | } |
| 3835 | |
| 3836 | return true; |
| 3837 | } |
| 3838 | |
| 3839 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3840 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3841 | GLintptr offset, |
| 3842 | GLsizeiptr length, |
| 3843 | GLbitfield access) |
| 3844 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3845 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3846 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3847 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3848 | return false; |
| 3849 | } |
| 3850 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3851 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3852 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3853 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3854 | return false; |
| 3855 | } |
| 3856 | |
| 3857 | if (length < 0) |
| 3858 | { |
| 3859 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3860 | return false; |
| 3861 | } |
| 3862 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3863 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3864 | |
| 3865 | if (!buffer) |
| 3866 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3867 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3868 | return false; |
| 3869 | } |
| 3870 | |
| 3871 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3872 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3873 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3874 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3875 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3876 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3877 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3878 | return false; |
| 3879 | } |
| 3880 | |
| 3881 | // Check for invalid bits in the mask |
| 3882 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3883 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3884 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3885 | |
| 3886 | if (access & ~(allAccessBits)) |
| 3887 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3888 | context->handleError(InvalidValue() |
| 3889 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3890 | return false; |
| 3891 | } |
| 3892 | |
| 3893 | if (length == 0) |
| 3894 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3895 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3896 | return false; |
| 3897 | } |
| 3898 | |
| 3899 | if (buffer->isMapped()) |
| 3900 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3901 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3902 | return false; |
| 3903 | } |
| 3904 | |
| 3905 | // Check for invalid bit combinations |
| 3906 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3907 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3908 | context->handleError(InvalidOperation() |
| 3909 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3910 | return false; |
| 3911 | } |
| 3912 | |
| 3913 | GLbitfield writeOnlyBits = |
| 3914 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3915 | |
| 3916 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3917 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3918 | context->handleError(InvalidOperation() |
| 3919 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3920 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3921 | return false; |
| 3922 | } |
| 3923 | |
| 3924 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3925 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3926 | context->handleError( |
| 3927 | InvalidOperation() |
| 3928 | << "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] | 3929 | return false; |
| 3930 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3931 | |
| 3932 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3933 | } |
| 3934 | |
| 3935 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3936 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3937 | GLintptr offset, |
| 3938 | GLsizeiptr length) |
| 3939 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3940 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3941 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3942 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3943 | return false; |
| 3944 | } |
| 3945 | |
| 3946 | if (length < 0) |
| 3947 | { |
| 3948 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3949 | return false; |
| 3950 | } |
| 3951 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3952 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3953 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3954 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3955 | return false; |
| 3956 | } |
| 3957 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3958 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3959 | |
| 3960 | if (buffer == nullptr) |
| 3961 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3962 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3963 | return false; |
| 3964 | } |
| 3965 | |
| 3966 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3967 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3968 | context->handleError(InvalidOperation() |
| 3969 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3970 | return false; |
| 3971 | } |
| 3972 | |
| 3973 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3974 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3975 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3976 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3977 | if (!checkedSize.IsValid() || |
| 3978 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3979 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3980 | context->handleError(InvalidValue() |
| 3981 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3982 | return false; |
| 3983 | } |
| 3984 | |
| 3985 | return true; |
| 3986 | } |
| 3987 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3988 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3989 | { |
| 3990 | if (n < 0) |
| 3991 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3992 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3993 | return false; |
| 3994 | } |
| 3995 | return true; |
| 3996 | } |
| 3997 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3998 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3999 | { |
| 4000 | if (!context->getExtensions().robustClientMemory) |
| 4001 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4002 | context->handleError(InvalidOperation() |
| 4003 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4004 | return false; |
| 4005 | } |
| 4006 | |
| 4007 | if (bufSize < 0) |
| 4008 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4009 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4010 | return false; |
| 4011 | } |
| 4012 | |
| 4013 | return true; |
| 4014 | } |
| 4015 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4016 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4017 | { |
| 4018 | if (bufSize < numParams) |
| 4019 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4020 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 4021 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4022 | return false; |
| 4023 | } |
| 4024 | |
| 4025 | return true; |
| 4026 | } |
| 4027 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4028 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4029 | GLenum target, |
| 4030 | GLenum attachment, |
| 4031 | GLenum pname, |
| 4032 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4033 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4034 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4035 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4036 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4037 | return false; |
| 4038 | } |
| 4039 | |
| 4040 | int clientVersion = context->getClientMajorVersion(); |
| 4041 | |
| 4042 | switch (pname) |
| 4043 | { |
| 4044 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4045 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4046 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4047 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4048 | break; |
| 4049 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4050 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4051 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4052 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4053 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4054 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4055 | { |
| 4056 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4057 | return false; |
| 4058 | } |
| 4059 | break; |
| 4060 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4061 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4062 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4063 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4064 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4065 | return false; |
| 4066 | } |
| 4067 | break; |
| 4068 | |
| 4069 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4070 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4071 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4072 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4073 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4074 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4075 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4076 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4077 | if (clientVersion < 3) |
| 4078 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4079 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4080 | return false; |
| 4081 | } |
| 4082 | break; |
| 4083 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4084 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4085 | if (!context->getExtensions().geometryShader) |
| 4086 | { |
| 4087 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4088 | return false; |
| 4089 | } |
| 4090 | break; |
| 4091 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4092 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4093 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4094 | return false; |
| 4095 | } |
| 4096 | |
| 4097 | // Determine if the attachment is a valid enum |
| 4098 | switch (attachment) |
| 4099 | { |
| 4100 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4101 | case GL_DEPTH: |
| 4102 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4103 | if (clientVersion < 3) |
| 4104 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4105 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4106 | return false; |
| 4107 | } |
| 4108 | break; |
| 4109 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4110 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4111 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4112 | { |
| 4113 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4114 | return false; |
| 4115 | } |
| 4116 | break; |
| 4117 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4118 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4119 | case GL_DEPTH_ATTACHMENT: |
| 4120 | case GL_STENCIL_ATTACHMENT: |
| 4121 | break; |
| 4122 | |
| 4123 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4124 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4125 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4126 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4127 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4128 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4129 | return false; |
| 4130 | } |
| 4131 | break; |
| 4132 | } |
| 4133 | |
| 4134 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4135 | ASSERT(framebuffer); |
| 4136 | |
| 4137 | if (framebuffer->id() == 0) |
| 4138 | { |
| 4139 | if (clientVersion < 3) |
| 4140 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4141 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4142 | return false; |
| 4143 | } |
| 4144 | |
| 4145 | switch (attachment) |
| 4146 | { |
| 4147 | case GL_BACK: |
| 4148 | case GL_DEPTH: |
| 4149 | case GL_STENCIL: |
| 4150 | break; |
| 4151 | |
| 4152 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4153 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4154 | return false; |
| 4155 | } |
| 4156 | } |
| 4157 | else |
| 4158 | { |
| 4159 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4160 | { |
| 4161 | // Valid attachment query |
| 4162 | } |
| 4163 | else |
| 4164 | { |
| 4165 | switch (attachment) |
| 4166 | { |
| 4167 | case GL_DEPTH_ATTACHMENT: |
| 4168 | case GL_STENCIL_ATTACHMENT: |
| 4169 | break; |
| 4170 | |
| 4171 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4172 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4173 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4174 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4175 | return false; |
| 4176 | } |
| 4177 | break; |
| 4178 | |
| 4179 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4180 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4181 | return false; |
| 4182 | } |
| 4183 | } |
| 4184 | } |
| 4185 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4186 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4187 | if (attachmentObject) |
| 4188 | { |
| 4189 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4190 | attachmentObject->type() == GL_TEXTURE || |
| 4191 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4192 | |
| 4193 | switch (pname) |
| 4194 | { |
| 4195 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4196 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4197 | attachmentObject->type() != GL_TEXTURE) |
| 4198 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4199 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4200 | return false; |
| 4201 | } |
| 4202 | break; |
| 4203 | |
| 4204 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4205 | if (attachmentObject->type() != GL_TEXTURE) |
| 4206 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4207 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4208 | return false; |
| 4209 | } |
| 4210 | break; |
| 4211 | |
| 4212 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4213 | if (attachmentObject->type() != GL_TEXTURE) |
| 4214 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4215 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4216 | return false; |
| 4217 | } |
| 4218 | break; |
| 4219 | |
| 4220 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4221 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4222 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4223 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4224 | return false; |
| 4225 | } |
| 4226 | break; |
| 4227 | |
| 4228 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4229 | if (attachmentObject->type() != GL_TEXTURE) |
| 4230 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4231 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4232 | return false; |
| 4233 | } |
| 4234 | break; |
| 4235 | |
| 4236 | default: |
| 4237 | break; |
| 4238 | } |
| 4239 | } |
| 4240 | else |
| 4241 | { |
| 4242 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4243 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4244 | |
| 4245 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4246 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4247 | // INVALID_OPERATION for all other pnames |
| 4248 | |
| 4249 | switch (pname) |
| 4250 | { |
| 4251 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4252 | break; |
| 4253 | |
| 4254 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4255 | if (clientVersion < 3) |
| 4256 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4257 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4258 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4259 | return false; |
| 4260 | } |
| 4261 | break; |
| 4262 | |
| 4263 | default: |
| 4264 | if (clientVersion < 3) |
| 4265 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4266 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4267 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4268 | return false; |
| 4269 | } |
| 4270 | else |
| 4271 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4272 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4273 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4274 | return false; |
| 4275 | } |
| 4276 | } |
| 4277 | } |
| 4278 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4279 | if (numParams) |
| 4280 | { |
| 4281 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4282 | { |
| 4283 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4284 | // parameters. |
| 4285 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4286 | *numParams = numViews * 2; |
| 4287 | } |
| 4288 | else |
| 4289 | { |
| 4290 | // For all other queries we can have only one output parameter. |
| 4291 | *numParams = 1; |
| 4292 | } |
| 4293 | } |
| 4294 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4295 | return true; |
| 4296 | } |
| 4297 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4298 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4299 | GLenum target, |
| 4300 | GLenum attachment, |
| 4301 | GLenum pname, |
| 4302 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4303 | GLsizei *length, |
| 4304 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4305 | { |
| 4306 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4307 | { |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4311 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4312 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4313 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4314 | { |
| 4315 | return false; |
| 4316 | } |
| 4317 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4318 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4319 | { |
| 4320 | return false; |
| 4321 | } |
| 4322 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4323 | SetRobustLengthParam(length, numParams); |
| 4324 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4325 | return true; |
| 4326 | } |
| 4327 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4328 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4329 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4330 | GLenum pname, |
| 4331 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4332 | GLsizei *length, |
| 4333 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4334 | { |
| 4335 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4336 | { |
| 4337 | return false; |
| 4338 | } |
| 4339 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4340 | GLsizei numParams = 0; |
| 4341 | |
| 4342 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4343 | { |
| 4344 | return false; |
| 4345 | } |
| 4346 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4347 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4348 | { |
| 4349 | return false; |
| 4350 | } |
| 4351 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4352 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4353 | return true; |
| 4354 | } |
| 4355 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4356 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4357 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4358 | GLenum pname, |
| 4359 | GLsizei bufSize, |
| 4360 | GLsizei *length, |
| 4361 | GLint64 *params) |
| 4362 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4363 | GLsizei numParams = 0; |
| 4364 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4365 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4366 | { |
| 4367 | return false; |
| 4368 | } |
| 4369 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4370 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4371 | { |
| 4372 | return false; |
| 4373 | } |
| 4374 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4375 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4376 | { |
| 4377 | return false; |
| 4378 | } |
| 4379 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4380 | SetRobustLengthParam(length, numParams); |
| 4381 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4382 | return true; |
| 4383 | } |
| 4384 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4385 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4386 | { |
| 4387 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4388 | if (numParams) |
| 4389 | { |
| 4390 | *numParams = 1; |
| 4391 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4392 | |
| 4393 | Program *programObject = GetValidProgram(context, program); |
| 4394 | if (!programObject) |
| 4395 | { |
| 4396 | return false; |
| 4397 | } |
| 4398 | |
| 4399 | switch (pname) |
| 4400 | { |
| 4401 | case GL_DELETE_STATUS: |
| 4402 | case GL_LINK_STATUS: |
| 4403 | case GL_VALIDATE_STATUS: |
| 4404 | case GL_INFO_LOG_LENGTH: |
| 4405 | case GL_ATTACHED_SHADERS: |
| 4406 | case GL_ACTIVE_ATTRIBUTES: |
| 4407 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4408 | case GL_ACTIVE_UNIFORMS: |
| 4409 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4410 | break; |
| 4411 | |
| 4412 | case GL_PROGRAM_BINARY_LENGTH: |
| 4413 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4414 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4415 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4416 | "requires GL_OES_get_program_binary or " |
| 4417 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4418 | return false; |
| 4419 | } |
| 4420 | break; |
| 4421 | |
| 4422 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4423 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4424 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4425 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4426 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4427 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4428 | if (context->getClientMajorVersion() < 3) |
| 4429 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4430 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4431 | return false; |
| 4432 | } |
| 4433 | break; |
| 4434 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4435 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4436 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4437 | if (context->getClientVersion() < Version(3, 1)) |
| 4438 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4439 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4440 | return false; |
| 4441 | } |
| 4442 | break; |
| 4443 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4444 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4445 | if (context->getClientVersion() < Version(3, 1)) |
| 4446 | { |
| 4447 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4448 | return false; |
| 4449 | } |
| 4450 | |
| 4451 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4452 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4453 | // program which has not been linked successfully, or which does not contain objects to |
| 4454 | // form a compute shader. |
| 4455 | if (!programObject->isLinked()) |
| 4456 | { |
| 4457 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4458 | return false; |
| 4459 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4460 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4461 | { |
| 4462 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4463 | return false; |
| 4464 | } |
| 4465 | break; |
| 4466 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4467 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4468 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4469 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4470 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4471 | if (!context->getExtensions().geometryShader) |
| 4472 | { |
| 4473 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4474 | return false; |
| 4475 | } |
| 4476 | |
| 4477 | // [EXT_geometry_shader] Chapter 7.12 |
| 4478 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4479 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4480 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4481 | // successfully, or which does not contain objects to form a geometry shader. |
| 4482 | if (!programObject->isLinked()) |
| 4483 | { |
| 4484 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4485 | return false; |
| 4486 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4487 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4488 | { |
| 4489 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4490 | return false; |
| 4491 | } |
| 4492 | break; |
| 4493 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4494 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4495 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4496 | return false; |
| 4497 | } |
| 4498 | |
| 4499 | return true; |
| 4500 | } |
| 4501 | |
| 4502 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4503 | GLuint program, |
| 4504 | GLenum pname, |
| 4505 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4506 | GLsizei *length, |
| 4507 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4508 | { |
| 4509 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4510 | { |
| 4511 | return false; |
| 4512 | } |
| 4513 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4514 | GLsizei numParams = 0; |
| 4515 | |
| 4516 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4517 | { |
| 4518 | return false; |
| 4519 | } |
| 4520 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4521 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4522 | { |
| 4523 | return false; |
| 4524 | } |
| 4525 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4526 | SetRobustLengthParam(length, numParams); |
| 4527 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4528 | return true; |
| 4529 | } |
| 4530 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4531 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4532 | GLenum target, |
| 4533 | GLenum pname, |
| 4534 | GLsizei bufSize, |
| 4535 | GLsizei *length, |
| 4536 | GLint *params) |
| 4537 | { |
| 4538 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4539 | { |
| 4540 | return false; |
| 4541 | } |
| 4542 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4543 | GLsizei numParams = 0; |
| 4544 | |
| 4545 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4546 | { |
| 4547 | return false; |
| 4548 | } |
| 4549 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4550 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4551 | { |
| 4552 | return false; |
| 4553 | } |
| 4554 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4555 | SetRobustLengthParam(length, numParams); |
| 4556 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4557 | return true; |
| 4558 | } |
| 4559 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4560 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4561 | GLuint shader, |
| 4562 | GLenum pname, |
| 4563 | GLsizei bufSize, |
| 4564 | GLsizei *length, |
| 4565 | GLint *params) |
| 4566 | { |
| 4567 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4568 | { |
| 4569 | return false; |
| 4570 | } |
| 4571 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4572 | GLsizei numParams = 0; |
| 4573 | |
| 4574 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4575 | { |
| 4576 | return false; |
| 4577 | } |
| 4578 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4579 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4580 | { |
| 4581 | return false; |
| 4582 | } |
| 4583 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4584 | SetRobustLengthParam(length, numParams); |
| 4585 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4586 | return true; |
| 4587 | } |
| 4588 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4589 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4590 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4591 | GLenum pname, |
| 4592 | GLsizei bufSize, |
| 4593 | GLsizei *length, |
| 4594 | GLfloat *params) |
| 4595 | { |
| 4596 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4597 | { |
| 4598 | return false; |
| 4599 | } |
| 4600 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4601 | GLsizei numParams = 0; |
| 4602 | |
| 4603 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4604 | { |
| 4605 | return false; |
| 4606 | } |
| 4607 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4608 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4609 | { |
| 4610 | return false; |
| 4611 | } |
| 4612 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4613 | SetRobustLengthParam(length, numParams); |
| 4614 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4615 | return true; |
| 4616 | } |
| 4617 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4618 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4619 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4620 | GLenum pname, |
| 4621 | GLsizei bufSize, |
| 4622 | GLsizei *length, |
| 4623 | GLint *params) |
| 4624 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4625 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4626 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4627 | { |
| 4628 | return false; |
| 4629 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4630 | GLsizei numParams = 0; |
| 4631 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4632 | { |
| 4633 | return false; |
| 4634 | } |
| 4635 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4636 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4637 | { |
| 4638 | return false; |
| 4639 | } |
| 4640 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4641 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4642 | return true; |
| 4643 | } |
| 4644 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4645 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4646 | TextureType target, |
| 4647 | GLenum pname, |
| 4648 | GLsizei bufSize, |
| 4649 | GLsizei *length, |
| 4650 | GLint *params) |
| 4651 | { |
| 4652 | UNIMPLEMENTED(); |
| 4653 | return false; |
| 4654 | } |
| 4655 | |
| 4656 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4657 | TextureType target, |
| 4658 | GLenum pname, |
| 4659 | GLsizei bufSize, |
| 4660 | GLsizei *length, |
| 4661 | GLuint *params) |
| 4662 | { |
| 4663 | UNIMPLEMENTED(); |
| 4664 | return false; |
| 4665 | } |
| 4666 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4667 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4668 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4669 | GLenum pname, |
| 4670 | GLsizei bufSize, |
| 4671 | const GLfloat *params) |
| 4672 | { |
| 4673 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4674 | { |
| 4675 | return false; |
| 4676 | } |
| 4677 | |
| 4678 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4679 | } |
| 4680 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4681 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4682 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4683 | GLenum pname, |
| 4684 | GLsizei bufSize, |
| 4685 | const GLint *params) |
| 4686 | { |
| 4687 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4688 | { |
| 4689 | return false; |
| 4690 | } |
| 4691 | |
| 4692 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4693 | } |
| 4694 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4695 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4696 | TextureType target, |
| 4697 | GLenum pname, |
| 4698 | GLsizei bufSize, |
| 4699 | const GLint *params) |
| 4700 | { |
| 4701 | UNIMPLEMENTED(); |
| 4702 | return false; |
| 4703 | } |
| 4704 | |
| 4705 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4706 | TextureType target, |
| 4707 | GLenum pname, |
| 4708 | GLsizei bufSize, |
| 4709 | const GLuint *params) |
| 4710 | { |
| 4711 | UNIMPLEMENTED(); |
| 4712 | return false; |
| 4713 | } |
| 4714 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4715 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4716 | GLuint sampler, |
| 4717 | GLenum pname, |
| 4718 | GLuint bufSize, |
| 4719 | GLsizei *length, |
| 4720 | GLfloat *params) |
| 4721 | { |
| 4722 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4723 | { |
| 4724 | return false; |
| 4725 | } |
| 4726 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4727 | GLsizei numParams = 0; |
| 4728 | |
| 4729 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4730 | { |
| 4731 | return false; |
| 4732 | } |
| 4733 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4734 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4735 | { |
| 4736 | return false; |
| 4737 | } |
| 4738 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4739 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4740 | return true; |
| 4741 | } |
| 4742 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4743 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4744 | GLuint sampler, |
| 4745 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4746 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4747 | GLsizei *length, |
| 4748 | GLint *params) |
| 4749 | { |
| 4750 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4751 | { |
| 4752 | return false; |
| 4753 | } |
| 4754 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4755 | GLsizei numParams = 0; |
| 4756 | |
| 4757 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4758 | { |
| 4759 | return false; |
| 4760 | } |
| 4761 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4762 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4763 | { |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4767 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4768 | return true; |
| 4769 | } |
| 4770 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4771 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4772 | GLuint sampler, |
| 4773 | GLenum pname, |
| 4774 | GLsizei bufSize, |
| 4775 | GLsizei *length, |
| 4776 | GLint *params) |
| 4777 | { |
| 4778 | UNIMPLEMENTED(); |
| 4779 | return false; |
| 4780 | } |
| 4781 | |
| 4782 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4783 | GLuint sampler, |
| 4784 | GLenum pname, |
| 4785 | GLsizei bufSize, |
| 4786 | GLsizei *length, |
| 4787 | GLuint *params) |
| 4788 | { |
| 4789 | UNIMPLEMENTED(); |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4793 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4794 | GLuint sampler, |
| 4795 | GLenum pname, |
| 4796 | GLsizei bufSize, |
| 4797 | const GLfloat *params) |
| 4798 | { |
| 4799 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4800 | { |
| 4801 | return false; |
| 4802 | } |
| 4803 | |
| 4804 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4805 | } |
| 4806 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4807 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4808 | GLuint sampler, |
| 4809 | GLenum pname, |
| 4810 | GLsizei bufSize, |
| 4811 | const GLint *params) |
| 4812 | { |
| 4813 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4814 | { |
| 4815 | return false; |
| 4816 | } |
| 4817 | |
| 4818 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4819 | } |
| 4820 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4821 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4822 | GLuint sampler, |
| 4823 | GLenum pname, |
| 4824 | GLsizei bufSize, |
| 4825 | const GLint *param) |
| 4826 | { |
| 4827 | UNIMPLEMENTED(); |
| 4828 | return false; |
| 4829 | } |
| 4830 | |
| 4831 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4832 | GLuint sampler, |
| 4833 | GLenum pname, |
| 4834 | GLsizei bufSize, |
| 4835 | const GLuint *param) |
| 4836 | { |
| 4837 | UNIMPLEMENTED(); |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4841 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4842 | GLuint index, |
| 4843 | GLenum pname, |
| 4844 | GLsizei bufSize, |
| 4845 | GLsizei *length, |
| 4846 | GLfloat *params) |
| 4847 | { |
| 4848 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4849 | { |
| 4850 | return false; |
| 4851 | } |
| 4852 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4853 | GLsizei writeLength = 0; |
| 4854 | |
| 4855 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4856 | { |
| 4857 | return false; |
| 4858 | } |
| 4859 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4860 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4861 | { |
| 4862 | return false; |
| 4863 | } |
| 4864 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4865 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4866 | return true; |
| 4867 | } |
| 4868 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4869 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4870 | GLuint index, |
| 4871 | GLenum pname, |
| 4872 | GLsizei bufSize, |
| 4873 | GLsizei *length, |
| 4874 | GLint *params) |
| 4875 | { |
| 4876 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4877 | { |
| 4878 | return false; |
| 4879 | } |
| 4880 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4881 | GLsizei writeLength = 0; |
| 4882 | |
| 4883 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4884 | { |
| 4885 | return false; |
| 4886 | } |
| 4887 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4888 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
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 | SetRobustLengthParam(length, writeLength); |
| 4894 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4895 | return true; |
| 4896 | } |
| 4897 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4898 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4899 | GLuint index, |
| 4900 | GLenum pname, |
| 4901 | GLsizei bufSize, |
| 4902 | GLsizei *length, |
| 4903 | void **pointer) |
| 4904 | { |
| 4905 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4906 | { |
| 4907 | return false; |
| 4908 | } |
| 4909 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4910 | GLsizei writeLength = 0; |
| 4911 | |
| 4912 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4913 | { |
| 4914 | return false; |
| 4915 | } |
| 4916 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4917 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
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 | SetRobustLengthParam(length, writeLength); |
| 4923 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4924 | return true; |
| 4925 | } |
| 4926 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4927 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4928 | GLuint index, |
| 4929 | GLenum pname, |
| 4930 | GLsizei bufSize, |
| 4931 | GLsizei *length, |
| 4932 | GLint *params) |
| 4933 | { |
| 4934 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4935 | { |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4939 | GLsizei writeLength = 0; |
| 4940 | |
| 4941 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4942 | { |
| 4943 | return false; |
| 4944 | } |
| 4945 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4946 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
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 | SetRobustLengthParam(length, writeLength); |
| 4952 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4953 | return true; |
| 4954 | } |
| 4955 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4956 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4957 | GLuint index, |
| 4958 | GLenum pname, |
| 4959 | GLsizei bufSize, |
| 4960 | GLsizei *length, |
| 4961 | GLuint *params) |
| 4962 | { |
| 4963 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4964 | { |
| 4965 | return false; |
| 4966 | } |
| 4967 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4968 | GLsizei writeLength = 0; |
| 4969 | |
| 4970 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4971 | { |
| 4972 | return false; |
| 4973 | } |
| 4974 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4975 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4976 | { |
| 4977 | return false; |
| 4978 | } |
| 4979 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4980 | SetRobustLengthParam(length, writeLength); |
| 4981 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4982 | return true; |
| 4983 | } |
| 4984 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4985 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 4986 | GLuint program, |
| 4987 | GLuint uniformBlockIndex, |
| 4988 | GLenum pname, |
| 4989 | GLsizei bufSize, |
| 4990 | GLsizei *length, |
| 4991 | GLint *params) |
| 4992 | { |
| 4993 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4994 | { |
| 4995 | return false; |
| 4996 | } |
| 4997 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4998 | GLsizei writeLength = 0; |
| 4999 | |
| 5000 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5001 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5002 | { |
| 5003 | return false; |
| 5004 | } |
| 5005 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5006 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5007 | { |
| 5008 | return false; |
| 5009 | } |
| 5010 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5011 | SetRobustLengthParam(length, writeLength); |
| 5012 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5013 | return true; |
| 5014 | } |
| 5015 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5016 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5017 | GLenum target, |
| 5018 | GLenum internalformat, |
| 5019 | GLenum pname, |
| 5020 | GLsizei bufSize, |
| 5021 | GLsizei *length, |
| 5022 | GLint *params) |
| 5023 | { |
| 5024 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5025 | { |
| 5026 | return false; |
| 5027 | } |
| 5028 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5029 | GLsizei numParams = 0; |
| 5030 | |
| 5031 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5032 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5033 | { |
| 5034 | return false; |
| 5035 | } |
| 5036 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5037 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5038 | { |
| 5039 | return false; |
| 5040 | } |
| 5041 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5042 | SetRobustLengthParam(length, numParams); |
| 5043 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5044 | return true; |
| 5045 | } |
| 5046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5047 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5048 | GLuint attribIndex, |
| 5049 | GLint size, |
| 5050 | GLenum type, |
| 5051 | GLboolean pureInteger) |
| 5052 | { |
| 5053 | const Caps &caps = context->getCaps(); |
| 5054 | if (attribIndex >= caps.maxVertexAttributes) |
| 5055 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5056 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5057 | return false; |
| 5058 | } |
| 5059 | |
| 5060 | if (size < 1 || size > 4) |
| 5061 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5062 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5063 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | switch (type) |
| 5067 | { |
| 5068 | case GL_BYTE: |
| 5069 | case GL_UNSIGNED_BYTE: |
| 5070 | case GL_SHORT: |
| 5071 | case GL_UNSIGNED_SHORT: |
| 5072 | break; |
| 5073 | |
| 5074 | case GL_INT: |
| 5075 | case GL_UNSIGNED_INT: |
| 5076 | if (context->getClientMajorVersion() < 3) |
| 5077 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5078 | context->handleError(InvalidEnum() |
| 5079 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5080 | return false; |
| 5081 | } |
| 5082 | break; |
| 5083 | |
| 5084 | case GL_FIXED: |
| 5085 | case GL_FLOAT: |
| 5086 | if (pureInteger) |
| 5087 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5088 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5089 | return false; |
| 5090 | } |
| 5091 | break; |
| 5092 | |
| 5093 | case GL_HALF_FLOAT: |
| 5094 | if (context->getClientMajorVersion() < 3) |
| 5095 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5096 | context->handleError(InvalidEnum() |
| 5097 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5098 | return false; |
| 5099 | } |
| 5100 | if (pureInteger) |
| 5101 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5102 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5103 | return false; |
| 5104 | } |
| 5105 | break; |
| 5106 | |
| 5107 | case GL_INT_2_10_10_10_REV: |
| 5108 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5109 | if (context->getClientMajorVersion() < 3) |
| 5110 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5111 | context->handleError(InvalidEnum() |
| 5112 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5113 | return false; |
| 5114 | } |
| 5115 | if (pureInteger) |
| 5116 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5117 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5118 | return false; |
| 5119 | } |
| 5120 | if (size != 4) |
| 5121 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5122 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5123 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5124 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5125 | return false; |
| 5126 | } |
| 5127 | break; |
| 5128 | |
| 5129 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5130 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5131 | return false; |
| 5132 | } |
| 5133 | |
| 5134 | return true; |
| 5135 | } |
| 5136 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5137 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5138 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5139 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5140 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5141 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5142 | GLint drawbuffer, |
| 5143 | const GLenum *validComponentTypes, |
| 5144 | size_t validComponentTypeCount) |
| 5145 | { |
| 5146 | const FramebufferAttachment *attachment = |
| 5147 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5148 | if (attachment) |
| 5149 | { |
| 5150 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5151 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5152 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5153 | { |
| 5154 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5155 | InvalidOperation() |
| 5156 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5157 | return false; |
| 5158 | } |
| 5159 | } |
| 5160 | |
| 5161 | return true; |
| 5162 | } |
| 5163 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5164 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5165 | { |
| 5166 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5167 | { |
| 5168 | return false; |
| 5169 | } |
| 5170 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5171 | gl::Buffer *pixelUnpackBuffer = |
| 5172 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5173 | if (pixelUnpackBuffer == nullptr) |
| 5174 | { |
| 5175 | if (dataSize < imageSize) |
| 5176 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5177 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5178 | } |
| 5179 | } |
| 5180 | return true; |
| 5181 | } |
| 5182 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5183 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5184 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5185 | GLenum pname, |
| 5186 | bool pointerVersion, |
| 5187 | GLsizei *numParams) |
| 5188 | { |
| 5189 | if (numParams) |
| 5190 | { |
| 5191 | *numParams = 0; |
| 5192 | } |
| 5193 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5194 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5195 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5196 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5197 | return false; |
| 5198 | } |
| 5199 | |
| 5200 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5201 | if (!buffer) |
| 5202 | { |
| 5203 | // 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] | 5204 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5205 | return false; |
| 5206 | } |
| 5207 | |
| 5208 | const Extensions &extensions = context->getExtensions(); |
| 5209 | |
| 5210 | switch (pname) |
| 5211 | { |
| 5212 | case GL_BUFFER_USAGE: |
| 5213 | case GL_BUFFER_SIZE: |
| 5214 | break; |
| 5215 | |
| 5216 | case GL_BUFFER_ACCESS_OES: |
| 5217 | if (!extensions.mapBuffer) |
| 5218 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5219 | context->handleError(InvalidEnum() |
| 5220 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5221 | return false; |
| 5222 | } |
| 5223 | break; |
| 5224 | |
| 5225 | case GL_BUFFER_MAPPED: |
| 5226 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5227 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5228 | !extensions.mapBufferRange) |
| 5229 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5230 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5231 | "GL_OES_mapbuffer or " |
| 5232 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5233 | return false; |
| 5234 | } |
| 5235 | break; |
| 5236 | |
| 5237 | case GL_BUFFER_MAP_POINTER: |
| 5238 | if (!pointerVersion) |
| 5239 | { |
| 5240 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5241 | InvalidEnum() |
| 5242 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5243 | return false; |
| 5244 | } |
| 5245 | break; |
| 5246 | |
| 5247 | case GL_BUFFER_ACCESS_FLAGS: |
| 5248 | case GL_BUFFER_MAP_OFFSET: |
| 5249 | case GL_BUFFER_MAP_LENGTH: |
| 5250 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5251 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5252 | context->handleError(InvalidEnum() |
| 5253 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5254 | return false; |
| 5255 | } |
| 5256 | break; |
| 5257 | |
| 5258 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5259 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | // All buffer parameter queries return one value. |
| 5264 | if (numParams) |
| 5265 | { |
| 5266 | *numParams = 1; |
| 5267 | } |
| 5268 | |
| 5269 | return true; |
| 5270 | } |
| 5271 | |
| 5272 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5273 | GLenum target, |
| 5274 | GLenum pname, |
| 5275 | GLsizei *length) |
| 5276 | { |
| 5277 | if (length) |
| 5278 | { |
| 5279 | *length = 0; |
| 5280 | } |
| 5281 | |
| 5282 | if (target != GL_RENDERBUFFER) |
| 5283 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5284 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5285 | return false; |
| 5286 | } |
| 5287 | |
| 5288 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5289 | if (renderbuffer == nullptr) |
| 5290 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5291 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5292 | return false; |
| 5293 | } |
| 5294 | |
| 5295 | switch (pname) |
| 5296 | { |
| 5297 | case GL_RENDERBUFFER_WIDTH: |
| 5298 | case GL_RENDERBUFFER_HEIGHT: |
| 5299 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5300 | case GL_RENDERBUFFER_RED_SIZE: |
| 5301 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5302 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5303 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5304 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5305 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5306 | break; |
| 5307 | |
| 5308 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5309 | if (!context->getExtensions().framebufferMultisample) |
| 5310 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5311 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5312 | return false; |
| 5313 | } |
| 5314 | break; |
| 5315 | |
| 5316 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5317 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5318 | return false; |
| 5319 | } |
| 5320 | |
| 5321 | if (length) |
| 5322 | { |
| 5323 | *length = 1; |
| 5324 | } |
| 5325 | return true; |
| 5326 | } |
| 5327 | |
| 5328 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5329 | { |
| 5330 | if (length) |
| 5331 | { |
| 5332 | *length = 0; |
| 5333 | } |
| 5334 | |
| 5335 | if (GetValidShader(context, shader) == nullptr) |
| 5336 | { |
| 5337 | return false; |
| 5338 | } |
| 5339 | |
| 5340 | switch (pname) |
| 5341 | { |
| 5342 | case GL_SHADER_TYPE: |
| 5343 | case GL_DELETE_STATUS: |
| 5344 | case GL_COMPILE_STATUS: |
| 5345 | case GL_INFO_LOG_LENGTH: |
| 5346 | case GL_SHADER_SOURCE_LENGTH: |
| 5347 | break; |
| 5348 | |
| 5349 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5350 | if (!context->getExtensions().translatedShaderSource) |
| 5351 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5352 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5353 | return false; |
| 5354 | } |
| 5355 | break; |
| 5356 | |
| 5357 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5358 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5359 | return false; |
| 5360 | } |
| 5361 | |
| 5362 | if (length) |
| 5363 | { |
| 5364 | *length = 1; |
| 5365 | } |
| 5366 | return true; |
| 5367 | } |
| 5368 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5369 | bool ValidateGetTexParameterBase(Context *context, |
| 5370 | TextureType target, |
| 5371 | GLenum pname, |
| 5372 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5373 | { |
| 5374 | if (length) |
| 5375 | { |
| 5376 | *length = 0; |
| 5377 | } |
| 5378 | |
| 5379 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5380 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5381 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5382 | return false; |
| 5383 | } |
| 5384 | |
| 5385 | if (context->getTargetTexture(target) == nullptr) |
| 5386 | { |
| 5387 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5388 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5389 | return false; |
| 5390 | } |
| 5391 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5392 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5393 | { |
| 5394 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5395 | return false; |
| 5396 | } |
| 5397 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5398 | switch (pname) |
| 5399 | { |
| 5400 | case GL_TEXTURE_MAG_FILTER: |
| 5401 | case GL_TEXTURE_MIN_FILTER: |
| 5402 | case GL_TEXTURE_WRAP_S: |
| 5403 | case GL_TEXTURE_WRAP_T: |
| 5404 | break; |
| 5405 | |
| 5406 | case GL_TEXTURE_USAGE_ANGLE: |
| 5407 | if (!context->getExtensions().textureUsage) |
| 5408 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5409 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5410 | return false; |
| 5411 | } |
| 5412 | break; |
| 5413 | |
| 5414 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5415 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5416 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5417 | return false; |
| 5418 | } |
| 5419 | break; |
| 5420 | |
| 5421 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5422 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5423 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5424 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5425 | return false; |
| 5426 | } |
| 5427 | break; |
| 5428 | |
| 5429 | case GL_TEXTURE_WRAP_R: |
| 5430 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5431 | case GL_TEXTURE_SWIZZLE_R: |
| 5432 | case GL_TEXTURE_SWIZZLE_G: |
| 5433 | case GL_TEXTURE_SWIZZLE_B: |
| 5434 | case GL_TEXTURE_SWIZZLE_A: |
| 5435 | case GL_TEXTURE_BASE_LEVEL: |
| 5436 | case GL_TEXTURE_MAX_LEVEL: |
| 5437 | case GL_TEXTURE_MIN_LOD: |
| 5438 | case GL_TEXTURE_MAX_LOD: |
| 5439 | case GL_TEXTURE_COMPARE_MODE: |
| 5440 | case GL_TEXTURE_COMPARE_FUNC: |
| 5441 | if (context->getClientMajorVersion() < 3) |
| 5442 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5443 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5444 | return false; |
| 5445 | } |
| 5446 | break; |
| 5447 | |
| 5448 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5449 | if (!context->getExtensions().textureSRGBDecode) |
| 5450 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5451 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5452 | return false; |
| 5453 | } |
| 5454 | break; |
| 5455 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5456 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5457 | if (context->getClientVersion() < Version(3, 1)) |
| 5458 | { |
| 5459 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5460 | return false; |
| 5461 | } |
| 5462 | break; |
| 5463 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5464 | case GL_GENERATE_MIPMAP: |
| 5465 | case GL_TEXTURE_CROP_RECT_OES: |
| 5466 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5467 | // after GL_OES_draw_texture functionality implemented |
| 5468 | if (context->getClientMajorVersion() > 1) |
| 5469 | { |
| 5470 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5471 | return false; |
| 5472 | } |
| 5473 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5474 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5475 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5476 | return false; |
| 5477 | } |
| 5478 | |
| 5479 | if (length) |
| 5480 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5481 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5482 | } |
| 5483 | return true; |
| 5484 | } |
| 5485 | |
| 5486 | bool ValidateGetVertexAttribBase(Context *context, |
| 5487 | GLuint index, |
| 5488 | GLenum pname, |
| 5489 | GLsizei *length, |
| 5490 | bool pointer, |
| 5491 | bool pureIntegerEntryPoint) |
| 5492 | { |
| 5493 | if (length) |
| 5494 | { |
| 5495 | *length = 0; |
| 5496 | } |
| 5497 | |
| 5498 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5499 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5500 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5501 | return false; |
| 5502 | } |
| 5503 | |
| 5504 | if (index >= context->getCaps().maxVertexAttributes) |
| 5505 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5506 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5507 | return false; |
| 5508 | } |
| 5509 | |
| 5510 | if (pointer) |
| 5511 | { |
| 5512 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5513 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5514 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5515 | return false; |
| 5516 | } |
| 5517 | } |
| 5518 | else |
| 5519 | { |
| 5520 | switch (pname) |
| 5521 | { |
| 5522 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5523 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5524 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5525 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5526 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5527 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5528 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5529 | break; |
| 5530 | |
| 5531 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5532 | static_assert( |
| 5533 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5534 | "ANGLE extension enums not equal to GL enums."); |
| 5535 | if (context->getClientMajorVersion() < 3 && |
| 5536 | !context->getExtensions().instancedArrays) |
| 5537 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5538 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5539 | "requires OpenGL ES 3.0 or " |
| 5540 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5541 | return false; |
| 5542 | } |
| 5543 | break; |
| 5544 | |
| 5545 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5546 | if (context->getClientMajorVersion() < 3) |
| 5547 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5548 | context->handleError( |
| 5549 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5550 | return false; |
| 5551 | } |
| 5552 | break; |
| 5553 | |
| 5554 | case GL_VERTEX_ATTRIB_BINDING: |
| 5555 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5556 | if (context->getClientVersion() < ES_3_1) |
| 5557 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5558 | context->handleError(InvalidEnum() |
| 5559 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5560 | return false; |
| 5561 | } |
| 5562 | break; |
| 5563 | |
| 5564 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5565 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5566 | return false; |
| 5567 | } |
| 5568 | } |
| 5569 | |
| 5570 | if (length) |
| 5571 | { |
| 5572 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5573 | { |
| 5574 | *length = 4; |
| 5575 | } |
| 5576 | else |
| 5577 | { |
| 5578 | *length = 1; |
| 5579 | } |
| 5580 | } |
| 5581 | |
| 5582 | return true; |
| 5583 | } |
| 5584 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5585 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5586 | GLint x, |
| 5587 | GLint y, |
| 5588 | GLsizei width, |
| 5589 | GLsizei height, |
| 5590 | GLenum format, |
| 5591 | GLenum type, |
| 5592 | GLsizei bufSize, |
| 5593 | GLsizei *length, |
| 5594 | GLsizei *columns, |
| 5595 | GLsizei *rows, |
| 5596 | void *pixels) |
| 5597 | { |
| 5598 | if (length != nullptr) |
| 5599 | { |
| 5600 | *length = 0; |
| 5601 | } |
| 5602 | if (rows != nullptr) |
| 5603 | { |
| 5604 | *rows = 0; |
| 5605 | } |
| 5606 | if (columns != nullptr) |
| 5607 | { |
| 5608 | *columns = 0; |
| 5609 | } |
| 5610 | |
| 5611 | if (width < 0 || height < 0) |
| 5612 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5613 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5614 | return false; |
| 5615 | } |
| 5616 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5617 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5618 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5619 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5620 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5621 | return false; |
| 5622 | } |
| 5623 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5624 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5625 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5626 | return false; |
| 5627 | } |
| 5628 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5629 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5630 | ASSERT(framebuffer); |
| 5631 | |
| 5632 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5633 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5634 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5635 | return false; |
| 5636 | } |
| 5637 | |
| 5638 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5639 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5640 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5641 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5642 | // situation is an application error that would lead to a crash in ANGLE. |
| 5643 | if (readBuffer == nullptr) |
| 5644 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5645 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5646 | return false; |
| 5647 | } |
| 5648 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5649 | // ANGLE_multiview, Revision 1: |
| 5650 | // 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] | 5651 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5652 | // in the current read framebuffer is more than one. |
| 5653 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5654 | { |
| 5655 | context->handleError(InvalidFramebufferOperation() |
| 5656 | << "Attempting to read from a multi-view framebuffer."); |
| 5657 | return false; |
| 5658 | } |
| 5659 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5660 | if (context->getExtensions().webglCompatibility) |
| 5661 | { |
| 5662 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5663 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5664 | // and type before validating the combination of format and type. However, the |
| 5665 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5666 | // verifies that GL_INVALID_OPERATION is generated. |
| 5667 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5668 | // dEQP/WebGL. |
| 5669 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5670 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5671 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5672 | return false; |
| 5673 | } |
| 5674 | |
| 5675 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5676 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5677 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5678 | return false; |
| 5679 | } |
| 5680 | } |
| 5681 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5682 | GLenum currentFormat = GL_NONE; |
| 5683 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5684 | |
| 5685 | GLenum currentType = GL_NONE; |
| 5686 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5687 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5688 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5689 | |
| 5690 | bool validFormatTypeCombination = |
| 5691 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5692 | |
| 5693 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5694 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5695 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5696 | return false; |
| 5697 | } |
| 5698 | |
| 5699 | // Check for pixel pack buffer related API errors |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5700 | gl::Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5701 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5702 | { |
| 5703 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5704 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5705 | return false; |
| 5706 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5707 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5708 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5709 | { |
| 5710 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5711 | return false; |
| 5712 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5713 | |
| 5714 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5715 | // would exceed the data store size. |
| 5716 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
| 5717 | const gl::Extents size(width, height, 1); |
| 5718 | const auto &pack = context->getGLState().getPackState(); |
| 5719 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5720 | GLuint endByte = 0; |
| 5721 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5722 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5723 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5724 | return false; |
| 5725 | } |
| 5726 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5727 | if (bufSize >= 0) |
| 5728 | { |
| 5729 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5730 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5731 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5732 | return false; |
| 5733 | } |
| 5734 | } |
| 5735 | |
| 5736 | if (pixelPackBuffer != nullptr) |
| 5737 | { |
| 5738 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5739 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5740 | checkedEndByte += checkedOffset; |
| 5741 | |
| 5742 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5743 | { |
| 5744 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5745 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5746 | return false; |
| 5747 | } |
| 5748 | } |
| 5749 | |
| 5750 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5751 | { |
| 5752 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5753 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5754 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5755 | return false; |
| 5756 | } |
| 5757 | |
| 5758 | *length = static_cast<GLsizei>(endByte); |
| 5759 | } |
| 5760 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5761 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5762 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5763 | if (start < 0) |
| 5764 | { |
| 5765 | // "subtract" the area that is less than 0 |
| 5766 | clippedExtent += start; |
| 5767 | } |
| 5768 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5769 | angle::CheckedNumeric<int> readExtent = start; |
| 5770 | readExtent += length; |
| 5771 | if (!readExtent.IsValid()) |
| 5772 | { |
| 5773 | return false; |
| 5774 | } |
| 5775 | |
| 5776 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5777 | { |
| 5778 | // Subtract the region to the right of the read buffer |
| 5779 | clippedExtent -= (readExtent - bufferSize); |
| 5780 | } |
| 5781 | |
| 5782 | if (!clippedExtent.IsValid()) |
| 5783 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5784 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5785 | } |
| 5786 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5787 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5788 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5789 | }; |
| 5790 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5791 | GLsizei writtenColumns = 0; |
| 5792 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5793 | { |
| 5794 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5795 | return false; |
| 5796 | } |
| 5797 | |
| 5798 | GLsizei writtenRows = 0; |
| 5799 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5800 | { |
| 5801 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5802 | return false; |
| 5803 | } |
| 5804 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5805 | if (columns != nullptr) |
| 5806 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5807 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5808 | } |
| 5809 | |
| 5810 | if (rows != nullptr) |
| 5811 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5812 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5813 | } |
| 5814 | |
| 5815 | return true; |
| 5816 | } |
| 5817 | |
| 5818 | template <typename ParamType> |
| 5819 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5820 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5821 | GLenum pname, |
| 5822 | GLsizei bufSize, |
| 5823 | const ParamType *params) |
| 5824 | { |
| 5825 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5826 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5827 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5828 | return false; |
| 5829 | } |
| 5830 | |
| 5831 | if (context->getTargetTexture(target) == nullptr) |
| 5832 | { |
| 5833 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5834 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5835 | return false; |
| 5836 | } |
| 5837 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5838 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5839 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5840 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5841 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5842 | return false; |
| 5843 | } |
| 5844 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5845 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5846 | { |
| 5847 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5848 | return false; |
| 5849 | } |
| 5850 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5851 | switch (pname) |
| 5852 | { |
| 5853 | case GL_TEXTURE_WRAP_R: |
| 5854 | case GL_TEXTURE_SWIZZLE_R: |
| 5855 | case GL_TEXTURE_SWIZZLE_G: |
| 5856 | case GL_TEXTURE_SWIZZLE_B: |
| 5857 | case GL_TEXTURE_SWIZZLE_A: |
| 5858 | case GL_TEXTURE_BASE_LEVEL: |
| 5859 | case GL_TEXTURE_MAX_LEVEL: |
| 5860 | case GL_TEXTURE_COMPARE_MODE: |
| 5861 | case GL_TEXTURE_COMPARE_FUNC: |
| 5862 | case GL_TEXTURE_MIN_LOD: |
| 5863 | case GL_TEXTURE_MAX_LOD: |
| 5864 | if (context->getClientMajorVersion() < 3) |
| 5865 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5866 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5867 | return false; |
| 5868 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5869 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5870 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5871 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5872 | "available without " |
| 5873 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5874 | return false; |
| 5875 | } |
| 5876 | break; |
| 5877 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5878 | case GL_GENERATE_MIPMAP: |
| 5879 | case GL_TEXTURE_CROP_RECT_OES: |
| 5880 | if (context->getClientMajorVersion() > 1) |
| 5881 | { |
| 5882 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5883 | return false; |
| 5884 | } |
| 5885 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5886 | default: |
| 5887 | break; |
| 5888 | } |
| 5889 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5890 | if (target == TextureType::_2DMultisample) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5891 | { |
| 5892 | switch (pname) |
| 5893 | { |
| 5894 | case GL_TEXTURE_MIN_FILTER: |
| 5895 | case GL_TEXTURE_MAG_FILTER: |
| 5896 | case GL_TEXTURE_WRAP_S: |
| 5897 | case GL_TEXTURE_WRAP_T: |
| 5898 | case GL_TEXTURE_WRAP_R: |
| 5899 | case GL_TEXTURE_MIN_LOD: |
| 5900 | case GL_TEXTURE_MAX_LOD: |
| 5901 | case GL_TEXTURE_COMPARE_MODE: |
| 5902 | case GL_TEXTURE_COMPARE_FUNC: |
| 5903 | context->handleError(InvalidEnum() |
| 5904 | << "Invalid parameter for 2D multisampled textures."); |
| 5905 | return false; |
| 5906 | } |
| 5907 | } |
| 5908 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5909 | switch (pname) |
| 5910 | { |
| 5911 | case GL_TEXTURE_WRAP_S: |
| 5912 | case GL_TEXTURE_WRAP_T: |
| 5913 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5914 | { |
| 5915 | bool restrictedWrapModes = |
| 5916 | target == TextureType::External || target == TextureType::Rectangle; |
| 5917 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5918 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5919 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5920 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5921 | } |
| 5922 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5923 | |
| 5924 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5925 | { |
| 5926 | bool restrictedMinFilter = |
| 5927 | target == TextureType::External || target == TextureType::Rectangle; |
| 5928 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5929 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5930 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5931 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5932 | } |
| 5933 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5934 | |
| 5935 | case GL_TEXTURE_MAG_FILTER: |
| 5936 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5937 | { |
| 5938 | return false; |
| 5939 | } |
| 5940 | break; |
| 5941 | |
| 5942 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5943 | if (!context->getExtensions().textureUsage) |
| 5944 | { |
| 5945 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5946 | return false; |
| 5947 | } |
| 5948 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5949 | switch (ConvertToGLenum(params[0])) |
| 5950 | { |
| 5951 | case GL_NONE: |
| 5952 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5953 | break; |
| 5954 | |
| 5955 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5956 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5957 | return false; |
| 5958 | } |
| 5959 | break; |
| 5960 | |
| 5961 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5962 | { |
| 5963 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5964 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5965 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5966 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5967 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5968 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 5969 | } |
| 5970 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5971 | |
| 5972 | case GL_TEXTURE_MIN_LOD: |
| 5973 | case GL_TEXTURE_MAX_LOD: |
| 5974 | // any value is permissible |
| 5975 | break; |
| 5976 | |
| 5977 | case GL_TEXTURE_COMPARE_MODE: |
| 5978 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5979 | { |
| 5980 | return false; |
| 5981 | } |
| 5982 | break; |
| 5983 | |
| 5984 | case GL_TEXTURE_COMPARE_FUNC: |
| 5985 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5986 | { |
| 5987 | return false; |
| 5988 | } |
| 5989 | break; |
| 5990 | |
| 5991 | case GL_TEXTURE_SWIZZLE_R: |
| 5992 | case GL_TEXTURE_SWIZZLE_G: |
| 5993 | case GL_TEXTURE_SWIZZLE_B: |
| 5994 | case GL_TEXTURE_SWIZZLE_A: |
| 5995 | switch (ConvertToGLenum(params[0])) |
| 5996 | { |
| 5997 | case GL_RED: |
| 5998 | case GL_GREEN: |
| 5999 | case GL_BLUE: |
| 6000 | case GL_ALPHA: |
| 6001 | case GL_ZERO: |
| 6002 | case GL_ONE: |
| 6003 | break; |
| 6004 | |
| 6005 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6006 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6007 | return false; |
| 6008 | } |
| 6009 | break; |
| 6010 | |
| 6011 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6012 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6013 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6014 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6015 | return false; |
| 6016 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6017 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6018 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6019 | context->handleError(InvalidOperation() |
| 6020 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6021 | return false; |
| 6022 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6023 | if (target == TextureType::_2DMultisample && static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6024 | { |
| 6025 | context->handleError(InvalidOperation() |
| 6026 | << "Base level must be 0 for multisampled textures."); |
| 6027 | return false; |
| 6028 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6029 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6030 | { |
| 6031 | context->handleError(InvalidOperation() |
| 6032 | << "Base level must be 0 for rectangle textures."); |
| 6033 | return false; |
| 6034 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6035 | break; |
| 6036 | |
| 6037 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6038 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6039 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6040 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6041 | return false; |
| 6042 | } |
| 6043 | break; |
| 6044 | |
| 6045 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6046 | if (context->getClientVersion() < Version(3, 1)) |
| 6047 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6048 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | return false; |
| 6050 | } |
| 6051 | switch (ConvertToGLenum(params[0])) |
| 6052 | { |
| 6053 | case GL_DEPTH_COMPONENT: |
| 6054 | case GL_STENCIL_INDEX: |
| 6055 | break; |
| 6056 | |
| 6057 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6058 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6059 | return false; |
| 6060 | } |
| 6061 | break; |
| 6062 | |
| 6063 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6064 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6065 | { |
| 6066 | return false; |
| 6067 | } |
| 6068 | break; |
| 6069 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6070 | case GL_GENERATE_MIPMAP: |
| 6071 | case GL_TEXTURE_CROP_RECT_OES: |
| 6072 | if (context->getClientMajorVersion() > 1) |
| 6073 | { |
| 6074 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6075 | return false; |
| 6076 | } |
| 6077 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6078 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6079 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6080 | return false; |
| 6081 | } |
| 6082 | |
| 6083 | return true; |
| 6084 | } |
| 6085 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6086 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 6087 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6088 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6089 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6090 | { |
| 6091 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6092 | { |
| 6093 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6094 | return false; |
| 6095 | } |
| 6096 | |
| 6097 | return true; |
| 6098 | } |
| 6099 | |
| 6100 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6101 | GLuint program, |
| 6102 | GLuint uniformBlockIndex, |
| 6103 | GLenum pname, |
| 6104 | GLsizei *length) |
| 6105 | { |
| 6106 | if (length) |
| 6107 | { |
| 6108 | *length = 0; |
| 6109 | } |
| 6110 | |
| 6111 | if (context->getClientMajorVersion() < 3) |
| 6112 | { |
| 6113 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6114 | return false; |
| 6115 | } |
| 6116 | |
| 6117 | Program *programObject = GetValidProgram(context, program); |
| 6118 | if (!programObject) |
| 6119 | { |
| 6120 | return false; |
| 6121 | } |
| 6122 | |
| 6123 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6124 | { |
| 6125 | context->handleError(InvalidValue() |
| 6126 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6127 | return false; |
| 6128 | } |
| 6129 | |
| 6130 | switch (pname) |
| 6131 | { |
| 6132 | case GL_UNIFORM_BLOCK_BINDING: |
| 6133 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6134 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6135 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6136 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6137 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6138 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6139 | break; |
| 6140 | |
| 6141 | default: |
| 6142 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6143 | return false; |
| 6144 | } |
| 6145 | |
| 6146 | if (length) |
| 6147 | { |
| 6148 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6149 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6150 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6151 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6152 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6153 | } |
| 6154 | else |
| 6155 | { |
| 6156 | *length = 1; |
| 6157 | } |
| 6158 | } |
| 6159 | |
| 6160 | return true; |
| 6161 | } |
| 6162 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6163 | template <typename ParamType> |
| 6164 | bool ValidateSamplerParameterBase(Context *context, |
| 6165 | GLuint sampler, |
| 6166 | GLenum pname, |
| 6167 | GLsizei bufSize, |
| 6168 | ParamType *params) |
| 6169 | { |
| 6170 | if (context->getClientMajorVersion() < 3) |
| 6171 | { |
| 6172 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6173 | return false; |
| 6174 | } |
| 6175 | |
| 6176 | if (!context->isSampler(sampler)) |
| 6177 | { |
| 6178 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6179 | return false; |
| 6180 | } |
| 6181 | |
| 6182 | const GLsizei minBufSize = 1; |
| 6183 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6184 | { |
| 6185 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6186 | return false; |
| 6187 | } |
| 6188 | |
| 6189 | switch (pname) |
| 6190 | { |
| 6191 | case GL_TEXTURE_WRAP_S: |
| 6192 | case GL_TEXTURE_WRAP_T: |
| 6193 | case GL_TEXTURE_WRAP_R: |
| 6194 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6195 | { |
| 6196 | return false; |
| 6197 | } |
| 6198 | break; |
| 6199 | |
| 6200 | case GL_TEXTURE_MIN_FILTER: |
| 6201 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6202 | { |
| 6203 | return false; |
| 6204 | } |
| 6205 | break; |
| 6206 | |
| 6207 | case GL_TEXTURE_MAG_FILTER: |
| 6208 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6209 | { |
| 6210 | return false; |
| 6211 | } |
| 6212 | break; |
| 6213 | |
| 6214 | case GL_TEXTURE_MIN_LOD: |
| 6215 | case GL_TEXTURE_MAX_LOD: |
| 6216 | // any value is permissible |
| 6217 | break; |
| 6218 | |
| 6219 | case GL_TEXTURE_COMPARE_MODE: |
| 6220 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6221 | { |
| 6222 | return false; |
| 6223 | } |
| 6224 | break; |
| 6225 | |
| 6226 | case GL_TEXTURE_COMPARE_FUNC: |
| 6227 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6228 | { |
| 6229 | return false; |
| 6230 | } |
| 6231 | break; |
| 6232 | |
| 6233 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6234 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6235 | { |
| 6236 | return false; |
| 6237 | } |
| 6238 | break; |
| 6239 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6240 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6241 | { |
| 6242 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6243 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6244 | { |
| 6245 | return false; |
| 6246 | } |
| 6247 | } |
| 6248 | break; |
| 6249 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6250 | default: |
| 6251 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6252 | return false; |
| 6253 | } |
| 6254 | |
| 6255 | return true; |
| 6256 | } |
| 6257 | |
| 6258 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 6259 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 6260 | |
| 6261 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6262 | GLuint sampler, |
| 6263 | GLenum pname, |
| 6264 | GLsizei *length) |
| 6265 | { |
| 6266 | if (length) |
| 6267 | { |
| 6268 | *length = 0; |
| 6269 | } |
| 6270 | |
| 6271 | if (context->getClientMajorVersion() < 3) |
| 6272 | { |
| 6273 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6274 | return false; |
| 6275 | } |
| 6276 | |
| 6277 | if (!context->isSampler(sampler)) |
| 6278 | { |
| 6279 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6280 | return false; |
| 6281 | } |
| 6282 | |
| 6283 | switch (pname) |
| 6284 | { |
| 6285 | case GL_TEXTURE_WRAP_S: |
| 6286 | case GL_TEXTURE_WRAP_T: |
| 6287 | case GL_TEXTURE_WRAP_R: |
| 6288 | case GL_TEXTURE_MIN_FILTER: |
| 6289 | case GL_TEXTURE_MAG_FILTER: |
| 6290 | case GL_TEXTURE_MIN_LOD: |
| 6291 | case GL_TEXTURE_MAX_LOD: |
| 6292 | case GL_TEXTURE_COMPARE_MODE: |
| 6293 | case GL_TEXTURE_COMPARE_FUNC: |
| 6294 | break; |
| 6295 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6296 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6297 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6298 | { |
| 6299 | return false; |
| 6300 | } |
| 6301 | break; |
| 6302 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6303 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6304 | if (!context->getExtensions().textureSRGBDecode) |
| 6305 | { |
| 6306 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6307 | return false; |
| 6308 | } |
| 6309 | break; |
| 6310 | |
| 6311 | default: |
| 6312 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6313 | return false; |
| 6314 | } |
| 6315 | |
| 6316 | if (length) |
| 6317 | { |
| 6318 | *length = 1; |
| 6319 | } |
| 6320 | return true; |
| 6321 | } |
| 6322 | |
| 6323 | bool ValidateGetInternalFormativBase(Context *context, |
| 6324 | GLenum target, |
| 6325 | GLenum internalformat, |
| 6326 | GLenum pname, |
| 6327 | GLsizei bufSize, |
| 6328 | GLsizei *numParams) |
| 6329 | { |
| 6330 | if (numParams) |
| 6331 | { |
| 6332 | *numParams = 0; |
| 6333 | } |
| 6334 | |
| 6335 | if (context->getClientMajorVersion() < 3) |
| 6336 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6338 | return false; |
| 6339 | } |
| 6340 | |
| 6341 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6342 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6343 | { |
| 6344 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6345 | return false; |
| 6346 | } |
| 6347 | |
| 6348 | switch (target) |
| 6349 | { |
| 6350 | case GL_RENDERBUFFER: |
| 6351 | break; |
| 6352 | |
| 6353 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 6354 | if (context->getClientVersion() < ES_3_1) |
| 6355 | { |
| 6356 | context->handleError(InvalidOperation() |
| 6357 | << "Texture target requires at least OpenGL ES 3.1."); |
| 6358 | return false; |
| 6359 | } |
| 6360 | break; |
| 6361 | |
| 6362 | default: |
| 6363 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6364 | return false; |
| 6365 | } |
| 6366 | |
| 6367 | if (bufSize < 0) |
| 6368 | { |
| 6369 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6370 | return false; |
| 6371 | } |
| 6372 | |
| 6373 | GLsizei maxWriteParams = 0; |
| 6374 | switch (pname) |
| 6375 | { |
| 6376 | case GL_NUM_SAMPLE_COUNTS: |
| 6377 | maxWriteParams = 1; |
| 6378 | break; |
| 6379 | |
| 6380 | case GL_SAMPLES: |
| 6381 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6382 | break; |
| 6383 | |
| 6384 | default: |
| 6385 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6386 | return false; |
| 6387 | } |
| 6388 | |
| 6389 | if (numParams) |
| 6390 | { |
| 6391 | // glGetInternalFormativ will not overflow bufSize |
| 6392 | *numParams = std::min(bufSize, maxWriteParams); |
| 6393 | } |
| 6394 | |
| 6395 | return true; |
| 6396 | } |
| 6397 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6398 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6399 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6400 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6401 | { |
| 6402 | context->handleError(InvalidOperation()); |
| 6403 | return false; |
| 6404 | } |
| 6405 | return true; |
| 6406 | } |
| 6407 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6408 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6409 | { |
| 6410 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6411 | { |
| 6412 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6413 | return false; |
| 6414 | } |
| 6415 | return true; |
| 6416 | } |
| 6417 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6418 | } // namespace gl |