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, |
| 636 | GLenum type, |
| 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 | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2962 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2963 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2964 | switch (type) |
| 2965 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2966 | case GL_UNSIGNED_BYTE: |
| 2967 | case GL_UNSIGNED_SHORT: |
| 2968 | break; |
| 2969 | case GL_UNSIGNED_INT: |
| 2970 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2971 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2972 | context->validationError(GL_INVALID_ENUM, kTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2973 | return false; |
| 2974 | } |
| 2975 | break; |
| 2976 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2977 | context->validationError(GL_INVALID_ENUM, kTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2978 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2979 | } |
| 2980 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2981 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2982 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2983 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2984 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2985 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2986 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2987 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2988 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2989 | if (context->getExtensions().geometryShader) |
| 2990 | { |
| 2991 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2992 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2993 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 2994 | context->validationError(GL_INVALID_OPERATION, kInvalidDrawModeTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2995 | return false; |
| 2996 | } |
| 2997 | } |
| 2998 | else |
| 2999 | { |
| 3000 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 3001 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 3002 | // 86) |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3003 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3004 | kUnsupportedDrawModeForTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3005 | return false; |
| 3006 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3009 | return true; |
| 3010 | } |
| 3011 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3012 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3013 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3014 | GLsizei count, |
| 3015 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3016 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3017 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3018 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3019 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3020 | return false; |
| 3021 | |
| 3022 | const State &state = context->getGLState(); |
| 3023 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3024 | if (!ValidateDrawBase(context, mode, count)) |
| 3025 | { |
| 3026 | return false; |
| 3027 | } |
| 3028 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3029 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 3030 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3031 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3032 | GLuint typeBytes = GetTypeInfo(type).bytes; |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3033 | |
| 3034 | if (context->getExtensions().webglCompatibility) |
| 3035 | { |
| 3036 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3037 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3038 | { |
| 3039 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3040 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3041 | // 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] | 3042 | context->validationError(GL_INVALID_OPERATION, kOffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3043 | return false; |
| 3044 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3045 | |
| 3046 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3047 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3048 | // error is generated. |
| 3049 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3050 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3051 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3052 | return false; |
| 3053 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3054 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3055 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 3056 | { |
| 3057 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3058 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3059 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3060 | context->validationError(GL_INVALID_OPERATION, "Index buffer is mapped."); |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3061 | return false; |
| 3062 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3063 | |
| 3064 | if (context->getExtensions().webglCompatibility || |
| 3065 | !context->getGLState().areClientArraysEnabled()) |
| 3066 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3067 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3068 | { |
| 3069 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3070 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3071 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3072 | context->validationError(GL_INVALID_OPERATION, kMustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3073 | return false; |
| 3074 | } |
| 3075 | } |
| 3076 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3077 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3078 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3079 | // This is an application error that would normally result in a crash, but we catch it and |
| 3080 | // return an error |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3081 | context->validationError(GL_INVALID_OPERATION, "No element array buffer and no pointer."); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3082 | return false; |
| 3083 | } |
| 3084 | |
| 3085 | if (count > 0 && elementArrayBuffer) |
| 3086 | { |
| 3087 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3088 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3089 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3090 | constexpr uint64_t kMaxTypeSize = 8; |
| 3091 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3092 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3093 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3094 | |
| 3095 | uint64_t typeSize = typeBytes; |
| 3096 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3097 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3098 | |
| 3099 | // Doing the multiplication here is overflow-safe |
| 3100 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3101 | |
| 3102 | // The offset can be any value, check for overflows |
| 3103 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3104 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3105 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3106 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3107 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3108 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3109 | |
| 3110 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3111 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3112 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3113 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3114 | return false; |
| 3115 | } |
| 3116 | |
| 3117 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3118 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3119 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3120 | context->validationError(GL_INVALID_OPERATION, kMismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3121 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3122 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3123 | |
| 3124 | if (context->getExtensions().webglCompatibility && |
| 3125 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3126 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3127 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3128 | kElementArrayBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3129 | return false; |
| 3130 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3131 | } |
| 3132 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3133 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3134 | { |
| 3135 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 3136 | IndexRange indexRange; |
| 3137 | ANGLE_VALIDATION_TRY(vao->getIndexRange(context, type, count, indices, &indexRange)); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 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 always |
| 3141 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3142 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3143 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3144 | context->validationError(GL_INVALID_OPERATION, kExceedsMaxElement); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3145 | return false; |
| 3146 | } |
| 3147 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3148 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3149 | { |
| 3150 | return false; |
| 3151 | } |
| 3152 | |
| 3153 | // No op if there are no real indices in the index data (all are primitive restart). |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3154 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3155 | } |
| 3156 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3157 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3158 | } |
| 3159 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3160 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3161 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3162 | GLsizei count, |
| 3163 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3164 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3165 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3166 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3167 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3168 | } |
| 3169 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3170 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3171 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3172 | GLsizei count, |
| 3173 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3174 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3175 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3176 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3177 | if (!context->getExtensions().instancedArrays) |
| 3178 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3179 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3180 | return false; |
| 3181 | } |
| 3182 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3183 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3184 | { |
| 3185 | return false; |
| 3186 | } |
| 3187 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3188 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3189 | } |
| 3190 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3191 | bool ValidateFramebufferTextureBase(Context *context, |
| 3192 | GLenum target, |
| 3193 | GLenum attachment, |
| 3194 | GLuint texture, |
| 3195 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3196 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3197 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3198 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3199 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3200 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3201 | } |
| 3202 | |
| 3203 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3204 | { |
| 3205 | return false; |
| 3206 | } |
| 3207 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3208 | if (texture != 0) |
| 3209 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3210 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3211 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3212 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3213 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3214 | context->validationError(GL_INVALID_OPERATION, kMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3215 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3216 | } |
| 3217 | |
| 3218 | if (level < 0) |
| 3219 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3220 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3221 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3222 | } |
| 3223 | } |
| 3224 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3225 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3226 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3227 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3228 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3229 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3230 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3231 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3232 | } |
| 3233 | |
| 3234 | return true; |
| 3235 | } |
| 3236 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3237 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3238 | { |
| 3239 | if (program == 0) |
| 3240 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3241 | context->validationError(GL_INVALID_VALUE, kProgramDoesNotExist); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3242 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3243 | } |
| 3244 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3245 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3246 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3247 | { |
| 3248 | return false; |
| 3249 | } |
| 3250 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3251 | if (!programObject || !programObject->isLinked()) |
| 3252 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3253 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3254 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3255 | } |
| 3256 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3257 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3258 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3259 | context->validationError(GL_INVALID_OPERATION, kInvalidUniformLocation); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3260 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3261 | } |
| 3262 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3263 | return true; |
| 3264 | } |
| 3265 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3266 | static bool ValidateSizedGetUniform(Context *context, |
| 3267 | GLuint program, |
| 3268 | GLint location, |
| 3269 | GLsizei bufSize, |
| 3270 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3271 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3272 | if (length) |
| 3273 | { |
| 3274 | *length = 0; |
| 3275 | } |
| 3276 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3277 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3278 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3279 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3280 | } |
| 3281 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3282 | if (bufSize < 0) |
| 3283 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3284 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3285 | return false; |
| 3286 | } |
| 3287 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3288 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3289 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3290 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3291 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3292 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3293 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3294 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3295 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3296 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3297 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3298 | } |
| 3299 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3300 | if (length) |
| 3301 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3302 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3303 | } |
| 3304 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3305 | return true; |
| 3306 | } |
| 3307 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3308 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3309 | GLuint program, |
| 3310 | GLint location, |
| 3311 | GLsizei bufSize, |
| 3312 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3313 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3314 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3315 | } |
| 3316 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3317 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3318 | GLuint program, |
| 3319 | GLint location, |
| 3320 | GLsizei bufSize, |
| 3321 | GLsizei *length, |
| 3322 | GLfloat *params) |
| 3323 | { |
| 3324 | UNIMPLEMENTED(); |
| 3325 | return false; |
| 3326 | } |
| 3327 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3328 | bool ValidateGetnUniformivEXT(Context *context, |
| 3329 | GLuint program, |
| 3330 | GLint location, |
| 3331 | GLsizei bufSize, |
| 3332 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3333 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3334 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3335 | } |
| 3336 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3337 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3338 | GLuint program, |
| 3339 | GLint location, |
| 3340 | GLsizei bufSize, |
| 3341 | GLsizei *length, |
| 3342 | GLint *params) |
| 3343 | { |
| 3344 | UNIMPLEMENTED(); |
| 3345 | return false; |
| 3346 | } |
| 3347 | |
| 3348 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3349 | GLuint program, |
| 3350 | GLint location, |
| 3351 | GLsizei bufSize, |
| 3352 | GLsizei *length, |
| 3353 | GLuint *params) |
| 3354 | { |
| 3355 | UNIMPLEMENTED(); |
| 3356 | return false; |
| 3357 | } |
| 3358 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3359 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3360 | GLuint program, |
| 3361 | GLint location, |
| 3362 | GLsizei bufSize, |
| 3363 | GLsizei *length, |
| 3364 | GLfloat *params) |
| 3365 | { |
| 3366 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3367 | { |
| 3368 | return false; |
| 3369 | } |
| 3370 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3371 | GLsizei writeLength = 0; |
| 3372 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3373 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3374 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3375 | { |
| 3376 | return false; |
| 3377 | } |
| 3378 | |
| 3379 | SetRobustLengthParam(length, writeLength); |
| 3380 | |
| 3381 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3385 | GLuint program, |
| 3386 | GLint location, |
| 3387 | GLsizei bufSize, |
| 3388 | GLsizei *length, |
| 3389 | GLint *params) |
| 3390 | { |
| 3391 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3392 | { |
| 3393 | return false; |
| 3394 | } |
| 3395 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3396 | GLsizei writeLength = 0; |
| 3397 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3398 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3399 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3400 | { |
| 3401 | return false; |
| 3402 | } |
| 3403 | |
| 3404 | SetRobustLengthParam(length, writeLength); |
| 3405 | |
| 3406 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3407 | } |
| 3408 | |
| 3409 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3410 | GLuint program, |
| 3411 | GLint location, |
| 3412 | GLsizei bufSize, |
| 3413 | GLsizei *length, |
| 3414 | GLuint *params) |
| 3415 | { |
| 3416 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3417 | { |
| 3418 | return false; |
| 3419 | } |
| 3420 | |
| 3421 | if (context->getClientMajorVersion() < 3) |
| 3422 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3423 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3424 | return false; |
| 3425 | } |
| 3426 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3427 | GLsizei writeLength = 0; |
| 3428 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3429 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3430 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3431 | { |
| 3432 | return false; |
| 3433 | } |
| 3434 | |
| 3435 | SetRobustLengthParam(length, writeLength); |
| 3436 | |
| 3437 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3438 | } |
| 3439 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3440 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3441 | GLenum target, |
| 3442 | GLsizei numAttachments, |
| 3443 | const GLenum *attachments, |
| 3444 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3445 | { |
| 3446 | if (numAttachments < 0) |
| 3447 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3448 | context->validationError(GL_INVALID_VALUE, kNegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3449 | return false; |
| 3450 | } |
| 3451 | |
| 3452 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3453 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3454 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3455 | { |
| 3456 | if (defaultFramebuffer) |
| 3457 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3458 | context->validationError(GL_INVALID_ENUM, kDefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3459 | return false; |
| 3460 | } |
| 3461 | |
| 3462 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3463 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3464 | context->validationError(GL_INVALID_OPERATION, |
| 3465 | "Requested color attachment is " |
| 3466 | "greater than the maximum supported " |
| 3467 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3468 | return false; |
| 3469 | } |
| 3470 | } |
| 3471 | else |
| 3472 | { |
| 3473 | switch (attachments[i]) |
| 3474 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3475 | case GL_DEPTH_ATTACHMENT: |
| 3476 | case GL_STENCIL_ATTACHMENT: |
| 3477 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3478 | if (defaultFramebuffer) |
| 3479 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3480 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3481 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3482 | return false; |
| 3483 | } |
| 3484 | break; |
| 3485 | case GL_COLOR: |
| 3486 | case GL_DEPTH: |
| 3487 | case GL_STENCIL: |
| 3488 | if (!defaultFramebuffer) |
| 3489 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3490 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3491 | kDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3492 | return false; |
| 3493 | } |
| 3494 | break; |
| 3495 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3496 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3497 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3498 | } |
| 3499 | } |
| 3500 | } |
| 3501 | |
| 3502 | return true; |
| 3503 | } |
| 3504 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3505 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3506 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3507 | if (!context->getExtensions().debugMarker) |
| 3508 | { |
| 3509 | // The debug marker calls should not set error state |
| 3510 | // 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] | 3511 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3512 | return false; |
| 3513 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3514 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3515 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3516 | if (length < 0) |
| 3517 | { |
| 3518 | return false; |
| 3519 | } |
| 3520 | |
| 3521 | if (marker == nullptr) |
| 3522 | { |
| 3523 | return false; |
| 3524 | } |
| 3525 | |
| 3526 | return true; |
| 3527 | } |
| 3528 | |
| 3529 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3530 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3531 | if (!context->getExtensions().debugMarker) |
| 3532 | { |
| 3533 | // The debug marker calls should not set error state |
| 3534 | // 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] | 3535 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3536 | return false; |
| 3537 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3538 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3539 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3540 | if (length < 0) |
| 3541 | { |
| 3542 | return false; |
| 3543 | } |
| 3544 | |
| 3545 | if (length > 0 && marker == nullptr) |
| 3546 | { |
| 3547 | return false; |
| 3548 | } |
| 3549 | |
| 3550 | return true; |
| 3551 | } |
| 3552 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3553 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3554 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3555 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3556 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3557 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3558 | return false; |
| 3559 | } |
| 3560 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3561 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3562 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3563 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3564 | if (!context->getExtensions().eglImage) |
| 3565 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3566 | context->validationError(GL_INVALID_ENUM, |
| 3567 | "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3568 | } |
| 3569 | break; |
| 3570 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3571 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3572 | if (!context->getExtensions().eglImageExternal) |
| 3573 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3574 | context->validationError(GL_INVALID_ENUM, |
| 3575 | "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3576 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3577 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3578 | break; |
| 3579 | |
| 3580 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3581 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3582 | return false; |
| 3583 | } |
| 3584 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3585 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3586 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3587 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3588 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3589 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3590 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
| 3593 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3594 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3595 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3596 | context->validationError(GL_INVALID_OPERATION, |
| 3597 | "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3598 | return false; |
| 3599 | } |
| 3600 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3601 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3602 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3603 | context->validationError(GL_INVALID_OPERATION, |
| 3604 | "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3605 | return false; |
| 3606 | } |
| 3607 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3608 | return true; |
| 3609 | } |
| 3610 | |
| 3611 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3612 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3613 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3614 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3615 | if (!context->getExtensions().eglImage) |
| 3616 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3617 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3618 | return false; |
| 3619 | } |
| 3620 | |
| 3621 | switch (target) |
| 3622 | { |
| 3623 | case GL_RENDERBUFFER: |
| 3624 | break; |
| 3625 | |
| 3626 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3627 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3628 | return false; |
| 3629 | } |
| 3630 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3631 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3632 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3633 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3634 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3635 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3636 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3637 | return false; |
| 3638 | } |
| 3639 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3640 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3641 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3642 | context->validationError(GL_INVALID_OPERATION, |
| 3643 | "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3644 | return false; |
| 3645 | } |
| 3646 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3647 | return true; |
| 3648 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3649 | |
| 3650 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3651 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3652 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3653 | { |
| 3654 | // The default VAO should always exist |
| 3655 | ASSERT(array != 0); |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3656 | context->validationError(GL_INVALID_OPERATION, kInvalidVertexArray); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3657 | return false; |
| 3658 | } |
| 3659 | |
| 3660 | return true; |
| 3661 | } |
| 3662 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3663 | bool ValidateProgramBinaryBase(Context *context, |
| 3664 | GLuint program, |
| 3665 | GLenum binaryFormat, |
| 3666 | const void *binary, |
| 3667 | GLint length) |
| 3668 | { |
| 3669 | Program *programObject = GetValidProgram(context, program); |
| 3670 | if (programObject == nullptr) |
| 3671 | { |
| 3672 | return false; |
| 3673 | } |
| 3674 | |
| 3675 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3676 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3677 | programBinaryFormats.end()) |
| 3678 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3679 | context->validationError(GL_INVALID_ENUM, "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3680 | return false; |
| 3681 | } |
| 3682 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3683 | if (context->hasActiveTransformFeedback(program)) |
| 3684 | { |
| 3685 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3686 | context->validationError(GL_INVALID_OPERATION, |
| 3687 | "Cannot change program binary while program " |
| 3688 | "is associated with an active transform " |
| 3689 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3690 | return false; |
| 3691 | } |
| 3692 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3693 | return true; |
| 3694 | } |
| 3695 | |
| 3696 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3697 | GLuint program, |
| 3698 | GLsizei bufSize, |
| 3699 | GLsizei *length, |
| 3700 | GLenum *binaryFormat, |
| 3701 | void *binary) |
| 3702 | { |
| 3703 | Program *programObject = GetValidProgram(context, program); |
| 3704 | if (programObject == nullptr) |
| 3705 | { |
| 3706 | return false; |
| 3707 | } |
| 3708 | |
| 3709 | if (!programObject->isLinked()) |
| 3710 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3711 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3712 | return false; |
| 3713 | } |
| 3714 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3715 | if (context->getCaps().programBinaryFormats.empty()) |
| 3716 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3717 | context->validationError(GL_INVALID_OPERATION, "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3718 | return false; |
| 3719 | } |
| 3720 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3721 | return true; |
| 3722 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3723 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3724 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3725 | { |
| 3726 | // 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] | 3727 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3728 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3729 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3730 | return false; |
| 3731 | } |
| 3732 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3733 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3734 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3735 | return false; |
| 3736 | } |
| 3737 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3738 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3739 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3740 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3741 | |
| 3742 | // This should come first before the check for the default frame buffer |
| 3743 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3744 | // rather than INVALID_OPERATION |
| 3745 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3746 | { |
| 3747 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3748 | |
| 3749 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3750 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3751 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3752 | { |
| 3753 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3754 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3755 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3756 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3757 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3758 | context->validationError(GL_INVALID_ENUM, "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3759 | return false; |
| 3760 | } |
| 3761 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3762 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3763 | context->validationError(GL_INVALID_OPERATION, |
| 3764 | "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3765 | return false; |
| 3766 | } |
| 3767 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3768 | frameBufferId != 0) |
| 3769 | { |
| 3770 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3771 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3772 | context->validationError(GL_INVALID_OPERATION, |
| 3773 | "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3774 | return false; |
| 3775 | } |
| 3776 | } |
| 3777 | |
| 3778 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3779 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3780 | if (frameBufferId == 0) |
| 3781 | { |
| 3782 | if (n != 1) |
| 3783 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3784 | context->validationError(GL_INVALID_OPERATION, |
| 3785 | "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3786 | return false; |
| 3787 | } |
| 3788 | |
| 3789 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3790 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3791 | context->validationError( |
| 3792 | GL_INVALID_OPERATION, |
| 3793 | "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] | 3794 | return false; |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | return true; |
| 3799 | } |
| 3800 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3801 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3802 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3803 | GLenum pname, |
| 3804 | GLsizei *length, |
| 3805 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3806 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3807 | if (length) |
| 3808 | { |
| 3809 | *length = 0; |
| 3810 | } |
| 3811 | |
| 3812 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3813 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3814 | context->validationError( |
| 3815 | GL_INVALID_OPERATION, |
| 3816 | "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] | 3817 | return false; |
| 3818 | } |
| 3819 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3820 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3821 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3822 | context->validationError(GL_INVALID_ENUM, "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3823 | return false; |
| 3824 | } |
| 3825 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3826 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3827 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3828 | case GL_BUFFER_MAP_POINTER: |
| 3829 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3830 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3831 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3832 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3833 | return false; |
| 3834 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3835 | |
| 3836 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3837 | // target bound to zero generate an INVALID_OPERATION error." |
| 3838 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3839 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3840 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3841 | context->validationError(GL_INVALID_OPERATION, |
| 3842 | "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3843 | return false; |
| 3844 | } |
| 3845 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3846 | if (length) |
| 3847 | { |
| 3848 | *length = 1; |
| 3849 | } |
| 3850 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3851 | return true; |
| 3852 | } |
| 3853 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3854 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3855 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3856 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3857 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3858 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3859 | return false; |
| 3860 | } |
| 3861 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3862 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3863 | |
| 3864 | if (buffer == nullptr || !buffer->isMapped()) |
| 3865 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3866 | context->validationError(GL_INVALID_OPERATION, "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3867 | return false; |
| 3868 | } |
| 3869 | |
| 3870 | return true; |
| 3871 | } |
| 3872 | |
| 3873 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3874 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3875 | GLintptr offset, |
| 3876 | GLsizeiptr length, |
| 3877 | GLbitfield access) |
| 3878 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3879 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3880 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3881 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3882 | return false; |
| 3883 | } |
| 3884 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3885 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3886 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3887 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3888 | return false; |
| 3889 | } |
| 3890 | |
| 3891 | if (length < 0) |
| 3892 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3893 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3894 | return false; |
| 3895 | } |
| 3896 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3897 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3898 | |
| 3899 | if (!buffer) |
| 3900 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3901 | context->validationError(GL_INVALID_OPERATION, "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3902 | return false; |
| 3903 | } |
| 3904 | |
| 3905 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3906 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3907 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3908 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3909 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3910 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3911 | context->validationError(GL_INVALID_VALUE, |
| 3912 | "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3913 | return false; |
| 3914 | } |
| 3915 | |
| 3916 | // Check for invalid bits in the mask |
| 3917 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3918 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3919 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3920 | |
| 3921 | if (access & ~(allAccessBits)) |
| 3922 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3923 | context->validationError(GL_INVALID_VALUE, "Invalid access bits"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3924 | return false; |
| 3925 | } |
| 3926 | |
| 3927 | if (length == 0) |
| 3928 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3929 | context->validationError(GL_INVALID_OPERATION, "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3930 | return false; |
| 3931 | } |
| 3932 | |
| 3933 | if (buffer->isMapped()) |
| 3934 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3935 | context->validationError(GL_INVALID_OPERATION, "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3936 | return false; |
| 3937 | } |
| 3938 | |
| 3939 | // Check for invalid bit combinations |
| 3940 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3941 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3942 | context->validationError(GL_INVALID_OPERATION, |
| 3943 | "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3944 | return false; |
| 3945 | } |
| 3946 | |
| 3947 | GLbitfield writeOnlyBits = |
| 3948 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3949 | |
| 3950 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3951 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3952 | context->validationError(GL_INVALID_OPERATION, |
| 3953 | "Invalid access bits when mapping buffer for reading"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3954 | return false; |
| 3955 | } |
| 3956 | |
| 3957 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3958 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3959 | context->validationError( |
| 3960 | GL_INVALID_OPERATION, |
| 3961 | "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] | 3962 | return false; |
| 3963 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3964 | |
| 3965 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3969 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3970 | GLintptr offset, |
| 3971 | GLsizeiptr length) |
| 3972 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3973 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3974 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3975 | context->validationError(GL_INVALID_VALUE, kNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3976 | return false; |
| 3977 | } |
| 3978 | |
| 3979 | if (length < 0) |
| 3980 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3981 | context->validationError(GL_INVALID_VALUE, kNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3982 | return false; |
| 3983 | } |
| 3984 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3985 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3986 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 3987 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3988 | return false; |
| 3989 | } |
| 3990 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3991 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3992 | |
| 3993 | if (buffer == nullptr) |
| 3994 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3995 | context->validationError(GL_INVALID_OPERATION, "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3996 | return false; |
| 3997 | } |
| 3998 | |
| 3999 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4000 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4001 | context->validationError(GL_INVALID_OPERATION, |
| 4002 | "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4003 | return false; |
| 4004 | } |
| 4005 | |
| 4006 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4007 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4008 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4009 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4010 | if (!checkedSize.IsValid() || |
| 4011 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4012 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4013 | context->validationError(GL_INVALID_VALUE, |
| 4014 | "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4015 | return false; |
| 4016 | } |
| 4017 | |
| 4018 | return true; |
| 4019 | } |
| 4020 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4021 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4022 | { |
| 4023 | if (n < 0) |
| 4024 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4025 | context->validationError(GL_INVALID_VALUE, kNegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4026 | return false; |
| 4027 | } |
| 4028 | return true; |
| 4029 | } |
| 4030 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4031 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4032 | { |
| 4033 | if (!context->getExtensions().robustClientMemory) |
| 4034 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4035 | context->validationError(GL_INVALID_OPERATION, |
| 4036 | "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4037 | return false; |
| 4038 | } |
| 4039 | |
| 4040 | if (bufSize < 0) |
| 4041 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4042 | context->validationError(GL_INVALID_VALUE, kNegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4043 | return false; |
| 4044 | } |
| 4045 | |
| 4046 | return true; |
| 4047 | } |
| 4048 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4049 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4050 | { |
| 4051 | if (bufSize < numParams) |
| 4052 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4053 | context->validationError(GL_INVALID_OPERATION, |
| 4054 | "More parameters are required than were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4055 | return false; |
| 4056 | } |
| 4057 | |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4061 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4062 | GLenum target, |
| 4063 | GLenum attachment, |
| 4064 | GLenum pname, |
| 4065 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4066 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4067 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4068 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4069 | context->validationError(GL_INVALID_ENUM, kInvalidFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4070 | return false; |
| 4071 | } |
| 4072 | |
| 4073 | int clientVersion = context->getClientMajorVersion(); |
| 4074 | |
| 4075 | switch (pname) |
| 4076 | { |
| 4077 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4078 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4079 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4080 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4081 | break; |
| 4082 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4083 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4084 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4085 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4086 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4087 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4088 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4089 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4090 | return false; |
| 4091 | } |
| 4092 | break; |
| 4093 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4094 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4095 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4096 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4097 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4098 | return false; |
| 4099 | } |
| 4100 | break; |
| 4101 | |
| 4102 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4103 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4104 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4105 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4106 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4107 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4108 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4109 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4110 | if (clientVersion < 3) |
| 4111 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4112 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4113 | return false; |
| 4114 | } |
| 4115 | break; |
| 4116 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4117 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4118 | if (!context->getExtensions().geometryShader) |
| 4119 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4120 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4121 | return false; |
| 4122 | } |
| 4123 | break; |
| 4124 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4125 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4126 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4127 | return false; |
| 4128 | } |
| 4129 | |
| 4130 | // Determine if the attachment is a valid enum |
| 4131 | switch (attachment) |
| 4132 | { |
| 4133 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4134 | case GL_DEPTH: |
| 4135 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4136 | if (clientVersion < 3) |
| 4137 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4138 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4139 | return false; |
| 4140 | } |
| 4141 | break; |
| 4142 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4143 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4144 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4145 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4146 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4147 | return false; |
| 4148 | } |
| 4149 | break; |
| 4150 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4151 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4152 | case GL_DEPTH_ATTACHMENT: |
| 4153 | case GL_STENCIL_ATTACHMENT: |
| 4154 | break; |
| 4155 | |
| 4156 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4157 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4158 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4159 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4160 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4161 | context->validationError(GL_INVALID_ENUM, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4162 | return false; |
| 4163 | } |
| 4164 | break; |
| 4165 | } |
| 4166 | |
| 4167 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4168 | ASSERT(framebuffer); |
| 4169 | |
| 4170 | if (framebuffer->id() == 0) |
| 4171 | { |
| 4172 | if (clientVersion < 3) |
| 4173 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4174 | context->validationError(GL_INVALID_OPERATION, kDefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4175 | return false; |
| 4176 | } |
| 4177 | |
| 4178 | switch (attachment) |
| 4179 | { |
| 4180 | case GL_BACK: |
| 4181 | case GL_DEPTH: |
| 4182 | case GL_STENCIL: |
| 4183 | break; |
| 4184 | |
| 4185 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4186 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4187 | return false; |
| 4188 | } |
| 4189 | } |
| 4190 | else |
| 4191 | { |
| 4192 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4193 | { |
| 4194 | // Valid attachment query |
| 4195 | } |
| 4196 | else |
| 4197 | { |
| 4198 | switch (attachment) |
| 4199 | { |
| 4200 | case GL_DEPTH_ATTACHMENT: |
| 4201 | case GL_STENCIL_ATTACHMENT: |
| 4202 | break; |
| 4203 | |
| 4204 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4205 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4206 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4207 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4208 | return false; |
| 4209 | } |
| 4210 | break; |
| 4211 | |
| 4212 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4213 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4214 | return false; |
| 4215 | } |
| 4216 | } |
| 4217 | } |
| 4218 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4219 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4220 | if (attachmentObject) |
| 4221 | { |
| 4222 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4223 | attachmentObject->type() == GL_TEXTURE || |
| 4224 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4225 | |
| 4226 | switch (pname) |
| 4227 | { |
| 4228 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4229 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4230 | attachmentObject->type() != GL_TEXTURE) |
| 4231 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4232 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4233 | return false; |
| 4234 | } |
| 4235 | break; |
| 4236 | |
| 4237 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4238 | if (attachmentObject->type() != GL_TEXTURE) |
| 4239 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4240 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4241 | return false; |
| 4242 | } |
| 4243 | break; |
| 4244 | |
| 4245 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4246 | if (attachmentObject->type() != GL_TEXTURE) |
| 4247 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4248 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4249 | return false; |
| 4250 | } |
| 4251 | break; |
| 4252 | |
| 4253 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4254 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4255 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4256 | context->validationError(GL_INVALID_OPERATION, kInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4257 | return false; |
| 4258 | } |
| 4259 | break; |
| 4260 | |
| 4261 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4262 | if (attachmentObject->type() != GL_TEXTURE) |
| 4263 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4264 | context->validationError(GL_INVALID_ENUM, kFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4265 | return false; |
| 4266 | } |
| 4267 | break; |
| 4268 | |
| 4269 | default: |
| 4270 | break; |
| 4271 | } |
| 4272 | } |
| 4273 | else |
| 4274 | { |
| 4275 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4276 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4277 | |
| 4278 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4279 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4280 | // INVALID_OPERATION for all other pnames |
| 4281 | |
| 4282 | switch (pname) |
| 4283 | { |
| 4284 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4285 | break; |
| 4286 | |
| 4287 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4288 | if (clientVersion < 3) |
| 4289 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4290 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4291 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4292 | return false; |
| 4293 | } |
| 4294 | break; |
| 4295 | |
| 4296 | default: |
| 4297 | if (clientVersion < 3) |
| 4298 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4299 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4300 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4301 | return false; |
| 4302 | } |
| 4303 | else |
| 4304 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4305 | context->validationError(GL_INVALID_OPERATION, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4306 | kInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4307 | return false; |
| 4308 | } |
| 4309 | } |
| 4310 | } |
| 4311 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4312 | if (numParams) |
| 4313 | { |
| 4314 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4315 | { |
| 4316 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4317 | // parameters. |
| 4318 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4319 | *numParams = numViews * 2; |
| 4320 | } |
| 4321 | else |
| 4322 | { |
| 4323 | // For all other queries we can have only one output parameter. |
| 4324 | *numParams = 1; |
| 4325 | } |
| 4326 | } |
| 4327 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4328 | return true; |
| 4329 | } |
| 4330 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4331 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4332 | GLenum target, |
| 4333 | GLenum attachment, |
| 4334 | GLenum pname, |
| 4335 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4336 | GLsizei *length, |
| 4337 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4338 | { |
| 4339 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4340 | { |
| 4341 | return false; |
| 4342 | } |
| 4343 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4344 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4345 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4346 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4347 | { |
| 4348 | return false; |
| 4349 | } |
| 4350 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4351 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4352 | { |
| 4353 | return false; |
| 4354 | } |
| 4355 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4356 | SetRobustLengthParam(length, numParams); |
| 4357 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4358 | return true; |
| 4359 | } |
| 4360 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4361 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4362 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4363 | GLenum pname, |
| 4364 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4365 | GLsizei *length, |
| 4366 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4367 | { |
| 4368 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4369 | { |
| 4370 | return false; |
| 4371 | } |
| 4372 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4373 | GLsizei numParams = 0; |
| 4374 | |
| 4375 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4376 | { |
| 4377 | return false; |
| 4378 | } |
| 4379 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4380 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4381 | { |
| 4382 | return false; |
| 4383 | } |
| 4384 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4385 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4386 | return true; |
| 4387 | } |
| 4388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4389 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4390 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4391 | GLenum pname, |
| 4392 | GLsizei bufSize, |
| 4393 | GLsizei *length, |
| 4394 | GLint64 *params) |
| 4395 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4396 | GLsizei numParams = 0; |
| 4397 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4398 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4399 | { |
| 4400 | return false; |
| 4401 | } |
| 4402 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4403 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4404 | { |
| 4405 | return false; |
| 4406 | } |
| 4407 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4408 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4409 | { |
| 4410 | return false; |
| 4411 | } |
| 4412 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4413 | SetRobustLengthParam(length, numParams); |
| 4414 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4415 | return true; |
| 4416 | } |
| 4417 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4418 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4419 | { |
| 4420 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4421 | if (numParams) |
| 4422 | { |
| 4423 | *numParams = 1; |
| 4424 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4425 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4426 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4427 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4428 | ? GetValidProgramNoResolve(context, program) |
| 4429 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4430 | if (!programObject) |
| 4431 | { |
| 4432 | return false; |
| 4433 | } |
| 4434 | |
| 4435 | switch (pname) |
| 4436 | { |
| 4437 | case GL_DELETE_STATUS: |
| 4438 | case GL_LINK_STATUS: |
| 4439 | case GL_VALIDATE_STATUS: |
| 4440 | case GL_INFO_LOG_LENGTH: |
| 4441 | case GL_ATTACHED_SHADERS: |
| 4442 | case GL_ACTIVE_ATTRIBUTES: |
| 4443 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4444 | case GL_ACTIVE_UNIFORMS: |
| 4445 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4446 | break; |
| 4447 | |
| 4448 | case GL_PROGRAM_BINARY_LENGTH: |
| 4449 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4450 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4451 | context->validationError(GL_INVALID_ENUM, |
| 4452 | "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4453 | "requires GL_OES_get_program_binary or " |
| 4454 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4455 | return false; |
| 4456 | } |
| 4457 | break; |
| 4458 | |
| 4459 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4460 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4461 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4462 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4463 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4464 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4465 | if (context->getClientMajorVersion() < 3) |
| 4466 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4467 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4468 | return false; |
| 4469 | } |
| 4470 | break; |
| 4471 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4472 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4473 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4474 | if (context->getClientVersion() < Version(3, 1)) |
| 4475 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4476 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4477 | return false; |
| 4478 | } |
| 4479 | break; |
| 4480 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4481 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4482 | if (context->getClientVersion() < Version(3, 1)) |
| 4483 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4484 | context->validationError(GL_INVALID_ENUM, kES31Required); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4485 | return false; |
| 4486 | } |
| 4487 | |
| 4488 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4489 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4490 | // program which has not been linked successfully, or which does not contain objects to |
| 4491 | // form a compute shader. |
| 4492 | if (!programObject->isLinked()) |
| 4493 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4494 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4495 | return false; |
| 4496 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4497 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4498 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4499 | context->validationError(GL_INVALID_OPERATION, kNoActiveComputeShaderStage); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4500 | return false; |
| 4501 | } |
| 4502 | break; |
| 4503 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4504 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4505 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4506 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4507 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4508 | if (!context->getExtensions().geometryShader) |
| 4509 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4510 | context->validationError(GL_INVALID_ENUM, kGeometryShaderExtensionNotEnabled); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4511 | return false; |
| 4512 | } |
| 4513 | |
| 4514 | // [EXT_geometry_shader] Chapter 7.12 |
| 4515 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4516 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4517 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4518 | // successfully, or which does not contain objects to form a geometry shader. |
| 4519 | if (!programObject->isLinked()) |
| 4520 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4521 | context->validationError(GL_INVALID_OPERATION, kProgramNotLinked); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4522 | return false; |
| 4523 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4524 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4525 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4526 | context->validationError(GL_INVALID_OPERATION, kNoActiveGeometryShaderStage); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4527 | return false; |
| 4528 | } |
| 4529 | break; |
| 4530 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4531 | case GL_COMPLETION_STATUS_KHR: |
| 4532 | if (!context->getExtensions().parallelShaderCompile) |
| 4533 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4534 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4535 | return false; |
| 4536 | } |
| 4537 | break; |
| 4538 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4539 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 4540 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4541 | return false; |
| 4542 | } |
| 4543 | |
| 4544 | return true; |
| 4545 | } |
| 4546 | |
| 4547 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4548 | GLuint program, |
| 4549 | GLenum pname, |
| 4550 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4551 | GLsizei *length, |
| 4552 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4553 | { |
| 4554 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4555 | { |
| 4556 | return false; |
| 4557 | } |
| 4558 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4559 | GLsizei numParams = 0; |
| 4560 | |
| 4561 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4562 | { |
| 4563 | return false; |
| 4564 | } |
| 4565 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4566 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4567 | { |
| 4568 | return false; |
| 4569 | } |
| 4570 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4571 | SetRobustLengthParam(length, numParams); |
| 4572 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4573 | return true; |
| 4574 | } |
| 4575 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4576 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4577 | GLenum target, |
| 4578 | GLenum pname, |
| 4579 | GLsizei bufSize, |
| 4580 | GLsizei *length, |
| 4581 | GLint *params) |
| 4582 | { |
| 4583 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4584 | { |
| 4585 | return false; |
| 4586 | } |
| 4587 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4588 | GLsizei numParams = 0; |
| 4589 | |
| 4590 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4591 | { |
| 4592 | return false; |
| 4593 | } |
| 4594 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4595 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4596 | { |
| 4597 | return false; |
| 4598 | } |
| 4599 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4600 | SetRobustLengthParam(length, numParams); |
| 4601 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4602 | return true; |
| 4603 | } |
| 4604 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4605 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4606 | GLuint shader, |
| 4607 | GLenum pname, |
| 4608 | GLsizei bufSize, |
| 4609 | GLsizei *length, |
| 4610 | GLint *params) |
| 4611 | { |
| 4612 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4613 | { |
| 4614 | return false; |
| 4615 | } |
| 4616 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4617 | GLsizei numParams = 0; |
| 4618 | |
| 4619 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4620 | { |
| 4621 | return false; |
| 4622 | } |
| 4623 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4624 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4625 | { |
| 4626 | return false; |
| 4627 | } |
| 4628 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4629 | SetRobustLengthParam(length, numParams); |
| 4630 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4631 | return true; |
| 4632 | } |
| 4633 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4634 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4635 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4636 | GLenum pname, |
| 4637 | GLsizei bufSize, |
| 4638 | GLsizei *length, |
| 4639 | GLfloat *params) |
| 4640 | { |
| 4641 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4642 | { |
| 4643 | return false; |
| 4644 | } |
| 4645 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4646 | GLsizei numParams = 0; |
| 4647 | |
| 4648 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4649 | { |
| 4650 | return false; |
| 4651 | } |
| 4652 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4653 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4654 | { |
| 4655 | return false; |
| 4656 | } |
| 4657 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4658 | SetRobustLengthParam(length, numParams); |
| 4659 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4660 | return true; |
| 4661 | } |
| 4662 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4663 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4664 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4665 | GLenum pname, |
| 4666 | GLsizei bufSize, |
| 4667 | GLsizei *length, |
| 4668 | GLint *params) |
| 4669 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4670 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4671 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4672 | { |
| 4673 | return false; |
| 4674 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4675 | GLsizei numParams = 0; |
| 4676 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4677 | { |
| 4678 | return false; |
| 4679 | } |
| 4680 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4681 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4682 | { |
| 4683 | return false; |
| 4684 | } |
| 4685 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4686 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4687 | return true; |
| 4688 | } |
| 4689 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4690 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4691 | TextureType target, |
| 4692 | GLenum pname, |
| 4693 | GLsizei bufSize, |
| 4694 | GLsizei *length, |
| 4695 | GLint *params) |
| 4696 | { |
| 4697 | UNIMPLEMENTED(); |
| 4698 | return false; |
| 4699 | } |
| 4700 | |
| 4701 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4702 | TextureType target, |
| 4703 | GLenum pname, |
| 4704 | GLsizei bufSize, |
| 4705 | GLsizei *length, |
| 4706 | GLuint *params) |
| 4707 | { |
| 4708 | UNIMPLEMENTED(); |
| 4709 | return false; |
| 4710 | } |
| 4711 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4712 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4713 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4714 | GLenum pname, |
| 4715 | GLsizei bufSize, |
| 4716 | const GLfloat *params) |
| 4717 | { |
| 4718 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4719 | { |
| 4720 | return false; |
| 4721 | } |
| 4722 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4723 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4724 | } |
| 4725 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4726 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4727 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4728 | GLenum pname, |
| 4729 | GLsizei bufSize, |
| 4730 | const GLint *params) |
| 4731 | { |
| 4732 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4733 | { |
| 4734 | return false; |
| 4735 | } |
| 4736 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4737 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4738 | } |
| 4739 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4740 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4741 | TextureType target, |
| 4742 | GLenum pname, |
| 4743 | GLsizei bufSize, |
| 4744 | const GLint *params) |
| 4745 | { |
| 4746 | UNIMPLEMENTED(); |
| 4747 | return false; |
| 4748 | } |
| 4749 | |
| 4750 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4751 | TextureType target, |
| 4752 | GLenum pname, |
| 4753 | GLsizei bufSize, |
| 4754 | const GLuint *params) |
| 4755 | { |
| 4756 | UNIMPLEMENTED(); |
| 4757 | return false; |
| 4758 | } |
| 4759 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4760 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4761 | GLuint sampler, |
| 4762 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4763 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4764 | GLsizei *length, |
| 4765 | GLfloat *params) |
| 4766 | { |
| 4767 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4768 | { |
| 4769 | return false; |
| 4770 | } |
| 4771 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4772 | GLsizei numParams = 0; |
| 4773 | |
| 4774 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4775 | { |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4779 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4780 | { |
| 4781 | return false; |
| 4782 | } |
| 4783 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4784 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4785 | return true; |
| 4786 | } |
| 4787 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4788 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4789 | GLuint sampler, |
| 4790 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4791 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4792 | GLsizei *length, |
| 4793 | GLint *params) |
| 4794 | { |
| 4795 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4796 | { |
| 4797 | return false; |
| 4798 | } |
| 4799 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4800 | GLsizei numParams = 0; |
| 4801 | |
| 4802 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4803 | { |
| 4804 | return false; |
| 4805 | } |
| 4806 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4807 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4808 | { |
| 4809 | return false; |
| 4810 | } |
| 4811 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4812 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4813 | return true; |
| 4814 | } |
| 4815 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4816 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4817 | GLuint sampler, |
| 4818 | GLenum pname, |
| 4819 | GLsizei bufSize, |
| 4820 | GLsizei *length, |
| 4821 | GLint *params) |
| 4822 | { |
| 4823 | UNIMPLEMENTED(); |
| 4824 | return false; |
| 4825 | } |
| 4826 | |
| 4827 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4828 | GLuint sampler, |
| 4829 | GLenum pname, |
| 4830 | GLsizei bufSize, |
| 4831 | GLsizei *length, |
| 4832 | GLuint *params) |
| 4833 | { |
| 4834 | UNIMPLEMENTED(); |
| 4835 | return false; |
| 4836 | } |
| 4837 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4838 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4839 | GLuint sampler, |
| 4840 | GLenum pname, |
| 4841 | GLsizei bufSize, |
| 4842 | const GLfloat *params) |
| 4843 | { |
| 4844 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4845 | { |
| 4846 | return false; |
| 4847 | } |
| 4848 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4849 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4850 | } |
| 4851 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4852 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4853 | GLuint sampler, |
| 4854 | GLenum pname, |
| 4855 | GLsizei bufSize, |
| 4856 | const GLint *params) |
| 4857 | { |
| 4858 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4859 | { |
| 4860 | return false; |
| 4861 | } |
| 4862 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4863 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4864 | } |
| 4865 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4866 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4867 | GLuint sampler, |
| 4868 | GLenum pname, |
| 4869 | GLsizei bufSize, |
| 4870 | const GLint *param) |
| 4871 | { |
| 4872 | UNIMPLEMENTED(); |
| 4873 | return false; |
| 4874 | } |
| 4875 | |
| 4876 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4877 | GLuint sampler, |
| 4878 | GLenum pname, |
| 4879 | GLsizei bufSize, |
| 4880 | const GLuint *param) |
| 4881 | { |
| 4882 | UNIMPLEMENTED(); |
| 4883 | return false; |
| 4884 | } |
| 4885 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4886 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4887 | GLuint index, |
| 4888 | GLenum pname, |
| 4889 | GLsizei bufSize, |
| 4890 | GLsizei *length, |
| 4891 | GLfloat *params) |
| 4892 | { |
| 4893 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4894 | { |
| 4895 | return false; |
| 4896 | } |
| 4897 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4898 | GLsizei writeLength = 0; |
| 4899 | |
| 4900 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4901 | { |
| 4902 | return false; |
| 4903 | } |
| 4904 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4905 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4906 | { |
| 4907 | return false; |
| 4908 | } |
| 4909 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4910 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4911 | return true; |
| 4912 | } |
| 4913 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4914 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4915 | GLuint index, |
| 4916 | GLenum pname, |
| 4917 | GLsizei bufSize, |
| 4918 | GLsizei *length, |
| 4919 | GLint *params) |
| 4920 | { |
| 4921 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4922 | { |
| 4923 | return false; |
| 4924 | } |
| 4925 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4926 | GLsizei writeLength = 0; |
| 4927 | |
| 4928 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4929 | { |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4933 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4934 | { |
| 4935 | return false; |
| 4936 | } |
| 4937 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4938 | SetRobustLengthParam(length, writeLength); |
| 4939 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4940 | return true; |
| 4941 | } |
| 4942 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4943 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4944 | GLuint index, |
| 4945 | GLenum pname, |
| 4946 | GLsizei bufSize, |
| 4947 | GLsizei *length, |
| 4948 | void **pointer) |
| 4949 | { |
| 4950 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4951 | { |
| 4952 | return false; |
| 4953 | } |
| 4954 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4955 | GLsizei writeLength = 0; |
| 4956 | |
| 4957 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4958 | { |
| 4959 | return false; |
| 4960 | } |
| 4961 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4962 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4963 | { |
| 4964 | return false; |
| 4965 | } |
| 4966 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4967 | SetRobustLengthParam(length, writeLength); |
| 4968 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4969 | return true; |
| 4970 | } |
| 4971 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4972 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4973 | GLuint index, |
| 4974 | GLenum pname, |
| 4975 | GLsizei bufSize, |
| 4976 | GLsizei *length, |
| 4977 | GLint *params) |
| 4978 | { |
| 4979 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4980 | { |
| 4981 | return false; |
| 4982 | } |
| 4983 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4984 | GLsizei writeLength = 0; |
| 4985 | |
| 4986 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4987 | { |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4991 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4992 | { |
| 4993 | return false; |
| 4994 | } |
| 4995 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4996 | SetRobustLengthParam(length, writeLength); |
| 4997 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4998 | return true; |
| 4999 | } |
| 5000 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5001 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5002 | GLuint index, |
| 5003 | GLenum pname, |
| 5004 | GLsizei bufSize, |
| 5005 | GLsizei *length, |
| 5006 | GLuint *params) |
| 5007 | { |
| 5008 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5009 | { |
| 5010 | return false; |
| 5011 | } |
| 5012 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5013 | GLsizei writeLength = 0; |
| 5014 | |
| 5015 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5016 | { |
| 5017 | return false; |
| 5018 | } |
| 5019 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5020 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5021 | { |
| 5022 | return false; |
| 5023 | } |
| 5024 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5025 | SetRobustLengthParam(length, writeLength); |
| 5026 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5027 | return true; |
| 5028 | } |
| 5029 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5030 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5031 | GLuint program, |
| 5032 | GLuint uniformBlockIndex, |
| 5033 | GLenum pname, |
| 5034 | GLsizei bufSize, |
| 5035 | GLsizei *length, |
| 5036 | GLint *params) |
| 5037 | { |
| 5038 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5039 | { |
| 5040 | return false; |
| 5041 | } |
| 5042 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5043 | GLsizei writeLength = 0; |
| 5044 | |
| 5045 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5046 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5047 | { |
| 5048 | return false; |
| 5049 | } |
| 5050 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5051 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5052 | { |
| 5053 | return false; |
| 5054 | } |
| 5055 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5056 | SetRobustLengthParam(length, writeLength); |
| 5057 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5058 | return true; |
| 5059 | } |
| 5060 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5061 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5062 | GLenum target, |
| 5063 | GLenum internalformat, |
| 5064 | GLenum pname, |
| 5065 | GLsizei bufSize, |
| 5066 | GLsizei *length, |
| 5067 | GLint *params) |
| 5068 | { |
| 5069 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5070 | { |
| 5071 | return false; |
| 5072 | } |
| 5073 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5074 | GLsizei numParams = 0; |
| 5075 | |
| 5076 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5077 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5078 | { |
| 5079 | return false; |
| 5080 | } |
| 5081 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5082 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5083 | { |
| 5084 | return false; |
| 5085 | } |
| 5086 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5087 | SetRobustLengthParam(length, numParams); |
| 5088 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5089 | return true; |
| 5090 | } |
| 5091 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5092 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5093 | GLuint attribIndex, |
| 5094 | GLint size, |
| 5095 | GLenum type, |
| 5096 | GLboolean pureInteger) |
| 5097 | { |
| 5098 | const Caps &caps = context->getCaps(); |
| 5099 | if (attribIndex >= caps.maxVertexAttributes) |
| 5100 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5101 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5102 | return false; |
| 5103 | } |
| 5104 | |
| 5105 | if (size < 1 || size > 4) |
| 5106 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5107 | context->validationError(GL_INVALID_VALUE, kInvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5108 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5109 | } |
| 5110 | |
| 5111 | switch (type) |
| 5112 | { |
| 5113 | case GL_BYTE: |
| 5114 | case GL_UNSIGNED_BYTE: |
| 5115 | case GL_SHORT: |
| 5116 | case GL_UNSIGNED_SHORT: |
| 5117 | break; |
| 5118 | |
| 5119 | case GL_INT: |
| 5120 | case GL_UNSIGNED_INT: |
| 5121 | if (context->getClientMajorVersion() < 3) |
| 5122 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5123 | context->validationError(GL_INVALID_ENUM, |
| 5124 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5125 | return false; |
| 5126 | } |
| 5127 | break; |
| 5128 | |
| 5129 | case GL_FIXED: |
| 5130 | case GL_FLOAT: |
| 5131 | if (pureInteger) |
| 5132 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5133 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5134 | return false; |
| 5135 | } |
| 5136 | break; |
| 5137 | |
| 5138 | case GL_HALF_FLOAT: |
| 5139 | if (context->getClientMajorVersion() < 3) |
| 5140 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5141 | context->validationError(GL_INVALID_ENUM, |
| 5142 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5143 | return false; |
| 5144 | } |
| 5145 | if (pureInteger) |
| 5146 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5147 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5148 | return false; |
| 5149 | } |
| 5150 | break; |
| 5151 | |
| 5152 | case GL_INT_2_10_10_10_REV: |
| 5153 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5154 | if (context->getClientMajorVersion() < 3) |
| 5155 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5156 | context->validationError(GL_INVALID_ENUM, |
| 5157 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5158 | return false; |
| 5159 | } |
| 5160 | if (pureInteger) |
| 5161 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5162 | context->validationError(GL_INVALID_ENUM, kInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5163 | return false; |
| 5164 | } |
| 5165 | if (size != 4) |
| 5166 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5167 | context->validationError(GL_INVALID_OPERATION, |
| 5168 | "Type is INT_2_10_10_10_REV or " |
| 5169 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5170 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5171 | return false; |
| 5172 | } |
| 5173 | break; |
| 5174 | |
| 5175 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5176 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | |
| 5180 | return true; |
| 5181 | } |
| 5182 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5183 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5184 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5185 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5186 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5187 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5188 | GLint drawbuffer, |
| 5189 | const GLenum *validComponentTypes, |
| 5190 | size_t validComponentTypeCount) |
| 5191 | { |
| 5192 | const FramebufferAttachment *attachment = |
| 5193 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5194 | if (attachment) |
| 5195 | { |
| 5196 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5197 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5198 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5199 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5200 | context->validationError( |
| 5201 | GL_INVALID_OPERATION, |
| 5202 | "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5203 | return false; |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | return true; |
| 5208 | } |
| 5209 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5210 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5211 | { |
| 5212 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5213 | { |
| 5214 | return false; |
| 5215 | } |
| 5216 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5217 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5218 | if (pixelUnpackBuffer == nullptr) |
| 5219 | { |
| 5220 | if (dataSize < imageSize) |
| 5221 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5222 | context->validationError(GL_INVALID_OPERATION, "dataSize is too small"); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5223 | } |
| 5224 | } |
| 5225 | return true; |
| 5226 | } |
| 5227 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5228 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5229 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5230 | GLenum pname, |
| 5231 | bool pointerVersion, |
| 5232 | GLsizei *numParams) |
| 5233 | { |
| 5234 | if (numParams) |
| 5235 | { |
| 5236 | *numParams = 0; |
| 5237 | } |
| 5238 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5239 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5240 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5241 | context->validationError(GL_INVALID_ENUM, kInvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5242 | return false; |
| 5243 | } |
| 5244 | |
| 5245 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5246 | if (!buffer) |
| 5247 | { |
| 5248 | // 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] | 5249 | context->validationError(GL_INVALID_OPERATION, kBufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5250 | return false; |
| 5251 | } |
| 5252 | |
| 5253 | const Extensions &extensions = context->getExtensions(); |
| 5254 | |
| 5255 | switch (pname) |
| 5256 | { |
| 5257 | case GL_BUFFER_USAGE: |
| 5258 | case GL_BUFFER_SIZE: |
| 5259 | break; |
| 5260 | |
| 5261 | case GL_BUFFER_ACCESS_OES: |
| 5262 | if (!extensions.mapBuffer) |
| 5263 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5264 | context->validationError(GL_INVALID_ENUM, |
| 5265 | "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5266 | return false; |
| 5267 | } |
| 5268 | break; |
| 5269 | |
| 5270 | case GL_BUFFER_MAPPED: |
| 5271 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5272 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5273 | !extensions.mapBufferRange) |
| 5274 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5275 | context->validationError(GL_INVALID_ENUM, |
| 5276 | "pname requires OpenGL ES 3.0, " |
| 5277 | "GL_OES_mapbuffer or " |
| 5278 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5279 | return false; |
| 5280 | } |
| 5281 | break; |
| 5282 | |
| 5283 | case GL_BUFFER_MAP_POINTER: |
| 5284 | if (!pointerVersion) |
| 5285 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5286 | context->validationError( |
| 5287 | GL_INVALID_ENUM, |
| 5288 | "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5289 | return false; |
| 5290 | } |
| 5291 | break; |
| 5292 | |
| 5293 | case GL_BUFFER_ACCESS_FLAGS: |
| 5294 | case GL_BUFFER_MAP_OFFSET: |
| 5295 | case GL_BUFFER_MAP_LENGTH: |
| 5296 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5297 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5298 | context->validationError( |
| 5299 | 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] | 5300 | return false; |
| 5301 | } |
| 5302 | break; |
| 5303 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5304 | case GL_MEMORY_SIZE_ANGLE: |
| 5305 | if (!context->getExtensions().memorySize) |
| 5306 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5307 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5308 | return false; |
| 5309 | } |
| 5310 | break; |
| 5311 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5312 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5313 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5314 | return false; |
| 5315 | } |
| 5316 | |
| 5317 | // All buffer parameter queries return one value. |
| 5318 | if (numParams) |
| 5319 | { |
| 5320 | *numParams = 1; |
| 5321 | } |
| 5322 | |
| 5323 | return true; |
| 5324 | } |
| 5325 | |
| 5326 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5327 | GLenum target, |
| 5328 | GLenum pname, |
| 5329 | GLsizei *length) |
| 5330 | { |
| 5331 | if (length) |
| 5332 | { |
| 5333 | *length = 0; |
| 5334 | } |
| 5335 | |
| 5336 | if (target != GL_RENDERBUFFER) |
| 5337 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5338 | context->validationError(GL_INVALID_ENUM, kInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5339 | return false; |
| 5340 | } |
| 5341 | |
| 5342 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5343 | if (renderbuffer == nullptr) |
| 5344 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5345 | context->validationError(GL_INVALID_OPERATION, kRenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5346 | return false; |
| 5347 | } |
| 5348 | |
| 5349 | switch (pname) |
| 5350 | { |
| 5351 | case GL_RENDERBUFFER_WIDTH: |
| 5352 | case GL_RENDERBUFFER_HEIGHT: |
| 5353 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5354 | case GL_RENDERBUFFER_RED_SIZE: |
| 5355 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5356 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5357 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5358 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5359 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5360 | break; |
| 5361 | |
| 5362 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5363 | if (!context->getExtensions().framebufferMultisample) |
| 5364 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5365 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5366 | return false; |
| 5367 | } |
| 5368 | break; |
| 5369 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5370 | case GL_MEMORY_SIZE_ANGLE: |
| 5371 | if (!context->getExtensions().memorySize) |
| 5372 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5373 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5374 | return false; |
| 5375 | } |
| 5376 | break; |
| 5377 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5378 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5379 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5380 | return false; |
| 5381 | } |
| 5382 | |
| 5383 | if (length) |
| 5384 | { |
| 5385 | *length = 1; |
| 5386 | } |
| 5387 | return true; |
| 5388 | } |
| 5389 | |
| 5390 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5391 | { |
| 5392 | if (length) |
| 5393 | { |
| 5394 | *length = 0; |
| 5395 | } |
| 5396 | |
| 5397 | if (GetValidShader(context, shader) == nullptr) |
| 5398 | { |
| 5399 | return false; |
| 5400 | } |
| 5401 | |
| 5402 | switch (pname) |
| 5403 | { |
| 5404 | case GL_SHADER_TYPE: |
| 5405 | case GL_DELETE_STATUS: |
| 5406 | case GL_COMPILE_STATUS: |
| 5407 | case GL_INFO_LOG_LENGTH: |
| 5408 | case GL_SHADER_SOURCE_LENGTH: |
| 5409 | break; |
| 5410 | |
| 5411 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5412 | if (!context->getExtensions().translatedShaderSource) |
| 5413 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5414 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5415 | return false; |
| 5416 | } |
| 5417 | break; |
| 5418 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5419 | case GL_COMPLETION_STATUS_KHR: |
| 5420 | if (!context->getExtensions().parallelShaderCompile) |
| 5421 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5422 | context->validationError(GL_INVALID_OPERATION, kExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5423 | return false; |
| 5424 | } |
| 5425 | break; |
| 5426 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5427 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5428 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5429 | return false; |
| 5430 | } |
| 5431 | |
| 5432 | if (length) |
| 5433 | { |
| 5434 | *length = 1; |
| 5435 | } |
| 5436 | return true; |
| 5437 | } |
| 5438 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5439 | bool ValidateGetTexParameterBase(Context *context, |
| 5440 | TextureType target, |
| 5441 | GLenum pname, |
| 5442 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5443 | { |
| 5444 | if (length) |
| 5445 | { |
| 5446 | *length = 0; |
| 5447 | } |
| 5448 | |
| 5449 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5450 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5451 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5452 | return false; |
| 5453 | } |
| 5454 | |
| 5455 | if (context->getTargetTexture(target) == nullptr) |
| 5456 | { |
| 5457 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5458 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5459 | return false; |
| 5460 | } |
| 5461 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5462 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5463 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5464 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5465 | return false; |
| 5466 | } |
| 5467 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5468 | switch (pname) |
| 5469 | { |
| 5470 | case GL_TEXTURE_MAG_FILTER: |
| 5471 | case GL_TEXTURE_MIN_FILTER: |
| 5472 | case GL_TEXTURE_WRAP_S: |
| 5473 | case GL_TEXTURE_WRAP_T: |
| 5474 | break; |
| 5475 | |
| 5476 | case GL_TEXTURE_USAGE_ANGLE: |
| 5477 | if (!context->getExtensions().textureUsage) |
| 5478 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5479 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5480 | return false; |
| 5481 | } |
| 5482 | break; |
| 5483 | |
| 5484 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5485 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5486 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5487 | return false; |
| 5488 | } |
| 5489 | break; |
| 5490 | |
| 5491 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5492 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5493 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5494 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5495 | return false; |
| 5496 | } |
| 5497 | break; |
| 5498 | |
| 5499 | case GL_TEXTURE_WRAP_R: |
| 5500 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5501 | case GL_TEXTURE_SWIZZLE_R: |
| 5502 | case GL_TEXTURE_SWIZZLE_G: |
| 5503 | case GL_TEXTURE_SWIZZLE_B: |
| 5504 | case GL_TEXTURE_SWIZZLE_A: |
| 5505 | case GL_TEXTURE_BASE_LEVEL: |
| 5506 | case GL_TEXTURE_MAX_LEVEL: |
| 5507 | case GL_TEXTURE_MIN_LOD: |
| 5508 | case GL_TEXTURE_MAX_LOD: |
| 5509 | case GL_TEXTURE_COMPARE_MODE: |
| 5510 | case GL_TEXTURE_COMPARE_FUNC: |
| 5511 | if (context->getClientMajorVersion() < 3) |
| 5512 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5513 | context->validationError(GL_INVALID_ENUM, "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5514 | return false; |
| 5515 | } |
| 5516 | break; |
| 5517 | |
| 5518 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5519 | if (!context->getExtensions().textureSRGBDecode) |
| 5520 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5521 | context->validationError(GL_INVALID_ENUM, |
| 5522 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5523 | return false; |
| 5524 | } |
| 5525 | break; |
| 5526 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5527 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5528 | if (context->getClientVersion() < Version(3, 1)) |
| 5529 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5530 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5531 | return false; |
| 5532 | } |
| 5533 | break; |
| 5534 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5535 | case GL_GENERATE_MIPMAP: |
| 5536 | case GL_TEXTURE_CROP_RECT_OES: |
| 5537 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5538 | // after GL_OES_draw_texture functionality implemented |
| 5539 | if (context->getClientMajorVersion() > 1) |
| 5540 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5541 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5542 | return false; |
| 5543 | } |
| 5544 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5545 | |
| 5546 | case GL_MEMORY_SIZE_ANGLE: |
| 5547 | if (!context->getExtensions().memorySize) |
| 5548 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5549 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5550 | return false; |
| 5551 | } |
| 5552 | break; |
| 5553 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5554 | case GL_TEXTURE_BORDER_COLOR: |
| 5555 | if (!context->getExtensions().textureBorderClamp) |
| 5556 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5557 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5558 | return false; |
| 5559 | } |
| 5560 | break; |
| 5561 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5562 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5563 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5564 | return false; |
| 5565 | } |
| 5566 | |
| 5567 | if (length) |
| 5568 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5569 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5570 | } |
| 5571 | return true; |
| 5572 | } |
| 5573 | |
| 5574 | bool ValidateGetVertexAttribBase(Context *context, |
| 5575 | GLuint index, |
| 5576 | GLenum pname, |
| 5577 | GLsizei *length, |
| 5578 | bool pointer, |
| 5579 | bool pureIntegerEntryPoint) |
| 5580 | { |
| 5581 | if (length) |
| 5582 | { |
| 5583 | *length = 0; |
| 5584 | } |
| 5585 | |
| 5586 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5587 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5588 | 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] | 5589 | return false; |
| 5590 | } |
| 5591 | |
| 5592 | if (index >= context->getCaps().maxVertexAttributes) |
| 5593 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5594 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5595 | return false; |
| 5596 | } |
| 5597 | |
| 5598 | if (pointer) |
| 5599 | { |
| 5600 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5601 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5602 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5603 | return false; |
| 5604 | } |
| 5605 | } |
| 5606 | else |
| 5607 | { |
| 5608 | switch (pname) |
| 5609 | { |
| 5610 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5611 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5612 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5613 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5614 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5615 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5616 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5617 | break; |
| 5618 | |
| 5619 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5620 | static_assert( |
| 5621 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5622 | "ANGLE extension enums not equal to GL enums."); |
| 5623 | if (context->getClientMajorVersion() < 3 && |
| 5624 | !context->getExtensions().instancedArrays) |
| 5625 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5626 | context->validationError(GL_INVALID_ENUM, |
| 5627 | "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5628 | "requires OpenGL ES 3.0 or " |
| 5629 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5630 | return false; |
| 5631 | } |
| 5632 | break; |
| 5633 | |
| 5634 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5635 | if (context->getClientMajorVersion() < 3) |
| 5636 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5637 | context->validationError( |
| 5638 | 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] | 5639 | return false; |
| 5640 | } |
| 5641 | break; |
| 5642 | |
| 5643 | case GL_VERTEX_ATTRIB_BINDING: |
| 5644 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5645 | if (context->getClientVersion() < ES_3_1) |
| 5646 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5647 | context->validationError(GL_INVALID_ENUM, |
| 5648 | "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5649 | return false; |
| 5650 | } |
| 5651 | break; |
| 5652 | |
| 5653 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5654 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5655 | return false; |
| 5656 | } |
| 5657 | } |
| 5658 | |
| 5659 | if (length) |
| 5660 | { |
| 5661 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5662 | { |
| 5663 | *length = 4; |
| 5664 | } |
| 5665 | else |
| 5666 | { |
| 5667 | *length = 1; |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | return true; |
| 5672 | } |
| 5673 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5674 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5675 | GLint x, |
| 5676 | GLint y, |
| 5677 | GLsizei width, |
| 5678 | GLsizei height, |
| 5679 | GLenum format, |
| 5680 | GLenum type, |
| 5681 | GLsizei bufSize, |
| 5682 | GLsizei *length, |
| 5683 | GLsizei *columns, |
| 5684 | GLsizei *rows, |
| 5685 | void *pixels) |
| 5686 | { |
| 5687 | if (length != nullptr) |
| 5688 | { |
| 5689 | *length = 0; |
| 5690 | } |
| 5691 | if (rows != nullptr) |
| 5692 | { |
| 5693 | *rows = 0; |
| 5694 | } |
| 5695 | if (columns != nullptr) |
| 5696 | { |
| 5697 | *columns = 0; |
| 5698 | } |
| 5699 | |
| 5700 | if (width < 0 || height < 0) |
| 5701 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5702 | context->validationError(GL_INVALID_VALUE, kNegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5703 | return false; |
| 5704 | } |
| 5705 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5706 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5707 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5708 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5709 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5710 | return false; |
| 5711 | } |
| 5712 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5713 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5714 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5715 | return false; |
| 5716 | } |
| 5717 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5718 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5719 | ASSERT(framebuffer); |
| 5720 | |
| 5721 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5722 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5723 | context->validationError(GL_INVALID_OPERATION, kReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5724 | return false; |
| 5725 | } |
| 5726 | |
| 5727 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5728 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5729 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5730 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5731 | // situation is an application error that would lead to a crash in ANGLE. |
| 5732 | if (readBuffer == nullptr) |
| 5733 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5734 | context->validationError(GL_INVALID_OPERATION, kMissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5735 | return false; |
| 5736 | } |
| 5737 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5738 | // ANGLE_multiview, Revision 1: |
| 5739 | // 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] | 5740 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5741 | // in the current read framebuffer is more than one. |
| 5742 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5743 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5744 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, |
| 5745 | "Attempting to read from a multi-view framebuffer."); |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5746 | return false; |
| 5747 | } |
| 5748 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5749 | if (context->getExtensions().webglCompatibility) |
| 5750 | { |
| 5751 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5752 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5753 | // and type before validating the combination of format and type. However, the |
| 5754 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5755 | // verifies that GL_INVALID_OPERATION is generated. |
| 5756 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5757 | // dEQP/WebGL. |
| 5758 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5759 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5760 | context->validationError(GL_INVALID_ENUM, kInvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5761 | return false; |
| 5762 | } |
| 5763 | |
| 5764 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5765 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5766 | context->validationError(GL_INVALID_ENUM, kInvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5767 | return false; |
| 5768 | } |
| 5769 | } |
| 5770 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5771 | GLenum currentFormat = GL_NONE; |
| 5772 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5773 | |
| 5774 | GLenum currentType = GL_NONE; |
| 5775 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5776 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5777 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5778 | |
| 5779 | bool validFormatTypeCombination = |
| 5780 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5781 | |
| 5782 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5783 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5784 | context->validationError(GL_INVALID_OPERATION, kMismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5785 | return false; |
| 5786 | } |
| 5787 | |
| 5788 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5789 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5790 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5791 | { |
| 5792 | // ...the buffer object's data store is currently mapped. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5793 | context->validationError(GL_INVALID_OPERATION, "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5794 | return false; |
| 5795 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5796 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5797 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5798 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5799 | context->validationError(GL_INVALID_OPERATION, kPixelPackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5800 | return false; |
| 5801 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5802 | |
| 5803 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5804 | // would exceed the data store size. |
| 5805 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5806 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5807 | const auto &pack = context->getGLState().getPackState(); |
| 5808 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5809 | GLuint endByte = 0; |
| 5810 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5811 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5812 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5813 | return false; |
| 5814 | } |
| 5815 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5816 | if (bufSize >= 0) |
| 5817 | { |
| 5818 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5819 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5820 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5821 | return false; |
| 5822 | } |
| 5823 | } |
| 5824 | |
| 5825 | if (pixelPackBuffer != nullptr) |
| 5826 | { |
| 5827 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5828 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5829 | checkedEndByte += checkedOffset; |
| 5830 | |
| 5831 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5832 | { |
| 5833 | // Overflow past the end of the buffer |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5834 | context->validationError(GL_INVALID_OPERATION, kParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5835 | return false; |
| 5836 | } |
| 5837 | } |
| 5838 | |
| 5839 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5840 | { |
| 5841 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5842 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5843 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5844 | return false; |
| 5845 | } |
| 5846 | |
| 5847 | *length = static_cast<GLsizei>(endByte); |
| 5848 | } |
| 5849 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5850 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5851 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5852 | if (start < 0) |
| 5853 | { |
| 5854 | // "subtract" the area that is less than 0 |
| 5855 | clippedExtent += start; |
| 5856 | } |
| 5857 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5858 | angle::CheckedNumeric<int> readExtent = start; |
| 5859 | readExtent += length; |
| 5860 | if (!readExtent.IsValid()) |
| 5861 | { |
| 5862 | return false; |
| 5863 | } |
| 5864 | |
| 5865 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5866 | { |
| 5867 | // Subtract the region to the right of the read buffer |
| 5868 | clippedExtent -= (readExtent - bufferSize); |
| 5869 | } |
| 5870 | |
| 5871 | if (!clippedExtent.IsValid()) |
| 5872 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5873 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5874 | } |
| 5875 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5876 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5877 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5878 | }; |
| 5879 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5880 | GLsizei writtenColumns = 0; |
| 5881 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5882 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5883 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5884 | return false; |
| 5885 | } |
| 5886 | |
| 5887 | GLsizei writtenRows = 0; |
| 5888 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5889 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5890 | context->validationError(GL_INVALID_OPERATION, kIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5891 | return false; |
| 5892 | } |
| 5893 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5894 | if (columns != nullptr) |
| 5895 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5896 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | if (rows != nullptr) |
| 5900 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5901 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5902 | } |
| 5903 | |
| 5904 | return true; |
| 5905 | } |
| 5906 | |
| 5907 | template <typename ParamType> |
| 5908 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5909 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5910 | GLenum pname, |
| 5911 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5912 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5913 | const ParamType *params) |
| 5914 | { |
| 5915 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5916 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5917 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5918 | return false; |
| 5919 | } |
| 5920 | |
| 5921 | if (context->getTargetTexture(target) == nullptr) |
| 5922 | { |
| 5923 | // Should only be possible for external textures |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5924 | context->validationError(GL_INVALID_ENUM, kTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5925 | return false; |
| 5926 | } |
| 5927 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5928 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5929 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5930 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5931 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5932 | return false; |
| 5933 | } |
| 5934 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5935 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5936 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5937 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5938 | return false; |
| 5939 | } |
| 5940 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5941 | switch (pname) |
| 5942 | { |
| 5943 | case GL_TEXTURE_WRAP_R: |
| 5944 | case GL_TEXTURE_SWIZZLE_R: |
| 5945 | case GL_TEXTURE_SWIZZLE_G: |
| 5946 | case GL_TEXTURE_SWIZZLE_B: |
| 5947 | case GL_TEXTURE_SWIZZLE_A: |
| 5948 | case GL_TEXTURE_BASE_LEVEL: |
| 5949 | case GL_TEXTURE_MAX_LEVEL: |
| 5950 | case GL_TEXTURE_COMPARE_MODE: |
| 5951 | case GL_TEXTURE_COMPARE_FUNC: |
| 5952 | case GL_TEXTURE_MIN_LOD: |
| 5953 | case GL_TEXTURE_MAX_LOD: |
| 5954 | if (context->getClientMajorVersion() < 3) |
| 5955 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5956 | context->validationError(GL_INVALID_ENUM, kES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5957 | return false; |
| 5958 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5959 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5960 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5961 | context->validationError(GL_INVALID_ENUM, |
| 5962 | "ES3 texture parameters are not " |
| 5963 | "available without " |
| 5964 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5965 | return false; |
| 5966 | } |
| 5967 | break; |
| 5968 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5969 | case GL_GENERATE_MIPMAP: |
| 5970 | case GL_TEXTURE_CROP_RECT_OES: |
| 5971 | if (context->getClientMajorVersion() > 1) |
| 5972 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 5973 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5974 | return false; |
| 5975 | } |
| 5976 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5977 | default: |
| 5978 | break; |
| 5979 | } |
| 5980 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5981 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5982 | { |
| 5983 | switch (pname) |
| 5984 | { |
| 5985 | case GL_TEXTURE_MIN_FILTER: |
| 5986 | case GL_TEXTURE_MAG_FILTER: |
| 5987 | case GL_TEXTURE_WRAP_S: |
| 5988 | case GL_TEXTURE_WRAP_T: |
| 5989 | case GL_TEXTURE_WRAP_R: |
| 5990 | case GL_TEXTURE_MIN_LOD: |
| 5991 | case GL_TEXTURE_MAX_LOD: |
| 5992 | case GL_TEXTURE_COMPARE_MODE: |
| 5993 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5994 | case GL_TEXTURE_BORDER_COLOR: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5995 | context->validationError(GL_INVALID_ENUM, |
| 5996 | "Invalid parameter for 2D multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5997 | return false; |
| 5998 | } |
| 5999 | } |
| 6000 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6001 | switch (pname) |
| 6002 | { |
| 6003 | case GL_TEXTURE_WRAP_S: |
| 6004 | case GL_TEXTURE_WRAP_T: |
| 6005 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6006 | { |
| 6007 | bool restrictedWrapModes = |
| 6008 | target == TextureType::External || target == TextureType::Rectangle; |
| 6009 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6010 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6011 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6012 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6013 | } |
| 6014 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6015 | |
| 6016 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6017 | { |
| 6018 | bool restrictedMinFilter = |
| 6019 | target == TextureType::External || target == TextureType::Rectangle; |
| 6020 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6021 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6022 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6023 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6024 | } |
| 6025 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6026 | |
| 6027 | case GL_TEXTURE_MAG_FILTER: |
| 6028 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6029 | { |
| 6030 | return false; |
| 6031 | } |
| 6032 | break; |
| 6033 | |
| 6034 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6035 | if (!context->getExtensions().textureUsage) |
| 6036 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6037 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6038 | return false; |
| 6039 | } |
| 6040 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6041 | switch (ConvertToGLenum(params[0])) |
| 6042 | { |
| 6043 | case GL_NONE: |
| 6044 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6045 | break; |
| 6046 | |
| 6047 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6048 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | return false; |
| 6050 | } |
| 6051 | break; |
| 6052 | |
| 6053 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6054 | { |
| 6055 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6056 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6057 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6058 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6059 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6060 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6061 | } |
| 6062 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6063 | |
| 6064 | case GL_TEXTURE_MIN_LOD: |
| 6065 | case GL_TEXTURE_MAX_LOD: |
| 6066 | // any value is permissible |
| 6067 | break; |
| 6068 | |
| 6069 | case GL_TEXTURE_COMPARE_MODE: |
| 6070 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6071 | { |
| 6072 | return false; |
| 6073 | } |
| 6074 | break; |
| 6075 | |
| 6076 | case GL_TEXTURE_COMPARE_FUNC: |
| 6077 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6078 | { |
| 6079 | return false; |
| 6080 | } |
| 6081 | break; |
| 6082 | |
| 6083 | case GL_TEXTURE_SWIZZLE_R: |
| 6084 | case GL_TEXTURE_SWIZZLE_G: |
| 6085 | case GL_TEXTURE_SWIZZLE_B: |
| 6086 | case GL_TEXTURE_SWIZZLE_A: |
| 6087 | switch (ConvertToGLenum(params[0])) |
| 6088 | { |
| 6089 | case GL_RED: |
| 6090 | case GL_GREEN: |
| 6091 | case GL_BLUE: |
| 6092 | case GL_ALPHA: |
| 6093 | case GL_ZERO: |
| 6094 | case GL_ONE: |
| 6095 | break; |
| 6096 | |
| 6097 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6098 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6099 | return false; |
| 6100 | } |
| 6101 | break; |
| 6102 | |
| 6103 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6104 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6105 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6106 | context->validationError(GL_INVALID_VALUE, "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6107 | return false; |
| 6108 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6109 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6110 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6111 | context->validationError(GL_INVALID_OPERATION, |
| 6112 | "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6113 | return false; |
| 6114 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6115 | if ((target == TextureType::_2DMultisample || |
| 6116 | target == TextureType::_2DMultisampleArray) && |
| 6117 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6118 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6119 | context->validationError(GL_INVALID_OPERATION, |
| 6120 | "Base level must be 0 for multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6121 | return false; |
| 6122 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6123 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6124 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6125 | context->validationError(GL_INVALID_OPERATION, |
| 6126 | "Base level must be 0 for rectangle textures."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6127 | return false; |
| 6128 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6129 | break; |
| 6130 | |
| 6131 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6132 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6133 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6134 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6135 | return false; |
| 6136 | } |
| 6137 | break; |
| 6138 | |
| 6139 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6140 | if (context->getClientVersion() < Version(3, 1)) |
| 6141 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6142 | context->validationError(GL_INVALID_ENUM, kEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6143 | return false; |
| 6144 | } |
| 6145 | switch (ConvertToGLenum(params[0])) |
| 6146 | { |
| 6147 | case GL_DEPTH_COMPONENT: |
| 6148 | case GL_STENCIL_INDEX: |
| 6149 | break; |
| 6150 | |
| 6151 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6152 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6153 | return false; |
| 6154 | } |
| 6155 | break; |
| 6156 | |
| 6157 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6158 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6159 | { |
| 6160 | return false; |
| 6161 | } |
| 6162 | break; |
| 6163 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6164 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6165 | if (context->getClientMajorVersion() > 1) |
| 6166 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6167 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6168 | return false; |
| 6169 | } |
| 6170 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6171 | |
| 6172 | case GL_TEXTURE_CROP_RECT_OES: |
| 6173 | if (context->getClientMajorVersion() > 1) |
| 6174 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6175 | context->validationError(GL_INVALID_ENUM, kGLES1Only); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6176 | return false; |
| 6177 | } |
| 6178 | if (!vectorParams) |
| 6179 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6180 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6181 | return false; |
| 6182 | } |
| 6183 | break; |
| 6184 | |
| 6185 | case GL_TEXTURE_BORDER_COLOR: |
| 6186 | if (!context->getExtensions().textureBorderClamp) |
| 6187 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6188 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6189 | return false; |
| 6190 | } |
| 6191 | if (!vectorParams) |
| 6192 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6193 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6194 | return false; |
| 6195 | } |
| 6196 | break; |
| 6197 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6198 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6199 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6200 | return false; |
| 6201 | } |
| 6202 | |
| 6203 | return true; |
| 6204 | } |
| 6205 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6206 | template bool ValidateTexParameterBase(Context *, |
| 6207 | TextureType, |
| 6208 | GLenum, |
| 6209 | GLsizei, |
| 6210 | bool, |
| 6211 | const GLfloat *); |
| 6212 | template bool ValidateTexParameterBase(Context *, |
| 6213 | TextureType, |
| 6214 | GLenum, |
| 6215 | GLsizei, |
| 6216 | bool, |
| 6217 | const GLint *); |
| 6218 | template bool ValidateTexParameterBase(Context *, |
| 6219 | TextureType, |
| 6220 | GLenum, |
| 6221 | GLsizei, |
| 6222 | bool, |
| 6223 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6224 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6225 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6226 | { |
| 6227 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6228 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6229 | context->validationError(GL_INVALID_VALUE, kIndexExceedsMaxVertexAttribute); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6230 | return false; |
| 6231 | } |
| 6232 | |
| 6233 | return true; |
| 6234 | } |
| 6235 | |
| 6236 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6237 | GLuint program, |
| 6238 | GLuint uniformBlockIndex, |
| 6239 | GLenum pname, |
| 6240 | GLsizei *length) |
| 6241 | { |
| 6242 | if (length) |
| 6243 | { |
| 6244 | *length = 0; |
| 6245 | } |
| 6246 | |
| 6247 | if (context->getClientMajorVersion() < 3) |
| 6248 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6249 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6250 | return false; |
| 6251 | } |
| 6252 | |
| 6253 | Program *programObject = GetValidProgram(context, program); |
| 6254 | if (!programObject) |
| 6255 | { |
| 6256 | return false; |
| 6257 | } |
| 6258 | |
| 6259 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6260 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6261 | context->validationError(GL_INVALID_VALUE, |
| 6262 | "uniformBlockIndex exceeds active uniform block count."); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6263 | return false; |
| 6264 | } |
| 6265 | |
| 6266 | switch (pname) |
| 6267 | { |
| 6268 | case GL_UNIFORM_BLOCK_BINDING: |
| 6269 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6270 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6271 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6272 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6273 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6274 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6275 | break; |
| 6276 | |
| 6277 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6278 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6279 | return false; |
| 6280 | } |
| 6281 | |
| 6282 | if (length) |
| 6283 | { |
| 6284 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6285 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6286 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6287 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6288 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6289 | } |
| 6290 | else |
| 6291 | { |
| 6292 | *length = 1; |
| 6293 | } |
| 6294 | } |
| 6295 | |
| 6296 | return true; |
| 6297 | } |
| 6298 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6299 | template <typename ParamType> |
| 6300 | bool ValidateSamplerParameterBase(Context *context, |
| 6301 | GLuint sampler, |
| 6302 | GLenum pname, |
| 6303 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6304 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6305 | ParamType *params) |
| 6306 | { |
| 6307 | if (context->getClientMajorVersion() < 3) |
| 6308 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6309 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6310 | return false; |
| 6311 | } |
| 6312 | |
| 6313 | if (!context->isSampler(sampler)) |
| 6314 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6315 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6316 | return false; |
| 6317 | } |
| 6318 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6319 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6320 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6321 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6322 | context->validationError(GL_INVALID_OPERATION, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6323 | return false; |
| 6324 | } |
| 6325 | |
| 6326 | switch (pname) |
| 6327 | { |
| 6328 | case GL_TEXTURE_WRAP_S: |
| 6329 | case GL_TEXTURE_WRAP_T: |
| 6330 | case GL_TEXTURE_WRAP_R: |
| 6331 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6332 | { |
| 6333 | return false; |
| 6334 | } |
| 6335 | break; |
| 6336 | |
| 6337 | case GL_TEXTURE_MIN_FILTER: |
| 6338 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6339 | { |
| 6340 | return false; |
| 6341 | } |
| 6342 | break; |
| 6343 | |
| 6344 | case GL_TEXTURE_MAG_FILTER: |
| 6345 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6346 | { |
| 6347 | return false; |
| 6348 | } |
| 6349 | break; |
| 6350 | |
| 6351 | case GL_TEXTURE_MIN_LOD: |
| 6352 | case GL_TEXTURE_MAX_LOD: |
| 6353 | // any value is permissible |
| 6354 | break; |
| 6355 | |
| 6356 | case GL_TEXTURE_COMPARE_MODE: |
| 6357 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6358 | { |
| 6359 | return false; |
| 6360 | } |
| 6361 | break; |
| 6362 | |
| 6363 | case GL_TEXTURE_COMPARE_FUNC: |
| 6364 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6365 | { |
| 6366 | return false; |
| 6367 | } |
| 6368 | break; |
| 6369 | |
| 6370 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6371 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6372 | { |
| 6373 | return false; |
| 6374 | } |
| 6375 | break; |
| 6376 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6377 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6378 | { |
| 6379 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6380 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6381 | { |
| 6382 | return false; |
| 6383 | } |
| 6384 | } |
| 6385 | break; |
| 6386 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6387 | case GL_TEXTURE_BORDER_COLOR: |
| 6388 | if (!context->getExtensions().textureBorderClamp) |
| 6389 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6390 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6391 | return false; |
| 6392 | } |
| 6393 | if (!vectorParams) |
| 6394 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6395 | context->validationError(GL_INVALID_ENUM, kInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6396 | return false; |
| 6397 | } |
| 6398 | break; |
| 6399 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6400 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6401 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6402 | return false; |
| 6403 | } |
| 6404 | |
| 6405 | return true; |
| 6406 | } |
| 6407 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6408 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6409 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6410 | template bool ValidateSamplerParameterBase(Context *, |
| 6411 | GLuint, |
| 6412 | GLenum, |
| 6413 | GLsizei, |
| 6414 | bool, |
| 6415 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6416 | |
| 6417 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6418 | GLuint sampler, |
| 6419 | GLenum pname, |
| 6420 | GLsizei *length) |
| 6421 | { |
| 6422 | if (length) |
| 6423 | { |
| 6424 | *length = 0; |
| 6425 | } |
| 6426 | |
| 6427 | if (context->getClientMajorVersion() < 3) |
| 6428 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6429 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6430 | return false; |
| 6431 | } |
| 6432 | |
| 6433 | if (!context->isSampler(sampler)) |
| 6434 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6435 | context->validationError(GL_INVALID_OPERATION, kInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6436 | return false; |
| 6437 | } |
| 6438 | |
| 6439 | switch (pname) |
| 6440 | { |
| 6441 | case GL_TEXTURE_WRAP_S: |
| 6442 | case GL_TEXTURE_WRAP_T: |
| 6443 | case GL_TEXTURE_WRAP_R: |
| 6444 | case GL_TEXTURE_MIN_FILTER: |
| 6445 | case GL_TEXTURE_MAG_FILTER: |
| 6446 | case GL_TEXTURE_MIN_LOD: |
| 6447 | case GL_TEXTURE_MAX_LOD: |
| 6448 | case GL_TEXTURE_COMPARE_MODE: |
| 6449 | case GL_TEXTURE_COMPARE_FUNC: |
| 6450 | break; |
| 6451 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6452 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6453 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6454 | { |
| 6455 | return false; |
| 6456 | } |
| 6457 | break; |
| 6458 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6459 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6460 | if (!context->getExtensions().textureSRGBDecode) |
| 6461 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6462 | context->validationError(GL_INVALID_ENUM, |
| 6463 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6464 | return false; |
| 6465 | } |
| 6466 | break; |
| 6467 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6468 | case GL_TEXTURE_BORDER_COLOR: |
| 6469 | if (!context->getExtensions().textureBorderClamp) |
| 6470 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6471 | context->validationError(GL_INVALID_ENUM, kExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6472 | return false; |
| 6473 | } |
| 6474 | break; |
| 6475 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6476 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6477 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6478 | return false; |
| 6479 | } |
| 6480 | |
| 6481 | if (length) |
| 6482 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6483 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6484 | } |
| 6485 | return true; |
| 6486 | } |
| 6487 | |
| 6488 | bool ValidateGetInternalFormativBase(Context *context, |
| 6489 | GLenum target, |
| 6490 | GLenum internalformat, |
| 6491 | GLenum pname, |
| 6492 | GLsizei bufSize, |
| 6493 | GLsizei *numParams) |
| 6494 | { |
| 6495 | if (numParams) |
| 6496 | { |
| 6497 | *numParams = 0; |
| 6498 | } |
| 6499 | |
| 6500 | if (context->getClientMajorVersion() < 3) |
| 6501 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6502 | context->validationError(GL_INVALID_OPERATION, kES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6503 | return false; |
| 6504 | } |
| 6505 | |
| 6506 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6507 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6508 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6509 | context->validationError(GL_INVALID_ENUM, "Internal format is not renderable."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6510 | return false; |
| 6511 | } |
| 6512 | |
| 6513 | switch (target) |
| 6514 | { |
| 6515 | case GL_RENDERBUFFER: |
| 6516 | break; |
| 6517 | |
| 6518 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6519 | if (context->getClientVersion() < ES_3_1 && |
| 6520 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6521 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6522 | context->validationError(GL_INVALID_ENUM, |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6523 | kMultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6524 | return false; |
| 6525 | } |
| 6526 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6527 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6528 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6529 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6530 | context->validationError(GL_INVALID_ENUM, kMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6531 | return false; |
| 6532 | } |
| 6533 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6534 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6535 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6536 | return false; |
| 6537 | } |
| 6538 | |
| 6539 | if (bufSize < 0) |
| 6540 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6541 | context->validationError(GL_INVALID_VALUE, kInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6542 | return false; |
| 6543 | } |
| 6544 | |
| 6545 | GLsizei maxWriteParams = 0; |
| 6546 | switch (pname) |
| 6547 | { |
| 6548 | case GL_NUM_SAMPLE_COUNTS: |
| 6549 | maxWriteParams = 1; |
| 6550 | break; |
| 6551 | |
| 6552 | case GL_SAMPLES: |
| 6553 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6554 | break; |
| 6555 | |
| 6556 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6557 | context->validationError(GL_INVALID_ENUM, kEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6558 | return false; |
| 6559 | } |
| 6560 | |
| 6561 | if (numParams) |
| 6562 | { |
| 6563 | // glGetInternalFormativ will not overflow bufSize |
| 6564 | *numParams = std::min(bufSize, maxWriteParams); |
| 6565 | } |
| 6566 | |
| 6567 | return true; |
| 6568 | } |
| 6569 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6570 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6571 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6572 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6573 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6574 | context->validationError(GL_INVALID_OPERATION, kInvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6575 | return false; |
| 6576 | } |
| 6577 | return true; |
| 6578 | } |
| 6579 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6580 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6581 | { |
| 6582 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6583 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6584 | context->validationError(GL_INVALID_ENUM, kInvalidMultitextureUnit); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6585 | return false; |
| 6586 | } |
| 6587 | return true; |
| 6588 | } |
| 6589 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6590 | bool ValidateTexStorageMultisample(Context *context, |
| 6591 | TextureType target, |
| 6592 | GLsizei samples, |
| 6593 | GLint internalFormat, |
| 6594 | GLsizei width, |
| 6595 | GLsizei height) |
| 6596 | { |
| 6597 | const Caps &caps = context->getCaps(); |
| 6598 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6599 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6600 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6601 | context->validationError(GL_INVALID_VALUE, kTextureWidthOrHeightOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6602 | return false; |
| 6603 | } |
| 6604 | |
| 6605 | if (samples == 0) |
| 6606 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6607 | context->validationError(GL_INVALID_VALUE, kSamplesZero); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6608 | return false; |
| 6609 | } |
| 6610 | |
| 6611 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6612 | if (!formatCaps.textureAttachment) |
| 6613 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6614 | context->validationError(GL_INVALID_ENUM, kRenderableInternalFormat); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6615 | return false; |
| 6616 | } |
| 6617 | |
| 6618 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6619 | // is one of the unsized base internalformats listed in table 8.11. |
| 6620 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6621 | if (formatInfo.internalFormat == GL_NONE) |
| 6622 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6623 | context->validationError(GL_INVALID_ENUM, kUnsizedInternalFormatUnsupported); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6624 | return false; |
| 6625 | } |
| 6626 | |
| 6627 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6628 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6629 | context->validationError(GL_INVALID_OPERATION, kSamplesOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6630 | return false; |
| 6631 | } |
| 6632 | |
| 6633 | Texture *texture = context->getTargetTexture(target); |
| 6634 | if (!texture || texture->id() == 0) |
| 6635 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6636 | context->validationError(GL_INVALID_OPERATION, kZeroBoundToTarget); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6637 | return false; |
| 6638 | } |
| 6639 | |
| 6640 | if (texture->getImmutableFormat()) |
| 6641 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6642 | context->validationError(GL_INVALID_OPERATION, kImmutableTextureBound); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6643 | return false; |
| 6644 | } |
| 6645 | return true; |
| 6646 | } |
| 6647 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6648 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6649 | TextureType target, |
| 6650 | GLsizei samples, |
| 6651 | GLint internalFormat, |
| 6652 | GLsizei width, |
| 6653 | GLsizei height) |
| 6654 | { |
| 6655 | if (target != TextureType::_2DMultisample) |
| 6656 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6657 | context->validationError(GL_INVALID_ENUM, kInvalidTarget); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6658 | return false; |
| 6659 | } |
| 6660 | |
| 6661 | if (width < 1 || height < 1) |
| 6662 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6663 | context->validationError(GL_INVALID_VALUE, kTextureSizeTooSmall); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6664 | return false; |
| 6665 | } |
| 6666 | |
| 6667 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6668 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6669 | |
| 6670 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6671 | TextureTarget target, |
| 6672 | GLint level, |
| 6673 | GLenum pname, |
| 6674 | GLsizei *length) |
| 6675 | { |
| 6676 | |
| 6677 | if (length) |
| 6678 | { |
| 6679 | *length = 0; |
| 6680 | } |
| 6681 | |
| 6682 | TextureType type = TextureTargetToType(target); |
| 6683 | |
| 6684 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6685 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6686 | context->validationError(GL_INVALID_ENUM, kInvalidTextureTarget); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6687 | return false; |
| 6688 | } |
| 6689 | |
| 6690 | if (context->getTargetTexture(type) == nullptr) |
| 6691 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6692 | context->validationError(GL_INVALID_ENUM, "No texture bound."); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6693 | return false; |
| 6694 | } |
| 6695 | |
| 6696 | if (!ValidMipLevel(context, type, level)) |
| 6697 | { |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6698 | context->validationError(GL_INVALID_VALUE, kInvalidMipLevel); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6699 | return false; |
| 6700 | } |
| 6701 | |
| 6702 | switch (pname) |
| 6703 | { |
| 6704 | case GL_TEXTURE_RED_TYPE: |
| 6705 | case GL_TEXTURE_GREEN_TYPE: |
| 6706 | case GL_TEXTURE_BLUE_TYPE: |
| 6707 | case GL_TEXTURE_ALPHA_TYPE: |
| 6708 | case GL_TEXTURE_DEPTH_TYPE: |
| 6709 | break; |
| 6710 | case GL_TEXTURE_RED_SIZE: |
| 6711 | case GL_TEXTURE_GREEN_SIZE: |
| 6712 | case GL_TEXTURE_BLUE_SIZE: |
| 6713 | case GL_TEXTURE_ALPHA_SIZE: |
| 6714 | case GL_TEXTURE_DEPTH_SIZE: |
| 6715 | case GL_TEXTURE_STENCIL_SIZE: |
| 6716 | case GL_TEXTURE_SHARED_SIZE: |
| 6717 | break; |
| 6718 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6719 | case GL_TEXTURE_WIDTH: |
| 6720 | case GL_TEXTURE_HEIGHT: |
| 6721 | case GL_TEXTURE_DEPTH: |
| 6722 | break; |
| 6723 | case GL_TEXTURE_SAMPLES: |
| 6724 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6725 | break; |
| 6726 | case GL_TEXTURE_COMPRESSED: |
| 6727 | break; |
| 6728 | default: |
Jamie Madill | e0472f3 | 2018-11-27 16:32:45 -0500 | [diff] [blame] | 6729 | context->validationError(GL_INVALID_ENUM, kInvalidPname); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6730 | return false; |
| 6731 | } |
| 6732 | |
| 6733 | if (length) |
| 6734 | { |
| 6735 | *length = 1; |
| 6736 | } |
| 6737 | return true; |
| 6738 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6739 | } // namespace gl |