Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 12 | #include "libANGLE/Display.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 13 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Query.h" |
| 19 | #include "libANGLE/Texture.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 24 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 25 | #include "libANGLE/queryutils.h" |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 26 | #include "libANGLE/validationES2_autogen.h" |
| 27 | #include "libANGLE/validationES3_autogen.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 28 | |
| 29 | #include "common/mathutil.h" |
| 30 | #include "common/utilities.h" |
| 31 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 32 | using namespace angle; |
| 33 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 36 | using namespace err; |
| 37 | |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 38 | namespace |
| 39 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 40 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 41 | { |
| 42 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 43 | // the compressed block size. |
| 44 | switch (internalFormat) |
| 45 | { |
| 46 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 48 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 49 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 50 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 52 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 53 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 54 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 59 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 60 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 61 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 62 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 63 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 64 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 65 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 66 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 67 | default: |
| 68 | return false; |
| 69 | } |
| 70 | } |
| 71 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 72 | { |
| 73 | // Compressed sub textures have additional formats that requires exact size. |
| 74 | // ES 3.1, Section 8.7, Page 171 |
| 75 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 76 | IsETC2EACFormat(internalFormat); |
| 77 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 78 | |
| 79 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 80 | { |
| 81 | CheckedNumeric<GLint> checkedA(a); |
| 82 | checkedA -= b; |
| 83 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 84 | checkedA = -checkedA; |
| 85 | return !checkedA.IsValid(); |
| 86 | } |
| 87 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 88 | bool ValidateDrawAttribsImpl(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 89 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 90 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 91 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 92 | |
Jamie Madill | 88602e6 | 2018-08-08 12:49:30 -0400 | [diff] [blame] | 93 | // An overflow can happen when adding the offset. Check against a special constant. |
| 94 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 95 | VertexAttribute::kIntegerOverflow || |
| 96 | context->getStateCache().getInstancedVertexElementLimit() == |
| 97 | VertexAttribute::kIntegerOverflow) |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 98 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 99 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 104 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 105 | context->validationError(GL_INVALID_OPERATION, kInsufficientVertexBufferSize); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 106 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 109 | ANGLE_INLINE bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
| 110 | { |
| 111 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 112 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
| 113 | { |
| 114 | return true; |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | return ValidateDrawAttribsImpl(context, primcount, maxVertex); |
| 119 | } |
| 120 | } |
| 121 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 122 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 123 | { |
| 124 | switch (type) |
| 125 | { |
| 126 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 127 | case GL_UNSIGNED_BYTE: |
| 128 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 129 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 130 | case GL_UNSIGNED_SHORT_5_6_5: |
| 131 | return context->getClientVersion() >= ES_2_0; |
| 132 | |
| 133 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 134 | case GL_BYTE: |
| 135 | case GL_INT: |
| 136 | case GL_SHORT: |
| 137 | case GL_UNSIGNED_INT: |
| 138 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 139 | case GL_UNSIGNED_INT_24_8: |
| 140 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 141 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 142 | case GL_UNSIGNED_SHORT: |
| 143 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 144 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 145 | return context->getClientVersion() >= ES_3_0; |
| 146 | |
| 147 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 148 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 149 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 150 | |
| 151 | case GL_HALF_FLOAT: |
| 152 | return context->getClientVersion() >= ES_3_0 || |
| 153 | context->getExtensions().textureHalfFloat; |
| 154 | |
| 155 | case GL_HALF_FLOAT_OES: |
| 156 | return context->getExtensions().colorBufferHalfFloat; |
| 157 | |
| 158 | default: |
| 159 | return false; |
| 160 | } |
| 161 | } |
| 162 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 163 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 164 | { |
| 165 | switch (format) |
| 166 | { |
| 167 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 168 | case GL_RGBA: |
| 169 | case GL_RGB: |
| 170 | case GL_ALPHA: |
| 171 | return context->getClientVersion() >= ES_2_0; |
| 172 | |
| 173 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 174 | case GL_RG: |
| 175 | case GL_RED: |
| 176 | case GL_RGBA_INTEGER: |
| 177 | case GL_RGB_INTEGER: |
| 178 | case GL_RG_INTEGER: |
| 179 | case GL_RED_INTEGER: |
| 180 | return context->getClientVersion() >= ES_3_0; |
| 181 | |
| 182 | case GL_SRGB_ALPHA_EXT: |
| 183 | case GL_SRGB_EXT: |
| 184 | return context->getExtensions().sRGB; |
| 185 | |
| 186 | case GL_BGRA_EXT: |
| 187 | return context->getExtensions().readFormatBGRA; |
| 188 | |
| 189 | default: |
| 190 | return false; |
| 191 | } |
| 192 | } |
| 193 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 194 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 195 | GLenum framebufferComponentType, |
| 196 | GLenum format, |
| 197 | GLenum type) |
| 198 | { |
| 199 | switch (framebufferComponentType) |
| 200 | { |
| 201 | case GL_UNSIGNED_NORMALIZED: |
| 202 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 203 | // ReadPixels with BGRA even if the extension is not present |
| 204 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 205 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 206 | type == GL_UNSIGNED_BYTE); |
| 207 | |
| 208 | case GL_SIGNED_NORMALIZED: |
| 209 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 210 | |
| 211 | case GL_INT: |
| 212 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 213 | |
| 214 | case GL_UNSIGNED_INT: |
| 215 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 216 | |
| 217 | case GL_FLOAT: |
| 218 | return (format == GL_RGBA && type == GL_FLOAT); |
| 219 | |
| 220 | default: |
| 221 | UNREACHABLE(); |
| 222 | return false; |
| 223 | } |
| 224 | } |
| 225 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 226 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 227 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 228 | { |
| 229 | switch (ConvertToGLenum(params[0])) |
| 230 | { |
| 231 | case GL_CLAMP_TO_EDGE: |
| 232 | break; |
| 233 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 234 | case GL_CLAMP_TO_BORDER: |
| 235 | if (!context->getExtensions().textureBorderClamp) |
| 236 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 237 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 238 | return false; |
| 239 | } |
| 240 | break; |
| 241 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 242 | case GL_REPEAT: |
| 243 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 244 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 245 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 246 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 247 | context->validationError(GL_INVALID_ENUM, kInvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 248 | return false; |
| 249 | } |
| 250 | break; |
| 251 | |
| 252 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 253 | context->validationError(GL_INVALID_ENUM, kInvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 254 | return false; |
| 255 | } |
| 256 | |
| 257 | return true; |
| 258 | } |
| 259 | |
| 260 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 261 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 262 | { |
| 263 | switch (ConvertToGLenum(params[0])) |
| 264 | { |
| 265 | case GL_NEAREST: |
| 266 | case GL_LINEAR: |
| 267 | break; |
| 268 | |
| 269 | case GL_NEAREST_MIPMAP_NEAREST: |
| 270 | case GL_LINEAR_MIPMAP_NEAREST: |
| 271 | case GL_NEAREST_MIPMAP_LINEAR: |
| 272 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 273 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 274 | { |
| 275 | // OES_EGL_image_external specifies this error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 276 | context->validationError(GL_INVALID_ENUM, kInvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 277 | return false; |
| 278 | } |
| 279 | break; |
| 280 | |
| 281 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 282 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 283 | return false; |
| 284 | } |
| 285 | |
| 286 | return true; |
| 287 | } |
| 288 | |
| 289 | template <typename ParamType> |
| 290 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 291 | { |
| 292 | switch (ConvertToGLenum(params[0])) |
| 293 | { |
| 294 | case GL_NEAREST: |
| 295 | case GL_LINEAR: |
| 296 | break; |
| 297 | |
| 298 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 299 | context->validationError(GL_INVALID_ENUM, kInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 300 | return false; |
| 301 | } |
| 302 | |
| 303 | return true; |
| 304 | } |
| 305 | |
| 306 | template <typename ParamType> |
| 307 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 308 | { |
| 309 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 310 | switch (ConvertToGLenum(params[0])) |
| 311 | { |
| 312 | case GL_NONE: |
| 313 | case GL_COMPARE_REF_TO_TEXTURE: |
| 314 | break; |
| 315 | |
| 316 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 317 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | |
| 321 | return true; |
| 322 | } |
| 323 | |
| 324 | template <typename ParamType> |
| 325 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 326 | { |
| 327 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 328 | switch (ConvertToGLenum(params[0])) |
| 329 | { |
| 330 | case GL_LEQUAL: |
| 331 | case GL_GEQUAL: |
| 332 | case GL_LESS: |
| 333 | case GL_GREATER: |
| 334 | case GL_EQUAL: |
| 335 | case GL_NOTEQUAL: |
| 336 | case GL_ALWAYS: |
| 337 | case GL_NEVER: |
| 338 | break; |
| 339 | |
| 340 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 341 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 342 | return false; |
| 343 | } |
| 344 | |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 349 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 350 | { |
| 351 | if (!context->getExtensions().textureSRGBDecode) |
| 352 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 353 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | |
| 357 | switch (ConvertToGLenum(params[0])) |
| 358 | { |
| 359 | case GL_DECODE_EXT: |
| 360 | case GL_SKIP_DECODE_EXT: |
| 361 | break; |
| 362 | |
| 363 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 364 | context->validationError(GL_INVALID_ENUM, kUnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 365 | return false; |
| 366 | } |
| 367 | |
| 368 | return true; |
| 369 | } |
| 370 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 371 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 372 | { |
| 373 | if (!context->getExtensions().textureFilterAnisotropic) |
| 374 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 375 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 376 | return false; |
| 377 | } |
| 378 | |
| 379 | return true; |
| 380 | } |
| 381 | |
| 382 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 383 | { |
| 384 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 385 | { |
| 386 | return false; |
| 387 | } |
| 388 | |
| 389 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 390 | |
| 391 | if (paramValue < 1 || paramValue > largest) |
| 392 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 393 | context->validationError(GL_INVALID_VALUE, kOutsideOfBounds); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 394 | return false; |
| 395 | } |
| 396 | |
| 397 | return true; |
| 398 | } |
| 399 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 400 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 401 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 402 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 403 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 404 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 405 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 406 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 407 | program->getActiveOutputVariables().to_ulong(), |
| 408 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 409 | } |
| 410 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 411 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 412 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 413 | const auto &glState = context->getGLState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 414 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 415 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 416 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 417 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 418 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 419 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 420 | |
| 421 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 422 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 423 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 424 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 425 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 426 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 427 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 428 | } |
| 429 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 430 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 431 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 432 | { |
| 433 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 434 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 435 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 436 | case PrimitiveMode::Points: |
| 437 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 438 | case PrimitiveMode::Lines: |
| 439 | case PrimitiveMode::LineStrip: |
| 440 | case PrimitiveMode::LineLoop: |
| 441 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 442 | case PrimitiveMode::LinesAdjacency: |
| 443 | case PrimitiveMode::LineStripAdjacency: |
| 444 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 445 | case PrimitiveMode::Triangles: |
| 446 | case PrimitiveMode::TriangleFan: |
| 447 | case PrimitiveMode::TriangleStrip: |
| 448 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 449 | case PrimitiveMode::TrianglesAdjacency: |
| 450 | case PrimitiveMode::TriangleStripAdjacency: |
| 451 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 452 | default: |
| 453 | UNREACHABLE(); |
| 454 | return false; |
| 455 | } |
| 456 | } |
| 457 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 458 | // GLES1 texture parameters are a small subset of the others |
| 459 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 460 | { |
| 461 | switch (pname) |
| 462 | { |
| 463 | case GL_TEXTURE_MAG_FILTER: |
| 464 | case GL_TEXTURE_MIN_FILTER: |
| 465 | case GL_TEXTURE_WRAP_S: |
| 466 | case GL_TEXTURE_WRAP_T: |
| 467 | case GL_TEXTURE_WRAP_R: |
| 468 | case GL_GENERATE_MIPMAP: |
| 469 | case GL_TEXTURE_CROP_RECT_OES: |
| 470 | return true; |
| 471 | default: |
| 472 | return false; |
| 473 | } |
| 474 | } |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 475 | |
| 476 | unsigned int GetSamplerParameterCount(GLenum pname) |
| 477 | { |
| 478 | return pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1; |
| 479 | } |
| 480 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 481 | } // anonymous namespace |
| 482 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 483 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 484 | { |
| 485 | if (length) |
| 486 | { |
| 487 | *length = value; |
| 488 | } |
| 489 | } |
| 490 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 491 | bool IsETC2EACFormat(const GLenum format) |
| 492 | { |
| 493 | // ES 3.1, Table 8.19 |
| 494 | switch (format) |
| 495 | { |
| 496 | case GL_COMPRESSED_R11_EAC: |
| 497 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 498 | case GL_COMPRESSED_RG11_EAC: |
| 499 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 500 | case GL_COMPRESSED_RGB8_ETC2: |
| 501 | case GL_COMPRESSED_SRGB8_ETC2: |
| 502 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 503 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 504 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 505 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 506 | return true; |
| 507 | |
| 508 | default: |
| 509 | return false; |
| 510 | } |
| 511 | } |
| 512 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 513 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 514 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 515 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 516 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 517 | case TextureType::_2D: |
| 518 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 519 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 520 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 521 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 522 | return context->getExtensions().textureRectangle; |
| 523 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 524 | case TextureType::_3D: |
| 525 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 526 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 527 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 528 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 529 | return (context->getClientVersion() >= Version(3, 1) || |
| 530 | context->getExtensions().textureMultisample); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 531 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 532 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 533 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 534 | default: |
| 535 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 536 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 539 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 540 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 541 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 542 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 543 | case TextureType::_2D: |
| 544 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 545 | return true; |
| 546 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 547 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 548 | return context->getExtensions().textureRectangle; |
| 549 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 550 | default: |
| 551 | return false; |
| 552 | } |
| 553 | } |
| 554 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 555 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 556 | { |
| 557 | switch (target) |
| 558 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 559 | case TextureType::_3D: |
| 560 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 561 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 562 | |
| 563 | default: |
| 564 | return false; |
| 565 | } |
| 566 | } |
| 567 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 568 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 569 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 570 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 571 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 572 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 573 | (context->getExtensions().eglImageExternal || |
| 574 | context->getExtensions().eglStreamConsumerExternal); |
| 575 | } |
| 576 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 577 | // This function differs from ValidTextureTarget in that the target must be |
| 578 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 579 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 580 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 581 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 582 | { |
| 583 | switch (target) |
| 584 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 585 | case TextureTarget::_2D: |
| 586 | case TextureTarget::CubeMapNegativeX: |
| 587 | case TextureTarget::CubeMapNegativeY: |
| 588 | case TextureTarget::CubeMapNegativeZ: |
| 589 | case TextureTarget::CubeMapPositiveX: |
| 590 | case TextureTarget::CubeMapPositiveY: |
| 591 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 592 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 593 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 594 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 595 | default: |
| 596 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 600 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 601 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 602 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 603 | { |
| 604 | ASSERT(context); |
| 605 | |
| 606 | if (!context->getExtensions().geometryShader) |
| 607 | { |
| 608 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 609 | // that does not match the current transform feedback object's draw mode (if transform |
| 610 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 611 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 612 | } |
| 613 | |
| 614 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 615 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 616 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 617 | case PrimitiveMode::Points: |
| 618 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 619 | case PrimitiveMode::Lines: |
| 620 | case PrimitiveMode::LineStrip: |
| 621 | case PrimitiveMode::LineLoop: |
| 622 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 623 | case PrimitiveMode::Triangles: |
| 624 | case PrimitiveMode::TriangleFan: |
| 625 | case PrimitiveMode::TriangleStrip: |
| 626 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 627 | default: |
| 628 | UNREACHABLE(); |
| 629 | return false; |
| 630 | } |
| 631 | } |
| 632 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 633 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 634 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 635 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 636 | DrawElementsType type, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 637 | const GLvoid *indices, |
| 638 | GLsizei primcount) |
| 639 | { |
| 640 | if (primcount < 0) |
| 641 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 642 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 643 | return false; |
| 644 | } |
| 645 | |
| 646 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 647 | { |
| 648 | return false; |
| 649 | } |
| 650 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 651 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 655 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 656 | GLint first, |
| 657 | GLsizei count, |
| 658 | GLsizei primcount) |
| 659 | { |
| 660 | if (primcount < 0) |
| 661 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 662 | context->validationError(GL_INVALID_VALUE, kNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 663 | return false; |
| 664 | } |
| 665 | |
| 666 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 667 | { |
| 668 | return false; |
| 669 | } |
| 670 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 671 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 672 | } |
| 673 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 674 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 675 | { |
| 676 | // Verify there is at least one active attribute with a divisor of zero |
| 677 | const State &state = context->getGLState(); |
| 678 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 679 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 680 | |
| 681 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 682 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 683 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 684 | { |
| 685 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 686 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 687 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 688 | { |
| 689 | return true; |
| 690 | } |
| 691 | } |
| 692 | |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 693 | context->validationError(GL_INVALID_OPERATION, kNoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 694 | return false; |
| 695 | } |
| 696 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 697 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 698 | { |
| 699 | switch (target) |
| 700 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 701 | case TextureType::_3D: |
| 702 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 703 | return true; |
| 704 | default: |
| 705 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 709 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 710 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 711 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 712 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 713 | case TextureType::_2D: |
| 714 | case TextureType::_2DArray: |
| 715 | case TextureType::_2DMultisample: |
| 716 | case TextureType::CubeMap: |
| 717 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 718 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 719 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 720 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 721 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 722 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 723 | default: |
| 724 | return false; |
| 725 | } |
| 726 | } |
| 727 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 728 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 729 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 730 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 731 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 732 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 733 | |
| 734 | switch (target) |
| 735 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 736 | case GL_FRAMEBUFFER: |
| 737 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 738 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 739 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 740 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 741 | return (context->getExtensions().framebufferBlit || |
| 742 | context->getClientMajorVersion() >= 3); |
| 743 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 744 | default: |
| 745 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 749 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 750 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 751 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 752 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 753 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 754 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 755 | case TextureType::_2D: |
| 756 | case TextureType::_2DArray: |
| 757 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 758 | case TextureType::_2DMultisampleArray: |
| 759 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 760 | // level-of-detail" for multisample textures should be. Could maybe make it zero. |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 761 | maxDimension = caps.max2DTextureSize; |
| 762 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 763 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 764 | maxDimension = caps.maxCubeMapTextureSize; |
| 765 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 766 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 767 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 768 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 769 | maxDimension = caps.max3DTextureSize; |
| 770 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 771 | default: |
| 772 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 773 | } |
| 774 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 775 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 776 | } |
| 777 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 778 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 779 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 780 | GLint level, |
| 781 | GLsizei width, |
| 782 | GLsizei height, |
| 783 | GLsizei depth, |
| 784 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 785 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 786 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 787 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 788 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 789 | return false; |
| 790 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 791 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 792 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 793 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 794 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 795 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 796 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 797 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 798 | context->validationError(GL_INVALID_VALUE, kTextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 799 | return false; |
| 800 | } |
| 801 | |
| 802 | if (!ValidMipLevel(context, target, level)) |
| 803 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 804 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 805 | return false; |
| 806 | } |
| 807 | |
| 808 | return true; |
| 809 | } |
| 810 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 811 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 812 | { |
| 813 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 814 | (size % blockSize == 0); |
| 815 | } |
| 816 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 817 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 818 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 819 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 820 | GLsizei width, |
| 821 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 822 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 823 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 824 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 825 | { |
| 826 | return false; |
| 827 | } |
| 828 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 829 | if (width < 0 || height < 0) |
| 830 | { |
| 831 | return false; |
| 832 | } |
| 833 | |
| 834 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 835 | { |
| 836 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 837 | // block size for level 0 but WebGL disallows this. |
| 838 | bool smallerThanBlockSizeAllowed = |
| 839 | level > 0 || !context->getExtensions().webglCompatibility; |
| 840 | |
| 841 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 842 | smallerThanBlockSizeAllowed) || |
| 843 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 844 | smallerThanBlockSizeAllowed)) |
| 845 | { |
| 846 | return false; |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | return true; |
| 851 | } |
| 852 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 853 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 854 | GLenum internalFormat, |
| 855 | GLint xoffset, |
| 856 | GLint yoffset, |
| 857 | GLsizei width, |
| 858 | GLsizei height, |
| 859 | size_t textureWidth, |
| 860 | size_t textureHeight) |
| 861 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 862 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 863 | if (!formatInfo.compressed) |
| 864 | { |
| 865 | return false; |
| 866 | } |
| 867 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 868 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 869 | { |
| 870 | return false; |
| 871 | } |
| 872 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 873 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 874 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 875 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 876 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 877 | { |
| 878 | return false; |
| 879 | } |
| 880 | |
| 881 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 882 | // size but fills the entire mip |
| 883 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 884 | static_cast<size_t>(width) == textureWidth && |
| 885 | static_cast<size_t>(height) == textureHeight; |
| 886 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 887 | (height % formatInfo.compressedBlockHeight) == 0; |
| 888 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 889 | { |
| 890 | return false; |
| 891 | } |
| 892 | } |
| 893 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 894 | return true; |
| 895 | } |
| 896 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 897 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 898 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 899 | GLsizei width, |
| 900 | GLsizei height, |
| 901 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 902 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 903 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 904 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 905 | GLsizei imageSize) |
| 906 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 907 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 908 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 909 | { |
| 910 | // Checks are not required |
| 911 | return true; |
| 912 | } |
| 913 | |
| 914 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 915 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 916 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 917 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 918 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 919 | const auto &unpack = context->getGLState().getUnpackState(); |
| 920 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 921 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 922 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 923 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 924 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 925 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 926 | return false; |
| 927 | } |
| 928 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 929 | if (pixelUnpackBuffer) |
| 930 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 931 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 932 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 933 | checkedEndByte += checkedOffset; |
| 934 | |
| 935 | if (!checkedEndByte.IsValid() || |
| 936 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 937 | { |
| 938 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 939 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 940 | return false; |
| 941 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 942 | if (context->getExtensions().webglCompatibility && |
| 943 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 944 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 945 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 946 | kPixelUnpackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 947 | return false; |
| 948 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 949 | } |
| 950 | else |
| 951 | { |
| 952 | ASSERT(imageSize >= 0); |
| 953 | if (pixels == nullptr && imageSize != 0) |
| 954 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 955 | context->validationError(GL_INVALID_OPERATION, |
| 956 | "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 957 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 958 | } |
| 959 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 960 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 961 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 962 | context->validationError(GL_INVALID_OPERATION, "imageSize is too small"); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 963 | return false; |
| 964 | } |
| 965 | } |
| 966 | |
| 967 | return true; |
| 968 | } |
| 969 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 970 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 971 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 972 | switch (queryType) |
| 973 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 974 | case QueryType::AnySamples: |
| 975 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 976 | return context->getClientMajorVersion() >= 3 || |
| 977 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 978 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 979 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 980 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 981 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 982 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 983 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 984 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 985 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 986 | default: |
| 987 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 991 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 992 | GLenum type, |
| 993 | GLboolean normalized, |
| 994 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 995 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 996 | bool pureInteger) |
| 997 | { |
| 998 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 999 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1000 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1001 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1002 | // parameter exceeds 255. |
| 1003 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1004 | if (stride > kMaxWebGLStride) |
| 1005 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1006 | context->validationError(GL_INVALID_VALUE, |
| 1007 | "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1012 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1013 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1014 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 1015 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 1016 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1017 | |
| 1018 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1019 | size_t sizeMask = (typeSize - 1); |
| 1020 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1021 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1022 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1023 | return false; |
| 1024 | } |
| 1025 | |
| 1026 | if ((stride & sizeMask) != 0) |
| 1027 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1028 | context->validationError(GL_INVALID_OPERATION, kStrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1029 | return false; |
| 1030 | } |
| 1031 | |
| 1032 | return true; |
| 1033 | } |
| 1034 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1035 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1036 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1037 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1038 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1039 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1040 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1041 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1042 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1043 | |
| 1044 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1045 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1046 | if (context->getShader(id)) |
| 1047 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1048 | context->validationError(GL_INVALID_OPERATION, kExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1049 | } |
| 1050 | else |
| 1051 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1052 | context->validationError(GL_INVALID_VALUE, kInvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1053 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1054 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1055 | |
| 1056 | return validProgram; |
| 1057 | } |
| 1058 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1059 | Program *GetValidProgram(Context *context, GLuint id) |
| 1060 | { |
| 1061 | Program *program = GetValidProgramNoResolve(context, id); |
| 1062 | if (program) |
| 1063 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1064 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1065 | } |
| 1066 | return program; |
| 1067 | } |
| 1068 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1069 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1070 | { |
| 1071 | // See ValidProgram for spec details. |
| 1072 | |
| 1073 | Shader *validShader = context->getShader(id); |
| 1074 | |
| 1075 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1076 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1077 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1078 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1079 | context->validationError(GL_INVALID_OPERATION, kExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1080 | } |
| 1081 | else |
| 1082 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1083 | context->validationError(GL_INVALID_VALUE, kInvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1084 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1085 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1086 | |
| 1087 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1090 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1091 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1092 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1093 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1094 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1095 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1096 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1097 | return false; |
| 1098 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1099 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1100 | // Color attachment 0 is validated below because it is always valid |
| 1101 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1102 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1103 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1104 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1105 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1106 | } |
| 1107 | } |
| 1108 | else |
| 1109 | { |
| 1110 | switch (attachment) |
| 1111 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1112 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1113 | case GL_DEPTH_ATTACHMENT: |
| 1114 | case GL_STENCIL_ATTACHMENT: |
| 1115 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1116 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1117 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1118 | if (!context->getExtensions().webglCompatibility && |
| 1119 | context->getClientMajorVersion() < 3) |
| 1120 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1121 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1122 | return false; |
| 1123 | } |
| 1124 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1125 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1126 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1127 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1128 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1129 | } |
| 1130 | } |
| 1131 | |
| 1132 | return true; |
| 1133 | } |
| 1134 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1135 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1136 | GLenum target, |
| 1137 | GLsizei samples, |
| 1138 | GLenum internalformat, |
| 1139 | GLsizei width, |
| 1140 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1141 | { |
| 1142 | switch (target) |
| 1143 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1144 | case GL_RENDERBUFFER: |
| 1145 | break; |
| 1146 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1147 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1148 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | if (width < 0 || height < 0 || samples < 0) |
| 1152 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1153 | context->validationError(GL_INVALID_VALUE, kInvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1154 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1157 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1158 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1159 | |
| 1160 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1161 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1163 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1164 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
| 1167 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1168 | // 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] | 1169 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1170 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1171 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1172 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1173 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1174 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1175 | } |
| 1176 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1177 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1178 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1179 | context->validationError(GL_INVALID_VALUE, kResourceMaxRenderbufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1180 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1181 | } |
| 1182 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1183 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1184 | if (handle == 0) |
| 1185 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1186 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1187 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
| 1190 | return true; |
| 1191 | } |
| 1192 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1193 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1194 | GLenum target, |
| 1195 | GLenum attachment, |
| 1196 | GLenum renderbuffertarget, |
| 1197 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1198 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1199 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1200 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1201 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1202 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1205 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1206 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1207 | ASSERT(framebuffer); |
| 1208 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1209 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1210 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1211 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1212 | } |
| 1213 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1214 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1215 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1216 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1217 | } |
| 1218 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1219 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1220 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1221 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1222 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1223 | if (renderbuffer != 0) |
| 1224 | { |
| 1225 | if (!context->getRenderbuffer(renderbuffer)) |
| 1226 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1227 | context->validationError(GL_INVALID_OPERATION, kInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1228 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1229 | } |
| 1230 | } |
| 1231 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1232 | return true; |
| 1233 | } |
| 1234 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1235 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1236 | GLint srcX0, |
| 1237 | GLint srcY0, |
| 1238 | GLint srcX1, |
| 1239 | GLint srcY1, |
| 1240 | GLint dstX0, |
| 1241 | GLint dstY0, |
| 1242 | GLint dstX1, |
| 1243 | GLint dstY1, |
| 1244 | GLbitfield mask, |
| 1245 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1246 | { |
| 1247 | switch (filter) |
| 1248 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1249 | case GL_NEAREST: |
| 1250 | break; |
| 1251 | case GL_LINEAR: |
| 1252 | break; |
| 1253 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1254 | context->validationError(GL_INVALID_ENUM, kBlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1255 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1259 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1260 | context->validationError(GL_INVALID_VALUE, kBlitInvalidMask); |
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 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1264 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1265 | // color buffer, leaving only nearest being unfiltered from above |
| 1266 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1267 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1268 | context->validationError(GL_INVALID_OPERATION, kBlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1269 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1272 | const auto &glState = context->getGLState(); |
| 1273 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1274 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1275 | |
| 1276 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1277 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1278 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1279 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1280 | } |
| 1281 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1282 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1283 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1284 | return false; |
| 1285 | } |
| 1286 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1287 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1288 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1289 | return false; |
| 1290 | } |
| 1291 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1292 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1293 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1294 | context->validationError(GL_INVALID_OPERATION, kBlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1295 | return false; |
| 1296 | } |
| 1297 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1298 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1300 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1301 | } |
| 1302 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1303 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1304 | // always run it in order to avoid triggering driver bugs. |
| 1305 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1306 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1307 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1308 | context->validationError(GL_INVALID_VALUE, kBlitDimensionsOutOfRange); |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1309 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1310 | } |
| 1311 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1313 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1314 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1315 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1316 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1317 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1318 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1319 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1320 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1321 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1322 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1323 | for (size_t drawbufferIdx = 0; |
| 1324 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1325 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1326 | const FramebufferAttachment *attachment = |
| 1327 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1328 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1329 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1330 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1331 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1332 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1333 | // 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] | 1334 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1335 | // as well |
| 1336 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1337 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1338 | // Changes with EXT_color_buffer_float: |
| 1339 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1340 | GLenum readComponentType = readFormat.info->componentType; |
| 1341 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1342 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1343 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1344 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1345 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1346 | |
| 1347 | if (extensions.colorBufferFloat) |
| 1348 | { |
| 1349 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1350 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1351 | |
| 1352 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1353 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1354 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1355 | kBlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1356 | return false; |
| 1357 | } |
| 1358 | } |
| 1359 | else if (readFixedPoint != drawFixedPoint) |
| 1360 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1361 | context->validationError(GL_INVALID_OPERATION, kBlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1362 | return false; |
| 1363 | } |
| 1364 | |
| 1365 | if (readComponentType == GL_UNSIGNED_INT && |
| 1366 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1367 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1368 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1369 | kBlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1370 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1371 | } |
| 1372 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1373 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
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 | kBlitTypeMismatchSignedInteger); |
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 | } |
| 1379 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1380 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1381 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1382 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1383 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1384 | kBlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1385 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1386 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1387 | |
| 1388 | if (context->getExtensions().webglCompatibility && |
| 1389 | *readColorBuffer == *attachment) |
| 1390 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1391 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1392 | return false; |
| 1393 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1397 | if ((readFormat.info->componentType == GL_INT || |
| 1398 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1399 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1400 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1401 | context->validationError(GL_INVALID_OPERATION, kBlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1402 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1404 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1405 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1406 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1407 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1408 | // situation is an application error that would lead to a crash in ANGLE. |
| 1409 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1410 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1411 | context->validationError(GL_INVALID_OPERATION, kBlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1412 | return false; |
| 1413 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1416 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1417 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1418 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1419 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1420 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1421 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1422 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1423 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1424 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1425 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1426 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1427 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1428 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1429 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1430 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1431 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1432 | kBlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1433 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1434 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1435 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1436 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1437 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1438 | context->validationError(GL_INVALID_OPERATION, kBlitMultisampledBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1439 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1440 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1441 | |
| 1442 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1443 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1444 | context->validationError(GL_INVALID_OPERATION, kBlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1447 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1448 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1449 | else if (drawBuffer) |
| 1450 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1451 | context->validationError(GL_INVALID_OPERATION, kBlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1452 | return false; |
| 1453 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1457 | // ANGLE_multiview, Revision 1: |
| 1458 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1459 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1460 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1461 | // views in the current read framebuffer is more than one. |
| 1462 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1463 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1464 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1465 | return false; |
| 1466 | } |
| 1467 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1468 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1469 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kBlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1470 | return false; |
| 1471 | } |
| 1472 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1473 | return true; |
| 1474 | } |
| 1475 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1476 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1477 | GLint x, |
| 1478 | GLint y, |
| 1479 | GLsizei width, |
| 1480 | GLsizei height, |
| 1481 | GLenum format, |
| 1482 | GLenum type, |
| 1483 | GLsizei bufSize, |
| 1484 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1485 | GLsizei *columns, |
| 1486 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1487 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1488 | { |
| 1489 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1490 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1491 | return false; |
| 1492 | } |
| 1493 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1494 | GLsizei writeLength = 0; |
| 1495 | GLsizei writeColumns = 0; |
| 1496 | GLsizei writeRows = 0; |
| 1497 | |
| 1498 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1499 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1500 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1501 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1502 | } |
| 1503 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1504 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1505 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1506 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1507 | } |
| 1508 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1509 | SetRobustLengthParam(length, writeLength); |
| 1510 | SetRobustLengthParam(columns, writeColumns); |
| 1511 | SetRobustLengthParam(rows, writeRows); |
| 1512 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1513 | return true; |
| 1514 | } |
| 1515 | |
| 1516 | bool ValidateReadnPixelsEXT(Context *context, |
| 1517 | GLint x, |
| 1518 | GLint y, |
| 1519 | GLsizei width, |
| 1520 | GLsizei height, |
| 1521 | GLenum format, |
| 1522 | GLenum type, |
| 1523 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1524 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1525 | { |
| 1526 | if (bufSize < 0) |
| 1527 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1528 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1529 | return false; |
| 1530 | } |
| 1531 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1532 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1533 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1534 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1535 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1536 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1537 | GLint x, |
| 1538 | GLint y, |
| 1539 | GLsizei width, |
| 1540 | GLsizei height, |
| 1541 | GLenum format, |
| 1542 | GLenum type, |
| 1543 | GLsizei bufSize, |
| 1544 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1545 | GLsizei *columns, |
| 1546 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1547 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1548 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1549 | GLsizei writeLength = 0; |
| 1550 | GLsizei writeColumns = 0; |
| 1551 | GLsizei writeRows = 0; |
| 1552 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1553 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1554 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
| 1557 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1558 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1559 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1560 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1561 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1562 | } |
| 1563 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1564 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1565 | { |
| 1566 | return false; |
| 1567 | } |
| 1568 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1569 | SetRobustLengthParam(length, writeLength); |
| 1570 | SetRobustLengthParam(columns, writeColumns); |
| 1571 | SetRobustLengthParam(rows, writeRows); |
| 1572 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1573 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1574 | } |
| 1575 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1576 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1577 | { |
| 1578 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1579 | !context->getExtensions().disjointTimerQuery) |
| 1580 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1581 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1582 | return false; |
| 1583 | } |
| 1584 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1585 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1586 | } |
| 1587 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1588 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1589 | { |
| 1590 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1591 | !context->getExtensions().disjointTimerQuery) |
| 1592 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1593 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1594 | return false; |
| 1595 | } |
| 1596 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1597 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1598 | } |
| 1599 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1600 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1601 | { |
| 1602 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1603 | !context->getExtensions().disjointTimerQuery) |
| 1604 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1605 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1606 | return false; |
| 1607 | } |
| 1608 | |
| 1609 | return true; |
| 1610 | } |
| 1611 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1612 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1613 | { |
| 1614 | if (!ValidQueryType(context, target)) |
| 1615 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1616 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1617 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1618 | } |
| 1619 | |
| 1620 | if (id == 0) |
| 1621 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1622 | context->validationError(GL_INVALID_OPERATION, "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1623 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1627 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1628 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1629 | // the active query for either target is non-zero), if <id> is the name of an |
| 1630 | // existing query object whose type does not match <target>, or if <id> is the |
| 1631 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1632 | // generated. |
| 1633 | |
| 1634 | // Ensure no other queries are active |
| 1635 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1636 | // separately that: |
| 1637 | // a) The query ID passed is not the current active query for any target/type |
| 1638 | // b) There are no active queries for the requested target (and in the case |
| 1639 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1640 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1641 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1642 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1643 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1644 | context->validationError(GL_INVALID_OPERATION, "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1645 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1646 | } |
| 1647 | |
| 1648 | Query *queryObject = context->getQuery(id, true, target); |
| 1649 | |
| 1650 | // check that name was obtained with glGenQueries |
| 1651 | if (!queryObject) |
| 1652 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1653 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1654 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | // check for type mismatch |
| 1658 | if (queryObject->getType() != target) |
| 1659 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1660 | context->validationError(GL_INVALID_OPERATION, "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1661 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1662 | } |
| 1663 | |
| 1664 | return true; |
| 1665 | } |
| 1666 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1667 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1668 | { |
| 1669 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1670 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1671 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1672 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1673 | return false; |
| 1674 | } |
| 1675 | |
| 1676 | return ValidateBeginQueryBase(context, target, id); |
| 1677 | } |
| 1678 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1679 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1680 | { |
| 1681 | if (!ValidQueryType(context, target)) |
| 1682 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1683 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1684 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1685 | } |
| 1686 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1687 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1688 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1689 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1690 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1691 | context->validationError(GL_INVALID_OPERATION, "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1692 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1693 | } |
| 1694 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1695 | return true; |
| 1696 | } |
| 1697 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1698 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1699 | { |
| 1700 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1701 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1702 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1703 | context->validationError(GL_INVALID_OPERATION, kQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
| 1706 | |
| 1707 | return ValidateEndQueryBase(context, target); |
| 1708 | } |
| 1709 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1710 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1711 | { |
| 1712 | if (!context->getExtensions().disjointTimerQuery) |
| 1713 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1714 | context->validationError(GL_INVALID_OPERATION, "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1715 | return false; |
| 1716 | } |
| 1717 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1718 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1719 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1720 | context->validationError(GL_INVALID_ENUM, kInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1721 | return false; |
| 1722 | } |
| 1723 | |
| 1724 | Query *queryObject = context->getQuery(id, true, target); |
| 1725 | if (queryObject == nullptr) |
| 1726 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1727 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1728 | return false; |
| 1729 | } |
| 1730 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1731 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1732 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1733 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1734 | return false; |
| 1735 | } |
| 1736 | |
| 1737 | return true; |
| 1738 | } |
| 1739 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1740 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1741 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1742 | if (numParams) |
| 1743 | { |
| 1744 | *numParams = 0; |
| 1745 | } |
| 1746 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1747 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1748 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1749 | context->validationError(GL_INVALID_ENUM, kInvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1750 | return false; |
| 1751 | } |
| 1752 | |
| 1753 | switch (pname) |
| 1754 | { |
| 1755 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1756 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1757 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1758 | context->validationError(GL_INVALID_ENUM, "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1759 | return false; |
| 1760 | } |
| 1761 | break; |
| 1762 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1763 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1764 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1765 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1766 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1767 | return false; |
| 1768 | } |
| 1769 | break; |
| 1770 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1771 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1772 | return false; |
| 1773 | } |
| 1774 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1775 | if (numParams) |
| 1776 | { |
| 1777 | // All queries return only one value |
| 1778 | *numParams = 1; |
| 1779 | } |
| 1780 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1781 | return true; |
| 1782 | } |
| 1783 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1784 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1785 | { |
| 1786 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1787 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1788 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1789 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1790 | return false; |
| 1791 | } |
| 1792 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1793 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1794 | } |
| 1795 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1796 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1797 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1798 | GLenum pname, |
| 1799 | GLsizei bufSize, |
| 1800 | GLsizei *length, |
| 1801 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1802 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1803 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1804 | { |
| 1805 | return false; |
| 1806 | } |
| 1807 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1808 | GLsizei numParams = 0; |
| 1809 | |
| 1810 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1811 | { |
| 1812 | return false; |
| 1813 | } |
| 1814 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1815 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1816 | { |
| 1817 | return false; |
| 1818 | } |
| 1819 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1820 | SetRobustLengthParam(length, numParams); |
| 1821 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1822 | return true; |
| 1823 | } |
| 1824 | |
| 1825 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1826 | { |
| 1827 | if (numParams) |
| 1828 | { |
| 1829 | *numParams = 0; |
| 1830 | } |
| 1831 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1832 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1833 | |
| 1834 | if (!queryObject) |
| 1835 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1836 | context->validationError(GL_INVALID_OPERATION, kInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1840 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1841 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1842 | context->validationError(GL_INVALID_OPERATION, kQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | switch (pname) |
| 1847 | { |
| 1848 | case GL_QUERY_RESULT_EXT: |
| 1849 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1850 | break; |
| 1851 | |
| 1852 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1853 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
| 1856 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1857 | if (numParams) |
| 1858 | { |
| 1859 | *numParams = 1; |
| 1860 | } |
| 1861 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1862 | return true; |
| 1863 | } |
| 1864 | |
| 1865 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1866 | { |
| 1867 | if (!context->getExtensions().disjointTimerQuery) |
| 1868 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1869 | context->validationError(GL_INVALID_OPERATION, "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1870 | return false; |
| 1871 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1872 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1873 | } |
| 1874 | |
| 1875 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1876 | GLuint id, |
| 1877 | GLenum pname, |
| 1878 | GLsizei bufSize, |
| 1879 | GLsizei *length, |
| 1880 | GLint *params) |
| 1881 | { |
| 1882 | if (!context->getExtensions().disjointTimerQuery) |
| 1883 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1884 | context->validationError(GL_INVALID_OPERATION, "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1885 | return false; |
| 1886 | } |
| 1887 | |
| 1888 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1889 | { |
| 1890 | return false; |
| 1891 | } |
| 1892 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1893 | GLsizei numParams = 0; |
| 1894 | |
| 1895 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1896 | { |
| 1897 | return false; |
| 1898 | } |
| 1899 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1900 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1901 | { |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1905 | SetRobustLengthParam(length, numParams); |
| 1906 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1907 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1908 | } |
| 1909 | |
| 1910 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1911 | { |
| 1912 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1913 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1914 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1915 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1916 | return false; |
| 1917 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1918 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1919 | } |
| 1920 | |
| 1921 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1922 | GLuint id, |
| 1923 | GLenum pname, |
| 1924 | GLsizei bufSize, |
| 1925 | GLsizei *length, |
| 1926 | GLuint *params) |
| 1927 | { |
| 1928 | if (!context->getExtensions().disjointTimerQuery && |
| 1929 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1930 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1931 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1932 | return false; |
| 1933 | } |
| 1934 | |
| 1935 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1936 | { |
| 1937 | return false; |
| 1938 | } |
| 1939 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1940 | GLsizei numParams = 0; |
| 1941 | |
| 1942 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1943 | { |
| 1944 | return false; |
| 1945 | } |
| 1946 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1947 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1948 | { |
| 1949 | return false; |
| 1950 | } |
| 1951 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1952 | SetRobustLengthParam(length, numParams); |
| 1953 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1954 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1958 | { |
| 1959 | if (!context->getExtensions().disjointTimerQuery) |
| 1960 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1961 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1962 | return false; |
| 1963 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1964 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1965 | } |
| 1966 | |
| 1967 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1968 | GLuint id, |
| 1969 | GLenum pname, |
| 1970 | GLsizei bufSize, |
| 1971 | GLsizei *length, |
| 1972 | GLint64 *params) |
| 1973 | { |
| 1974 | if (!context->getExtensions().disjointTimerQuery) |
| 1975 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 1976 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1977 | return false; |
| 1978 | } |
| 1979 | |
| 1980 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1981 | { |
| 1982 | return false; |
| 1983 | } |
| 1984 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1985 | GLsizei numParams = 0; |
| 1986 | |
| 1987 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1988 | { |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1992 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1993 | { |
| 1994 | return false; |
| 1995 | } |
| 1996 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1997 | SetRobustLengthParam(length, numParams); |
| 1998 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1999 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2003 | { |
| 2004 | if (!context->getExtensions().disjointTimerQuery) |
| 2005 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2006 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2007 | return false; |
| 2008 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2009 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2010 | } |
| 2011 | |
| 2012 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2013 | GLuint id, |
| 2014 | GLenum pname, |
| 2015 | GLsizei bufSize, |
| 2016 | GLsizei *length, |
| 2017 | GLuint64 *params) |
| 2018 | { |
| 2019 | if (!context->getExtensions().disjointTimerQuery) |
| 2020 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2021 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2022 | return false; |
| 2023 | } |
| 2024 | |
| 2025 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2026 | { |
| 2027 | return false; |
| 2028 | } |
| 2029 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2030 | GLsizei numParams = 0; |
| 2031 | |
| 2032 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2033 | { |
| 2034 | return false; |
| 2035 | } |
| 2036 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2037 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2038 | { |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2042 | SetRobustLengthParam(length, numParams); |
| 2043 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2044 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2045 | } |
| 2046 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2047 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2048 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2049 | GLint location, |
| 2050 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2051 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2052 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2053 | // TODO(Jiajia): Add image uniform check in future. |
| 2054 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2055 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2056 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
| 2059 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2060 | if (!program) |
| 2061 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2062 | context->validationError(GL_INVALID_OPERATION, kInvalidProgramName); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2063 | return false; |
| 2064 | } |
| 2065 | |
| 2066 | if (!program->isLinked()) |
| 2067 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2068 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2069 | return false; |
| 2070 | } |
| 2071 | |
| 2072 | if (location == -1) |
| 2073 | { |
| 2074 | // Silently ignore the uniform command |
| 2075 | return false; |
| 2076 | } |
| 2077 | |
| 2078 | const auto &uniformLocations = program->getUniformLocations(); |
| 2079 | size_t castedLocation = static_cast<size_t>(location); |
| 2080 | if (castedLocation >= uniformLocations.size()) |
| 2081 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2082 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2083 | return false; |
| 2084 | } |
| 2085 | |
| 2086 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2087 | if (uniformLocation.ignored) |
| 2088 | { |
| 2089 | // Silently ignore the uniform command |
| 2090 | return false; |
| 2091 | } |
| 2092 | |
| 2093 | if (!uniformLocation.used()) |
| 2094 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2095 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2096 | return false; |
| 2097 | } |
| 2098 | |
| 2099 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2100 | |
| 2101 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
Jamie Madill | 2fc0806 | 2018-05-10 15:10:55 -0400 | [diff] [blame] | 2102 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2103 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2104 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformCount); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2105 | return false; |
| 2106 | } |
| 2107 | |
| 2108 | *uniformOut = &uniform; |
| 2109 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2110 | } |
| 2111 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2112 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2113 | GLenum uniformType, |
| 2114 | GLsizei count, |
| 2115 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2116 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2117 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2118 | // It is compatible with INT or BOOL. |
| 2119 | // Do these cheap tests first, for a little extra speed. |
| 2120 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2121 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2122 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2123 | } |
| 2124 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2125 | if (IsSamplerType(uniformType)) |
| 2126 | { |
| 2127 | // Check that the values are in range. |
| 2128 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2129 | for (GLsizei i = 0; i < count; ++i) |
| 2130 | { |
| 2131 | if (value[i] < 0 || value[i] >= max) |
| 2132 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2133 | context->validationError(GL_INVALID_VALUE, "sampler uniform value out of range"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2134 | return false; |
| 2135 | } |
| 2136 | } |
| 2137 | return true; |
| 2138 | } |
| 2139 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2140 | context->validationError(GL_INVALID_OPERATION, "wrong type of value for uniform"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2141 | return false; |
| 2142 | } |
| 2143 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2144 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2145 | { |
| 2146 | // Check that the value type is compatible with uniform type. |
| 2147 | if (valueType == uniformType) |
| 2148 | { |
| 2149 | return true; |
| 2150 | } |
| 2151 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2152 | context->validationError(GL_INVALID_OPERATION, "wrong type of value for uniform"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2153 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2154 | } |
| 2155 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2156 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2157 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2158 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2159 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2160 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2161 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2164 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2165 | { |
| 2166 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2167 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2168 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2169 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2170 | } |
| 2171 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2172 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2173 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2174 | GLint location, |
| 2175 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2176 | GLboolean transpose) |
| 2177 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2178 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2180 | context->validationError(GL_INVALID_VALUE, kES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2181 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2182 | } |
| 2183 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2184 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2185 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2186 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2187 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2188 | } |
| 2189 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2190 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2191 | { |
| 2192 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2193 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2194 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2195 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2196 | } |
| 2197 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2198 | const Caps &caps = context->getCaps(); |
| 2199 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2200 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2201 | { |
| 2202 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2203 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2204 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2205 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2206 | context->validationError(GL_INVALID_OPERATION, kIndexExceedsMaxDrawBuffer); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2207 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2208 | } |
| 2209 | } |
| 2210 | |
| 2211 | switch (pname) |
| 2212 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2213 | case GL_TEXTURE_BINDING_2D: |
| 2214 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2215 | case GL_TEXTURE_BINDING_3D: |
| 2216 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2217 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2218 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2219 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2220 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2221 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2222 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2223 | return false; |
| 2224 | } |
| 2225 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2226 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2227 | if (!context->getExtensions().textureRectangle) |
| 2228 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2229 | context->validationError(GL_INVALID_ENUM, |
| 2230 | "ANGLE_texture_rectangle extension not present"); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2231 | return false; |
| 2232 | } |
| 2233 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2234 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2235 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2236 | !context->getExtensions().eglImageExternal) |
| 2237 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2238 | context->validationError(GL_INVALID_ENUM, |
| 2239 | "Neither NV_EGL_stream_consumer_external " |
| 2240 | "nor GL_OES_EGL_image_external " |
| 2241 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2242 | return false; |
| 2243 | } |
| 2244 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2245 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2246 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2247 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2248 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2249 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2250 | ASSERT(readFramebuffer); |
| 2251 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2252 | if (!ValidateFramebufferComplete<GL_INVALID_OPERATION>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2253 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2254 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2255 | } |
| 2256 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2257 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2258 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2259 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2260 | return false; |
| 2261 | } |
| 2262 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2263 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2264 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2265 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2266 | context->validationError(GL_INVALID_OPERATION, kReadBufferNotAttached); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2267 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2268 | } |
| 2269 | } |
| 2270 | break; |
| 2271 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2272 | default: |
| 2273 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2274 | } |
| 2275 | |
| 2276 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2277 | if (*numParams == 0) |
| 2278 | { |
| 2279 | return false; |
| 2280 | } |
| 2281 | |
| 2282 | return true; |
| 2283 | } |
| 2284 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2285 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2286 | GLenum pname, |
| 2287 | GLsizei bufSize, |
| 2288 | GLsizei *length, |
| 2289 | GLboolean *params) |
| 2290 | { |
| 2291 | GLenum nativeType; |
| 2292 | unsigned int numParams = 0; |
| 2293 | |
| 2294 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2295 | { |
| 2296 | return false; |
| 2297 | } |
| 2298 | |
| 2299 | SetRobustLengthParam(length, numParams); |
| 2300 | |
| 2301 | return true; |
| 2302 | } |
| 2303 | |
| 2304 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2305 | GLenum pname, |
| 2306 | GLsizei bufSize, |
| 2307 | GLsizei *length, |
| 2308 | GLfloat *params) |
| 2309 | { |
| 2310 | GLenum nativeType; |
| 2311 | unsigned int numParams = 0; |
| 2312 | |
| 2313 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2314 | { |
| 2315 | return false; |
| 2316 | } |
| 2317 | |
| 2318 | SetRobustLengthParam(length, numParams); |
| 2319 | |
| 2320 | return true; |
| 2321 | } |
| 2322 | |
| 2323 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2324 | GLenum pname, |
| 2325 | GLsizei bufSize, |
| 2326 | GLsizei *length, |
| 2327 | GLint *data) |
| 2328 | { |
| 2329 | GLenum nativeType; |
| 2330 | unsigned int numParams = 0; |
| 2331 | |
| 2332 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2333 | { |
| 2334 | return false; |
| 2335 | } |
| 2336 | |
| 2337 | SetRobustLengthParam(length, numParams); |
| 2338 | |
| 2339 | return true; |
| 2340 | } |
| 2341 | |
| 2342 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2343 | GLenum pname, |
| 2344 | GLsizei bufSize, |
| 2345 | GLsizei *length, |
| 2346 | GLint64 *data) |
| 2347 | { |
| 2348 | GLenum nativeType; |
| 2349 | unsigned int numParams = 0; |
| 2350 | |
| 2351 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2352 | { |
| 2353 | return false; |
| 2354 | } |
| 2355 | |
| 2356 | if (nativeType == GL_INT_64_ANGLEX) |
| 2357 | { |
| 2358 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | SetRobustLengthParam(length, numParams); |
| 2363 | return true; |
| 2364 | } |
| 2365 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2366 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2367 | GLenum pname, |
| 2368 | GLsizei bufSize, |
| 2369 | GLenum *nativeType, |
| 2370 | unsigned int *numParams) |
| 2371 | { |
| 2372 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2373 | { |
| 2374 | return false; |
| 2375 | } |
| 2376 | |
| 2377 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2378 | { |
| 2379 | return false; |
| 2380 | } |
| 2381 | |
| 2382 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2383 | { |
| 2384 | return false; |
| 2385 | } |
| 2386 | |
| 2387 | return true; |
| 2388 | } |
| 2389 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2390 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2391 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2392 | GLint level, |
| 2393 | GLenum internalformat, |
| 2394 | bool isSubImage, |
| 2395 | GLint xoffset, |
| 2396 | GLint yoffset, |
| 2397 | GLint zoffset, |
| 2398 | GLint x, |
| 2399 | GLint y, |
| 2400 | GLsizei width, |
| 2401 | GLsizei height, |
| 2402 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2403 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2404 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2405 | TextureType texType = TextureTargetToType(target); |
| 2406 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2407 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2408 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2409 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2410 | return false; |
| 2411 | } |
| 2412 | |
| 2413 | if (width < 0 || height < 0) |
| 2414 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2415 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2416 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2417 | } |
| 2418 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2419 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2420 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
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, kOffsetOverflow); |
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 | |
| 2426 | if (border != 0) |
| 2427 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2428 | context->validationError(GL_INVALID_VALUE, kInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2429 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2430 | } |
| 2431 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2432 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2433 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2434 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
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 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2438 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2439 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2440 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2441 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2442 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2443 | } |
| 2444 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2445 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2446 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2447 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2448 | } |
| 2449 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2450 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2451 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2452 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2453 | return false; |
| 2454 | } |
| 2455 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2456 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2457 | // 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] | 2458 | // 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] | 2459 | // 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] | 2460 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2461 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2462 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2463 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2464 | return false; |
| 2465 | } |
| 2466 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2467 | // ANGLE_multiview spec, Revision 1: |
| 2468 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2469 | // 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] | 2470 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2471 | // framebuffer is more than one. |
| 2472 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2473 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2474 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, |
| 2475 | "The active read framebuffer object has multiview attachments."); |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2476 | return false; |
| 2477 | } |
| 2478 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2479 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2480 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2481 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2482 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2483 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2484 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2485 | maxDimension = caps.max2DTextureSize; |
| 2486 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2487 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2488 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2489 | maxDimension = caps.maxCubeMapTextureSize; |
| 2490 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2491 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2492 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2493 | maxDimension = caps.maxRectangleTextureSize; |
| 2494 | break; |
| 2495 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2496 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2497 | maxDimension = caps.max2DTextureSize; |
| 2498 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2499 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2500 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2501 | maxDimension = caps.max3DTextureSize; |
| 2502 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2503 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2504 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2505 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [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 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2510 | if (!texture) |
| 2511 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2512 | context->validationError(GL_INVALID_OPERATION, kTextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2513 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2514 | } |
| 2515 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2516 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2517 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2518 | context->validationError(GL_INVALID_OPERATION, kTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2519 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2520 | } |
| 2521 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2522 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2523 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2524 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2525 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2526 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2527 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2528 | context->validationError(GL_INVALID_OPERATION, kInvalidFormat); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2529 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | if (isSubImage) |
| 2533 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2534 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2535 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2536 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2537 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2538 | context->validationError(GL_INVALID_VALUE, kOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2539 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2540 | } |
| 2541 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2542 | else |
| 2543 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2544 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2545 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2546 | context->validationError(GL_INVALID_VALUE, kCubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2547 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2548 | } |
| 2549 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2550 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2551 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2552 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2553 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2554 | } |
| 2555 | |
| 2556 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2557 | if (static_cast<int>(width) > maxLevelDimension || |
| 2558 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2559 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2560 | context->validationError(GL_INVALID_VALUE, kResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2561 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2562 | } |
| 2563 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2564 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2565 | if (textureFormatOut) |
| 2566 | { |
| 2567 | *textureFormatOut = texture->getFormat(target, level); |
| 2568 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2569 | |
| 2570 | // Detect texture copying feedback loops for WebGL. |
| 2571 | if (context->getExtensions().webglCompatibility) |
| 2572 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2573 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2574 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2575 | context->validationError(GL_INVALID_OPERATION, kFeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2576 | return false; |
| 2577 | } |
| 2578 | } |
| 2579 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2580 | return true; |
| 2581 | } |
| 2582 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2583 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2584 | // completeness check. |
| 2585 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2586 | { |
| 2587 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2588 | const State &state = context->getGLState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2589 | |
| 2590 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2591 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2592 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2593 | VertexArray *vertexArray = state.getVertexArray(); |
| 2594 | ASSERT(vertexArray); |
| 2595 | |
| 2596 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2597 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2598 | return kBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2602 | // Section 6.10 of the WebGL 1.0 spec. |
| 2603 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2604 | ASSERT(framebuffer); |
| 2605 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2606 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2607 | { |
| 2608 | ASSERT(framebuffer); |
| 2609 | const FramebufferAttachment *dsAttachment = |
| 2610 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2611 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2612 | ASSERT(stencilBits <= 8); |
| 2613 | |
| 2614 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2615 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2616 | { |
| 2617 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2618 | |
| 2619 | bool differentRefs = |
| 2620 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2621 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2622 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2623 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2624 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2625 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2626 | |
| 2627 | if (differentRefs || differentWritemasks || differentMasks) |
| 2628 | { |
| 2629 | if (!extensions.webglCompatibility) |
| 2630 | { |
| 2631 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2632 | "stencil writemasks, reference values, or stencil mask values."; |
| 2633 | } |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2634 | return kStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2635 | } |
| 2636 | } |
| 2637 | } |
| 2638 | |
| 2639 | if (!framebuffer->isComplete(context)) |
| 2640 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2641 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2642 | return kDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2646 | { |
| 2647 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2648 | { |
| 2649 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2650 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2651 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2652 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2653 | return kVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2654 | } |
| 2655 | |
| 2656 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2657 | { |
| 2658 | // This is an application error that would normally result in a crash, but we catch it |
| 2659 | // and return an error |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2660 | return kVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2661 | } |
| 2662 | } |
| 2663 | |
| 2664 | // If we are running GLES1, there is no current program. |
| 2665 | if (context->getClientVersion() >= Version(2, 0)) |
| 2666 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2667 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2668 | if (!program) |
| 2669 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2670 | return kProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2674 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2675 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2676 | // produce undefined result. |
| 2677 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2678 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2679 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2680 | return kNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2681 | } |
| 2682 | |
| 2683 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2684 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2685 | return kTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2686 | } |
| 2687 | |
| 2688 | if (extensions.multiview) |
| 2689 | { |
| 2690 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2691 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2692 | if (framebufferNumViews != programNumViews) |
| 2693 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2694 | return kMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
| 2697 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2698 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2699 | framebufferNumViews > 1) |
| 2700 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2701 | return kMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2705 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2706 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2707 | return kMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2708 | } |
| 2709 | } |
| 2710 | |
| 2711 | // Uniform buffer validation |
| 2712 | for (unsigned int uniformBlockIndex = 0; |
| 2713 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2714 | { |
| 2715 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2716 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2717 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2718 | state.getIndexedUniformBuffer(blockBinding); |
| 2719 | |
| 2720 | if (uniformBuffer.get() == nullptr) |
| 2721 | { |
| 2722 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2723 | return kUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2724 | } |
| 2725 | |
| 2726 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2727 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2728 | { |
| 2729 | // undefined behaviour |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2730 | return kUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2731 | } |
| 2732 | |
| 2733 | if (extensions.webglCompatibility && |
| 2734 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2735 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2736 | return kUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2737 | } |
| 2738 | } |
| 2739 | |
| 2740 | // Do some additonal WebGL-specific validation |
| 2741 | if (extensions.webglCompatibility) |
| 2742 | { |
| 2743 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2744 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2745 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2746 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2747 | return kTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2748 | } |
| 2749 | |
| 2750 | // Detect rendering feedback loops for WebGL. |
| 2751 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2752 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2753 | return kFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2754 | } |
| 2755 | |
| 2756 | // Detect that the vertex shader input types match the attribute types |
| 2757 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2758 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2759 | return kVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2760 | } |
| 2761 | |
| 2762 | // Detect that the color buffer types match the fragment shader output types |
| 2763 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2764 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2765 | return kDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2766 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2767 | |
| 2768 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2769 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2770 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2771 | return kVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2772 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2773 | } |
| 2774 | } |
| 2775 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2776 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2777 | } |
| 2778 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2779 | bool ValidateDrawMode(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2780 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2781 | const Extensions &extensions = context->getExtensions(); |
| 2782 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2783 | switch (mode) |
| 2784 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2785 | case PrimitiveMode::Points: |
| 2786 | case PrimitiveMode::Lines: |
| 2787 | case PrimitiveMode::LineLoop: |
| 2788 | case PrimitiveMode::LineStrip: |
| 2789 | case PrimitiveMode::Triangles: |
| 2790 | case PrimitiveMode::TriangleStrip: |
| 2791 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2792 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2793 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2794 | case PrimitiveMode::LinesAdjacency: |
| 2795 | case PrimitiveMode::LineStripAdjacency: |
| 2796 | case PrimitiveMode::TrianglesAdjacency: |
| 2797 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2798 | if (!extensions.geometryShader) |
| 2799 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2800 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2801 | return false; |
| 2802 | } |
| 2803 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2804 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2805 | context->validationError(GL_INVALID_ENUM, kInvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2806 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2807 | } |
| 2808 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2809 | // If we are running GLES1, there is no current program. |
| 2810 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2811 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2812 | const State &state = context->getGLState(); |
| 2813 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2814 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2815 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2816 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2817 | // Do geometry shader specific validations |
| 2818 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
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 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2821 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2822 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2823 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2824 | kIncompatibleDrawModeAgainstGeometryShader); |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2825 | return false; |
| 2826 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2827 | } |
| 2828 | } |
| 2829 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2830 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2833 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
| 2834 | { |
| 2835 | if (!context->getStateCache().isValidDrawMode(mode)) |
| 2836 | { |
| 2837 | return ValidateDrawMode(context, mode); |
| 2838 | } |
| 2839 | |
| 2840 | if (count < 0) |
| 2841 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2842 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2843 | return false; |
| 2844 | } |
| 2845 | |
| 2846 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2847 | if (drawStatesError) |
| 2848 | { |
| 2849 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2850 | |
| 2851 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2852 | // Incomplete. |
| 2853 | GLenum errorCode = |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2854 | (errorMessage == kDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2855 | : GL_INVALID_OPERATION); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2856 | context->validationError(errorCode, errorMessage); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2857 | return false; |
| 2858 | } |
| 2859 | |
| 2860 | return true; |
| 2861 | } |
| 2862 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2863 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2864 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2865 | GLint first, |
| 2866 | GLsizei count, |
| 2867 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2868 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2869 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2870 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2871 | context->validationError(GL_INVALID_VALUE, kNegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2872 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2873 | } |
| 2874 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2875 | if (count < 0) |
| 2876 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2877 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2878 | return false; |
| 2879 | } |
| 2880 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2881 | const State &state = context->getGLState(); |
| 2882 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2883 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2884 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2885 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2886 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2887 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2888 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2889 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2890 | return false; |
| 2891 | } |
| 2892 | |
| 2893 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2894 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2895 | context->validationError(GL_INVALID_OPERATION, kTransformFeedbackBufferTooSmall); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2896 | return false; |
| 2897 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2898 | } |
| 2899 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2900 | if (!context->getStateCache().isValidDrawMode(mode)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2901 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2902 | return ValidateDrawMode(context, mode); |
| 2903 | } |
| 2904 | |
| 2905 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2906 | if (drawStatesError) |
| 2907 | { |
| 2908 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2909 | |
| 2910 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2911 | // Incomplete. |
| 2912 | GLenum errorCode = |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2913 | (errorMessage == kDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2914 | : GL_INVALID_OPERATION); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2915 | context->validationError(errorCode, errorMessage); |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2916 | return false; |
| 2917 | } |
| 2918 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2919 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2920 | // - first < 0 has been checked as an error condition. |
| 2921 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2922 | // From this we know maxVertex will be positive, and only need to check if it overflows GLint. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2923 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2924 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2925 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2926 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2927 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2928 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2929 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2930 | return false; |
| 2931 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2932 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2933 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2934 | { |
| 2935 | return false; |
| 2936 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2937 | } |
| 2938 | |
| 2939 | return true; |
| 2940 | } |
| 2941 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2942 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2943 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2944 | GLint first, |
| 2945 | GLsizei count, |
| 2946 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2947 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2948 | if (!context->getExtensions().instancedArrays) |
| 2949 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2950 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2951 | return false; |
| 2952 | } |
| 2953 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2954 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2955 | { |
| 2956 | return false; |
| 2957 | } |
| 2958 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2959 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2960 | } |
| 2961 | |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 2962 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, DrawElementsType type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2963 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 2964 | if (!context->getStateCache().isValidDrawElementsType(type)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2965 | { |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 2966 | if (type == DrawElementsType::UnsignedInt) |
| 2967 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2968 | context->validationError(GL_INVALID_ENUM, kTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2969 | return false; |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 2970 | } |
| 2971 | |
| 2972 | ASSERT(type == DrawElementsType::InvalidEnum); |
| 2973 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
| 2974 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2975 | } |
| 2976 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2977 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2978 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2979 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2980 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2981 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2982 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2983 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2984 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2985 | if (context->getExtensions().geometryShader) |
| 2986 | { |
| 2987 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2988 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2989 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2990 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2991 | return false; |
| 2992 | } |
| 2993 | } |
| 2994 | else |
| 2995 | { |
| 2996 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2997 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2998 | // 86) |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2999 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3000 | kUnsupportedDrawModeForTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3001 | return false; |
| 3002 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3003 | } |
| 3004 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3005 | return true; |
| 3006 | } |
| 3007 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3008 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3009 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3010 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 3011 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3012 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3013 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3014 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3015 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3016 | return false; |
| 3017 | |
| 3018 | const State &state = context->getGLState(); |
| 3019 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3020 | if (!ValidateDrawBase(context, mode, count)) |
| 3021 | { |
| 3022 | return false; |
| 3023 | } |
| 3024 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3025 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 3026 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3027 | |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 3028 | GLuint typeBytes = GetDrawElementsTypeSize(type); |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3029 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3030 | |
| 3031 | if (context->getExtensions().webglCompatibility) |
| 3032 | { |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3033 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3034 | { |
| 3035 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3036 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3037 | // data type passed to the call, or an INVALID_OPERATION error is generated. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3038 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3039 | return false; |
| 3040 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3041 | |
| 3042 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3043 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3044 | // error is generated. |
| 3045 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3046 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3047 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3048 | return false; |
| 3049 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3050 | |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3051 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3052 | { |
| 3053 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3054 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3055 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3056 | context->validationError(GL_INVALID_OPERATION, kMustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3057 | return false; |
| 3058 | } |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3059 | |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3060 | if (elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3061 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3062 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3063 | kElementArrayBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3064 | return false; |
| 3065 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3066 | } |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3067 | else |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3068 | { |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3069 | if (elementArrayBuffer) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3070 | { |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3071 | if (elementArrayBuffer->isMapped()) |
| 3072 | { |
| 3073 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3074 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the |
| 3075 | // WebGL 2.0 API. https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3076 | context->validationError(GL_INVALID_OPERATION, "Index buffer is mapped."); |
| 3077 | return false; |
| 3078 | } |
| 3079 | } |
| 3080 | else if (!context->getGLState().areClientArraysEnabled()) |
| 3081 | { |
| 3082 | context->validationError(GL_INVALID_OPERATION, kMustHaveElementArrayBinding); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3083 | return false; |
| 3084 | } |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3085 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3086 | |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3087 | if (count > 0) |
| 3088 | { |
| 3089 | if (!elementArrayBuffer) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3090 | { |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3091 | if (!indices) |
| 3092 | { |
| 3093 | // This is an application error that would normally result in a crash, but we catch |
| 3094 | // it and return an error |
| 3095 | context->validationError(GL_INVALID_OPERATION, |
| 3096 | "No element array buffer and no pointer."); |
| 3097 | return false; |
| 3098 | } |
| 3099 | } |
| 3100 | else |
| 3101 | { |
| 3102 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3103 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3104 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3105 | constexpr uint64_t kMaxTypeSize = 8; |
| 3106 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3107 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3108 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3109 | |
| 3110 | uint64_t typeSize = typeBytes; |
| 3111 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3112 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3113 | |
| 3114 | // Doing the multiplication here is overflow-safe |
| 3115 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3116 | |
| 3117 | // The offset can be any value, check for overflows |
| 3118 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3119 | if (elementDataSizeNoOffset > kUint64Max - offset) |
| 3120 | { |
| 3121 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
| 3122 | return false; |
| 3123 | } |
| 3124 | |
| 3125 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3126 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
| 3127 | { |
| 3128 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
| 3129 | return false; |
| 3130 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3131 | } |
| 3132 | |
Jamie Madill | 2c0d6a9 | 2018-11-28 14:03:58 -0500 | [diff] [blame] | 3133 | if (!context->getExtensions().robustBufferAccessBehavior && primcount > 0) |
| 3134 | { |
| 3135 | // Use the parameter buffer to retrieve and cache the index range. |
| 3136 | IndexRange indexRange; |
| 3137 | ANGLE_VALIDATION_TRY(vao->getIndexRange(context, type, count, indices, &indexRange)); |
| 3138 | |
| 3139 | // If we use an index greater than our maximum supported index range, return an error. |
| 3140 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should |
| 3141 | // always return an error if possible here. |
| 3142 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
| 3143 | { |
| 3144 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxElement); |
| 3145 | return false; |
| 3146 | } |
| 3147 | |
| 3148 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
| 3149 | { |
| 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | // No op if there are no real indices in the index data (all are primitive restart). |
| 3154 | return (indexRange.vertexIndexCount > 0); |
| 3155 | } |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3158 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3159 | } |
| 3160 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3161 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3162 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3163 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 3164 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3165 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3166 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3167 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3168 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3169 | } |
| 3170 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3171 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3172 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3173 | GLsizei count, |
Jamie Madill | 8dc27f9 | 2018-11-29 11:45:44 -0500 | [diff] [blame^] | 3174 | DrawElementsType type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3175 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3176 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3177 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3178 | if (!context->getExtensions().instancedArrays) |
| 3179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3180 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3181 | return false; |
| 3182 | } |
| 3183 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3184 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3185 | { |
| 3186 | return false; |
| 3187 | } |
| 3188 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3189 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3190 | } |
| 3191 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3192 | bool ValidateFramebufferTextureBase(Context *context, |
| 3193 | GLenum target, |
| 3194 | GLenum attachment, |
| 3195 | GLuint texture, |
| 3196 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3197 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3198 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3199 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3200 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3201 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3205 | { |
| 3206 | return false; |
| 3207 | } |
| 3208 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3209 | if (texture != 0) |
| 3210 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3211 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3212 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3213 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3214 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3215 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3216 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3217 | } |
| 3218 | |
| 3219 | if (level < 0) |
| 3220 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3221 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3222 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3223 | } |
| 3224 | } |
| 3225 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3226 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3227 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3228 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3229 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3230 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3231 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3232 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3233 | } |
| 3234 | |
| 3235 | return true; |
| 3236 | } |
| 3237 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3238 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3239 | { |
| 3240 | if (program == 0) |
| 3241 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3242 | context->validationError(GL_INVALID_VALUE, kProgramDoesNotExist); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3243 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3244 | } |
| 3245 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3246 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3247 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3248 | { |
| 3249 | return false; |
| 3250 | } |
| 3251 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3252 | if (!programObject || !programObject->isLinked()) |
| 3253 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3254 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3255 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3256 | } |
| 3257 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3258 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3259 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3260 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3261 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3262 | } |
| 3263 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3264 | return true; |
| 3265 | } |
| 3266 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3267 | static bool ValidateSizedGetUniform(Context *context, |
| 3268 | GLuint program, |
| 3269 | GLint location, |
| 3270 | GLsizei bufSize, |
| 3271 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3272 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3273 | if (length) |
| 3274 | { |
| 3275 | *length = 0; |
| 3276 | } |
| 3277 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3278 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3279 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3280 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3281 | } |
| 3282 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3283 | if (bufSize < 0) |
| 3284 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3285 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3286 | return false; |
| 3287 | } |
| 3288 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3289 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3290 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3291 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3292 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3293 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3294 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3295 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3296 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3297 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3298 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3299 | } |
| 3300 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3301 | if (length) |
| 3302 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3303 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3304 | } |
| 3305 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3306 | return true; |
| 3307 | } |
| 3308 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3309 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3310 | GLuint program, |
| 3311 | GLint location, |
| 3312 | GLsizei bufSize, |
| 3313 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3314 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3315 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3316 | } |
| 3317 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3318 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3319 | GLuint program, |
| 3320 | GLint location, |
| 3321 | GLsizei bufSize, |
| 3322 | GLsizei *length, |
| 3323 | GLfloat *params) |
| 3324 | { |
| 3325 | UNIMPLEMENTED(); |
| 3326 | return false; |
| 3327 | } |
| 3328 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3329 | bool ValidateGetnUniformivEXT(Context *context, |
| 3330 | GLuint program, |
| 3331 | GLint location, |
| 3332 | GLsizei bufSize, |
| 3333 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3334 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3335 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3336 | } |
| 3337 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3338 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3339 | GLuint program, |
| 3340 | GLint location, |
| 3341 | GLsizei bufSize, |
| 3342 | GLsizei *length, |
| 3343 | GLint *params) |
| 3344 | { |
| 3345 | UNIMPLEMENTED(); |
| 3346 | return false; |
| 3347 | } |
| 3348 | |
| 3349 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3350 | GLuint program, |
| 3351 | GLint location, |
| 3352 | GLsizei bufSize, |
| 3353 | GLsizei *length, |
| 3354 | GLuint *params) |
| 3355 | { |
| 3356 | UNIMPLEMENTED(); |
| 3357 | return false; |
| 3358 | } |
| 3359 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3360 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3361 | GLuint program, |
| 3362 | GLint location, |
| 3363 | GLsizei bufSize, |
| 3364 | GLsizei *length, |
| 3365 | GLfloat *params) |
| 3366 | { |
| 3367 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3368 | { |
| 3369 | return false; |
| 3370 | } |
| 3371 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3372 | GLsizei writeLength = 0; |
| 3373 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3374 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3375 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3376 | { |
| 3377 | return false; |
| 3378 | } |
| 3379 | |
| 3380 | SetRobustLengthParam(length, writeLength); |
| 3381 | |
| 3382 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3383 | } |
| 3384 | |
| 3385 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3386 | GLuint program, |
| 3387 | GLint location, |
| 3388 | GLsizei bufSize, |
| 3389 | GLsizei *length, |
| 3390 | GLint *params) |
| 3391 | { |
| 3392 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3393 | { |
| 3394 | return false; |
| 3395 | } |
| 3396 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3397 | GLsizei writeLength = 0; |
| 3398 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3399 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3400 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3401 | { |
| 3402 | return false; |
| 3403 | } |
| 3404 | |
| 3405 | SetRobustLengthParam(length, writeLength); |
| 3406 | |
| 3407 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3408 | } |
| 3409 | |
| 3410 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3411 | GLuint program, |
| 3412 | GLint location, |
| 3413 | GLsizei bufSize, |
| 3414 | GLsizei *length, |
| 3415 | GLuint *params) |
| 3416 | { |
| 3417 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3418 | { |
| 3419 | return false; |
| 3420 | } |
| 3421 | |
| 3422 | if (context->getClientMajorVersion() < 3) |
| 3423 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3424 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3425 | return false; |
| 3426 | } |
| 3427 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3428 | GLsizei writeLength = 0; |
| 3429 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3430 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3431 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3432 | { |
| 3433 | return false; |
| 3434 | } |
| 3435 | |
| 3436 | SetRobustLengthParam(length, writeLength); |
| 3437 | |
| 3438 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3439 | } |
| 3440 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3441 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3442 | GLenum target, |
| 3443 | GLsizei numAttachments, |
| 3444 | const GLenum *attachments, |
| 3445 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3446 | { |
| 3447 | if (numAttachments < 0) |
| 3448 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3449 | context->validationError(GL_INVALID_VALUE, kNegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3450 | return false; |
| 3451 | } |
| 3452 | |
| 3453 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3454 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3455 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3456 | { |
| 3457 | if (defaultFramebuffer) |
| 3458 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3459 | context->validationError(GL_INVALID_ENUM, kDefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3460 | return false; |
| 3461 | } |
| 3462 | |
| 3463 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3464 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3465 | context->validationError(GL_INVALID_OPERATION, |
| 3466 | "Requested color attachment is " |
| 3467 | "greater than the maximum supported " |
| 3468 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3469 | return false; |
| 3470 | } |
| 3471 | } |
| 3472 | else |
| 3473 | { |
| 3474 | switch (attachments[i]) |
| 3475 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3476 | case GL_DEPTH_ATTACHMENT: |
| 3477 | case GL_STENCIL_ATTACHMENT: |
| 3478 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3479 | if (defaultFramebuffer) |
| 3480 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3481 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3482 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3483 | return false; |
| 3484 | } |
| 3485 | break; |
| 3486 | case GL_COLOR: |
| 3487 | case GL_DEPTH: |
| 3488 | case GL_STENCIL: |
| 3489 | if (!defaultFramebuffer) |
| 3490 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3491 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3492 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3493 | return false; |
| 3494 | } |
| 3495 | break; |
| 3496 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3497 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3498 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3499 | } |
| 3500 | } |
| 3501 | } |
| 3502 | |
| 3503 | return true; |
| 3504 | } |
| 3505 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3506 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3507 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3508 | if (!context->getExtensions().debugMarker) |
| 3509 | { |
| 3510 | // The debug marker calls should not set error state |
| 3511 | // 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] | 3512 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3513 | return false; |
| 3514 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3515 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3516 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3517 | if (length < 0) |
| 3518 | { |
| 3519 | return false; |
| 3520 | } |
| 3521 | |
| 3522 | if (marker == nullptr) |
| 3523 | { |
| 3524 | return false; |
| 3525 | } |
| 3526 | |
| 3527 | return true; |
| 3528 | } |
| 3529 | |
| 3530 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3531 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3532 | if (!context->getExtensions().debugMarker) |
| 3533 | { |
| 3534 | // The debug marker calls should not set error state |
| 3535 | // 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] | 3536 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3537 | return false; |
| 3538 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3539 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3540 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3541 | if (length < 0) |
| 3542 | { |
| 3543 | return false; |
| 3544 | } |
| 3545 | |
| 3546 | if (length > 0 && marker == nullptr) |
| 3547 | { |
| 3548 | return false; |
| 3549 | } |
| 3550 | |
| 3551 | return true; |
| 3552 | } |
| 3553 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3554 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3555 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3556 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3557 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3558 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3559 | return false; |
| 3560 | } |
| 3561 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3562 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3563 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3564 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3565 | if (!context->getExtensions().eglImage) |
| 3566 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3567 | context->validationError(GL_INVALID_ENUM, |
| 3568 | "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3569 | } |
| 3570 | break; |
| 3571 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3572 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3573 | if (!context->getExtensions().eglImageExternal) |
| 3574 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3575 | context->validationError(GL_INVALID_ENUM, |
| 3576 | "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3577 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3578 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3579 | break; |
| 3580 | |
| 3581 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3582 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3583 | return false; |
| 3584 | } |
| 3585 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3586 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3587 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3588 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3589 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3590 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3591 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3592 | return false; |
| 3593 | } |
| 3594 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3595 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3596 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3597 | context->validationError(GL_INVALID_OPERATION, |
| 3598 | "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3599 | return false; |
| 3600 | } |
| 3601 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3602 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3603 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3604 | context->validationError(GL_INVALID_OPERATION, |
| 3605 | "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3606 | return false; |
| 3607 | } |
| 3608 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3609 | return true; |
| 3610 | } |
| 3611 | |
| 3612 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3613 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3614 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3615 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3616 | if (!context->getExtensions().eglImage) |
| 3617 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3618 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3619 | return false; |
| 3620 | } |
| 3621 | |
| 3622 | switch (target) |
| 3623 | { |
| 3624 | case GL_RENDERBUFFER: |
| 3625 | break; |
| 3626 | |
| 3627 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3628 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3629 | return false; |
| 3630 | } |
| 3631 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3632 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3633 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3634 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3635 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3636 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3637 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3638 | return false; |
| 3639 | } |
| 3640 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3641 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3642 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3643 | context->validationError(GL_INVALID_OPERATION, |
| 3644 | "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3645 | return false; |
| 3646 | } |
| 3647 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3648 | return true; |
| 3649 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3650 | |
| 3651 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3652 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3653 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3654 | { |
| 3655 | // The default VAO should always exist |
| 3656 | ASSERT(array != 0); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3657 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexArray); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3658 | return false; |
| 3659 | } |
| 3660 | |
| 3661 | return true; |
| 3662 | } |
| 3663 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3664 | bool ValidateProgramBinaryBase(Context *context, |
| 3665 | GLuint program, |
| 3666 | GLenum binaryFormat, |
| 3667 | const void *binary, |
| 3668 | GLint length) |
| 3669 | { |
| 3670 | Program *programObject = GetValidProgram(context, program); |
| 3671 | if (programObject == nullptr) |
| 3672 | { |
| 3673 | return false; |
| 3674 | } |
| 3675 | |
| 3676 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3677 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3678 | programBinaryFormats.end()) |
| 3679 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3680 | context->validationError(GL_INVALID_ENUM, "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3681 | return false; |
| 3682 | } |
| 3683 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3684 | if (context->hasActiveTransformFeedback(program)) |
| 3685 | { |
| 3686 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3687 | context->validationError(GL_INVALID_OPERATION, |
| 3688 | "Cannot change program binary while program " |
| 3689 | "is associated with an active transform " |
| 3690 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3691 | return false; |
| 3692 | } |
| 3693 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3694 | return true; |
| 3695 | } |
| 3696 | |
| 3697 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3698 | GLuint program, |
| 3699 | GLsizei bufSize, |
| 3700 | GLsizei *length, |
| 3701 | GLenum *binaryFormat, |
| 3702 | void *binary) |
| 3703 | { |
| 3704 | Program *programObject = GetValidProgram(context, program); |
| 3705 | if (programObject == nullptr) |
| 3706 | { |
| 3707 | return false; |
| 3708 | } |
| 3709 | |
| 3710 | if (!programObject->isLinked()) |
| 3711 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3712 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3713 | return false; |
| 3714 | } |
| 3715 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3716 | if (context->getCaps().programBinaryFormats.empty()) |
| 3717 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3718 | context->validationError(GL_INVALID_OPERATION, "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3719 | return false; |
| 3720 | } |
| 3721 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3722 | return true; |
| 3723 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3724 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3725 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3726 | { |
| 3727 | // 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] | 3728 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3729 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3730 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3731 | return false; |
| 3732 | } |
| 3733 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3734 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3735 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3736 | return false; |
| 3737 | } |
| 3738 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3739 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3740 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3741 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3742 | |
| 3743 | // This should come first before the check for the default frame buffer |
| 3744 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3745 | // rather than INVALID_OPERATION |
| 3746 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3747 | { |
| 3748 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3749 | |
| 3750 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3751 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3752 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3753 | { |
| 3754 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3755 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3756 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3757 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3758 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3759 | context->validationError(GL_INVALID_ENUM, "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3760 | return false; |
| 3761 | } |
| 3762 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3763 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3764 | context->validationError(GL_INVALID_OPERATION, |
| 3765 | "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3766 | return false; |
| 3767 | } |
| 3768 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3769 | frameBufferId != 0) |
| 3770 | { |
| 3771 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3772 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3773 | context->validationError(GL_INVALID_OPERATION, |
| 3774 | "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3775 | return false; |
| 3776 | } |
| 3777 | } |
| 3778 | |
| 3779 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3780 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3781 | if (frameBufferId == 0) |
| 3782 | { |
| 3783 | if (n != 1) |
| 3784 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3785 | context->validationError(GL_INVALID_OPERATION, |
| 3786 | "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3791 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3792 | context->validationError( |
| 3793 | GL_INVALID_OPERATION, |
| 3794 | "Only NONE or BACK are valid values when drawing to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3795 | return false; |
| 3796 | } |
| 3797 | } |
| 3798 | |
| 3799 | return true; |
| 3800 | } |
| 3801 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3802 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3803 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3804 | GLenum pname, |
| 3805 | GLsizei *length, |
| 3806 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3807 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3808 | if (length) |
| 3809 | { |
| 3810 | *length = 0; |
| 3811 | } |
| 3812 | |
| 3813 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3814 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3815 | context->validationError( |
| 3816 | GL_INVALID_OPERATION, |
| 3817 | "Context does not support OpenGL ES 3.0 or GL_OES_mapbuffer is not enabled."); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3818 | return false; |
| 3819 | } |
| 3820 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3821 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3822 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3823 | context->validationError(GL_INVALID_ENUM, "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3824 | return false; |
| 3825 | } |
| 3826 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3827 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3828 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3829 | case GL_BUFFER_MAP_POINTER: |
| 3830 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3831 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3832 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3833 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3834 | return false; |
| 3835 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3836 | |
| 3837 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3838 | // target bound to zero generate an INVALID_OPERATION error." |
| 3839 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3840 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3841 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3842 | context->validationError(GL_INVALID_OPERATION, |
| 3843 | "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3844 | return false; |
| 3845 | } |
| 3846 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3847 | if (length) |
| 3848 | { |
| 3849 | *length = 1; |
| 3850 | } |
| 3851 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3852 | return true; |
| 3853 | } |
| 3854 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3855 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3856 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3857 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3858 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3859 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3860 | return false; |
| 3861 | } |
| 3862 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3863 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3864 | |
| 3865 | if (buffer == nullptr || !buffer->isMapped()) |
| 3866 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3867 | context->validationError(GL_INVALID_OPERATION, "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3868 | return false; |
| 3869 | } |
| 3870 | |
| 3871 | return true; |
| 3872 | } |
| 3873 | |
| 3874 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3875 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3876 | GLintptr offset, |
| 3877 | GLsizeiptr length, |
| 3878 | GLbitfield access) |
| 3879 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3880 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3881 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3882 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3883 | return false; |
| 3884 | } |
| 3885 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3886 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3887 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3888 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3889 | return false; |
| 3890 | } |
| 3891 | |
| 3892 | if (length < 0) |
| 3893 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3894 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3895 | return false; |
| 3896 | } |
| 3897 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3898 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3899 | |
| 3900 | if (!buffer) |
| 3901 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3902 | context->validationError(GL_INVALID_OPERATION, "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3903 | return false; |
| 3904 | } |
| 3905 | |
| 3906 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3907 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3908 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3909 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3910 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3911 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3912 | context->validationError(GL_INVALID_VALUE, |
| 3913 | "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3914 | return false; |
| 3915 | } |
| 3916 | |
| 3917 | // Check for invalid bits in the mask |
| 3918 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3919 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3920 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3921 | |
| 3922 | if (access & ~(allAccessBits)) |
| 3923 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3924 | context->validationError(GL_INVALID_VALUE, "Invalid access bits"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3925 | return false; |
| 3926 | } |
| 3927 | |
| 3928 | if (length == 0) |
| 3929 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3930 | context->validationError(GL_INVALID_OPERATION, "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3931 | return false; |
| 3932 | } |
| 3933 | |
| 3934 | if (buffer->isMapped()) |
| 3935 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3936 | context->validationError(GL_INVALID_OPERATION, "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | // Check for invalid bit combinations |
| 3941 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3942 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3943 | context->validationError(GL_INVALID_OPERATION, |
| 3944 | "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3945 | return false; |
| 3946 | } |
| 3947 | |
| 3948 | GLbitfield writeOnlyBits = |
| 3949 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3950 | |
| 3951 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3952 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3953 | context->validationError(GL_INVALID_OPERATION, |
| 3954 | "Invalid access bits when mapping buffer for reading"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3955 | return false; |
| 3956 | } |
| 3957 | |
| 3958 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3959 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3960 | context->validationError( |
| 3961 | GL_INVALID_OPERATION, |
| 3962 | "The explicit flushing bit may only be set if the buffer is mapped for writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3963 | return false; |
| 3964 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3965 | |
| 3966 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3967 | } |
| 3968 | |
| 3969 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3970 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3971 | GLintptr offset, |
| 3972 | GLsizeiptr length) |
| 3973 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3974 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3975 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3976 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3977 | return false; |
| 3978 | } |
| 3979 | |
| 3980 | if (length < 0) |
| 3981 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3982 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3983 | return false; |
| 3984 | } |
| 3985 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3986 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3987 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3988 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3989 | return false; |
| 3990 | } |
| 3991 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3992 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3993 | |
| 3994 | if (buffer == nullptr) |
| 3995 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3996 | context->validationError(GL_INVALID_OPERATION, "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3997 | return false; |
| 3998 | } |
| 3999 | |
| 4000 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4001 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4002 | context->validationError(GL_INVALID_OPERATION, |
| 4003 | "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4004 | return false; |
| 4005 | } |
| 4006 | |
| 4007 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4008 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4009 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4010 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4011 | if (!checkedSize.IsValid() || |
| 4012 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4013 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4014 | context->validationError(GL_INVALID_VALUE, |
| 4015 | "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4016 | return false; |
| 4017 | } |
| 4018 | |
| 4019 | return true; |
| 4020 | } |
| 4021 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4022 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4023 | { |
| 4024 | if (n < 0) |
| 4025 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4026 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4027 | return false; |
| 4028 | } |
| 4029 | return true; |
| 4030 | } |
| 4031 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4032 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4033 | { |
| 4034 | if (!context->getExtensions().robustClientMemory) |
| 4035 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4036 | context->validationError(GL_INVALID_OPERATION, |
| 4037 | "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4038 | return false; |
| 4039 | } |
| 4040 | |
| 4041 | if (bufSize < 0) |
| 4042 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4043 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4044 | return false; |
| 4045 | } |
| 4046 | |
| 4047 | return true; |
| 4048 | } |
| 4049 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4050 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4051 | { |
| 4052 | if (bufSize < numParams) |
| 4053 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4054 | context->validationError(GL_INVALID_OPERATION, |
| 4055 | "More parameters are required than were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4056 | return false; |
| 4057 | } |
| 4058 | |
| 4059 | return true; |
| 4060 | } |
| 4061 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4062 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4063 | GLenum target, |
| 4064 | GLenum attachment, |
| 4065 | GLenum pname, |
| 4066 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4067 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4068 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4069 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4070 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4071 | return false; |
| 4072 | } |
| 4073 | |
| 4074 | int clientVersion = context->getClientMajorVersion(); |
| 4075 | |
| 4076 | switch (pname) |
| 4077 | { |
| 4078 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4079 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4080 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4081 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4082 | break; |
| 4083 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4084 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4085 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4086 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4087 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4088 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4089 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4090 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4091 | return false; |
| 4092 | } |
| 4093 | break; |
| 4094 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4095 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4096 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4097 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4098 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4099 | return false; |
| 4100 | } |
| 4101 | break; |
| 4102 | |
| 4103 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4104 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4105 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4106 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4107 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4108 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4109 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4110 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4111 | if (clientVersion < 3) |
| 4112 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4113 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4114 | return false; |
| 4115 | } |
| 4116 | break; |
| 4117 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4118 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4119 | if (!context->getExtensions().geometryShader) |
| 4120 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4121 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4122 | return false; |
| 4123 | } |
| 4124 | break; |
| 4125 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4126 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4127 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4128 | return false; |
| 4129 | } |
| 4130 | |
| 4131 | // Determine if the attachment is a valid enum |
| 4132 | switch (attachment) |
| 4133 | { |
| 4134 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4135 | case GL_DEPTH: |
| 4136 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4137 | if (clientVersion < 3) |
| 4138 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4139 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4140 | return false; |
| 4141 | } |
| 4142 | break; |
| 4143 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4144 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4145 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4147 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4148 | return false; |
| 4149 | } |
| 4150 | break; |
| 4151 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4152 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4153 | case GL_DEPTH_ATTACHMENT: |
| 4154 | case GL_STENCIL_ATTACHMENT: |
| 4155 | break; |
| 4156 | |
| 4157 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4158 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4159 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4160 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4161 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4162 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4163 | return false; |
| 4164 | } |
| 4165 | break; |
| 4166 | } |
| 4167 | |
| 4168 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4169 | ASSERT(framebuffer); |
| 4170 | |
| 4171 | if (framebuffer->id() == 0) |
| 4172 | { |
| 4173 | if (clientVersion < 3) |
| 4174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4175 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4176 | return false; |
| 4177 | } |
| 4178 | |
| 4179 | switch (attachment) |
| 4180 | { |
| 4181 | case GL_BACK: |
| 4182 | case GL_DEPTH: |
| 4183 | case GL_STENCIL: |
| 4184 | break; |
| 4185 | |
| 4186 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4187 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | } |
| 4191 | else |
| 4192 | { |
| 4193 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4194 | { |
| 4195 | // Valid attachment query |
| 4196 | } |
| 4197 | else |
| 4198 | { |
| 4199 | switch (attachment) |
| 4200 | { |
| 4201 | case GL_DEPTH_ATTACHMENT: |
| 4202 | case GL_STENCIL_ATTACHMENT: |
| 4203 | break; |
| 4204 | |
| 4205 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4206 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4207 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4208 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4209 | return false; |
| 4210 | } |
| 4211 | break; |
| 4212 | |
| 4213 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4214 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4215 | return false; |
| 4216 | } |
| 4217 | } |
| 4218 | } |
| 4219 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4220 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4221 | if (attachmentObject) |
| 4222 | { |
| 4223 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4224 | attachmentObject->type() == GL_TEXTURE || |
| 4225 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4226 | |
| 4227 | switch (pname) |
| 4228 | { |
| 4229 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4230 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4231 | attachmentObject->type() != GL_TEXTURE) |
| 4232 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4233 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4234 | return false; |
| 4235 | } |
| 4236 | break; |
| 4237 | |
| 4238 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4239 | if (attachmentObject->type() != GL_TEXTURE) |
| 4240 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4241 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4242 | return false; |
| 4243 | } |
| 4244 | break; |
| 4245 | |
| 4246 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4247 | if (attachmentObject->type() != GL_TEXTURE) |
| 4248 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4249 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4250 | return false; |
| 4251 | } |
| 4252 | break; |
| 4253 | |
| 4254 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4255 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4256 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4257 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4258 | return false; |
| 4259 | } |
| 4260 | break; |
| 4261 | |
| 4262 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4263 | if (attachmentObject->type() != GL_TEXTURE) |
| 4264 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4265 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4266 | return false; |
| 4267 | } |
| 4268 | break; |
| 4269 | |
| 4270 | default: |
| 4271 | break; |
| 4272 | } |
| 4273 | } |
| 4274 | else |
| 4275 | { |
| 4276 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4277 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4278 | |
| 4279 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4280 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4281 | // INVALID_OPERATION for all other pnames |
| 4282 | |
| 4283 | switch (pname) |
| 4284 | { |
| 4285 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4286 | break; |
| 4287 | |
| 4288 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4289 | if (clientVersion < 3) |
| 4290 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4291 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4292 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4293 | return false; |
| 4294 | } |
| 4295 | break; |
| 4296 | |
| 4297 | default: |
| 4298 | if (clientVersion < 3) |
| 4299 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4300 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4301 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4302 | return false; |
| 4303 | } |
| 4304 | else |
| 4305 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4306 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4307 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | } |
| 4311 | } |
| 4312 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4313 | if (numParams) |
| 4314 | { |
| 4315 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4316 | { |
| 4317 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4318 | // parameters. |
| 4319 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4320 | *numParams = numViews * 2; |
| 4321 | } |
| 4322 | else |
| 4323 | { |
| 4324 | // For all other queries we can have only one output parameter. |
| 4325 | *numParams = 1; |
| 4326 | } |
| 4327 | } |
| 4328 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4329 | return true; |
| 4330 | } |
| 4331 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4332 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4333 | GLenum target, |
| 4334 | GLenum attachment, |
| 4335 | GLenum pname, |
| 4336 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4337 | GLsizei *length, |
| 4338 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4339 | { |
| 4340 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4341 | { |
| 4342 | return false; |
| 4343 | } |
| 4344 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4345 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4346 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4347 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4348 | { |
| 4349 | return false; |
| 4350 | } |
| 4351 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4352 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4353 | { |
| 4354 | return false; |
| 4355 | } |
| 4356 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4357 | SetRobustLengthParam(length, numParams); |
| 4358 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4359 | return true; |
| 4360 | } |
| 4361 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4362 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4363 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4364 | GLenum pname, |
| 4365 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4366 | GLsizei *length, |
| 4367 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4368 | { |
| 4369 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4370 | { |
| 4371 | return false; |
| 4372 | } |
| 4373 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4374 | GLsizei numParams = 0; |
| 4375 | |
| 4376 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4377 | { |
| 4378 | return false; |
| 4379 | } |
| 4380 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4381 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4382 | { |
| 4383 | return false; |
| 4384 | } |
| 4385 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4386 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4387 | return true; |
| 4388 | } |
| 4389 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4390 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4391 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4392 | GLenum pname, |
| 4393 | GLsizei bufSize, |
| 4394 | GLsizei *length, |
| 4395 | GLint64 *params) |
| 4396 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4397 | GLsizei numParams = 0; |
| 4398 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4399 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4400 | { |
| 4401 | return false; |
| 4402 | } |
| 4403 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4404 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4405 | { |
| 4406 | return false; |
| 4407 | } |
| 4408 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4409 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4410 | { |
| 4411 | return false; |
| 4412 | } |
| 4413 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4414 | SetRobustLengthParam(length, numParams); |
| 4415 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4416 | return true; |
| 4417 | } |
| 4418 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4419 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4420 | { |
| 4421 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4422 | if (numParams) |
| 4423 | { |
| 4424 | *numParams = 1; |
| 4425 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4426 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4427 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4428 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4429 | ? GetValidProgramNoResolve(context, program) |
| 4430 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4431 | if (!programObject) |
| 4432 | { |
| 4433 | return false; |
| 4434 | } |
| 4435 | |
| 4436 | switch (pname) |
| 4437 | { |
| 4438 | case GL_DELETE_STATUS: |
| 4439 | case GL_LINK_STATUS: |
| 4440 | case GL_VALIDATE_STATUS: |
| 4441 | case GL_INFO_LOG_LENGTH: |
| 4442 | case GL_ATTACHED_SHADERS: |
| 4443 | case GL_ACTIVE_ATTRIBUTES: |
| 4444 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4445 | case GL_ACTIVE_UNIFORMS: |
| 4446 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4447 | break; |
| 4448 | |
| 4449 | case GL_PROGRAM_BINARY_LENGTH: |
| 4450 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4451 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4452 | context->validationError(GL_INVALID_ENUM, |
| 4453 | "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4454 | "requires GL_OES_get_program_binary or " |
| 4455 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4456 | return false; |
| 4457 | } |
| 4458 | break; |
| 4459 | |
| 4460 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4461 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4462 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4463 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4464 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4465 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4466 | if (context->getClientMajorVersion() < 3) |
| 4467 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4468 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4469 | return false; |
| 4470 | } |
| 4471 | break; |
| 4472 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4473 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4474 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4475 | if (context->getClientVersion() < Version(3, 1)) |
| 4476 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4477 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4478 | return false; |
| 4479 | } |
| 4480 | break; |
| 4481 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4482 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4483 | if (context->getClientVersion() < Version(3, 1)) |
| 4484 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4485 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4486 | return false; |
| 4487 | } |
| 4488 | |
| 4489 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4490 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4491 | // program which has not been linked successfully, or which does not contain objects to |
| 4492 | // form a compute shader. |
| 4493 | if (!programObject->isLinked()) |
| 4494 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4495 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4496 | return false; |
| 4497 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4498 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4499 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4500 | context->validationError(GL_INVALID_OPERATION, kNoActiveComputeShaderStage); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4501 | return false; |
| 4502 | } |
| 4503 | break; |
| 4504 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4505 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4506 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4507 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4508 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4509 | if (!context->getExtensions().geometryShader) |
| 4510 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4511 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4512 | return false; |
| 4513 | } |
| 4514 | |
| 4515 | // [EXT_geometry_shader] Chapter 7.12 |
| 4516 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4517 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4518 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4519 | // successfully, or which does not contain objects to form a geometry shader. |
| 4520 | if (!programObject->isLinked()) |
| 4521 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4522 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4523 | return false; |
| 4524 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4525 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4526 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4527 | context->validationError(GL_INVALID_OPERATION, kNoActiveGeometryShaderStage); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4528 | return false; |
| 4529 | } |
| 4530 | break; |
| 4531 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4532 | case GL_COMPLETION_STATUS_KHR: |
| 4533 | if (!context->getExtensions().parallelShaderCompile) |
| 4534 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4535 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4536 | return false; |
| 4537 | } |
| 4538 | break; |
| 4539 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4540 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4541 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4542 | return false; |
| 4543 | } |
| 4544 | |
| 4545 | return true; |
| 4546 | } |
| 4547 | |
| 4548 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4549 | GLuint program, |
| 4550 | GLenum pname, |
| 4551 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4552 | GLsizei *length, |
| 4553 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4554 | { |
| 4555 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4556 | { |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4560 | GLsizei numParams = 0; |
| 4561 | |
| 4562 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4563 | { |
| 4564 | return false; |
| 4565 | } |
| 4566 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4567 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4568 | { |
| 4569 | return false; |
| 4570 | } |
| 4571 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4572 | SetRobustLengthParam(length, numParams); |
| 4573 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4574 | return true; |
| 4575 | } |
| 4576 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4577 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4578 | GLenum target, |
| 4579 | GLenum pname, |
| 4580 | GLsizei bufSize, |
| 4581 | GLsizei *length, |
| 4582 | GLint *params) |
| 4583 | { |
| 4584 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4585 | { |
| 4586 | return false; |
| 4587 | } |
| 4588 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4589 | GLsizei numParams = 0; |
| 4590 | |
| 4591 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4592 | { |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4596 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4597 | { |
| 4598 | return false; |
| 4599 | } |
| 4600 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4601 | SetRobustLengthParam(length, numParams); |
| 4602 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4603 | return true; |
| 4604 | } |
| 4605 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4606 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4607 | GLuint shader, |
| 4608 | GLenum pname, |
| 4609 | GLsizei bufSize, |
| 4610 | GLsizei *length, |
| 4611 | GLint *params) |
| 4612 | { |
| 4613 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4614 | { |
| 4615 | return false; |
| 4616 | } |
| 4617 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4618 | GLsizei numParams = 0; |
| 4619 | |
| 4620 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4621 | { |
| 4622 | return false; |
| 4623 | } |
| 4624 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4625 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4626 | { |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4630 | SetRobustLengthParam(length, numParams); |
| 4631 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4632 | return true; |
| 4633 | } |
| 4634 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4635 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4636 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4637 | GLenum pname, |
| 4638 | GLsizei bufSize, |
| 4639 | GLsizei *length, |
| 4640 | GLfloat *params) |
| 4641 | { |
| 4642 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4643 | { |
| 4644 | return false; |
| 4645 | } |
| 4646 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4647 | GLsizei numParams = 0; |
| 4648 | |
| 4649 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4650 | { |
| 4651 | return false; |
| 4652 | } |
| 4653 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4654 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4655 | { |
| 4656 | return false; |
| 4657 | } |
| 4658 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4659 | SetRobustLengthParam(length, numParams); |
| 4660 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4661 | return true; |
| 4662 | } |
| 4663 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4664 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4665 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4666 | GLenum pname, |
| 4667 | GLsizei bufSize, |
| 4668 | GLsizei *length, |
| 4669 | GLint *params) |
| 4670 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4671 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4672 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4673 | { |
| 4674 | return false; |
| 4675 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4676 | GLsizei numParams = 0; |
| 4677 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4678 | { |
| 4679 | return false; |
| 4680 | } |
| 4681 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4682 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4683 | { |
| 4684 | return false; |
| 4685 | } |
| 4686 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4687 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4688 | return true; |
| 4689 | } |
| 4690 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4691 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4692 | TextureType target, |
| 4693 | GLenum pname, |
| 4694 | GLsizei bufSize, |
| 4695 | GLsizei *length, |
| 4696 | GLint *params) |
| 4697 | { |
| 4698 | UNIMPLEMENTED(); |
| 4699 | return false; |
| 4700 | } |
| 4701 | |
| 4702 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4703 | TextureType target, |
| 4704 | GLenum pname, |
| 4705 | GLsizei bufSize, |
| 4706 | GLsizei *length, |
| 4707 | GLuint *params) |
| 4708 | { |
| 4709 | UNIMPLEMENTED(); |
| 4710 | return false; |
| 4711 | } |
| 4712 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4713 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4714 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4715 | GLenum pname, |
| 4716 | GLsizei bufSize, |
| 4717 | const GLfloat *params) |
| 4718 | { |
| 4719 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4720 | { |
| 4721 | return false; |
| 4722 | } |
| 4723 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4724 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4725 | } |
| 4726 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4727 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4728 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4729 | GLenum pname, |
| 4730 | GLsizei bufSize, |
| 4731 | const GLint *params) |
| 4732 | { |
| 4733 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4734 | { |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4738 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4739 | } |
| 4740 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4741 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4742 | TextureType target, |
| 4743 | GLenum pname, |
| 4744 | GLsizei bufSize, |
| 4745 | const GLint *params) |
| 4746 | { |
| 4747 | UNIMPLEMENTED(); |
| 4748 | return false; |
| 4749 | } |
| 4750 | |
| 4751 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4752 | TextureType target, |
| 4753 | GLenum pname, |
| 4754 | GLsizei bufSize, |
| 4755 | const GLuint *params) |
| 4756 | { |
| 4757 | UNIMPLEMENTED(); |
| 4758 | return false; |
| 4759 | } |
| 4760 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4761 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4762 | GLuint sampler, |
| 4763 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4764 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4765 | GLsizei *length, |
| 4766 | GLfloat *params) |
| 4767 | { |
| 4768 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4769 | { |
| 4770 | return false; |
| 4771 | } |
| 4772 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4773 | GLsizei numParams = 0; |
| 4774 | |
| 4775 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4776 | { |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4780 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4781 | { |
| 4782 | return false; |
| 4783 | } |
| 4784 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4785 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4786 | return true; |
| 4787 | } |
| 4788 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4789 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4790 | GLuint sampler, |
| 4791 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4792 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4793 | GLsizei *length, |
| 4794 | GLint *params) |
| 4795 | { |
| 4796 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4797 | { |
| 4798 | return false; |
| 4799 | } |
| 4800 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4801 | GLsizei numParams = 0; |
| 4802 | |
| 4803 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4804 | { |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4808 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4809 | { |
| 4810 | return false; |
| 4811 | } |
| 4812 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4813 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4814 | return true; |
| 4815 | } |
| 4816 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4817 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4818 | GLuint sampler, |
| 4819 | GLenum pname, |
| 4820 | GLsizei bufSize, |
| 4821 | GLsizei *length, |
| 4822 | GLint *params) |
| 4823 | { |
| 4824 | UNIMPLEMENTED(); |
| 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4829 | GLuint sampler, |
| 4830 | GLenum pname, |
| 4831 | GLsizei bufSize, |
| 4832 | GLsizei *length, |
| 4833 | GLuint *params) |
| 4834 | { |
| 4835 | UNIMPLEMENTED(); |
| 4836 | return false; |
| 4837 | } |
| 4838 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4839 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4840 | GLuint sampler, |
| 4841 | GLenum pname, |
| 4842 | GLsizei bufSize, |
| 4843 | const GLfloat *params) |
| 4844 | { |
| 4845 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4846 | { |
| 4847 | return false; |
| 4848 | } |
| 4849 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4850 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4851 | } |
| 4852 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4853 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4854 | GLuint sampler, |
| 4855 | GLenum pname, |
| 4856 | GLsizei bufSize, |
| 4857 | const GLint *params) |
| 4858 | { |
| 4859 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4860 | { |
| 4861 | return false; |
| 4862 | } |
| 4863 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4864 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4865 | } |
| 4866 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4867 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4868 | GLuint sampler, |
| 4869 | GLenum pname, |
| 4870 | GLsizei bufSize, |
| 4871 | const GLint *param) |
| 4872 | { |
| 4873 | UNIMPLEMENTED(); |
| 4874 | return false; |
| 4875 | } |
| 4876 | |
| 4877 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4878 | GLuint sampler, |
| 4879 | GLenum pname, |
| 4880 | GLsizei bufSize, |
| 4881 | const GLuint *param) |
| 4882 | { |
| 4883 | UNIMPLEMENTED(); |
| 4884 | return false; |
| 4885 | } |
| 4886 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4887 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4888 | GLuint index, |
| 4889 | GLenum pname, |
| 4890 | GLsizei bufSize, |
| 4891 | GLsizei *length, |
| 4892 | GLfloat *params) |
| 4893 | { |
| 4894 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4895 | { |
| 4896 | return false; |
| 4897 | } |
| 4898 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4899 | GLsizei writeLength = 0; |
| 4900 | |
| 4901 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4902 | { |
| 4903 | return false; |
| 4904 | } |
| 4905 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4906 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4907 | { |
| 4908 | return false; |
| 4909 | } |
| 4910 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4911 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4912 | return true; |
| 4913 | } |
| 4914 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4915 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4916 | GLuint index, |
| 4917 | GLenum pname, |
| 4918 | GLsizei bufSize, |
| 4919 | GLsizei *length, |
| 4920 | GLint *params) |
| 4921 | { |
| 4922 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4923 | { |
| 4924 | return false; |
| 4925 | } |
| 4926 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4927 | GLsizei writeLength = 0; |
| 4928 | |
| 4929 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4930 | { |
| 4931 | return false; |
| 4932 | } |
| 4933 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4934 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4935 | { |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4939 | SetRobustLengthParam(length, writeLength); |
| 4940 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4941 | return true; |
| 4942 | } |
| 4943 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4944 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4945 | GLuint index, |
| 4946 | GLenum pname, |
| 4947 | GLsizei bufSize, |
| 4948 | GLsizei *length, |
| 4949 | void **pointer) |
| 4950 | { |
| 4951 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4952 | { |
| 4953 | return false; |
| 4954 | } |
| 4955 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4956 | GLsizei writeLength = 0; |
| 4957 | |
| 4958 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4959 | { |
| 4960 | return false; |
| 4961 | } |
| 4962 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4963 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4964 | { |
| 4965 | return false; |
| 4966 | } |
| 4967 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4968 | SetRobustLengthParam(length, writeLength); |
| 4969 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4970 | return true; |
| 4971 | } |
| 4972 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4973 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4974 | GLuint index, |
| 4975 | GLenum pname, |
| 4976 | GLsizei bufSize, |
| 4977 | GLsizei *length, |
| 4978 | GLint *params) |
| 4979 | { |
| 4980 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4981 | { |
| 4982 | return false; |
| 4983 | } |
| 4984 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4985 | GLsizei writeLength = 0; |
| 4986 | |
| 4987 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4988 | { |
| 4989 | return false; |
| 4990 | } |
| 4991 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4992 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4993 | { |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4997 | SetRobustLengthParam(length, writeLength); |
| 4998 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4999 | return true; |
| 5000 | } |
| 5001 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5002 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5003 | GLuint index, |
| 5004 | GLenum pname, |
| 5005 | GLsizei bufSize, |
| 5006 | GLsizei *length, |
| 5007 | GLuint *params) |
| 5008 | { |
| 5009 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5010 | { |
| 5011 | return false; |
| 5012 | } |
| 5013 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5014 | GLsizei writeLength = 0; |
| 5015 | |
| 5016 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5017 | { |
| 5018 | return false; |
| 5019 | } |
| 5020 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5021 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5022 | { |
| 5023 | return false; |
| 5024 | } |
| 5025 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5026 | SetRobustLengthParam(length, writeLength); |
| 5027 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5028 | return true; |
| 5029 | } |
| 5030 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5031 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5032 | GLuint program, |
| 5033 | GLuint uniformBlockIndex, |
| 5034 | GLenum pname, |
| 5035 | GLsizei bufSize, |
| 5036 | GLsizei *length, |
| 5037 | GLint *params) |
| 5038 | { |
| 5039 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5040 | { |
| 5041 | return false; |
| 5042 | } |
| 5043 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5044 | GLsizei writeLength = 0; |
| 5045 | |
| 5046 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5047 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5048 | { |
| 5049 | return false; |
| 5050 | } |
| 5051 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5052 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5053 | { |
| 5054 | return false; |
| 5055 | } |
| 5056 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5057 | SetRobustLengthParam(length, writeLength); |
| 5058 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5059 | return true; |
| 5060 | } |
| 5061 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5062 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5063 | GLenum target, |
| 5064 | GLenum internalformat, |
| 5065 | GLenum pname, |
| 5066 | GLsizei bufSize, |
| 5067 | GLsizei *length, |
| 5068 | GLint *params) |
| 5069 | { |
| 5070 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5071 | { |
| 5072 | return false; |
| 5073 | } |
| 5074 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5075 | GLsizei numParams = 0; |
| 5076 | |
| 5077 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5078 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5079 | { |
| 5080 | return false; |
| 5081 | } |
| 5082 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5083 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5084 | { |
| 5085 | return false; |
| 5086 | } |
| 5087 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5088 | SetRobustLengthParam(length, numParams); |
| 5089 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5090 | return true; |
| 5091 | } |
| 5092 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5093 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5094 | GLuint attribIndex, |
| 5095 | GLint size, |
| 5096 | GLenum type, |
| 5097 | GLboolean pureInteger) |
| 5098 | { |
| 5099 | const Caps &caps = context->getCaps(); |
| 5100 | if (attribIndex >= caps.maxVertexAttributes) |
| 5101 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5102 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5103 | return false; |
| 5104 | } |
| 5105 | |
| 5106 | if (size < 1 || size > 4) |
| 5107 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5108 | context->validationError(GL_INVALID_VALUE, kInvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5109 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | switch (type) |
| 5113 | { |
| 5114 | case GL_BYTE: |
| 5115 | case GL_UNSIGNED_BYTE: |
| 5116 | case GL_SHORT: |
| 5117 | case GL_UNSIGNED_SHORT: |
| 5118 | break; |
| 5119 | |
| 5120 | case GL_INT: |
| 5121 | case GL_UNSIGNED_INT: |
| 5122 | if (context->getClientMajorVersion() < 3) |
| 5123 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5124 | context->validationError(GL_INVALID_ENUM, |
| 5125 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5126 | return false; |
| 5127 | } |
| 5128 | break; |
| 5129 | |
| 5130 | case GL_FIXED: |
| 5131 | case GL_FLOAT: |
| 5132 | if (pureInteger) |
| 5133 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5134 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5135 | return false; |
| 5136 | } |
| 5137 | break; |
| 5138 | |
| 5139 | case GL_HALF_FLOAT: |
| 5140 | if (context->getClientMajorVersion() < 3) |
| 5141 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5142 | context->validationError(GL_INVALID_ENUM, |
| 5143 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5144 | return false; |
| 5145 | } |
| 5146 | if (pureInteger) |
| 5147 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5148 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5149 | return false; |
| 5150 | } |
| 5151 | break; |
| 5152 | |
| 5153 | case GL_INT_2_10_10_10_REV: |
| 5154 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5155 | if (context->getClientMajorVersion() < 3) |
| 5156 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5157 | context->validationError(GL_INVALID_ENUM, |
| 5158 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5159 | return false; |
| 5160 | } |
| 5161 | if (pureInteger) |
| 5162 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5163 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5164 | return false; |
| 5165 | } |
| 5166 | if (size != 4) |
| 5167 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5168 | context->validationError(GL_INVALID_OPERATION, |
| 5169 | "Type is INT_2_10_10_10_REV or " |
| 5170 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5171 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5172 | return false; |
| 5173 | } |
| 5174 | break; |
| 5175 | |
| 5176 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5177 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5178 | return false; |
| 5179 | } |
| 5180 | |
| 5181 | return true; |
| 5182 | } |
| 5183 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5184 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5185 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5186 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5187 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5188 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5189 | GLint drawbuffer, |
| 5190 | const GLenum *validComponentTypes, |
| 5191 | size_t validComponentTypeCount) |
| 5192 | { |
| 5193 | const FramebufferAttachment *attachment = |
| 5194 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5195 | if (attachment) |
| 5196 | { |
| 5197 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5198 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5199 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5200 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5201 | context->validationError( |
| 5202 | GL_INVALID_OPERATION, |
| 5203 | "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5204 | return false; |
| 5205 | } |
| 5206 | } |
| 5207 | |
| 5208 | return true; |
| 5209 | } |
| 5210 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5211 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5212 | { |
| 5213 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5214 | { |
| 5215 | return false; |
| 5216 | } |
| 5217 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5218 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5219 | if (pixelUnpackBuffer == nullptr) |
| 5220 | { |
| 5221 | if (dataSize < imageSize) |
| 5222 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5223 | context->validationError(GL_INVALID_OPERATION, "dataSize is too small"); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | return true; |
| 5227 | } |
| 5228 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5229 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5230 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5231 | GLenum pname, |
| 5232 | bool pointerVersion, |
| 5233 | GLsizei *numParams) |
| 5234 | { |
| 5235 | if (numParams) |
| 5236 | { |
| 5237 | *numParams = 0; |
| 5238 | } |
| 5239 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5240 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5241 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5242 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5243 | return false; |
| 5244 | } |
| 5245 | |
| 5246 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5247 | if (!buffer) |
| 5248 | { |
| 5249 | // 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] | 5250 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5251 | return false; |
| 5252 | } |
| 5253 | |
| 5254 | const Extensions &extensions = context->getExtensions(); |
| 5255 | |
| 5256 | switch (pname) |
| 5257 | { |
| 5258 | case GL_BUFFER_USAGE: |
| 5259 | case GL_BUFFER_SIZE: |
| 5260 | break; |
| 5261 | |
| 5262 | case GL_BUFFER_ACCESS_OES: |
| 5263 | if (!extensions.mapBuffer) |
| 5264 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5265 | context->validationError(GL_INVALID_ENUM, |
| 5266 | "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | break; |
| 5270 | |
| 5271 | case GL_BUFFER_MAPPED: |
| 5272 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5273 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5274 | !extensions.mapBufferRange) |
| 5275 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5276 | context->validationError(GL_INVALID_ENUM, |
| 5277 | "pname requires OpenGL ES 3.0, " |
| 5278 | "GL_OES_mapbuffer or " |
| 5279 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5280 | return false; |
| 5281 | } |
| 5282 | break; |
| 5283 | |
| 5284 | case GL_BUFFER_MAP_POINTER: |
| 5285 | if (!pointerVersion) |
| 5286 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5287 | context->validationError( |
| 5288 | GL_INVALID_ENUM, |
| 5289 | "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5290 | return false; |
| 5291 | } |
| 5292 | break; |
| 5293 | |
| 5294 | case GL_BUFFER_ACCESS_FLAGS: |
| 5295 | case GL_BUFFER_MAP_OFFSET: |
| 5296 | case GL_BUFFER_MAP_LENGTH: |
| 5297 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5298 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5299 | context->validationError( |
| 5300 | GL_INVALID_ENUM, "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5301 | return false; |
| 5302 | } |
| 5303 | break; |
| 5304 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5305 | case GL_MEMORY_SIZE_ANGLE: |
| 5306 | if (!context->getExtensions().memorySize) |
| 5307 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5308 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5309 | return false; |
| 5310 | } |
| 5311 | break; |
| 5312 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5313 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5314 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5315 | return false; |
| 5316 | } |
| 5317 | |
| 5318 | // All buffer parameter queries return one value. |
| 5319 | if (numParams) |
| 5320 | { |
| 5321 | *numParams = 1; |
| 5322 | } |
| 5323 | |
| 5324 | return true; |
| 5325 | } |
| 5326 | |
| 5327 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5328 | GLenum target, |
| 5329 | GLenum pname, |
| 5330 | GLsizei *length) |
| 5331 | { |
| 5332 | if (length) |
| 5333 | { |
| 5334 | *length = 0; |
| 5335 | } |
| 5336 | |
| 5337 | if (target != GL_RENDERBUFFER) |
| 5338 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5339 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5340 | return false; |
| 5341 | } |
| 5342 | |
| 5343 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5344 | if (renderbuffer == nullptr) |
| 5345 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5346 | context->validationError(GL_INVALID_OPERATION, kRenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5347 | return false; |
| 5348 | } |
| 5349 | |
| 5350 | switch (pname) |
| 5351 | { |
| 5352 | case GL_RENDERBUFFER_WIDTH: |
| 5353 | case GL_RENDERBUFFER_HEIGHT: |
| 5354 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5355 | case GL_RENDERBUFFER_RED_SIZE: |
| 5356 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5357 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5358 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5359 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5360 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5361 | break; |
| 5362 | |
| 5363 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5364 | if (!context->getExtensions().framebufferMultisample) |
| 5365 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5366 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5367 | return false; |
| 5368 | } |
| 5369 | break; |
| 5370 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5371 | case GL_MEMORY_SIZE_ANGLE: |
| 5372 | if (!context->getExtensions().memorySize) |
| 5373 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5374 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5375 | return false; |
| 5376 | } |
| 5377 | break; |
| 5378 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5379 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5380 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5381 | return false; |
| 5382 | } |
| 5383 | |
| 5384 | if (length) |
| 5385 | { |
| 5386 | *length = 1; |
| 5387 | } |
| 5388 | return true; |
| 5389 | } |
| 5390 | |
| 5391 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5392 | { |
| 5393 | if (length) |
| 5394 | { |
| 5395 | *length = 0; |
| 5396 | } |
| 5397 | |
| 5398 | if (GetValidShader(context, shader) == nullptr) |
| 5399 | { |
| 5400 | return false; |
| 5401 | } |
| 5402 | |
| 5403 | switch (pname) |
| 5404 | { |
| 5405 | case GL_SHADER_TYPE: |
| 5406 | case GL_DELETE_STATUS: |
| 5407 | case GL_COMPILE_STATUS: |
| 5408 | case GL_INFO_LOG_LENGTH: |
| 5409 | case GL_SHADER_SOURCE_LENGTH: |
| 5410 | break; |
| 5411 | |
| 5412 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5413 | if (!context->getExtensions().translatedShaderSource) |
| 5414 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5415 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5416 | return false; |
| 5417 | } |
| 5418 | break; |
| 5419 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5420 | case GL_COMPLETION_STATUS_KHR: |
| 5421 | if (!context->getExtensions().parallelShaderCompile) |
| 5422 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5423 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5424 | return false; |
| 5425 | } |
| 5426 | break; |
| 5427 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5428 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5429 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5430 | return false; |
| 5431 | } |
| 5432 | |
| 5433 | if (length) |
| 5434 | { |
| 5435 | *length = 1; |
| 5436 | } |
| 5437 | return true; |
| 5438 | } |
| 5439 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5440 | bool ValidateGetTexParameterBase(Context *context, |
| 5441 | TextureType target, |
| 5442 | GLenum pname, |
| 5443 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5444 | { |
| 5445 | if (length) |
| 5446 | { |
| 5447 | *length = 0; |
| 5448 | } |
| 5449 | |
| 5450 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5451 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5452 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5453 | return false; |
| 5454 | } |
| 5455 | |
| 5456 | if (context->getTargetTexture(target) == nullptr) |
| 5457 | { |
| 5458 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5459 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5460 | return false; |
| 5461 | } |
| 5462 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5463 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5464 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5465 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5466 | return false; |
| 5467 | } |
| 5468 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5469 | switch (pname) |
| 5470 | { |
| 5471 | case GL_TEXTURE_MAG_FILTER: |
| 5472 | case GL_TEXTURE_MIN_FILTER: |
| 5473 | case GL_TEXTURE_WRAP_S: |
| 5474 | case GL_TEXTURE_WRAP_T: |
| 5475 | break; |
| 5476 | |
| 5477 | case GL_TEXTURE_USAGE_ANGLE: |
| 5478 | if (!context->getExtensions().textureUsage) |
| 5479 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5480 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5481 | return false; |
| 5482 | } |
| 5483 | break; |
| 5484 | |
| 5485 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5486 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5487 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5488 | return false; |
| 5489 | } |
| 5490 | break; |
| 5491 | |
| 5492 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5493 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5494 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5495 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5496 | return false; |
| 5497 | } |
| 5498 | break; |
| 5499 | |
| 5500 | case GL_TEXTURE_WRAP_R: |
| 5501 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5502 | case GL_TEXTURE_SWIZZLE_R: |
| 5503 | case GL_TEXTURE_SWIZZLE_G: |
| 5504 | case GL_TEXTURE_SWIZZLE_B: |
| 5505 | case GL_TEXTURE_SWIZZLE_A: |
| 5506 | case GL_TEXTURE_BASE_LEVEL: |
| 5507 | case GL_TEXTURE_MAX_LEVEL: |
| 5508 | case GL_TEXTURE_MIN_LOD: |
| 5509 | case GL_TEXTURE_MAX_LOD: |
| 5510 | case GL_TEXTURE_COMPARE_MODE: |
| 5511 | case GL_TEXTURE_COMPARE_FUNC: |
| 5512 | if (context->getClientMajorVersion() < 3) |
| 5513 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5514 | context->validationError(GL_INVALID_ENUM, "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5515 | return false; |
| 5516 | } |
| 5517 | break; |
| 5518 | |
| 5519 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5520 | if (!context->getExtensions().textureSRGBDecode) |
| 5521 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5522 | context->validationError(GL_INVALID_ENUM, |
| 5523 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5524 | return false; |
| 5525 | } |
| 5526 | break; |
| 5527 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5528 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5529 | if (context->getClientVersion() < Version(3, 1)) |
| 5530 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5531 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5532 | return false; |
| 5533 | } |
| 5534 | break; |
| 5535 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5536 | case GL_GENERATE_MIPMAP: |
| 5537 | case GL_TEXTURE_CROP_RECT_OES: |
| 5538 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5539 | // after GL_OES_draw_texture functionality implemented |
| 5540 | if (context->getClientMajorVersion() > 1) |
| 5541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5542 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5543 | return false; |
| 5544 | } |
| 5545 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5546 | |
| 5547 | case GL_MEMORY_SIZE_ANGLE: |
| 5548 | if (!context->getExtensions().memorySize) |
| 5549 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5550 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5551 | return false; |
| 5552 | } |
| 5553 | break; |
| 5554 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5555 | case GL_TEXTURE_BORDER_COLOR: |
| 5556 | if (!context->getExtensions().textureBorderClamp) |
| 5557 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5558 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5559 | return false; |
| 5560 | } |
| 5561 | break; |
| 5562 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5563 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5564 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5565 | return false; |
| 5566 | } |
| 5567 | |
| 5568 | if (length) |
| 5569 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5570 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5571 | } |
| 5572 | return true; |
| 5573 | } |
| 5574 | |
| 5575 | bool ValidateGetVertexAttribBase(Context *context, |
| 5576 | GLuint index, |
| 5577 | GLenum pname, |
| 5578 | GLsizei *length, |
| 5579 | bool pointer, |
| 5580 | bool pureIntegerEntryPoint) |
| 5581 | { |
| 5582 | if (length) |
| 5583 | { |
| 5584 | *length = 0; |
| 5585 | } |
| 5586 | |
| 5587 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5588 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5589 | context->validationError(GL_INVALID_OPERATION, "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5590 | return false; |
| 5591 | } |
| 5592 | |
| 5593 | if (index >= context->getCaps().maxVertexAttributes) |
| 5594 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5595 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5596 | return false; |
| 5597 | } |
| 5598 | |
| 5599 | if (pointer) |
| 5600 | { |
| 5601 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5602 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5603 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5604 | return false; |
| 5605 | } |
| 5606 | } |
| 5607 | else |
| 5608 | { |
| 5609 | switch (pname) |
| 5610 | { |
| 5611 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5612 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5613 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5614 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5615 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5616 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5617 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5618 | break; |
| 5619 | |
| 5620 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5621 | static_assert( |
| 5622 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5623 | "ANGLE extension enums not equal to GL enums."); |
| 5624 | if (context->getClientMajorVersion() < 3 && |
| 5625 | !context->getExtensions().instancedArrays) |
| 5626 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5627 | context->validationError(GL_INVALID_ENUM, |
| 5628 | "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5629 | "requires OpenGL ES 3.0 or " |
| 5630 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5631 | return false; |
| 5632 | } |
| 5633 | break; |
| 5634 | |
| 5635 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5636 | if (context->getClientMajorVersion() < 3) |
| 5637 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5638 | context->validationError( |
| 5639 | GL_INVALID_ENUM, "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5640 | return false; |
| 5641 | } |
| 5642 | break; |
| 5643 | |
| 5644 | case GL_VERTEX_ATTRIB_BINDING: |
| 5645 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5646 | if (context->getClientVersion() < ES_3_1) |
| 5647 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5648 | context->validationError(GL_INVALID_ENUM, |
| 5649 | "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5650 | return false; |
| 5651 | } |
| 5652 | break; |
| 5653 | |
| 5654 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5655 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5656 | return false; |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | if (length) |
| 5661 | { |
| 5662 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5663 | { |
| 5664 | *length = 4; |
| 5665 | } |
| 5666 | else |
| 5667 | { |
| 5668 | *length = 1; |
| 5669 | } |
| 5670 | } |
| 5671 | |
| 5672 | return true; |
| 5673 | } |
| 5674 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5675 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5676 | GLint x, |
| 5677 | GLint y, |
| 5678 | GLsizei width, |
| 5679 | GLsizei height, |
| 5680 | GLenum format, |
| 5681 | GLenum type, |
| 5682 | GLsizei bufSize, |
| 5683 | GLsizei *length, |
| 5684 | GLsizei *columns, |
| 5685 | GLsizei *rows, |
| 5686 | void *pixels) |
| 5687 | { |
| 5688 | if (length != nullptr) |
| 5689 | { |
| 5690 | *length = 0; |
| 5691 | } |
| 5692 | if (rows != nullptr) |
| 5693 | { |
| 5694 | *rows = 0; |
| 5695 | } |
| 5696 | if (columns != nullptr) |
| 5697 | { |
| 5698 | *columns = 0; |
| 5699 | } |
| 5700 | |
| 5701 | if (width < 0 || height < 0) |
| 5702 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5703 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5704 | return false; |
| 5705 | } |
| 5706 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5707 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5708 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5709 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5710 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5711 | return false; |
| 5712 | } |
| 5713 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5714 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5715 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5716 | return false; |
| 5717 | } |
| 5718 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5719 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5720 | ASSERT(framebuffer); |
| 5721 | |
| 5722 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5723 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5724 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5725 | return false; |
| 5726 | } |
| 5727 | |
| 5728 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5729 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5730 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5731 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5732 | // situation is an application error that would lead to a crash in ANGLE. |
| 5733 | if (readBuffer == nullptr) |
| 5734 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5735 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5736 | return false; |
| 5737 | } |
| 5738 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5739 | // ANGLE_multiview, Revision 1: |
| 5740 | // 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] | 5741 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5742 | // in the current read framebuffer is more than one. |
| 5743 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5744 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5745 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, |
| 5746 | "Attempting to read from a multi-view framebuffer."); |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5747 | return false; |
| 5748 | } |
| 5749 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5750 | if (context->getExtensions().webglCompatibility) |
| 5751 | { |
| 5752 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5753 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5754 | // and type before validating the combination of format and type. However, the |
| 5755 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5756 | // verifies that GL_INVALID_OPERATION is generated. |
| 5757 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5758 | // dEQP/WebGL. |
| 5759 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5760 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5761 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5762 | return false; |
| 5763 | } |
| 5764 | |
| 5765 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5766 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5767 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5768 | return false; |
| 5769 | } |
| 5770 | } |
| 5771 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5772 | GLenum currentFormat = GL_NONE; |
| 5773 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5774 | |
| 5775 | GLenum currentType = GL_NONE; |
| 5776 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5777 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5778 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5779 | |
| 5780 | bool validFormatTypeCombination = |
| 5781 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5782 | |
| 5783 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5784 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5785 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5786 | return false; |
| 5787 | } |
| 5788 | |
| 5789 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5790 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5791 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5792 | { |
| 5793 | // ...the buffer object's data store is currently mapped. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5794 | context->validationError(GL_INVALID_OPERATION, "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5795 | return false; |
| 5796 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5797 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5798 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5799 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5800 | context->validationError(GL_INVALID_OPERATION, kPixelPackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5801 | return false; |
| 5802 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5803 | |
| 5804 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5805 | // would exceed the data store size. |
| 5806 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5807 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5808 | const auto &pack = context->getGLState().getPackState(); |
| 5809 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5810 | GLuint endByte = 0; |
| 5811 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5812 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5813 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5814 | return false; |
| 5815 | } |
| 5816 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5817 | if (bufSize >= 0) |
| 5818 | { |
| 5819 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5820 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5821 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5822 | return false; |
| 5823 | } |
| 5824 | } |
| 5825 | |
| 5826 | if (pixelPackBuffer != nullptr) |
| 5827 | { |
| 5828 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5829 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5830 | checkedEndByte += checkedOffset; |
| 5831 | |
| 5832 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5833 | { |
| 5834 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5835 | context->validationError(GL_INVALID_OPERATION, kParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5836 | return false; |
| 5837 | } |
| 5838 | } |
| 5839 | |
| 5840 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5841 | { |
| 5842 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5843 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5844 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5845 | return false; |
| 5846 | } |
| 5847 | |
| 5848 | *length = static_cast<GLsizei>(endByte); |
| 5849 | } |
| 5850 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5851 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5852 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5853 | if (start < 0) |
| 5854 | { |
| 5855 | // "subtract" the area that is less than 0 |
| 5856 | clippedExtent += start; |
| 5857 | } |
| 5858 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5859 | angle::CheckedNumeric<int> readExtent = start; |
| 5860 | readExtent += length; |
| 5861 | if (!readExtent.IsValid()) |
| 5862 | { |
| 5863 | return false; |
| 5864 | } |
| 5865 | |
| 5866 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5867 | { |
| 5868 | // Subtract the region to the right of the read buffer |
| 5869 | clippedExtent -= (readExtent - bufferSize); |
| 5870 | } |
| 5871 | |
| 5872 | if (!clippedExtent.IsValid()) |
| 5873 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5874 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5875 | } |
| 5876 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5877 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5878 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5879 | }; |
| 5880 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5881 | GLsizei writtenColumns = 0; |
| 5882 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5883 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5884 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5885 | return false; |
| 5886 | } |
| 5887 | |
| 5888 | GLsizei writtenRows = 0; |
| 5889 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5890 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5891 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5892 | return false; |
| 5893 | } |
| 5894 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5895 | if (columns != nullptr) |
| 5896 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5897 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5898 | } |
| 5899 | |
| 5900 | if (rows != nullptr) |
| 5901 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5902 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5903 | } |
| 5904 | |
| 5905 | return true; |
| 5906 | } |
| 5907 | |
| 5908 | template <typename ParamType> |
| 5909 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5910 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5911 | GLenum pname, |
| 5912 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5913 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5914 | const ParamType *params) |
| 5915 | { |
| 5916 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5917 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5918 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5919 | return false; |
| 5920 | } |
| 5921 | |
| 5922 | if (context->getTargetTexture(target) == nullptr) |
| 5923 | { |
| 5924 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5925 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5926 | return false; |
| 5927 | } |
| 5928 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5929 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5930 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5931 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5932 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5936 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5937 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5938 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5939 | return false; |
| 5940 | } |
| 5941 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5942 | switch (pname) |
| 5943 | { |
| 5944 | case GL_TEXTURE_WRAP_R: |
| 5945 | case GL_TEXTURE_SWIZZLE_R: |
| 5946 | case GL_TEXTURE_SWIZZLE_G: |
| 5947 | case GL_TEXTURE_SWIZZLE_B: |
| 5948 | case GL_TEXTURE_SWIZZLE_A: |
| 5949 | case GL_TEXTURE_BASE_LEVEL: |
| 5950 | case GL_TEXTURE_MAX_LEVEL: |
| 5951 | case GL_TEXTURE_COMPARE_MODE: |
| 5952 | case GL_TEXTURE_COMPARE_FUNC: |
| 5953 | case GL_TEXTURE_MIN_LOD: |
| 5954 | case GL_TEXTURE_MAX_LOD: |
| 5955 | if (context->getClientMajorVersion() < 3) |
| 5956 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5957 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5958 | return false; |
| 5959 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5960 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5961 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5962 | context->validationError(GL_INVALID_ENUM, |
| 5963 | "ES3 texture parameters are not " |
| 5964 | "available without " |
| 5965 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5966 | return false; |
| 5967 | } |
| 5968 | break; |
| 5969 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5970 | case GL_GENERATE_MIPMAP: |
| 5971 | case GL_TEXTURE_CROP_RECT_OES: |
| 5972 | if (context->getClientMajorVersion() > 1) |
| 5973 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5974 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5975 | return false; |
| 5976 | } |
| 5977 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5978 | default: |
| 5979 | break; |
| 5980 | } |
| 5981 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5982 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5983 | { |
| 5984 | switch (pname) |
| 5985 | { |
| 5986 | case GL_TEXTURE_MIN_FILTER: |
| 5987 | case GL_TEXTURE_MAG_FILTER: |
| 5988 | case GL_TEXTURE_WRAP_S: |
| 5989 | case GL_TEXTURE_WRAP_T: |
| 5990 | case GL_TEXTURE_WRAP_R: |
| 5991 | case GL_TEXTURE_MIN_LOD: |
| 5992 | case GL_TEXTURE_MAX_LOD: |
| 5993 | case GL_TEXTURE_COMPARE_MODE: |
| 5994 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5995 | case GL_TEXTURE_BORDER_COLOR: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5996 | context->validationError(GL_INVALID_ENUM, |
| 5997 | "Invalid parameter for 2D multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5998 | return false; |
| 5999 | } |
| 6000 | } |
| 6001 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6002 | switch (pname) |
| 6003 | { |
| 6004 | case GL_TEXTURE_WRAP_S: |
| 6005 | case GL_TEXTURE_WRAP_T: |
| 6006 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6007 | { |
| 6008 | bool restrictedWrapModes = |
| 6009 | target == TextureType::External || target == TextureType::Rectangle; |
| 6010 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6011 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6012 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6013 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6014 | } |
| 6015 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6016 | |
| 6017 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6018 | { |
| 6019 | bool restrictedMinFilter = |
| 6020 | target == TextureType::External || target == TextureType::Rectangle; |
| 6021 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6022 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6023 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6024 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6025 | } |
| 6026 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6027 | |
| 6028 | case GL_TEXTURE_MAG_FILTER: |
| 6029 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6030 | { |
| 6031 | return false; |
| 6032 | } |
| 6033 | break; |
| 6034 | |
| 6035 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6036 | if (!context->getExtensions().textureUsage) |
| 6037 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6038 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6039 | return false; |
| 6040 | } |
| 6041 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6042 | switch (ConvertToGLenum(params[0])) |
| 6043 | { |
| 6044 | case GL_NONE: |
| 6045 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6046 | break; |
| 6047 | |
| 6048 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6049 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6050 | return false; |
| 6051 | } |
| 6052 | break; |
| 6053 | |
| 6054 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6055 | { |
| 6056 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6057 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6058 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6059 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6060 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6061 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6062 | } |
| 6063 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6064 | |
| 6065 | case GL_TEXTURE_MIN_LOD: |
| 6066 | case GL_TEXTURE_MAX_LOD: |
| 6067 | // any value is permissible |
| 6068 | break; |
| 6069 | |
| 6070 | case GL_TEXTURE_COMPARE_MODE: |
| 6071 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6072 | { |
| 6073 | return false; |
| 6074 | } |
| 6075 | break; |
| 6076 | |
| 6077 | case GL_TEXTURE_COMPARE_FUNC: |
| 6078 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6079 | { |
| 6080 | return false; |
| 6081 | } |
| 6082 | break; |
| 6083 | |
| 6084 | case GL_TEXTURE_SWIZZLE_R: |
| 6085 | case GL_TEXTURE_SWIZZLE_G: |
| 6086 | case GL_TEXTURE_SWIZZLE_B: |
| 6087 | case GL_TEXTURE_SWIZZLE_A: |
| 6088 | switch (ConvertToGLenum(params[0])) |
| 6089 | { |
| 6090 | case GL_RED: |
| 6091 | case GL_GREEN: |
| 6092 | case GL_BLUE: |
| 6093 | case GL_ALPHA: |
| 6094 | case GL_ZERO: |
| 6095 | case GL_ONE: |
| 6096 | break; |
| 6097 | |
| 6098 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6099 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6100 | return false; |
| 6101 | } |
| 6102 | break; |
| 6103 | |
| 6104 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6105 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6106 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6107 | context->validationError(GL_INVALID_VALUE, "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6108 | return false; |
| 6109 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6110 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6111 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6112 | context->validationError(GL_INVALID_OPERATION, |
| 6113 | "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6114 | return false; |
| 6115 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6116 | if ((target == TextureType::_2DMultisample || |
| 6117 | target == TextureType::_2DMultisampleArray) && |
| 6118 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6119 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6120 | context->validationError(GL_INVALID_OPERATION, |
| 6121 | "Base level must be 0 for multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6122 | return false; |
| 6123 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6124 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6125 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6126 | context->validationError(GL_INVALID_OPERATION, |
| 6127 | "Base level must be 0 for rectangle textures."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6128 | return false; |
| 6129 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6130 | break; |
| 6131 | |
| 6132 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6133 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6134 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6135 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6136 | return false; |
| 6137 | } |
| 6138 | break; |
| 6139 | |
| 6140 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6141 | if (context->getClientVersion() < Version(3, 1)) |
| 6142 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6143 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6144 | return false; |
| 6145 | } |
| 6146 | switch (ConvertToGLenum(params[0])) |
| 6147 | { |
| 6148 | case GL_DEPTH_COMPONENT: |
| 6149 | case GL_STENCIL_INDEX: |
| 6150 | break; |
| 6151 | |
| 6152 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6153 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6154 | return false; |
| 6155 | } |
| 6156 | break; |
| 6157 | |
| 6158 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6159 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6160 | { |
| 6161 | return false; |
| 6162 | } |
| 6163 | break; |
| 6164 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6165 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6166 | if (context->getClientMajorVersion() > 1) |
| 6167 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6168 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6169 | return false; |
| 6170 | } |
| 6171 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6172 | |
| 6173 | case GL_TEXTURE_CROP_RECT_OES: |
| 6174 | if (context->getClientMajorVersion() > 1) |
| 6175 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6176 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6177 | return false; |
| 6178 | } |
| 6179 | if (!vectorParams) |
| 6180 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6181 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6182 | return false; |
| 6183 | } |
| 6184 | break; |
| 6185 | |
| 6186 | case GL_TEXTURE_BORDER_COLOR: |
| 6187 | if (!context->getExtensions().textureBorderClamp) |
| 6188 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6189 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6190 | return false; |
| 6191 | } |
| 6192 | if (!vectorParams) |
| 6193 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6194 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6195 | return false; |
| 6196 | } |
| 6197 | break; |
| 6198 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6199 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6200 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6201 | return false; |
| 6202 | } |
| 6203 | |
| 6204 | return true; |
| 6205 | } |
| 6206 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6207 | template bool ValidateTexParameterBase(Context *, |
| 6208 | TextureType, |
| 6209 | GLenum, |
| 6210 | GLsizei, |
| 6211 | bool, |
| 6212 | const GLfloat *); |
| 6213 | template bool ValidateTexParameterBase(Context *, |
| 6214 | TextureType, |
| 6215 | GLenum, |
| 6216 | GLsizei, |
| 6217 | bool, |
| 6218 | const GLint *); |
| 6219 | template bool ValidateTexParameterBase(Context *, |
| 6220 | TextureType, |
| 6221 | GLenum, |
| 6222 | GLsizei, |
| 6223 | bool, |
| 6224 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6225 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6226 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6227 | { |
| 6228 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6229 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6230 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6231 | return false; |
| 6232 | } |
| 6233 | |
| 6234 | return true; |
| 6235 | } |
| 6236 | |
| 6237 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6238 | GLuint program, |
| 6239 | GLuint uniformBlockIndex, |
| 6240 | GLenum pname, |
| 6241 | GLsizei *length) |
| 6242 | { |
| 6243 | if (length) |
| 6244 | { |
| 6245 | *length = 0; |
| 6246 | } |
| 6247 | |
| 6248 | if (context->getClientMajorVersion() < 3) |
| 6249 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6250 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6251 | return false; |
| 6252 | } |
| 6253 | |
| 6254 | Program *programObject = GetValidProgram(context, program); |
| 6255 | if (!programObject) |
| 6256 | { |
| 6257 | return false; |
| 6258 | } |
| 6259 | |
| 6260 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6261 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6262 | context->validationError(GL_INVALID_VALUE, |
| 6263 | "uniformBlockIndex exceeds active uniform block count."); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6264 | return false; |
| 6265 | } |
| 6266 | |
| 6267 | switch (pname) |
| 6268 | { |
| 6269 | case GL_UNIFORM_BLOCK_BINDING: |
| 6270 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6271 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6272 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6273 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6274 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6275 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6276 | break; |
| 6277 | |
| 6278 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6279 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6280 | return false; |
| 6281 | } |
| 6282 | |
| 6283 | if (length) |
| 6284 | { |
| 6285 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6286 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6287 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6288 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6289 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6290 | } |
| 6291 | else |
| 6292 | { |
| 6293 | *length = 1; |
| 6294 | } |
| 6295 | } |
| 6296 | |
| 6297 | return true; |
| 6298 | } |
| 6299 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6300 | template <typename ParamType> |
| 6301 | bool ValidateSamplerParameterBase(Context *context, |
| 6302 | GLuint sampler, |
| 6303 | GLenum pname, |
| 6304 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6305 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6306 | ParamType *params) |
| 6307 | { |
| 6308 | if (context->getClientMajorVersion() < 3) |
| 6309 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6310 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6311 | return false; |
| 6312 | } |
| 6313 | |
| 6314 | if (!context->isSampler(sampler)) |
| 6315 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6316 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6317 | return false; |
| 6318 | } |
| 6319 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6320 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6321 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6322 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6323 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6324 | return false; |
| 6325 | } |
| 6326 | |
| 6327 | switch (pname) |
| 6328 | { |
| 6329 | case GL_TEXTURE_WRAP_S: |
| 6330 | case GL_TEXTURE_WRAP_T: |
| 6331 | case GL_TEXTURE_WRAP_R: |
| 6332 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6333 | { |
| 6334 | return false; |
| 6335 | } |
| 6336 | break; |
| 6337 | |
| 6338 | case GL_TEXTURE_MIN_FILTER: |
| 6339 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6340 | { |
| 6341 | return false; |
| 6342 | } |
| 6343 | break; |
| 6344 | |
| 6345 | case GL_TEXTURE_MAG_FILTER: |
| 6346 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6347 | { |
| 6348 | return false; |
| 6349 | } |
| 6350 | break; |
| 6351 | |
| 6352 | case GL_TEXTURE_MIN_LOD: |
| 6353 | case GL_TEXTURE_MAX_LOD: |
| 6354 | // any value is permissible |
| 6355 | break; |
| 6356 | |
| 6357 | case GL_TEXTURE_COMPARE_MODE: |
| 6358 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6359 | { |
| 6360 | return false; |
| 6361 | } |
| 6362 | break; |
| 6363 | |
| 6364 | case GL_TEXTURE_COMPARE_FUNC: |
| 6365 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6366 | { |
| 6367 | return false; |
| 6368 | } |
| 6369 | break; |
| 6370 | |
| 6371 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6372 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6373 | { |
| 6374 | return false; |
| 6375 | } |
| 6376 | break; |
| 6377 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6378 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6379 | { |
| 6380 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6381 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6382 | { |
| 6383 | return false; |
| 6384 | } |
| 6385 | } |
| 6386 | break; |
| 6387 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6388 | case GL_TEXTURE_BORDER_COLOR: |
| 6389 | if (!context->getExtensions().textureBorderClamp) |
| 6390 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6391 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6392 | return false; |
| 6393 | } |
| 6394 | if (!vectorParams) |
| 6395 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6396 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6397 | return false; |
| 6398 | } |
| 6399 | break; |
| 6400 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6401 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6402 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6403 | return false; |
| 6404 | } |
| 6405 | |
| 6406 | return true; |
| 6407 | } |
| 6408 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6409 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6410 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6411 | template bool ValidateSamplerParameterBase(Context *, |
| 6412 | GLuint, |
| 6413 | GLenum, |
| 6414 | GLsizei, |
| 6415 | bool, |
| 6416 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6417 | |
| 6418 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6419 | GLuint sampler, |
| 6420 | GLenum pname, |
| 6421 | GLsizei *length) |
| 6422 | { |
| 6423 | if (length) |
| 6424 | { |
| 6425 | *length = 0; |
| 6426 | } |
| 6427 | |
| 6428 | if (context->getClientMajorVersion() < 3) |
| 6429 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6430 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6431 | return false; |
| 6432 | } |
| 6433 | |
| 6434 | if (!context->isSampler(sampler)) |
| 6435 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6436 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6437 | return false; |
| 6438 | } |
| 6439 | |
| 6440 | switch (pname) |
| 6441 | { |
| 6442 | case GL_TEXTURE_WRAP_S: |
| 6443 | case GL_TEXTURE_WRAP_T: |
| 6444 | case GL_TEXTURE_WRAP_R: |
| 6445 | case GL_TEXTURE_MIN_FILTER: |
| 6446 | case GL_TEXTURE_MAG_FILTER: |
| 6447 | case GL_TEXTURE_MIN_LOD: |
| 6448 | case GL_TEXTURE_MAX_LOD: |
| 6449 | case GL_TEXTURE_COMPARE_MODE: |
| 6450 | case GL_TEXTURE_COMPARE_FUNC: |
| 6451 | break; |
| 6452 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6453 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6454 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6455 | { |
| 6456 | return false; |
| 6457 | } |
| 6458 | break; |
| 6459 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6460 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6461 | if (!context->getExtensions().textureSRGBDecode) |
| 6462 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6463 | context->validationError(GL_INVALID_ENUM, |
| 6464 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6465 | return false; |
| 6466 | } |
| 6467 | break; |
| 6468 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6469 | case GL_TEXTURE_BORDER_COLOR: |
| 6470 | if (!context->getExtensions().textureBorderClamp) |
| 6471 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6472 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6473 | return false; |
| 6474 | } |
| 6475 | break; |
| 6476 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6477 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6478 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6479 | return false; |
| 6480 | } |
| 6481 | |
| 6482 | if (length) |
| 6483 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6484 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6485 | } |
| 6486 | return true; |
| 6487 | } |
| 6488 | |
| 6489 | bool ValidateGetInternalFormativBase(Context *context, |
| 6490 | GLenum target, |
| 6491 | GLenum internalformat, |
| 6492 | GLenum pname, |
| 6493 | GLsizei bufSize, |
| 6494 | GLsizei *numParams) |
| 6495 | { |
| 6496 | if (numParams) |
| 6497 | { |
| 6498 | *numParams = 0; |
| 6499 | } |
| 6500 | |
| 6501 | if (context->getClientMajorVersion() < 3) |
| 6502 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6503 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6504 | return false; |
| 6505 | } |
| 6506 | |
| 6507 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6508 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6509 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6510 | context->validationError(GL_INVALID_ENUM, "Internal format is not renderable."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6511 | return false; |
| 6512 | } |
| 6513 | |
| 6514 | switch (target) |
| 6515 | { |
| 6516 | case GL_RENDERBUFFER: |
| 6517 | break; |
| 6518 | |
| 6519 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6520 | if (context->getClientVersion() < ES_3_1 && |
| 6521 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6522 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6523 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6524 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6525 | return false; |
| 6526 | } |
| 6527 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6528 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6529 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6530 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6531 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6532 | return false; |
| 6533 | } |
| 6534 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6535 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6536 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6537 | return false; |
| 6538 | } |
| 6539 | |
| 6540 | if (bufSize < 0) |
| 6541 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6542 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6543 | return false; |
| 6544 | } |
| 6545 | |
| 6546 | GLsizei maxWriteParams = 0; |
| 6547 | switch (pname) |
| 6548 | { |
| 6549 | case GL_NUM_SAMPLE_COUNTS: |
| 6550 | maxWriteParams = 1; |
| 6551 | break; |
| 6552 | |
| 6553 | case GL_SAMPLES: |
| 6554 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6555 | break; |
| 6556 | |
| 6557 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6558 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6559 | return false; |
| 6560 | } |
| 6561 | |
| 6562 | if (numParams) |
| 6563 | { |
| 6564 | // glGetInternalFormativ will not overflow bufSize |
| 6565 | *numParams = std::min(bufSize, maxWriteParams); |
| 6566 | } |
| 6567 | |
| 6568 | return true; |
| 6569 | } |
| 6570 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6571 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6572 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6573 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6574 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6575 | context->validationError(GL_INVALID_OPERATION, kInvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6576 | return false; |
| 6577 | } |
| 6578 | return true; |
| 6579 | } |
| 6580 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6581 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6582 | { |
| 6583 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6584 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6585 | context->validationError(GL_INVALID_ENUM, kInvalidMultitextureUnit); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6586 | return false; |
| 6587 | } |
| 6588 | return true; |
| 6589 | } |
| 6590 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6591 | bool ValidateTexStorageMultisample(Context *context, |
| 6592 | TextureType target, |
| 6593 | GLsizei samples, |
| 6594 | GLint internalFormat, |
| 6595 | GLsizei width, |
| 6596 | GLsizei height) |
| 6597 | { |
| 6598 | const Caps &caps = context->getCaps(); |
| 6599 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6600 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6601 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6602 | context->validationError(GL_INVALID_VALUE, kTextureWidthOrHeightOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6603 | return false; |
| 6604 | } |
| 6605 | |
| 6606 | if (samples == 0) |
| 6607 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6608 | context->validationError(GL_INVALID_VALUE, kSamplesZero); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6609 | return false; |
| 6610 | } |
| 6611 | |
| 6612 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6613 | if (!formatCaps.textureAttachment) |
| 6614 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6615 | context->validationError(GL_INVALID_ENUM, kRenderableInternalFormat); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6616 | return false; |
| 6617 | } |
| 6618 | |
| 6619 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6620 | // is one of the unsized base internalformats listed in table 8.11. |
| 6621 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6622 | if (formatInfo.internalFormat == GL_NONE) |
| 6623 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6624 | context->validationError(GL_INVALID_ENUM, kUnsizedInternalFormatUnsupported); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6625 | return false; |
| 6626 | } |
| 6627 | |
| 6628 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6629 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6630 | context->validationError(GL_INVALID_OPERATION, kSamplesOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6631 | return false; |
| 6632 | } |
| 6633 | |
| 6634 | Texture *texture = context->getTargetTexture(target); |
| 6635 | if (!texture || texture->id() == 0) |
| 6636 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6637 | context->validationError(GL_INVALID_OPERATION, kZeroBoundToTarget); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6638 | return false; |
| 6639 | } |
| 6640 | |
| 6641 | if (texture->getImmutableFormat()) |
| 6642 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6643 | context->validationError(GL_INVALID_OPERATION, kImmutableTextureBound); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6644 | return false; |
| 6645 | } |
| 6646 | return true; |
| 6647 | } |
| 6648 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6649 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6650 | TextureType target, |
| 6651 | GLsizei samples, |
| 6652 | GLint internalFormat, |
| 6653 | GLsizei width, |
| 6654 | GLsizei height) |
| 6655 | { |
| 6656 | if (target != TextureType::_2DMultisample) |
| 6657 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6658 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6659 | return false; |
| 6660 | } |
| 6661 | |
| 6662 | if (width < 1 || height < 1) |
| 6663 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6664 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6665 | return false; |
| 6666 | } |
| 6667 | |
| 6668 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6669 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6670 | |
| 6671 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6672 | TextureTarget target, |
| 6673 | GLint level, |
| 6674 | GLenum pname, |
| 6675 | GLsizei *length) |
| 6676 | { |
| 6677 | |
| 6678 | if (length) |
| 6679 | { |
| 6680 | *length = 0; |
| 6681 | } |
| 6682 | |
| 6683 | TextureType type = TextureTargetToType(target); |
| 6684 | |
| 6685 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6686 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6687 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6688 | return false; |
| 6689 | } |
| 6690 | |
| 6691 | if (context->getTargetTexture(type) == nullptr) |
| 6692 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6693 | context->validationError(GL_INVALID_ENUM, "No texture bound."); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6694 | return false; |
| 6695 | } |
| 6696 | |
| 6697 | if (!ValidMipLevel(context, type, level)) |
| 6698 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6699 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6700 | return false; |
| 6701 | } |
| 6702 | |
| 6703 | switch (pname) |
| 6704 | { |
| 6705 | case GL_TEXTURE_RED_TYPE: |
| 6706 | case GL_TEXTURE_GREEN_TYPE: |
| 6707 | case GL_TEXTURE_BLUE_TYPE: |
| 6708 | case GL_TEXTURE_ALPHA_TYPE: |
| 6709 | case GL_TEXTURE_DEPTH_TYPE: |
| 6710 | break; |
| 6711 | case GL_TEXTURE_RED_SIZE: |
| 6712 | case GL_TEXTURE_GREEN_SIZE: |
| 6713 | case GL_TEXTURE_BLUE_SIZE: |
| 6714 | case GL_TEXTURE_ALPHA_SIZE: |
| 6715 | case GL_TEXTURE_DEPTH_SIZE: |
| 6716 | case GL_TEXTURE_STENCIL_SIZE: |
| 6717 | case GL_TEXTURE_SHARED_SIZE: |
| 6718 | break; |
| 6719 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6720 | case GL_TEXTURE_WIDTH: |
| 6721 | case GL_TEXTURE_HEIGHT: |
| 6722 | case GL_TEXTURE_DEPTH: |
| 6723 | break; |
| 6724 | case GL_TEXTURE_SAMPLES: |
| 6725 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6726 | break; |
| 6727 | case GL_TEXTURE_COMPRESSED: |
| 6728 | break; |
| 6729 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6730 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6731 | return false; |
| 6732 | } |
| 6733 | |
| 6734 | if (length) |
| 6735 | { |
| 6736 | *length = 1; |
| 6737 | } |
| 6738 | return true; |
| 6739 | } |
Yizhou Jiang | 7310da3 | 2018-11-05 14:40:01 +0800 | [diff] [blame] | 6740 | |
| 6741 | bool ValidateGetMultisamplefvBase(Context *context, GLenum pname, GLuint index, GLfloat *val) |
| 6742 | { |
| 6743 | if (pname != GL_SAMPLE_POSITION) |
| 6744 | { |
| 6745 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
| 6746 | return false; |
| 6747 | } |
| 6748 | |
| 6749 | Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 6750 | GLint samples = framebuffer->getSamples(context); |
| 6751 | |
| 6752 | if (index >= static_cast<GLuint>(samples)) |
| 6753 | { |
| 6754 | context->validationError(GL_INVALID_VALUE, kIndexExceedsSamples); |
| 6755 | return false; |
| 6756 | } |
| 6757 | |
| 6758 | return true; |
| 6759 | } |
| 6760 | |
| 6761 | bool ValidateSampleMaskiBase(Context *context, GLuint maskNumber, GLbitfield mask) |
| 6762 | { |
| 6763 | if (maskNumber >= context->getCaps().maxSampleMaskWords) |
| 6764 | { |
| 6765 | context->validationError(GL_INVALID_VALUE, kInvalidSampleMaskNumber); |
| 6766 | return false; |
| 6767 | } |
| 6768 | |
| 6769 | return true; |
| 6770 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6771 | } // namespace gl |