Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 12 | #include "libANGLE/Display.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 13 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Query.h" |
| 19 | #include "libANGLE/Texture.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 24 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 25 | #include "libANGLE/queryutils.h" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 26 | #include "libANGLE/validationES2_autogen.h" |
| 27 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 28 | |
| 29 | #include "common/mathutil.h" |
| 30 | #include "common/utilities.h" |
| 31 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 32 | using namespace angle; |
| 33 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 36 | using namespace err; |
| 37 | |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 38 | namespace |
| 39 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 40 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 41 | { |
| 42 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 43 | // the compressed block size. |
| 44 | switch (internalFormat) |
| 45 | { |
| 46 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 48 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 49 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 50 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 52 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 53 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 54 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 59 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 60 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 61 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 62 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 63 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 64 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 65 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 66 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 67 | default: |
| 68 | return false; |
| 69 | } |
| 70 | } |
| 71 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 72 | { |
| 73 | // Compressed sub textures have additional formats that requires exact size. |
| 74 | // ES 3.1, Section 8.7, Page 171 |
| 75 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 76 | IsETC2EACFormat(internalFormat); |
| 77 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 78 | |
| 79 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 80 | { |
| 81 | CheckedNumeric<GLint> checkedA(a); |
| 82 | checkedA -= b; |
| 83 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 84 | checkedA = -checkedA; |
| 85 | return !checkedA.IsValid(); |
| 86 | } |
| 87 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 88 | bool ValidateDrawAttribsImpl(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 89 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 90 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 91 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 92 | |
Jamie Madill | 88602e6 | 2018-08-08 12:49:30 -0400 | [diff] [blame] | 93 | // An overflow can happen when adding the offset. Check against a special constant. |
| 94 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 95 | VertexAttribute::kIntegerOverflow || |
| 96 | context->getStateCache().getInstancedVertexElementLimit() == |
| 97 | VertexAttribute::kIntegerOverflow) |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 98 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 104 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 105 | context->validationError(GL_INVALID_OPERATION, kInsufficientVertexBufferSize); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 106 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 109 | ANGLE_INLINE bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
| 110 | { |
| 111 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 112 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
| 113 | { |
| 114 | return true; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | return ValidateDrawAttribsImpl(context, primcount, maxVertex); |
| 119 | } |
| 120 | } |
| 121 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 122 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 123 | { |
| 124 | switch (type) |
| 125 | { |
| 126 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 127 | case GL_UNSIGNED_BYTE: |
| 128 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 129 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 130 | case GL_UNSIGNED_SHORT_5_6_5: |
| 131 | return context->getClientVersion() >= ES_2_0; |
| 132 | |
| 133 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 134 | case GL_BYTE: |
| 135 | case GL_INT: |
| 136 | case GL_SHORT: |
| 137 | case GL_UNSIGNED_INT: |
| 138 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 139 | case GL_UNSIGNED_INT_24_8: |
| 140 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 141 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 142 | case GL_UNSIGNED_SHORT: |
| 143 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 144 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 145 | return context->getClientVersion() >= ES_3_0; |
| 146 | |
| 147 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 148 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 149 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 150 | |
| 151 | case GL_HALF_FLOAT: |
| 152 | return context->getClientVersion() >= ES_3_0 || |
| 153 | context->getExtensions().textureHalfFloat; |
| 154 | |
| 155 | case GL_HALF_FLOAT_OES: |
| 156 | return context->getExtensions().colorBufferHalfFloat; |
| 157 | |
| 158 | default: |
| 159 | return false; |
| 160 | } |
| 161 | } |
| 162 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 163 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 164 | { |
| 165 | switch (format) |
| 166 | { |
| 167 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 168 | case GL_RGBA: |
| 169 | case GL_RGB: |
| 170 | case GL_ALPHA: |
| 171 | return context->getClientVersion() >= ES_2_0; |
| 172 | |
| 173 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 174 | case GL_RG: |
| 175 | case GL_RED: |
| 176 | case GL_RGBA_INTEGER: |
| 177 | case GL_RGB_INTEGER: |
| 178 | case GL_RG_INTEGER: |
| 179 | case GL_RED_INTEGER: |
| 180 | return context->getClientVersion() >= ES_3_0; |
| 181 | |
| 182 | case GL_SRGB_ALPHA_EXT: |
| 183 | case GL_SRGB_EXT: |
| 184 | return context->getExtensions().sRGB; |
| 185 | |
| 186 | case GL_BGRA_EXT: |
| 187 | return context->getExtensions().readFormatBGRA; |
| 188 | |
| 189 | default: |
| 190 | return false; |
| 191 | } |
| 192 | } |
| 193 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 194 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 195 | GLenum framebufferComponentType, |
| 196 | GLenum format, |
| 197 | GLenum type) |
| 198 | { |
| 199 | switch (framebufferComponentType) |
| 200 | { |
| 201 | case GL_UNSIGNED_NORMALIZED: |
| 202 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 203 | // ReadPixels with BGRA even if the extension is not present |
| 204 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 205 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 206 | type == GL_UNSIGNED_BYTE); |
| 207 | |
| 208 | case GL_SIGNED_NORMALIZED: |
| 209 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 210 | |
| 211 | case GL_INT: |
| 212 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 213 | |
| 214 | case GL_UNSIGNED_INT: |
| 215 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 216 | |
| 217 | case GL_FLOAT: |
| 218 | return (format == GL_RGBA && type == GL_FLOAT); |
| 219 | |
| 220 | default: |
| 221 | UNREACHABLE(); |
| 222 | return false; |
| 223 | } |
| 224 | } |
| 225 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 226 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 227 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 228 | { |
| 229 | switch (ConvertToGLenum(params[0])) |
| 230 | { |
| 231 | case GL_CLAMP_TO_EDGE: |
| 232 | break; |
| 233 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 234 | case GL_CLAMP_TO_BORDER: |
| 235 | if (!context->getExtensions().textureBorderClamp) |
| 236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 237 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | break; |
| 241 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 242 | case GL_REPEAT: |
| 243 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 244 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 245 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 246 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 247 | context->validationError(GL_INVALID_ENUM, kInvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 253 | context->validationError(GL_INVALID_ENUM, kInvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 254 | return false; |
| 255 | } |
| 256 | |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 261 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 262 | { |
| 263 | switch (ConvertToGLenum(params[0])) |
| 264 | { |
| 265 | case GL_NEAREST: |
| 266 | case GL_LINEAR: |
| 267 | break; |
| 268 | |
| 269 | case GL_NEAREST_MIPMAP_NEAREST: |
| 270 | case GL_LINEAR_MIPMAP_NEAREST: |
| 271 | case GL_NEAREST_MIPMAP_LINEAR: |
| 272 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 273 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 274 | { |
| 275 | // OES_EGL_image_external specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 276 | context->validationError(GL_INVALID_ENUM, kInvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | break; |
| 280 | |
| 281 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 282 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 283 | return false; |
| 284 | } |
| 285 | |
| 286 | return true; |
| 287 | } |
| 288 | |
| 289 | template <typename ParamType> |
| 290 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 291 | { |
| 292 | switch (ConvertToGLenum(params[0])) |
| 293 | { |
| 294 | case GL_NEAREST: |
| 295 | case GL_LINEAR: |
| 296 | break; |
| 297 | |
| 298 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 299 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
| 303 | return true; |
| 304 | } |
| 305 | |
| 306 | template <typename ParamType> |
| 307 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 308 | { |
| 309 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 310 | switch (ConvertToGLenum(params[0])) |
| 311 | { |
| 312 | case GL_NONE: |
| 313 | case GL_COMPARE_REF_TO_TEXTURE: |
| 314 | break; |
| 315 | |
| 316 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 317 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | template <typename ParamType> |
| 325 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 326 | { |
| 327 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 328 | switch (ConvertToGLenum(params[0])) |
| 329 | { |
| 330 | case GL_LEQUAL: |
| 331 | case GL_GEQUAL: |
| 332 | case GL_LESS: |
| 333 | case GL_GREATER: |
| 334 | case GL_EQUAL: |
| 335 | case GL_NOTEQUAL: |
| 336 | case GL_ALWAYS: |
| 337 | case GL_NEVER: |
| 338 | break; |
| 339 | |
| 340 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 341 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 342 | return false; |
| 343 | } |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 349 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 350 | { |
| 351 | if (!context->getExtensions().textureSRGBDecode) |
| 352 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 353 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | |
| 357 | switch (ConvertToGLenum(params[0])) |
| 358 | { |
| 359 | case GL_DECODE_EXT: |
| 360 | case GL_SKIP_DECODE_EXT: |
| 361 | break; |
| 362 | |
| 363 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 364 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 365 | return false; |
| 366 | } |
| 367 | |
| 368 | return true; |
| 369 | } |
| 370 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 371 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 372 | { |
| 373 | if (!context->getExtensions().textureFilterAnisotropic) |
| 374 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 375 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 376 | return false; |
| 377 | } |
| 378 | |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 383 | { |
| 384 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 385 | { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 390 | |
| 391 | if (paramValue < 1 || paramValue > largest) |
| 392 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 393 | context->validationError(GL_INVALID_VALUE, kOutsideOfBounds); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 394 | return false; |
| 395 | } |
| 396 | |
| 397 | return true; |
| 398 | } |
| 399 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 400 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 401 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 402 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 403 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 404 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 405 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 406 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 407 | program->getActiveOutputVariables().to_ulong(), |
| 408 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 411 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 412 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 413 | const auto &glState = context->getGLState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 414 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 415 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 416 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 417 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 418 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 419 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 420 | |
| 421 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 422 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 423 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 424 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 425 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 426 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 427 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 430 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 431 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 432 | { |
| 433 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 434 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 435 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 436 | case PrimitiveMode::Points: |
| 437 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 438 | case PrimitiveMode::Lines: |
| 439 | case PrimitiveMode::LineStrip: |
| 440 | case PrimitiveMode::LineLoop: |
| 441 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 442 | case PrimitiveMode::LinesAdjacency: |
| 443 | case PrimitiveMode::LineStripAdjacency: |
| 444 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 445 | case PrimitiveMode::Triangles: |
| 446 | case PrimitiveMode::TriangleFan: |
| 447 | case PrimitiveMode::TriangleStrip: |
| 448 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 449 | case PrimitiveMode::TrianglesAdjacency: |
| 450 | case PrimitiveMode::TriangleStripAdjacency: |
| 451 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 452 | default: |
| 453 | UNREACHABLE(); |
| 454 | return false; |
| 455 | } |
| 456 | } |
| 457 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 458 | // GLES1 texture parameters are a small subset of the others |
| 459 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 460 | { |
| 461 | switch (pname) |
| 462 | { |
| 463 | case GL_TEXTURE_MAG_FILTER: |
| 464 | case GL_TEXTURE_MIN_FILTER: |
| 465 | case GL_TEXTURE_WRAP_S: |
| 466 | case GL_TEXTURE_WRAP_T: |
| 467 | case GL_TEXTURE_WRAP_R: |
| 468 | case GL_GENERATE_MIPMAP: |
| 469 | case GL_TEXTURE_CROP_RECT_OES: |
| 470 | return true; |
| 471 | default: |
| 472 | return false; |
| 473 | } |
| 474 | } |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 475 | |
| 476 | unsigned int GetSamplerParameterCount(GLenum pname) |
| 477 | { |
| 478 | return pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1; |
| 479 | } |
| 480 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 481 | } // anonymous namespace |
| 482 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 483 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 484 | { |
| 485 | if (length) |
| 486 | { |
| 487 | *length = value; |
| 488 | } |
| 489 | } |
| 490 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 491 | bool IsETC2EACFormat(const GLenum format) |
| 492 | { |
| 493 | // ES 3.1, Table 8.19 |
| 494 | switch (format) |
| 495 | { |
| 496 | case GL_COMPRESSED_R11_EAC: |
| 497 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 498 | case GL_COMPRESSED_RG11_EAC: |
| 499 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 500 | case GL_COMPRESSED_RGB8_ETC2: |
| 501 | case GL_COMPRESSED_SRGB8_ETC2: |
| 502 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 503 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 504 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 505 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 506 | return true; |
| 507 | |
| 508 | default: |
| 509 | return false; |
| 510 | } |
| 511 | } |
| 512 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 513 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 514 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 515 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 516 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 517 | case TextureType::_2D: |
| 518 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 519 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 520 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 521 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 522 | return context->getExtensions().textureRectangle; |
| 523 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 524 | case TextureType::_3D: |
| 525 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 526 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 527 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 528 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 529 | return (context->getClientVersion() >= Version(3, 1) || |
| 530 | context->getExtensions().textureMultisample); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 531 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 532 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 533 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 534 | default: |
| 535 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 536 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 539 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 540 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 541 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 542 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 543 | case TextureType::_2D: |
| 544 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 545 | return true; |
| 546 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 547 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 548 | return context->getExtensions().textureRectangle; |
| 549 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 550 | default: |
| 551 | return false; |
| 552 | } |
| 553 | } |
| 554 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 555 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 556 | { |
| 557 | switch (target) |
| 558 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 559 | case TextureType::_3D: |
| 560 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 561 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 562 | |
| 563 | default: |
| 564 | return false; |
| 565 | } |
| 566 | } |
| 567 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 568 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 569 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 570 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 571 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 572 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 573 | (context->getExtensions().eglImageExternal || |
| 574 | context->getExtensions().eglStreamConsumerExternal); |
| 575 | } |
| 576 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 577 | // This function differs from ValidTextureTarget in that the target must be |
| 578 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 579 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 580 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 581 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 582 | { |
| 583 | switch (target) |
| 584 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 585 | case TextureTarget::_2D: |
| 586 | case TextureTarget::CubeMapNegativeX: |
| 587 | case TextureTarget::CubeMapNegativeY: |
| 588 | case TextureTarget::CubeMapNegativeZ: |
| 589 | case TextureTarget::CubeMapPositiveX: |
| 590 | case TextureTarget::CubeMapPositiveY: |
| 591 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 592 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 593 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 594 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 595 | default: |
| 596 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 600 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 601 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 602 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 603 | { |
| 604 | ASSERT(context); |
| 605 | |
| 606 | if (!context->getExtensions().geometryShader) |
| 607 | { |
| 608 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 609 | // that does not match the current transform feedback object's draw mode (if transform |
| 610 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 611 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 612 | } |
| 613 | |
| 614 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 615 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 616 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 617 | case PrimitiveMode::Points: |
| 618 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 619 | case PrimitiveMode::Lines: |
| 620 | case PrimitiveMode::LineStrip: |
| 621 | case PrimitiveMode::LineLoop: |
| 622 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 623 | case PrimitiveMode::Triangles: |
| 624 | case PrimitiveMode::TriangleFan: |
| 625 | case PrimitiveMode::TriangleStrip: |
| 626 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 627 | default: |
| 628 | UNREACHABLE(); |
| 629 | return false; |
| 630 | } |
| 631 | } |
| 632 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 633 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 634 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 636 | DrawElementsType type, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 637 | const GLvoid *indices, |
| 638 | GLsizei primcount) |
| 639 | { |
| 640 | if (primcount < 0) |
| 641 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 642 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 643 | return false; |
| 644 | } |
| 645 | |
| 646 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 647 | { |
| 648 | return false; |
| 649 | } |
| 650 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 651 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 655 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 656 | GLint first, |
| 657 | GLsizei count, |
| 658 | GLsizei primcount) |
| 659 | { |
| 660 | if (primcount < 0) |
| 661 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 662 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 663 | return false; |
| 664 | } |
| 665 | |
| 666 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 667 | { |
| 668 | return false; |
| 669 | } |
| 670 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 671 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 672 | } |
| 673 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 674 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | { |
| 676 | // Verify there is at least one active attribute with a divisor of zero |
| 677 | const State &state = context->getGLState(); |
| 678 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 679 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 680 | |
| 681 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 682 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 683 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 684 | { |
| 685 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 686 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 687 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 688 | { |
| 689 | return true; |
| 690 | } |
| 691 | } |
| 692 | |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 693 | context->validationError(GL_INVALID_OPERATION, kNoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 697 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 698 | { |
| 699 | switch (target) |
| 700 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 701 | case TextureType::_3D: |
| 702 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 703 | return true; |
| 704 | default: |
| 705 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 709 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 710 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 711 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 712 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 713 | case TextureType::_2D: |
| 714 | case TextureType::_2DArray: |
| 715 | case TextureType::_2DMultisample: |
| 716 | case TextureType::CubeMap: |
| 717 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 718 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 719 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 720 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 721 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 722 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 723 | default: |
| 724 | return false; |
| 725 | } |
| 726 | } |
| 727 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 728 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 729 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 730 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 731 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 732 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 733 | |
| 734 | switch (target) |
| 735 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 736 | case GL_FRAMEBUFFER: |
| 737 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 738 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 739 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 740 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 741 | return (context->getExtensions().framebufferBlit || |
| 742 | context->getClientMajorVersion() >= 3); |
| 743 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 744 | default: |
| 745 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 749 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 750 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 751 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 752 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 753 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 754 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 755 | case TextureType::_2D: |
| 756 | case TextureType::_2DArray: |
| 757 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 758 | case TextureType::_2DMultisampleArray: |
| 759 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 760 | // level-of-detail" for multisample textures should be. Could maybe make it zero. |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 761 | maxDimension = caps.max2DTextureSize; |
| 762 | break; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 763 | |
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; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 767 | |
| 768 | case TextureType::External: |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 769 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 770 | return level == 0; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 771 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 772 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 773 | maxDimension = caps.max3DTextureSize; |
| 774 | break; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 775 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 776 | default: |
| 777 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 778 | } |
| 779 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 780 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 781 | } |
| 782 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 783 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 784 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 785 | GLint level, |
| 786 | GLsizei width, |
| 787 | GLsizei height, |
| 788 | GLsizei depth, |
| 789 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 790 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 791 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 792 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 793 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 794 | return false; |
| 795 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 796 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 797 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 798 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 799 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 800 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 801 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 802 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 803 | context->validationError(GL_INVALID_VALUE, kTextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 804 | return false; |
| 805 | } |
| 806 | |
| 807 | if (!ValidMipLevel(context, target, level)) |
| 808 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 809 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 810 | return false; |
| 811 | } |
| 812 | |
| 813 | return true; |
| 814 | } |
| 815 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 816 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 817 | { |
| 818 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 819 | (size % blockSize == 0); |
| 820 | } |
| 821 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 822 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 823 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 824 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 825 | GLsizei width, |
| 826 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 827 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 828 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 829 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 830 | { |
| 831 | return false; |
| 832 | } |
| 833 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 834 | if (width < 0 || height < 0) |
| 835 | { |
| 836 | return false; |
| 837 | } |
| 838 | |
| 839 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 840 | { |
| 841 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 842 | // block size for level 0 but WebGL disallows this. |
| 843 | bool smallerThanBlockSizeAllowed = |
| 844 | level > 0 || !context->getExtensions().webglCompatibility; |
| 845 | |
| 846 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 847 | smallerThanBlockSizeAllowed) || |
| 848 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 849 | smallerThanBlockSizeAllowed)) |
| 850 | { |
| 851 | return false; |
| 852 | } |
| 853 | } |
| 854 | |
| 855 | return true; |
| 856 | } |
| 857 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 858 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 859 | GLenum internalFormat, |
| 860 | GLint xoffset, |
| 861 | GLint yoffset, |
| 862 | GLsizei width, |
| 863 | GLsizei height, |
| 864 | size_t textureWidth, |
| 865 | size_t textureHeight) |
| 866 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 867 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 868 | if (!formatInfo.compressed) |
| 869 | { |
| 870 | return false; |
| 871 | } |
| 872 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 873 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 874 | { |
| 875 | return false; |
| 876 | } |
| 877 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 878 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 879 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 880 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 881 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 882 | { |
| 883 | return false; |
| 884 | } |
| 885 | |
| 886 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 887 | // size but fills the entire mip |
| 888 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 889 | static_cast<size_t>(width) == textureWidth && |
| 890 | static_cast<size_t>(height) == textureHeight; |
| 891 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 892 | (height % formatInfo.compressedBlockHeight) == 0; |
| 893 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 894 | { |
| 895 | return false; |
| 896 | } |
| 897 | } |
| 898 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 899 | return true; |
| 900 | } |
| 901 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 902 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 903 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 904 | GLsizei width, |
| 905 | GLsizei height, |
| 906 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 907 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 908 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 909 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 910 | GLsizei imageSize) |
| 911 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 912 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 913 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 914 | { |
| 915 | // Checks are not required |
| 916 | return true; |
| 917 | } |
| 918 | |
| 919 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 920 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 921 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 922 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 923 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 924 | const auto &unpack = context->getGLState().getUnpackState(); |
| 925 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 926 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 927 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 928 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 929 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 930 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 931 | return false; |
| 932 | } |
| 933 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 934 | if (pixelUnpackBuffer) |
| 935 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 936 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 937 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 938 | checkedEndByte += checkedOffset; |
| 939 | |
| 940 | if (!checkedEndByte.IsValid() || |
| 941 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 942 | { |
| 943 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 944 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 945 | return false; |
| 946 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 947 | if (context->getExtensions().webglCompatibility && |
| 948 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 949 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 950 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 951 | kPixelUnpackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 952 | return false; |
| 953 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 954 | } |
| 955 | else |
| 956 | { |
| 957 | ASSERT(imageSize >= 0); |
| 958 | if (pixels == nullptr && imageSize != 0) |
| 959 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 960 | context->validationError(GL_INVALID_OPERATION, kImageSizeMustBeZero); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 961 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 962 | } |
| 963 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 964 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 965 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 966 | context->validationError(GL_INVALID_OPERATION, kImageSizeTooSmall); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 967 | return false; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | return true; |
| 972 | } |
| 973 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 974 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 975 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 976 | switch (queryType) |
| 977 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 978 | case QueryType::AnySamples: |
| 979 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 980 | return context->getClientMajorVersion() >= 3 || |
| 981 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 982 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 983 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 984 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 985 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 986 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 987 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 988 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 989 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 990 | default: |
| 991 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 995 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 996 | GLenum type, |
| 997 | GLboolean normalized, |
| 998 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 999 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1000 | bool pureInteger) |
| 1001 | { |
| 1002 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1003 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1004 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1005 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1006 | // parameter exceeds 255. |
| 1007 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1008 | if (stride > kMaxWebGLStride) |
| 1009 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1010 | context->validationError(GL_INVALID_VALUE, kStrideExceedsWebGLLimit); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1011 | return false; |
| 1012 | } |
| 1013 | |
| 1014 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1015 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1016 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1017 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 1018 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 1019 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1020 | |
| 1021 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1022 | size_t sizeMask = (typeSize - 1); |
| 1023 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1024 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1025 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1026 | return false; |
| 1027 | } |
| 1028 | |
| 1029 | if ((stride & sizeMask) != 0) |
| 1030 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1031 | context->validationError(GL_INVALID_OPERATION, kStrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1032 | return false; |
| 1033 | } |
| 1034 | |
| 1035 | return true; |
| 1036 | } |
| 1037 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1038 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1039 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1040 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1041 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1042 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1043 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1044 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1045 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1046 | |
| 1047 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1048 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1049 | if (context->getShader(id)) |
| 1050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1051 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1052 | } |
| 1053 | else |
| 1054 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1055 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1056 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1057 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1058 | |
| 1059 | return validProgram; |
| 1060 | } |
| 1061 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1062 | Program *GetValidProgram(Context *context, GLuint id) |
| 1063 | { |
| 1064 | Program *program = GetValidProgramNoResolve(context, id); |
| 1065 | if (program) |
| 1066 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1067 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1068 | } |
| 1069 | return program; |
| 1070 | } |
| 1071 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1072 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1073 | { |
| 1074 | // See ValidProgram for spec details. |
| 1075 | |
| 1076 | Shader *validShader = context->getShader(id); |
| 1077 | |
| 1078 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1079 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1080 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1081 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1082 | context->validationError(GL_INVALID_OPERATION, kExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1083 | } |
| 1084 | else |
| 1085 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1086 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1087 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1088 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1089 | |
| 1090 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1091 | } |
| 1092 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1093 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1094 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1095 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1096 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1097 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1098 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1099 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1100 | return false; |
| 1101 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1102 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1103 | // Color attachment 0 is validated below because it is always valid |
| 1104 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1105 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1106 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1107 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1108 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | else |
| 1112 | { |
| 1113 | switch (attachment) |
| 1114 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1115 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1116 | case GL_DEPTH_ATTACHMENT: |
| 1117 | case GL_STENCIL_ATTACHMENT: |
| 1118 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1119 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1121 | if (!context->getExtensions().webglCompatibility && |
| 1122 | context->getClientMajorVersion() < 3) |
| 1123 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1124 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1125 | return false; |
| 1126 | } |
| 1127 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1128 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1129 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1130 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1131 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1132 | } |
| 1133 | } |
| 1134 | |
| 1135 | return true; |
| 1136 | } |
| 1137 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1138 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1139 | GLenum target, |
| 1140 | GLsizei samples, |
| 1141 | GLenum internalformat, |
| 1142 | GLsizei width, |
| 1143 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1144 | { |
| 1145 | switch (target) |
| 1146 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1147 | case GL_RENDERBUFFER: |
| 1148 | break; |
| 1149 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1150 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1151 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | if (width < 0 || height < 0 || samples < 0) |
| 1155 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1156 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1157 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1158 | } |
| 1159 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1160 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1161 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1162 | |
| 1163 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1164 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1165 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1166 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1167 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1168 | } |
| 1169 | |
| 1170 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1171 | // 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] | 1172 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1173 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1174 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1175 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1176 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1177 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1180 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1181 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1182 | context->validationError(GL_INVALID_VALUE, kResourceMaxRenderbufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1186 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1187 | if (handle == 0) |
| 1188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1189 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1190 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | return true; |
| 1194 | } |
| 1195 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1196 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1197 | GLenum target, |
| 1198 | GLenum attachment, |
| 1199 | GLenum renderbuffertarget, |
| 1200 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1201 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1202 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1203 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1204 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1205 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1206 | } |
| 1207 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1208 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1209 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1210 | ASSERT(framebuffer); |
| 1211 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1212 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1213 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1214 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1215 | } |
| 1216 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1217 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1218 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1219 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1220 | } |
| 1221 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1222 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1223 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1224 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1225 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1226 | if (renderbuffer != 0) |
| 1227 | { |
| 1228 | if (!context->getRenderbuffer(renderbuffer)) |
| 1229 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1230 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1231 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1232 | } |
| 1233 | } |
| 1234 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1235 | return true; |
| 1236 | } |
| 1237 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1238 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1239 | GLint srcX0, |
| 1240 | GLint srcY0, |
| 1241 | GLint srcX1, |
| 1242 | GLint srcY1, |
| 1243 | GLint dstX0, |
| 1244 | GLint dstY0, |
| 1245 | GLint dstX1, |
| 1246 | GLint dstY1, |
| 1247 | GLbitfield mask, |
| 1248 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1249 | { |
| 1250 | switch (filter) |
| 1251 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1252 | case GL_NEAREST: |
| 1253 | break; |
| 1254 | case GL_LINEAR: |
| 1255 | break; |
| 1256 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1257 | context->validationError(GL_INVALID_ENUM, kBlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1258 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1259 | } |
| 1260 | |
| 1261 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1262 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1263 | context->validationError(GL_INVALID_VALUE, kBlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1264 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1265 | } |
| 1266 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1267 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1268 | // color buffer, leaving only nearest being unfiltered from above |
| 1269 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1270 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1271 | context->validationError(GL_INVALID_OPERATION, kBlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1272 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1273 | } |
| 1274 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1275 | const auto &glState = context->getGLState(); |
| 1276 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1277 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1278 | |
| 1279 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1280 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1281 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1282 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1283 | } |
| 1284 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1285 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1286 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1290 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1291 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1292 | return false; |
| 1293 | } |
| 1294 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1295 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1297 | context->validationError(GL_INVALID_OPERATION, kBlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1298 | return false; |
| 1299 | } |
| 1300 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1301 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1302 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1303 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1304 | } |
| 1305 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1306 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1307 | // always run it in order to avoid triggering driver bugs. |
| 1308 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1309 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1310 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1311 | context->validationError(GL_INVALID_VALUE, kBlitDimensionsOutOfRange); |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1312 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1313 | } |
| 1314 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1315 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1316 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1317 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1318 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1319 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1320 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1321 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1322 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1323 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1324 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1325 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1326 | for (size_t drawbufferIdx = 0; |
| 1327 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1328 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1329 | const FramebufferAttachment *attachment = |
| 1330 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1331 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1332 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1333 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1334 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1335 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1336 | // 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] | 1337 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1338 | // as well |
| 1339 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1340 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1341 | // Changes with EXT_color_buffer_float: |
| 1342 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1343 | GLenum readComponentType = readFormat.info->componentType; |
| 1344 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1345 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1346 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1347 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1348 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1349 | |
| 1350 | if (extensions.colorBufferFloat) |
| 1351 | { |
| 1352 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1353 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1354 | |
| 1355 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1356 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1357 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1358 | kBlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1359 | return false; |
| 1360 | } |
| 1361 | } |
| 1362 | else if (readFixedPoint != drawFixedPoint) |
| 1363 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1364 | context->validationError(GL_INVALID_OPERATION, kBlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1365 | return false; |
| 1366 | } |
| 1367 | |
| 1368 | if (readComponentType == GL_UNSIGNED_INT && |
| 1369 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1370 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1371 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1372 | kBlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1373 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1374 | } |
| 1375 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1376 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1377 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1378 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1379 | kBlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1380 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1381 | } |
| 1382 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1383 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1384 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1385 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1386 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1387 | kBlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1388 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1389 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1390 | |
| 1391 | if (context->getExtensions().webglCompatibility && |
| 1392 | *readColorBuffer == *attachment) |
| 1393 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1394 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1395 | return false; |
| 1396 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1397 | } |
| 1398 | } |
| 1399 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1400 | if ((readFormat.info->componentType == GL_INT || |
| 1401 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1402 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1404 | context->validationError(GL_INVALID_OPERATION, kBlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1405 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1406 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1407 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1408 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1409 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1410 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1411 | // situation is an application error that would lead to a crash in ANGLE. |
| 1412 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1413 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1414 | context->validationError(GL_INVALID_OPERATION, kBlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1415 | return false; |
| 1416 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1417 | } |
| 1418 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1419 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1420 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1421 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1422 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1423 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1424 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1425 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1426 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1427 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1428 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1429 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1430 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1431 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1432 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1433 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1434 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1435 | kBlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1436 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1437 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1438 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1439 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1440 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1441 | context->validationError(GL_INVALID_OPERATION, kBlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1442 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1443 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1444 | |
| 1445 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1446 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1447 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1448 | return false; |
| 1449 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1450 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1451 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1452 | else if (drawBuffer) |
| 1453 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1454 | context->validationError(GL_INVALID_OPERATION, kBlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1455 | return false; |
| 1456 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1457 | } |
| 1458 | } |
| 1459 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1460 | // ANGLE_multiview, Revision 1: |
| 1461 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1462 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1463 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1464 | // views in the current read framebuffer is more than one. |
| 1465 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1466 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1467 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
| 1470 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1471 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1472 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1473 | return false; |
| 1474 | } |
| 1475 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1476 | return true; |
| 1477 | } |
| 1478 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1479 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1480 | GLint x, |
| 1481 | GLint y, |
| 1482 | GLsizei width, |
| 1483 | GLsizei height, |
| 1484 | GLenum format, |
| 1485 | GLenum type, |
| 1486 | GLsizei bufSize, |
| 1487 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1488 | GLsizei *columns, |
| 1489 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1490 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1491 | { |
| 1492 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1493 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1494 | return false; |
| 1495 | } |
| 1496 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1497 | GLsizei writeLength = 0; |
| 1498 | GLsizei writeColumns = 0; |
| 1499 | GLsizei writeRows = 0; |
| 1500 | |
| 1501 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1502 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1503 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1504 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1505 | } |
| 1506 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1507 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1508 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1509 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1510 | } |
| 1511 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1512 | SetRobustLengthParam(length, writeLength); |
| 1513 | SetRobustLengthParam(columns, writeColumns); |
| 1514 | SetRobustLengthParam(rows, writeRows); |
| 1515 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1516 | return true; |
| 1517 | } |
| 1518 | |
| 1519 | bool ValidateReadnPixelsEXT(Context *context, |
| 1520 | GLint x, |
| 1521 | GLint y, |
| 1522 | GLsizei width, |
| 1523 | GLsizei height, |
| 1524 | GLenum format, |
| 1525 | GLenum type, |
| 1526 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1527 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1528 | { |
| 1529 | if (bufSize < 0) |
| 1530 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1531 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1532 | return false; |
| 1533 | } |
| 1534 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1535 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1536 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1537 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1538 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1539 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1540 | GLint x, |
| 1541 | GLint y, |
| 1542 | GLsizei width, |
| 1543 | GLsizei height, |
| 1544 | GLenum format, |
| 1545 | GLenum type, |
| 1546 | GLsizei bufSize, |
| 1547 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1548 | GLsizei *columns, |
| 1549 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1550 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1551 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1552 | GLsizei writeLength = 0; |
| 1553 | GLsizei writeColumns = 0; |
| 1554 | GLsizei writeRows = 0; |
| 1555 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1556 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1557 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1558 | return false; |
| 1559 | } |
| 1560 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1561 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1562 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1563 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1564 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1565 | } |
| 1566 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1567 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1568 | { |
| 1569 | return false; |
| 1570 | } |
| 1571 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1572 | SetRobustLengthParam(length, writeLength); |
| 1573 | SetRobustLengthParam(columns, writeColumns); |
| 1574 | SetRobustLengthParam(rows, writeRows); |
| 1575 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1576 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1577 | } |
| 1578 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1579 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1580 | { |
| 1581 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1582 | !context->getExtensions().disjointTimerQuery) |
| 1583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1584 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1585 | return false; |
| 1586 | } |
| 1587 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1588 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1589 | } |
| 1590 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1591 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1592 | { |
| 1593 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1594 | !context->getExtensions().disjointTimerQuery) |
| 1595 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1596 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1597 | return false; |
| 1598 | } |
| 1599 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1600 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1601 | } |
| 1602 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1603 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1604 | { |
| 1605 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1606 | !context->getExtensions().disjointTimerQuery) |
| 1607 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1608 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1609 | return false; |
| 1610 | } |
| 1611 | |
| 1612 | return true; |
| 1613 | } |
| 1614 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1615 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1616 | { |
| 1617 | if (!ValidQueryType(context, target)) |
| 1618 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1619 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1620 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | if (id == 0) |
| 1624 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1625 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1626 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1630 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1631 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1632 | // the active query for either target is non-zero), if <id> is the name of an |
| 1633 | // existing query object whose type does not match <target>, or if <id> is the |
| 1634 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1635 | // generated. |
| 1636 | |
| 1637 | // Ensure no other queries are active |
| 1638 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1639 | // separately that: |
| 1640 | // a) The query ID passed is not the current active query for any target/type |
| 1641 | // b) There are no active queries for the requested target (and in the case |
| 1642 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1643 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1644 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1645 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1646 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1647 | context->validationError(GL_INVALID_OPERATION, kOtherQueryActive); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1648 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | Query *queryObject = context->getQuery(id, true, target); |
| 1652 | |
| 1653 | // check that name was obtained with glGenQueries |
| 1654 | if (!queryObject) |
| 1655 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1656 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1657 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | // check for type mismatch |
| 1661 | if (queryObject->getType() != target) |
| 1662 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1663 | context->validationError(GL_INVALID_OPERATION, kQueryTargetMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1664 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1665 | } |
| 1666 | |
| 1667 | return true; |
| 1668 | } |
| 1669 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1670 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1671 | { |
| 1672 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1673 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1674 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1675 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1676 | return false; |
| 1677 | } |
| 1678 | |
| 1679 | return ValidateBeginQueryBase(context, target, id); |
| 1680 | } |
| 1681 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1682 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1683 | { |
| 1684 | if (!ValidQueryType(context, target)) |
| 1685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1686 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1687 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1688 | } |
| 1689 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1690 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1691 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1692 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1693 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1694 | context->validationError(GL_INVALID_OPERATION, kQueryInactive); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1695 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1696 | } |
| 1697 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1698 | return true; |
| 1699 | } |
| 1700 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1701 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1702 | { |
| 1703 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1704 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1705 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1706 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | return ValidateEndQueryBase(context, target); |
| 1711 | } |
| 1712 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1713 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1714 | { |
| 1715 | if (!context->getExtensions().disjointTimerQuery) |
| 1716 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1717 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1718 | return false; |
| 1719 | } |
| 1720 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1721 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1722 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1723 | context->validationError(GL_INVALID_ENUM, kInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1724 | return false; |
| 1725 | } |
| 1726 | |
| 1727 | Query *queryObject = context->getQuery(id, true, target); |
| 1728 | if (queryObject == nullptr) |
| 1729 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1730 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1731 | return false; |
| 1732 | } |
| 1733 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1734 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1735 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1736 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1737 | return false; |
| 1738 | } |
| 1739 | |
| 1740 | return true; |
| 1741 | } |
| 1742 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1743 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1744 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1745 | if (numParams) |
| 1746 | { |
| 1747 | *numParams = 0; |
| 1748 | } |
| 1749 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1750 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1751 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1752 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1753 | return false; |
| 1754 | } |
| 1755 | |
| 1756 | switch (pname) |
| 1757 | { |
| 1758 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1759 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1760 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1761 | context->validationError(GL_INVALID_ENUM, kInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1762 | return false; |
| 1763 | } |
| 1764 | break; |
| 1765 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1766 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1767 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1768 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1769 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1770 | return false; |
| 1771 | } |
| 1772 | break; |
| 1773 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1774 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1775 | return false; |
| 1776 | } |
| 1777 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1778 | if (numParams) |
| 1779 | { |
| 1780 | // All queries return only one value |
| 1781 | *numParams = 1; |
| 1782 | } |
| 1783 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1784 | return true; |
| 1785 | } |
| 1786 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1787 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1788 | { |
| 1789 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1790 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1791 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1792 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1793 | return false; |
| 1794 | } |
| 1795 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1796 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1797 | } |
| 1798 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1799 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1800 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1801 | GLenum pname, |
| 1802 | GLsizei bufSize, |
| 1803 | GLsizei *length, |
| 1804 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1805 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1806 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1807 | { |
| 1808 | return false; |
| 1809 | } |
| 1810 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1811 | GLsizei numParams = 0; |
| 1812 | |
| 1813 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1814 | { |
| 1815 | return false; |
| 1816 | } |
| 1817 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1818 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1819 | { |
| 1820 | return false; |
| 1821 | } |
| 1822 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1823 | SetRobustLengthParam(length, numParams); |
| 1824 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1825 | return true; |
| 1826 | } |
| 1827 | |
| 1828 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1829 | { |
| 1830 | if (numParams) |
| 1831 | { |
| 1832 | *numParams = 0; |
| 1833 | } |
| 1834 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1835 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1836 | |
| 1837 | if (!queryObject) |
| 1838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1839 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1840 | return false; |
| 1841 | } |
| 1842 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1843 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1844 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1845 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1846 | return false; |
| 1847 | } |
| 1848 | |
| 1849 | switch (pname) |
| 1850 | { |
| 1851 | case GL_QUERY_RESULT_EXT: |
| 1852 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1853 | break; |
| 1854 | |
| 1855 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1856 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1857 | return false; |
| 1858 | } |
| 1859 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1860 | if (numParams) |
| 1861 | { |
| 1862 | *numParams = 1; |
| 1863 | } |
| 1864 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1865 | return true; |
| 1866 | } |
| 1867 | |
| 1868 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1869 | { |
| 1870 | if (!context->getExtensions().disjointTimerQuery) |
| 1871 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1872 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1873 | return false; |
| 1874 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1875 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1876 | } |
| 1877 | |
| 1878 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1879 | GLuint id, |
| 1880 | GLenum pname, |
| 1881 | GLsizei bufSize, |
| 1882 | GLsizei *length, |
| 1883 | GLint *params) |
| 1884 | { |
| 1885 | if (!context->getExtensions().disjointTimerQuery) |
| 1886 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1887 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
| 1890 | |
| 1891 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1892 | { |
| 1893 | return false; |
| 1894 | } |
| 1895 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1896 | GLsizei numParams = 0; |
| 1897 | |
| 1898 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1899 | { |
| 1900 | return false; |
| 1901 | } |
| 1902 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1903 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1904 | { |
| 1905 | return false; |
| 1906 | } |
| 1907 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1908 | SetRobustLengthParam(length, numParams); |
| 1909 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1910 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1914 | { |
| 1915 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1916 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1917 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1918 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1919 | return false; |
| 1920 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1921 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1922 | } |
| 1923 | |
| 1924 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1925 | GLuint id, |
| 1926 | GLenum pname, |
| 1927 | GLsizei bufSize, |
| 1928 | GLsizei *length, |
| 1929 | GLuint *params) |
| 1930 | { |
| 1931 | if (!context->getExtensions().disjointTimerQuery && |
| 1932 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1933 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1934 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1935 | return false; |
| 1936 | } |
| 1937 | |
| 1938 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1939 | { |
| 1940 | return false; |
| 1941 | } |
| 1942 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1943 | GLsizei numParams = 0; |
| 1944 | |
| 1945 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1946 | { |
| 1947 | return false; |
| 1948 | } |
| 1949 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1950 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1951 | { |
| 1952 | return false; |
| 1953 | } |
| 1954 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1955 | SetRobustLengthParam(length, numParams); |
| 1956 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1957 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1961 | { |
| 1962 | if (!context->getExtensions().disjointTimerQuery) |
| 1963 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1964 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1965 | return false; |
| 1966 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1967 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1968 | } |
| 1969 | |
| 1970 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1971 | GLuint id, |
| 1972 | GLenum pname, |
| 1973 | GLsizei bufSize, |
| 1974 | GLsizei *length, |
| 1975 | GLint64 *params) |
| 1976 | { |
| 1977 | if (!context->getExtensions().disjointTimerQuery) |
| 1978 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1979 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1980 | return false; |
| 1981 | } |
| 1982 | |
| 1983 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1984 | { |
| 1985 | return false; |
| 1986 | } |
| 1987 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1988 | GLsizei numParams = 0; |
| 1989 | |
| 1990 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1991 | { |
| 1992 | return false; |
| 1993 | } |
| 1994 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1995 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1996 | { |
| 1997 | return false; |
| 1998 | } |
| 1999 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2000 | SetRobustLengthParam(length, numParams); |
| 2001 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2002 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2006 | { |
| 2007 | if (!context->getExtensions().disjointTimerQuery) |
| 2008 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2009 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2010 | return false; |
| 2011 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2012 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2013 | } |
| 2014 | |
| 2015 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2016 | GLuint id, |
| 2017 | GLenum pname, |
| 2018 | GLsizei bufSize, |
| 2019 | GLsizei *length, |
| 2020 | GLuint64 *params) |
| 2021 | { |
| 2022 | if (!context->getExtensions().disjointTimerQuery) |
| 2023 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2024 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2025 | return false; |
| 2026 | } |
| 2027 | |
| 2028 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2029 | { |
| 2030 | return false; |
| 2031 | } |
| 2032 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2033 | GLsizei numParams = 0; |
| 2034 | |
| 2035 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2036 | { |
| 2037 | return false; |
| 2038 | } |
| 2039 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2040 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2041 | { |
| 2042 | return false; |
| 2043 | } |
| 2044 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2045 | SetRobustLengthParam(length, numParams); |
| 2046 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2047 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2048 | } |
| 2049 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2050 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2051 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2052 | GLint location, |
| 2053 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2054 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2055 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2056 | // TODO(Jiajia): Add image uniform check in future. |
| 2057 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2058 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2059 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2060 | return false; |
| 2061 | } |
| 2062 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2063 | if (!program) |
| 2064 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2065 | context->validationError(GL_INVALID_OPERATION, kInvalidProgramName); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2066 | return false; |
| 2067 | } |
| 2068 | |
| 2069 | if (!program->isLinked()) |
| 2070 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2071 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2072 | return false; |
| 2073 | } |
| 2074 | |
| 2075 | if (location == -1) |
| 2076 | { |
| 2077 | // Silently ignore the uniform command |
| 2078 | return false; |
| 2079 | } |
| 2080 | |
| 2081 | const auto &uniformLocations = program->getUniformLocations(); |
| 2082 | size_t castedLocation = static_cast<size_t>(location); |
| 2083 | if (castedLocation >= uniformLocations.size()) |
| 2084 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2085 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2086 | return false; |
| 2087 | } |
| 2088 | |
| 2089 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2090 | if (uniformLocation.ignored) |
| 2091 | { |
| 2092 | // Silently ignore the uniform command |
| 2093 | return false; |
| 2094 | } |
| 2095 | |
| 2096 | if (!uniformLocation.used()) |
| 2097 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2098 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2099 | return false; |
| 2100 | } |
| 2101 | |
| 2102 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2103 | |
| 2104 | // 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] | 2105 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2106 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2107 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformCount); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2108 | return false; |
| 2109 | } |
| 2110 | |
| 2111 | *uniformOut = &uniform; |
| 2112 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2113 | } |
| 2114 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2115 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2116 | GLenum uniformType, |
| 2117 | GLsizei count, |
| 2118 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2119 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2120 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2121 | // It is compatible with INT or BOOL. |
| 2122 | // Do these cheap tests first, for a little extra speed. |
| 2123 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2124 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2125 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2126 | } |
| 2127 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2128 | if (IsSamplerType(uniformType)) |
| 2129 | { |
| 2130 | // Check that the values are in range. |
| 2131 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2132 | for (GLsizei i = 0; i < count; ++i) |
| 2133 | { |
| 2134 | if (value[i] < 0 || value[i] >= max) |
| 2135 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2136 | context->validationError(GL_INVALID_VALUE, kSamplerUniformValueOutOfRange); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2137 | return false; |
| 2138 | } |
| 2139 | } |
| 2140 | return true; |
| 2141 | } |
| 2142 | |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2143 | context->validationError(GL_INVALID_OPERATION, kUniformTypeMismatch); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2144 | return false; |
| 2145 | } |
| 2146 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2147 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2148 | { |
| 2149 | // Check that the value type is compatible with uniform type. |
| 2150 | if (valueType == uniformType) |
| 2151 | { |
| 2152 | return true; |
| 2153 | } |
| 2154 | |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2155 | context->validationError(GL_INVALID_OPERATION, kUniformTypeMismatch); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2156 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2157 | } |
| 2158 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2159 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2160 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2161 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2162 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2163 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2164 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2165 | } |
| 2166 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2167 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2168 | { |
| 2169 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2170 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2171 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2172 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2173 | } |
| 2174 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2175 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2176 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2177 | GLint location, |
| 2178 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2179 | GLboolean transpose) |
| 2180 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2181 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2182 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2183 | context->validationError(GL_INVALID_VALUE, kES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2184 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2185 | } |
| 2186 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2187 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2188 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2189 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2190 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2191 | } |
| 2192 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2193 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2194 | { |
| 2195 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2197 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2198 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2199 | } |
| 2200 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2201 | const Caps &caps = context->getCaps(); |
| 2202 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2203 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2204 | { |
| 2205 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2206 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2207 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2208 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2209 | context->validationError(GL_INVALID_OPERATION, kIndexExceedsMaxDrawBuffer); |
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 | } |
| 2213 | |
| 2214 | switch (pname) |
| 2215 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2216 | case GL_TEXTURE_BINDING_2D: |
| 2217 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2218 | case GL_TEXTURE_BINDING_3D: |
| 2219 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2220 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2221 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2222 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2223 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2224 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2225 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2226 | return false; |
| 2227 | } |
| 2228 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2229 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2230 | if (!context->getExtensions().textureRectangle) |
| 2231 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2232 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2233 | return false; |
| 2234 | } |
| 2235 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2236 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2237 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2238 | !context->getExtensions().eglImageExternal) |
| 2239 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2240 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2241 | return false; |
| 2242 | } |
| 2243 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2244 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2245 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2246 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2247 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2248 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2249 | ASSERT(readFramebuffer); |
| 2250 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2251 | if (!ValidateFramebufferComplete<GL_INVALID_OPERATION>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2252 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2253 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2254 | } |
| 2255 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2256 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2257 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2258 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2259 | return false; |
| 2260 | } |
| 2261 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2262 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2263 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2264 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2265 | context->validationError(GL_INVALID_OPERATION, kReadBufferNotAttached); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2266 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2267 | } |
| 2268 | } |
| 2269 | break; |
| 2270 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2271 | default: |
| 2272 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2276 | if (*numParams == 0) |
| 2277 | { |
| 2278 | return false; |
| 2279 | } |
| 2280 | |
| 2281 | return true; |
| 2282 | } |
| 2283 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2284 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2285 | GLenum pname, |
| 2286 | GLsizei bufSize, |
| 2287 | GLsizei *length, |
| 2288 | GLboolean *params) |
| 2289 | { |
| 2290 | GLenum nativeType; |
| 2291 | unsigned int numParams = 0; |
| 2292 | |
| 2293 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2294 | { |
| 2295 | return false; |
| 2296 | } |
| 2297 | |
| 2298 | SetRobustLengthParam(length, numParams); |
| 2299 | |
| 2300 | return true; |
| 2301 | } |
| 2302 | |
| 2303 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2304 | GLenum pname, |
| 2305 | GLsizei bufSize, |
| 2306 | GLsizei *length, |
| 2307 | GLfloat *params) |
| 2308 | { |
| 2309 | GLenum nativeType; |
| 2310 | unsigned int numParams = 0; |
| 2311 | |
| 2312 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2313 | { |
| 2314 | return false; |
| 2315 | } |
| 2316 | |
| 2317 | SetRobustLengthParam(length, numParams); |
| 2318 | |
| 2319 | return true; |
| 2320 | } |
| 2321 | |
| 2322 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2323 | GLenum pname, |
| 2324 | GLsizei bufSize, |
| 2325 | GLsizei *length, |
| 2326 | GLint *data) |
| 2327 | { |
| 2328 | GLenum nativeType; |
| 2329 | unsigned int numParams = 0; |
| 2330 | |
| 2331 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2332 | { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | SetRobustLengthParam(length, numParams); |
| 2337 | |
| 2338 | return true; |
| 2339 | } |
| 2340 | |
| 2341 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2342 | GLenum pname, |
| 2343 | GLsizei bufSize, |
| 2344 | GLsizei *length, |
| 2345 | GLint64 *data) |
| 2346 | { |
| 2347 | GLenum nativeType; |
| 2348 | unsigned int numParams = 0; |
| 2349 | |
| 2350 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2351 | { |
| 2352 | return false; |
| 2353 | } |
| 2354 | |
| 2355 | if (nativeType == GL_INT_64_ANGLEX) |
| 2356 | { |
| 2357 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2358 | return false; |
| 2359 | } |
| 2360 | |
| 2361 | SetRobustLengthParam(length, numParams); |
| 2362 | return true; |
| 2363 | } |
| 2364 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2365 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2366 | GLenum pname, |
| 2367 | GLsizei bufSize, |
| 2368 | GLenum *nativeType, |
| 2369 | unsigned int *numParams) |
| 2370 | { |
| 2371 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2372 | { |
| 2373 | return false; |
| 2374 | } |
| 2375 | |
| 2376 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2377 | { |
| 2378 | return false; |
| 2379 | } |
| 2380 | |
| 2381 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2382 | { |
| 2383 | return false; |
| 2384 | } |
| 2385 | |
| 2386 | return true; |
| 2387 | } |
| 2388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2389 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2390 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2391 | GLint level, |
| 2392 | GLenum internalformat, |
| 2393 | bool isSubImage, |
| 2394 | GLint xoffset, |
| 2395 | GLint yoffset, |
| 2396 | GLint zoffset, |
| 2397 | GLint x, |
| 2398 | GLint y, |
| 2399 | GLsizei width, |
| 2400 | GLsizei height, |
| 2401 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2402 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2403 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2404 | TextureType texType = TextureTargetToType(target); |
| 2405 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2406 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2407 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2408 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2409 | return false; |
| 2410 | } |
| 2411 | |
| 2412 | if (width < 0 || height < 0) |
| 2413 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2414 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2415 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2416 | } |
| 2417 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2418 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2419 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2420 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2421 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2422 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2423 | } |
| 2424 | |
| 2425 | if (border != 0) |
| 2426 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2427 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2428 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2429 | } |
| 2430 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2431 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2432 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2433 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2434 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2435 | } |
| 2436 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2437 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2438 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2439 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2440 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2441 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2442 | } |
| 2443 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2444 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2445 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2446 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2447 | } |
| 2448 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2449 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2450 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2451 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2455 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2456 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2457 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2458 | // situation is an application error that would lead to a crash in ANGLE. |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2459 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2460 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2461 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2462 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2463 | return false; |
| 2464 | } |
| 2465 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2466 | // ANGLE_multiview spec, Revision 1: |
| 2467 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2468 | // INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the current read framebuffer |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 2469 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2470 | // framebuffer is more than one. |
| 2471 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2472 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2473 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kMultiviewReadFramebuffer); |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2474 | return false; |
| 2475 | } |
| 2476 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2477 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2478 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2479 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2480 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2481 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2482 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2483 | maxDimension = caps.max2DTextureSize; |
| 2484 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2485 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2486 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2487 | maxDimension = caps.maxCubeMapTextureSize; |
| 2488 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2489 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2490 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2491 | maxDimension = caps.maxRectangleTextureSize; |
| 2492 | break; |
| 2493 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2494 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2495 | maxDimension = caps.max2DTextureSize; |
| 2496 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2497 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2498 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2499 | maxDimension = caps.max3DTextureSize; |
| 2500 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2501 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2502 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2503 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2504 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2505 | } |
| 2506 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2507 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2508 | if (!texture) |
| 2509 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2510 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2511 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2512 | } |
| 2513 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2514 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2515 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2516 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2517 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2518 | } |
| 2519 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2520 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2521 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2522 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2523 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2524 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2525 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2526 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2527 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | if (isSubImage) |
| 2531 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2532 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2533 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2534 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2535 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2536 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2537 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2538 | } |
| 2539 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2540 | else |
| 2541 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2542 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2543 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2544 | context->validationError(GL_INVALID_VALUE, kCubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2545 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2546 | } |
| 2547 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2548 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2549 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2550 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2551 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2555 | if (static_cast<int>(width) > maxLevelDimension || |
| 2556 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2557 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2558 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2559 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2560 | } |
| 2561 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2562 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2563 | if (textureFormatOut) |
| 2564 | { |
| 2565 | *textureFormatOut = texture->getFormat(target, level); |
| 2566 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2567 | |
| 2568 | // Detect texture copying feedback loops for WebGL. |
| 2569 | if (context->getExtensions().webglCompatibility) |
| 2570 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2571 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2573 | context->validationError(GL_INVALID_OPERATION, kFeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2574 | return false; |
| 2575 | } |
| 2576 | } |
| 2577 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2578 | return true; |
| 2579 | } |
| 2580 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2581 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2582 | // completeness check. |
| 2583 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2584 | { |
| 2585 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2586 | const State &state = context->getGLState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2587 | |
| 2588 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2589 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2590 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2591 | VertexArray *vertexArray = state.getVertexArray(); |
| 2592 | ASSERT(vertexArray); |
| 2593 | |
| 2594 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2595 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2596 | return kBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2597 | } |
| 2598 | |
| 2599 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2600 | // Section 6.10 of the WebGL 1.0 spec. |
| 2601 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2602 | ASSERT(framebuffer); |
| 2603 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2604 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2605 | { |
| 2606 | ASSERT(framebuffer); |
| 2607 | const FramebufferAttachment *dsAttachment = |
| 2608 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2609 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2610 | ASSERT(stencilBits <= 8); |
| 2611 | |
| 2612 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2613 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2614 | { |
| 2615 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2616 | |
| 2617 | bool differentRefs = |
| 2618 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2619 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2620 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2621 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2622 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2623 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2624 | |
| 2625 | if (differentRefs || differentWritemasks || differentMasks) |
| 2626 | { |
| 2627 | if (!extensions.webglCompatibility) |
| 2628 | { |
| 2629 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2630 | "stencil writemasks, reference values, or stencil mask values."; |
| 2631 | } |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2632 | return kStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2633 | } |
| 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | if (!framebuffer->isComplete(context)) |
| 2638 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2639 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2640 | return kDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2644 | { |
| 2645 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2646 | { |
| 2647 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2648 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2649 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2650 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2651 | return kVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2652 | } |
| 2653 | |
| 2654 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2655 | { |
| 2656 | // This is an application error that would normally result in a crash, but we catch it |
| 2657 | // and return an error |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2658 | return kVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | // If we are running GLES1, there is no current program. |
| 2663 | if (context->getClientVersion() >= Version(2, 0)) |
| 2664 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2665 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2666 | if (!program) |
| 2667 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2668 | return kProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2669 | } |
| 2670 | |
| 2671 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2672 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2673 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2674 | // produce undefined result. |
| 2675 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2676 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2677 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2678 | return kNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2679 | } |
| 2680 | |
| 2681 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2682 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2683 | return kTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2684 | } |
| 2685 | |
| 2686 | if (extensions.multiview) |
| 2687 | { |
| 2688 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2689 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2690 | if (framebufferNumViews != programNumViews) |
| 2691 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2692 | return kMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2693 | } |
| 2694 | |
| 2695 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2696 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
Jamie Madill | 3a25622 | 2018-12-08 09:56:39 -0500 | [diff] [blame^] | 2697 | !transformFeedbackObject->isPaused() && framebufferNumViews > 1) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2698 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2699 | return kMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2703 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2705 | return kMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2706 | } |
| 2707 | } |
| 2708 | |
| 2709 | // Uniform buffer validation |
| 2710 | for (unsigned int uniformBlockIndex = 0; |
| 2711 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2712 | { |
| 2713 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2714 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2715 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2716 | state.getIndexedUniformBuffer(blockBinding); |
| 2717 | |
| 2718 | if (uniformBuffer.get() == nullptr) |
| 2719 | { |
| 2720 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2721 | return kUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2725 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2726 | { |
| 2727 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2728 | return kUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | if (extensions.webglCompatibility && |
| 2732 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2733 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2734 | return kUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | // Do some additonal WebGL-specific validation |
| 2739 | if (extensions.webglCompatibility) |
| 2740 | { |
| 2741 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2742 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2743 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2744 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2745 | return kTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | // Detect rendering feedback loops for WebGL. |
| 2749 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2750 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2751 | return kFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | // Detect that the vertex shader input types match the attribute types |
| 2755 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2756 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2757 | return kVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2758 | } |
| 2759 | |
| 2760 | // Detect that the color buffer types match the fragment shader output types |
| 2761 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2762 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2763 | return kDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2764 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2765 | |
| 2766 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2767 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2768 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2769 | return kVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2770 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2771 | } |
| 2772 | } |
| 2773 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2774 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2775 | } |
| 2776 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2777 | bool ValidateDrawMode(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2778 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2779 | const Extensions &extensions = context->getExtensions(); |
| 2780 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2781 | switch (mode) |
| 2782 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2783 | case PrimitiveMode::Points: |
| 2784 | case PrimitiveMode::Lines: |
| 2785 | case PrimitiveMode::LineLoop: |
| 2786 | case PrimitiveMode::LineStrip: |
| 2787 | case PrimitiveMode::Triangles: |
| 2788 | case PrimitiveMode::TriangleStrip: |
| 2789 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2790 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2791 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2792 | case PrimitiveMode::LinesAdjacency: |
| 2793 | case PrimitiveMode::LineStripAdjacency: |
| 2794 | case PrimitiveMode::TrianglesAdjacency: |
| 2795 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2796 | if (!extensions.geometryShader) |
| 2797 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2798 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2799 | return false; |
| 2800 | } |
| 2801 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2802 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2803 | context->validationError(GL_INVALID_ENUM, kInvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2804 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2805 | } |
| 2806 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2807 | // If we are running GLES1, there is no current program. |
| 2808 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2809 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2810 | const State &state = context->getGLState(); |
| 2811 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2812 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2813 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2814 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2815 | // Do geometry shader specific validations |
| 2816 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2817 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2818 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2819 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2820 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2821 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2822 | kIncompatibleDrawModeAgainstGeometryShader); |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2823 | return false; |
| 2824 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2825 | } |
| 2826 | } |
| 2827 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2828 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2829 | } |
| 2830 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2831 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2832 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2833 | GLint first, |
| 2834 | GLsizei count, |
| 2835 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2836 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2837 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2838 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2839 | context->validationError(GL_INVALID_VALUE, kNegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2840 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2841 | } |
| 2842 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2843 | if (!ValidateDrawBase(context, mode, count)) |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2844 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2845 | return false; |
| 2846 | } |
| 2847 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2848 | const State &state = context->getGLState(); |
| 2849 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2850 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2851 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2852 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2853 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2854 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2855 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2856 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2857 | return false; |
| 2858 | } |
| 2859 | |
| 2860 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2861 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2862 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackBufferTooSmall); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2863 | return false; |
| 2864 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2865 | } |
| 2866 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2867 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2868 | // - first < 0 has been checked as an error condition. |
| 2869 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2870 | // 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] | 2871 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2872 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2873 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2874 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2875 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2876 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2877 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2878 | return false; |
| 2879 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2880 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2881 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2882 | { |
| 2883 | return false; |
| 2884 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2885 | } |
| 2886 | |
| 2887 | return true; |
| 2888 | } |
| 2889 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2890 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2891 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2892 | GLint first, |
| 2893 | GLsizei count, |
| 2894 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2895 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2896 | if (!context->getExtensions().instancedArrays) |
| 2897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2898 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2899 | return false; |
| 2900 | } |
| 2901 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2902 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2903 | { |
| 2904 | return false; |
| 2905 | } |
| 2906 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2907 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2908 | } |
| 2909 | |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2910 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, DrawElementsType type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2911 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2912 | if (!context->getStateCache().isValidDrawElementsType(type)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2913 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2914 | if (type == DrawElementsType::UnsignedInt) |
| 2915 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2916 | context->validationError(GL_INVALID_ENUM, kTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2917 | return false; |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2918 | } |
| 2919 | |
| 2920 | ASSERT(type == DrawElementsType::InvalidEnum); |
| 2921 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2922 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2923 | } |
| 2924 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2925 | // TODO(jmadill): Cache all of these into fast checks. http://anglebug.com/2966 |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2926 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2927 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2928 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2929 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2930 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2931 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2932 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2933 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2934 | if (context->getExtensions().geometryShader) |
| 2935 | { |
| 2936 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2937 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2938 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2939 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2940 | return false; |
| 2941 | } |
| 2942 | } |
| 2943 | else |
| 2944 | { |
| 2945 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2946 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2947 | // 86) |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2948 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2949 | kUnsupportedDrawModeForTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2950 | return false; |
| 2951 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2952 | } |
| 2953 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2954 | const VertexArray *vao = state.getVertexArray(); |
| 2955 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 2956 | |
| 2957 | if (elementArrayBuffer) |
| 2958 | { |
| 2959 | if (context->getExtensions().webglCompatibility) |
| 2960 | { |
| 2961 | if (elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2962 | { |
| 2963 | context->validationError(GL_INVALID_OPERATION, |
| 2964 | kElementArrayBufferBoundForTransformFeedback); |
| 2965 | return false; |
| 2966 | } |
| 2967 | } |
| 2968 | else if (elementArrayBuffer->isMapped()) |
| 2969 | { |
| 2970 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 2971 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the |
| 2972 | // WebGL 2.0 API. https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2973 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
| 2974 | return false; |
| 2975 | } |
| 2976 | } |
| 2977 | else |
| 2978 | { |
| 2979 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
| 2980 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 2981 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
| 2982 | if (!context->getGLState().areClientArraysEnabled() || |
| 2983 | context->getExtensions().webglCompatibility) |
| 2984 | { |
| 2985 | context->validationError(GL_INVALID_OPERATION, kMustHaveElementArrayBinding); |
| 2986 | return false; |
| 2987 | } |
| 2988 | } |
| 2989 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2990 | return true; |
| 2991 | } |
| 2992 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2993 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2994 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2995 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2996 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2997 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2998 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2999 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3000 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3001 | { |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3002 | return false; |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3003 | } |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3004 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3005 | if (!ValidateDrawBase(context, mode, count)) |
| 3006 | { |
| 3007 | return false; |
| 3008 | } |
| 3009 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3010 | const State &state = context->getGLState(); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3011 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 3012 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3013 | |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 3014 | GLuint typeBytes = GetDrawElementsTypeSize(type); |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3015 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3016 | |
| 3017 | if (context->getExtensions().webglCompatibility) |
| 3018 | { |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3019 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3020 | { |
| 3021 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3022 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3023 | // data type passed to the call, or an INVALID_OPERATION error is generated. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3024 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3025 | return false; |
| 3026 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3027 | |
| 3028 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3029 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3030 | // error is generated. |
| 3031 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3032 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3033 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3034 | return false; |
| 3035 | } |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3036 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3037 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3038 | // Early exit. |
| 3039 | if (count == 0) |
| 3040 | { |
| 3041 | return true; |
| 3042 | } |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3043 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3044 | if (!elementArrayBuffer) |
| 3045 | { |
| 3046 | if (!indices) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3047 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3048 | // This is an application error that would normally result in a crash, but we catch |
| 3049 | // it and return an error |
| 3050 | context->validationError(GL_INVALID_OPERATION, kElementArrayNoBufferOrPointer); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3051 | return false; |
| 3052 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3053 | } |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3054 | else |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3055 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3056 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3057 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3058 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3059 | constexpr uint64_t kMaxTypeSize = 8; |
| 3060 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3061 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3062 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3063 | |
| 3064 | uint64_t typeSize = typeBytes; |
| 3065 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3066 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3067 | |
| 3068 | // Doing the multiplication here is overflow-safe |
| 3069 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3070 | |
| 3071 | // The offset can be any value, check for overflows |
| 3072 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3073 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3074 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3075 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
| 3076 | return false; |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3077 | } |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3078 | |
| 3079 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3080 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3081 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3082 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3083 | return false; |
| 3084 | } |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3085 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3086 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3087 | if (!context->getExtensions().robustBufferAccessBehavior && primcount > 0) |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3088 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3089 | // Use the parameter buffer to retrieve and cache the index range. |
| 3090 | IndexRange indexRange; |
| 3091 | ANGLE_VALIDATION_TRY(vao->getIndexRange(context, type, count, indices, &indexRange)); |
| 3092 | |
| 3093 | // If we use an index greater than our maximum supported index range, return an error. |
| 3094 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should |
| 3095 | // always return an error if possible here. |
| 3096 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3097 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3098 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxElement); |
| 3099 | return false; |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3100 | } |
| 3101 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3102 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3103 | { |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3104 | return false; |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3105 | } |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 3106 | |
| 3107 | // No op if there are no real indices in the index data (all are primitive restart). |
| 3108 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3109 | } |
| 3110 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3111 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3112 | } |
| 3113 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3114 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3115 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3116 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 3117 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3118 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3119 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3120 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3121 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3122 | } |
| 3123 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3124 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3125 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3126 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 3127 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3128 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3129 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3130 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3131 | if (!context->getExtensions().instancedArrays) |
| 3132 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3133 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3134 | return false; |
| 3135 | } |
| 3136 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3137 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3138 | { |
| 3139 | return false; |
| 3140 | } |
| 3141 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3142 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3143 | } |
| 3144 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3145 | bool ValidateFramebufferTextureBase(Context *context, |
| 3146 | GLenum target, |
| 3147 | GLenum attachment, |
| 3148 | GLuint texture, |
| 3149 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3150 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3151 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3152 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3153 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3154 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3155 | } |
| 3156 | |
| 3157 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3158 | { |
| 3159 | return false; |
| 3160 | } |
| 3161 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3162 | if (texture != 0) |
| 3163 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3164 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3165 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3166 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3167 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3168 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3169 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3170 | } |
| 3171 | |
| 3172 | if (level < 0) |
| 3173 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3174 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3175 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3176 | } |
| 3177 | } |
| 3178 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3179 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3180 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3181 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3182 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3183 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3184 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3185 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3186 | } |
| 3187 | |
| 3188 | return true; |
| 3189 | } |
| 3190 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3191 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3192 | { |
| 3193 | if (program == 0) |
| 3194 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3195 | context->validationError(GL_INVALID_VALUE, kProgramDoesNotExist); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3196 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3197 | } |
| 3198 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3199 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3200 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3201 | { |
| 3202 | return false; |
| 3203 | } |
| 3204 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3205 | if (!programObject || !programObject->isLinked()) |
| 3206 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3207 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3208 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3209 | } |
| 3210 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3211 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3212 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3213 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3214 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3215 | } |
| 3216 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3217 | return true; |
| 3218 | } |
| 3219 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3220 | static bool ValidateSizedGetUniform(Context *context, |
| 3221 | GLuint program, |
| 3222 | GLint location, |
| 3223 | GLsizei bufSize, |
| 3224 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3225 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3226 | if (length) |
| 3227 | { |
| 3228 | *length = 0; |
| 3229 | } |
| 3230 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3231 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3232 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3233 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3234 | } |
| 3235 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3236 | if (bufSize < 0) |
| 3237 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3238 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3239 | return false; |
| 3240 | } |
| 3241 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3242 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3243 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3244 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3245 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3246 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3247 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3248 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3249 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3250 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3251 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3252 | } |
| 3253 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3254 | if (length) |
| 3255 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3256 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3257 | } |
| 3258 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3259 | return true; |
| 3260 | } |
| 3261 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3262 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3263 | GLuint program, |
| 3264 | GLint location, |
| 3265 | GLsizei bufSize, |
| 3266 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3267 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3268 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3269 | } |
| 3270 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3271 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3272 | GLuint program, |
| 3273 | GLint location, |
| 3274 | GLsizei bufSize, |
| 3275 | GLsizei *length, |
| 3276 | GLfloat *params) |
| 3277 | { |
| 3278 | UNIMPLEMENTED(); |
| 3279 | return false; |
| 3280 | } |
| 3281 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3282 | bool ValidateGetnUniformivEXT(Context *context, |
| 3283 | GLuint program, |
| 3284 | GLint location, |
| 3285 | GLsizei bufSize, |
| 3286 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3287 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3288 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3289 | } |
| 3290 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3291 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3292 | GLuint program, |
| 3293 | GLint location, |
| 3294 | GLsizei bufSize, |
| 3295 | GLsizei *length, |
| 3296 | GLint *params) |
| 3297 | { |
| 3298 | UNIMPLEMENTED(); |
| 3299 | return false; |
| 3300 | } |
| 3301 | |
| 3302 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3303 | GLuint program, |
| 3304 | GLint location, |
| 3305 | GLsizei bufSize, |
| 3306 | GLsizei *length, |
| 3307 | GLuint *params) |
| 3308 | { |
| 3309 | UNIMPLEMENTED(); |
| 3310 | return false; |
| 3311 | } |
| 3312 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3313 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3314 | GLuint program, |
| 3315 | GLint location, |
| 3316 | GLsizei bufSize, |
| 3317 | GLsizei *length, |
| 3318 | GLfloat *params) |
| 3319 | { |
| 3320 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3321 | { |
| 3322 | return false; |
| 3323 | } |
| 3324 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3325 | GLsizei writeLength = 0; |
| 3326 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3327 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3328 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3329 | { |
| 3330 | return false; |
| 3331 | } |
| 3332 | |
| 3333 | SetRobustLengthParam(length, writeLength); |
| 3334 | |
| 3335 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3336 | } |
| 3337 | |
| 3338 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3339 | GLuint program, |
| 3340 | GLint location, |
| 3341 | GLsizei bufSize, |
| 3342 | GLsizei *length, |
| 3343 | GLint *params) |
| 3344 | { |
| 3345 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3346 | { |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3350 | GLsizei writeLength = 0; |
| 3351 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3352 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3353 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3354 | { |
| 3355 | return false; |
| 3356 | } |
| 3357 | |
| 3358 | SetRobustLengthParam(length, writeLength); |
| 3359 | |
| 3360 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3361 | } |
| 3362 | |
| 3363 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3364 | GLuint program, |
| 3365 | GLint location, |
| 3366 | GLsizei bufSize, |
| 3367 | GLsizei *length, |
| 3368 | GLuint *params) |
| 3369 | { |
| 3370 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3371 | { |
| 3372 | return false; |
| 3373 | } |
| 3374 | |
| 3375 | if (context->getClientMajorVersion() < 3) |
| 3376 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3377 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3378 | return false; |
| 3379 | } |
| 3380 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3381 | GLsizei writeLength = 0; |
| 3382 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3383 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3384 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3385 | { |
| 3386 | return false; |
| 3387 | } |
| 3388 | |
| 3389 | SetRobustLengthParam(length, writeLength); |
| 3390 | |
| 3391 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3392 | } |
| 3393 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3394 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3395 | GLenum target, |
| 3396 | GLsizei numAttachments, |
| 3397 | const GLenum *attachments, |
| 3398 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3399 | { |
| 3400 | if (numAttachments < 0) |
| 3401 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3402 | context->validationError(GL_INVALID_VALUE, kNegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3407 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3408 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3409 | { |
| 3410 | if (defaultFramebuffer) |
| 3411 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3412 | context->validationError(GL_INVALID_ENUM, kDefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3413 | return false; |
| 3414 | } |
| 3415 | |
| 3416 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3417 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3418 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxColorAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3419 | return false; |
| 3420 | } |
| 3421 | } |
| 3422 | else |
| 3423 | { |
| 3424 | switch (attachments[i]) |
| 3425 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3426 | case GL_DEPTH_ATTACHMENT: |
| 3427 | case GL_STENCIL_ATTACHMENT: |
| 3428 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3429 | if (defaultFramebuffer) |
| 3430 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3431 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3432 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3433 | return false; |
| 3434 | } |
| 3435 | break; |
| 3436 | case GL_COLOR: |
| 3437 | case GL_DEPTH: |
| 3438 | case GL_STENCIL: |
| 3439 | if (!defaultFramebuffer) |
| 3440 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3441 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3442 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3443 | return false; |
| 3444 | } |
| 3445 | break; |
| 3446 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3447 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3448 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3449 | } |
| 3450 | } |
| 3451 | } |
| 3452 | |
| 3453 | return true; |
| 3454 | } |
| 3455 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3456 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3457 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3458 | if (!context->getExtensions().debugMarker) |
| 3459 | { |
| 3460 | // The debug marker calls should not set error state |
| 3461 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3462 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3463 | return false; |
| 3464 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3465 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3466 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3467 | if (length < 0) |
| 3468 | { |
| 3469 | return false; |
| 3470 | } |
| 3471 | |
| 3472 | if (marker == nullptr) |
| 3473 | { |
| 3474 | return false; |
| 3475 | } |
| 3476 | |
| 3477 | return true; |
| 3478 | } |
| 3479 | |
| 3480 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3481 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3482 | if (!context->getExtensions().debugMarker) |
| 3483 | { |
| 3484 | // The debug marker calls should not set error state |
| 3485 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3486 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3487 | return false; |
| 3488 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3489 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3490 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3491 | if (length < 0) |
| 3492 | { |
| 3493 | return false; |
| 3494 | } |
| 3495 | |
| 3496 | if (length > 0 && marker == nullptr) |
| 3497 | { |
| 3498 | return false; |
| 3499 | } |
| 3500 | |
| 3501 | return true; |
| 3502 | } |
| 3503 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3504 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3505 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3506 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3507 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3508 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3509 | return false; |
| 3510 | } |
| 3511 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3512 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3513 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3514 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3515 | if (!context->getExtensions().eglImage) |
| 3516 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3517 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3518 | } |
| 3519 | break; |
| 3520 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3521 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3522 | if (!context->getExtensions().eglImageExternal) |
| 3523 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3524 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3525 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3526 | break; |
| 3527 | |
| 3528 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3529 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3530 | return false; |
| 3531 | } |
| 3532 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3533 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3534 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3535 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3536 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3537 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3538 | context->validationError(GL_INVALID_VALUE, kInvalidEGLImage); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3539 | return false; |
| 3540 | } |
| 3541 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3542 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3543 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3544 | context->validationError(GL_INVALID_OPERATION, kEGLImageCannotCreate2DMultisampled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3545 | return false; |
| 3546 | } |
| 3547 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3548 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3549 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3550 | context->validationError(GL_INVALID_OPERATION, kEGLImageTextureFormatNotSupported); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3551 | return false; |
| 3552 | } |
| 3553 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3554 | return true; |
| 3555 | } |
| 3556 | |
| 3557 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3558 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3559 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3560 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3561 | if (!context->getExtensions().eglImage) |
| 3562 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3563 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3564 | return false; |
| 3565 | } |
| 3566 | |
| 3567 | switch (target) |
| 3568 | { |
| 3569 | case GL_RENDERBUFFER: |
| 3570 | break; |
| 3571 | |
| 3572 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3573 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3574 | return false; |
| 3575 | } |
| 3576 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3577 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3578 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3579 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3580 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3581 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3582 | context->validationError(GL_INVALID_VALUE, kInvalidEGLImage); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3583 | return false; |
| 3584 | } |
| 3585 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3586 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3587 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3588 | context->validationError(GL_INVALID_OPERATION, kEGLImageRenderbufferFormatNotSupported); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3589 | return false; |
| 3590 | } |
| 3591 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3592 | return true; |
| 3593 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3594 | |
| 3595 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3596 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3597 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3598 | { |
| 3599 | // The default VAO should always exist |
| 3600 | ASSERT(array != 0); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3601 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexArray); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | return true; |
| 3606 | } |
| 3607 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3608 | bool ValidateProgramBinaryBase(Context *context, |
| 3609 | GLuint program, |
| 3610 | GLenum binaryFormat, |
| 3611 | const void *binary, |
| 3612 | GLint length) |
| 3613 | { |
| 3614 | Program *programObject = GetValidProgram(context, program); |
| 3615 | if (programObject == nullptr) |
| 3616 | { |
| 3617 | return false; |
| 3618 | } |
| 3619 | |
| 3620 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3621 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3622 | programBinaryFormats.end()) |
| 3623 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3624 | context->validationError(GL_INVALID_ENUM, kInvalidProgramBinaryFormat); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3625 | return false; |
| 3626 | } |
| 3627 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3628 | if (context->hasActiveTransformFeedback(program)) |
| 3629 | { |
| 3630 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3631 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackProgramBinary); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3632 | return false; |
| 3633 | } |
| 3634 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3635 | return true; |
| 3636 | } |
| 3637 | |
| 3638 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3639 | GLuint program, |
| 3640 | GLsizei bufSize, |
| 3641 | GLsizei *length, |
| 3642 | GLenum *binaryFormat, |
| 3643 | void *binary) |
| 3644 | { |
| 3645 | Program *programObject = GetValidProgram(context, program); |
| 3646 | if (programObject == nullptr) |
| 3647 | { |
| 3648 | return false; |
| 3649 | } |
| 3650 | |
| 3651 | if (!programObject->isLinked()) |
| 3652 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3653 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3654 | return false; |
| 3655 | } |
| 3656 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3657 | if (context->getCaps().programBinaryFormats.empty()) |
| 3658 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3659 | context->validationError(GL_INVALID_OPERATION, kNoProgramBinaryFormats); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3660 | return false; |
| 3661 | } |
| 3662 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3663 | return true; |
| 3664 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3665 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3666 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3667 | { |
| 3668 | // 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] | 3669 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3670 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3671 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3672 | return false; |
| 3673 | } |
| 3674 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3675 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3676 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3677 | return false; |
| 3678 | } |
| 3679 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3680 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3681 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3682 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3683 | |
| 3684 | // This should come first before the check for the default frame buffer |
| 3685 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3686 | // rather than INVALID_OPERATION |
| 3687 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3688 | { |
| 3689 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3690 | |
| 3691 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3692 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3693 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3694 | { |
| 3695 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3696 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3697 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3698 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3699 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3700 | context->validationError(GL_INVALID_ENUM, kInvalidDrawBuffer); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3701 | return false; |
| 3702 | } |
| 3703 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3704 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3705 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxColorAttachments); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3706 | return false; |
| 3707 | } |
| 3708 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3709 | frameBufferId != 0) |
| 3710 | { |
| 3711 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3712 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3713 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawBufferValue); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3714 | return false; |
| 3715 | } |
| 3716 | } |
| 3717 | |
| 3718 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3719 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3720 | if (frameBufferId == 0) |
| 3721 | { |
| 3722 | if (n != 1) |
| 3723 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3724 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawBufferCountForDefault); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3725 | return false; |
| 3726 | } |
| 3727 | |
| 3728 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3729 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3730 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferInvalidDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | } |
| 3734 | |
| 3735 | return true; |
| 3736 | } |
| 3737 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3738 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3739 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3740 | GLenum pname, |
| 3741 | GLsizei *length, |
| 3742 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3743 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3744 | if (length) |
| 3745 | { |
| 3746 | *length = 0; |
| 3747 | } |
| 3748 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3749 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3750 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3751 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3752 | return false; |
| 3753 | } |
| 3754 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3755 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3756 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3757 | case GL_BUFFER_MAP_POINTER: |
| 3758 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3759 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3760 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3761 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3762 | return false; |
| 3763 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3764 | |
| 3765 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3766 | // target bound to zero generate an INVALID_OPERATION error." |
| 3767 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3768 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3769 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3770 | context->validationError(GL_INVALID_OPERATION, kBufferPointerNotAvailable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3771 | return false; |
| 3772 | } |
| 3773 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3774 | if (length) |
| 3775 | { |
| 3776 | *length = 1; |
| 3777 | } |
| 3778 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3779 | return true; |
| 3780 | } |
| 3781 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3782 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3783 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3784 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3785 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3786 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3787 | return false; |
| 3788 | } |
| 3789 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3790 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3791 | |
| 3792 | if (buffer == nullptr || !buffer->isMapped()) |
| 3793 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3794 | context->validationError(GL_INVALID_OPERATION, kBufferNotMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3795 | return false; |
| 3796 | } |
| 3797 | |
| 3798 | return true; |
| 3799 | } |
| 3800 | |
| 3801 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3802 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3803 | GLintptr offset, |
| 3804 | GLsizeiptr length, |
| 3805 | GLbitfield access) |
| 3806 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3807 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3808 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3809 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3810 | return false; |
| 3811 | } |
| 3812 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3813 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3814 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3815 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3816 | return false; |
| 3817 | } |
| 3818 | |
| 3819 | if (length < 0) |
| 3820 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3821 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3822 | return false; |
| 3823 | } |
| 3824 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3825 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3826 | |
| 3827 | if (!buffer) |
| 3828 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3829 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3830 | return false; |
| 3831 | } |
| 3832 | |
| 3833 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3834 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3835 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3836 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3837 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3838 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3839 | context->validationError(GL_INVALID_VALUE, kMapOutOfRange); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3840 | return false; |
| 3841 | } |
| 3842 | |
| 3843 | // Check for invalid bits in the mask |
| 3844 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3845 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3846 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3847 | |
| 3848 | if (access & ~(allAccessBits)) |
| 3849 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3850 | context->validationError(GL_INVALID_VALUE, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3851 | return false; |
| 3852 | } |
| 3853 | |
| 3854 | if (length == 0) |
| 3855 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3856 | context->validationError(GL_INVALID_OPERATION, kLengthZero); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3857 | return false; |
| 3858 | } |
| 3859 | |
| 3860 | if (buffer->isMapped()) |
| 3861 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3862 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3863 | return false; |
| 3864 | } |
| 3865 | |
| 3866 | // Check for invalid bit combinations |
| 3867 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3868 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3869 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsReadWrite); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3870 | return false; |
| 3871 | } |
| 3872 | |
| 3873 | GLbitfield writeOnlyBits = |
| 3874 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3875 | |
| 3876 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3877 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3878 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsRead); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3879 | return false; |
| 3880 | } |
| 3881 | |
| 3882 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3883 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3884 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsFlush); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3885 | return false; |
| 3886 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3887 | |
| 3888 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3892 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3893 | GLintptr offset, |
| 3894 | GLsizeiptr length) |
| 3895 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3896 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3897 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3898 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3899 | return false; |
| 3900 | } |
| 3901 | |
| 3902 | if (length < 0) |
| 3903 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3904 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3905 | return false; |
| 3906 | } |
| 3907 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3908 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3909 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3910 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3911 | return false; |
| 3912 | } |
| 3913 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3914 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3915 | |
| 3916 | if (buffer == nullptr) |
| 3917 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3918 | context->validationError(GL_INVALID_OPERATION, kInvalidFlushZero); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3919 | return false; |
| 3920 | } |
| 3921 | |
| 3922 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3923 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3924 | context->validationError(GL_INVALID_OPERATION, kInvalidFlushTarget); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3925 | return false; |
| 3926 | } |
| 3927 | |
| 3928 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3929 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3930 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3931 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3932 | if (!checkedSize.IsValid() || |
| 3933 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3934 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3935 | context->validationError(GL_INVALID_VALUE, kInvalidFlushOutOfRange); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3936 | return false; |
| 3937 | } |
| 3938 | |
| 3939 | return true; |
| 3940 | } |
| 3941 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3942 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3943 | { |
| 3944 | if (n < 0) |
| 3945 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3946 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3947 | return false; |
| 3948 | } |
| 3949 | return true; |
| 3950 | } |
| 3951 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3952 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3953 | { |
| 3954 | if (!context->getExtensions().robustClientMemory) |
| 3955 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3956 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3957 | return false; |
| 3958 | } |
| 3959 | |
| 3960 | if (bufSize < 0) |
| 3961 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3962 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3963 | return false; |
| 3964 | } |
| 3965 | |
| 3966 | return true; |
| 3967 | } |
| 3968 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3969 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3970 | { |
| 3971 | if (bufSize < numParams) |
| 3972 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3973 | context->validationError(GL_INVALID_OPERATION, kInsufficientParams); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3974 | return false; |
| 3975 | } |
| 3976 | |
| 3977 | return true; |
| 3978 | } |
| 3979 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 3980 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 3981 | GLenum target, |
| 3982 | GLenum attachment, |
| 3983 | GLenum pname, |
| 3984 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3985 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3986 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3987 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3988 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3989 | return false; |
| 3990 | } |
| 3991 | |
| 3992 | int clientVersion = context->getClientMajorVersion(); |
| 3993 | |
| 3994 | switch (pname) |
| 3995 | { |
| 3996 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 3997 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 3998 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 3999 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4000 | break; |
| 4001 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4002 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4003 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4004 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4005 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4006 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4007 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4008 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4009 | return false; |
| 4010 | } |
| 4011 | break; |
| 4012 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4013 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4014 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4015 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4016 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4017 | return false; |
| 4018 | } |
| 4019 | break; |
| 4020 | |
| 4021 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4022 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4023 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4024 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4025 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4026 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4027 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4028 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4029 | if (clientVersion < 3) |
| 4030 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4031 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4032 | return false; |
| 4033 | } |
| 4034 | break; |
| 4035 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4036 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4037 | if (!context->getExtensions().geometryShader) |
| 4038 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4039 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4040 | return false; |
| 4041 | } |
| 4042 | break; |
| 4043 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4044 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4045 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4046 | return false; |
| 4047 | } |
| 4048 | |
| 4049 | // Determine if the attachment is a valid enum |
| 4050 | switch (attachment) |
| 4051 | { |
| 4052 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4053 | case GL_DEPTH: |
| 4054 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4055 | if (clientVersion < 3) |
| 4056 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4057 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4058 | return false; |
| 4059 | } |
| 4060 | break; |
| 4061 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4062 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4063 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4064 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4065 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4066 | return false; |
| 4067 | } |
| 4068 | break; |
| 4069 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4070 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4071 | case GL_DEPTH_ATTACHMENT: |
| 4072 | case GL_STENCIL_ATTACHMENT: |
| 4073 | break; |
| 4074 | |
| 4075 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4076 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4077 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4078 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4079 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4080 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4081 | return false; |
| 4082 | } |
| 4083 | break; |
| 4084 | } |
| 4085 | |
| 4086 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4087 | ASSERT(framebuffer); |
| 4088 | |
| 4089 | if (framebuffer->id() == 0) |
| 4090 | { |
| 4091 | if (clientVersion < 3) |
| 4092 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4093 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4094 | return false; |
| 4095 | } |
| 4096 | |
| 4097 | switch (attachment) |
| 4098 | { |
| 4099 | case GL_BACK: |
| 4100 | case GL_DEPTH: |
| 4101 | case GL_STENCIL: |
| 4102 | break; |
| 4103 | |
| 4104 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4105 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4106 | return false; |
| 4107 | } |
| 4108 | } |
| 4109 | else |
| 4110 | { |
| 4111 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4112 | { |
| 4113 | // Valid attachment query |
| 4114 | } |
| 4115 | else |
| 4116 | { |
| 4117 | switch (attachment) |
| 4118 | { |
| 4119 | case GL_DEPTH_ATTACHMENT: |
| 4120 | case GL_STENCIL_ATTACHMENT: |
| 4121 | break; |
| 4122 | |
| 4123 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4124 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4125 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4126 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4127 | return false; |
| 4128 | } |
| 4129 | break; |
| 4130 | |
| 4131 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4132 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4133 | return false; |
| 4134 | } |
| 4135 | } |
| 4136 | } |
| 4137 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4138 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4139 | if (attachmentObject) |
| 4140 | { |
| 4141 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4142 | attachmentObject->type() == GL_TEXTURE || |
| 4143 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4144 | |
| 4145 | switch (pname) |
| 4146 | { |
| 4147 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4148 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4149 | attachmentObject->type() != GL_TEXTURE) |
| 4150 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4151 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4152 | return false; |
| 4153 | } |
| 4154 | break; |
| 4155 | |
| 4156 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4157 | if (attachmentObject->type() != GL_TEXTURE) |
| 4158 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4159 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4160 | return false; |
| 4161 | } |
| 4162 | break; |
| 4163 | |
| 4164 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4165 | if (attachmentObject->type() != GL_TEXTURE) |
| 4166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4167 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4168 | return false; |
| 4169 | } |
| 4170 | break; |
| 4171 | |
| 4172 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4173 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4175 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4176 | return false; |
| 4177 | } |
| 4178 | break; |
| 4179 | |
| 4180 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4181 | if (attachmentObject->type() != GL_TEXTURE) |
| 4182 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4183 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4184 | return false; |
| 4185 | } |
| 4186 | break; |
| 4187 | |
| 4188 | default: |
| 4189 | break; |
| 4190 | } |
| 4191 | } |
| 4192 | else |
| 4193 | { |
| 4194 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4195 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4196 | |
| 4197 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4198 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4199 | // INVALID_OPERATION for all other pnames |
| 4200 | |
| 4201 | switch (pname) |
| 4202 | { |
| 4203 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4204 | break; |
| 4205 | |
| 4206 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4207 | if (clientVersion < 3) |
| 4208 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4209 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4210 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | break; |
| 4214 | |
| 4215 | default: |
| 4216 | if (clientVersion < 3) |
| 4217 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4218 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4219 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4220 | return false; |
| 4221 | } |
| 4222 | else |
| 4223 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4224 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4225 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4226 | return false; |
| 4227 | } |
| 4228 | } |
| 4229 | } |
| 4230 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4231 | if (numParams) |
| 4232 | { |
| 4233 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4234 | { |
| 4235 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4236 | // parameters. |
| 4237 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4238 | *numParams = numViews * 2; |
| 4239 | } |
| 4240 | else |
| 4241 | { |
| 4242 | // For all other queries we can have only one output parameter. |
| 4243 | *numParams = 1; |
| 4244 | } |
| 4245 | } |
| 4246 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4247 | return true; |
| 4248 | } |
| 4249 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4250 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4251 | GLenum target, |
| 4252 | GLenum attachment, |
| 4253 | GLenum pname, |
| 4254 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4255 | GLsizei *length, |
| 4256 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4257 | { |
| 4258 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4259 | { |
| 4260 | return false; |
| 4261 | } |
| 4262 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4263 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4264 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4265 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4266 | { |
| 4267 | return false; |
| 4268 | } |
| 4269 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4270 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4271 | { |
| 4272 | return false; |
| 4273 | } |
| 4274 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4275 | SetRobustLengthParam(length, numParams); |
| 4276 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4277 | return true; |
| 4278 | } |
| 4279 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4280 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4281 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4282 | GLenum pname, |
| 4283 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4284 | GLsizei *length, |
| 4285 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4286 | { |
| 4287 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4288 | { |
| 4289 | return false; |
| 4290 | } |
| 4291 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4292 | GLsizei numParams = 0; |
| 4293 | |
| 4294 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4295 | { |
| 4296 | return false; |
| 4297 | } |
| 4298 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4299 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4300 | { |
| 4301 | return false; |
| 4302 | } |
| 4303 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4304 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4305 | return true; |
| 4306 | } |
| 4307 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4308 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4309 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4310 | GLenum pname, |
| 4311 | GLsizei bufSize, |
| 4312 | GLsizei *length, |
| 4313 | GLint64 *params) |
| 4314 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4315 | GLsizei numParams = 0; |
| 4316 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4317 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4318 | { |
| 4319 | return false; |
| 4320 | } |
| 4321 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4322 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4323 | { |
| 4324 | return false; |
| 4325 | } |
| 4326 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4327 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4328 | { |
| 4329 | return false; |
| 4330 | } |
| 4331 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4332 | SetRobustLengthParam(length, numParams); |
| 4333 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4334 | return true; |
| 4335 | } |
| 4336 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4337 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4338 | { |
| 4339 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4340 | if (numParams) |
| 4341 | { |
| 4342 | *numParams = 1; |
| 4343 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4344 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4345 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4346 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4347 | ? GetValidProgramNoResolve(context, program) |
| 4348 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4349 | if (!programObject) |
| 4350 | { |
| 4351 | return false; |
| 4352 | } |
| 4353 | |
| 4354 | switch (pname) |
| 4355 | { |
| 4356 | case GL_DELETE_STATUS: |
| 4357 | case GL_LINK_STATUS: |
| 4358 | case GL_VALIDATE_STATUS: |
| 4359 | case GL_INFO_LOG_LENGTH: |
| 4360 | case GL_ATTACHED_SHADERS: |
| 4361 | case GL_ACTIVE_ATTRIBUTES: |
| 4362 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4363 | case GL_ACTIVE_UNIFORMS: |
| 4364 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4365 | break; |
| 4366 | |
| 4367 | case GL_PROGRAM_BINARY_LENGTH: |
| 4368 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4369 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4370 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4371 | return false; |
| 4372 | } |
| 4373 | break; |
| 4374 | |
| 4375 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4376 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4377 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4378 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4379 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4380 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4381 | if (context->getClientMajorVersion() < 3) |
| 4382 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4383 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4384 | return false; |
| 4385 | } |
| 4386 | break; |
| 4387 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4388 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4389 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4390 | if (context->getClientVersion() < Version(3, 1)) |
| 4391 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4392 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4393 | return false; |
| 4394 | } |
| 4395 | break; |
| 4396 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4397 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4398 | if (context->getClientVersion() < Version(3, 1)) |
| 4399 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4400 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4401 | return false; |
| 4402 | } |
| 4403 | |
| 4404 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4405 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4406 | // program which has not been linked successfully, or which does not contain objects to |
| 4407 | // form a compute shader. |
| 4408 | if (!programObject->isLinked()) |
| 4409 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4410 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4411 | return false; |
| 4412 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4413 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4414 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4415 | context->validationError(GL_INVALID_OPERATION, kNoActiveComputeShaderStage); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4416 | return false; |
| 4417 | } |
| 4418 | break; |
| 4419 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4420 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4421 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4422 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4423 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4424 | if (!context->getExtensions().geometryShader) |
| 4425 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4426 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4427 | return false; |
| 4428 | } |
| 4429 | |
| 4430 | // [EXT_geometry_shader] Chapter 7.12 |
| 4431 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4432 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4433 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4434 | // successfully, or which does not contain objects to form a geometry shader. |
| 4435 | if (!programObject->isLinked()) |
| 4436 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4437 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4438 | return false; |
| 4439 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4440 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4441 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4442 | context->validationError(GL_INVALID_OPERATION, kNoActiveGeometryShaderStage); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4443 | return false; |
| 4444 | } |
| 4445 | break; |
| 4446 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4447 | case GL_COMPLETION_STATUS_KHR: |
| 4448 | if (!context->getExtensions().parallelShaderCompile) |
| 4449 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4450 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4451 | return false; |
| 4452 | } |
| 4453 | break; |
| 4454 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4455 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4456 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4457 | return false; |
| 4458 | } |
| 4459 | |
| 4460 | return true; |
| 4461 | } |
| 4462 | |
| 4463 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4464 | GLuint program, |
| 4465 | GLenum pname, |
| 4466 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4467 | GLsizei *length, |
| 4468 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4469 | { |
| 4470 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4471 | { |
| 4472 | return false; |
| 4473 | } |
| 4474 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4475 | GLsizei numParams = 0; |
| 4476 | |
| 4477 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4478 | { |
| 4479 | return false; |
| 4480 | } |
| 4481 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4482 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4483 | { |
| 4484 | return false; |
| 4485 | } |
| 4486 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4487 | SetRobustLengthParam(length, numParams); |
| 4488 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4489 | return true; |
| 4490 | } |
| 4491 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4492 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4493 | GLenum target, |
| 4494 | GLenum pname, |
| 4495 | GLsizei bufSize, |
| 4496 | GLsizei *length, |
| 4497 | GLint *params) |
| 4498 | { |
| 4499 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4500 | { |
| 4501 | return false; |
| 4502 | } |
| 4503 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4504 | GLsizei numParams = 0; |
| 4505 | |
| 4506 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4507 | { |
| 4508 | return false; |
| 4509 | } |
| 4510 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4511 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4512 | { |
| 4513 | return false; |
| 4514 | } |
| 4515 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4516 | SetRobustLengthParam(length, numParams); |
| 4517 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4518 | return true; |
| 4519 | } |
| 4520 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4521 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4522 | GLuint shader, |
| 4523 | GLenum pname, |
| 4524 | GLsizei bufSize, |
| 4525 | GLsizei *length, |
| 4526 | GLint *params) |
| 4527 | { |
| 4528 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4529 | { |
| 4530 | return false; |
| 4531 | } |
| 4532 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4533 | GLsizei numParams = 0; |
| 4534 | |
| 4535 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4536 | { |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4540 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4541 | { |
| 4542 | return false; |
| 4543 | } |
| 4544 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4545 | SetRobustLengthParam(length, numParams); |
| 4546 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4547 | return true; |
| 4548 | } |
| 4549 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4550 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4551 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4552 | GLenum pname, |
| 4553 | GLsizei bufSize, |
| 4554 | GLsizei *length, |
| 4555 | GLfloat *params) |
| 4556 | { |
| 4557 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4558 | { |
| 4559 | return false; |
| 4560 | } |
| 4561 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4562 | GLsizei numParams = 0; |
| 4563 | |
| 4564 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4565 | { |
| 4566 | return false; |
| 4567 | } |
| 4568 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4569 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4570 | { |
| 4571 | return false; |
| 4572 | } |
| 4573 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4574 | SetRobustLengthParam(length, numParams); |
| 4575 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4576 | return true; |
| 4577 | } |
| 4578 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4579 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4580 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4581 | GLenum pname, |
| 4582 | GLsizei bufSize, |
| 4583 | GLsizei *length, |
| 4584 | GLint *params) |
| 4585 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4586 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4587 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4588 | { |
| 4589 | return false; |
| 4590 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4591 | GLsizei numParams = 0; |
| 4592 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4593 | { |
| 4594 | return false; |
| 4595 | } |
| 4596 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4597 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4598 | { |
| 4599 | return false; |
| 4600 | } |
| 4601 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4602 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4603 | return true; |
| 4604 | } |
| 4605 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4606 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4607 | TextureType target, |
| 4608 | GLenum pname, |
| 4609 | GLsizei bufSize, |
| 4610 | GLsizei *length, |
| 4611 | GLint *params) |
| 4612 | { |
| 4613 | UNIMPLEMENTED(); |
| 4614 | return false; |
| 4615 | } |
| 4616 | |
| 4617 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4618 | TextureType target, |
| 4619 | GLenum pname, |
| 4620 | GLsizei bufSize, |
| 4621 | GLsizei *length, |
| 4622 | GLuint *params) |
| 4623 | { |
| 4624 | UNIMPLEMENTED(); |
| 4625 | return false; |
| 4626 | } |
| 4627 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4628 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4629 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4630 | GLenum pname, |
| 4631 | GLsizei bufSize, |
| 4632 | const GLfloat *params) |
| 4633 | { |
| 4634 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4635 | { |
| 4636 | return false; |
| 4637 | } |
| 4638 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4639 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4640 | } |
| 4641 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4642 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4643 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4644 | GLenum pname, |
| 4645 | GLsizei bufSize, |
| 4646 | const GLint *params) |
| 4647 | { |
| 4648 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4649 | { |
| 4650 | return false; |
| 4651 | } |
| 4652 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4653 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4654 | } |
| 4655 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4656 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4657 | TextureType target, |
| 4658 | GLenum pname, |
| 4659 | GLsizei bufSize, |
| 4660 | const GLint *params) |
| 4661 | { |
| 4662 | UNIMPLEMENTED(); |
| 4663 | return false; |
| 4664 | } |
| 4665 | |
| 4666 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4667 | TextureType target, |
| 4668 | GLenum pname, |
| 4669 | GLsizei bufSize, |
| 4670 | const GLuint *params) |
| 4671 | { |
| 4672 | UNIMPLEMENTED(); |
| 4673 | return false; |
| 4674 | } |
| 4675 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4676 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4677 | GLuint sampler, |
| 4678 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4679 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4680 | GLsizei *length, |
| 4681 | GLfloat *params) |
| 4682 | { |
| 4683 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4684 | { |
| 4685 | return false; |
| 4686 | } |
| 4687 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4688 | GLsizei numParams = 0; |
| 4689 | |
| 4690 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4691 | { |
| 4692 | return false; |
| 4693 | } |
| 4694 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4695 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4696 | { |
| 4697 | return false; |
| 4698 | } |
| 4699 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4700 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4701 | return true; |
| 4702 | } |
| 4703 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4704 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4705 | GLuint sampler, |
| 4706 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4707 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4708 | GLsizei *length, |
| 4709 | GLint *params) |
| 4710 | { |
| 4711 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4712 | { |
| 4713 | return false; |
| 4714 | } |
| 4715 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4716 | GLsizei numParams = 0; |
| 4717 | |
| 4718 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4719 | { |
| 4720 | return false; |
| 4721 | } |
| 4722 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4723 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4724 | { |
| 4725 | return false; |
| 4726 | } |
| 4727 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4728 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4729 | return true; |
| 4730 | } |
| 4731 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4732 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4733 | GLuint sampler, |
| 4734 | GLenum pname, |
| 4735 | GLsizei bufSize, |
| 4736 | GLsizei *length, |
| 4737 | GLint *params) |
| 4738 | { |
| 4739 | UNIMPLEMENTED(); |
| 4740 | return false; |
| 4741 | } |
| 4742 | |
| 4743 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4744 | GLuint sampler, |
| 4745 | GLenum pname, |
| 4746 | GLsizei bufSize, |
| 4747 | GLsizei *length, |
| 4748 | GLuint *params) |
| 4749 | { |
| 4750 | UNIMPLEMENTED(); |
| 4751 | return false; |
| 4752 | } |
| 4753 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4754 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4755 | GLuint sampler, |
| 4756 | GLenum pname, |
| 4757 | GLsizei bufSize, |
| 4758 | const GLfloat *params) |
| 4759 | { |
| 4760 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4761 | { |
| 4762 | return false; |
| 4763 | } |
| 4764 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4765 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4766 | } |
| 4767 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4768 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4769 | GLuint sampler, |
| 4770 | GLenum pname, |
| 4771 | GLsizei bufSize, |
| 4772 | const GLint *params) |
| 4773 | { |
| 4774 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4775 | { |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4779 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4780 | } |
| 4781 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4782 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4783 | GLuint sampler, |
| 4784 | GLenum pname, |
| 4785 | GLsizei bufSize, |
| 4786 | const GLint *param) |
| 4787 | { |
| 4788 | UNIMPLEMENTED(); |
| 4789 | return false; |
| 4790 | } |
| 4791 | |
| 4792 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4793 | GLuint sampler, |
| 4794 | GLenum pname, |
| 4795 | GLsizei bufSize, |
| 4796 | const GLuint *param) |
| 4797 | { |
| 4798 | UNIMPLEMENTED(); |
| 4799 | return false; |
| 4800 | } |
| 4801 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4802 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4803 | GLuint index, |
| 4804 | GLenum pname, |
| 4805 | GLsizei bufSize, |
| 4806 | GLsizei *length, |
| 4807 | GLfloat *params) |
| 4808 | { |
| 4809 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4810 | { |
| 4811 | return false; |
| 4812 | } |
| 4813 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4814 | GLsizei writeLength = 0; |
| 4815 | |
| 4816 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4817 | { |
| 4818 | return false; |
| 4819 | } |
| 4820 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4821 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4822 | { |
| 4823 | return false; |
| 4824 | } |
| 4825 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4826 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4827 | return true; |
| 4828 | } |
| 4829 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4830 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4831 | GLuint index, |
| 4832 | GLenum pname, |
| 4833 | GLsizei bufSize, |
| 4834 | GLsizei *length, |
| 4835 | GLint *params) |
| 4836 | { |
| 4837 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4838 | { |
| 4839 | return false; |
| 4840 | } |
| 4841 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4842 | GLsizei writeLength = 0; |
| 4843 | |
| 4844 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4845 | { |
| 4846 | return false; |
| 4847 | } |
| 4848 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4849 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4850 | { |
| 4851 | return false; |
| 4852 | } |
| 4853 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4854 | SetRobustLengthParam(length, writeLength); |
| 4855 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4856 | return true; |
| 4857 | } |
| 4858 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4859 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4860 | GLuint index, |
| 4861 | GLenum pname, |
| 4862 | GLsizei bufSize, |
| 4863 | GLsizei *length, |
| 4864 | void **pointer) |
| 4865 | { |
| 4866 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4867 | { |
| 4868 | return false; |
| 4869 | } |
| 4870 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4871 | GLsizei writeLength = 0; |
| 4872 | |
| 4873 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4874 | { |
| 4875 | return false; |
| 4876 | } |
| 4877 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4878 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4879 | { |
| 4880 | return false; |
| 4881 | } |
| 4882 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4883 | SetRobustLengthParam(length, writeLength); |
| 4884 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4885 | return true; |
| 4886 | } |
| 4887 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4888 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4889 | GLuint index, |
| 4890 | GLenum pname, |
| 4891 | GLsizei bufSize, |
| 4892 | GLsizei *length, |
| 4893 | GLint *params) |
| 4894 | { |
| 4895 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4896 | { |
| 4897 | return false; |
| 4898 | } |
| 4899 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4900 | GLsizei writeLength = 0; |
| 4901 | |
| 4902 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4903 | { |
| 4904 | return false; |
| 4905 | } |
| 4906 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4907 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4908 | { |
| 4909 | return false; |
| 4910 | } |
| 4911 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4912 | SetRobustLengthParam(length, writeLength); |
| 4913 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4914 | return true; |
| 4915 | } |
| 4916 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4917 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4918 | GLuint index, |
| 4919 | GLenum pname, |
| 4920 | GLsizei bufSize, |
| 4921 | GLsizei *length, |
| 4922 | GLuint *params) |
| 4923 | { |
| 4924 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4925 | { |
| 4926 | return false; |
| 4927 | } |
| 4928 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4929 | GLsizei writeLength = 0; |
| 4930 | |
| 4931 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4932 | { |
| 4933 | return false; |
| 4934 | } |
| 4935 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4936 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4937 | { |
| 4938 | return false; |
| 4939 | } |
| 4940 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4941 | SetRobustLengthParam(length, writeLength); |
| 4942 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4943 | return true; |
| 4944 | } |
| 4945 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4946 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 4947 | GLuint program, |
| 4948 | GLuint uniformBlockIndex, |
| 4949 | GLenum pname, |
| 4950 | GLsizei bufSize, |
| 4951 | GLsizei *length, |
| 4952 | GLint *params) |
| 4953 | { |
| 4954 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4955 | { |
| 4956 | return false; |
| 4957 | } |
| 4958 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4959 | GLsizei writeLength = 0; |
| 4960 | |
| 4961 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 4962 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4963 | { |
| 4964 | return false; |
| 4965 | } |
| 4966 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4967 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4968 | { |
| 4969 | return false; |
| 4970 | } |
| 4971 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4972 | SetRobustLengthParam(length, writeLength); |
| 4973 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4974 | return true; |
| 4975 | } |
| 4976 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 4977 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4978 | GLenum target, |
| 4979 | GLenum internalformat, |
| 4980 | GLenum pname, |
| 4981 | GLsizei bufSize, |
| 4982 | GLsizei *length, |
| 4983 | GLint *params) |
| 4984 | { |
| 4985 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4986 | { |
| 4987 | return false; |
| 4988 | } |
| 4989 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4990 | GLsizei numParams = 0; |
| 4991 | |
| 4992 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 4993 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4994 | { |
| 4995 | return false; |
| 4996 | } |
| 4997 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4998 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4999 | { |
| 5000 | return false; |
| 5001 | } |
| 5002 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5003 | SetRobustLengthParam(length, numParams); |
| 5004 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5005 | return true; |
| 5006 | } |
| 5007 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5008 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5009 | GLuint attribIndex, |
| 5010 | GLint size, |
| 5011 | GLenum type, |
| 5012 | GLboolean pureInteger) |
| 5013 | { |
| 5014 | const Caps &caps = context->getCaps(); |
| 5015 | if (attribIndex >= caps.maxVertexAttributes) |
| 5016 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5017 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5018 | return false; |
| 5019 | } |
| 5020 | |
| 5021 | if (size < 1 || size > 4) |
| 5022 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5023 | context->validationError(GL_INVALID_VALUE, kInvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5024 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5025 | } |
| 5026 | |
| 5027 | switch (type) |
| 5028 | { |
| 5029 | case GL_BYTE: |
| 5030 | case GL_UNSIGNED_BYTE: |
| 5031 | case GL_SHORT: |
| 5032 | case GL_UNSIGNED_SHORT: |
| 5033 | break; |
| 5034 | |
| 5035 | case GL_INT: |
| 5036 | case GL_UNSIGNED_INT: |
| 5037 | if (context->getClientMajorVersion() < 3) |
| 5038 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5039 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5040 | return false; |
| 5041 | } |
| 5042 | break; |
| 5043 | |
| 5044 | case GL_FIXED: |
| 5045 | case GL_FLOAT: |
| 5046 | if (pureInteger) |
| 5047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5048 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5049 | return false; |
| 5050 | } |
| 5051 | break; |
| 5052 | |
| 5053 | case GL_HALF_FLOAT: |
| 5054 | if (context->getClientMajorVersion() < 3) |
| 5055 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5056 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5057 | return false; |
| 5058 | } |
| 5059 | if (pureInteger) |
| 5060 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5061 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5062 | return false; |
| 5063 | } |
| 5064 | break; |
| 5065 | |
| 5066 | case GL_INT_2_10_10_10_REV: |
| 5067 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5068 | if (context->getClientMajorVersion() < 3) |
| 5069 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5070 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5071 | return false; |
| 5072 | } |
| 5073 | if (pureInteger) |
| 5074 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5075 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5076 | return false; |
| 5077 | } |
| 5078 | if (size != 4) |
| 5079 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5080 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexAttribSize2101010); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5081 | return false; |
| 5082 | } |
| 5083 | break; |
| 5084 | |
| 5085 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5086 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5087 | return false; |
| 5088 | } |
| 5089 | |
| 5090 | return true; |
| 5091 | } |
| 5092 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5093 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5094 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5095 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5096 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5097 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5098 | GLint drawbuffer, |
| 5099 | const GLenum *validComponentTypes, |
| 5100 | size_t validComponentTypeCount) |
| 5101 | { |
| 5102 | const FramebufferAttachment *attachment = |
| 5103 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5104 | if (attachment) |
| 5105 | { |
| 5106 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5107 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5108 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5109 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5110 | context->validationError(GL_INVALID_OPERATION, kNoDefinedClearConversion); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5111 | return false; |
| 5112 | } |
| 5113 | } |
| 5114 | |
| 5115 | return true; |
| 5116 | } |
| 5117 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5118 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5119 | { |
| 5120 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5121 | { |
| 5122 | return false; |
| 5123 | } |
| 5124 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5125 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5126 | if (pixelUnpackBuffer == nullptr) |
| 5127 | { |
| 5128 | if (dataSize < imageSize) |
| 5129 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5130 | context->validationError(GL_INVALID_OPERATION, kCompressedDataSizeTooSmall); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5131 | } |
| 5132 | } |
| 5133 | return true; |
| 5134 | } |
| 5135 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5136 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5137 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5138 | GLenum pname, |
| 5139 | bool pointerVersion, |
| 5140 | GLsizei *numParams) |
| 5141 | { |
| 5142 | if (numParams) |
| 5143 | { |
| 5144 | *numParams = 0; |
| 5145 | } |
| 5146 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5147 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5148 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5149 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5150 | return false; |
| 5151 | } |
| 5152 | |
| 5153 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5154 | if (!buffer) |
| 5155 | { |
| 5156 | // A null buffer means that "0" is bound to the requested buffer target |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5157 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5158 | return false; |
| 5159 | } |
| 5160 | |
| 5161 | const Extensions &extensions = context->getExtensions(); |
| 5162 | |
| 5163 | switch (pname) |
| 5164 | { |
| 5165 | case GL_BUFFER_USAGE: |
| 5166 | case GL_BUFFER_SIZE: |
| 5167 | break; |
| 5168 | |
| 5169 | case GL_BUFFER_ACCESS_OES: |
| 5170 | if (!extensions.mapBuffer) |
| 5171 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5172 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5173 | return false; |
| 5174 | } |
| 5175 | break; |
| 5176 | |
| 5177 | case GL_BUFFER_MAPPED: |
| 5178 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5179 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5180 | !extensions.mapBufferRange) |
| 5181 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5182 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5183 | return false; |
| 5184 | } |
| 5185 | break; |
| 5186 | |
| 5187 | case GL_BUFFER_MAP_POINTER: |
| 5188 | if (!pointerVersion) |
| 5189 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5190 | context->validationError(GL_INVALID_ENUM, kInvalidMapPointerQuery); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5191 | return false; |
| 5192 | } |
| 5193 | break; |
| 5194 | |
| 5195 | case GL_BUFFER_ACCESS_FLAGS: |
| 5196 | case GL_BUFFER_MAP_OFFSET: |
| 5197 | case GL_BUFFER_MAP_LENGTH: |
| 5198 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5199 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5200 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5201 | return false; |
| 5202 | } |
| 5203 | break; |
| 5204 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5205 | case GL_MEMORY_SIZE_ANGLE: |
| 5206 | if (!context->getExtensions().memorySize) |
| 5207 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5208 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5209 | return false; |
| 5210 | } |
| 5211 | break; |
| 5212 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5213 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5214 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5215 | return false; |
| 5216 | } |
| 5217 | |
| 5218 | // All buffer parameter queries return one value. |
| 5219 | if (numParams) |
| 5220 | { |
| 5221 | *numParams = 1; |
| 5222 | } |
| 5223 | |
| 5224 | return true; |
| 5225 | } |
| 5226 | |
| 5227 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5228 | GLenum target, |
| 5229 | GLenum pname, |
| 5230 | GLsizei *length) |
| 5231 | { |
| 5232 | if (length) |
| 5233 | { |
| 5234 | *length = 0; |
| 5235 | } |
| 5236 | |
| 5237 | if (target != GL_RENDERBUFFER) |
| 5238 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5239 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5240 | return false; |
| 5241 | } |
| 5242 | |
| 5243 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5244 | if (renderbuffer == nullptr) |
| 5245 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5246 | context->validationError(GL_INVALID_OPERATION, kRenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5247 | return false; |
| 5248 | } |
| 5249 | |
| 5250 | switch (pname) |
| 5251 | { |
| 5252 | case GL_RENDERBUFFER_WIDTH: |
| 5253 | case GL_RENDERBUFFER_HEIGHT: |
| 5254 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5255 | case GL_RENDERBUFFER_RED_SIZE: |
| 5256 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5257 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5258 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5259 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5260 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5261 | break; |
| 5262 | |
| 5263 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5264 | if (!context->getExtensions().framebufferMultisample) |
| 5265 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5266 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | break; |
| 5270 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5271 | case GL_MEMORY_SIZE_ANGLE: |
| 5272 | if (!context->getExtensions().memorySize) |
| 5273 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5274 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5275 | return false; |
| 5276 | } |
| 5277 | break; |
| 5278 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5279 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5280 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5281 | return false; |
| 5282 | } |
| 5283 | |
| 5284 | if (length) |
| 5285 | { |
| 5286 | *length = 1; |
| 5287 | } |
| 5288 | return true; |
| 5289 | } |
| 5290 | |
| 5291 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5292 | { |
| 5293 | if (length) |
| 5294 | { |
| 5295 | *length = 0; |
| 5296 | } |
| 5297 | |
| 5298 | if (GetValidShader(context, shader) == nullptr) |
| 5299 | { |
| 5300 | return false; |
| 5301 | } |
| 5302 | |
| 5303 | switch (pname) |
| 5304 | { |
| 5305 | case GL_SHADER_TYPE: |
| 5306 | case GL_DELETE_STATUS: |
| 5307 | case GL_COMPILE_STATUS: |
| 5308 | case GL_INFO_LOG_LENGTH: |
| 5309 | case GL_SHADER_SOURCE_LENGTH: |
| 5310 | break; |
| 5311 | |
| 5312 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5313 | if (!context->getExtensions().translatedShaderSource) |
| 5314 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5315 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5316 | return false; |
| 5317 | } |
| 5318 | break; |
| 5319 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5320 | case GL_COMPLETION_STATUS_KHR: |
| 5321 | if (!context->getExtensions().parallelShaderCompile) |
| 5322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5323 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5324 | return false; |
| 5325 | } |
| 5326 | break; |
| 5327 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5328 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5329 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5330 | return false; |
| 5331 | } |
| 5332 | |
| 5333 | if (length) |
| 5334 | { |
| 5335 | *length = 1; |
| 5336 | } |
| 5337 | return true; |
| 5338 | } |
| 5339 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5340 | bool ValidateGetTexParameterBase(Context *context, |
| 5341 | TextureType target, |
| 5342 | GLenum pname, |
| 5343 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5344 | { |
| 5345 | if (length) |
| 5346 | { |
| 5347 | *length = 0; |
| 5348 | } |
| 5349 | |
| 5350 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5351 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5352 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | if (context->getTargetTexture(target) == nullptr) |
| 5357 | { |
| 5358 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5359 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5360 | return false; |
| 5361 | } |
| 5362 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5363 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5364 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5365 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5366 | return false; |
| 5367 | } |
| 5368 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5369 | switch (pname) |
| 5370 | { |
| 5371 | case GL_TEXTURE_MAG_FILTER: |
| 5372 | case GL_TEXTURE_MIN_FILTER: |
| 5373 | case GL_TEXTURE_WRAP_S: |
| 5374 | case GL_TEXTURE_WRAP_T: |
| 5375 | break; |
| 5376 | |
| 5377 | case GL_TEXTURE_USAGE_ANGLE: |
| 5378 | if (!context->getExtensions().textureUsage) |
| 5379 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5380 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5381 | return false; |
| 5382 | } |
| 5383 | break; |
| 5384 | |
| 5385 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5386 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5387 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5388 | return false; |
| 5389 | } |
| 5390 | break; |
| 5391 | |
| 5392 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5393 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5394 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5395 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5396 | return false; |
| 5397 | } |
| 5398 | break; |
| 5399 | |
| 5400 | case GL_TEXTURE_WRAP_R: |
| 5401 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5402 | case GL_TEXTURE_SWIZZLE_R: |
| 5403 | case GL_TEXTURE_SWIZZLE_G: |
| 5404 | case GL_TEXTURE_SWIZZLE_B: |
| 5405 | case GL_TEXTURE_SWIZZLE_A: |
| 5406 | case GL_TEXTURE_BASE_LEVEL: |
| 5407 | case GL_TEXTURE_MAX_LEVEL: |
| 5408 | case GL_TEXTURE_MIN_LOD: |
| 5409 | case GL_TEXTURE_MAX_LOD: |
| 5410 | case GL_TEXTURE_COMPARE_MODE: |
| 5411 | case GL_TEXTURE_COMPARE_FUNC: |
| 5412 | if (context->getClientMajorVersion() < 3) |
| 5413 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5414 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5415 | return false; |
| 5416 | } |
| 5417 | break; |
| 5418 | |
| 5419 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5420 | if (!context->getExtensions().textureSRGBDecode) |
| 5421 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5422 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5423 | return false; |
| 5424 | } |
| 5425 | break; |
| 5426 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5427 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5428 | if (context->getClientVersion() < Version(3, 1)) |
| 5429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5430 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5431 | return false; |
| 5432 | } |
| 5433 | break; |
| 5434 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5435 | case GL_GENERATE_MIPMAP: |
| 5436 | case GL_TEXTURE_CROP_RECT_OES: |
| 5437 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5438 | // after GL_OES_draw_texture functionality implemented |
| 5439 | if (context->getClientMajorVersion() > 1) |
| 5440 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5441 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5442 | return false; |
| 5443 | } |
| 5444 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5445 | |
| 5446 | case GL_MEMORY_SIZE_ANGLE: |
| 5447 | if (!context->getExtensions().memorySize) |
| 5448 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5449 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5450 | return false; |
| 5451 | } |
| 5452 | break; |
| 5453 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5454 | case GL_TEXTURE_BORDER_COLOR: |
| 5455 | if (!context->getExtensions().textureBorderClamp) |
| 5456 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5457 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5458 | return false; |
| 5459 | } |
| 5460 | break; |
| 5461 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5462 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5463 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5464 | return false; |
| 5465 | } |
| 5466 | |
| 5467 | if (length) |
| 5468 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5469 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5470 | } |
| 5471 | return true; |
| 5472 | } |
| 5473 | |
| 5474 | bool ValidateGetVertexAttribBase(Context *context, |
| 5475 | GLuint index, |
| 5476 | GLenum pname, |
| 5477 | GLsizei *length, |
| 5478 | bool pointer, |
| 5479 | bool pureIntegerEntryPoint) |
| 5480 | { |
| 5481 | if (length) |
| 5482 | { |
| 5483 | *length = 0; |
| 5484 | } |
| 5485 | |
| 5486 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5487 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5488 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5489 | return false; |
| 5490 | } |
| 5491 | |
| 5492 | if (index >= context->getCaps().maxVertexAttributes) |
| 5493 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5494 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5495 | return false; |
| 5496 | } |
| 5497 | |
| 5498 | if (pointer) |
| 5499 | { |
| 5500 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5501 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5502 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5503 | return false; |
| 5504 | } |
| 5505 | } |
| 5506 | else |
| 5507 | { |
| 5508 | switch (pname) |
| 5509 | { |
| 5510 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5511 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5512 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5513 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5514 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5515 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5516 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5517 | break; |
| 5518 | |
| 5519 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5520 | static_assert( |
| 5521 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5522 | "ANGLE extension enums not equal to GL enums."); |
| 5523 | if (context->getClientMajorVersion() < 3 && |
| 5524 | !context->getExtensions().instancedArrays) |
| 5525 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5526 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5527 | return false; |
| 5528 | } |
| 5529 | break; |
| 5530 | |
| 5531 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5532 | if (context->getClientMajorVersion() < 3) |
| 5533 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5534 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | break; |
| 5538 | |
| 5539 | case GL_VERTEX_ATTRIB_BINDING: |
| 5540 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5541 | if (context->getClientVersion() < ES_3_1) |
| 5542 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5543 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5544 | return false; |
| 5545 | } |
| 5546 | break; |
| 5547 | |
| 5548 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5549 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5550 | return false; |
| 5551 | } |
| 5552 | } |
| 5553 | |
| 5554 | if (length) |
| 5555 | { |
| 5556 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5557 | { |
| 5558 | *length = 4; |
| 5559 | } |
| 5560 | else |
| 5561 | { |
| 5562 | *length = 1; |
| 5563 | } |
| 5564 | } |
| 5565 | |
| 5566 | return true; |
| 5567 | } |
| 5568 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5569 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5570 | GLint x, |
| 5571 | GLint y, |
| 5572 | GLsizei width, |
| 5573 | GLsizei height, |
| 5574 | GLenum format, |
| 5575 | GLenum type, |
| 5576 | GLsizei bufSize, |
| 5577 | GLsizei *length, |
| 5578 | GLsizei *columns, |
| 5579 | GLsizei *rows, |
| 5580 | void *pixels) |
| 5581 | { |
| 5582 | if (length != nullptr) |
| 5583 | { |
| 5584 | *length = 0; |
| 5585 | } |
| 5586 | if (rows != nullptr) |
| 5587 | { |
| 5588 | *rows = 0; |
| 5589 | } |
| 5590 | if (columns != nullptr) |
| 5591 | { |
| 5592 | *columns = 0; |
| 5593 | } |
| 5594 | |
| 5595 | if (width < 0 || height < 0) |
| 5596 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5597 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5598 | return false; |
| 5599 | } |
| 5600 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5601 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5602 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5603 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5604 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5605 | return false; |
| 5606 | } |
| 5607 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5608 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5609 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5610 | return false; |
| 5611 | } |
| 5612 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5613 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5614 | ASSERT(framebuffer); |
| 5615 | |
| 5616 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5618 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5619 | return false; |
| 5620 | } |
| 5621 | |
| 5622 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5623 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5624 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5625 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5626 | // situation is an application error that would lead to a crash in ANGLE. |
| 5627 | if (readBuffer == nullptr) |
| 5628 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5629 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5630 | return false; |
| 5631 | } |
| 5632 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5633 | // ANGLE_multiview, Revision 1: |
| 5634 | // 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] | 5635 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5636 | // in the current read framebuffer is more than one. |
| 5637 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5638 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5639 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kMultiviewReadFramebuffer); |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5640 | return false; |
| 5641 | } |
| 5642 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5643 | if (context->getExtensions().webglCompatibility) |
| 5644 | { |
| 5645 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5646 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5647 | // and type before validating the combination of format and type. However, the |
| 5648 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5649 | // verifies that GL_INVALID_OPERATION is generated. |
| 5650 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5651 | // dEQP/WebGL. |
| 5652 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5653 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5654 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5655 | return false; |
| 5656 | } |
| 5657 | |
| 5658 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5659 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5660 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5661 | return false; |
| 5662 | } |
| 5663 | } |
| 5664 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5665 | GLenum currentFormat = GL_NONE; |
| 5666 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5667 | |
| 5668 | GLenum currentType = GL_NONE; |
| 5669 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5670 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5671 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5672 | |
| 5673 | bool validFormatTypeCombination = |
| 5674 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5675 | |
| 5676 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5677 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5678 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5679 | return false; |
| 5680 | } |
| 5681 | |
| 5682 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5683 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5684 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5685 | { |
| 5686 | // ...the buffer object's data store is currently mapped. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5687 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5688 | return false; |
| 5689 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5690 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5691 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5693 | context->validationError(GL_INVALID_OPERATION, kPixelPackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5694 | return false; |
| 5695 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5696 | |
| 5697 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5698 | // would exceed the data store size. |
| 5699 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5700 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5701 | const auto &pack = context->getGLState().getPackState(); |
| 5702 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5703 | GLuint endByte = 0; |
| 5704 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5705 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5706 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5707 | return false; |
| 5708 | } |
| 5709 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5710 | if (bufSize >= 0) |
| 5711 | { |
| 5712 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5713 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5714 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5715 | return false; |
| 5716 | } |
| 5717 | } |
| 5718 | |
| 5719 | if (pixelPackBuffer != nullptr) |
| 5720 | { |
| 5721 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5722 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5723 | checkedEndByte += checkedOffset; |
| 5724 | |
| 5725 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5726 | { |
| 5727 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5728 | context->validationError(GL_INVALID_OPERATION, kParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5729 | return false; |
| 5730 | } |
| 5731 | } |
| 5732 | |
| 5733 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5734 | { |
| 5735 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5736 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5737 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5738 | return false; |
| 5739 | } |
| 5740 | |
| 5741 | *length = static_cast<GLsizei>(endByte); |
| 5742 | } |
| 5743 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5744 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5745 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5746 | if (start < 0) |
| 5747 | { |
| 5748 | // "subtract" the area that is less than 0 |
| 5749 | clippedExtent += start; |
| 5750 | } |
| 5751 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5752 | angle::CheckedNumeric<int> readExtent = start; |
| 5753 | readExtent += length; |
| 5754 | if (!readExtent.IsValid()) |
| 5755 | { |
| 5756 | return false; |
| 5757 | } |
| 5758 | |
| 5759 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5760 | { |
| 5761 | // Subtract the region to the right of the read buffer |
| 5762 | clippedExtent -= (readExtent - bufferSize); |
| 5763 | } |
| 5764 | |
| 5765 | if (!clippedExtent.IsValid()) |
| 5766 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5767 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5768 | } |
| 5769 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5770 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5771 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5772 | }; |
| 5773 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5774 | GLsizei writtenColumns = 0; |
| 5775 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5776 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5777 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5778 | return false; |
| 5779 | } |
| 5780 | |
| 5781 | GLsizei writtenRows = 0; |
| 5782 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5783 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5784 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5785 | return false; |
| 5786 | } |
| 5787 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5788 | if (columns != nullptr) |
| 5789 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5790 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5791 | } |
| 5792 | |
| 5793 | if (rows != nullptr) |
| 5794 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5795 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5796 | } |
| 5797 | |
| 5798 | return true; |
| 5799 | } |
| 5800 | |
| 5801 | template <typename ParamType> |
| 5802 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5803 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5804 | GLenum pname, |
| 5805 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5806 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5807 | const ParamType *params) |
| 5808 | { |
| 5809 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5810 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5811 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5812 | return false; |
| 5813 | } |
| 5814 | |
| 5815 | if (context->getTargetTexture(target) == nullptr) |
| 5816 | { |
| 5817 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5818 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5819 | return false; |
| 5820 | } |
| 5821 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5822 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5823 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5824 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5825 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5826 | return false; |
| 5827 | } |
| 5828 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5829 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5830 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5831 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5832 | return false; |
| 5833 | } |
| 5834 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5835 | switch (pname) |
| 5836 | { |
| 5837 | case GL_TEXTURE_WRAP_R: |
| 5838 | case GL_TEXTURE_SWIZZLE_R: |
| 5839 | case GL_TEXTURE_SWIZZLE_G: |
| 5840 | case GL_TEXTURE_SWIZZLE_B: |
| 5841 | case GL_TEXTURE_SWIZZLE_A: |
| 5842 | case GL_TEXTURE_BASE_LEVEL: |
| 5843 | case GL_TEXTURE_MAX_LEVEL: |
| 5844 | case GL_TEXTURE_COMPARE_MODE: |
| 5845 | case GL_TEXTURE_COMPARE_FUNC: |
| 5846 | case GL_TEXTURE_MIN_LOD: |
| 5847 | case GL_TEXTURE_MAX_LOD: |
| 5848 | if (context->getClientMajorVersion() < 3) |
| 5849 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5850 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5851 | return false; |
| 5852 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5853 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5854 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5855 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5856 | return false; |
| 5857 | } |
| 5858 | break; |
| 5859 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5860 | case GL_GENERATE_MIPMAP: |
| 5861 | case GL_TEXTURE_CROP_RECT_OES: |
| 5862 | if (context->getClientMajorVersion() > 1) |
| 5863 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5864 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5865 | return false; |
| 5866 | } |
| 5867 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5868 | default: |
| 5869 | break; |
| 5870 | } |
| 5871 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5872 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5873 | { |
| 5874 | switch (pname) |
| 5875 | { |
| 5876 | case GL_TEXTURE_MIN_FILTER: |
| 5877 | case GL_TEXTURE_MAG_FILTER: |
| 5878 | case GL_TEXTURE_WRAP_S: |
| 5879 | case GL_TEXTURE_WRAP_T: |
| 5880 | case GL_TEXTURE_WRAP_R: |
| 5881 | case GL_TEXTURE_MIN_LOD: |
| 5882 | case GL_TEXTURE_MAX_LOD: |
| 5883 | case GL_TEXTURE_COMPARE_MODE: |
| 5884 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5885 | case GL_TEXTURE_BORDER_COLOR: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5886 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5887 | return false; |
| 5888 | } |
| 5889 | } |
| 5890 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5891 | switch (pname) |
| 5892 | { |
| 5893 | case GL_TEXTURE_WRAP_S: |
| 5894 | case GL_TEXTURE_WRAP_T: |
| 5895 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5896 | { |
| 5897 | bool restrictedWrapModes = |
| 5898 | target == TextureType::External || target == TextureType::Rectangle; |
| 5899 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5900 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5901 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5902 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5903 | } |
| 5904 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5905 | |
| 5906 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5907 | { |
| 5908 | bool restrictedMinFilter = |
| 5909 | target == TextureType::External || target == TextureType::Rectangle; |
| 5910 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5911 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5912 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5913 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5914 | } |
| 5915 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5916 | |
| 5917 | case GL_TEXTURE_MAG_FILTER: |
| 5918 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5919 | { |
| 5920 | return false; |
| 5921 | } |
| 5922 | break; |
| 5923 | |
| 5924 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5925 | if (!context->getExtensions().textureUsage) |
| 5926 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5927 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5928 | return false; |
| 5929 | } |
| 5930 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5931 | switch (ConvertToGLenum(params[0])) |
| 5932 | { |
| 5933 | case GL_NONE: |
| 5934 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5935 | break; |
| 5936 | |
| 5937 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5938 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5939 | return false; |
| 5940 | } |
| 5941 | break; |
| 5942 | |
| 5943 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5944 | { |
| 5945 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5946 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5947 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5948 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5949 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5950 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 5951 | } |
| 5952 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5953 | |
| 5954 | case GL_TEXTURE_MIN_LOD: |
| 5955 | case GL_TEXTURE_MAX_LOD: |
| 5956 | // any value is permissible |
| 5957 | break; |
| 5958 | |
| 5959 | case GL_TEXTURE_COMPARE_MODE: |
| 5960 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5961 | { |
| 5962 | return false; |
| 5963 | } |
| 5964 | break; |
| 5965 | |
| 5966 | case GL_TEXTURE_COMPARE_FUNC: |
| 5967 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5968 | { |
| 5969 | return false; |
| 5970 | } |
| 5971 | break; |
| 5972 | |
| 5973 | case GL_TEXTURE_SWIZZLE_R: |
| 5974 | case GL_TEXTURE_SWIZZLE_G: |
| 5975 | case GL_TEXTURE_SWIZZLE_B: |
| 5976 | case GL_TEXTURE_SWIZZLE_A: |
| 5977 | switch (ConvertToGLenum(params[0])) |
| 5978 | { |
| 5979 | case GL_RED: |
| 5980 | case GL_GREEN: |
| 5981 | case GL_BLUE: |
| 5982 | case GL_ALPHA: |
| 5983 | case GL_ZERO: |
| 5984 | case GL_ONE: |
| 5985 | break; |
| 5986 | |
| 5987 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5988 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5989 | return false; |
| 5990 | } |
| 5991 | break; |
| 5992 | |
| 5993 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5994 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5995 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5996 | context->validationError(GL_INVALID_VALUE, kBaseLevelNegative); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5997 | return false; |
| 5998 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5999 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6000 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6001 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6002 | return false; |
| 6003 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6004 | if ((target == TextureType::_2DMultisample || |
| 6005 | target == TextureType::_2DMultisampleArray) && |
| 6006 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6007 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6008 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6009 | return false; |
| 6010 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6011 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6012 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6013 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6014 | return false; |
| 6015 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6016 | break; |
| 6017 | |
| 6018 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6019 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6020 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6021 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6022 | return false; |
| 6023 | } |
| 6024 | break; |
| 6025 | |
| 6026 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6027 | if (context->getClientVersion() < Version(3, 1)) |
| 6028 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6029 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6030 | return false; |
| 6031 | } |
| 6032 | switch (ConvertToGLenum(params[0])) |
| 6033 | { |
| 6034 | case GL_DEPTH_COMPONENT: |
| 6035 | case GL_STENCIL_INDEX: |
| 6036 | break; |
| 6037 | |
| 6038 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6039 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6040 | return false; |
| 6041 | } |
| 6042 | break; |
| 6043 | |
| 6044 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6045 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6046 | { |
| 6047 | return false; |
| 6048 | } |
| 6049 | break; |
| 6050 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6051 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6052 | if (context->getClientMajorVersion() > 1) |
| 6053 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6054 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6055 | return false; |
| 6056 | } |
| 6057 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6058 | |
| 6059 | case GL_TEXTURE_CROP_RECT_OES: |
| 6060 | if (context->getClientMajorVersion() > 1) |
| 6061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6062 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6063 | return false; |
| 6064 | } |
| 6065 | if (!vectorParams) |
| 6066 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6067 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6068 | return false; |
| 6069 | } |
| 6070 | break; |
| 6071 | |
| 6072 | case GL_TEXTURE_BORDER_COLOR: |
| 6073 | if (!context->getExtensions().textureBorderClamp) |
| 6074 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6075 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6076 | return false; |
| 6077 | } |
| 6078 | if (!vectorParams) |
| 6079 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6080 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6081 | return false; |
| 6082 | } |
| 6083 | break; |
| 6084 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6085 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6086 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6087 | return false; |
| 6088 | } |
| 6089 | |
| 6090 | return true; |
| 6091 | } |
| 6092 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6093 | template bool ValidateTexParameterBase(Context *, |
| 6094 | TextureType, |
| 6095 | GLenum, |
| 6096 | GLsizei, |
| 6097 | bool, |
| 6098 | const GLfloat *); |
| 6099 | template bool ValidateTexParameterBase(Context *, |
| 6100 | TextureType, |
| 6101 | GLenum, |
| 6102 | GLsizei, |
| 6103 | bool, |
| 6104 | const GLint *); |
| 6105 | template bool ValidateTexParameterBase(Context *, |
| 6106 | TextureType, |
| 6107 | GLenum, |
| 6108 | GLsizei, |
| 6109 | bool, |
| 6110 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6111 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6112 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6113 | { |
| 6114 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6115 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6116 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6117 | return false; |
| 6118 | } |
| 6119 | |
| 6120 | return true; |
| 6121 | } |
| 6122 | |
| 6123 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6124 | GLuint program, |
| 6125 | GLuint uniformBlockIndex, |
| 6126 | GLenum pname, |
| 6127 | GLsizei *length) |
| 6128 | { |
| 6129 | if (length) |
| 6130 | { |
| 6131 | *length = 0; |
| 6132 | } |
| 6133 | |
| 6134 | if (context->getClientMajorVersion() < 3) |
| 6135 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6136 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6137 | return false; |
| 6138 | } |
| 6139 | |
| 6140 | Program *programObject = GetValidProgram(context, program); |
| 6141 | if (!programObject) |
| 6142 | { |
| 6143 | return false; |
| 6144 | } |
| 6145 | |
| 6146 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6147 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6148 | context->validationError(GL_INVALID_VALUE, kIndexExceedsActiveUniformBlockCount); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6149 | return false; |
| 6150 | } |
| 6151 | |
| 6152 | switch (pname) |
| 6153 | { |
| 6154 | case GL_UNIFORM_BLOCK_BINDING: |
| 6155 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6156 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6157 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6158 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6159 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6160 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6161 | break; |
| 6162 | |
| 6163 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6164 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6165 | return false; |
| 6166 | } |
| 6167 | |
| 6168 | if (length) |
| 6169 | { |
| 6170 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6171 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6172 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6173 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6174 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6175 | } |
| 6176 | else |
| 6177 | { |
| 6178 | *length = 1; |
| 6179 | } |
| 6180 | } |
| 6181 | |
| 6182 | return true; |
| 6183 | } |
| 6184 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6185 | template <typename ParamType> |
| 6186 | bool ValidateSamplerParameterBase(Context *context, |
| 6187 | GLuint sampler, |
| 6188 | GLenum pname, |
| 6189 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6190 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6191 | ParamType *params) |
| 6192 | { |
| 6193 | if (context->getClientMajorVersion() < 3) |
| 6194 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6195 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6196 | return false; |
| 6197 | } |
| 6198 | |
| 6199 | if (!context->isSampler(sampler)) |
| 6200 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6201 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6202 | return false; |
| 6203 | } |
| 6204 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6205 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6206 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6207 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6208 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6209 | return false; |
| 6210 | } |
| 6211 | |
| 6212 | switch (pname) |
| 6213 | { |
| 6214 | case GL_TEXTURE_WRAP_S: |
| 6215 | case GL_TEXTURE_WRAP_T: |
| 6216 | case GL_TEXTURE_WRAP_R: |
| 6217 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6218 | { |
| 6219 | return false; |
| 6220 | } |
| 6221 | break; |
| 6222 | |
| 6223 | case GL_TEXTURE_MIN_FILTER: |
| 6224 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6225 | { |
| 6226 | return false; |
| 6227 | } |
| 6228 | break; |
| 6229 | |
| 6230 | case GL_TEXTURE_MAG_FILTER: |
| 6231 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6232 | { |
| 6233 | return false; |
| 6234 | } |
| 6235 | break; |
| 6236 | |
| 6237 | case GL_TEXTURE_MIN_LOD: |
| 6238 | case GL_TEXTURE_MAX_LOD: |
| 6239 | // any value is permissible |
| 6240 | break; |
| 6241 | |
| 6242 | case GL_TEXTURE_COMPARE_MODE: |
| 6243 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6244 | { |
| 6245 | return false; |
| 6246 | } |
| 6247 | break; |
| 6248 | |
| 6249 | case GL_TEXTURE_COMPARE_FUNC: |
| 6250 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6251 | { |
| 6252 | return false; |
| 6253 | } |
| 6254 | break; |
| 6255 | |
| 6256 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6257 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6258 | { |
| 6259 | return false; |
| 6260 | } |
| 6261 | break; |
| 6262 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6263 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6264 | { |
| 6265 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6266 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6267 | { |
| 6268 | return false; |
| 6269 | } |
| 6270 | } |
| 6271 | break; |
| 6272 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6273 | case GL_TEXTURE_BORDER_COLOR: |
| 6274 | if (!context->getExtensions().textureBorderClamp) |
| 6275 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6276 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6277 | return false; |
| 6278 | } |
| 6279 | if (!vectorParams) |
| 6280 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6281 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6282 | return false; |
| 6283 | } |
| 6284 | break; |
| 6285 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6286 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6287 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6288 | return false; |
| 6289 | } |
| 6290 | |
| 6291 | return true; |
| 6292 | } |
| 6293 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6294 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6295 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6296 | template bool ValidateSamplerParameterBase(Context *, |
| 6297 | GLuint, |
| 6298 | GLenum, |
| 6299 | GLsizei, |
| 6300 | bool, |
| 6301 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6302 | |
| 6303 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6304 | GLuint sampler, |
| 6305 | GLenum pname, |
| 6306 | GLsizei *length) |
| 6307 | { |
| 6308 | if (length) |
| 6309 | { |
| 6310 | *length = 0; |
| 6311 | } |
| 6312 | |
| 6313 | if (context->getClientMajorVersion() < 3) |
| 6314 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6315 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6316 | return false; |
| 6317 | } |
| 6318 | |
| 6319 | if (!context->isSampler(sampler)) |
| 6320 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6321 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6322 | return false; |
| 6323 | } |
| 6324 | |
| 6325 | switch (pname) |
| 6326 | { |
| 6327 | case GL_TEXTURE_WRAP_S: |
| 6328 | case GL_TEXTURE_WRAP_T: |
| 6329 | case GL_TEXTURE_WRAP_R: |
| 6330 | case GL_TEXTURE_MIN_FILTER: |
| 6331 | case GL_TEXTURE_MAG_FILTER: |
| 6332 | case GL_TEXTURE_MIN_LOD: |
| 6333 | case GL_TEXTURE_MAX_LOD: |
| 6334 | case GL_TEXTURE_COMPARE_MODE: |
| 6335 | case GL_TEXTURE_COMPARE_FUNC: |
| 6336 | break; |
| 6337 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6338 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6339 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6340 | { |
| 6341 | return false; |
| 6342 | } |
| 6343 | break; |
| 6344 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6345 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6346 | if (!context->getExtensions().textureSRGBDecode) |
| 6347 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6348 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6349 | return false; |
| 6350 | } |
| 6351 | break; |
| 6352 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6353 | case GL_TEXTURE_BORDER_COLOR: |
| 6354 | if (!context->getExtensions().textureBorderClamp) |
| 6355 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6356 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6357 | return false; |
| 6358 | } |
| 6359 | break; |
| 6360 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6361 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6362 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6363 | return false; |
| 6364 | } |
| 6365 | |
| 6366 | if (length) |
| 6367 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6368 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6369 | } |
| 6370 | return true; |
| 6371 | } |
| 6372 | |
| 6373 | bool ValidateGetInternalFormativBase(Context *context, |
| 6374 | GLenum target, |
| 6375 | GLenum internalformat, |
| 6376 | GLenum pname, |
| 6377 | GLsizei bufSize, |
| 6378 | GLsizei *numParams) |
| 6379 | { |
| 6380 | if (numParams) |
| 6381 | { |
| 6382 | *numParams = 0; |
| 6383 | } |
| 6384 | |
| 6385 | if (context->getClientMajorVersion() < 3) |
| 6386 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6387 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6388 | return false; |
| 6389 | } |
| 6390 | |
| 6391 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6392 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6393 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6394 | context->validationError(GL_INVALID_ENUM, kFormatNotRenderable); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6395 | return false; |
| 6396 | } |
| 6397 | |
| 6398 | switch (target) |
| 6399 | { |
| 6400 | case GL_RENDERBUFFER: |
| 6401 | break; |
| 6402 | |
| 6403 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6404 | if (context->getClientVersion() < ES_3_1 && |
| 6405 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6406 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6407 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6408 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6409 | return false; |
| 6410 | } |
| 6411 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6412 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6413 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6414 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6415 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6416 | return false; |
| 6417 | } |
| 6418 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6419 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6420 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6421 | return false; |
| 6422 | } |
| 6423 | |
| 6424 | if (bufSize < 0) |
| 6425 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6426 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6427 | return false; |
| 6428 | } |
| 6429 | |
| 6430 | GLsizei maxWriteParams = 0; |
| 6431 | switch (pname) |
| 6432 | { |
| 6433 | case GL_NUM_SAMPLE_COUNTS: |
| 6434 | maxWriteParams = 1; |
| 6435 | break; |
| 6436 | |
| 6437 | case GL_SAMPLES: |
| 6438 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6439 | break; |
| 6440 | |
| 6441 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6442 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6443 | return false; |
| 6444 | } |
| 6445 | |
| 6446 | if (numParams) |
| 6447 | { |
| 6448 | // glGetInternalFormativ will not overflow bufSize |
| 6449 | *numParams = std::min(bufSize, maxWriteParams); |
| 6450 | } |
| 6451 | |
| 6452 | return true; |
| 6453 | } |
| 6454 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6455 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6456 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6457 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6458 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6459 | context->validationError(GL_INVALID_OPERATION, kInvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6460 | return false; |
| 6461 | } |
| 6462 | return true; |
| 6463 | } |
| 6464 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6465 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6466 | { |
| 6467 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6468 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6469 | context->validationError(GL_INVALID_ENUM, kInvalidMultitextureUnit); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6470 | return false; |
| 6471 | } |
| 6472 | return true; |
| 6473 | } |
| 6474 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6475 | bool ValidateTexStorageMultisample(Context *context, |
| 6476 | TextureType target, |
| 6477 | GLsizei samples, |
| 6478 | GLint internalFormat, |
| 6479 | GLsizei width, |
| 6480 | GLsizei height) |
| 6481 | { |
| 6482 | const Caps &caps = context->getCaps(); |
| 6483 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6484 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6485 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6486 | context->validationError(GL_INVALID_VALUE, kTextureWidthOrHeightOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6487 | return false; |
| 6488 | } |
| 6489 | |
| 6490 | if (samples == 0) |
| 6491 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6492 | context->validationError(GL_INVALID_VALUE, kSamplesZero); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6493 | return false; |
| 6494 | } |
| 6495 | |
| 6496 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6497 | if (!formatCaps.textureAttachment) |
| 6498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6499 | context->validationError(GL_INVALID_ENUM, kRenderableInternalFormat); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6500 | return false; |
| 6501 | } |
| 6502 | |
| 6503 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6504 | // is one of the unsized base internalformats listed in table 8.11. |
| 6505 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6506 | if (formatInfo.internalFormat == GL_NONE) |
| 6507 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6508 | context->validationError(GL_INVALID_ENUM, kUnsizedInternalFormatUnsupported); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6509 | return false; |
| 6510 | } |
| 6511 | |
| 6512 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6513 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6514 | context->validationError(GL_INVALID_OPERATION, kSamplesOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6515 | return false; |
| 6516 | } |
| 6517 | |
| 6518 | Texture *texture = context->getTargetTexture(target); |
| 6519 | if (!texture || texture->id() == 0) |
| 6520 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6521 | context->validationError(GL_INVALID_OPERATION, kZeroBoundToTarget); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6522 | return false; |
| 6523 | } |
| 6524 | |
| 6525 | if (texture->getImmutableFormat()) |
| 6526 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6527 | context->validationError(GL_INVALID_OPERATION, kImmutableTextureBound); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6528 | return false; |
| 6529 | } |
| 6530 | return true; |
| 6531 | } |
| 6532 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6533 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6534 | TextureType target, |
| 6535 | GLsizei samples, |
| 6536 | GLint internalFormat, |
| 6537 | GLsizei width, |
| 6538 | GLsizei height) |
| 6539 | { |
| 6540 | if (target != TextureType::_2DMultisample) |
| 6541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6542 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6543 | return false; |
| 6544 | } |
| 6545 | |
| 6546 | if (width < 1 || height < 1) |
| 6547 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6548 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6549 | return false; |
| 6550 | } |
| 6551 | |
| 6552 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6553 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6554 | |
| 6555 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6556 | TextureTarget target, |
| 6557 | GLint level, |
| 6558 | GLenum pname, |
| 6559 | GLsizei *length) |
| 6560 | { |
| 6561 | |
| 6562 | if (length) |
| 6563 | { |
| 6564 | *length = 0; |
| 6565 | } |
| 6566 | |
| 6567 | TextureType type = TextureTargetToType(target); |
| 6568 | |
| 6569 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6570 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6571 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6572 | return false; |
| 6573 | } |
| 6574 | |
| 6575 | if (context->getTargetTexture(type) == nullptr) |
| 6576 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6577 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6578 | return false; |
| 6579 | } |
| 6580 | |
| 6581 | if (!ValidMipLevel(context, type, level)) |
| 6582 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6583 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6584 | return false; |
| 6585 | } |
| 6586 | |
| 6587 | switch (pname) |
| 6588 | { |
| 6589 | case GL_TEXTURE_RED_TYPE: |
| 6590 | case GL_TEXTURE_GREEN_TYPE: |
| 6591 | case GL_TEXTURE_BLUE_TYPE: |
| 6592 | case GL_TEXTURE_ALPHA_TYPE: |
| 6593 | case GL_TEXTURE_DEPTH_TYPE: |
| 6594 | break; |
| 6595 | case GL_TEXTURE_RED_SIZE: |
| 6596 | case GL_TEXTURE_GREEN_SIZE: |
| 6597 | case GL_TEXTURE_BLUE_SIZE: |
| 6598 | case GL_TEXTURE_ALPHA_SIZE: |
| 6599 | case GL_TEXTURE_DEPTH_SIZE: |
| 6600 | case GL_TEXTURE_STENCIL_SIZE: |
| 6601 | case GL_TEXTURE_SHARED_SIZE: |
| 6602 | break; |
| 6603 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6604 | case GL_TEXTURE_WIDTH: |
| 6605 | case GL_TEXTURE_HEIGHT: |
| 6606 | case GL_TEXTURE_DEPTH: |
| 6607 | break; |
| 6608 | case GL_TEXTURE_SAMPLES: |
| 6609 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6610 | break; |
| 6611 | case GL_TEXTURE_COMPRESSED: |
| 6612 | break; |
| 6613 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6614 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6615 | return false; |
| 6616 | } |
| 6617 | |
| 6618 | if (length) |
| 6619 | { |
| 6620 | *length = 1; |
| 6621 | } |
| 6622 | return true; |
| 6623 | } |
Yizhou Jiang | 7310da3 | 2018-11-05 14:40:01 +0800 | [diff] [blame] | 6624 | |
| 6625 | bool ValidateGetMultisamplefvBase(Context *context, GLenum pname, GLuint index, GLfloat *val) |
| 6626 | { |
| 6627 | if (pname != GL_SAMPLE_POSITION) |
| 6628 | { |
| 6629 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
| 6630 | return false; |
| 6631 | } |
| 6632 | |
| 6633 | Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 6634 | GLint samples = framebuffer->getSamples(context); |
| 6635 | |
| 6636 | if (index >= static_cast<GLuint>(samples)) |
| 6637 | { |
| 6638 | context->validationError(GL_INVALID_VALUE, kIndexExceedsSamples); |
| 6639 | return false; |
| 6640 | } |
| 6641 | |
| 6642 | return true; |
| 6643 | } |
| 6644 | |
| 6645 | bool ValidateSampleMaskiBase(Context *context, GLuint maskNumber, GLbitfield mask) |
| 6646 | { |
| 6647 | if (maskNumber >= context->getCaps().maxSampleMaskWords) |
| 6648 | { |
| 6649 | context->validationError(GL_INVALID_VALUE, kInvalidSampleMaskNumber); |
| 6650 | return false; |
| 6651 | } |
| 6652 | |
| 6653 | return true; |
| 6654 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6655 | } // namespace gl |