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" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 21 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 22 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 23 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 24 | #include "libANGLE/queryutils.h" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 25 | #include "libANGLE/validationES2_autogen.h" |
| 26 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 27 | |
| 28 | #include "common/mathutil.h" |
| 29 | #include "common/utilities.h" |
| 30 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 31 | using namespace angle; |
| 32 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 33 | namespace gl |
| 34 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 35 | using namespace err; |
| 36 | |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 37 | namespace |
| 38 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 39 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 40 | { |
| 41 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 42 | // the compressed block size. |
| 43 | switch (internalFormat) |
| 44 | { |
| 45 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 48 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 49 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 52 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 53 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 54 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 58 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 59 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 60 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 61 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 62 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 63 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 64 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 65 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 66 | default: |
| 67 | return false; |
| 68 | } |
| 69 | } |
| 70 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 71 | { |
| 72 | // Compressed sub textures have additional formats that requires exact size. |
| 73 | // ES 3.1, Section 8.7, Page 171 |
| 74 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 75 | IsETC2EACFormat(internalFormat); |
| 76 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 77 | |
| 78 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 79 | { |
| 80 | CheckedNumeric<GLint> checkedA(a); |
| 81 | checkedA -= b; |
| 82 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 83 | checkedA = -checkedA; |
| 84 | return !checkedA.IsValid(); |
| 85 | } |
| 86 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 87 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 88 | { |
| 89 | switch (type) |
| 90 | { |
| 91 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 92 | case GL_UNSIGNED_BYTE: |
| 93 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 94 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 95 | case GL_UNSIGNED_SHORT_5_6_5: |
| 96 | return context->getClientVersion() >= ES_2_0; |
| 97 | |
| 98 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 99 | case GL_BYTE: |
| 100 | case GL_INT: |
| 101 | case GL_SHORT: |
| 102 | case GL_UNSIGNED_INT: |
| 103 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 104 | case GL_UNSIGNED_INT_24_8: |
| 105 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 106 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 107 | case GL_UNSIGNED_SHORT: |
| 108 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 109 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 110 | return context->getClientVersion() >= ES_3_0; |
| 111 | |
| 112 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 113 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 114 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 115 | |
| 116 | case GL_HALF_FLOAT: |
| 117 | return context->getClientVersion() >= ES_3_0 || |
| 118 | context->getExtensions().textureHalfFloat; |
| 119 | |
| 120 | case GL_HALF_FLOAT_OES: |
| 121 | return context->getExtensions().colorBufferHalfFloat; |
| 122 | |
| 123 | default: |
| 124 | return false; |
| 125 | } |
| 126 | } |
| 127 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 128 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 129 | { |
| 130 | switch (format) |
| 131 | { |
| 132 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 133 | case GL_RGBA: |
| 134 | case GL_RGB: |
| 135 | case GL_ALPHA: |
| 136 | return context->getClientVersion() >= ES_2_0; |
| 137 | |
| 138 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 139 | case GL_RG: |
| 140 | case GL_RED: |
| 141 | case GL_RGBA_INTEGER: |
| 142 | case GL_RGB_INTEGER: |
| 143 | case GL_RG_INTEGER: |
| 144 | case GL_RED_INTEGER: |
| 145 | return context->getClientVersion() >= ES_3_0; |
| 146 | |
| 147 | case GL_SRGB_ALPHA_EXT: |
| 148 | case GL_SRGB_EXT: |
| 149 | return context->getExtensions().sRGB; |
| 150 | |
| 151 | case GL_BGRA_EXT: |
| 152 | return context->getExtensions().readFormatBGRA; |
| 153 | |
| 154 | default: |
| 155 | return false; |
| 156 | } |
| 157 | } |
| 158 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 159 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 160 | GLenum framebufferComponentType, |
| 161 | GLenum format, |
| 162 | GLenum type) |
| 163 | { |
| 164 | switch (framebufferComponentType) |
| 165 | { |
| 166 | case GL_UNSIGNED_NORMALIZED: |
| 167 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 168 | // ReadPixels with BGRA even if the extension is not present |
| 169 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 170 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 171 | type == GL_UNSIGNED_BYTE); |
| 172 | |
| 173 | case GL_SIGNED_NORMALIZED: |
| 174 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 175 | |
| 176 | case GL_INT: |
| 177 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 178 | |
| 179 | case GL_UNSIGNED_INT: |
| 180 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 181 | |
| 182 | case GL_FLOAT: |
| 183 | return (format == GL_RGBA && type == GL_FLOAT); |
| 184 | |
| 185 | default: |
| 186 | UNREACHABLE(); |
| 187 | return false; |
| 188 | } |
| 189 | } |
| 190 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 191 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 192 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 193 | { |
| 194 | switch (ConvertToGLenum(params[0])) |
| 195 | { |
| 196 | case GL_CLAMP_TO_EDGE: |
| 197 | break; |
| 198 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 199 | case GL_CLAMP_TO_BORDER: |
| 200 | if (!context->getExtensions().textureBorderClamp) |
| 201 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 202 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 203 | return false; |
| 204 | } |
| 205 | break; |
| 206 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 207 | case GL_REPEAT: |
| 208 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 209 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 210 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 211 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 212 | context->validationError(GL_INVALID_ENUM, kInvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 213 | return false; |
| 214 | } |
| 215 | break; |
| 216 | |
| 217 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 218 | context->validationError(GL_INVALID_ENUM, kInvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 219 | return false; |
| 220 | } |
| 221 | |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 226 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 227 | { |
| 228 | switch (ConvertToGLenum(params[0])) |
| 229 | { |
| 230 | case GL_NEAREST: |
| 231 | case GL_LINEAR: |
| 232 | break; |
| 233 | |
| 234 | case GL_NEAREST_MIPMAP_NEAREST: |
| 235 | case GL_LINEAR_MIPMAP_NEAREST: |
| 236 | case GL_NEAREST_MIPMAP_LINEAR: |
| 237 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 238 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 239 | { |
| 240 | // OES_EGL_image_external specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 241 | context->validationError(GL_INVALID_ENUM, kInvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | break; |
| 245 | |
| 246 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 247 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | |
| 251 | return true; |
| 252 | } |
| 253 | |
| 254 | template <typename ParamType> |
| 255 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 256 | { |
| 257 | switch (ConvertToGLenum(params[0])) |
| 258 | { |
| 259 | case GL_NEAREST: |
| 260 | case GL_LINEAR: |
| 261 | break; |
| 262 | |
| 263 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 264 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 265 | return false; |
| 266 | } |
| 267 | |
| 268 | return true; |
| 269 | } |
| 270 | |
| 271 | template <typename ParamType> |
| 272 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 273 | { |
| 274 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 275 | switch (ConvertToGLenum(params[0])) |
| 276 | { |
| 277 | case GL_NONE: |
| 278 | case GL_COMPARE_REF_TO_TEXTURE: |
| 279 | break; |
| 280 | |
| 281 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 282 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
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 ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 291 | { |
| 292 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 293 | switch (ConvertToGLenum(params[0])) |
| 294 | { |
| 295 | case GL_LEQUAL: |
| 296 | case GL_GEQUAL: |
| 297 | case GL_LESS: |
| 298 | case GL_GREATER: |
| 299 | case GL_EQUAL: |
| 300 | case GL_NOTEQUAL: |
| 301 | case GL_ALWAYS: |
| 302 | case GL_NEVER: |
| 303 | break; |
| 304 | |
| 305 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 306 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 307 | return false; |
| 308 | } |
| 309 | |
| 310 | return true; |
| 311 | } |
| 312 | |
| 313 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 314 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 315 | { |
| 316 | if (!context->getExtensions().textureSRGBDecode) |
| 317 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 318 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 319 | return false; |
| 320 | } |
| 321 | |
| 322 | switch (ConvertToGLenum(params[0])) |
| 323 | { |
| 324 | case GL_DECODE_EXT: |
| 325 | case GL_SKIP_DECODE_EXT: |
| 326 | break; |
| 327 | |
| 328 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 329 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 330 | return false; |
| 331 | } |
| 332 | |
| 333 | return true; |
| 334 | } |
| 335 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 336 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 337 | { |
| 338 | if (!context->getExtensions().textureFilterAnisotropic) |
| 339 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 340 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 341 | return false; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
| 347 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 348 | { |
| 349 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 350 | { |
| 351 | return false; |
| 352 | } |
| 353 | |
| 354 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 355 | |
| 356 | if (paramValue < 1 || paramValue > largest) |
| 357 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 358 | context->validationError(GL_INVALID_VALUE, kOutsideOfBounds); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 359 | return false; |
| 360 | } |
| 361 | |
| 362 | return true; |
| 363 | } |
| 364 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 365 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 366 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 367 | const Program *program = context->getState().getLinkedProgram(context); |
| 368 | const Framebuffer *framebuffer = context->getState().getDrawFramebuffer(); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 369 | |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame^] | 370 | return ValidateComponentTypeMasks(program->getDrawBufferTypeMask().to_ulong(), |
| 371 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 372 | program->getActiveOutputVariables().to_ulong(), |
| 373 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 374 | } |
| 375 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 376 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 377 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 378 | const auto &glState = context->getState(); |
| 379 | const Program *program = context->getState().getLinkedProgram(context); |
| 380 | const VertexArray *vao = context->getState().getVertexArray(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 381 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 382 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 383 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 384 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 385 | |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame^] | 386 | vaoAttribEnabledMask |= vaoAttribEnabledMask << kMaxComponentTypeMaskIndex; |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 387 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 388 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 389 | |
Jamie Madill | 6e18a23 | 2019-01-16 13:27:14 -0500 | [diff] [blame^] | 390 | return ValidateComponentTypeMasks(program->getAttributesTypeMask().to_ulong(), |
| 391 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 392 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 393 | } |
| 394 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 395 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 396 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 397 | { |
| 398 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 399 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 400 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 401 | case PrimitiveMode::Points: |
| 402 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 403 | case PrimitiveMode::Lines: |
| 404 | case PrimitiveMode::LineStrip: |
| 405 | case PrimitiveMode::LineLoop: |
| 406 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 407 | case PrimitiveMode::LinesAdjacency: |
| 408 | case PrimitiveMode::LineStripAdjacency: |
| 409 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 410 | case PrimitiveMode::Triangles: |
| 411 | case PrimitiveMode::TriangleFan: |
| 412 | case PrimitiveMode::TriangleStrip: |
| 413 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 414 | case PrimitiveMode::TrianglesAdjacency: |
| 415 | case PrimitiveMode::TriangleStripAdjacency: |
| 416 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 417 | default: |
| 418 | UNREACHABLE(); |
| 419 | return false; |
| 420 | } |
| 421 | } |
| 422 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 423 | // GLES1 texture parameters are a small subset of the others |
| 424 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 425 | { |
| 426 | switch (pname) |
| 427 | { |
| 428 | case GL_TEXTURE_MAG_FILTER: |
| 429 | case GL_TEXTURE_MIN_FILTER: |
| 430 | case GL_TEXTURE_WRAP_S: |
| 431 | case GL_TEXTURE_WRAP_T: |
| 432 | case GL_TEXTURE_WRAP_R: |
| 433 | case GL_GENERATE_MIPMAP: |
| 434 | case GL_TEXTURE_CROP_RECT_OES: |
| 435 | return true; |
| 436 | default: |
| 437 | return false; |
| 438 | } |
| 439 | } |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 440 | |
| 441 | unsigned int GetSamplerParameterCount(GLenum pname) |
| 442 | { |
| 443 | return pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1; |
| 444 | } |
| 445 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 446 | } // anonymous namespace |
| 447 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 448 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 449 | { |
| 450 | if (length) |
| 451 | { |
| 452 | *length = value; |
| 453 | } |
| 454 | } |
| 455 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 456 | bool IsETC2EACFormat(const GLenum format) |
| 457 | { |
| 458 | // ES 3.1, Table 8.19 |
| 459 | switch (format) |
| 460 | { |
| 461 | case GL_COMPRESSED_R11_EAC: |
| 462 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 463 | case GL_COMPRESSED_RG11_EAC: |
| 464 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 465 | case GL_COMPRESSED_RGB8_ETC2: |
| 466 | case GL_COMPRESSED_SRGB8_ETC2: |
| 467 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 468 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 469 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 470 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 471 | return true; |
| 472 | |
| 473 | default: |
| 474 | return false; |
| 475 | } |
| 476 | } |
| 477 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 478 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 479 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 480 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 481 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 482 | case TextureType::_2D: |
| 483 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 484 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 485 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 486 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 487 | return context->getExtensions().textureRectangle; |
| 488 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 489 | case TextureType::_3D: |
| 490 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 491 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 492 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 493 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 494 | return (context->getClientVersion() >= Version(3, 1) || |
| 495 | context->getExtensions().textureMultisample); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 496 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 497 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 498 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 499 | default: |
| 500 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 501 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 504 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 505 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 506 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 507 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 508 | case TextureType::_2D: |
| 509 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 510 | return true; |
| 511 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 512 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 513 | return context->getExtensions().textureRectangle; |
| 514 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 515 | default: |
| 516 | return false; |
| 517 | } |
| 518 | } |
| 519 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 520 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 521 | { |
| 522 | switch (target) |
| 523 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 524 | case TextureType::_3D: |
| 525 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 526 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 527 | |
| 528 | default: |
| 529 | return false; |
| 530 | } |
| 531 | } |
| 532 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 533 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 534 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 535 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 536 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 537 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 538 | (context->getExtensions().eglImageExternal || |
| 539 | context->getExtensions().eglStreamConsumerExternal); |
| 540 | } |
| 541 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 542 | // This function differs from ValidTextureTarget in that the target must be |
| 543 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 544 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 545 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 546 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 547 | { |
| 548 | switch (target) |
| 549 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 550 | case TextureTarget::_2D: |
| 551 | case TextureTarget::CubeMapNegativeX: |
| 552 | case TextureTarget::CubeMapNegativeY: |
| 553 | case TextureTarget::CubeMapNegativeZ: |
| 554 | case TextureTarget::CubeMapPositiveX: |
| 555 | case TextureTarget::CubeMapPositiveY: |
| 556 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 557 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 558 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 559 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 560 | default: |
| 561 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 562 | } |
| 563 | } |
| 564 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 565 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 566 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 567 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 568 | { |
| 569 | ASSERT(context); |
| 570 | |
| 571 | if (!context->getExtensions().geometryShader) |
| 572 | { |
| 573 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 574 | // that does not match the current transform feedback object's draw mode (if transform |
| 575 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 576 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 577 | } |
| 578 | |
| 579 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 580 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 581 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 582 | case PrimitiveMode::Points: |
| 583 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 584 | case PrimitiveMode::Lines: |
| 585 | case PrimitiveMode::LineStrip: |
| 586 | case PrimitiveMode::LineLoop: |
| 587 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 588 | case PrimitiveMode::Triangles: |
| 589 | case PrimitiveMode::TriangleFan: |
| 590 | case PrimitiveMode::TriangleStrip: |
| 591 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 592 | default: |
| 593 | UNREACHABLE(); |
| 594 | return false; |
| 595 | } |
| 596 | } |
| 597 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 598 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 599 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 600 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 601 | DrawElementsType type, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 602 | const GLvoid *indices, |
| 603 | GLsizei primcount) |
| 604 | { |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 605 | if (primcount <= 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 606 | { |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 607 | if (primcount < 0) |
| 608 | { |
| 609 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
| 610 | return false; |
| 611 | } |
| 612 | |
| 613 | // Early exit. |
| 614 | return ValidateDrawElementsCommon(context, mode, count, type, indices, primcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 618 | { |
| 619 | return false; |
| 620 | } |
| 621 | |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 622 | if (count == 0) |
| 623 | { |
| 624 | // Early exit. |
| 625 | return true; |
| 626 | } |
| 627 | |
| 628 | return ValidateDrawInstancedAttribs(context, primcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 632 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 633 | GLint first, |
| 634 | GLsizei count, |
| 635 | GLsizei primcount) |
| 636 | { |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 637 | if (primcount <= 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 638 | { |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 639 | if (primcount < 0) |
| 640 | { |
| 641 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
| 642 | return false; |
| 643 | } |
| 644 | |
| 645 | // Early exit. |
| 646 | return ValidateDrawArraysCommon(context, mode, first, count, primcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 654 | if (count == 0) |
| 655 | { |
| 656 | // Early exit. |
| 657 | return true; |
| 658 | } |
| 659 | |
| 660 | return ValidateDrawInstancedAttribs(context, primcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 661 | } |
| 662 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 663 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 664 | { |
| 665 | // Verify there is at least one active attribute with a divisor of zero |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 666 | const State &state = context->getState(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 667 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 668 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 669 | |
| 670 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 671 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 672 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 673 | { |
| 674 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 675 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 676 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 677 | { |
| 678 | return true; |
| 679 | } |
| 680 | } |
| 681 | |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 682 | context->validationError(GL_INVALID_OPERATION, kNoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 683 | return false; |
| 684 | } |
| 685 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 686 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 687 | { |
| 688 | switch (target) |
| 689 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 690 | case TextureType::_3D: |
| 691 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 692 | return true; |
| 693 | default: |
| 694 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 698 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 699 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 700 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 701 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 702 | case TextureType::_2D: |
| 703 | case TextureType::_2DArray: |
| 704 | case TextureType::_2DMultisample: |
| 705 | case TextureType::CubeMap: |
| 706 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 707 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 708 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 709 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 710 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 711 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 712 | default: |
| 713 | return false; |
| 714 | } |
| 715 | } |
| 716 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 717 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 718 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 719 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 720 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 721 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 722 | |
| 723 | switch (target) |
| 724 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 725 | case GL_FRAMEBUFFER: |
| 726 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 727 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 728 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 729 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 730 | return (context->getExtensions().framebufferBlit || |
| 731 | context->getClientMajorVersion() >= 3); |
| 732 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 733 | default: |
| 734 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 738 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 739 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 740 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 741 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 742 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 743 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 744 | case TextureType::_2D: |
| 745 | case TextureType::_2DArray: |
| 746 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 747 | case TextureType::_2DMultisampleArray: |
| 748 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 749 | // 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] | 750 | maxDimension = caps.max2DTextureSize; |
| 751 | break; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 752 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 753 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 754 | maxDimension = caps.maxCubeMapTextureSize; |
| 755 | break; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 756 | |
| 757 | case TextureType::External: |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 758 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 759 | return level == 0; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 760 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 761 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 762 | maxDimension = caps.max3DTextureSize; |
| 763 | break; |
Geoff Lang | be607ad | 2018-11-29 10:14:22 -0500 | [diff] [blame] | 764 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 765 | default: |
| 766 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 769 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 772 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 773 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 774 | GLint level, |
| 775 | GLsizei width, |
| 776 | GLsizei height, |
| 777 | GLsizei depth, |
| 778 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 779 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 780 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 781 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 782 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 783 | return false; |
| 784 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 785 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 786 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 787 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 788 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 789 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 790 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 791 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 792 | context->validationError(GL_INVALID_VALUE, kTextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 793 | return false; |
| 794 | } |
| 795 | |
| 796 | if (!ValidMipLevel(context, target, level)) |
| 797 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 798 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 799 | return false; |
| 800 | } |
| 801 | |
| 802 | return true; |
| 803 | } |
| 804 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 805 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 806 | { |
| 807 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 808 | (size % blockSize == 0); |
| 809 | } |
| 810 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 811 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 812 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 813 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 814 | GLsizei width, |
| 815 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 816 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 817 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 818 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 819 | { |
| 820 | return false; |
| 821 | } |
| 822 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 823 | if (width < 0 || height < 0) |
| 824 | { |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 829 | { |
| 830 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 831 | // block size for level 0 but WebGL disallows this. |
| 832 | bool smallerThanBlockSizeAllowed = |
| 833 | level > 0 || !context->getExtensions().webglCompatibility; |
| 834 | |
| 835 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 836 | smallerThanBlockSizeAllowed) || |
| 837 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 838 | smallerThanBlockSizeAllowed)) |
| 839 | { |
| 840 | return false; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return true; |
| 845 | } |
| 846 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 847 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 848 | GLenum internalFormat, |
| 849 | GLint xoffset, |
| 850 | GLint yoffset, |
| 851 | GLsizei width, |
| 852 | GLsizei height, |
| 853 | size_t textureWidth, |
| 854 | size_t textureHeight) |
| 855 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 856 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 857 | if (!formatInfo.compressed) |
| 858 | { |
| 859 | return false; |
| 860 | } |
| 861 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 862 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 863 | { |
| 864 | return false; |
| 865 | } |
| 866 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 867 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 868 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 869 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 870 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 871 | { |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 876 | // size but fills the entire mip |
| 877 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 878 | static_cast<size_t>(width) == textureWidth && |
| 879 | static_cast<size_t>(height) == textureHeight; |
| 880 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 881 | (height % formatInfo.compressedBlockHeight) == 0; |
| 882 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 883 | { |
| 884 | return false; |
| 885 | } |
| 886 | } |
| 887 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 888 | return true; |
| 889 | } |
| 890 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 891 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 892 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 893 | GLsizei width, |
| 894 | GLsizei height, |
| 895 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 896 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 897 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 898 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 899 | GLsizei imageSize) |
| 900 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 901 | Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 902 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 903 | { |
| 904 | // Checks are not required |
| 905 | return true; |
| 906 | } |
| 907 | |
| 908 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 909 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 910 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 911 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 912 | const Extents size(width, height, depth); |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 913 | const auto &unpack = context->getState().getUnpackState(); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 914 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 915 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 916 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 917 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 918 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 919 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 920 | return false; |
| 921 | } |
| 922 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 923 | if (pixelUnpackBuffer) |
| 924 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 925 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 926 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 927 | checkedEndByte += checkedOffset; |
| 928 | |
| 929 | if (!checkedEndByte.IsValid() || |
| 930 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 931 | { |
| 932 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 933 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 934 | return false; |
| 935 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 936 | if (context->getExtensions().webglCompatibility && |
| 937 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 938 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 939 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 940 | kPixelUnpackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 941 | return false; |
| 942 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 943 | } |
| 944 | else |
| 945 | { |
| 946 | ASSERT(imageSize >= 0); |
| 947 | if (pixels == nullptr && imageSize != 0) |
| 948 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 949 | context->validationError(GL_INVALID_OPERATION, kImageSizeMustBeZero); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 950 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 951 | } |
| 952 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 953 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 954 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 955 | context->validationError(GL_INVALID_OPERATION, kImageSizeTooSmall); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 956 | return false; |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | return true; |
| 961 | } |
| 962 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 963 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 964 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 965 | switch (queryType) |
| 966 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 967 | case QueryType::AnySamples: |
| 968 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 969 | return context->getClientMajorVersion() >= 3 || |
| 970 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 971 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 972 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 973 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 974 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 975 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 976 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 977 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 978 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 979 | default: |
| 980 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 984 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 985 | VertexAttribType type, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 986 | GLboolean normalized, |
| 987 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 988 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 989 | bool pureInteger) |
| 990 | { |
| 991 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 992 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 993 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 994 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 995 | // parameter exceeds 255. |
| 996 | constexpr GLsizei kMaxWebGLStride = 255; |
| 997 | if (stride > kMaxWebGLStride) |
| 998 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 999 | context->validationError(GL_INVALID_VALUE, kStrideExceedsWebGLLimit); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1000 | return false; |
| 1001 | } |
| 1002 | |
| 1003 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1004 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1005 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1006 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 1007 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 1008 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1009 | |
| 1010 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1011 | size_t sizeMask = (typeSize - 1); |
| 1012 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1013 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1014 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1015 | return false; |
| 1016 | } |
| 1017 | |
| 1018 | if ((stride & sizeMask) != 0) |
| 1019 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1020 | context->validationError(GL_INVALID_OPERATION, kStrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | return true; |
| 1025 | } |
| 1026 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1027 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1028 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1029 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1030 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1031 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1032 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1033 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1034 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1035 | |
| 1036 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1037 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1038 | if (context->getShader(id)) |
| 1039 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1040 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1041 | } |
| 1042 | else |
| 1043 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1044 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1045 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1046 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1047 | |
| 1048 | return validProgram; |
| 1049 | } |
| 1050 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1051 | Program *GetValidProgram(Context *context, GLuint id) |
| 1052 | { |
| 1053 | Program *program = GetValidProgramNoResolve(context, id); |
| 1054 | if (program) |
| 1055 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1056 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1057 | } |
| 1058 | return program; |
| 1059 | } |
| 1060 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1061 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1062 | { |
| 1063 | // See ValidProgram for spec details. |
| 1064 | |
| 1065 | Shader *validShader = context->getShader(id); |
| 1066 | |
| 1067 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1068 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1069 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1070 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1071 | context->validationError(GL_INVALID_OPERATION, kExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1072 | } |
| 1073 | else |
| 1074 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1075 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1076 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1077 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1078 | |
| 1079 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1080 | } |
| 1081 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1082 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1083 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1084 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1085 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1086 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1087 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1088 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1089 | return false; |
| 1090 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1091 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1092 | // Color attachment 0 is validated below because it is always valid |
| 1093 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1094 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1095 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1096 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1097 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1098 | } |
| 1099 | } |
| 1100 | else |
| 1101 | { |
| 1102 | switch (attachment) |
| 1103 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1104 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1105 | case GL_DEPTH_ATTACHMENT: |
| 1106 | case GL_STENCIL_ATTACHMENT: |
| 1107 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1108 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1109 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1110 | if (!context->getExtensions().webglCompatibility && |
| 1111 | context->getClientMajorVersion() < 3) |
| 1112 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1113 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1114 | return false; |
| 1115 | } |
| 1116 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1117 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1118 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1119 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | return true; |
| 1125 | } |
| 1126 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1127 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1128 | GLenum target, |
| 1129 | GLsizei samples, |
| 1130 | GLenum internalformat, |
| 1131 | GLsizei width, |
| 1132 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1133 | { |
| 1134 | switch (target) |
| 1135 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1136 | case GL_RENDERBUFFER: |
| 1137 | break; |
| 1138 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1139 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1140 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | if (width < 0 || height < 0 || samples < 0) |
| 1144 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1145 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1146 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1149 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1150 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1151 | |
| 1152 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1153 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1154 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1155 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1156 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1160 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1161 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1162 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1163 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1164 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1165 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1166 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1167 | } |
| 1168 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1169 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1171 | context->validationError(GL_INVALID_VALUE, kResourceMaxRenderbufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1172 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1175 | GLuint handle = context->getState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | if (handle == 0) |
| 1177 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1178 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1179 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | return true; |
| 1183 | } |
| 1184 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1185 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1186 | GLenum target, |
| 1187 | GLenum attachment, |
| 1188 | GLenum renderbuffertarget, |
| 1189 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1190 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1191 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1192 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1193 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1194 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1195 | } |
| 1196 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1197 | Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1198 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1199 | ASSERT(framebuffer); |
| 1200 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1201 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1202 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1203 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1204 | } |
| 1205 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1206 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1207 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1208 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1209 | } |
| 1210 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1211 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1212 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1213 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1214 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1215 | if (renderbuffer != 0) |
| 1216 | { |
| 1217 | if (!context->getRenderbuffer(renderbuffer)) |
| 1218 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1219 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1220 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1221 | } |
| 1222 | } |
| 1223 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1224 | return true; |
| 1225 | } |
| 1226 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1227 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1228 | GLint srcX0, |
| 1229 | GLint srcY0, |
| 1230 | GLint srcX1, |
| 1231 | GLint srcY1, |
| 1232 | GLint dstX0, |
| 1233 | GLint dstY0, |
| 1234 | GLint dstX1, |
| 1235 | GLint dstY1, |
| 1236 | GLbitfield mask, |
| 1237 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1238 | { |
| 1239 | switch (filter) |
| 1240 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1241 | case GL_NEAREST: |
| 1242 | break; |
| 1243 | case GL_LINEAR: |
| 1244 | break; |
| 1245 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1246 | context->validationError(GL_INVALID_ENUM, kBlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1247 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1251 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1252 | context->validationError(GL_INVALID_VALUE, kBlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1253 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1256 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1257 | // color buffer, leaving only nearest being unfiltered from above |
| 1258 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1259 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1260 | context->validationError(GL_INVALID_OPERATION, kBlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1261 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1264 | const auto &glState = context->getState(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1265 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1266 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1267 | |
| 1268 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1269 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1270 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1271 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1272 | } |
| 1273 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1274 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1275 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1276 | return false; |
| 1277 | } |
| 1278 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1279 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1280 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1281 | return false; |
| 1282 | } |
| 1283 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1284 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1285 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1286 | context->validationError(GL_INVALID_OPERATION, kBlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1290 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1291 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1292 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1293 | } |
| 1294 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1295 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1296 | // always run it in order to avoid triggering driver bugs. |
| 1297 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1298 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1299 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1300 | context->validationError(GL_INVALID_VALUE, kBlitDimensionsOutOfRange); |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1301 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1302 | } |
| 1303 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1304 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1305 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1307 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1308 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1309 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1311 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1313 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1314 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1315 | for (size_t drawbufferIdx = 0; |
| 1316 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1317 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1318 | const FramebufferAttachment *attachment = |
| 1319 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1320 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1321 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1322 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1323 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1324 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1325 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1326 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1327 | // as well |
| 1328 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1329 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1330 | // Changes with EXT_color_buffer_float: |
| 1331 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1332 | GLenum readComponentType = readFormat.info->componentType; |
| 1333 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1334 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1335 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1336 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1337 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1338 | |
| 1339 | if (extensions.colorBufferFloat) |
| 1340 | { |
| 1341 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1342 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1343 | |
| 1344 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1345 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1346 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1347 | kBlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1348 | return false; |
| 1349 | } |
| 1350 | } |
| 1351 | else if (readFixedPoint != drawFixedPoint) |
| 1352 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1353 | context->validationError(GL_INVALID_OPERATION, kBlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | if (readComponentType == GL_UNSIGNED_INT && |
| 1358 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1359 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1360 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1361 | kBlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1362 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1363 | } |
| 1364 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1365 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1366 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1367 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1368 | kBlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1369 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1372 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1373 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1374 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1375 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1376 | kBlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1377 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1378 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1379 | |
| 1380 | if (context->getExtensions().webglCompatibility && |
| 1381 | *readColorBuffer == *attachment) |
| 1382 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1383 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1384 | return false; |
| 1385 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1386 | } |
| 1387 | } |
| 1388 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1389 | if ((readFormat.info->componentType == GL_INT || |
| 1390 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1391 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1392 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1393 | context->validationError(GL_INVALID_OPERATION, kBlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1394 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1395 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1396 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1397 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1398 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1399 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1400 | // situation is an application error that would lead to a crash in ANGLE. |
| 1401 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1402 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1403 | context->validationError(GL_INVALID_OPERATION, kBlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1404 | return false; |
| 1405 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1406 | } |
| 1407 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1408 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1409 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1410 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1411 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1412 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1414 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1415 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1416 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1417 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1419 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1421 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1422 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1423 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1424 | kBlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1425 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1426 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1427 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1428 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1430 | context->validationError(GL_INVALID_OPERATION, kBlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1431 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1432 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1433 | |
| 1434 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1435 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1436 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1439 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1440 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1441 | else if (drawBuffer) |
| 1442 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1443 | context->validationError(GL_INVALID_OPERATION, kBlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1444 | return false; |
| 1445 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1449 | // ANGLE_multiview, Revision 1: |
| 1450 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1451 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1452 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1453 | // views in the current read framebuffer is more than one. |
| 1454 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1455 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1456 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1457 | return false; |
| 1458 | } |
| 1459 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1460 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1461 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1462 | return false; |
| 1463 | } |
| 1464 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1465 | return true; |
| 1466 | } |
| 1467 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1468 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1469 | GLint x, |
| 1470 | GLint y, |
| 1471 | GLsizei width, |
| 1472 | GLsizei height, |
| 1473 | GLenum format, |
| 1474 | GLenum type, |
| 1475 | GLsizei bufSize, |
| 1476 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1477 | GLsizei *columns, |
| 1478 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1479 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1480 | { |
| 1481 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1482 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1483 | return false; |
| 1484 | } |
| 1485 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1486 | GLsizei writeLength = 0; |
| 1487 | GLsizei writeColumns = 0; |
| 1488 | GLsizei writeRows = 0; |
| 1489 | |
| 1490 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1491 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1492 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1493 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1494 | } |
| 1495 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1496 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1497 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1498 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1499 | } |
| 1500 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1501 | SetRobustLengthParam(length, writeLength); |
| 1502 | SetRobustLengthParam(columns, writeColumns); |
| 1503 | SetRobustLengthParam(rows, writeRows); |
| 1504 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1505 | return true; |
| 1506 | } |
| 1507 | |
| 1508 | bool ValidateReadnPixelsEXT(Context *context, |
| 1509 | GLint x, |
| 1510 | GLint y, |
| 1511 | GLsizei width, |
| 1512 | GLsizei height, |
| 1513 | GLenum format, |
| 1514 | GLenum type, |
| 1515 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1516 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1517 | { |
| 1518 | if (bufSize < 0) |
| 1519 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1520 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1521 | return false; |
| 1522 | } |
| 1523 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1524 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1525 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1526 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1527 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1528 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1529 | GLint x, |
| 1530 | GLint y, |
| 1531 | GLsizei width, |
| 1532 | GLsizei height, |
| 1533 | GLenum format, |
| 1534 | GLenum type, |
| 1535 | GLsizei bufSize, |
| 1536 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1537 | GLsizei *columns, |
| 1538 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1539 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1540 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1541 | GLsizei writeLength = 0; |
| 1542 | GLsizei writeColumns = 0; |
| 1543 | GLsizei writeRows = 0; |
| 1544 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1545 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1546 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1547 | return false; |
| 1548 | } |
| 1549 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1550 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1551 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1552 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1553 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1554 | } |
| 1555 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1556 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1557 | { |
| 1558 | return false; |
| 1559 | } |
| 1560 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1561 | SetRobustLengthParam(length, writeLength); |
| 1562 | SetRobustLengthParam(columns, writeColumns); |
| 1563 | SetRobustLengthParam(rows, writeRows); |
| 1564 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1565 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1566 | } |
| 1567 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1568 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1569 | { |
| 1570 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1571 | !context->getExtensions().disjointTimerQuery) |
| 1572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1573 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1574 | return false; |
| 1575 | } |
| 1576 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1577 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1578 | } |
| 1579 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1580 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1581 | { |
| 1582 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1583 | !context->getExtensions().disjointTimerQuery) |
| 1584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1585 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1586 | return false; |
| 1587 | } |
| 1588 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1589 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1590 | } |
| 1591 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1592 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1593 | { |
| 1594 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1595 | !context->getExtensions().disjointTimerQuery) |
| 1596 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1597 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1598 | return false; |
| 1599 | } |
| 1600 | |
| 1601 | return true; |
| 1602 | } |
| 1603 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1604 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1605 | { |
| 1606 | if (!ValidQueryType(context, target)) |
| 1607 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1608 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1609 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1610 | } |
| 1611 | |
| 1612 | if (id == 0) |
| 1613 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1614 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1615 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1619 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1620 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1621 | // the active query for either target is non-zero), if <id> is the name of an |
| 1622 | // existing query object whose type does not match <target>, or if <id> is the |
| 1623 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1624 | // generated. |
| 1625 | |
| 1626 | // Ensure no other queries are active |
| 1627 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1628 | // separately that: |
| 1629 | // a) The query ID passed is not the current active query for any target/type |
| 1630 | // b) There are no active queries for the requested target (and in the case |
| 1631 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1632 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1633 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1634 | if (context->getState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1635 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1636 | context->validationError(GL_INVALID_OPERATION, kOtherQueryActive); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1637 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | Query *queryObject = context->getQuery(id, true, target); |
| 1641 | |
| 1642 | // check that name was obtained with glGenQueries |
| 1643 | if (!queryObject) |
| 1644 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1645 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1646 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | // check for type mismatch |
| 1650 | if (queryObject->getType() != target) |
| 1651 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1652 | context->validationError(GL_INVALID_OPERATION, kQueryTargetMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1653 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | return true; |
| 1657 | } |
| 1658 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1659 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1660 | { |
| 1661 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1662 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1663 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1664 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1665 | return false; |
| 1666 | } |
| 1667 | |
| 1668 | return ValidateBeginQueryBase(context, target, id); |
| 1669 | } |
| 1670 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1671 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1672 | { |
| 1673 | if (!ValidQueryType(context, target)) |
| 1674 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1675 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1676 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1679 | const Query *queryObject = context->getState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1680 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1681 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1682 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1683 | context->validationError(GL_INVALID_OPERATION, kQueryInactive); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1684 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1687 | return true; |
| 1688 | } |
| 1689 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1690 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1691 | { |
| 1692 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1693 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1694 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1695 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1696 | return false; |
| 1697 | } |
| 1698 | |
| 1699 | return ValidateEndQueryBase(context, target); |
| 1700 | } |
| 1701 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1702 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1703 | { |
| 1704 | if (!context->getExtensions().disjointTimerQuery) |
| 1705 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1706 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1707 | return false; |
| 1708 | } |
| 1709 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1710 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1711 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1712 | context->validationError(GL_INVALID_ENUM, kInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1713 | return false; |
| 1714 | } |
| 1715 | |
| 1716 | Query *queryObject = context->getQuery(id, true, target); |
| 1717 | if (queryObject == nullptr) |
| 1718 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1719 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1720 | return false; |
| 1721 | } |
| 1722 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1723 | if (context->getState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1724 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1725 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
| 1728 | |
| 1729 | return true; |
| 1730 | } |
| 1731 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1732 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1733 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1734 | if (numParams) |
| 1735 | { |
| 1736 | *numParams = 0; |
| 1737 | } |
| 1738 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1739 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1740 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1741 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1742 | return false; |
| 1743 | } |
| 1744 | |
| 1745 | switch (pname) |
| 1746 | { |
| 1747 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1748 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1749 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1750 | context->validationError(GL_INVALID_ENUM, kInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1751 | return false; |
| 1752 | } |
| 1753 | break; |
| 1754 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1755 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1756 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1757 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1758 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1759 | return false; |
| 1760 | } |
| 1761 | break; |
| 1762 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1763 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1764 | return false; |
| 1765 | } |
| 1766 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1767 | if (numParams) |
| 1768 | { |
| 1769 | // All queries return only one value |
| 1770 | *numParams = 1; |
| 1771 | } |
| 1772 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1773 | return true; |
| 1774 | } |
| 1775 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1776 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1777 | { |
| 1778 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1779 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1780 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1781 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1782 | return false; |
| 1783 | } |
| 1784 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1785 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1786 | } |
| 1787 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1788 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1789 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1790 | GLenum pname, |
| 1791 | GLsizei bufSize, |
| 1792 | GLsizei *length, |
| 1793 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1794 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1795 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1796 | { |
| 1797 | return false; |
| 1798 | } |
| 1799 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1800 | GLsizei numParams = 0; |
| 1801 | |
| 1802 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1803 | { |
| 1804 | return false; |
| 1805 | } |
| 1806 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1807 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1808 | { |
| 1809 | return false; |
| 1810 | } |
| 1811 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1812 | SetRobustLengthParam(length, numParams); |
| 1813 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1814 | return true; |
| 1815 | } |
| 1816 | |
| 1817 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1818 | { |
| 1819 | if (numParams) |
| 1820 | { |
| 1821 | *numParams = 0; |
| 1822 | } |
| 1823 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1824 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1825 | |
| 1826 | if (!queryObject) |
| 1827 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1828 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1829 | return false; |
| 1830 | } |
| 1831 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 1832 | if (context->getState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1833 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1834 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1835 | return false; |
| 1836 | } |
| 1837 | |
| 1838 | switch (pname) |
| 1839 | { |
| 1840 | case GL_QUERY_RESULT_EXT: |
| 1841 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1842 | break; |
| 1843 | |
| 1844 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1845 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1846 | return false; |
| 1847 | } |
| 1848 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1849 | if (numParams) |
| 1850 | { |
| 1851 | *numParams = 1; |
| 1852 | } |
| 1853 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1854 | return true; |
| 1855 | } |
| 1856 | |
| 1857 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1858 | { |
| 1859 | if (!context->getExtensions().disjointTimerQuery) |
| 1860 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1861 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1862 | return false; |
| 1863 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1864 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1865 | } |
| 1866 | |
| 1867 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1868 | GLuint id, |
| 1869 | GLenum pname, |
| 1870 | GLsizei bufSize, |
| 1871 | GLsizei *length, |
| 1872 | GLint *params) |
| 1873 | { |
| 1874 | if (!context->getExtensions().disjointTimerQuery) |
| 1875 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 1876 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1877 | return false; |
| 1878 | } |
| 1879 | |
| 1880 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1881 | { |
| 1882 | return false; |
| 1883 | } |
| 1884 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1885 | GLsizei numParams = 0; |
| 1886 | |
| 1887 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1888 | { |
| 1889 | return false; |
| 1890 | } |
| 1891 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1892 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1893 | { |
| 1894 | return false; |
| 1895 | } |
| 1896 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1897 | SetRobustLengthParam(length, numParams); |
| 1898 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1899 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1903 | { |
| 1904 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1905 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1906 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1907 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1910 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1911 | } |
| 1912 | |
| 1913 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1914 | GLuint id, |
| 1915 | GLenum pname, |
| 1916 | GLsizei bufSize, |
| 1917 | GLsizei *length, |
| 1918 | GLuint *params) |
| 1919 | { |
| 1920 | if (!context->getExtensions().disjointTimerQuery && |
| 1921 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1922 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1923 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1924 | return false; |
| 1925 | } |
| 1926 | |
| 1927 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1928 | { |
| 1929 | return false; |
| 1930 | } |
| 1931 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1932 | GLsizei numParams = 0; |
| 1933 | |
| 1934 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1935 | { |
| 1936 | return false; |
| 1937 | } |
| 1938 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1939 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1940 | { |
| 1941 | return false; |
| 1942 | } |
| 1943 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1944 | SetRobustLengthParam(length, numParams); |
| 1945 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1946 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1947 | } |
| 1948 | |
| 1949 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1950 | { |
| 1951 | if (!context->getExtensions().disjointTimerQuery) |
| 1952 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1953 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1954 | return false; |
| 1955 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1956 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1957 | } |
| 1958 | |
| 1959 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1960 | GLuint id, |
| 1961 | GLenum pname, |
| 1962 | GLsizei bufSize, |
| 1963 | GLsizei *length, |
| 1964 | GLint64 *params) |
| 1965 | { |
| 1966 | if (!context->getExtensions().disjointTimerQuery) |
| 1967 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1968 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1969 | return false; |
| 1970 | } |
| 1971 | |
| 1972 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1973 | { |
| 1974 | return false; |
| 1975 | } |
| 1976 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1977 | GLsizei numParams = 0; |
| 1978 | |
| 1979 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1980 | { |
| 1981 | return false; |
| 1982 | } |
| 1983 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1984 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1985 | { |
| 1986 | return false; |
| 1987 | } |
| 1988 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1989 | SetRobustLengthParam(length, numParams); |
| 1990 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1991 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 1995 | { |
| 1996 | if (!context->getExtensions().disjointTimerQuery) |
| 1997 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1998 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1999 | return false; |
| 2000 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2001 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2002 | } |
| 2003 | |
| 2004 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2005 | GLuint id, |
| 2006 | GLenum pname, |
| 2007 | GLsizei bufSize, |
| 2008 | GLsizei *length, |
| 2009 | GLuint64 *params) |
| 2010 | { |
| 2011 | if (!context->getExtensions().disjointTimerQuery) |
| 2012 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2013 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2014 | return false; |
| 2015 | } |
| 2016 | |
| 2017 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2018 | { |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2022 | GLsizei numParams = 0; |
| 2023 | |
| 2024 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2025 | { |
| 2026 | return false; |
| 2027 | } |
| 2028 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2029 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2030 | { |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2034 | SetRobustLengthParam(length, numParams); |
| 2035 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2036 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2037 | } |
| 2038 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2039 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2040 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2041 | GLint location, |
| 2042 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2043 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2044 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2045 | // TODO(Jiajia): Add image uniform check in future. |
| 2046 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2048 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2049 | return false; |
| 2050 | } |
| 2051 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2052 | if (!program) |
| 2053 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2054 | context->validationError(GL_INVALID_OPERATION, kInvalidProgramName); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2055 | return false; |
| 2056 | } |
| 2057 | |
| 2058 | if (!program->isLinked()) |
| 2059 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2060 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2061 | return false; |
| 2062 | } |
| 2063 | |
| 2064 | if (location == -1) |
| 2065 | { |
| 2066 | // Silently ignore the uniform command |
| 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | const auto &uniformLocations = program->getUniformLocations(); |
| 2071 | size_t castedLocation = static_cast<size_t>(location); |
| 2072 | if (castedLocation >= uniformLocations.size()) |
| 2073 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2074 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2075 | return false; |
| 2076 | } |
| 2077 | |
| 2078 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2079 | if (uniformLocation.ignored) |
| 2080 | { |
| 2081 | // Silently ignore the uniform command |
| 2082 | return false; |
| 2083 | } |
| 2084 | |
| 2085 | if (!uniformLocation.used()) |
| 2086 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2087 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2088 | return false; |
| 2089 | } |
| 2090 | |
| 2091 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2092 | |
| 2093 | // 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] | 2094 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2095 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2096 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformCount); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2097 | return false; |
| 2098 | } |
| 2099 | |
| 2100 | *uniformOut = &uniform; |
| 2101 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2102 | } |
| 2103 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2104 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2105 | GLenum uniformType, |
| 2106 | GLsizei count, |
| 2107 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2108 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2109 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2110 | // It is compatible with INT or BOOL. |
| 2111 | // Do these cheap tests first, for a little extra speed. |
| 2112 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2113 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2114 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2115 | } |
| 2116 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2117 | if (IsSamplerType(uniformType)) |
| 2118 | { |
| 2119 | // Check that the values are in range. |
| 2120 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2121 | for (GLsizei i = 0; i < count; ++i) |
| 2122 | { |
| 2123 | if (value[i] < 0 || value[i] >= max) |
| 2124 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2125 | context->validationError(GL_INVALID_VALUE, kSamplerUniformValueOutOfRange); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2126 | return false; |
| 2127 | } |
| 2128 | } |
| 2129 | return true; |
| 2130 | } |
| 2131 | |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2132 | context->validationError(GL_INVALID_OPERATION, kUniformTypeMismatch); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2133 | return false; |
| 2134 | } |
| 2135 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2136 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2137 | { |
| 2138 | // Check that the value type is compatible with uniform type. |
| 2139 | if (valueType == uniformType) |
| 2140 | { |
| 2141 | return true; |
| 2142 | } |
| 2143 | |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2144 | context->validationError(GL_INVALID_OPERATION, kUniformTypeMismatch); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2145 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2146 | } |
| 2147 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2148 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2149 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2150 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2151 | Program *programObject = context->getState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2152 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2153 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2156 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2157 | { |
| 2158 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2159 | Program *programObject = context->getState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2160 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2161 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2162 | } |
| 2163 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2164 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2165 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2166 | GLint location, |
| 2167 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2168 | GLboolean transpose) |
| 2169 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2170 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2171 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2172 | context->validationError(GL_INVALID_VALUE, kES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2173 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2174 | } |
| 2175 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2176 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2177 | Program *programObject = context->getState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2178 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2179 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2180 | } |
| 2181 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2182 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2183 | { |
| 2184 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2185 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2186 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2187 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2188 | } |
| 2189 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2190 | const Caps &caps = context->getCaps(); |
| 2191 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2192 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2193 | { |
| 2194 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2195 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2196 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2197 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2198 | context->validationError(GL_INVALID_OPERATION, kIndexExceedsMaxDrawBuffer); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2199 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2200 | } |
| 2201 | } |
| 2202 | |
| 2203 | switch (pname) |
| 2204 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2205 | case GL_TEXTURE_BINDING_2D: |
| 2206 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2207 | case GL_TEXTURE_BINDING_3D: |
| 2208 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2209 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2210 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2211 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2212 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2213 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2214 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2215 | return false; |
| 2216 | } |
| 2217 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2218 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2219 | if (!context->getExtensions().textureRectangle) |
| 2220 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2221 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2222 | return false; |
| 2223 | } |
| 2224 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2225 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2226 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2227 | !context->getExtensions().eglImageExternal) |
| 2228 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2229 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2230 | return false; |
| 2231 | } |
| 2232 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2233 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2234 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2235 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2236 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2237 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2238 | ASSERT(readFramebuffer); |
| 2239 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2240 | if (!ValidateFramebufferComplete<GL_INVALID_OPERATION>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2241 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2242 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2243 | } |
| 2244 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2245 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2246 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2247 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2248 | return false; |
| 2249 | } |
| 2250 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2251 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2252 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2253 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2254 | context->validationError(GL_INVALID_OPERATION, kReadBufferNotAttached); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2255 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2256 | } |
| 2257 | } |
| 2258 | break; |
| 2259 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2260 | default: |
| 2261 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2262 | } |
| 2263 | |
| 2264 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2265 | if (*numParams == 0) |
| 2266 | { |
| 2267 | return false; |
| 2268 | } |
| 2269 | |
| 2270 | return true; |
| 2271 | } |
| 2272 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2273 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2274 | GLenum pname, |
| 2275 | GLsizei bufSize, |
| 2276 | GLsizei *length, |
| 2277 | GLboolean *params) |
| 2278 | { |
| 2279 | GLenum nativeType; |
| 2280 | unsigned int numParams = 0; |
| 2281 | |
| 2282 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2283 | { |
| 2284 | return false; |
| 2285 | } |
| 2286 | |
| 2287 | SetRobustLengthParam(length, numParams); |
| 2288 | |
| 2289 | return true; |
| 2290 | } |
| 2291 | |
| 2292 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2293 | GLenum pname, |
| 2294 | GLsizei bufSize, |
| 2295 | GLsizei *length, |
| 2296 | GLfloat *params) |
| 2297 | { |
| 2298 | GLenum nativeType; |
| 2299 | unsigned int numParams = 0; |
| 2300 | |
| 2301 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2302 | { |
| 2303 | return false; |
| 2304 | } |
| 2305 | |
| 2306 | SetRobustLengthParam(length, numParams); |
| 2307 | |
| 2308 | return true; |
| 2309 | } |
| 2310 | |
| 2311 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2312 | GLenum pname, |
| 2313 | GLsizei bufSize, |
| 2314 | GLsizei *length, |
| 2315 | GLint *data) |
| 2316 | { |
| 2317 | GLenum nativeType; |
| 2318 | unsigned int numParams = 0; |
| 2319 | |
| 2320 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2321 | { |
| 2322 | return false; |
| 2323 | } |
| 2324 | |
| 2325 | SetRobustLengthParam(length, numParams); |
| 2326 | |
| 2327 | return true; |
| 2328 | } |
| 2329 | |
| 2330 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2331 | GLenum pname, |
| 2332 | GLsizei bufSize, |
| 2333 | GLsizei *length, |
| 2334 | GLint64 *data) |
| 2335 | { |
| 2336 | GLenum nativeType; |
| 2337 | unsigned int numParams = 0; |
| 2338 | |
| 2339 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2340 | { |
| 2341 | return false; |
| 2342 | } |
| 2343 | |
| 2344 | if (nativeType == GL_INT_64_ANGLEX) |
| 2345 | { |
| 2346 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2347 | return false; |
| 2348 | } |
| 2349 | |
| 2350 | SetRobustLengthParam(length, numParams); |
| 2351 | return true; |
| 2352 | } |
| 2353 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2354 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2355 | GLenum pname, |
| 2356 | GLsizei bufSize, |
| 2357 | GLenum *nativeType, |
| 2358 | unsigned int *numParams) |
| 2359 | { |
| 2360 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2361 | { |
| 2362 | return false; |
| 2363 | } |
| 2364 | |
| 2365 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2366 | { |
| 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2371 | { |
| 2372 | return false; |
| 2373 | } |
| 2374 | |
| 2375 | return true; |
| 2376 | } |
| 2377 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2378 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2379 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2380 | GLint level, |
| 2381 | GLenum internalformat, |
| 2382 | bool isSubImage, |
| 2383 | GLint xoffset, |
| 2384 | GLint yoffset, |
| 2385 | GLint zoffset, |
| 2386 | GLint x, |
| 2387 | GLint y, |
| 2388 | GLsizei width, |
| 2389 | GLsizei height, |
| 2390 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2391 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2392 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2393 | TextureType texType = TextureTargetToType(target); |
| 2394 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2395 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2396 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2397 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2398 | return false; |
| 2399 | } |
| 2400 | |
| 2401 | if (width < 0 || height < 0) |
| 2402 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2403 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2404 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2405 | } |
| 2406 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2407 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2408 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2409 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2410 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2411 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2412 | } |
| 2413 | |
| 2414 | if (border != 0) |
| 2415 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2416 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2417 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2418 | } |
| 2419 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2420 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2421 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2422 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2423 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2424 | } |
| 2425 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2426 | const State &state = context->getState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2427 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2428 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2429 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2430 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2431 | } |
| 2432 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2433 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2434 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2435 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2436 | } |
| 2437 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2438 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2439 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2440 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2441 | return false; |
| 2442 | } |
| 2443 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2444 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2445 | // 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] | 2446 | // 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] | 2447 | // 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] | 2448 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2449 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2450 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2451 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2455 | // ANGLE_multiview spec, Revision 1: |
| 2456 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2457 | // 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] | 2458 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2459 | // framebuffer is more than one. |
| 2460 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2461 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 2462 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kMultiviewReadFramebuffer); |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2463 | return false; |
| 2464 | } |
| 2465 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2466 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2467 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2468 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2469 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2470 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2471 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2472 | maxDimension = caps.max2DTextureSize; |
| 2473 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2474 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2475 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2476 | maxDimension = caps.maxCubeMapTextureSize; |
| 2477 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2478 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2479 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2480 | maxDimension = caps.maxRectangleTextureSize; |
| 2481 | break; |
| 2482 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2483 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2484 | maxDimension = caps.max2DTextureSize; |
| 2485 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2486 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2487 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2488 | maxDimension = caps.max3DTextureSize; |
| 2489 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2490 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2491 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2492 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2493 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2494 | } |
| 2495 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2496 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2497 | if (!texture) |
| 2498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2499 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2500 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2501 | } |
| 2502 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2503 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2504 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2505 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2506 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2507 | } |
| 2508 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2509 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2510 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2511 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2512 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2513 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2514 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2515 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2516 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | if (isSubImage) |
| 2520 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2521 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2522 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2523 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2524 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2525 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2526 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2527 | } |
| 2528 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2529 | else |
| 2530 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2531 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2532 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2533 | context->validationError(GL_INVALID_VALUE, kCubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2534 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2537 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2538 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2539 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2540 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2544 | if (static_cast<int>(width) > maxLevelDimension || |
| 2545 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2546 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2547 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2548 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2549 | } |
| 2550 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2551 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2552 | if (textureFormatOut) |
| 2553 | { |
| 2554 | *textureFormatOut = texture->getFormat(target, level); |
| 2555 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2556 | |
| 2557 | // Detect texture copying feedback loops for WebGL. |
| 2558 | if (context->getExtensions().webglCompatibility) |
| 2559 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2560 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2561 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2562 | context->validationError(GL_INVALID_OPERATION, kFeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2563 | return false; |
| 2564 | } |
| 2565 | } |
| 2566 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2567 | return true; |
| 2568 | } |
| 2569 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2570 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2571 | // completeness check. |
| 2572 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2573 | { |
| 2574 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2575 | const State &state = context->getState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2576 | |
| 2577 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2578 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2579 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2580 | VertexArray *vertexArray = state.getVertexArray(); |
| 2581 | ASSERT(vertexArray); |
| 2582 | |
| 2583 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2585 | return kBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2586 | } |
| 2587 | |
| 2588 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2589 | // Section 6.10 of the WebGL 1.0 spec. |
| 2590 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2591 | ASSERT(framebuffer); |
| 2592 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2593 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2594 | { |
| 2595 | ASSERT(framebuffer); |
| 2596 | const FramebufferAttachment *dsAttachment = |
| 2597 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2598 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2599 | ASSERT(stencilBits <= 8); |
| 2600 | |
| 2601 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2602 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2603 | { |
| 2604 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2605 | |
| 2606 | bool differentRefs = |
| 2607 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2608 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2609 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2610 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2611 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2612 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2613 | |
| 2614 | if (differentRefs || differentWritemasks || differentMasks) |
| 2615 | { |
| 2616 | if (!extensions.webglCompatibility) |
| 2617 | { |
| 2618 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2619 | "stencil writemasks, reference values, or stencil mask values."; |
| 2620 | } |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2621 | return kStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2622 | } |
| 2623 | } |
| 2624 | } |
| 2625 | |
| 2626 | if (!framebuffer->isComplete(context)) |
| 2627 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2628 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2629 | return kDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2633 | { |
| 2634 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2635 | { |
| 2636 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2637 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2638 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2639 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2640 | return kVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2644 | { |
| 2645 | // This is an application error that would normally result in a crash, but we catch it |
| 2646 | // and return an error |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2647 | return kVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | // If we are running GLES1, there is no current program. |
| 2652 | if (context->getClientVersion() >= Version(2, 0)) |
| 2653 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2654 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2655 | if (!program) |
| 2656 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2657 | return kProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2658 | } |
| 2659 | |
| 2660 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2661 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2662 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2663 | // produce undefined result. |
| 2664 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2665 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2666 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2667 | return kNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2668 | } |
| 2669 | |
| 2670 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2671 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2672 | return kTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2673 | } |
| 2674 | |
| 2675 | if (extensions.multiview) |
| 2676 | { |
| 2677 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2678 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2679 | if (framebufferNumViews != programNumViews) |
| 2680 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2681 | return kMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2685 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
Jamie Madill | 3a25622 | 2018-12-08 09:56:39 -0500 | [diff] [blame] | 2686 | !transformFeedbackObject->isPaused() && framebufferNumViews > 1) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2687 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2688 | return kMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2689 | } |
| 2690 | |
| 2691 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2692 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2693 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2694 | return kMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2695 | } |
| 2696 | } |
| 2697 | |
| 2698 | // Uniform buffer validation |
| 2699 | for (unsigned int uniformBlockIndex = 0; |
| 2700 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2701 | { |
| 2702 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2703 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2704 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2705 | state.getIndexedUniformBuffer(blockBinding); |
| 2706 | |
| 2707 | if (uniformBuffer.get() == nullptr) |
| 2708 | { |
| 2709 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2710 | return kUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2714 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2715 | { |
| 2716 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2717 | return kUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2718 | } |
| 2719 | |
| 2720 | if (extensions.webglCompatibility && |
| 2721 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2722 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2723 | return kUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2724 | } |
| 2725 | } |
| 2726 | |
| 2727 | // Do some additonal WebGL-specific validation |
| 2728 | if (extensions.webglCompatibility) |
| 2729 | { |
James Darpinian | e4109f2 | 2018-12-13 16:25:53 -0800 | [diff] [blame] | 2730 | if (!state.validateSamplerFormats()) |
| 2731 | { |
| 2732 | return kSamplerFormatMismatch; |
| 2733 | } |
| 2734 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2735 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2736 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2737 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2738 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2739 | return kTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | // Detect rendering feedback loops for WebGL. |
| 2743 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2744 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2745 | return kFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | // Detect that the vertex shader input types match the attribute types |
| 2749 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2750 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2751 | return kVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2752 | } |
| 2753 | |
| 2754 | // Detect that the color buffer types match the fragment shader output types |
| 2755 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2756 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2757 | return kDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2758 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2759 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2760 | const VertexArray *vao = context->getState().getVertexArray(); |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2761 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2762 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2763 | return kVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2764 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2765 | } |
| 2766 | } |
| 2767 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2768 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2769 | } |
| 2770 | |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2771 | void RecordDrawModeError(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2772 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2773 | const State &state = context->getState(); |
Jamie Madill | 9b02506 | 2018-12-12 15:44:12 -0500 | [diff] [blame] | 2774 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
| 2775 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2776 | !curTransformFeedback->isPaused()) |
| 2777 | { |
| 2778 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2779 | curTransformFeedback->getPrimitiveMode(), mode)) |
| 2780 | { |
| 2781 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2782 | return; |
Jamie Madill | 9b02506 | 2018-12-12 15:44:12 -0500 | [diff] [blame] | 2783 | } |
| 2784 | } |
| 2785 | |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2786 | const Extensions &extensions = context->getExtensions(); |
| 2787 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2788 | switch (mode) |
| 2789 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2790 | case PrimitiveMode::Points: |
| 2791 | case PrimitiveMode::Lines: |
| 2792 | case PrimitiveMode::LineLoop: |
| 2793 | case PrimitiveMode::LineStrip: |
| 2794 | case PrimitiveMode::Triangles: |
| 2795 | case PrimitiveMode::TriangleStrip: |
| 2796 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2797 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2798 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2799 | case PrimitiveMode::LinesAdjacency: |
| 2800 | case PrimitiveMode::LineStripAdjacency: |
| 2801 | case PrimitiveMode::TrianglesAdjacency: |
| 2802 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2803 | if (!extensions.geometryShader) |
| 2804 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2805 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2806 | return; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2807 | } |
| 2808 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2809 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2810 | context->validationError(GL_INVALID_ENUM, kInvalidDrawMode); |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2811 | return; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2814 | // If we are running GLES1, there is no current program. |
| 2815 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2816 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2817 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2818 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2819 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2820 | // Do geometry shader specific validations |
| 2821 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2822 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2823 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2824 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2825 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2826 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2827 | kIncompatibleDrawModeAgainstGeometryShader); |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2828 | return; |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2829 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2830 | } |
| 2831 | } |
| 2832 | |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 2833 | // An error should be recorded. |
| 2834 | UNREACHABLE(); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2835 | } |
| 2836 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2837 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2838 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2839 | GLint first, |
| 2840 | GLsizei count, |
| 2841 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2842 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2843 | if (!context->getExtensions().instancedArrays) |
| 2844 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2845 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2846 | return false; |
| 2847 | } |
| 2848 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2849 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2850 | { |
| 2851 | return false; |
| 2852 | } |
| 2853 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2854 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2855 | } |
| 2856 | |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2857 | const char *ValidateDrawElementsStates(Context *context) |
| 2858 | { |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2859 | const State &state = context->getState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2860 | |
Jamie Madill | ae6ba9f | 2018-12-21 23:00:04 -0500 | [diff] [blame] | 2861 | if (context->getStateCache().isTransformFeedbackActiveUnpaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2862 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2863 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2864 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
Jamie Madill | 9b02506 | 2018-12-12 15:44:12 -0500 | [diff] [blame] | 2865 | if (!context->getExtensions().geometryShader) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2866 | { |
| 2867 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2868 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2869 | // 86) |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2870 | return kUnsupportedDrawModeForTransformFeedback; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2871 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2872 | } |
| 2873 | |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2874 | const VertexArray *vao = state.getVertexArray(); |
| 2875 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
| 2876 | |
| 2877 | if (elementArrayBuffer) |
| 2878 | { |
| 2879 | if (context->getExtensions().webglCompatibility) |
| 2880 | { |
| 2881 | if (elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2882 | { |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2883 | return kElementArrayBufferBoundForTransformFeedback; |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2884 | } |
| 2885 | } |
| 2886 | else if (elementArrayBuffer->isMapped()) |
| 2887 | { |
| 2888 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 2889 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the |
| 2890 | // WebGL 2.0 API. https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2891 | return kBufferMapped; |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2892 | } |
| 2893 | } |
| 2894 | else |
| 2895 | { |
| 2896 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
| 2897 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 2898 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2899 | if (!context->getState().areClientArraysEnabled() || |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2900 | context->getExtensions().webglCompatibility) |
| 2901 | { |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2902 | return kMustHaveElementArrayBinding; |
Jamie Madill | f5c88e7 | 2018-12-08 09:56:38 -0500 | [diff] [blame] | 2903 | } |
| 2904 | } |
| 2905 | |
Jamie Madill | 1e85326 | 2018-12-21 09:07:38 -0500 | [diff] [blame] | 2906 | return nullptr; |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2907 | } |
| 2908 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2909 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2910 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2911 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2912 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2913 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2914 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2915 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2916 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2917 | } |
| 2918 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2919 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2920 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2921 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame] | 2922 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2923 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2924 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2925 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2926 | if (!context->getExtensions().instancedArrays) |
| 2927 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2928 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2929 | return false; |
| 2930 | } |
| 2931 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2932 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2933 | { |
| 2934 | return false; |
| 2935 | } |
| 2936 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2937 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2938 | } |
| 2939 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2940 | bool ValidateFramebufferTextureBase(Context *context, |
| 2941 | GLenum target, |
| 2942 | GLenum attachment, |
| 2943 | GLuint texture, |
| 2944 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2945 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 2946 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2947 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2948 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2949 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 2953 | { |
| 2954 | return false; |
| 2955 | } |
| 2956 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2957 | if (texture != 0) |
| 2958 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2959 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2960 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 2961 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2962 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2963 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2964 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | if (level < 0) |
| 2968 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2969 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2970 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2971 | } |
| 2972 | } |
| 2973 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 2974 | const Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 2975 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2976 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 2977 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2978 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2979 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2980 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 2981 | } |
| 2982 | |
| 2983 | return true; |
| 2984 | } |
| 2985 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2986 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2987 | { |
| 2988 | if (program == 0) |
| 2989 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2990 | context->validationError(GL_INVALID_VALUE, kProgramDoesNotExist); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2991 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 2992 | } |
| 2993 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2994 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 2995 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 2996 | { |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3000 | if (!programObject || !programObject->isLinked()) |
| 3001 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3002 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3003 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3004 | } |
| 3005 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3006 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3007 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3008 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3009 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3010 | } |
| 3011 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3012 | return true; |
| 3013 | } |
| 3014 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3015 | static bool ValidateSizedGetUniform(Context *context, |
| 3016 | GLuint program, |
| 3017 | GLint location, |
| 3018 | GLsizei bufSize, |
| 3019 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3020 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3021 | if (length) |
| 3022 | { |
| 3023 | *length = 0; |
| 3024 | } |
| 3025 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3026 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3027 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3028 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3029 | } |
| 3030 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3031 | if (bufSize < 0) |
| 3032 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3033 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3034 | return false; |
| 3035 | } |
| 3036 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3037 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3038 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3039 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3040 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3041 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3042 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3043 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3044 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3045 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3046 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3047 | } |
| 3048 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3049 | if (length) |
| 3050 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3051 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3052 | } |
| 3053 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3054 | return true; |
| 3055 | } |
| 3056 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3057 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3058 | GLuint program, |
| 3059 | GLint location, |
| 3060 | GLsizei bufSize, |
| 3061 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3062 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3063 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3064 | } |
| 3065 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3066 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3067 | GLuint program, |
| 3068 | GLint location, |
| 3069 | GLsizei bufSize, |
| 3070 | GLsizei *length, |
| 3071 | GLfloat *params) |
| 3072 | { |
| 3073 | UNIMPLEMENTED(); |
| 3074 | return false; |
| 3075 | } |
| 3076 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3077 | bool ValidateGetnUniformivEXT(Context *context, |
| 3078 | GLuint program, |
| 3079 | GLint location, |
| 3080 | GLsizei bufSize, |
| 3081 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3082 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3083 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3084 | } |
| 3085 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3086 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3087 | GLuint program, |
| 3088 | GLint location, |
| 3089 | GLsizei bufSize, |
| 3090 | GLsizei *length, |
| 3091 | GLint *params) |
| 3092 | { |
| 3093 | UNIMPLEMENTED(); |
| 3094 | return false; |
| 3095 | } |
| 3096 | |
| 3097 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3098 | GLuint program, |
| 3099 | GLint location, |
| 3100 | GLsizei bufSize, |
| 3101 | GLsizei *length, |
| 3102 | GLuint *params) |
| 3103 | { |
| 3104 | UNIMPLEMENTED(); |
| 3105 | return false; |
| 3106 | } |
| 3107 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3108 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3109 | GLuint program, |
| 3110 | GLint location, |
| 3111 | GLsizei bufSize, |
| 3112 | GLsizei *length, |
| 3113 | GLfloat *params) |
| 3114 | { |
| 3115 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3116 | { |
| 3117 | return false; |
| 3118 | } |
| 3119 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3120 | GLsizei writeLength = 0; |
| 3121 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3122 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3123 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3124 | { |
| 3125 | return false; |
| 3126 | } |
| 3127 | |
| 3128 | SetRobustLengthParam(length, writeLength); |
| 3129 | |
| 3130 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3134 | GLuint program, |
| 3135 | GLint location, |
| 3136 | GLsizei bufSize, |
| 3137 | GLsizei *length, |
| 3138 | GLint *params) |
| 3139 | { |
| 3140 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3141 | { |
| 3142 | return false; |
| 3143 | } |
| 3144 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3145 | GLsizei writeLength = 0; |
| 3146 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3147 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3148 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3149 | { |
| 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | SetRobustLengthParam(length, writeLength); |
| 3154 | |
| 3155 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3159 | GLuint program, |
| 3160 | GLint location, |
| 3161 | GLsizei bufSize, |
| 3162 | GLsizei *length, |
| 3163 | GLuint *params) |
| 3164 | { |
| 3165 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3166 | { |
| 3167 | return false; |
| 3168 | } |
| 3169 | |
| 3170 | if (context->getClientMajorVersion() < 3) |
| 3171 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3172 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3173 | return false; |
| 3174 | } |
| 3175 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3176 | GLsizei writeLength = 0; |
| 3177 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3178 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3179 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3180 | { |
| 3181 | return false; |
| 3182 | } |
| 3183 | |
| 3184 | SetRobustLengthParam(length, writeLength); |
| 3185 | |
| 3186 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3187 | } |
| 3188 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3189 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3190 | GLenum target, |
| 3191 | GLsizei numAttachments, |
| 3192 | const GLenum *attachments, |
| 3193 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3194 | { |
| 3195 | if (numAttachments < 0) |
| 3196 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3197 | context->validationError(GL_INVALID_VALUE, kNegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3198 | return false; |
| 3199 | } |
| 3200 | |
| 3201 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3202 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3203 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3204 | { |
| 3205 | if (defaultFramebuffer) |
| 3206 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3207 | context->validationError(GL_INVALID_ENUM, kDefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3208 | return false; |
| 3209 | } |
| 3210 | |
| 3211 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3212 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3213 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxColorAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3214 | return false; |
| 3215 | } |
| 3216 | } |
| 3217 | else |
| 3218 | { |
| 3219 | switch (attachments[i]) |
| 3220 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3221 | case GL_DEPTH_ATTACHMENT: |
| 3222 | case GL_STENCIL_ATTACHMENT: |
| 3223 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3224 | if (defaultFramebuffer) |
| 3225 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3226 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3227 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3228 | return false; |
| 3229 | } |
| 3230 | break; |
| 3231 | case GL_COLOR: |
| 3232 | case GL_DEPTH: |
| 3233 | case GL_STENCIL: |
| 3234 | if (!defaultFramebuffer) |
| 3235 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3236 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3237 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3238 | return false; |
| 3239 | } |
| 3240 | break; |
| 3241 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3242 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3243 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3244 | } |
| 3245 | } |
| 3246 | } |
| 3247 | |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3251 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3252 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3253 | if (!context->getExtensions().debugMarker) |
| 3254 | { |
| 3255 | // The debug marker calls should not set error state |
| 3256 | // 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] | 3257 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3258 | return false; |
| 3259 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3260 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3261 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3262 | if (length < 0) |
| 3263 | { |
| 3264 | return false; |
| 3265 | } |
| 3266 | |
| 3267 | if (marker == nullptr) |
| 3268 | { |
| 3269 | return false; |
| 3270 | } |
| 3271 | |
| 3272 | return true; |
| 3273 | } |
| 3274 | |
| 3275 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3276 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3277 | if (!context->getExtensions().debugMarker) |
| 3278 | { |
| 3279 | // The debug marker calls should not set error state |
| 3280 | // 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] | 3281 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3282 | return false; |
| 3283 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3284 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3285 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3286 | if (length < 0) |
| 3287 | { |
| 3288 | return false; |
| 3289 | } |
| 3290 | |
| 3291 | if (length > 0 && marker == nullptr) |
| 3292 | { |
| 3293 | return false; |
| 3294 | } |
| 3295 | |
| 3296 | return true; |
| 3297 | } |
| 3298 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3299 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3300 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3301 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3302 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3303 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3304 | return false; |
| 3305 | } |
| 3306 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3307 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3308 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3309 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3310 | if (!context->getExtensions().eglImage) |
| 3311 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3312 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3313 | } |
| 3314 | break; |
| 3315 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3316 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3317 | if (!context->getExtensions().eglImageExternal) |
| 3318 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3319 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3320 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3321 | break; |
| 3322 | |
| 3323 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3324 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3325 | return false; |
| 3326 | } |
| 3327 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3328 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3329 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3330 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3331 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3332 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3333 | context->validationError(GL_INVALID_VALUE, kInvalidEGLImage); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3334 | return false; |
| 3335 | } |
| 3336 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3337 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3338 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3339 | context->validationError(GL_INVALID_OPERATION, kEGLImageCannotCreate2DMultisampled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3340 | return false; |
| 3341 | } |
| 3342 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3343 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3344 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3345 | context->validationError(GL_INVALID_OPERATION, kEGLImageTextureFormatNotSupported); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3346 | return false; |
| 3347 | } |
| 3348 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3349 | return true; |
| 3350 | } |
| 3351 | |
| 3352 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3353 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3354 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3355 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3356 | if (!context->getExtensions().eglImage) |
| 3357 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3358 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3359 | return false; |
| 3360 | } |
| 3361 | |
| 3362 | switch (target) |
| 3363 | { |
| 3364 | case GL_RENDERBUFFER: |
| 3365 | break; |
| 3366 | |
| 3367 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3368 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3369 | return false; |
| 3370 | } |
| 3371 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3372 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3373 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3374 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3375 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3376 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3377 | context->validationError(GL_INVALID_VALUE, kInvalidEGLImage); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3378 | return false; |
| 3379 | } |
| 3380 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3381 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3382 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3383 | context->validationError(GL_INVALID_OPERATION, kEGLImageRenderbufferFormatNotSupported); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3384 | return false; |
| 3385 | } |
| 3386 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3387 | return true; |
| 3388 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3389 | |
| 3390 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3391 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3392 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3393 | { |
| 3394 | // The default VAO should always exist |
| 3395 | ASSERT(array != 0); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3396 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexArray); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3397 | return false; |
| 3398 | } |
| 3399 | |
| 3400 | return true; |
| 3401 | } |
| 3402 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3403 | bool ValidateProgramBinaryBase(Context *context, |
| 3404 | GLuint program, |
| 3405 | GLenum binaryFormat, |
| 3406 | const void *binary, |
| 3407 | GLint length) |
| 3408 | { |
| 3409 | Program *programObject = GetValidProgram(context, program); |
| 3410 | if (programObject == nullptr) |
| 3411 | { |
| 3412 | return false; |
| 3413 | } |
| 3414 | |
| 3415 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3416 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3417 | programBinaryFormats.end()) |
| 3418 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3419 | context->validationError(GL_INVALID_ENUM, kInvalidProgramBinaryFormat); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3420 | return false; |
| 3421 | } |
| 3422 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3423 | if (context->hasActiveTransformFeedback(program)) |
| 3424 | { |
| 3425 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3426 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackProgramBinary); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3427 | return false; |
| 3428 | } |
| 3429 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3430 | return true; |
| 3431 | } |
| 3432 | |
| 3433 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3434 | GLuint program, |
| 3435 | GLsizei bufSize, |
| 3436 | GLsizei *length, |
| 3437 | GLenum *binaryFormat, |
| 3438 | void *binary) |
| 3439 | { |
| 3440 | Program *programObject = GetValidProgram(context, program); |
| 3441 | if (programObject == nullptr) |
| 3442 | { |
| 3443 | return false; |
| 3444 | } |
| 3445 | |
| 3446 | if (!programObject->isLinked()) |
| 3447 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3448 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3449 | return false; |
| 3450 | } |
| 3451 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3452 | if (context->getCaps().programBinaryFormats.empty()) |
| 3453 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3454 | context->validationError(GL_INVALID_OPERATION, kNoProgramBinaryFormats); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3455 | return false; |
| 3456 | } |
| 3457 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3458 | return true; |
| 3459 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3460 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3461 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3462 | { |
| 3463 | // 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] | 3464 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3465 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3466 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3467 | return false; |
| 3468 | } |
| 3469 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3470 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3471 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3472 | return false; |
| 3473 | } |
| 3474 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3475 | ASSERT(context->getState().getDrawFramebuffer()); |
| 3476 | GLuint frameBufferId = context->getState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3477 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3478 | |
| 3479 | // This should come first before the check for the default frame buffer |
| 3480 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3481 | // rather than INVALID_OPERATION |
| 3482 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3483 | { |
| 3484 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3485 | |
| 3486 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3487 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3488 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3489 | { |
| 3490 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3491 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3492 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3493 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3494 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3495 | context->validationError(GL_INVALID_ENUM, kInvalidDrawBuffer); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3496 | return false; |
| 3497 | } |
| 3498 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3499 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3500 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxColorAttachments); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3501 | return false; |
| 3502 | } |
| 3503 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3504 | frameBufferId != 0) |
| 3505 | { |
| 3506 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3507 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3508 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawBufferValue); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3509 | return false; |
| 3510 | } |
| 3511 | } |
| 3512 | |
| 3513 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3514 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3515 | if (frameBufferId == 0) |
| 3516 | { |
| 3517 | if (n != 1) |
| 3518 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3519 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawBufferCountForDefault); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3520 | return false; |
| 3521 | } |
| 3522 | |
| 3523 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3524 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3525 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferInvalidDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3526 | return false; |
| 3527 | } |
| 3528 | } |
| 3529 | |
| 3530 | return true; |
| 3531 | } |
| 3532 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3533 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3534 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3535 | GLenum pname, |
| 3536 | GLsizei *length, |
| 3537 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3538 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3539 | if (length) |
| 3540 | { |
| 3541 | *length = 0; |
| 3542 | } |
| 3543 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3544 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3545 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3546 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3547 | return false; |
| 3548 | } |
| 3549 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3550 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3551 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3552 | case GL_BUFFER_MAP_POINTER: |
| 3553 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3554 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3555 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3556 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3557 | return false; |
| 3558 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3559 | |
| 3560 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3561 | // target bound to zero generate an INVALID_OPERATION error." |
| 3562 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3563 | if (context->getState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3564 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3565 | context->validationError(GL_INVALID_OPERATION, kBufferPointerNotAvailable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3566 | return false; |
| 3567 | } |
| 3568 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3569 | if (length) |
| 3570 | { |
| 3571 | *length = 1; |
| 3572 | } |
| 3573 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3574 | return true; |
| 3575 | } |
| 3576 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3577 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3578 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3579 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3580 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3581 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3582 | return false; |
| 3583 | } |
| 3584 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3585 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3586 | |
| 3587 | if (buffer == nullptr || !buffer->isMapped()) |
| 3588 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3589 | context->validationError(GL_INVALID_OPERATION, kBufferNotMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3590 | return false; |
| 3591 | } |
| 3592 | |
| 3593 | return true; |
| 3594 | } |
| 3595 | |
| 3596 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3597 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3598 | GLintptr offset, |
| 3599 | GLsizeiptr length, |
| 3600 | GLbitfield access) |
| 3601 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3602 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3603 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3604 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3605 | return false; |
| 3606 | } |
| 3607 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3608 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3609 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3610 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3611 | return false; |
| 3612 | } |
| 3613 | |
| 3614 | if (length < 0) |
| 3615 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3616 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3617 | return false; |
| 3618 | } |
| 3619 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3620 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3621 | |
| 3622 | if (!buffer) |
| 3623 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3624 | context->validationError(GL_INVALID_OPERATION, kBufferNotMappable); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3625 | return false; |
| 3626 | } |
| 3627 | |
| 3628 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3629 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3630 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3631 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3632 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3633 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3634 | context->validationError(GL_INVALID_VALUE, kMapOutOfRange); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3635 | return false; |
| 3636 | } |
| 3637 | |
| 3638 | // Check for invalid bits in the mask |
| 3639 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3640 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3641 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3642 | |
| 3643 | if (access & ~(allAccessBits)) |
| 3644 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3645 | context->validationError(GL_INVALID_VALUE, kInvalidAccessBits); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3646 | return false; |
| 3647 | } |
| 3648 | |
| 3649 | if (length == 0) |
| 3650 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3651 | context->validationError(GL_INVALID_OPERATION, kLengthZero); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3652 | return false; |
| 3653 | } |
| 3654 | |
| 3655 | if (buffer->isMapped()) |
| 3656 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3657 | context->validationError(GL_INVALID_OPERATION, kBufferAlreadyMapped); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3658 | return false; |
| 3659 | } |
| 3660 | |
| 3661 | // Check for invalid bit combinations |
| 3662 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3663 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3664 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsReadWrite); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3665 | return false; |
| 3666 | } |
| 3667 | |
| 3668 | GLbitfield writeOnlyBits = |
| 3669 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3670 | |
| 3671 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3672 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3673 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsRead); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3674 | return false; |
| 3675 | } |
| 3676 | |
| 3677 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3678 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3679 | context->validationError(GL_INVALID_OPERATION, kInvalidAccessBitsFlush); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3680 | return false; |
| 3681 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3682 | |
| 3683 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3684 | } |
| 3685 | |
| 3686 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3687 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3688 | GLintptr offset, |
| 3689 | GLsizeiptr length) |
| 3690 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3691 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3692 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3693 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3694 | return false; |
| 3695 | } |
| 3696 | |
| 3697 | if (length < 0) |
| 3698 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3699 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3700 | return false; |
| 3701 | } |
| 3702 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3703 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3704 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3705 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3706 | return false; |
| 3707 | } |
| 3708 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3709 | Buffer *buffer = context->getState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3710 | |
| 3711 | if (buffer == nullptr) |
| 3712 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3713 | context->validationError(GL_INVALID_OPERATION, kInvalidFlushZero); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3714 | return false; |
| 3715 | } |
| 3716 | |
| 3717 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3718 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3719 | context->validationError(GL_INVALID_OPERATION, kInvalidFlushTarget); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3720 | return false; |
| 3721 | } |
| 3722 | |
| 3723 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3724 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3725 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3726 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3727 | if (!checkedSize.IsValid() || |
| 3728 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3729 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3730 | context->validationError(GL_INVALID_VALUE, kInvalidFlushOutOfRange); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | |
| 3734 | return true; |
| 3735 | } |
| 3736 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3737 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3738 | { |
| 3739 | if (n < 0) |
| 3740 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3741 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3742 | return false; |
| 3743 | } |
| 3744 | return true; |
| 3745 | } |
| 3746 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3747 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3748 | { |
| 3749 | if (!context->getExtensions().robustClientMemory) |
| 3750 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3751 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3752 | return false; |
| 3753 | } |
| 3754 | |
| 3755 | if (bufSize < 0) |
| 3756 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3757 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3758 | return false; |
| 3759 | } |
| 3760 | |
| 3761 | return true; |
| 3762 | } |
| 3763 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3764 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3765 | { |
| 3766 | if (bufSize < numParams) |
| 3767 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 3768 | context->validationError(GL_INVALID_OPERATION, kInsufficientParams); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3769 | return false; |
| 3770 | } |
| 3771 | |
| 3772 | return true; |
| 3773 | } |
| 3774 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 3775 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 3776 | GLenum target, |
| 3777 | GLenum attachment, |
| 3778 | GLenum pname, |
| 3779 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3780 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3781 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3782 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3783 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3784 | return false; |
| 3785 | } |
| 3786 | |
| 3787 | int clientVersion = context->getClientMajorVersion(); |
| 3788 | |
| 3789 | switch (pname) |
| 3790 | { |
| 3791 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 3792 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 3793 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 3794 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 3795 | break; |
| 3796 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 3797 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 3798 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 3799 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 3800 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 3801 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 3802 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3803 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 3804 | return false; |
| 3805 | } |
| 3806 | break; |
| 3807 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3808 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 3809 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 3810 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3811 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3812 | return false; |
| 3813 | } |
| 3814 | break; |
| 3815 | |
| 3816 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 3817 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 3818 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 3819 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 3820 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 3821 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 3822 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 3823 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 3824 | if (clientVersion < 3) |
| 3825 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3826 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3827 | return false; |
| 3828 | } |
| 3829 | break; |
| 3830 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 3831 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 3832 | if (!context->getExtensions().geometryShader) |
| 3833 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3834 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | break; |
| 3838 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3839 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3840 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3841 | return false; |
| 3842 | } |
| 3843 | |
| 3844 | // Determine if the attachment is a valid enum |
| 3845 | switch (attachment) |
| 3846 | { |
| 3847 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3848 | case GL_DEPTH: |
| 3849 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3850 | if (clientVersion < 3) |
| 3851 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3852 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3853 | return false; |
| 3854 | } |
| 3855 | break; |
| 3856 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 3857 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3858 | if (clientVersion < 3 && !context->isWebGL1()) |
| 3859 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3860 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 3861 | return false; |
| 3862 | } |
| 3863 | break; |
| 3864 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3865 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3866 | case GL_DEPTH_ATTACHMENT: |
| 3867 | case GL_STENCIL_ATTACHMENT: |
| 3868 | break; |
| 3869 | |
| 3870 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3871 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 3872 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3873 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 3874 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3875 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3876 | return false; |
| 3877 | } |
| 3878 | break; |
| 3879 | } |
| 3880 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 3881 | const Framebuffer *framebuffer = context->getState().getTargetFramebuffer(target); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3882 | ASSERT(framebuffer); |
| 3883 | |
| 3884 | if (framebuffer->id() == 0) |
| 3885 | { |
| 3886 | if (clientVersion < 3) |
| 3887 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3888 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3889 | return false; |
| 3890 | } |
| 3891 | |
| 3892 | switch (attachment) |
| 3893 | { |
| 3894 | case GL_BACK: |
| 3895 | case GL_DEPTH: |
| 3896 | case GL_STENCIL: |
| 3897 | break; |
| 3898 | |
| 3899 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3900 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3901 | return false; |
| 3902 | } |
| 3903 | } |
| 3904 | else |
| 3905 | { |
| 3906 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 3907 | { |
| 3908 | // Valid attachment query |
| 3909 | } |
| 3910 | else |
| 3911 | { |
| 3912 | switch (attachment) |
| 3913 | { |
| 3914 | case GL_DEPTH_ATTACHMENT: |
| 3915 | case GL_STENCIL_ATTACHMENT: |
| 3916 | break; |
| 3917 | |
| 3918 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 3919 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3920 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3921 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3922 | return false; |
| 3923 | } |
| 3924 | break; |
| 3925 | |
| 3926 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3927 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3928 | return false; |
| 3929 | } |
| 3930 | } |
| 3931 | } |
| 3932 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 3933 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3934 | if (attachmentObject) |
| 3935 | { |
| 3936 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 3937 | attachmentObject->type() == GL_TEXTURE || |
| 3938 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 3939 | |
| 3940 | switch (pname) |
| 3941 | { |
| 3942 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 3943 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 3944 | attachmentObject->type() != GL_TEXTURE) |
| 3945 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3946 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3947 | return false; |
| 3948 | } |
| 3949 | break; |
| 3950 | |
| 3951 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 3952 | if (attachmentObject->type() != GL_TEXTURE) |
| 3953 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3954 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3955 | return false; |
| 3956 | } |
| 3957 | break; |
| 3958 | |
| 3959 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 3960 | if (attachmentObject->type() != GL_TEXTURE) |
| 3961 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3962 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3963 | return false; |
| 3964 | } |
| 3965 | break; |
| 3966 | |
| 3967 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 3968 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 3969 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3970 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3971 | return false; |
| 3972 | } |
| 3973 | break; |
| 3974 | |
| 3975 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 3976 | if (attachmentObject->type() != GL_TEXTURE) |
| 3977 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3978 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3979 | return false; |
| 3980 | } |
| 3981 | break; |
| 3982 | |
| 3983 | default: |
| 3984 | break; |
| 3985 | } |
| 3986 | } |
| 3987 | else |
| 3988 | { |
| 3989 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 3990 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 3991 | |
| 3992 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 3993 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 3994 | // INVALID_OPERATION for all other pnames |
| 3995 | |
| 3996 | switch (pname) |
| 3997 | { |
| 3998 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 3999 | break; |
| 4000 | |
| 4001 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4002 | if (clientVersion < 3) |
| 4003 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4004 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4005 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4006 | return false; |
| 4007 | } |
| 4008 | break; |
| 4009 | |
| 4010 | default: |
| 4011 | if (clientVersion < 3) |
| 4012 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4013 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4014 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4015 | return false; |
| 4016 | } |
| 4017 | else |
| 4018 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4019 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4020 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4021 | return false; |
| 4022 | } |
| 4023 | } |
| 4024 | } |
| 4025 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4026 | if (numParams) |
| 4027 | { |
| 4028 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4029 | { |
| 4030 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4031 | // parameters. |
| 4032 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4033 | *numParams = numViews * 2; |
| 4034 | } |
| 4035 | else |
| 4036 | { |
| 4037 | // For all other queries we can have only one output parameter. |
| 4038 | *numParams = 1; |
| 4039 | } |
| 4040 | } |
| 4041 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4042 | return true; |
| 4043 | } |
| 4044 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4045 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4046 | GLenum target, |
| 4047 | GLenum attachment, |
| 4048 | GLenum pname, |
| 4049 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4050 | GLsizei *length, |
| 4051 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4052 | { |
| 4053 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4054 | { |
| 4055 | return false; |
| 4056 | } |
| 4057 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4058 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4059 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4060 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4061 | { |
| 4062 | return false; |
| 4063 | } |
| 4064 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4065 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4066 | { |
| 4067 | return false; |
| 4068 | } |
| 4069 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4070 | SetRobustLengthParam(length, numParams); |
| 4071 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4072 | return true; |
| 4073 | } |
| 4074 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4075 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4076 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4077 | GLenum pname, |
| 4078 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4079 | GLsizei *length, |
| 4080 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4081 | { |
| 4082 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4083 | { |
| 4084 | return false; |
| 4085 | } |
| 4086 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4087 | GLsizei numParams = 0; |
| 4088 | |
| 4089 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4090 | { |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4094 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4095 | { |
| 4096 | return false; |
| 4097 | } |
| 4098 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4099 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4100 | return true; |
| 4101 | } |
| 4102 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4103 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4104 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4105 | GLenum pname, |
| 4106 | GLsizei bufSize, |
| 4107 | GLsizei *length, |
| 4108 | GLint64 *params) |
| 4109 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4110 | GLsizei numParams = 0; |
| 4111 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4112 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4113 | { |
| 4114 | return false; |
| 4115 | } |
| 4116 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4117 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4118 | { |
| 4119 | return false; |
| 4120 | } |
| 4121 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4122 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4123 | { |
| 4124 | return false; |
| 4125 | } |
| 4126 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4127 | SetRobustLengthParam(length, numParams); |
| 4128 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4129 | return true; |
| 4130 | } |
| 4131 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4132 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4133 | { |
| 4134 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4135 | if (numParams) |
| 4136 | { |
| 4137 | *numParams = 1; |
| 4138 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4139 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4140 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4141 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4142 | ? GetValidProgramNoResolve(context, program) |
| 4143 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4144 | if (!programObject) |
| 4145 | { |
| 4146 | return false; |
| 4147 | } |
| 4148 | |
| 4149 | switch (pname) |
| 4150 | { |
| 4151 | case GL_DELETE_STATUS: |
| 4152 | case GL_LINK_STATUS: |
| 4153 | case GL_VALIDATE_STATUS: |
| 4154 | case GL_INFO_LOG_LENGTH: |
| 4155 | case GL_ATTACHED_SHADERS: |
| 4156 | case GL_ACTIVE_ATTRIBUTES: |
| 4157 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4158 | case GL_ACTIVE_UNIFORMS: |
| 4159 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4160 | break; |
| 4161 | |
| 4162 | case GL_PROGRAM_BINARY_LENGTH: |
| 4163 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4164 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4165 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4166 | return false; |
| 4167 | } |
| 4168 | break; |
| 4169 | |
| 4170 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4171 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4172 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4173 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4174 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4175 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4176 | if (context->getClientMajorVersion() < 3) |
| 4177 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4178 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4179 | return false; |
| 4180 | } |
| 4181 | break; |
| 4182 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4183 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4184 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4185 | if (context->getClientVersion() < Version(3, 1)) |
| 4186 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4187 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | break; |
| 4191 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4192 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4193 | if (context->getClientVersion() < Version(3, 1)) |
| 4194 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4195 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4196 | return false; |
| 4197 | } |
| 4198 | |
| 4199 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4200 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4201 | // program which has not been linked successfully, or which does not contain objects to |
| 4202 | // form a compute shader. |
| 4203 | if (!programObject->isLinked()) |
| 4204 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4205 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4206 | return false; |
| 4207 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4208 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4209 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4210 | context->validationError(GL_INVALID_OPERATION, kNoActiveComputeShaderStage); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | break; |
| 4214 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4215 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4216 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4217 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4218 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4219 | if (!context->getExtensions().geometryShader) |
| 4220 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4221 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4222 | return false; |
| 4223 | } |
| 4224 | |
| 4225 | // [EXT_geometry_shader] Chapter 7.12 |
| 4226 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4227 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4228 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4229 | // successfully, or which does not contain objects to form a geometry shader. |
| 4230 | if (!programObject->isLinked()) |
| 4231 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4232 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4233 | return false; |
| 4234 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4235 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4237 | context->validationError(GL_INVALID_OPERATION, kNoActiveGeometryShaderStage); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4238 | return false; |
| 4239 | } |
| 4240 | break; |
| 4241 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4242 | case GL_COMPLETION_STATUS_KHR: |
| 4243 | if (!context->getExtensions().parallelShaderCompile) |
| 4244 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4245 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4246 | return false; |
| 4247 | } |
| 4248 | break; |
| 4249 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4250 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4251 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4252 | return false; |
| 4253 | } |
| 4254 | |
| 4255 | return true; |
| 4256 | } |
| 4257 | |
| 4258 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4259 | GLuint program, |
| 4260 | GLenum pname, |
| 4261 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4262 | GLsizei *length, |
| 4263 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4264 | { |
| 4265 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4266 | { |
| 4267 | return false; |
| 4268 | } |
| 4269 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4270 | GLsizei numParams = 0; |
| 4271 | |
| 4272 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4273 | { |
| 4274 | return false; |
| 4275 | } |
| 4276 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4277 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4278 | { |
| 4279 | return false; |
| 4280 | } |
| 4281 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4282 | SetRobustLengthParam(length, numParams); |
| 4283 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4284 | return true; |
| 4285 | } |
| 4286 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4287 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4288 | GLenum target, |
| 4289 | GLenum pname, |
| 4290 | GLsizei bufSize, |
| 4291 | GLsizei *length, |
| 4292 | GLint *params) |
| 4293 | { |
| 4294 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4295 | { |
| 4296 | return false; |
| 4297 | } |
| 4298 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4299 | GLsizei numParams = 0; |
| 4300 | |
| 4301 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4302 | { |
| 4303 | return false; |
| 4304 | } |
| 4305 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4306 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4307 | { |
| 4308 | return false; |
| 4309 | } |
| 4310 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4311 | SetRobustLengthParam(length, numParams); |
| 4312 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4313 | return true; |
| 4314 | } |
| 4315 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4316 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4317 | GLuint shader, |
| 4318 | GLenum pname, |
| 4319 | GLsizei bufSize, |
| 4320 | GLsizei *length, |
| 4321 | GLint *params) |
| 4322 | { |
| 4323 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4324 | { |
| 4325 | return false; |
| 4326 | } |
| 4327 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4328 | GLsizei numParams = 0; |
| 4329 | |
| 4330 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4331 | { |
| 4332 | return false; |
| 4333 | } |
| 4334 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4335 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4336 | { |
| 4337 | return false; |
| 4338 | } |
| 4339 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4340 | SetRobustLengthParam(length, numParams); |
| 4341 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4342 | return true; |
| 4343 | } |
| 4344 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4345 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4346 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4347 | GLenum pname, |
| 4348 | GLsizei bufSize, |
| 4349 | GLsizei *length, |
| 4350 | GLfloat *params) |
| 4351 | { |
| 4352 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4353 | { |
| 4354 | return false; |
| 4355 | } |
| 4356 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4357 | GLsizei numParams = 0; |
| 4358 | |
| 4359 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4360 | { |
| 4361 | return false; |
| 4362 | } |
| 4363 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4364 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4365 | { |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4369 | SetRobustLengthParam(length, numParams); |
| 4370 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4371 | return true; |
| 4372 | } |
| 4373 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4374 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4375 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4376 | GLenum pname, |
| 4377 | GLsizei bufSize, |
| 4378 | GLsizei *length, |
| 4379 | GLint *params) |
| 4380 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4381 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4382 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4383 | { |
| 4384 | return false; |
| 4385 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4386 | GLsizei numParams = 0; |
| 4387 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4388 | { |
| 4389 | return false; |
| 4390 | } |
| 4391 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4392 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4393 | { |
| 4394 | return false; |
| 4395 | } |
| 4396 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4397 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4398 | return true; |
| 4399 | } |
| 4400 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4401 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4402 | TextureType target, |
| 4403 | GLenum pname, |
| 4404 | GLsizei bufSize, |
| 4405 | GLsizei *length, |
| 4406 | GLint *params) |
| 4407 | { |
| 4408 | UNIMPLEMENTED(); |
| 4409 | return false; |
| 4410 | } |
| 4411 | |
| 4412 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4413 | TextureType target, |
| 4414 | GLenum pname, |
| 4415 | GLsizei bufSize, |
| 4416 | GLsizei *length, |
| 4417 | GLuint *params) |
| 4418 | { |
| 4419 | UNIMPLEMENTED(); |
| 4420 | return false; |
| 4421 | } |
| 4422 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4423 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4424 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4425 | GLenum pname, |
| 4426 | GLsizei bufSize, |
| 4427 | const GLfloat *params) |
| 4428 | { |
| 4429 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4430 | { |
| 4431 | return false; |
| 4432 | } |
| 4433 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4434 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4435 | } |
| 4436 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4437 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4438 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4439 | GLenum pname, |
| 4440 | GLsizei bufSize, |
| 4441 | const GLint *params) |
| 4442 | { |
| 4443 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4444 | { |
| 4445 | return false; |
| 4446 | } |
| 4447 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4448 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4449 | } |
| 4450 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4451 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4452 | TextureType target, |
| 4453 | GLenum pname, |
| 4454 | GLsizei bufSize, |
| 4455 | const GLint *params) |
| 4456 | { |
| 4457 | UNIMPLEMENTED(); |
| 4458 | return false; |
| 4459 | } |
| 4460 | |
| 4461 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4462 | TextureType target, |
| 4463 | GLenum pname, |
| 4464 | GLsizei bufSize, |
| 4465 | const GLuint *params) |
| 4466 | { |
| 4467 | UNIMPLEMENTED(); |
| 4468 | return false; |
| 4469 | } |
| 4470 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4471 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4472 | GLuint sampler, |
| 4473 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4474 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4475 | GLsizei *length, |
| 4476 | GLfloat *params) |
| 4477 | { |
| 4478 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4479 | { |
| 4480 | return false; |
| 4481 | } |
| 4482 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4483 | GLsizei numParams = 0; |
| 4484 | |
| 4485 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4486 | { |
| 4487 | return false; |
| 4488 | } |
| 4489 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4490 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4491 | { |
| 4492 | return false; |
| 4493 | } |
| 4494 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4495 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4496 | return true; |
| 4497 | } |
| 4498 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4499 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4500 | GLuint sampler, |
| 4501 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4502 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4503 | GLsizei *length, |
| 4504 | GLint *params) |
| 4505 | { |
| 4506 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4507 | { |
| 4508 | return false; |
| 4509 | } |
| 4510 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4511 | GLsizei numParams = 0; |
| 4512 | |
| 4513 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4514 | { |
| 4515 | return false; |
| 4516 | } |
| 4517 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4518 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4519 | { |
| 4520 | return false; |
| 4521 | } |
| 4522 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4523 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4524 | return true; |
| 4525 | } |
| 4526 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4527 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4528 | GLuint sampler, |
| 4529 | GLenum pname, |
| 4530 | GLsizei bufSize, |
| 4531 | GLsizei *length, |
| 4532 | GLint *params) |
| 4533 | { |
| 4534 | UNIMPLEMENTED(); |
| 4535 | return false; |
| 4536 | } |
| 4537 | |
| 4538 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4539 | GLuint sampler, |
| 4540 | GLenum pname, |
| 4541 | GLsizei bufSize, |
| 4542 | GLsizei *length, |
| 4543 | GLuint *params) |
| 4544 | { |
| 4545 | UNIMPLEMENTED(); |
| 4546 | return false; |
| 4547 | } |
| 4548 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4549 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4550 | GLuint sampler, |
| 4551 | GLenum pname, |
| 4552 | GLsizei bufSize, |
| 4553 | const GLfloat *params) |
| 4554 | { |
| 4555 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4556 | { |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4560 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4561 | } |
| 4562 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4563 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4564 | GLuint sampler, |
| 4565 | GLenum pname, |
| 4566 | GLsizei bufSize, |
| 4567 | const GLint *params) |
| 4568 | { |
| 4569 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4570 | { |
| 4571 | return false; |
| 4572 | } |
| 4573 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4574 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4575 | } |
| 4576 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4577 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4578 | GLuint sampler, |
| 4579 | GLenum pname, |
| 4580 | GLsizei bufSize, |
| 4581 | const GLint *param) |
| 4582 | { |
| 4583 | UNIMPLEMENTED(); |
| 4584 | return false; |
| 4585 | } |
| 4586 | |
| 4587 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4588 | GLuint sampler, |
| 4589 | GLenum pname, |
| 4590 | GLsizei bufSize, |
| 4591 | const GLuint *param) |
| 4592 | { |
| 4593 | UNIMPLEMENTED(); |
| 4594 | return false; |
| 4595 | } |
| 4596 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4597 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4598 | GLuint index, |
| 4599 | GLenum pname, |
| 4600 | GLsizei bufSize, |
| 4601 | GLsizei *length, |
| 4602 | GLfloat *params) |
| 4603 | { |
| 4604 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4605 | { |
| 4606 | return false; |
| 4607 | } |
| 4608 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4609 | GLsizei writeLength = 0; |
| 4610 | |
| 4611 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4612 | { |
| 4613 | return false; |
| 4614 | } |
| 4615 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4616 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4617 | { |
| 4618 | return false; |
| 4619 | } |
| 4620 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4621 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4622 | return true; |
| 4623 | } |
| 4624 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4625 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4626 | GLuint index, |
| 4627 | GLenum pname, |
| 4628 | GLsizei bufSize, |
| 4629 | GLsizei *length, |
| 4630 | GLint *params) |
| 4631 | { |
| 4632 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4633 | { |
| 4634 | return false; |
| 4635 | } |
| 4636 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4637 | GLsizei writeLength = 0; |
| 4638 | |
| 4639 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4640 | { |
| 4641 | return false; |
| 4642 | } |
| 4643 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4644 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4645 | { |
| 4646 | return false; |
| 4647 | } |
| 4648 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4649 | SetRobustLengthParam(length, writeLength); |
| 4650 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4651 | return true; |
| 4652 | } |
| 4653 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4654 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4655 | GLuint index, |
| 4656 | GLenum pname, |
| 4657 | GLsizei bufSize, |
| 4658 | GLsizei *length, |
| 4659 | void **pointer) |
| 4660 | { |
| 4661 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4662 | { |
| 4663 | return false; |
| 4664 | } |
| 4665 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4666 | GLsizei writeLength = 0; |
| 4667 | |
| 4668 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4669 | { |
| 4670 | return false; |
| 4671 | } |
| 4672 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4673 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4674 | { |
| 4675 | return false; |
| 4676 | } |
| 4677 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4678 | SetRobustLengthParam(length, writeLength); |
| 4679 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4680 | return true; |
| 4681 | } |
| 4682 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4683 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4684 | GLuint index, |
| 4685 | GLenum pname, |
| 4686 | GLsizei bufSize, |
| 4687 | GLsizei *length, |
| 4688 | GLint *params) |
| 4689 | { |
| 4690 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4691 | { |
| 4692 | return false; |
| 4693 | } |
| 4694 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4695 | GLsizei writeLength = 0; |
| 4696 | |
| 4697 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4698 | { |
| 4699 | return false; |
| 4700 | } |
| 4701 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4702 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4703 | { |
| 4704 | return false; |
| 4705 | } |
| 4706 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4707 | SetRobustLengthParam(length, writeLength); |
| 4708 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4709 | return true; |
| 4710 | } |
| 4711 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4712 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4713 | GLuint index, |
| 4714 | GLenum pname, |
| 4715 | GLsizei bufSize, |
| 4716 | GLsizei *length, |
| 4717 | GLuint *params) |
| 4718 | { |
| 4719 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4720 | { |
| 4721 | return false; |
| 4722 | } |
| 4723 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4724 | GLsizei writeLength = 0; |
| 4725 | |
| 4726 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4727 | { |
| 4728 | return false; |
| 4729 | } |
| 4730 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4731 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4732 | { |
| 4733 | return false; |
| 4734 | } |
| 4735 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4736 | SetRobustLengthParam(length, writeLength); |
| 4737 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4738 | return true; |
| 4739 | } |
| 4740 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4741 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 4742 | GLuint program, |
| 4743 | GLuint uniformBlockIndex, |
| 4744 | GLenum pname, |
| 4745 | GLsizei bufSize, |
| 4746 | GLsizei *length, |
| 4747 | GLint *params) |
| 4748 | { |
| 4749 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4750 | { |
| 4751 | return false; |
| 4752 | } |
| 4753 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4754 | GLsizei writeLength = 0; |
| 4755 | |
| 4756 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 4757 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4758 | { |
| 4759 | return false; |
| 4760 | } |
| 4761 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4762 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4763 | { |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4767 | SetRobustLengthParam(length, writeLength); |
| 4768 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4769 | return true; |
| 4770 | } |
| 4771 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 4772 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4773 | GLenum target, |
| 4774 | GLenum internalformat, |
| 4775 | GLenum pname, |
| 4776 | GLsizei bufSize, |
| 4777 | GLsizei *length, |
| 4778 | GLint *params) |
| 4779 | { |
| 4780 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4781 | { |
| 4782 | return false; |
| 4783 | } |
| 4784 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4785 | GLsizei numParams = 0; |
| 4786 | |
| 4787 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 4788 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4789 | { |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4793 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4794 | { |
| 4795 | return false; |
| 4796 | } |
| 4797 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4798 | SetRobustLengthParam(length, numParams); |
| 4799 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4800 | return true; |
| 4801 | } |
| 4802 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4803 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4804 | GLuint attribIndex, |
| 4805 | GLint size, |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4806 | VertexAttribType type, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4807 | GLboolean pureInteger) |
| 4808 | { |
| 4809 | const Caps &caps = context->getCaps(); |
| 4810 | if (attribIndex >= caps.maxVertexAttributes) |
| 4811 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4812 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4813 | return false; |
| 4814 | } |
| 4815 | |
| 4816 | if (size < 1 || size > 4) |
| 4817 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4818 | context->validationError(GL_INVALID_VALUE, kInvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 4819 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4820 | } |
| 4821 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4822 | // This validation could be improved using a table and better encapsulation. |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4823 | switch (type) |
| 4824 | { |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4825 | case VertexAttribType::Byte: |
| 4826 | case VertexAttribType::UnsignedByte: |
| 4827 | case VertexAttribType::Short: |
| 4828 | case VertexAttribType::UnsignedShort: |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4829 | break; |
| 4830 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4831 | case VertexAttribType::Int: |
| 4832 | case VertexAttribType::UnsignedInt: |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4833 | if (context->getClientMajorVersion() < 3) |
| 4834 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4835 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4836 | return false; |
| 4837 | } |
| 4838 | break; |
| 4839 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4840 | case VertexAttribType::Fixed: |
| 4841 | case VertexAttribType::Float: |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4842 | if (pureInteger) |
| 4843 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4844 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4845 | return false; |
| 4846 | } |
| 4847 | break; |
| 4848 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4849 | case VertexAttribType::HalfFloat: |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4850 | if (context->getClientMajorVersion() < 3) |
| 4851 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4852 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4853 | return false; |
| 4854 | } |
| 4855 | if (pureInteger) |
| 4856 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4857 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4858 | return false; |
| 4859 | } |
| 4860 | break; |
| 4861 | |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame] | 4862 | case VertexAttribType::Int2101010: |
| 4863 | case VertexAttribType::UnsignedInt2101010: |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4864 | if (context->getClientMajorVersion() < 3) |
| 4865 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4866 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4867 | return false; |
| 4868 | } |
| 4869 | if (pureInteger) |
| 4870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4871 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4872 | return false; |
| 4873 | } |
| 4874 | if (size != 4) |
| 4875 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4876 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexAttribSize2101010); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4877 | return false; |
| 4878 | } |
| 4879 | break; |
| 4880 | |
| 4881 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4882 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4883 | return false; |
| 4884 | } |
| 4885 | |
| 4886 | return true; |
| 4887 | } |
| 4888 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4889 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 4890 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 4891 | // specified clear value and the type of a buffer that is being cleared generates an |
| 4892 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4893 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4894 | GLint drawbuffer, |
| 4895 | const GLenum *validComponentTypes, |
| 4896 | size_t validComponentTypeCount) |
| 4897 | { |
| 4898 | const FramebufferAttachment *attachment = |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4899 | context->getState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4900 | if (attachment) |
| 4901 | { |
| 4902 | GLenum componentType = attachment->getFormat().info->componentType; |
| 4903 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 4904 | if (std::find(validComponentTypes, end, componentType) == end) |
| 4905 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4906 | context->validationError(GL_INVALID_OPERATION, kNoDefinedClearConversion); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4907 | return false; |
| 4908 | } |
| 4909 | } |
| 4910 | |
| 4911 | return true; |
| 4912 | } |
| 4913 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4914 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4915 | { |
| 4916 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 4917 | { |
| 4918 | return false; |
| 4919 | } |
| 4920 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4921 | Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4922 | if (pixelUnpackBuffer == nullptr) |
| 4923 | { |
| 4924 | if (dataSize < imageSize) |
| 4925 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4926 | context->validationError(GL_INVALID_OPERATION, kCompressedDataSizeTooSmall); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4927 | } |
| 4928 | } |
| 4929 | return true; |
| 4930 | } |
| 4931 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4932 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4933 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4934 | GLenum pname, |
| 4935 | bool pointerVersion, |
| 4936 | GLsizei *numParams) |
| 4937 | { |
| 4938 | if (numParams) |
| 4939 | { |
| 4940 | *numParams = 0; |
| 4941 | } |
| 4942 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4943 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4944 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4945 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4946 | return false; |
| 4947 | } |
| 4948 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 4949 | const Buffer *buffer = context->getState().getTargetBuffer(target); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4950 | if (!buffer) |
| 4951 | { |
| 4952 | // 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] | 4953 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4954 | return false; |
| 4955 | } |
| 4956 | |
| 4957 | const Extensions &extensions = context->getExtensions(); |
| 4958 | |
| 4959 | switch (pname) |
| 4960 | { |
| 4961 | case GL_BUFFER_USAGE: |
| 4962 | case GL_BUFFER_SIZE: |
| 4963 | break; |
| 4964 | |
| 4965 | case GL_BUFFER_ACCESS_OES: |
| 4966 | if (!extensions.mapBuffer) |
| 4967 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4968 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4969 | return false; |
| 4970 | } |
| 4971 | break; |
| 4972 | |
| 4973 | case GL_BUFFER_MAPPED: |
| 4974 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 4975 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 4976 | !extensions.mapBufferRange) |
| 4977 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4978 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4979 | return false; |
| 4980 | } |
| 4981 | break; |
| 4982 | |
| 4983 | case GL_BUFFER_MAP_POINTER: |
| 4984 | if (!pointerVersion) |
| 4985 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4986 | context->validationError(GL_INVALID_ENUM, kInvalidMapPointerQuery); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4987 | return false; |
| 4988 | } |
| 4989 | break; |
| 4990 | |
| 4991 | case GL_BUFFER_ACCESS_FLAGS: |
| 4992 | case GL_BUFFER_MAP_OFFSET: |
| 4993 | case GL_BUFFER_MAP_LENGTH: |
| 4994 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 4995 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 4996 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4997 | return false; |
| 4998 | } |
| 4999 | break; |
| 5000 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5001 | case GL_MEMORY_SIZE_ANGLE: |
| 5002 | if (!context->getExtensions().memorySize) |
| 5003 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5004 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5005 | return false; |
| 5006 | } |
| 5007 | break; |
| 5008 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5009 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5010 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5011 | return false; |
| 5012 | } |
| 5013 | |
| 5014 | // All buffer parameter queries return one value. |
| 5015 | if (numParams) |
| 5016 | { |
| 5017 | *numParams = 1; |
| 5018 | } |
| 5019 | |
| 5020 | return true; |
| 5021 | } |
| 5022 | |
| 5023 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5024 | GLenum target, |
| 5025 | GLenum pname, |
| 5026 | GLsizei *length) |
| 5027 | { |
| 5028 | if (length) |
| 5029 | { |
| 5030 | *length = 0; |
| 5031 | } |
| 5032 | |
| 5033 | if (target != GL_RENDERBUFFER) |
| 5034 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5035 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5036 | return false; |
| 5037 | } |
| 5038 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5039 | Renderbuffer *renderbuffer = context->getState().getCurrentRenderbuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5040 | if (renderbuffer == nullptr) |
| 5041 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5042 | context->validationError(GL_INVALID_OPERATION, kRenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5043 | return false; |
| 5044 | } |
| 5045 | |
| 5046 | switch (pname) |
| 5047 | { |
| 5048 | case GL_RENDERBUFFER_WIDTH: |
| 5049 | case GL_RENDERBUFFER_HEIGHT: |
| 5050 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5051 | case GL_RENDERBUFFER_RED_SIZE: |
| 5052 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5053 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5054 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5055 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5056 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5057 | break; |
| 5058 | |
| 5059 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5060 | if (!context->getExtensions().framebufferMultisample) |
| 5061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5062 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5063 | return false; |
| 5064 | } |
| 5065 | break; |
| 5066 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5067 | case GL_MEMORY_SIZE_ANGLE: |
| 5068 | if (!context->getExtensions().memorySize) |
| 5069 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5070 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5071 | return false; |
| 5072 | } |
| 5073 | break; |
| 5074 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5075 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5076 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5077 | return false; |
| 5078 | } |
| 5079 | |
| 5080 | if (length) |
| 5081 | { |
| 5082 | *length = 1; |
| 5083 | } |
| 5084 | return true; |
| 5085 | } |
| 5086 | |
| 5087 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5088 | { |
| 5089 | if (length) |
| 5090 | { |
| 5091 | *length = 0; |
| 5092 | } |
| 5093 | |
| 5094 | if (GetValidShader(context, shader) == nullptr) |
| 5095 | { |
| 5096 | return false; |
| 5097 | } |
| 5098 | |
| 5099 | switch (pname) |
| 5100 | { |
| 5101 | case GL_SHADER_TYPE: |
| 5102 | case GL_DELETE_STATUS: |
| 5103 | case GL_COMPILE_STATUS: |
| 5104 | case GL_INFO_LOG_LENGTH: |
| 5105 | case GL_SHADER_SOURCE_LENGTH: |
| 5106 | break; |
| 5107 | |
| 5108 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5109 | if (!context->getExtensions().translatedShaderSource) |
| 5110 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5111 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5112 | return false; |
| 5113 | } |
| 5114 | break; |
| 5115 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5116 | case GL_COMPLETION_STATUS_KHR: |
| 5117 | if (!context->getExtensions().parallelShaderCompile) |
| 5118 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5119 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5120 | return false; |
| 5121 | } |
| 5122 | break; |
| 5123 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5124 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5125 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5126 | return false; |
| 5127 | } |
| 5128 | |
| 5129 | if (length) |
| 5130 | { |
| 5131 | *length = 1; |
| 5132 | } |
| 5133 | return true; |
| 5134 | } |
| 5135 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5136 | bool ValidateGetTexParameterBase(Context *context, |
| 5137 | TextureType target, |
| 5138 | GLenum pname, |
| 5139 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5140 | { |
| 5141 | if (length) |
| 5142 | { |
| 5143 | *length = 0; |
| 5144 | } |
| 5145 | |
| 5146 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5147 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5148 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5149 | return false; |
| 5150 | } |
| 5151 | |
| 5152 | if (context->getTargetTexture(target) == nullptr) |
| 5153 | { |
| 5154 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5155 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5156 | return false; |
| 5157 | } |
| 5158 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5159 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5160 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5161 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5162 | return false; |
| 5163 | } |
| 5164 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5165 | switch (pname) |
| 5166 | { |
| 5167 | case GL_TEXTURE_MAG_FILTER: |
| 5168 | case GL_TEXTURE_MIN_FILTER: |
| 5169 | case GL_TEXTURE_WRAP_S: |
| 5170 | case GL_TEXTURE_WRAP_T: |
| 5171 | break; |
| 5172 | |
| 5173 | case GL_TEXTURE_USAGE_ANGLE: |
| 5174 | if (!context->getExtensions().textureUsage) |
| 5175 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5176 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | break; |
| 5180 | |
| 5181 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5182 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5183 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5184 | return false; |
| 5185 | } |
| 5186 | break; |
| 5187 | |
| 5188 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5189 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5190 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5191 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5192 | return false; |
| 5193 | } |
| 5194 | break; |
| 5195 | |
| 5196 | case GL_TEXTURE_WRAP_R: |
| 5197 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5198 | case GL_TEXTURE_SWIZZLE_R: |
| 5199 | case GL_TEXTURE_SWIZZLE_G: |
| 5200 | case GL_TEXTURE_SWIZZLE_B: |
| 5201 | case GL_TEXTURE_SWIZZLE_A: |
| 5202 | case GL_TEXTURE_BASE_LEVEL: |
| 5203 | case GL_TEXTURE_MAX_LEVEL: |
| 5204 | case GL_TEXTURE_MIN_LOD: |
| 5205 | case GL_TEXTURE_MAX_LOD: |
| 5206 | case GL_TEXTURE_COMPARE_MODE: |
| 5207 | case GL_TEXTURE_COMPARE_FUNC: |
| 5208 | if (context->getClientMajorVersion() < 3) |
| 5209 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5210 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES30); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5211 | return false; |
| 5212 | } |
| 5213 | break; |
| 5214 | |
| 5215 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5216 | if (!context->getExtensions().textureSRGBDecode) |
| 5217 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5218 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5219 | return false; |
| 5220 | } |
| 5221 | break; |
| 5222 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5223 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5224 | if (context->getClientVersion() < Version(3, 1)) |
| 5225 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5226 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5227 | return false; |
| 5228 | } |
| 5229 | break; |
| 5230 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5231 | case GL_GENERATE_MIPMAP: |
| 5232 | case GL_TEXTURE_CROP_RECT_OES: |
| 5233 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5234 | // after GL_OES_draw_texture functionality implemented |
| 5235 | if (context->getClientMajorVersion() > 1) |
| 5236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5237 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5238 | return false; |
| 5239 | } |
| 5240 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5241 | |
| 5242 | case GL_MEMORY_SIZE_ANGLE: |
| 5243 | if (!context->getExtensions().memorySize) |
| 5244 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5245 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5246 | return false; |
| 5247 | } |
| 5248 | break; |
| 5249 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5250 | case GL_TEXTURE_BORDER_COLOR: |
| 5251 | if (!context->getExtensions().textureBorderClamp) |
| 5252 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5253 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5254 | return false; |
| 5255 | } |
| 5256 | break; |
| 5257 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5258 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5259 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5260 | return false; |
| 5261 | } |
| 5262 | |
| 5263 | if (length) |
| 5264 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5265 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5266 | } |
| 5267 | return true; |
| 5268 | } |
| 5269 | |
| 5270 | bool ValidateGetVertexAttribBase(Context *context, |
| 5271 | GLuint index, |
| 5272 | GLenum pname, |
| 5273 | GLsizei *length, |
| 5274 | bool pointer, |
| 5275 | bool pureIntegerEntryPoint) |
| 5276 | { |
| 5277 | if (length) |
| 5278 | { |
| 5279 | *length = 0; |
| 5280 | } |
| 5281 | |
| 5282 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5283 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5284 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5285 | return false; |
| 5286 | } |
| 5287 | |
| 5288 | if (index >= context->getCaps().maxVertexAttributes) |
| 5289 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5290 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5291 | return false; |
| 5292 | } |
| 5293 | |
| 5294 | if (pointer) |
| 5295 | { |
| 5296 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5297 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5298 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5299 | return false; |
| 5300 | } |
| 5301 | } |
| 5302 | else |
| 5303 | { |
| 5304 | switch (pname) |
| 5305 | { |
| 5306 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5307 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5308 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5309 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5310 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5311 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5312 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5313 | break; |
| 5314 | |
| 5315 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5316 | static_assert( |
| 5317 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5318 | "ANGLE extension enums not equal to GL enums."); |
| 5319 | if (context->getClientMajorVersion() < 3 && |
| 5320 | !context->getExtensions().instancedArrays) |
| 5321 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5322 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5323 | return false; |
| 5324 | } |
| 5325 | break; |
| 5326 | |
| 5327 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5328 | if (context->getClientMajorVersion() < 3) |
| 5329 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5330 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5331 | return false; |
| 5332 | } |
| 5333 | break; |
| 5334 | |
| 5335 | case GL_VERTEX_ATTRIB_BINDING: |
| 5336 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5337 | if (context->getClientVersion() < ES_3_1) |
| 5338 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5339 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5340 | return false; |
| 5341 | } |
| 5342 | break; |
| 5343 | |
| 5344 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5345 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5346 | return false; |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | if (length) |
| 5351 | { |
| 5352 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5353 | { |
| 5354 | *length = 4; |
| 5355 | } |
| 5356 | else |
| 5357 | { |
| 5358 | *length = 1; |
| 5359 | } |
| 5360 | } |
| 5361 | |
| 5362 | return true; |
| 5363 | } |
| 5364 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5365 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5366 | GLint x, |
| 5367 | GLint y, |
| 5368 | GLsizei width, |
| 5369 | GLsizei height, |
| 5370 | GLenum format, |
| 5371 | GLenum type, |
| 5372 | GLsizei bufSize, |
| 5373 | GLsizei *length, |
| 5374 | GLsizei *columns, |
| 5375 | GLsizei *rows, |
| 5376 | void *pixels) |
| 5377 | { |
| 5378 | if (length != nullptr) |
| 5379 | { |
| 5380 | *length = 0; |
| 5381 | } |
| 5382 | if (rows != nullptr) |
| 5383 | { |
| 5384 | *rows = 0; |
| 5385 | } |
| 5386 | if (columns != nullptr) |
| 5387 | { |
| 5388 | *columns = 0; |
| 5389 | } |
| 5390 | |
| 5391 | if (width < 0 || height < 0) |
| 5392 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5393 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5394 | return false; |
| 5395 | } |
| 5396 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5397 | Framebuffer *readFramebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5398 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5399 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5400 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5401 | return false; |
| 5402 | } |
| 5403 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5404 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5405 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5406 | return false; |
| 5407 | } |
| 5408 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5409 | Framebuffer *framebuffer = context->getState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5410 | ASSERT(framebuffer); |
| 5411 | |
| 5412 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5413 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5414 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5415 | return false; |
| 5416 | } |
| 5417 | |
| 5418 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5419 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5420 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5421 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5422 | // situation is an application error that would lead to a crash in ANGLE. |
| 5423 | if (readBuffer == nullptr) |
| 5424 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5425 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5426 | return false; |
| 5427 | } |
| 5428 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5429 | // ANGLE_multiview, Revision 1: |
| 5430 | // 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] | 5431 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5432 | // in the current read framebuffer is more than one. |
| 5433 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5434 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5435 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kMultiviewReadFramebuffer); |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5436 | return false; |
| 5437 | } |
| 5438 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5439 | if (context->getExtensions().webglCompatibility) |
| 5440 | { |
| 5441 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5442 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5443 | // and type before validating the combination of format and type. However, the |
| 5444 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5445 | // verifies that GL_INVALID_OPERATION is generated. |
| 5446 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5447 | // dEQP/WebGL. |
| 5448 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5449 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5450 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5451 | return false; |
| 5452 | } |
| 5453 | |
| 5454 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5455 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5456 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5457 | return false; |
| 5458 | } |
| 5459 | } |
| 5460 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5461 | GLenum currentFormat = GL_NONE; |
| 5462 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5463 | |
| 5464 | GLenum currentType = GL_NONE; |
| 5465 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5466 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5467 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5468 | |
| 5469 | bool validFormatTypeCombination = |
| 5470 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5471 | |
| 5472 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5473 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5474 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5475 | return false; |
| 5476 | } |
| 5477 | |
| 5478 | // Check for pixel pack buffer related API errors |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5479 | Buffer *pixelPackBuffer = context->getState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5480 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5481 | { |
| 5482 | // ...the buffer object's data store is currently mapped. |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5483 | context->validationError(GL_INVALID_OPERATION, kBufferMapped); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5484 | return false; |
| 5485 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5486 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5487 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5488 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5489 | context->validationError(GL_INVALID_OPERATION, kPixelPackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5490 | return false; |
| 5491 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5492 | |
| 5493 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5494 | // would exceed the data store size. |
| 5495 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5496 | const Extents size(width, height, 1); |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 5497 | const auto &pack = context->getState().getPackState(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5498 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5499 | GLuint endByte = 0; |
| 5500 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5501 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5502 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5503 | return false; |
| 5504 | } |
| 5505 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5506 | if (bufSize >= 0) |
| 5507 | { |
| 5508 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5509 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5510 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5511 | return false; |
| 5512 | } |
| 5513 | } |
| 5514 | |
| 5515 | if (pixelPackBuffer != nullptr) |
| 5516 | { |
| 5517 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5518 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5519 | checkedEndByte += checkedOffset; |
| 5520 | |
| 5521 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5522 | { |
| 5523 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5524 | context->validationError(GL_INVALID_OPERATION, kParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5525 | return false; |
| 5526 | } |
| 5527 | } |
| 5528 | |
| 5529 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5530 | { |
| 5531 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5532 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5533 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5534 | return false; |
| 5535 | } |
| 5536 | |
| 5537 | *length = static_cast<GLsizei>(endByte); |
| 5538 | } |
| 5539 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5540 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5541 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5542 | if (start < 0) |
| 5543 | { |
| 5544 | // "subtract" the area that is less than 0 |
| 5545 | clippedExtent += start; |
| 5546 | } |
| 5547 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5548 | angle::CheckedNumeric<int> readExtent = start; |
| 5549 | readExtent += length; |
| 5550 | if (!readExtent.IsValid()) |
| 5551 | { |
| 5552 | return false; |
| 5553 | } |
| 5554 | |
| 5555 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5556 | { |
| 5557 | // Subtract the region to the right of the read buffer |
| 5558 | clippedExtent -= (readExtent - bufferSize); |
| 5559 | } |
| 5560 | |
| 5561 | if (!clippedExtent.IsValid()) |
| 5562 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5563 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5564 | } |
| 5565 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5566 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5567 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5568 | }; |
| 5569 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5570 | GLsizei writtenColumns = 0; |
| 5571 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5572 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5573 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5574 | return false; |
| 5575 | } |
| 5576 | |
| 5577 | GLsizei writtenRows = 0; |
| 5578 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5579 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5580 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5581 | return false; |
| 5582 | } |
| 5583 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5584 | if (columns != nullptr) |
| 5585 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5586 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5587 | } |
| 5588 | |
| 5589 | if (rows != nullptr) |
| 5590 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5591 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5592 | } |
| 5593 | |
| 5594 | return true; |
| 5595 | } |
| 5596 | |
| 5597 | template <typename ParamType> |
| 5598 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5599 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5600 | GLenum pname, |
| 5601 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5602 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5603 | const ParamType *params) |
| 5604 | { |
| 5605 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5606 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5607 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5608 | return false; |
| 5609 | } |
| 5610 | |
| 5611 | if (context->getTargetTexture(target) == nullptr) |
| 5612 | { |
| 5613 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5614 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5615 | return false; |
| 5616 | } |
| 5617 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5618 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5619 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5620 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5621 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5622 | return false; |
| 5623 | } |
| 5624 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5625 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5626 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5627 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5628 | return false; |
| 5629 | } |
| 5630 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5631 | switch (pname) |
| 5632 | { |
| 5633 | case GL_TEXTURE_WRAP_R: |
| 5634 | case GL_TEXTURE_SWIZZLE_R: |
| 5635 | case GL_TEXTURE_SWIZZLE_G: |
| 5636 | case GL_TEXTURE_SWIZZLE_B: |
| 5637 | case GL_TEXTURE_SWIZZLE_A: |
| 5638 | case GL_TEXTURE_BASE_LEVEL: |
| 5639 | case GL_TEXTURE_MAX_LEVEL: |
| 5640 | case GL_TEXTURE_COMPARE_MODE: |
| 5641 | case GL_TEXTURE_COMPARE_FUNC: |
| 5642 | case GL_TEXTURE_MIN_LOD: |
| 5643 | case GL_TEXTURE_MAX_LOD: |
| 5644 | if (context->getClientMajorVersion() < 3) |
| 5645 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5646 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5647 | return false; |
| 5648 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5649 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5650 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5651 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5652 | return false; |
| 5653 | } |
| 5654 | break; |
| 5655 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5656 | case GL_GENERATE_MIPMAP: |
| 5657 | case GL_TEXTURE_CROP_RECT_OES: |
| 5658 | if (context->getClientMajorVersion() > 1) |
| 5659 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5660 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5661 | return false; |
| 5662 | } |
| 5663 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5664 | default: |
| 5665 | break; |
| 5666 | } |
| 5667 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5668 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5669 | { |
| 5670 | switch (pname) |
| 5671 | { |
| 5672 | case GL_TEXTURE_MIN_FILTER: |
| 5673 | case GL_TEXTURE_MAG_FILTER: |
| 5674 | case GL_TEXTURE_WRAP_S: |
| 5675 | case GL_TEXTURE_WRAP_T: |
| 5676 | case GL_TEXTURE_WRAP_R: |
| 5677 | case GL_TEXTURE_MIN_LOD: |
| 5678 | case GL_TEXTURE_MAX_LOD: |
| 5679 | case GL_TEXTURE_COMPARE_MODE: |
| 5680 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5681 | case GL_TEXTURE_BORDER_COLOR: |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5682 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5683 | return false; |
| 5684 | } |
| 5685 | } |
| 5686 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5687 | switch (pname) |
| 5688 | { |
| 5689 | case GL_TEXTURE_WRAP_S: |
| 5690 | case GL_TEXTURE_WRAP_T: |
| 5691 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5692 | { |
| 5693 | bool restrictedWrapModes = |
| 5694 | target == TextureType::External || target == TextureType::Rectangle; |
| 5695 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5696 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5697 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5698 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5699 | } |
| 5700 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5701 | |
| 5702 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5703 | { |
| 5704 | bool restrictedMinFilter = |
| 5705 | target == TextureType::External || target == TextureType::Rectangle; |
| 5706 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5707 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5708 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5709 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5710 | } |
| 5711 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5712 | |
| 5713 | case GL_TEXTURE_MAG_FILTER: |
| 5714 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5715 | { |
| 5716 | return false; |
| 5717 | } |
| 5718 | break; |
| 5719 | |
| 5720 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5721 | if (!context->getExtensions().textureUsage) |
| 5722 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5723 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5724 | return false; |
| 5725 | } |
| 5726 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5727 | switch (ConvertToGLenum(params[0])) |
| 5728 | { |
| 5729 | case GL_NONE: |
| 5730 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5731 | break; |
| 5732 | |
| 5733 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5734 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5735 | return false; |
| 5736 | } |
| 5737 | break; |
| 5738 | |
| 5739 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5740 | { |
| 5741 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5742 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5743 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5744 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5745 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5746 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 5747 | } |
| 5748 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5749 | |
| 5750 | case GL_TEXTURE_MIN_LOD: |
| 5751 | case GL_TEXTURE_MAX_LOD: |
| 5752 | // any value is permissible |
| 5753 | break; |
| 5754 | |
| 5755 | case GL_TEXTURE_COMPARE_MODE: |
| 5756 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5757 | { |
| 5758 | return false; |
| 5759 | } |
| 5760 | break; |
| 5761 | |
| 5762 | case GL_TEXTURE_COMPARE_FUNC: |
| 5763 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5764 | { |
| 5765 | return false; |
| 5766 | } |
| 5767 | break; |
| 5768 | |
| 5769 | case GL_TEXTURE_SWIZZLE_R: |
| 5770 | case GL_TEXTURE_SWIZZLE_G: |
| 5771 | case GL_TEXTURE_SWIZZLE_B: |
| 5772 | case GL_TEXTURE_SWIZZLE_A: |
| 5773 | switch (ConvertToGLenum(params[0])) |
| 5774 | { |
| 5775 | case GL_RED: |
| 5776 | case GL_GREEN: |
| 5777 | case GL_BLUE: |
| 5778 | case GL_ALPHA: |
| 5779 | case GL_ZERO: |
| 5780 | case GL_ONE: |
| 5781 | break; |
| 5782 | |
| 5783 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5784 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5785 | return false; |
| 5786 | } |
| 5787 | break; |
| 5788 | |
| 5789 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5790 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5791 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5792 | context->validationError(GL_INVALID_VALUE, kBaseLevelNegative); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5793 | return false; |
| 5794 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5795 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5796 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5797 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5798 | return false; |
| 5799 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5800 | if ((target == TextureType::_2DMultisample || |
| 5801 | target == TextureType::_2DMultisampleArray) && |
| 5802 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5803 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5804 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5805 | return false; |
| 5806 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5807 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5808 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5809 | context->validationError(GL_INVALID_OPERATION, kBaseLevelNonZero); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5810 | return false; |
| 5811 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5812 | break; |
| 5813 | |
| 5814 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5815 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5816 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5817 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5818 | return false; |
| 5819 | } |
| 5820 | break; |
| 5821 | |
| 5822 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5823 | if (context->getClientVersion() < Version(3, 1)) |
| 5824 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5825 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5826 | return false; |
| 5827 | } |
| 5828 | switch (ConvertToGLenum(params[0])) |
| 5829 | { |
| 5830 | case GL_DEPTH_COMPONENT: |
| 5831 | case GL_STENCIL_INDEX: |
| 5832 | break; |
| 5833 | |
| 5834 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5835 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5836 | return false; |
| 5837 | } |
| 5838 | break; |
| 5839 | |
| 5840 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5841 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 5842 | { |
| 5843 | return false; |
| 5844 | } |
| 5845 | break; |
| 5846 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5847 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5848 | if (context->getClientMajorVersion() > 1) |
| 5849 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5850 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5851 | return false; |
| 5852 | } |
| 5853 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5854 | |
| 5855 | case GL_TEXTURE_CROP_RECT_OES: |
| 5856 | if (context->getClientMajorVersion() > 1) |
| 5857 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5858 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5859 | return false; |
| 5860 | } |
| 5861 | if (!vectorParams) |
| 5862 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5863 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5864 | return false; |
| 5865 | } |
| 5866 | break; |
| 5867 | |
| 5868 | case GL_TEXTURE_BORDER_COLOR: |
| 5869 | if (!context->getExtensions().textureBorderClamp) |
| 5870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5871 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5872 | return false; |
| 5873 | } |
| 5874 | if (!vectorParams) |
| 5875 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5876 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5877 | return false; |
| 5878 | } |
| 5879 | break; |
| 5880 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5881 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5882 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5883 | return false; |
| 5884 | } |
| 5885 | |
| 5886 | return true; |
| 5887 | } |
| 5888 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5889 | template bool ValidateTexParameterBase(Context *, |
| 5890 | TextureType, |
| 5891 | GLenum, |
| 5892 | GLsizei, |
| 5893 | bool, |
| 5894 | const GLfloat *); |
| 5895 | template bool ValidateTexParameterBase(Context *, |
| 5896 | TextureType, |
| 5897 | GLenum, |
| 5898 | GLsizei, |
| 5899 | bool, |
| 5900 | const GLint *); |
| 5901 | template bool ValidateTexParameterBase(Context *, |
| 5902 | TextureType, |
| 5903 | GLenum, |
| 5904 | GLsizei, |
| 5905 | bool, |
| 5906 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5907 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5908 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5909 | { |
| 5910 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5911 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5912 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5913 | return false; |
| 5914 | } |
| 5915 | |
| 5916 | return true; |
| 5917 | } |
| 5918 | |
| 5919 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 5920 | GLuint program, |
| 5921 | GLuint uniformBlockIndex, |
| 5922 | GLenum pname, |
| 5923 | GLsizei *length) |
| 5924 | { |
| 5925 | if (length) |
| 5926 | { |
| 5927 | *length = 0; |
| 5928 | } |
| 5929 | |
| 5930 | if (context->getClientMajorVersion() < 3) |
| 5931 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5932 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | |
| 5936 | Program *programObject = GetValidProgram(context, program); |
| 5937 | if (!programObject) |
| 5938 | { |
| 5939 | return false; |
| 5940 | } |
| 5941 | |
| 5942 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 5943 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 5944 | context->validationError(GL_INVALID_VALUE, kIndexExceedsActiveUniformBlockCount); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5945 | return false; |
| 5946 | } |
| 5947 | |
| 5948 | switch (pname) |
| 5949 | { |
| 5950 | case GL_UNIFORM_BLOCK_BINDING: |
| 5951 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 5952 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 5953 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 5954 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 5955 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 5956 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 5957 | break; |
| 5958 | |
| 5959 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5960 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5961 | return false; |
| 5962 | } |
| 5963 | |
| 5964 | if (length) |
| 5965 | { |
| 5966 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 5967 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 5968 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5969 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 5970 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 5971 | } |
| 5972 | else |
| 5973 | { |
| 5974 | *length = 1; |
| 5975 | } |
| 5976 | } |
| 5977 | |
| 5978 | return true; |
| 5979 | } |
| 5980 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5981 | template <typename ParamType> |
| 5982 | bool ValidateSamplerParameterBase(Context *context, |
| 5983 | GLuint sampler, |
| 5984 | GLenum pname, |
| 5985 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5986 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5987 | ParamType *params) |
| 5988 | { |
| 5989 | if (context->getClientMajorVersion() < 3) |
| 5990 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5991 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5992 | return false; |
| 5993 | } |
| 5994 | |
| 5995 | if (!context->isSampler(sampler)) |
| 5996 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5997 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5998 | return false; |
| 5999 | } |
| 6000 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6001 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6002 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6003 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6004 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6005 | return false; |
| 6006 | } |
| 6007 | |
| 6008 | switch (pname) |
| 6009 | { |
| 6010 | case GL_TEXTURE_WRAP_S: |
| 6011 | case GL_TEXTURE_WRAP_T: |
| 6012 | case GL_TEXTURE_WRAP_R: |
| 6013 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6014 | { |
| 6015 | return false; |
| 6016 | } |
| 6017 | break; |
| 6018 | |
| 6019 | case GL_TEXTURE_MIN_FILTER: |
| 6020 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6021 | { |
| 6022 | return false; |
| 6023 | } |
| 6024 | break; |
| 6025 | |
| 6026 | case GL_TEXTURE_MAG_FILTER: |
| 6027 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6028 | { |
| 6029 | return false; |
| 6030 | } |
| 6031 | break; |
| 6032 | |
| 6033 | case GL_TEXTURE_MIN_LOD: |
| 6034 | case GL_TEXTURE_MAX_LOD: |
| 6035 | // any value is permissible |
| 6036 | break; |
| 6037 | |
| 6038 | case GL_TEXTURE_COMPARE_MODE: |
| 6039 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6040 | { |
| 6041 | return false; |
| 6042 | } |
| 6043 | break; |
| 6044 | |
| 6045 | case GL_TEXTURE_COMPARE_FUNC: |
| 6046 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6047 | { |
| 6048 | return false; |
| 6049 | } |
| 6050 | break; |
| 6051 | |
| 6052 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6053 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6054 | { |
| 6055 | return false; |
| 6056 | } |
| 6057 | break; |
| 6058 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6059 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6060 | { |
| 6061 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6062 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6063 | { |
| 6064 | return false; |
| 6065 | } |
| 6066 | } |
| 6067 | break; |
| 6068 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6069 | case GL_TEXTURE_BORDER_COLOR: |
| 6070 | if (!context->getExtensions().textureBorderClamp) |
| 6071 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6072 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6073 | return false; |
| 6074 | } |
| 6075 | if (!vectorParams) |
| 6076 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6077 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6078 | return false; |
| 6079 | } |
| 6080 | break; |
| 6081 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6082 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6083 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6084 | return false; |
| 6085 | } |
| 6086 | |
| 6087 | return true; |
| 6088 | } |
| 6089 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6090 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6091 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6092 | template bool ValidateSamplerParameterBase(Context *, |
| 6093 | GLuint, |
| 6094 | GLenum, |
| 6095 | GLsizei, |
| 6096 | bool, |
| 6097 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6098 | |
| 6099 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6100 | GLuint sampler, |
| 6101 | GLenum pname, |
| 6102 | GLsizei *length) |
| 6103 | { |
| 6104 | if (length) |
| 6105 | { |
| 6106 | *length = 0; |
| 6107 | } |
| 6108 | |
| 6109 | if (context->getClientMajorVersion() < 3) |
| 6110 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6111 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6112 | return false; |
| 6113 | } |
| 6114 | |
| 6115 | if (!context->isSampler(sampler)) |
| 6116 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6117 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6118 | return false; |
| 6119 | } |
| 6120 | |
| 6121 | switch (pname) |
| 6122 | { |
| 6123 | case GL_TEXTURE_WRAP_S: |
| 6124 | case GL_TEXTURE_WRAP_T: |
| 6125 | case GL_TEXTURE_WRAP_R: |
| 6126 | case GL_TEXTURE_MIN_FILTER: |
| 6127 | case GL_TEXTURE_MAG_FILTER: |
| 6128 | case GL_TEXTURE_MIN_LOD: |
| 6129 | case GL_TEXTURE_MAX_LOD: |
| 6130 | case GL_TEXTURE_COMPARE_MODE: |
| 6131 | case GL_TEXTURE_COMPARE_FUNC: |
| 6132 | break; |
| 6133 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6134 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6135 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6136 | { |
| 6137 | return false; |
| 6138 | } |
| 6139 | break; |
| 6140 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6141 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6142 | if (!context->getExtensions().textureSRGBDecode) |
| 6143 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6144 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6145 | return false; |
| 6146 | } |
| 6147 | break; |
| 6148 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6149 | case GL_TEXTURE_BORDER_COLOR: |
| 6150 | if (!context->getExtensions().textureBorderClamp) |
| 6151 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6152 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6153 | return false; |
| 6154 | } |
| 6155 | break; |
| 6156 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6157 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6158 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6159 | return false; |
| 6160 | } |
| 6161 | |
| 6162 | if (length) |
| 6163 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6164 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6165 | } |
| 6166 | return true; |
| 6167 | } |
| 6168 | |
| 6169 | bool ValidateGetInternalFormativBase(Context *context, |
| 6170 | GLenum target, |
| 6171 | GLenum internalformat, |
| 6172 | GLenum pname, |
| 6173 | GLsizei bufSize, |
| 6174 | GLsizei *numParams) |
| 6175 | { |
| 6176 | if (numParams) |
| 6177 | { |
| 6178 | *numParams = 0; |
| 6179 | } |
| 6180 | |
| 6181 | if (context->getClientMajorVersion() < 3) |
| 6182 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6183 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6184 | return false; |
| 6185 | } |
| 6186 | |
| 6187 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6188 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6189 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6190 | context->validationError(GL_INVALID_ENUM, kFormatNotRenderable); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6191 | return false; |
| 6192 | } |
| 6193 | |
| 6194 | switch (target) |
| 6195 | { |
| 6196 | case GL_RENDERBUFFER: |
| 6197 | break; |
| 6198 | |
| 6199 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6200 | if (context->getClientVersion() < ES_3_1 && |
| 6201 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6202 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6203 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6204 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6205 | return false; |
| 6206 | } |
| 6207 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6208 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6209 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6210 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6211 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6212 | return false; |
| 6213 | } |
| 6214 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6215 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6216 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6217 | return false; |
| 6218 | } |
| 6219 | |
| 6220 | if (bufSize < 0) |
| 6221 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6222 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6223 | return false; |
| 6224 | } |
| 6225 | |
| 6226 | GLsizei maxWriteParams = 0; |
| 6227 | switch (pname) |
| 6228 | { |
| 6229 | case GL_NUM_SAMPLE_COUNTS: |
| 6230 | maxWriteParams = 1; |
| 6231 | break; |
| 6232 | |
| 6233 | case GL_SAMPLES: |
| 6234 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6235 | break; |
| 6236 | |
| 6237 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6238 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6239 | return false; |
| 6240 | } |
| 6241 | |
| 6242 | if (numParams) |
| 6243 | { |
| 6244 | // glGetInternalFormativ will not overflow bufSize |
| 6245 | *numParams = std::min(bufSize, maxWriteParams); |
| 6246 | } |
| 6247 | |
| 6248 | return true; |
| 6249 | } |
| 6250 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6251 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6252 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6253 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6254 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6255 | context->validationError(GL_INVALID_OPERATION, kInvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6256 | return false; |
| 6257 | } |
| 6258 | return true; |
| 6259 | } |
| 6260 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6261 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6262 | { |
| 6263 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6264 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6265 | context->validationError(GL_INVALID_ENUM, kInvalidMultitextureUnit); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6266 | return false; |
| 6267 | } |
| 6268 | return true; |
| 6269 | } |
| 6270 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6271 | bool ValidateTexStorageMultisample(Context *context, |
| 6272 | TextureType target, |
| 6273 | GLsizei samples, |
| 6274 | GLint internalFormat, |
| 6275 | GLsizei width, |
| 6276 | GLsizei height) |
| 6277 | { |
| 6278 | const Caps &caps = context->getCaps(); |
| 6279 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6280 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6281 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6282 | context->validationError(GL_INVALID_VALUE, kTextureWidthOrHeightOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6283 | return false; |
| 6284 | } |
| 6285 | |
| 6286 | if (samples == 0) |
| 6287 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6288 | context->validationError(GL_INVALID_VALUE, kSamplesZero); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6289 | return false; |
| 6290 | } |
| 6291 | |
| 6292 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6293 | if (!formatCaps.textureAttachment) |
| 6294 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6295 | context->validationError(GL_INVALID_ENUM, kRenderableInternalFormat); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6296 | return false; |
| 6297 | } |
| 6298 | |
| 6299 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6300 | // is one of the unsized base internalformats listed in table 8.11. |
| 6301 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6302 | if (formatInfo.internalFormat == GL_NONE) |
| 6303 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6304 | context->validationError(GL_INVALID_ENUM, kUnsizedInternalFormatUnsupported); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6305 | return false; |
| 6306 | } |
| 6307 | |
| 6308 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6309 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6310 | context->validationError(GL_INVALID_OPERATION, kSamplesOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6311 | return false; |
| 6312 | } |
| 6313 | |
| 6314 | Texture *texture = context->getTargetTexture(target); |
| 6315 | if (!texture || texture->id() == 0) |
| 6316 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6317 | context->validationError(GL_INVALID_OPERATION, kZeroBoundToTarget); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6318 | return false; |
| 6319 | } |
| 6320 | |
| 6321 | if (texture->getImmutableFormat()) |
| 6322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6323 | context->validationError(GL_INVALID_OPERATION, kImmutableTextureBound); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6324 | return false; |
| 6325 | } |
| 6326 | return true; |
| 6327 | } |
| 6328 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6329 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6330 | TextureType target, |
| 6331 | GLsizei samples, |
| 6332 | GLint internalFormat, |
| 6333 | GLsizei width, |
| 6334 | GLsizei height) |
| 6335 | { |
| 6336 | if (target != TextureType::_2DMultisample) |
| 6337 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6338 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6339 | return false; |
| 6340 | } |
| 6341 | |
| 6342 | if (width < 1 || height < 1) |
| 6343 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6344 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6345 | return false; |
| 6346 | } |
| 6347 | |
| 6348 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6349 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6350 | |
| 6351 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6352 | TextureTarget target, |
| 6353 | GLint level, |
| 6354 | GLenum pname, |
| 6355 | GLsizei *length) |
| 6356 | { |
| 6357 | |
| 6358 | if (length) |
| 6359 | { |
| 6360 | *length = 0; |
| 6361 | } |
| 6362 | |
| 6363 | TextureType type = TextureTargetToType(target); |
| 6364 | |
| 6365 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6366 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6367 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6368 | return false; |
| 6369 | } |
| 6370 | |
| 6371 | if (context->getTargetTexture(type) == nullptr) |
| 6372 | { |
Jamie Madill | c3e3731 | 2018-11-30 15:25:39 -0500 | [diff] [blame] | 6373 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6374 | return false; |
| 6375 | } |
| 6376 | |
| 6377 | if (!ValidMipLevel(context, type, level)) |
| 6378 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6379 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6380 | return false; |
| 6381 | } |
| 6382 | |
| 6383 | switch (pname) |
| 6384 | { |
| 6385 | case GL_TEXTURE_RED_TYPE: |
| 6386 | case GL_TEXTURE_GREEN_TYPE: |
| 6387 | case GL_TEXTURE_BLUE_TYPE: |
| 6388 | case GL_TEXTURE_ALPHA_TYPE: |
| 6389 | case GL_TEXTURE_DEPTH_TYPE: |
| 6390 | break; |
| 6391 | case GL_TEXTURE_RED_SIZE: |
| 6392 | case GL_TEXTURE_GREEN_SIZE: |
| 6393 | case GL_TEXTURE_BLUE_SIZE: |
| 6394 | case GL_TEXTURE_ALPHA_SIZE: |
| 6395 | case GL_TEXTURE_DEPTH_SIZE: |
| 6396 | case GL_TEXTURE_STENCIL_SIZE: |
| 6397 | case GL_TEXTURE_SHARED_SIZE: |
| 6398 | break; |
| 6399 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6400 | case GL_TEXTURE_WIDTH: |
| 6401 | case GL_TEXTURE_HEIGHT: |
| 6402 | case GL_TEXTURE_DEPTH: |
| 6403 | break; |
| 6404 | case GL_TEXTURE_SAMPLES: |
| 6405 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6406 | break; |
| 6407 | case GL_TEXTURE_COMPRESSED: |
| 6408 | break; |
| 6409 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6410 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6411 | return false; |
| 6412 | } |
| 6413 | |
| 6414 | if (length) |
| 6415 | { |
| 6416 | *length = 1; |
| 6417 | } |
| 6418 | return true; |
| 6419 | } |
Yizhou Jiang | 7310da3 | 2018-11-05 14:40:01 +0800 | [diff] [blame] | 6420 | |
| 6421 | bool ValidateGetMultisamplefvBase(Context *context, GLenum pname, GLuint index, GLfloat *val) |
| 6422 | { |
| 6423 | if (pname != GL_SAMPLE_POSITION) |
| 6424 | { |
| 6425 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
| 6426 | return false; |
| 6427 | } |
| 6428 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 6429 | Framebuffer *framebuffer = context->getState().getDrawFramebuffer(); |
Yizhou Jiang | 7310da3 | 2018-11-05 14:40:01 +0800 | [diff] [blame] | 6430 | GLint samples = framebuffer->getSamples(context); |
| 6431 | |
| 6432 | if (index >= static_cast<GLuint>(samples)) |
| 6433 | { |
| 6434 | context->validationError(GL_INVALID_VALUE, kIndexExceedsSamples); |
| 6435 | return false; |
| 6436 | } |
| 6437 | |
| 6438 | return true; |
| 6439 | } |
| 6440 | |
| 6441 | bool ValidateSampleMaskiBase(Context *context, GLuint maskNumber, GLbitfield mask) |
| 6442 | { |
| 6443 | if (maskNumber >= context->getCaps().maxSampleMaskWords) |
| 6444 | { |
| 6445 | context->validationError(GL_INVALID_VALUE, kInvalidSampleMaskNumber); |
| 6446 | return false; |
| 6447 | } |
| 6448 | |
| 6449 | return true; |
| 6450 | } |
Jamie Madill | 9fa54ea | 2019-01-02 18:38:33 -0500 | [diff] [blame] | 6451 | |
| 6452 | void RecordDrawAttribsError(Context *context) |
| 6453 | { |
| 6454 | // An overflow can happen when adding the offset. Check against a special constant. |
| 6455 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 6456 | VertexAttribute::kIntegerOverflow || |
| 6457 | context->getStateCache().getInstancedVertexElementLimit() == |
| 6458 | VertexAttribute::kIntegerOverflow) |
| 6459 | { |
| 6460 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
| 6461 | } |
| 6462 | else |
| 6463 | { |
| 6464 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 6465 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
| 6466 | context->validationError(GL_INVALID_OPERATION, kInsufficientVertexBufferSize); |
| 6467 | } |
| 6468 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6469 | } // namespace gl |