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 | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 36 | namespace |
| 37 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 38 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 39 | { |
| 40 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 41 | // the compressed block size. |
| 42 | switch (internalFormat) |
| 43 | { |
| 44 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 48 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 52 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 53 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
Olli Etuaho | f2ed299 | 2018-10-04 13:54:42 +0300 | [diff] [blame] | 59 | case GL_COMPRESSED_RGBA_BPTC_UNORM_EXT: |
| 60 | case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT: |
| 61 | case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT: |
| 62 | case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT: |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 63 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 64 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 65 | default: |
| 66 | return false; |
| 67 | } |
| 68 | } |
| 69 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 70 | { |
| 71 | // Compressed sub textures have additional formats that requires exact size. |
| 72 | // ES 3.1, Section 8.7, Page 171 |
| 73 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 74 | IsETC2EACFormat(internalFormat); |
| 75 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 76 | |
| 77 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 78 | { |
| 79 | CheckedNumeric<GLint> checkedA(a); |
| 80 | checkedA -= b; |
| 81 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 82 | checkedA = -checkedA; |
| 83 | return !checkedA.IsValid(); |
| 84 | } |
| 85 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 86 | bool ValidateDrawAttribsImpl(Context *context, GLint primcount, GLint maxVertex) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 87 | { |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 88 | // If we're drawing zero vertices, we have enough data. |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 89 | ASSERT(primcount > 0); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 90 | |
Jamie Madill | 88602e6 | 2018-08-08 12:49:30 -0400 | [diff] [blame] | 91 | // An overflow can happen when adding the offset. Check against a special constant. |
| 92 | if (context->getStateCache().getNonInstancedVertexElementLimit() == |
| 93 | VertexAttribute::kIntegerOverflow || |
| 94 | context->getStateCache().getInstancedVertexElementLimit() == |
| 95 | VertexAttribute::kIntegerOverflow) |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 96 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 97 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 98 | return false; |
| 99 | } |
| 100 | |
| 101 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 102 | // We can return INVALID_OPERATION if our buffer does not have enough backing data. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 103 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientVertexBufferSize); |
Jamie Madill | a2d1d2d | 2018-08-01 11:34:46 -0400 | [diff] [blame] | 104 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 105 | } |
| 106 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 107 | ANGLE_INLINE bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex) |
| 108 | { |
| 109 | if (maxVertex <= context->getStateCache().getNonInstancedVertexElementLimit() && |
| 110 | (primcount - 1) <= context->getStateCache().getInstancedVertexElementLimit()) |
| 111 | { |
| 112 | return true; |
| 113 | } |
| 114 | else |
| 115 | { |
| 116 | return ValidateDrawAttribsImpl(context, primcount, maxVertex); |
| 117 | } |
| 118 | } |
| 119 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 120 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 121 | { |
| 122 | switch (type) |
| 123 | { |
| 124 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 125 | case GL_UNSIGNED_BYTE: |
| 126 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 127 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 128 | case GL_UNSIGNED_SHORT_5_6_5: |
| 129 | return context->getClientVersion() >= ES_2_0; |
| 130 | |
| 131 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 132 | case GL_BYTE: |
| 133 | case GL_INT: |
| 134 | case GL_SHORT: |
| 135 | case GL_UNSIGNED_INT: |
| 136 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 137 | case GL_UNSIGNED_INT_24_8: |
| 138 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 139 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 140 | case GL_UNSIGNED_SHORT: |
| 141 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 142 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 143 | return context->getClientVersion() >= ES_3_0; |
| 144 | |
| 145 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 146 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 147 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 148 | |
| 149 | case GL_HALF_FLOAT: |
| 150 | return context->getClientVersion() >= ES_3_0 || |
| 151 | context->getExtensions().textureHalfFloat; |
| 152 | |
| 153 | case GL_HALF_FLOAT_OES: |
| 154 | return context->getExtensions().colorBufferHalfFloat; |
| 155 | |
| 156 | default: |
| 157 | return false; |
| 158 | } |
| 159 | } |
| 160 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 161 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 162 | { |
| 163 | switch (format) |
| 164 | { |
| 165 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 166 | case GL_RGBA: |
| 167 | case GL_RGB: |
| 168 | case GL_ALPHA: |
| 169 | return context->getClientVersion() >= ES_2_0; |
| 170 | |
| 171 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 172 | case GL_RG: |
| 173 | case GL_RED: |
| 174 | case GL_RGBA_INTEGER: |
| 175 | case GL_RGB_INTEGER: |
| 176 | case GL_RG_INTEGER: |
| 177 | case GL_RED_INTEGER: |
| 178 | return context->getClientVersion() >= ES_3_0; |
| 179 | |
| 180 | case GL_SRGB_ALPHA_EXT: |
| 181 | case GL_SRGB_EXT: |
| 182 | return context->getExtensions().sRGB; |
| 183 | |
| 184 | case GL_BGRA_EXT: |
| 185 | return context->getExtensions().readFormatBGRA; |
| 186 | |
| 187 | default: |
| 188 | return false; |
| 189 | } |
| 190 | } |
| 191 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 192 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 193 | GLenum framebufferComponentType, |
| 194 | GLenum format, |
| 195 | GLenum type) |
| 196 | { |
| 197 | switch (framebufferComponentType) |
| 198 | { |
| 199 | case GL_UNSIGNED_NORMALIZED: |
| 200 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 201 | // ReadPixels with BGRA even if the extension is not present |
| 202 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 203 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 204 | type == GL_UNSIGNED_BYTE); |
| 205 | |
| 206 | case GL_SIGNED_NORMALIZED: |
| 207 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 208 | |
| 209 | case GL_INT: |
| 210 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 211 | |
| 212 | case GL_UNSIGNED_INT: |
| 213 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 214 | |
| 215 | case GL_FLOAT: |
| 216 | return (format == GL_RGBA && type == GL_FLOAT); |
| 217 | |
| 218 | default: |
| 219 | UNREACHABLE(); |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 224 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 225 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 226 | { |
| 227 | switch (ConvertToGLenum(params[0])) |
| 228 | { |
| 229 | case GL_CLAMP_TO_EDGE: |
| 230 | break; |
| 231 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 232 | case GL_CLAMP_TO_BORDER: |
| 233 | if (!context->getExtensions().textureBorderClamp) |
| 234 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 235 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 236 | return false; |
| 237 | } |
| 238 | break; |
| 239 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 240 | case GL_REPEAT: |
| 241 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 242 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 243 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 244 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 245 | context->validationError(GL_INVALID_ENUM, kErrorInvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 246 | return false; |
| 247 | } |
| 248 | break; |
| 249 | |
| 250 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 251 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 252 | return false; |
| 253 | } |
| 254 | |
| 255 | return true; |
| 256 | } |
| 257 | |
| 258 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 259 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 260 | { |
| 261 | switch (ConvertToGLenum(params[0])) |
| 262 | { |
| 263 | case GL_NEAREST: |
| 264 | case GL_LINEAR: |
| 265 | break; |
| 266 | |
| 267 | case GL_NEAREST_MIPMAP_NEAREST: |
| 268 | case GL_LINEAR_MIPMAP_NEAREST: |
| 269 | case GL_NEAREST_MIPMAP_LINEAR: |
| 270 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 271 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 272 | { |
| 273 | // OES_EGL_image_external specifies this error. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 274 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 275 | return false; |
| 276 | } |
| 277 | break; |
| 278 | |
| 279 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 280 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 281 | return false; |
| 282 | } |
| 283 | |
| 284 | return true; |
| 285 | } |
| 286 | |
| 287 | template <typename ParamType> |
| 288 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 289 | { |
| 290 | switch (ConvertToGLenum(params[0])) |
| 291 | { |
| 292 | case GL_NEAREST: |
| 293 | case GL_LINEAR: |
| 294 | break; |
| 295 | |
| 296 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 297 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 298 | return false; |
| 299 | } |
| 300 | |
| 301 | return true; |
| 302 | } |
| 303 | |
| 304 | template <typename ParamType> |
| 305 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 306 | { |
| 307 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 308 | switch (ConvertToGLenum(params[0])) |
| 309 | { |
| 310 | case GL_NONE: |
| 311 | case GL_COMPARE_REF_TO_TEXTURE: |
| 312 | break; |
| 313 | |
| 314 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 315 | context->validationError(GL_INVALID_ENUM, kErrorUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 316 | return false; |
| 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
| 322 | template <typename ParamType> |
| 323 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 324 | { |
| 325 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 326 | switch (ConvertToGLenum(params[0])) |
| 327 | { |
| 328 | case GL_LEQUAL: |
| 329 | case GL_GEQUAL: |
| 330 | case GL_LESS: |
| 331 | case GL_GREATER: |
| 332 | case GL_EQUAL: |
| 333 | case GL_NOTEQUAL: |
| 334 | case GL_ALWAYS: |
| 335 | case GL_NEVER: |
| 336 | break; |
| 337 | |
| 338 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 339 | context->validationError(GL_INVALID_ENUM, kErrorUnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 340 | return false; |
| 341 | } |
| 342 | |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 347 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 348 | { |
| 349 | if (!context->getExtensions().textureSRGBDecode) |
| 350 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 351 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 352 | return false; |
| 353 | } |
| 354 | |
| 355 | switch (ConvertToGLenum(params[0])) |
| 356 | { |
| 357 | case GL_DECODE_EXT: |
| 358 | case GL_SKIP_DECODE_EXT: |
| 359 | break; |
| 360 | |
| 361 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 362 | context->validationError(GL_INVALID_ENUM, kErrorUnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 363 | return false; |
| 364 | } |
| 365 | |
| 366 | return true; |
| 367 | } |
| 368 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 369 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 370 | { |
| 371 | if (!context->getExtensions().textureFilterAnisotropic) |
| 372 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 373 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 374 | return false; |
| 375 | } |
| 376 | |
| 377 | return true; |
| 378 | } |
| 379 | |
| 380 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 381 | { |
| 382 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 383 | { |
| 384 | return false; |
| 385 | } |
| 386 | |
| 387 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 388 | |
| 389 | if (paramValue < 1 || paramValue > largest) |
| 390 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 391 | context->validationError(GL_INVALID_VALUE, kErrorOutsideOfBounds); |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 392 | return false; |
| 393 | } |
| 394 | |
| 395 | return true; |
| 396 | } |
| 397 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 398 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 399 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 400 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 401 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 402 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 403 | return ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 404 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 405 | program->getActiveOutputVariables().to_ulong(), |
| 406 | framebuffer->getDrawBufferMask().to_ulong()); |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 407 | } |
| 408 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 409 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 410 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 411 | const auto &glState = context->getGLState(); |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 412 | const Program *program = context->getGLState().getLinkedProgram(context); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 413 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 414 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 415 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 416 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 417 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 418 | |
| 419 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 420 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 421 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 422 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 423 | return ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), |
| 424 | vaoAttribTypeBits, program->getAttributesMask().to_ulong(), |
| 425 | 0xFFFF); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 426 | } |
| 427 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 428 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 429 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 430 | { |
| 431 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 432 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 433 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 434 | case PrimitiveMode::Points: |
| 435 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 436 | case PrimitiveMode::Lines: |
| 437 | case PrimitiveMode::LineStrip: |
| 438 | case PrimitiveMode::LineLoop: |
| 439 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 440 | case PrimitiveMode::LinesAdjacency: |
| 441 | case PrimitiveMode::LineStripAdjacency: |
| 442 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 443 | case PrimitiveMode::Triangles: |
| 444 | case PrimitiveMode::TriangleFan: |
| 445 | case PrimitiveMode::TriangleStrip: |
| 446 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 447 | case PrimitiveMode::TrianglesAdjacency: |
| 448 | case PrimitiveMode::TriangleStripAdjacency: |
| 449 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 450 | default: |
| 451 | UNREACHABLE(); |
| 452 | return false; |
| 453 | } |
| 454 | } |
| 455 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 456 | // GLES1 texture parameters are a small subset of the others |
| 457 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 458 | { |
| 459 | switch (pname) |
| 460 | { |
| 461 | case GL_TEXTURE_MAG_FILTER: |
| 462 | case GL_TEXTURE_MIN_FILTER: |
| 463 | case GL_TEXTURE_WRAP_S: |
| 464 | case GL_TEXTURE_WRAP_T: |
| 465 | case GL_TEXTURE_WRAP_R: |
| 466 | case GL_GENERATE_MIPMAP: |
| 467 | case GL_TEXTURE_CROP_RECT_OES: |
| 468 | return true; |
| 469 | default: |
| 470 | return false; |
| 471 | } |
| 472 | } |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 473 | |
| 474 | unsigned int GetSamplerParameterCount(GLenum pname) |
| 475 | { |
| 476 | return pname == GL_TEXTURE_BORDER_COLOR ? 4 : 1; |
| 477 | } |
| 478 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 479 | } // anonymous namespace |
| 480 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 481 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 482 | { |
| 483 | if (length) |
| 484 | { |
| 485 | *length = value; |
| 486 | } |
| 487 | } |
| 488 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 489 | bool IsETC2EACFormat(const GLenum format) |
| 490 | { |
| 491 | // ES 3.1, Table 8.19 |
| 492 | switch (format) |
| 493 | { |
| 494 | case GL_COMPRESSED_R11_EAC: |
| 495 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 496 | case GL_COMPRESSED_RG11_EAC: |
| 497 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 498 | case GL_COMPRESSED_RGB8_ETC2: |
| 499 | case GL_COMPRESSED_SRGB8_ETC2: |
| 500 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 501 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 502 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 503 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 504 | return true; |
| 505 | |
| 506 | default: |
| 507 | return false; |
| 508 | } |
| 509 | } |
| 510 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 511 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 512 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 513 | switch (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 | case TextureType::_2D: |
| 516 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 517 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 518 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 519 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 520 | return context->getExtensions().textureRectangle; |
| 521 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 522 | case TextureType::_3D: |
| 523 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 524 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 525 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 526 | case TextureType::_2DMultisample: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 527 | return (context->getClientVersion() >= Version(3, 1) || |
| 528 | context->getExtensions().textureMultisample); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 529 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 530 | return context->getExtensions().textureStorageMultisample2DArray; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 531 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 532 | default: |
| 533 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 534 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 535 | } |
| 536 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 537 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 538 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 539 | switch (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 | case TextureType::_2D: |
| 542 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 543 | return true; |
| 544 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 545 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 546 | return context->getExtensions().textureRectangle; |
| 547 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 548 | default: |
| 549 | return false; |
| 550 | } |
| 551 | } |
| 552 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 553 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 554 | { |
| 555 | switch (target) |
| 556 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 557 | case TextureType::_3D: |
| 558 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 559 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 560 | |
| 561 | default: |
| 562 | return false; |
| 563 | } |
| 564 | } |
| 565 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 566 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 567 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 568 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 569 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 570 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 571 | (context->getExtensions().eglImageExternal || |
| 572 | context->getExtensions().eglStreamConsumerExternal); |
| 573 | } |
| 574 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 575 | // This function differs from ValidTextureTarget in that the target must be |
| 576 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 577 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 578 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 579 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 580 | { |
| 581 | switch (target) |
| 582 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 583 | case TextureTarget::_2D: |
| 584 | case TextureTarget::CubeMapNegativeX: |
| 585 | case TextureTarget::CubeMapNegativeY: |
| 586 | case TextureTarget::CubeMapNegativeZ: |
| 587 | case TextureTarget::CubeMapPositiveX: |
| 588 | case TextureTarget::CubeMapPositiveY: |
| 589 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 590 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 591 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 592 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 593 | default: |
| 594 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 598 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 599 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 600 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 601 | { |
| 602 | ASSERT(context); |
| 603 | |
| 604 | if (!context->getExtensions().geometryShader) |
| 605 | { |
| 606 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 607 | // that does not match the current transform feedback object's draw mode (if transform |
| 608 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 609 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 610 | } |
| 611 | |
| 612 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 613 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 614 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 615 | case PrimitiveMode::Points: |
| 616 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 617 | case PrimitiveMode::Lines: |
| 618 | case PrimitiveMode::LineStrip: |
| 619 | case PrimitiveMode::LineLoop: |
| 620 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 621 | case PrimitiveMode::Triangles: |
| 622 | case PrimitiveMode::TriangleFan: |
| 623 | case PrimitiveMode::TriangleStrip: |
| 624 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 625 | default: |
| 626 | UNREACHABLE(); |
| 627 | return false; |
| 628 | } |
| 629 | } |
| 630 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 631 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 632 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 633 | GLsizei count, |
| 634 | GLenum type, |
| 635 | const GLvoid *indices, |
| 636 | GLsizei primcount) |
| 637 | { |
| 638 | if (primcount < 0) |
| 639 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 640 | context->validationError(GL_INVALID_VALUE, kErrorNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 641 | return false; |
| 642 | } |
| 643 | |
| 644 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 645 | { |
| 646 | return false; |
| 647 | } |
| 648 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 649 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 653 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 654 | GLint first, |
| 655 | GLsizei count, |
| 656 | GLsizei primcount) |
| 657 | { |
| 658 | if (primcount < 0) |
| 659 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 660 | context->validationError(GL_INVALID_VALUE, kErrorNegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 661 | return false; |
| 662 | } |
| 663 | |
| 664 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 665 | { |
| 666 | return false; |
| 667 | } |
| 668 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 669 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 670 | } |
| 671 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 672 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 673 | { |
| 674 | // Verify there is at least one active attribute with a divisor of zero |
| 675 | const State &state = context->getGLState(); |
| 676 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 677 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 678 | |
| 679 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 680 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 681 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 682 | { |
| 683 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 684 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 685 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 686 | { |
| 687 | return true; |
| 688 | } |
| 689 | } |
| 690 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 691 | context->validationError(GL_INVALID_OPERATION, kErrorNoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 692 | return false; |
| 693 | } |
| 694 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 695 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 696 | { |
| 697 | switch (target) |
| 698 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 699 | case TextureType::_3D: |
| 700 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 701 | return true; |
| 702 | default: |
| 703 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 704 | } |
| 705 | } |
| 706 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 707 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 708 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 709 | switch (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 | case TextureType::_2D: |
| 712 | case TextureType::_2DArray: |
| 713 | case TextureType::_2DMultisample: |
| 714 | case TextureType::CubeMap: |
| 715 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 716 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 717 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 718 | return context->getExtensions().textureRectangle; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 719 | case TextureType::_2DMultisampleArray: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 720 | return context->getExtensions().textureStorageMultisample2DArray; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 721 | default: |
| 722 | return false; |
| 723 | } |
| 724 | } |
| 725 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 726 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 727 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 728 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 729 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 730 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 731 | |
| 732 | switch (target) |
| 733 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 734 | case GL_FRAMEBUFFER: |
| 735 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 736 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 737 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 738 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 739 | return (context->getExtensions().framebufferBlit || |
| 740 | context->getClientMajorVersion() >= 3); |
| 741 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 742 | default: |
| 743 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 744 | } |
| 745 | } |
| 746 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 747 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 748 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 749 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 750 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 751 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 752 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 753 | case TextureType::_2D: |
| 754 | case TextureType::_2DArray: |
| 755 | case TextureType::_2DMultisample: |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 756 | case TextureType::_2DMultisampleArray: |
| 757 | // TODO(http://anglebug.com/2775): It's a bit unclear what the "maximum allowable |
| 758 | // 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] | 759 | maxDimension = caps.max2DTextureSize; |
| 760 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 761 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 762 | maxDimension = caps.maxCubeMapTextureSize; |
| 763 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 764 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 765 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 766 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 767 | maxDimension = caps.max3DTextureSize; |
| 768 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 769 | default: |
| 770 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 773 | return level <= log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 774 | } |
| 775 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 776 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 777 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 778 | GLint level, |
| 779 | GLsizei width, |
| 780 | GLsizei height, |
| 781 | GLsizei depth, |
| 782 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 783 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 784 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 785 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 786 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 787 | return false; |
| 788 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 789 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 790 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 791 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 792 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 793 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 794 | (level != 0 && (!isPow2(width) || !isPow2(height) || !isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 795 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 796 | context->validationError(GL_INVALID_VALUE, kErrorTextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 797 | return false; |
| 798 | } |
| 799 | |
| 800 | if (!ValidMipLevel(context, target, level)) |
| 801 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 802 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 803 | return false; |
| 804 | } |
| 805 | |
| 806 | return true; |
| 807 | } |
| 808 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 809 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 810 | { |
| 811 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 812 | (size % blockSize == 0); |
| 813 | } |
| 814 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 815 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 816 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 817 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 818 | GLsizei width, |
| 819 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 820 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 821 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 822 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 823 | { |
| 824 | return false; |
| 825 | } |
| 826 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 827 | if (width < 0 || height < 0) |
| 828 | { |
| 829 | return false; |
| 830 | } |
| 831 | |
| 832 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 833 | { |
| 834 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 835 | // block size for level 0 but WebGL disallows this. |
| 836 | bool smallerThanBlockSizeAllowed = |
| 837 | level > 0 || !context->getExtensions().webglCompatibility; |
| 838 | |
| 839 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 840 | smallerThanBlockSizeAllowed) || |
| 841 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 842 | smallerThanBlockSizeAllowed)) |
| 843 | { |
| 844 | return false; |
| 845 | } |
| 846 | } |
| 847 | |
| 848 | return true; |
| 849 | } |
| 850 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 851 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 852 | GLenum internalFormat, |
| 853 | GLint xoffset, |
| 854 | GLint yoffset, |
| 855 | GLsizei width, |
| 856 | GLsizei height, |
| 857 | size_t textureWidth, |
| 858 | size_t textureHeight) |
| 859 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 860 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 861 | if (!formatInfo.compressed) |
| 862 | { |
| 863 | return false; |
| 864 | } |
| 865 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 866 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 867 | { |
| 868 | return false; |
| 869 | } |
| 870 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 871 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 872 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 873 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 874 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 875 | { |
| 876 | return false; |
| 877 | } |
| 878 | |
| 879 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 880 | // size but fills the entire mip |
| 881 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 882 | static_cast<size_t>(width) == textureWidth && |
| 883 | static_cast<size_t>(height) == textureHeight; |
| 884 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 885 | (height % formatInfo.compressedBlockHeight) == 0; |
| 886 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 887 | { |
| 888 | return false; |
| 889 | } |
| 890 | } |
| 891 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 892 | return true; |
| 893 | } |
| 894 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 895 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 896 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 897 | GLsizei width, |
| 898 | GLsizei height, |
| 899 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 900 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 901 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 902 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 903 | GLsizei imageSize) |
| 904 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 905 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 906 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 907 | { |
| 908 | // Checks are not required |
| 909 | return true; |
| 910 | } |
| 911 | |
| 912 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 913 | // would exceed the data store size. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 914 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 915 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 916 | const Extents size(width, height, depth); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 917 | const auto &unpack = context->getGLState().getUnpackState(); |
| 918 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 919 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
| 920 | GLuint endByte = 0; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 921 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 922 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 923 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 924 | return false; |
| 925 | } |
| 926 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 927 | if (pixelUnpackBuffer) |
| 928 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 929 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 930 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 931 | checkedEndByte += checkedOffset; |
| 932 | |
| 933 | if (!checkedEndByte.IsValid() || |
| 934 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 935 | { |
| 936 | // Overflow past the end of the buffer |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 937 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 938 | return false; |
| 939 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 940 | if (context->getExtensions().webglCompatibility && |
| 941 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 942 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 943 | context->validationError(GL_INVALID_OPERATION, |
| 944 | kErrorPixelUnpackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 945 | return false; |
| 946 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 947 | } |
| 948 | else |
| 949 | { |
| 950 | ASSERT(imageSize >= 0); |
| 951 | if (pixels == nullptr && imageSize != 0) |
| 952 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 953 | context->validationError(GL_INVALID_OPERATION, |
| 954 | "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 955 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 956 | } |
| 957 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 958 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 959 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 960 | context->validationError(GL_INVALID_OPERATION, "imageSize is too small"); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 961 | return false; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | return true; |
| 966 | } |
| 967 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 968 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 969 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 970 | switch (queryType) |
| 971 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 972 | case QueryType::AnySamples: |
| 973 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 974 | return context->getClientMajorVersion() >= 3 || |
| 975 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 976 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 977 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 978 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 979 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 980 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 981 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 982 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 983 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 984 | default: |
| 985 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 986 | } |
| 987 | } |
| 988 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 989 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 990 | GLenum type, |
| 991 | GLboolean normalized, |
| 992 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 993 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 994 | bool pureInteger) |
| 995 | { |
| 996 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 997 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 998 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 999 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1000 | // parameter exceeds 255. |
| 1001 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1002 | if (stride > kMaxWebGLStride) |
| 1003 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1004 | context->validationError(GL_INVALID_VALUE, |
| 1005 | "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1010 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1011 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1012 | // or an INVALID_OPERATION error is generated. |
Frank Henigman | d633b15 | 2018-10-04 23:34:31 -0400 | [diff] [blame] | 1013 | angle::FormatID internalType = GetVertexFormatID(type, normalized, 1, pureInteger); |
| 1014 | size_t typeSize = GetVertexFormatSize(internalType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1015 | |
| 1016 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1017 | size_t sizeMask = (typeSize - 1); |
| 1018 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1019 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1020 | context->validationError(GL_INVALID_OPERATION, kErrorOffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
| 1023 | |
| 1024 | if ((stride & sizeMask) != 0) |
| 1025 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1026 | context->validationError(GL_INVALID_OPERATION, kErrorStrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1027 | return false; |
| 1028 | } |
| 1029 | |
| 1030 | return true; |
| 1031 | } |
| 1032 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1033 | Program *GetValidProgramNoResolve(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1034 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1035 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1036 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1037 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1038 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1039 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1040 | Program *validProgram = context->getProgramNoResolveLink(id); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1041 | |
| 1042 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1043 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1044 | if (context->getShader(id)) |
| 1045 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1046 | context->validationError(GL_INVALID_OPERATION, kErrorExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1047 | } |
| 1048 | else |
| 1049 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1050 | context->validationError(GL_INVALID_VALUE, kErrorInvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1051 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1052 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1053 | |
| 1054 | return validProgram; |
| 1055 | } |
| 1056 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1057 | Program *GetValidProgram(Context *context, GLuint id) |
| 1058 | { |
| 1059 | Program *program = GetValidProgramNoResolve(context, id); |
| 1060 | if (program) |
| 1061 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 1062 | program->resolveLink(context); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1063 | } |
| 1064 | return program; |
| 1065 | } |
| 1066 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1067 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1068 | { |
| 1069 | // See ValidProgram for spec details. |
| 1070 | |
| 1071 | Shader *validShader = context->getShader(id); |
| 1072 | |
| 1073 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1074 | { |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 1075 | if (context->getProgramNoResolveLink(id)) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1076 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1077 | context->validationError(GL_INVALID_OPERATION, kErrorExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1078 | } |
| 1079 | else |
| 1080 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1081 | context->validationError(GL_INVALID_VALUE, kErrorInvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1082 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1083 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1084 | |
| 1085 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1086 | } |
| 1087 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1088 | bool ValidateAttachmentTarget(Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1089 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1090 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
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 (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1093 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1094 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1095 | return false; |
| 1096 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1097 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1098 | // Color attachment 0 is validated below because it is always valid |
| 1099 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1100 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1101 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1102 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1103 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | else |
| 1107 | { |
| 1108 | switch (attachment) |
| 1109 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1110 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1111 | case GL_DEPTH_ATTACHMENT: |
| 1112 | case GL_STENCIL_ATTACHMENT: |
| 1113 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1114 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1115 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1116 | if (!context->getExtensions().webglCompatibility && |
| 1117 | context->getClientMajorVersion() < 3) |
| 1118 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1119 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | return false; |
| 1121 | } |
| 1122 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1123 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1124 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1125 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1126 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | return true; |
| 1131 | } |
| 1132 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1133 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1134 | GLenum target, |
| 1135 | GLsizei samples, |
| 1136 | GLenum internalformat, |
| 1137 | GLsizei width, |
| 1138 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1139 | { |
| 1140 | switch (target) |
| 1141 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1142 | case GL_RENDERBUFFER: |
| 1143 | break; |
| 1144 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1145 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1146 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1147 | } |
| 1148 | |
| 1149 | if (width < 0 || height < 0 || samples < 0) |
| 1150 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1151 | context->validationError(GL_INVALID_VALUE, kErrorInvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1152 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1153 | } |
| 1154 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1155 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1156 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1157 | |
| 1158 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1159 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1160 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1161 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1162 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1163 | } |
| 1164 | |
| 1165 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1166 | // 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] | 1167 | // only sized internal formats. |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1168 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(convertedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1169 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1171 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1172 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1173 | } |
| 1174 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1175 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1176 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1177 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxRenderbufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1178 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1179 | } |
| 1180 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1181 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1182 | if (handle == 0) |
| 1183 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1184 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1185 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
| 1188 | return true; |
| 1189 | } |
| 1190 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1191 | bool ValidateFramebufferRenderbufferParameters(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1192 | GLenum target, |
| 1193 | GLenum attachment, |
| 1194 | GLenum renderbuffertarget, |
| 1195 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1196 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1197 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1198 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1199 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1200 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1201 | } |
| 1202 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1203 | Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1204 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1205 | ASSERT(framebuffer); |
| 1206 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1207 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1208 | context->validationError(GL_INVALID_OPERATION, kErrorDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1209 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1210 | } |
| 1211 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1212 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1213 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1214 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1215 | } |
| 1216 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1217 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1218 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1219 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1220 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1221 | if (renderbuffer != 0) |
| 1222 | { |
| 1223 | if (!context->getRenderbuffer(renderbuffer)) |
| 1224 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1225 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1226 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1227 | } |
| 1228 | } |
| 1229 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1230 | return true; |
| 1231 | } |
| 1232 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1233 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1234 | GLint srcX0, |
| 1235 | GLint srcY0, |
| 1236 | GLint srcX1, |
| 1237 | GLint srcY1, |
| 1238 | GLint dstX0, |
| 1239 | GLint dstY0, |
| 1240 | GLint dstX1, |
| 1241 | GLint dstY1, |
| 1242 | GLbitfield mask, |
| 1243 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1244 | { |
| 1245 | switch (filter) |
| 1246 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1247 | case GL_NEAREST: |
| 1248 | break; |
| 1249 | case GL_LINEAR: |
| 1250 | break; |
| 1251 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1252 | context->validationError(GL_INVALID_ENUM, kErrorBlitInvalidFilter); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1253 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1257 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1258 | context->validationError(GL_INVALID_VALUE, kErrorBlitInvalidMask); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1259 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1262 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1263 | // color buffer, leaving only nearest being unfiltered from above |
| 1264 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1265 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1266 | context->validationError(GL_INVALID_OPERATION, kErrorBlitOnlyNearestForNonColor); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1267 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1268 | } |
| 1269 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1270 | const auto &glState = context->getGLState(); |
| 1271 | Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1272 | Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1273 | |
| 1274 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1275 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1276 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kErrorBlitFramebufferMissing); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1277 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1280 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1281 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1282 | return false; |
| 1283 | } |
| 1284 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1285 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1286 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1287 | return false; |
| 1288 | } |
| 1289 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1290 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1291 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1292 | context->validationError(GL_INVALID_OPERATION, kErrorBlitFeedbackLoop); |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1296 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1297 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1298 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1301 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1302 | // always run it in order to avoid triggering driver bugs. |
| 1303 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1304 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1305 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1306 | context->validationError(GL_INVALID_VALUE, kErrorBlitDimensionsOutOfRange); |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1307 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1308 | } |
| 1309 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1311 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1313 | { |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 1314 | const FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
| 1315 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1316 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1317 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1318 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1319 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1320 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1321 | for (size_t drawbufferIdx = 0; |
| 1322 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1323 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1324 | const FramebufferAttachment *attachment = |
| 1325 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1326 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1327 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1328 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1329 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1330 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1331 | // 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] | 1332 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1333 | // as well |
| 1334 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1335 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1336 | // Changes with EXT_color_buffer_float: |
| 1337 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1338 | GLenum readComponentType = readFormat.info->componentType; |
| 1339 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1340 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1341 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1342 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1343 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1344 | |
| 1345 | if (extensions.colorBufferFloat) |
| 1346 | { |
| 1347 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1348 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1349 | |
| 1350 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1351 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1352 | context->validationError(GL_INVALID_OPERATION, |
| 1353 | kErrorBlitTypeMismatchFixedOrFloat); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | } |
| 1357 | else if (readFixedPoint != drawFixedPoint) |
| 1358 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1359 | context->validationError(GL_INVALID_OPERATION, |
| 1360 | kErrorBlitTypeMismatchFixedPoint); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1361 | return false; |
| 1362 | } |
| 1363 | |
| 1364 | if (readComponentType == GL_UNSIGNED_INT && |
| 1365 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1366 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1367 | context->validationError(GL_INVALID_OPERATION, |
| 1368 | kErrorBlitTypeMismatchUnsignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1369 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1370 | } |
| 1371 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1372 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1373 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1374 | context->validationError(GL_INVALID_OPERATION, |
| 1375 | kErrorBlitTypeMismatchSignedInteger); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1376 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1377 | } |
| 1378 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1379 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1380 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1381 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1382 | context->validationError(GL_INVALID_OPERATION, |
| 1383 | kErrorBlitMultisampledFormatOrBoundsMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1384 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1385 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1386 | |
| 1387 | if (context->getExtensions().webglCompatibility && |
| 1388 | *readColorBuffer == *attachment) |
| 1389 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1390 | context->validationError(GL_INVALID_OPERATION, kErrorBlitSameImageColor); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1391 | return false; |
| 1392 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1393 | } |
| 1394 | } |
| 1395 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1396 | if ((readFormat.info->componentType == GL_INT || |
| 1397 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1398 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1399 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1400 | context->validationError(GL_INVALID_OPERATION, kErrorBlitIntegerWithLinearFilter); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1401 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1402 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1404 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1405 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1406 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1407 | // situation is an application error that would lead to a crash in ANGLE. |
| 1408 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1409 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1410 | context->validationError(GL_INVALID_OPERATION, kErrorBlitMissingColor); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1411 | return false; |
| 1412 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1415 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1416 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1417 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1418 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1419 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1421 | const FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1422 | readFramebuffer->getAttachment(context, attachments[i]); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1423 | const FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1424 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1426 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1427 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1428 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1429 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1430 | context->validationError(GL_INVALID_OPERATION, |
| 1431 | kErrorBlitDepthOrStencilFormatMismatch); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1432 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1433 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1434 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1435 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1436 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1437 | context->validationError(GL_INVALID_OPERATION, |
| 1438 | kErrorBlitMultisampledBoundsMismatch); |
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 | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1444 | context->validationError(GL_INVALID_OPERATION, |
| 1445 | kErrorBlitSameImageDepthOrStencil); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1448 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1449 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1450 | else if (drawBuffer) |
| 1451 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1452 | context->validationError(GL_INVALID_OPERATION, kErrorBlitMissingDepthOrStencil); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1453 | return false; |
| 1454 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1455 | } |
| 1456 | } |
| 1457 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1458 | // ANGLE_multiview, Revision 1: |
| 1459 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
Olli Etuaho | 8acb1b6 | 2018-07-30 16:20:54 +0300 | [diff] [blame] | 1460 | // multi-view layout of the current draw framebuffer is not NONE, or if the multi-view layout of |
| 1461 | // the current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of |
| 1462 | // views in the current read framebuffer is more than one. |
| 1463 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1464 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1465 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kErrorBlitFromMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
| 1468 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1469 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1470 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, kErrorBlitToMultiview); |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1471 | return false; |
| 1472 | } |
| 1473 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1474 | return true; |
| 1475 | } |
| 1476 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1477 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1478 | GLint x, |
| 1479 | GLint y, |
| 1480 | GLsizei width, |
| 1481 | GLsizei height, |
| 1482 | GLenum format, |
| 1483 | GLenum type, |
| 1484 | GLsizei bufSize, |
| 1485 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1486 | GLsizei *columns, |
| 1487 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1488 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1489 | { |
| 1490 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1491 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1492 | return false; |
| 1493 | } |
| 1494 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1495 | GLsizei writeLength = 0; |
| 1496 | GLsizei writeColumns = 0; |
| 1497 | GLsizei writeRows = 0; |
| 1498 | |
| 1499 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1500 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1501 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1502 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1503 | } |
| 1504 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1505 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1506 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1507 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1508 | } |
| 1509 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1510 | SetRobustLengthParam(length, writeLength); |
| 1511 | SetRobustLengthParam(columns, writeColumns); |
| 1512 | SetRobustLengthParam(rows, writeRows); |
| 1513 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1514 | return true; |
| 1515 | } |
| 1516 | |
| 1517 | bool ValidateReadnPixelsEXT(Context *context, |
| 1518 | GLint x, |
| 1519 | GLint y, |
| 1520 | GLsizei width, |
| 1521 | GLsizei height, |
| 1522 | GLenum format, |
| 1523 | GLenum type, |
| 1524 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1525 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1526 | { |
| 1527 | if (bufSize < 0) |
| 1528 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1529 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1530 | return false; |
| 1531 | } |
| 1532 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1533 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1534 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1535 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1536 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1537 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1538 | GLint x, |
| 1539 | GLint y, |
| 1540 | GLsizei width, |
| 1541 | GLsizei height, |
| 1542 | GLenum format, |
| 1543 | GLenum type, |
| 1544 | GLsizei bufSize, |
| 1545 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1546 | GLsizei *columns, |
| 1547 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1548 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1549 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1550 | GLsizei writeLength = 0; |
| 1551 | GLsizei writeColumns = 0; |
| 1552 | GLsizei writeRows = 0; |
| 1553 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1554 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1555 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1556 | return false; |
| 1557 | } |
| 1558 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1559 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1560 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1561 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1562 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1563 | } |
| 1564 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1565 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1566 | { |
| 1567 | return false; |
| 1568 | } |
| 1569 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1570 | SetRobustLengthParam(length, writeLength); |
| 1571 | SetRobustLengthParam(columns, writeColumns); |
| 1572 | SetRobustLengthParam(rows, writeRows); |
| 1573 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1574 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1575 | } |
| 1576 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1577 | bool ValidateGenQueriesEXT(Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1578 | { |
| 1579 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1580 | !context->getExtensions().disjointTimerQuery) |
| 1581 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1582 | context->validationError(GL_INVALID_OPERATION, kErrorQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1583 | return false; |
| 1584 | } |
| 1585 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1586 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1587 | } |
| 1588 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1589 | bool ValidateDeleteQueriesEXT(Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1590 | { |
| 1591 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1592 | !context->getExtensions().disjointTimerQuery) |
| 1593 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1594 | context->validationError(GL_INVALID_OPERATION, kErrorQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1595 | return false; |
| 1596 | } |
| 1597 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1598 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1601 | bool ValidateIsQueryEXT(Context *context, GLuint id) |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1602 | { |
| 1603 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1604 | !context->getExtensions().disjointTimerQuery) |
| 1605 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1606 | context->validationError(GL_INVALID_OPERATION, kErrorQueryExtensionNotEnabled); |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1607 | return false; |
| 1608 | } |
| 1609 | |
| 1610 | return true; |
| 1611 | } |
| 1612 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1613 | bool ValidateBeginQueryBase(Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1614 | { |
| 1615 | if (!ValidQueryType(context, target)) |
| 1616 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1617 | context->validationError(GL_INVALID_ENUM, kErrorInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1618 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | if (id == 0) |
| 1622 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1623 | context->validationError(GL_INVALID_OPERATION, "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1624 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1628 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1629 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1630 | // the active query for either target is non-zero), if <id> is the name of an |
| 1631 | // existing query object whose type does not match <target>, or if <id> is the |
| 1632 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1633 | // generated. |
| 1634 | |
| 1635 | // Ensure no other queries are active |
| 1636 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1637 | // separately that: |
| 1638 | // a) The query ID passed is not the current active query for any target/type |
| 1639 | // b) There are no active queries for the requested target (and in the case |
| 1640 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1641 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1642 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1643 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1644 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1645 | context->validationError(GL_INVALID_OPERATION, "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1646 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1647 | } |
| 1648 | |
| 1649 | Query *queryObject = context->getQuery(id, true, target); |
| 1650 | |
| 1651 | // check that name was obtained with glGenQueries |
| 1652 | if (!queryObject) |
| 1653 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1654 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1655 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | // check for type mismatch |
| 1659 | if (queryObject->getType() != target) |
| 1660 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1661 | context->validationError(GL_INVALID_OPERATION, "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1662 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | return true; |
| 1666 | } |
| 1667 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1668 | bool ValidateBeginQueryEXT(Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1669 | { |
| 1670 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1671 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1672 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1673 | context->validationError(GL_INVALID_OPERATION, kErrorQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1674 | return false; |
| 1675 | } |
| 1676 | |
| 1677 | return ValidateBeginQueryBase(context, target, id); |
| 1678 | } |
| 1679 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1680 | bool ValidateEndQueryBase(Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1681 | { |
| 1682 | if (!ValidQueryType(context, target)) |
| 1683 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1684 | context->validationError(GL_INVALID_ENUM, kErrorInvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1685 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1686 | } |
| 1687 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1688 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1689 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1690 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1691 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1692 | context->validationError(GL_INVALID_OPERATION, "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1693 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1694 | } |
| 1695 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1696 | return true; |
| 1697 | } |
| 1698 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 1699 | bool ValidateEndQueryEXT(Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1700 | { |
| 1701 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1702 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1703 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1704 | context->validationError(GL_INVALID_OPERATION, kErrorQueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1705 | return false; |
| 1706 | } |
| 1707 | |
| 1708 | return ValidateEndQueryBase(context, target); |
| 1709 | } |
| 1710 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1711 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1712 | { |
| 1713 | if (!context->getExtensions().disjointTimerQuery) |
| 1714 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1715 | context->validationError(GL_INVALID_OPERATION, "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1716 | return false; |
| 1717 | } |
| 1718 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1719 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1720 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1721 | context->validationError(GL_INVALID_ENUM, kErrorInvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1722 | return false; |
| 1723 | } |
| 1724 | |
| 1725 | Query *queryObject = context->getQuery(id, true, target); |
| 1726 | if (queryObject == nullptr) |
| 1727 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1728 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1729 | return false; |
| 1730 | } |
| 1731 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1732 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1733 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1734 | context->validationError(GL_INVALID_OPERATION, kErrorQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1735 | return false; |
| 1736 | } |
| 1737 | |
| 1738 | return true; |
| 1739 | } |
| 1740 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1741 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1742 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1743 | if (numParams) |
| 1744 | { |
| 1745 | *numParams = 0; |
| 1746 | } |
| 1747 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1748 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1749 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1750 | context->validationError(GL_INVALID_ENUM, kErrorInvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1751 | return false; |
| 1752 | } |
| 1753 | |
| 1754 | switch (pname) |
| 1755 | { |
| 1756 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1757 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1758 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1759 | context->validationError(GL_INVALID_ENUM, "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1760 | return false; |
| 1761 | } |
| 1762 | break; |
| 1763 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1764 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1765 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1766 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1767 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1768 | return false; |
| 1769 | } |
| 1770 | break; |
| 1771 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1772 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1773 | return false; |
| 1774 | } |
| 1775 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1776 | if (numParams) |
| 1777 | { |
| 1778 | // All queries return only one value |
| 1779 | *numParams = 1; |
| 1780 | } |
| 1781 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1782 | return true; |
| 1783 | } |
| 1784 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1785 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1786 | { |
| 1787 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1788 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1789 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1790 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1791 | return false; |
| 1792 | } |
| 1793 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1794 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1795 | } |
| 1796 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1797 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1798 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1799 | GLenum pname, |
| 1800 | GLsizei bufSize, |
| 1801 | GLsizei *length, |
| 1802 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1803 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1804 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1805 | { |
| 1806 | return false; |
| 1807 | } |
| 1808 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1809 | GLsizei numParams = 0; |
| 1810 | |
| 1811 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1812 | { |
| 1813 | return false; |
| 1814 | } |
| 1815 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1816 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1817 | { |
| 1818 | return false; |
| 1819 | } |
| 1820 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1821 | SetRobustLengthParam(length, numParams); |
| 1822 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1823 | return true; |
| 1824 | } |
| 1825 | |
| 1826 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1827 | { |
| 1828 | if (numParams) |
| 1829 | { |
| 1830 | *numParams = 0; |
| 1831 | } |
| 1832 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1833 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1834 | |
| 1835 | if (!queryObject) |
| 1836 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1837 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1838 | return false; |
| 1839 | } |
| 1840 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1841 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1842 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1843 | context->validationError(GL_INVALID_OPERATION, kErrorQueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1844 | return false; |
| 1845 | } |
| 1846 | |
| 1847 | switch (pname) |
| 1848 | { |
| 1849 | case GL_QUERY_RESULT_EXT: |
| 1850 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1851 | break; |
| 1852 | |
| 1853 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1854 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1855 | return false; |
| 1856 | } |
| 1857 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1858 | if (numParams) |
| 1859 | { |
| 1860 | *numParams = 1; |
| 1861 | } |
| 1862 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1863 | return true; |
| 1864 | } |
| 1865 | |
| 1866 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1867 | { |
| 1868 | if (!context->getExtensions().disjointTimerQuery) |
| 1869 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1870 | context->validationError(GL_INVALID_OPERATION, "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1871 | return false; |
| 1872 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1873 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1874 | } |
| 1875 | |
| 1876 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1877 | GLuint id, |
| 1878 | GLenum pname, |
| 1879 | GLsizei bufSize, |
| 1880 | GLsizei *length, |
| 1881 | GLint *params) |
| 1882 | { |
| 1883 | if (!context->getExtensions().disjointTimerQuery) |
| 1884 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1885 | context->validationError(GL_INVALID_OPERATION, "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1886 | return false; |
| 1887 | } |
| 1888 | |
| 1889 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1890 | { |
| 1891 | return false; |
| 1892 | } |
| 1893 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1894 | GLsizei numParams = 0; |
| 1895 | |
| 1896 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1897 | { |
| 1898 | return false; |
| 1899 | } |
| 1900 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1901 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1902 | { |
| 1903 | return false; |
| 1904 | } |
| 1905 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1906 | SetRobustLengthParam(length, numParams); |
| 1907 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1908 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1912 | { |
| 1913 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1914 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1915 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1916 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1917 | return false; |
| 1918 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1919 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1920 | } |
| 1921 | |
| 1922 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1923 | GLuint id, |
| 1924 | GLenum pname, |
| 1925 | GLsizei bufSize, |
| 1926 | GLsizei *length, |
| 1927 | GLuint *params) |
| 1928 | { |
| 1929 | if (!context->getExtensions().disjointTimerQuery && |
| 1930 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1931 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1932 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1933 | return false; |
| 1934 | } |
| 1935 | |
| 1936 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1937 | { |
| 1938 | return false; |
| 1939 | } |
| 1940 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1941 | GLsizei numParams = 0; |
| 1942 | |
| 1943 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1944 | { |
| 1945 | return false; |
| 1946 | } |
| 1947 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1948 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1949 | { |
| 1950 | return false; |
| 1951 | } |
| 1952 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1953 | SetRobustLengthParam(length, numParams); |
| 1954 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1955 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1959 | { |
| 1960 | if (!context->getExtensions().disjointTimerQuery) |
| 1961 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1962 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1963 | return false; |
| 1964 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1965 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1966 | } |
| 1967 | |
| 1968 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1969 | GLuint id, |
| 1970 | GLenum pname, |
| 1971 | GLsizei bufSize, |
| 1972 | GLsizei *length, |
| 1973 | GLint64 *params) |
| 1974 | { |
| 1975 | if (!context->getExtensions().disjointTimerQuery) |
| 1976 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 1977 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1978 | return false; |
| 1979 | } |
| 1980 | |
| 1981 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1982 | { |
| 1983 | return false; |
| 1984 | } |
| 1985 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1986 | GLsizei numParams = 0; |
| 1987 | |
| 1988 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1989 | { |
| 1990 | return false; |
| 1991 | } |
| 1992 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1993 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1994 | { |
| 1995 | return false; |
| 1996 | } |
| 1997 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1998 | SetRobustLengthParam(length, numParams); |
| 1999 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2000 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2001 | } |
| 2002 | |
| 2003 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2004 | { |
| 2005 | if (!context->getExtensions().disjointTimerQuery) |
| 2006 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2007 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2008 | return false; |
| 2009 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2010 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2011 | } |
| 2012 | |
| 2013 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2014 | GLuint id, |
| 2015 | GLenum pname, |
| 2016 | GLsizei bufSize, |
| 2017 | GLsizei *length, |
| 2018 | GLuint64 *params) |
| 2019 | { |
| 2020 | if (!context->getExtensions().disjointTimerQuery) |
| 2021 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2022 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2023 | return false; |
| 2024 | } |
| 2025 | |
| 2026 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2027 | { |
| 2028 | return false; |
| 2029 | } |
| 2030 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2031 | GLsizei numParams = 0; |
| 2032 | |
| 2033 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2034 | { |
| 2035 | return false; |
| 2036 | } |
| 2037 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2038 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2039 | { |
| 2040 | return false; |
| 2041 | } |
| 2042 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2043 | SetRobustLengthParam(length, numParams); |
| 2044 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2045 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2046 | } |
| 2047 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2048 | bool ValidateUniformCommonBase(Context *context, |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2049 | Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2050 | GLint location, |
| 2051 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2052 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2053 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2054 | // TODO(Jiajia): Add image uniform check in future. |
| 2055 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2056 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2057 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2058 | return false; |
| 2059 | } |
| 2060 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2061 | if (!program) |
| 2062 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2063 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidProgramName); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2064 | return false; |
| 2065 | } |
| 2066 | |
| 2067 | if (!program->isLinked()) |
| 2068 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2069 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2070 | return false; |
| 2071 | } |
| 2072 | |
| 2073 | if (location == -1) |
| 2074 | { |
| 2075 | // Silently ignore the uniform command |
| 2076 | return false; |
| 2077 | } |
| 2078 | |
| 2079 | const auto &uniformLocations = program->getUniformLocations(); |
| 2080 | size_t castedLocation = static_cast<size_t>(location); |
| 2081 | if (castedLocation >= uniformLocations.size()) |
| 2082 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2083 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2084 | return false; |
| 2085 | } |
| 2086 | |
| 2087 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2088 | if (uniformLocation.ignored) |
| 2089 | { |
| 2090 | // Silently ignore the uniform command |
| 2091 | return false; |
| 2092 | } |
| 2093 | |
| 2094 | if (!uniformLocation.used()) |
| 2095 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2096 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidUniformLocation); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2097 | return false; |
| 2098 | } |
| 2099 | |
| 2100 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2101 | |
| 2102 | // 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] | 2103 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2104 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2105 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidUniformCount); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | *uniformOut = &uniform; |
| 2110 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2111 | } |
| 2112 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2113 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2114 | GLenum uniformType, |
| 2115 | GLsizei count, |
| 2116 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2117 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2118 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2119 | // It is compatible with INT or BOOL. |
| 2120 | // Do these cheap tests first, for a little extra speed. |
| 2121 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2122 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2123 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2124 | } |
| 2125 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2126 | if (IsSamplerType(uniformType)) |
| 2127 | { |
| 2128 | // Check that the values are in range. |
| 2129 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2130 | for (GLsizei i = 0; i < count; ++i) |
| 2131 | { |
| 2132 | if (value[i] < 0 || value[i] >= max) |
| 2133 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2134 | context->validationError(GL_INVALID_VALUE, "sampler uniform value out of range"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2135 | return false; |
| 2136 | } |
| 2137 | } |
| 2138 | return true; |
| 2139 | } |
| 2140 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2141 | context->validationError(GL_INVALID_OPERATION, "wrong type of value for uniform"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2142 | return false; |
| 2143 | } |
| 2144 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2145 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2146 | { |
| 2147 | // Check that the value type is compatible with uniform type. |
| 2148 | if (valueType == uniformType) |
| 2149 | { |
| 2150 | return true; |
| 2151 | } |
| 2152 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2153 | context->validationError(GL_INVALID_OPERATION, "wrong type of value for uniform"); |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2154 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2155 | } |
| 2156 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2157 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2158 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2159 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2160 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2161 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2162 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2163 | } |
| 2164 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2165 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2166 | { |
| 2167 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2168 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2169 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2170 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2171 | } |
| 2172 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2173 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2174 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2175 | GLint location, |
| 2176 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2177 | GLboolean transpose) |
| 2178 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2179 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2180 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2181 | context->validationError(GL_INVALID_VALUE, kErrorES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2182 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2183 | } |
| 2184 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2185 | const LinkedUniform *uniform = nullptr; |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2186 | Program *programObject = context->getGLState().getLinkedProgram(context); |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2187 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2188 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2189 | } |
| 2190 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2191 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2192 | { |
| 2193 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2194 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2195 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2196 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2197 | } |
| 2198 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2199 | const Caps &caps = context->getCaps(); |
| 2200 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2201 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2202 | { |
| 2203 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2204 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2205 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2206 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2207 | context->validationError(GL_INVALID_OPERATION, kErrorIndexExceedsMaxDrawBuffer); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2208 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2209 | } |
| 2210 | } |
| 2211 | |
| 2212 | switch (pname) |
| 2213 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2214 | case GL_TEXTURE_BINDING_2D: |
| 2215 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2216 | case GL_TEXTURE_BINDING_3D: |
| 2217 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2218 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2219 | break; |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2220 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 2221 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2222 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2223 | context->validationError(GL_INVALID_ENUM, kErrorMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 2224 | return false; |
| 2225 | } |
| 2226 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2227 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2228 | if (!context->getExtensions().textureRectangle) |
| 2229 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2230 | context->validationError(GL_INVALID_ENUM, |
| 2231 | "ANGLE_texture_rectangle extension not present"); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2232 | return false; |
| 2233 | } |
| 2234 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2235 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2236 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2237 | !context->getExtensions().eglImageExternal) |
| 2238 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2239 | context->validationError(GL_INVALID_ENUM, |
| 2240 | "Neither NV_EGL_stream_consumer_external " |
| 2241 | "nor GL_OES_EGL_image_external " |
| 2242 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2243 | return false; |
| 2244 | } |
| 2245 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2246 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2247 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2248 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2249 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2250 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2251 | ASSERT(readFramebuffer); |
| 2252 | |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2253 | if (!ValidateFramebufferComplete<GL_INVALID_OPERATION>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2254 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2255 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2256 | } |
| 2257 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2258 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2259 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2260 | context->validationError(GL_INVALID_OPERATION, kErrorReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2261 | return false; |
| 2262 | } |
| 2263 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2264 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2265 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2266 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2267 | context->validationError(GL_INVALID_OPERATION, kErrorReadBufferNotAttached); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2268 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2269 | } |
| 2270 | } |
| 2271 | break; |
| 2272 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2273 | default: |
| 2274 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2278 | if (*numParams == 0) |
| 2279 | { |
| 2280 | return false; |
| 2281 | } |
| 2282 | |
| 2283 | return true; |
| 2284 | } |
| 2285 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2286 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2287 | GLenum pname, |
| 2288 | GLsizei bufSize, |
| 2289 | GLsizei *length, |
| 2290 | GLboolean *params) |
| 2291 | { |
| 2292 | GLenum nativeType; |
| 2293 | unsigned int numParams = 0; |
| 2294 | |
| 2295 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2296 | { |
| 2297 | return false; |
| 2298 | } |
| 2299 | |
| 2300 | SetRobustLengthParam(length, numParams); |
| 2301 | |
| 2302 | return true; |
| 2303 | } |
| 2304 | |
| 2305 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2306 | GLenum pname, |
| 2307 | GLsizei bufSize, |
| 2308 | GLsizei *length, |
| 2309 | GLfloat *params) |
| 2310 | { |
| 2311 | GLenum nativeType; |
| 2312 | unsigned int numParams = 0; |
| 2313 | |
| 2314 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2315 | { |
| 2316 | return false; |
| 2317 | } |
| 2318 | |
| 2319 | SetRobustLengthParam(length, numParams); |
| 2320 | |
| 2321 | return true; |
| 2322 | } |
| 2323 | |
| 2324 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2325 | GLenum pname, |
| 2326 | GLsizei bufSize, |
| 2327 | GLsizei *length, |
| 2328 | GLint *data) |
| 2329 | { |
| 2330 | GLenum nativeType; |
| 2331 | unsigned int numParams = 0; |
| 2332 | |
| 2333 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2334 | { |
| 2335 | return false; |
| 2336 | } |
| 2337 | |
| 2338 | SetRobustLengthParam(length, numParams); |
| 2339 | |
| 2340 | return true; |
| 2341 | } |
| 2342 | |
| 2343 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2344 | GLenum pname, |
| 2345 | GLsizei bufSize, |
| 2346 | GLsizei *length, |
| 2347 | GLint64 *data) |
| 2348 | { |
| 2349 | GLenum nativeType; |
| 2350 | unsigned int numParams = 0; |
| 2351 | |
| 2352 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2353 | { |
| 2354 | return false; |
| 2355 | } |
| 2356 | |
| 2357 | if (nativeType == GL_INT_64_ANGLEX) |
| 2358 | { |
| 2359 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2360 | return false; |
| 2361 | } |
| 2362 | |
| 2363 | SetRobustLengthParam(length, numParams); |
| 2364 | return true; |
| 2365 | } |
| 2366 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2367 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2368 | GLenum pname, |
| 2369 | GLsizei bufSize, |
| 2370 | GLenum *nativeType, |
| 2371 | unsigned int *numParams) |
| 2372 | { |
| 2373 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2374 | { |
| 2375 | return false; |
| 2376 | } |
| 2377 | |
| 2378 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2379 | { |
| 2380 | return false; |
| 2381 | } |
| 2382 | |
| 2383 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2384 | { |
| 2385 | return false; |
| 2386 | } |
| 2387 | |
| 2388 | return true; |
| 2389 | } |
| 2390 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2391 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2392 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2393 | GLint level, |
| 2394 | GLenum internalformat, |
| 2395 | bool isSubImage, |
| 2396 | GLint xoffset, |
| 2397 | GLint yoffset, |
| 2398 | GLint zoffset, |
| 2399 | GLint x, |
| 2400 | GLint y, |
| 2401 | GLsizei width, |
| 2402 | GLsizei height, |
| 2403 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2404 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2405 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2406 | TextureType texType = TextureTargetToType(target); |
| 2407 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2408 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2409 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2410 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2411 | return false; |
| 2412 | } |
| 2413 | |
| 2414 | if (width < 0 || height < 0) |
| 2415 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2416 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2417 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2418 | } |
| 2419 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2420 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2421 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2422 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2423 | context->validationError(GL_INVALID_VALUE, kErrorOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2424 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2425 | } |
| 2426 | |
| 2427 | if (border != 0) |
| 2428 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2429 | context->validationError(GL_INVALID_VALUE, kErrorInvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2430 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2431 | } |
| 2432 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2433 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2434 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2435 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2436 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2437 | } |
| 2438 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2439 | const State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2440 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2441 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2442 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2443 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2444 | } |
| 2445 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2446 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2447 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2448 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2449 | } |
| 2450 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2451 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2452 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2453 | context->validationError(GL_INVALID_OPERATION, kErrorReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2454 | return false; |
| 2455 | } |
| 2456 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2457 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2458 | // 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] | 2459 | // 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] | 2460 | // 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] | 2461 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2462 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2463 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2464 | context->validationError(GL_INVALID_OPERATION, kErrorMissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2465 | return false; |
| 2466 | } |
| 2467 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2468 | // ANGLE_multiview spec, Revision 1: |
| 2469 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2470 | // 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] | 2471 | // is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views in the current read |
| 2472 | // framebuffer is more than one. |
| 2473 | if (readFramebuffer->readDisallowedByMultiview()) |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2474 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2475 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, |
| 2476 | "The active read framebuffer object has multiview attachments."); |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2477 | return false; |
| 2478 | } |
| 2479 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2480 | const Caps &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2481 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2482 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2483 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2484 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2485 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2486 | maxDimension = caps.max2DTextureSize; |
| 2487 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2488 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2489 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2490 | maxDimension = caps.maxCubeMapTextureSize; |
| 2491 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2492 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2493 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2494 | maxDimension = caps.maxRectangleTextureSize; |
| 2495 | break; |
| 2496 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2497 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2498 | maxDimension = caps.max2DTextureSize; |
| 2499 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2500 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2501 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2502 | maxDimension = caps.max3DTextureSize; |
| 2503 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2504 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2505 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2506 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2507 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2508 | } |
| 2509 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2510 | Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2511 | if (!texture) |
| 2512 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2513 | context->validationError(GL_INVALID_OPERATION, kErrorTextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2514 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2517 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2518 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2519 | context->validationError(GL_INVALID_OPERATION, kErrorTextureIsImmutable); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2520 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2521 | } |
| 2522 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2523 | const InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2524 | isSubImage ? *texture->getFormat(target, level).info |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2525 | : GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2526 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2527 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2528 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2529 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidFormat); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2530 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2531 | } |
| 2532 | |
| 2533 | if (isSubImage) |
| 2534 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2535 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2536 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2537 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2538 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2539 | context->validationError(GL_INVALID_VALUE, kErrorOffsetOverflow); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2540 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2541 | } |
| 2542 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2543 | else |
| 2544 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2545 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2546 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2547 | context->validationError(GL_INVALID_VALUE, kErrorCubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2548 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2549 | } |
| 2550 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2551 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2552 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2553 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2554 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
| 2557 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2558 | if (static_cast<int>(width) > maxLevelDimension || |
| 2559 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2560 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2561 | context->validationError(GL_INVALID_VALUE, kErrorResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2562 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2563 | } |
| 2564 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2565 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2566 | if (textureFormatOut) |
| 2567 | { |
| 2568 | *textureFormatOut = texture->getFormat(target, level); |
| 2569 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2570 | |
| 2571 | // Detect texture copying feedback loops for WebGL. |
| 2572 | if (context->getExtensions().webglCompatibility) |
| 2573 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2574 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2575 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2576 | context->validationError(GL_INVALID_OPERATION, kErrorFeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2577 | return false; |
| 2578 | } |
| 2579 | } |
| 2580 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2581 | return true; |
| 2582 | } |
| 2583 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2584 | // Note all errors returned from this function are INVALID_OPERATION except for the draw framebuffer |
| 2585 | // completeness check. |
| 2586 | const char *ValidateDrawStates(Context *context) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2587 | { |
| 2588 | const Extensions &extensions = context->getExtensions(); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2589 | const State &state = context->getGLState(); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2590 | |
| 2591 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2592 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2593 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2594 | VertexArray *vertexArray = state.getVertexArray(); |
| 2595 | ASSERT(vertexArray); |
| 2596 | |
| 2597 | if (!extensions.webglCompatibility && vertexArray->hasMappedEnabledArrayBuffer()) |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2598 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2599 | return kErrorBufferMapped; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2603 | // Section 6.10 of the WebGL 1.0 spec. |
| 2604 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Jamie Madill | d84b673 | 2018-09-06 15:54:35 -0400 | [diff] [blame] | 2605 | ASSERT(framebuffer); |
| 2606 | |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2607 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
| 2608 | { |
| 2609 | ASSERT(framebuffer); |
| 2610 | const FramebufferAttachment *dsAttachment = |
| 2611 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2612 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2613 | ASSERT(stencilBits <= 8); |
| 2614 | |
| 2615 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
| 2616 | if (depthStencilState.stencilTest && stencilBits > 0) |
| 2617 | { |
| 2618 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2619 | |
| 2620 | bool differentRefs = |
| 2621 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2622 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2623 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2624 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2625 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2626 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2627 | |
| 2628 | if (differentRefs || differentWritemasks || differentMasks) |
| 2629 | { |
| 2630 | if (!extensions.webglCompatibility) |
| 2631 | { |
| 2632 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2633 | "stencil writemasks, reference values, or stencil mask values."; |
| 2634 | } |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2635 | return kErrorStencilReferenceMaskOrMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2636 | } |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | if (!framebuffer->isComplete(context)) |
| 2641 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2642 | // Note: this error should be generated as INVALID_FRAMEBUFFER_OPERATION. |
| 2643 | return kErrorDrawFramebufferIncomplete; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2644 | } |
| 2645 | |
| 2646 | if (context->getStateCache().hasAnyEnabledClientAttrib()) |
| 2647 | { |
| 2648 | if (context->getExtensions().webglCompatibility || !state.areClientArraysEnabled()) |
| 2649 | { |
| 2650 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 2651 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 2652 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 2653 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2654 | return kErrorVertexArrayNoBuffer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2655 | } |
| 2656 | |
| 2657 | if (state.getVertexArray()->hasEnabledNullPointerClientArray()) |
| 2658 | { |
| 2659 | // This is an application error that would normally result in a crash, but we catch it |
| 2660 | // and return an error |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2661 | return kErrorVertexArrayNoBufferPointer; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2662 | } |
| 2663 | } |
| 2664 | |
| 2665 | // If we are running GLES1, there is no current program. |
| 2666 | if (context->getClientVersion() >= Version(2, 0)) |
| 2667 | { |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2668 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2669 | if (!program) |
| 2670 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2671 | return kErrorProgramNotBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2672 | } |
| 2673 | |
| 2674 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2675 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2676 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2677 | // produce undefined result. |
| 2678 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2679 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
| 2680 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2681 | return kErrorNoActiveGraphicsShaderStage; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | if (!program->validateSamplers(nullptr, context->getCaps())) |
| 2685 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2686 | return kErrorTextureTypeConflict; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2687 | } |
| 2688 | |
| 2689 | if (extensions.multiview) |
| 2690 | { |
| 2691 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2692 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2693 | if (framebufferNumViews != programNumViews) |
| 2694 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2695 | return kErrorMultiviewMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2696 | } |
| 2697 | |
| 2698 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2699 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2700 | framebufferNumViews > 1) |
| 2701 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2702 | return kErrorMultiviewTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2706 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2707 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2708 | return kErrorMultiviewTimerQuery; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | // Uniform buffer validation |
| 2713 | for (unsigned int uniformBlockIndex = 0; |
| 2714 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
| 2715 | { |
| 2716 | const InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2717 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2718 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2719 | state.getIndexedUniformBuffer(blockBinding); |
| 2720 | |
| 2721 | if (uniformBuffer.get() == nullptr) |
| 2722 | { |
| 2723 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2724 | return kErrorUniformBufferUnbound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2725 | } |
| 2726 | |
| 2727 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2728 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2729 | { |
| 2730 | // undefined behaviour |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2731 | return kErrorUniformBufferTooSmall; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2732 | } |
| 2733 | |
| 2734 | if (extensions.webglCompatibility && |
| 2735 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2736 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2737 | return kErrorUniformBufferBoundForTransformFeedback; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | // Do some additonal WebGL-specific validation |
| 2742 | if (extensions.webglCompatibility) |
| 2743 | { |
| 2744 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2745 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2746 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2747 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2748 | return kErrorTransformFeedbackBufferDoubleBound; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2749 | } |
| 2750 | |
| 2751 | // Detect rendering feedback loops for WebGL. |
| 2752 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2753 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2754 | return kErrorFeedbackLoop; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | // Detect that the vertex shader input types match the attribute types |
| 2758 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2759 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2760 | return kErrorVertexShaderTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2761 | } |
| 2762 | |
| 2763 | // Detect that the color buffer types match the fragment shader output types |
| 2764 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2765 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2766 | return kErrorDrawBufferTypeMismatch; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2767 | } |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2768 | |
| 2769 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 2770 | if (vao->hasTransformFeedbackBindingConflict(context)) |
| 2771 | { |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2772 | return kErrorVertexBufferBoundForTransformFeedback; |
Jamie Madill | 03cb526 | 2018-08-08 15:49:24 -0400 | [diff] [blame] | 2773 | } |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2774 | } |
| 2775 | } |
| 2776 | |
Jamie Madill | b42162f | 2018-08-20 12:58:37 -0400 | [diff] [blame] | 2777 | return nullptr; |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2778 | } |
| 2779 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2780 | bool ValidateDrawMode(Context *context, PrimitiveMode mode) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2781 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2782 | const Extensions &extensions = context->getExtensions(); |
| 2783 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2784 | switch (mode) |
| 2785 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2786 | case PrimitiveMode::Points: |
| 2787 | case PrimitiveMode::Lines: |
| 2788 | case PrimitiveMode::LineLoop: |
| 2789 | case PrimitiveMode::LineStrip: |
| 2790 | case PrimitiveMode::Triangles: |
| 2791 | case PrimitiveMode::TriangleStrip: |
| 2792 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2793 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2794 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2795 | case PrimitiveMode::LinesAdjacency: |
| 2796 | case PrimitiveMode::LineStripAdjacency: |
| 2797 | case PrimitiveMode::TrianglesAdjacency: |
| 2798 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2799 | if (!extensions.geometryShader) |
| 2800 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2801 | context->validationError(GL_INVALID_ENUM, kErrorGeometryShaderExtensionNotEnabled); |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2802 | return false; |
| 2803 | } |
| 2804 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2805 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2806 | context->validationError(GL_INVALID_ENUM, kErrorInvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2807 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2808 | } |
| 2809 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2810 | // If we are running GLES1, there is no current program. |
| 2811 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2812 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2813 | const State &state = context->getGLState(); |
| 2814 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2815 | Program *program = state.getLinkedProgram(context); |
Jamie Madill | e7d80f3 | 2018-08-08 15:49:23 -0400 | [diff] [blame] | 2816 | ASSERT(program); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2817 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2818 | // Do geometry shader specific validations |
| 2819 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2820 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2821 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2822 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2823 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2824 | context->validationError(GL_INVALID_OPERATION, |
| 2825 | kErrorIncompatibleDrawModeAgainstGeometryShader); |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2826 | return false; |
| 2827 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2828 | } |
| 2829 | } |
| 2830 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2831 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2832 | } |
| 2833 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2834 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
| 2835 | { |
| 2836 | if (!context->getStateCache().isValidDrawMode(mode)) |
| 2837 | { |
| 2838 | return ValidateDrawMode(context, mode); |
| 2839 | } |
| 2840 | |
| 2841 | if (count < 0) |
| 2842 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2843 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2844 | return false; |
| 2845 | } |
| 2846 | |
| 2847 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2848 | if (drawStatesError) |
| 2849 | { |
| 2850 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2851 | |
| 2852 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2853 | // Incomplete. |
| 2854 | GLenum errorCode = |
| 2855 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2856 | : GL_INVALID_OPERATION); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2857 | context->validationError(errorCode, errorMessage); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2858 | return false; |
| 2859 | } |
| 2860 | |
| 2861 | return true; |
| 2862 | } |
| 2863 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2864 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2865 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2866 | GLint first, |
| 2867 | GLsizei count, |
| 2868 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2869 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2870 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2871 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2872 | context->validationError(GL_INVALID_VALUE, kErrorNegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2873 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2874 | } |
| 2875 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2876 | if (count < 0) |
| 2877 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2878 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2879 | return false; |
| 2880 | } |
| 2881 | |
Jamie Madill | 7f23293 | 2018-09-12 11:03:06 -0400 | [diff] [blame] | 2882 | const State &state = context->getGLState(); |
| 2883 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2884 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2885 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2886 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2887 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2888 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2889 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2890 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidDrawModeTransformFeedback); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2891 | return false; |
| 2892 | } |
| 2893 | |
| 2894 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2895 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2896 | context->validationError(GL_INVALID_OPERATION, kErrorTransformFeedbackBufferTooSmall); |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2897 | return false; |
| 2898 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2899 | } |
| 2900 | |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2901 | if (!context->getStateCache().isValidDrawMode(mode)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2902 | { |
Jamie Madill | 16e28fd | 2018-09-12 11:03:05 -0400 | [diff] [blame] | 2903 | return ValidateDrawMode(context, mode); |
| 2904 | } |
| 2905 | |
| 2906 | intptr_t drawStatesError = context->getStateCache().getBasicDrawStatesError(context); |
| 2907 | if (drawStatesError) |
| 2908 | { |
| 2909 | const char *errorMessage = reinterpret_cast<const char *>(drawStatesError); |
| 2910 | |
| 2911 | // All errors from ValidateDrawStates should return INVALID_OPERATION except Framebuffer |
| 2912 | // Incomplete. |
| 2913 | GLenum errorCode = |
| 2914 | (errorMessage == kErrorDrawFramebufferIncomplete ? GL_INVALID_FRAMEBUFFER_OPERATION |
| 2915 | : GL_INVALID_OPERATION); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2916 | context->validationError(errorCode, errorMessage); |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2917 | return false; |
| 2918 | } |
| 2919 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2920 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2921 | // - first < 0 has been checked as an error condition. |
| 2922 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2923 | // 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] | 2924 | ASSERT(first >= 0); |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2925 | if (count > 0 && primcount > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2926 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2927 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2928 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2929 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2930 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2931 | return false; |
| 2932 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2933 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 2934 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex))) |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2935 | { |
| 2936 | return false; |
| 2937 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2938 | } |
| 2939 | |
| 2940 | return true; |
| 2941 | } |
| 2942 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2943 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2944 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2945 | GLint first, |
| 2946 | GLsizei count, |
| 2947 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2948 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2949 | if (!context->getExtensions().instancedArrays) |
| 2950 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2951 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2952 | return false; |
| 2953 | } |
| 2954 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2955 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2956 | { |
| 2957 | return false; |
| 2958 | } |
| 2959 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2960 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2961 | } |
| 2962 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2963 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2964 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2965 | switch (type) |
| 2966 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2967 | case GL_UNSIGNED_BYTE: |
| 2968 | case GL_UNSIGNED_SHORT: |
| 2969 | break; |
| 2970 | case GL_UNSIGNED_INT: |
| 2971 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2972 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2973 | context->validationError(GL_INVALID_ENUM, kErrorTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2974 | return false; |
| 2975 | } |
| 2976 | break; |
| 2977 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2978 | context->validationError(GL_INVALID_ENUM, kErrorTypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2979 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2980 | } |
| 2981 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2982 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2983 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 2984 | TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2985 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2986 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2987 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2988 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2989 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2990 | if (context->getExtensions().geometryShader) |
| 2991 | { |
| 2992 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2993 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2994 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 2995 | context->validationError(GL_INVALID_OPERATION, |
| 2996 | kErrorInvalidDrawModeTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2997 | return false; |
| 2998 | } |
| 2999 | } |
| 3000 | else |
| 3001 | { |
| 3002 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 3003 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 3004 | // 86) |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3005 | context->validationError(GL_INVALID_OPERATION, |
| 3006 | kErrorUnsupportedDrawModeForTransformFeedback); |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3007 | return false; |
| 3008 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3009 | } |
| 3010 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3011 | return true; |
| 3012 | } |
| 3013 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3014 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3015 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3016 | GLsizei count, |
| 3017 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3018 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3019 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3020 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3021 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3022 | return false; |
| 3023 | |
| 3024 | const State &state = context->getGLState(); |
| 3025 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3026 | if (!ValidateDrawBase(context, mode, count)) |
| 3027 | { |
| 3028 | return false; |
| 3029 | } |
| 3030 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3031 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 3032 | Buffer *elementArrayBuffer = vao->getElementArrayBuffer(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3033 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3034 | GLuint typeBytes = GetTypeInfo(type).bytes; |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3035 | |
| 3036 | if (context->getExtensions().webglCompatibility) |
| 3037 | { |
| 3038 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3039 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3040 | { |
| 3041 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3042 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3043 | // data type passed to the call, or an INVALID_OPERATION error is generated. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3044 | context->validationError(GL_INVALID_OPERATION, kErrorOffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3045 | return false; |
| 3046 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3047 | |
| 3048 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3049 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3050 | // error is generated. |
| 3051 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3052 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3053 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3054 | return false; |
| 3055 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3056 | } |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3057 | else if (elementArrayBuffer && elementArrayBuffer->isMapped()) |
| 3058 | { |
| 3059 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, |
| 3060 | // FlushMappedBufferRange, and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3061 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3062 | context->validationError(GL_INVALID_OPERATION, "Index buffer is mapped."); |
Jamie Madill | cc73f24 | 2018-08-01 11:34:48 -0400 | [diff] [blame] | 3063 | return false; |
| 3064 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3065 | |
| 3066 | if (context->getExtensions().webglCompatibility || |
| 3067 | !context->getGLState().areClientArraysEnabled()) |
| 3068 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3069 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3070 | { |
| 3071 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3072 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3073 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3074 | context->validationError(GL_INVALID_OPERATION, kErrorMustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3075 | return false; |
| 3076 | } |
| 3077 | } |
| 3078 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3079 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3080 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3081 | // This is an application error that would normally result in a crash, but we catch it and |
| 3082 | // return an error |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3083 | context->validationError(GL_INVALID_OPERATION, "No element array buffer and no pointer."); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3084 | return false; |
| 3085 | } |
| 3086 | |
| 3087 | if (count > 0 && elementArrayBuffer) |
| 3088 | { |
| 3089 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3090 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3091 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3092 | constexpr uint64_t kMaxTypeSize = 8; |
| 3093 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3094 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3095 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3096 | |
| 3097 | uint64_t typeSize = typeBytes; |
| 3098 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3099 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3100 | |
| 3101 | // Doing the multiplication here is overflow-safe |
| 3102 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3103 | |
| 3104 | // The offset can be any value, check for overflows |
| 3105 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3106 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3107 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3108 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3109 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3110 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3111 | |
| 3112 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3113 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3114 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3115 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3116 | return false; |
| 3117 | } |
| 3118 | |
| 3119 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3120 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3121 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3122 | context->validationError(GL_INVALID_OPERATION, kErrorMismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3123 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3124 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3125 | |
| 3126 | if (context->getExtensions().webglCompatibility && |
| 3127 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3128 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3129 | context->validationError(GL_INVALID_OPERATION, |
| 3130 | kErrorElementArrayBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3131 | return false; |
| 3132 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3133 | } |
| 3134 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3135 | if (!context->getExtensions().robustBufferAccessBehavior && count > 0 && primcount > 0) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3136 | { |
| 3137 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 3138 | IndexRange indexRange; |
| 3139 | ANGLE_VALIDATION_TRY(vao->getIndexRange(context, type, count, indices, &indexRange)); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3140 | |
| 3141 | // If we use an index greater than our maximum supported index range, return an error. |
| 3142 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3143 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3144 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3145 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3146 | context->validationError(GL_INVALID_OPERATION, kErrorExceedsMaxElement); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3147 | return false; |
| 3148 | } |
| 3149 | |
Jamie Madill | 2da5356 | 2018-08-01 11:34:47 -0400 | [diff] [blame] | 3150 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3151 | { |
| 3152 | return false; |
| 3153 | } |
| 3154 | |
| 3155 | // 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] | 3156 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3159 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3160 | } |
| 3161 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3162 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3163 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3164 | GLsizei count, |
| 3165 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3166 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3167 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3168 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3169 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3170 | } |
| 3171 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3172 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3173 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3174 | GLsizei count, |
| 3175 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3176 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3177 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3178 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3179 | if (!context->getExtensions().instancedArrays) |
| 3180 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3181 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3182 | return false; |
| 3183 | } |
| 3184 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3185 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3186 | { |
| 3187 | return false; |
| 3188 | } |
| 3189 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3190 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3191 | } |
| 3192 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3193 | bool ValidateFramebufferTextureBase(Context *context, |
| 3194 | GLenum target, |
| 3195 | GLenum attachment, |
| 3196 | GLuint texture, |
| 3197 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3198 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3199 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3200 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3201 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3202 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3203 | } |
| 3204 | |
| 3205 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3206 | { |
| 3207 | return false; |
| 3208 | } |
| 3209 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3210 | if (texture != 0) |
| 3211 | { |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3212 | Texture *tex = context->getTexture(texture); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3213 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3214 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3215 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3216 | context->validationError(GL_INVALID_OPERATION, kErrorMissingTexture); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3217 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | if (level < 0) |
| 3221 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3222 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3223 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3224 | } |
| 3225 | } |
| 3226 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3227 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3228 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3229 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3230 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3231 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3232 | context->validationError(GL_INVALID_OPERATION, kErrorDefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3233 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | return true; |
| 3237 | } |
| 3238 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3239 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3240 | { |
| 3241 | if (program == 0) |
| 3242 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3243 | context->validationError(GL_INVALID_VALUE, kErrorProgramDoesNotExist); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3244 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3245 | } |
| 3246 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 3247 | Program *programObject = GetValidProgram(context, program); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3248 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3249 | { |
| 3250 | return false; |
| 3251 | } |
| 3252 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3253 | if (!programObject || !programObject->isLinked()) |
| 3254 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3255 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3256 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3257 | } |
| 3258 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3259 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3260 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3261 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidUniformLocation); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3262 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3263 | } |
| 3264 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3265 | return true; |
| 3266 | } |
| 3267 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3268 | static bool ValidateSizedGetUniform(Context *context, |
| 3269 | GLuint program, |
| 3270 | GLint location, |
| 3271 | GLsizei bufSize, |
| 3272 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3273 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3274 | if (length) |
| 3275 | { |
| 3276 | *length = 0; |
| 3277 | } |
| 3278 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3279 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3280 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3281 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3282 | } |
| 3283 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3284 | if (bufSize < 0) |
| 3285 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3286 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3287 | return false; |
| 3288 | } |
| 3289 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 3290 | Program *programObject = context->getProgramResolveLink(program); |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3291 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3292 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3293 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3294 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3295 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3296 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3297 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3298 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3299 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3300 | } |
| 3301 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3302 | if (length) |
| 3303 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3304 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3305 | } |
| 3306 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3307 | return true; |
| 3308 | } |
| 3309 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3310 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3311 | GLuint program, |
| 3312 | GLint location, |
| 3313 | GLsizei bufSize, |
| 3314 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3315 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3316 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3317 | } |
| 3318 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3319 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3320 | GLuint program, |
| 3321 | GLint location, |
| 3322 | GLsizei bufSize, |
| 3323 | GLsizei *length, |
| 3324 | GLfloat *params) |
| 3325 | { |
| 3326 | UNIMPLEMENTED(); |
| 3327 | return false; |
| 3328 | } |
| 3329 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3330 | bool ValidateGetnUniformivEXT(Context *context, |
| 3331 | GLuint program, |
| 3332 | GLint location, |
| 3333 | GLsizei bufSize, |
| 3334 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3335 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3336 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3337 | } |
| 3338 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3339 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3340 | GLuint program, |
| 3341 | GLint location, |
| 3342 | GLsizei bufSize, |
| 3343 | GLsizei *length, |
| 3344 | GLint *params) |
| 3345 | { |
| 3346 | UNIMPLEMENTED(); |
| 3347 | return false; |
| 3348 | } |
| 3349 | |
| 3350 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3351 | GLuint program, |
| 3352 | GLint location, |
| 3353 | GLsizei bufSize, |
| 3354 | GLsizei *length, |
| 3355 | GLuint *params) |
| 3356 | { |
| 3357 | UNIMPLEMENTED(); |
| 3358 | return false; |
| 3359 | } |
| 3360 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3361 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3362 | GLuint program, |
| 3363 | GLint location, |
| 3364 | GLsizei bufSize, |
| 3365 | GLsizei *length, |
| 3366 | GLfloat *params) |
| 3367 | { |
| 3368 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3369 | { |
| 3370 | return false; |
| 3371 | } |
| 3372 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3373 | GLsizei writeLength = 0; |
| 3374 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3375 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3376 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3377 | { |
| 3378 | return false; |
| 3379 | } |
| 3380 | |
| 3381 | SetRobustLengthParam(length, writeLength); |
| 3382 | |
| 3383 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3384 | } |
| 3385 | |
| 3386 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3387 | GLuint program, |
| 3388 | GLint location, |
| 3389 | GLsizei bufSize, |
| 3390 | GLsizei *length, |
| 3391 | GLint *params) |
| 3392 | { |
| 3393 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3394 | { |
| 3395 | return false; |
| 3396 | } |
| 3397 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3398 | GLsizei writeLength = 0; |
| 3399 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3400 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3401 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3402 | { |
| 3403 | return false; |
| 3404 | } |
| 3405 | |
| 3406 | SetRobustLengthParam(length, writeLength); |
| 3407 | |
| 3408 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3409 | } |
| 3410 | |
| 3411 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3412 | GLuint program, |
| 3413 | GLint location, |
| 3414 | GLsizei bufSize, |
| 3415 | GLsizei *length, |
| 3416 | GLuint *params) |
| 3417 | { |
| 3418 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3419 | { |
| 3420 | return false; |
| 3421 | } |
| 3422 | |
| 3423 | if (context->getClientMajorVersion() < 3) |
| 3424 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3425 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3426 | return false; |
| 3427 | } |
| 3428 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3429 | GLsizei writeLength = 0; |
| 3430 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3431 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3432 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3433 | { |
| 3434 | return false; |
| 3435 | } |
| 3436 | |
| 3437 | SetRobustLengthParam(length, writeLength); |
| 3438 | |
| 3439 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3440 | } |
| 3441 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3442 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3443 | GLenum target, |
| 3444 | GLsizei numAttachments, |
| 3445 | const GLenum *attachments, |
| 3446 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3447 | { |
| 3448 | if (numAttachments < 0) |
| 3449 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3450 | context->validationError(GL_INVALID_VALUE, kErrorNegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3451 | return false; |
| 3452 | } |
| 3453 | |
| 3454 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3455 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3456 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3457 | { |
| 3458 | if (defaultFramebuffer) |
| 3459 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3460 | context->validationError(GL_INVALID_ENUM, |
| 3461 | kErrorDefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3462 | return false; |
| 3463 | } |
| 3464 | |
| 3465 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3466 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3467 | context->validationError(GL_INVALID_OPERATION, |
| 3468 | "Requested color attachment is " |
| 3469 | "greater than the maximum supported " |
| 3470 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3471 | return false; |
| 3472 | } |
| 3473 | } |
| 3474 | else |
| 3475 | { |
| 3476 | switch (attachments[i]) |
| 3477 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3478 | case GL_DEPTH_ATTACHMENT: |
| 3479 | case GL_STENCIL_ATTACHMENT: |
| 3480 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3481 | if (defaultFramebuffer) |
| 3482 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3483 | context->validationError(GL_INVALID_ENUM, |
| 3484 | kErrorDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3485 | return false; |
| 3486 | } |
| 3487 | break; |
| 3488 | case GL_COLOR: |
| 3489 | case GL_DEPTH: |
| 3490 | case GL_STENCIL: |
| 3491 | if (!defaultFramebuffer) |
| 3492 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3493 | context->validationError(GL_INVALID_ENUM, |
| 3494 | kErrorDefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3495 | return false; |
| 3496 | } |
| 3497 | break; |
| 3498 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3499 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3500 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3501 | } |
| 3502 | } |
| 3503 | } |
| 3504 | |
| 3505 | return true; |
| 3506 | } |
| 3507 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3508 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3509 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3510 | if (!context->getExtensions().debugMarker) |
| 3511 | { |
| 3512 | // The debug marker calls should not set error state |
| 3513 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3514 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3515 | return false; |
| 3516 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3517 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3518 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3519 | if (length < 0) |
| 3520 | { |
| 3521 | return false; |
| 3522 | } |
| 3523 | |
| 3524 | if (marker == nullptr) |
| 3525 | { |
| 3526 | return false; |
| 3527 | } |
| 3528 | |
| 3529 | return true; |
| 3530 | } |
| 3531 | |
| 3532 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3533 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3534 | if (!context->getExtensions().debugMarker) |
| 3535 | { |
| 3536 | // The debug marker calls should not set error state |
| 3537 | // However, it seems reasonable to set an error state if the extension is not enabled |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3538 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3539 | return false; |
| 3540 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3541 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3542 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3543 | if (length < 0) |
| 3544 | { |
| 3545 | return false; |
| 3546 | } |
| 3547 | |
| 3548 | if (length > 0 && marker == nullptr) |
| 3549 | { |
| 3550 | return false; |
| 3551 | } |
| 3552 | |
| 3553 | return true; |
| 3554 | } |
| 3555 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3556 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3557 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3558 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3559 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3560 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3561 | return false; |
| 3562 | } |
| 3563 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3564 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3565 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3566 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3567 | if (!context->getExtensions().eglImage) |
| 3568 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3569 | context->validationError(GL_INVALID_ENUM, |
| 3570 | "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3571 | } |
| 3572 | break; |
| 3573 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3574 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3575 | if (!context->getExtensions().eglImageExternal) |
| 3576 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3577 | context->validationError(GL_INVALID_ENUM, |
| 3578 | "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3579 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3580 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3581 | break; |
| 3582 | |
| 3583 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3584 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3585 | return false; |
| 3586 | } |
| 3587 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3588 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3589 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3590 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3591 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3592 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3593 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3594 | return false; |
| 3595 | } |
| 3596 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3597 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3598 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3599 | context->validationError(GL_INVALID_OPERATION, |
| 3600 | "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3601 | return false; |
| 3602 | } |
| 3603 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3604 | if (!imageObject->isTexturable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3605 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3606 | context->validationError(GL_INVALID_OPERATION, |
| 3607 | "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3608 | return false; |
| 3609 | } |
| 3610 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3611 | return true; |
| 3612 | } |
| 3613 | |
| 3614 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3615 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3616 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3617 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3618 | if (!context->getExtensions().eglImage) |
| 3619 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3620 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3621 | return false; |
| 3622 | } |
| 3623 | |
| 3624 | switch (target) |
| 3625 | { |
| 3626 | case GL_RENDERBUFFER: |
| 3627 | break; |
| 3628 | |
| 3629 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3630 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3631 | return false; |
| 3632 | } |
| 3633 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3634 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3635 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3636 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3637 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3638 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3639 | context->validationError(GL_INVALID_VALUE, "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3640 | return false; |
| 3641 | } |
| 3642 | |
Yuly Novikov | 2eb5407 | 2018-08-22 16:41:26 -0400 | [diff] [blame] | 3643 | if (!imageObject->isRenderable(context)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3644 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3645 | context->validationError(GL_INVALID_OPERATION, |
| 3646 | "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3647 | return false; |
| 3648 | } |
| 3649 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3650 | return true; |
| 3651 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3652 | |
| 3653 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3654 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3655 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3656 | { |
| 3657 | // The default VAO should always exist |
| 3658 | ASSERT(array != 0); |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3659 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidVertexArray); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3660 | return false; |
| 3661 | } |
| 3662 | |
| 3663 | return true; |
| 3664 | } |
| 3665 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3666 | bool ValidateProgramBinaryBase(Context *context, |
| 3667 | GLuint program, |
| 3668 | GLenum binaryFormat, |
| 3669 | const void *binary, |
| 3670 | GLint length) |
| 3671 | { |
| 3672 | Program *programObject = GetValidProgram(context, program); |
| 3673 | if (programObject == nullptr) |
| 3674 | { |
| 3675 | return false; |
| 3676 | } |
| 3677 | |
| 3678 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3679 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3680 | programBinaryFormats.end()) |
| 3681 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3682 | context->validationError(GL_INVALID_ENUM, "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3683 | return false; |
| 3684 | } |
| 3685 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3686 | if (context->hasActiveTransformFeedback(program)) |
| 3687 | { |
| 3688 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3689 | context->validationError(GL_INVALID_OPERATION, |
| 3690 | "Cannot change program binary while program " |
| 3691 | "is associated with an active transform " |
| 3692 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3693 | return false; |
| 3694 | } |
| 3695 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3696 | return true; |
| 3697 | } |
| 3698 | |
| 3699 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3700 | GLuint program, |
| 3701 | GLsizei bufSize, |
| 3702 | GLsizei *length, |
| 3703 | GLenum *binaryFormat, |
| 3704 | void *binary) |
| 3705 | { |
| 3706 | Program *programObject = GetValidProgram(context, program); |
| 3707 | if (programObject == nullptr) |
| 3708 | { |
| 3709 | return false; |
| 3710 | } |
| 3711 | |
| 3712 | if (!programObject->isLinked()) |
| 3713 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3714 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3715 | return false; |
| 3716 | } |
| 3717 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3718 | if (context->getCaps().programBinaryFormats.empty()) |
| 3719 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3720 | context->validationError(GL_INVALID_OPERATION, "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3721 | return false; |
| 3722 | } |
| 3723 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3724 | return true; |
| 3725 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3726 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3727 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3728 | { |
| 3729 | // 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] | 3730 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3731 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3732 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3733 | return false; |
| 3734 | } |
| 3735 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3736 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3737 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3738 | return false; |
| 3739 | } |
| 3740 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3741 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3742 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3743 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3744 | |
| 3745 | // This should come first before the check for the default frame buffer |
| 3746 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3747 | // rather than INVALID_OPERATION |
| 3748 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3749 | { |
| 3750 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3751 | |
| 3752 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3753 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3754 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3755 | { |
| 3756 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3757 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3758 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3759 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3760 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3761 | context->validationError(GL_INVALID_ENUM, "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3762 | return false; |
| 3763 | } |
| 3764 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3765 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3766 | context->validationError(GL_INVALID_OPERATION, |
| 3767 | "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3768 | return false; |
| 3769 | } |
| 3770 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3771 | frameBufferId != 0) |
| 3772 | { |
| 3773 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3774 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3775 | context->validationError(GL_INVALID_OPERATION, |
| 3776 | "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3777 | return false; |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3782 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3783 | if (frameBufferId == 0) |
| 3784 | { |
| 3785 | if (n != 1) |
| 3786 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3787 | context->validationError(GL_INVALID_OPERATION, |
| 3788 | "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3789 | return false; |
| 3790 | } |
| 3791 | |
| 3792 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3793 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3794 | context->validationError( |
| 3795 | GL_INVALID_OPERATION, |
| 3796 | "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] | 3797 | return false; |
| 3798 | } |
| 3799 | } |
| 3800 | |
| 3801 | return true; |
| 3802 | } |
| 3803 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3804 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3805 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3806 | GLenum pname, |
| 3807 | GLsizei *length, |
| 3808 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3809 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3810 | if (length) |
| 3811 | { |
| 3812 | *length = 0; |
| 3813 | } |
| 3814 | |
| 3815 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3816 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3817 | context->validationError( |
| 3818 | GL_INVALID_OPERATION, |
| 3819 | "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] | 3820 | return false; |
| 3821 | } |
| 3822 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3823 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3824 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3825 | context->validationError(GL_INVALID_ENUM, "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3826 | return false; |
| 3827 | } |
| 3828 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3829 | switch (pname) |
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 | case GL_BUFFER_MAP_POINTER: |
| 3832 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3833 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3834 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3835 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3836 | return false; |
| 3837 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3838 | |
| 3839 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3840 | // target bound to zero generate an INVALID_OPERATION error." |
| 3841 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3842 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3843 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3844 | context->validationError(GL_INVALID_OPERATION, |
| 3845 | "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3846 | return false; |
| 3847 | } |
| 3848 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3849 | if (length) |
| 3850 | { |
| 3851 | *length = 1; |
| 3852 | } |
| 3853 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3854 | return true; |
| 3855 | } |
| 3856 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3857 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3858 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3859 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3860 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3861 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3862 | return false; |
| 3863 | } |
| 3864 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3865 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3866 | |
| 3867 | if (buffer == nullptr || !buffer->isMapped()) |
| 3868 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3869 | context->validationError(GL_INVALID_OPERATION, "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3870 | return false; |
| 3871 | } |
| 3872 | |
| 3873 | return true; |
| 3874 | } |
| 3875 | |
| 3876 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3877 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3878 | GLintptr offset, |
| 3879 | GLsizeiptr length, |
| 3880 | GLbitfield access) |
| 3881 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3882 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3883 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3884 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3885 | return false; |
| 3886 | } |
| 3887 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3888 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3889 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3890 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3891 | return false; |
| 3892 | } |
| 3893 | |
| 3894 | if (length < 0) |
| 3895 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3896 | context->validationError(GL_INVALID_VALUE, kErrorNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3897 | return false; |
| 3898 | } |
| 3899 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3900 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3901 | |
| 3902 | if (!buffer) |
| 3903 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3904 | context->validationError(GL_INVALID_OPERATION, "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3905 | return false; |
| 3906 | } |
| 3907 | |
| 3908 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3909 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3910 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3911 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3912 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3913 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3914 | context->validationError(GL_INVALID_VALUE, |
| 3915 | "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3916 | return false; |
| 3917 | } |
| 3918 | |
| 3919 | // Check for invalid bits in the mask |
| 3920 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3921 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3922 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3923 | |
| 3924 | if (access & ~(allAccessBits)) |
| 3925 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3926 | context->validationError(GL_INVALID_VALUE, "Invalid access bits"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3927 | return false; |
| 3928 | } |
| 3929 | |
| 3930 | if (length == 0) |
| 3931 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3932 | context->validationError(GL_INVALID_OPERATION, "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3933 | return false; |
| 3934 | } |
| 3935 | |
| 3936 | if (buffer->isMapped()) |
| 3937 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3938 | context->validationError(GL_INVALID_OPERATION, "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3939 | return false; |
| 3940 | } |
| 3941 | |
| 3942 | // Check for invalid bit combinations |
| 3943 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3944 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3945 | context->validationError(GL_INVALID_OPERATION, |
| 3946 | "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3947 | return false; |
| 3948 | } |
| 3949 | |
| 3950 | GLbitfield writeOnlyBits = |
| 3951 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3952 | |
| 3953 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3954 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3955 | context->validationError(GL_INVALID_OPERATION, |
| 3956 | "Invalid access bits when mapping buffer for reading"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3957 | return false; |
| 3958 | } |
| 3959 | |
| 3960 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3961 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3962 | context->validationError( |
| 3963 | GL_INVALID_OPERATION, |
| 3964 | "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] | 3965 | return false; |
| 3966 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3967 | |
| 3968 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3972 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3973 | GLintptr offset, |
| 3974 | GLsizeiptr length) |
| 3975 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3976 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3977 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3978 | context->validationError(GL_INVALID_VALUE, kErrorNegativeOffset); |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3979 | return false; |
| 3980 | } |
| 3981 | |
| 3982 | if (length < 0) |
| 3983 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3984 | context->validationError(GL_INVALID_VALUE, kErrorNegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3985 | return false; |
| 3986 | } |
| 3987 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3988 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3989 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3990 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3991 | return false; |
| 3992 | } |
| 3993 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3994 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3995 | |
| 3996 | if (buffer == nullptr) |
| 3997 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 3998 | context->validationError(GL_INVALID_OPERATION, "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3999 | return false; |
| 4000 | } |
| 4001 | |
| 4002 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4003 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4004 | context->validationError(GL_INVALID_OPERATION, |
| 4005 | "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4006 | return false; |
| 4007 | } |
| 4008 | |
| 4009 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4010 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4011 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4012 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4013 | if (!checkedSize.IsValid() || |
| 4014 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4015 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4016 | context->validationError(GL_INVALID_VALUE, |
| 4017 | "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4018 | return false; |
| 4019 | } |
| 4020 | |
| 4021 | return true; |
| 4022 | } |
| 4023 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4024 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4025 | { |
| 4026 | if (n < 0) |
| 4027 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4028 | context->validationError(GL_INVALID_VALUE, kErrorNegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4029 | return false; |
| 4030 | } |
| 4031 | return true; |
| 4032 | } |
| 4033 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4034 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4035 | { |
| 4036 | if (!context->getExtensions().robustClientMemory) |
| 4037 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4038 | context->validationError(GL_INVALID_OPERATION, |
| 4039 | "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4040 | return false; |
| 4041 | } |
| 4042 | |
| 4043 | if (bufSize < 0) |
| 4044 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4045 | context->validationError(GL_INVALID_VALUE, kErrorNegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4046 | return false; |
| 4047 | } |
| 4048 | |
| 4049 | return true; |
| 4050 | } |
| 4051 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4052 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4053 | { |
| 4054 | if (bufSize < numParams) |
| 4055 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4056 | context->validationError(GL_INVALID_OPERATION, |
| 4057 | "More parameters are required than were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4058 | return false; |
| 4059 | } |
| 4060 | |
| 4061 | return true; |
| 4062 | } |
| 4063 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4064 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4065 | GLenum target, |
| 4066 | GLenum attachment, |
| 4067 | GLenum pname, |
| 4068 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4069 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4070 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4071 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4072 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4073 | return false; |
| 4074 | } |
| 4075 | |
| 4076 | int clientVersion = context->getClientMajorVersion(); |
| 4077 | |
| 4078 | switch (pname) |
| 4079 | { |
| 4080 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4081 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4082 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4083 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4084 | break; |
| 4085 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4086 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4087 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4088 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4089 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4090 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4091 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4092 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4093 | return false; |
| 4094 | } |
| 4095 | break; |
| 4096 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4097 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4098 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4099 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4100 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4101 | return false; |
| 4102 | } |
| 4103 | break; |
| 4104 | |
| 4105 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4106 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4107 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4108 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4109 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4110 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4111 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4112 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4113 | if (clientVersion < 3) |
| 4114 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4115 | context->validationError(GL_INVALID_ENUM, kErrorES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4116 | return false; |
| 4117 | } |
| 4118 | break; |
| 4119 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4120 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4121 | if (!context->getExtensions().geometryShader) |
| 4122 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4123 | context->validationError(GL_INVALID_ENUM, kErrorGeometryShaderExtensionNotEnabled); |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4124 | return false; |
| 4125 | } |
| 4126 | break; |
| 4127 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4128 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4129 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4130 | return false; |
| 4131 | } |
| 4132 | |
| 4133 | // Determine if the attachment is a valid enum |
| 4134 | switch (attachment) |
| 4135 | { |
| 4136 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4137 | case GL_DEPTH: |
| 4138 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4139 | if (clientVersion < 3) |
| 4140 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4141 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4142 | return false; |
| 4143 | } |
| 4144 | break; |
| 4145 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4146 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4147 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4148 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4149 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4150 | return false; |
| 4151 | } |
| 4152 | break; |
| 4153 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4154 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4155 | case GL_DEPTH_ATTACHMENT: |
| 4156 | case GL_STENCIL_ATTACHMENT: |
| 4157 | break; |
| 4158 | |
| 4159 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4160 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4161 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4162 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4163 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4164 | context->validationError(GL_INVALID_ENUM, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | break; |
| 4168 | } |
| 4169 | |
| 4170 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4171 | ASSERT(framebuffer); |
| 4172 | |
| 4173 | if (framebuffer->id() == 0) |
| 4174 | { |
| 4175 | if (clientVersion < 3) |
| 4176 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4177 | context->validationError(GL_INVALID_OPERATION, kErrorDefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4178 | return false; |
| 4179 | } |
| 4180 | |
| 4181 | switch (attachment) |
| 4182 | { |
| 4183 | case GL_BACK: |
| 4184 | case GL_DEPTH: |
| 4185 | case GL_STENCIL: |
| 4186 | break; |
| 4187 | |
| 4188 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4189 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4190 | return false; |
| 4191 | } |
| 4192 | } |
| 4193 | else |
| 4194 | { |
| 4195 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4196 | { |
| 4197 | // Valid attachment query |
| 4198 | } |
| 4199 | else |
| 4200 | { |
| 4201 | switch (attachment) |
| 4202 | { |
| 4203 | case GL_DEPTH_ATTACHMENT: |
| 4204 | case GL_STENCIL_ATTACHMENT: |
| 4205 | break; |
| 4206 | |
| 4207 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4208 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4209 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4210 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4211 | return false; |
| 4212 | } |
| 4213 | break; |
| 4214 | |
| 4215 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4216 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4217 | return false; |
| 4218 | } |
| 4219 | } |
| 4220 | } |
| 4221 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4222 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4223 | if (attachmentObject) |
| 4224 | { |
| 4225 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4226 | attachmentObject->type() == GL_TEXTURE || |
| 4227 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4228 | |
| 4229 | switch (pname) |
| 4230 | { |
| 4231 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4232 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4233 | attachmentObject->type() != GL_TEXTURE) |
| 4234 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4235 | context->validationError(GL_INVALID_ENUM, |
| 4236 | kErrorFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4237 | return false; |
| 4238 | } |
| 4239 | break; |
| 4240 | |
| 4241 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4242 | if (attachmentObject->type() != GL_TEXTURE) |
| 4243 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4244 | context->validationError(GL_INVALID_ENUM, |
| 4245 | kErrorFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4246 | return false; |
| 4247 | } |
| 4248 | break; |
| 4249 | |
| 4250 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4251 | if (attachmentObject->type() != GL_TEXTURE) |
| 4252 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4253 | context->validationError(GL_INVALID_ENUM, |
| 4254 | kErrorFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4255 | return false; |
| 4256 | } |
| 4257 | break; |
| 4258 | |
| 4259 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4260 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4261 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4262 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4263 | return false; |
| 4264 | } |
| 4265 | break; |
| 4266 | |
| 4267 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4268 | if (attachmentObject->type() != GL_TEXTURE) |
| 4269 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4270 | context->validationError(GL_INVALID_ENUM, |
| 4271 | kErrorFramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4272 | return false; |
| 4273 | } |
| 4274 | break; |
| 4275 | |
| 4276 | default: |
| 4277 | break; |
| 4278 | } |
| 4279 | } |
| 4280 | else |
| 4281 | { |
| 4282 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4283 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4284 | |
| 4285 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4286 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4287 | // INVALID_OPERATION for all other pnames |
| 4288 | |
| 4289 | switch (pname) |
| 4290 | { |
| 4291 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4292 | break; |
| 4293 | |
| 4294 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4295 | if (clientVersion < 3) |
| 4296 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4297 | context->validationError(GL_INVALID_ENUM, |
| 4298 | kErrorInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4299 | return false; |
| 4300 | } |
| 4301 | break; |
| 4302 | |
| 4303 | default: |
| 4304 | if (clientVersion < 3) |
| 4305 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4306 | context->validationError(GL_INVALID_ENUM, |
| 4307 | kErrorInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4308 | return false; |
| 4309 | } |
| 4310 | else |
| 4311 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4312 | context->validationError(GL_INVALID_OPERATION, |
| 4313 | kErrorInvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4314 | return false; |
| 4315 | } |
| 4316 | } |
| 4317 | } |
| 4318 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4319 | if (numParams) |
| 4320 | { |
| 4321 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4322 | { |
| 4323 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4324 | // parameters. |
| 4325 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4326 | *numParams = numViews * 2; |
| 4327 | } |
| 4328 | else |
| 4329 | { |
| 4330 | // For all other queries we can have only one output parameter. |
| 4331 | *numParams = 1; |
| 4332 | } |
| 4333 | } |
| 4334 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4335 | return true; |
| 4336 | } |
| 4337 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4338 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4339 | GLenum target, |
| 4340 | GLenum attachment, |
| 4341 | GLenum pname, |
| 4342 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4343 | GLsizei *length, |
| 4344 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4345 | { |
| 4346 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4347 | { |
| 4348 | return false; |
| 4349 | } |
| 4350 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4351 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4352 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4353 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4354 | { |
| 4355 | return false; |
| 4356 | } |
| 4357 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4358 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4359 | { |
| 4360 | return false; |
| 4361 | } |
| 4362 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4363 | SetRobustLengthParam(length, numParams); |
| 4364 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4365 | return true; |
| 4366 | } |
| 4367 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4368 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4369 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4370 | GLenum pname, |
| 4371 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4372 | GLsizei *length, |
| 4373 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4374 | { |
| 4375 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4376 | { |
| 4377 | return false; |
| 4378 | } |
| 4379 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4380 | GLsizei numParams = 0; |
| 4381 | |
| 4382 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4383 | { |
| 4384 | return false; |
| 4385 | } |
| 4386 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4387 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4388 | { |
| 4389 | return false; |
| 4390 | } |
| 4391 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4392 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4393 | return true; |
| 4394 | } |
| 4395 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4396 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4397 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4398 | GLenum pname, |
| 4399 | GLsizei bufSize, |
| 4400 | GLsizei *length, |
| 4401 | GLint64 *params) |
| 4402 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4403 | GLsizei numParams = 0; |
| 4404 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4405 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4406 | { |
| 4407 | return false; |
| 4408 | } |
| 4409 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4410 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4411 | { |
| 4412 | return false; |
| 4413 | } |
| 4414 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4415 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4416 | { |
| 4417 | return false; |
| 4418 | } |
| 4419 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4420 | SetRobustLengthParam(length, numParams); |
| 4421 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4422 | return true; |
| 4423 | } |
| 4424 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4425 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4426 | { |
| 4427 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4428 | if (numParams) |
| 4429 | { |
| 4430 | *numParams = 1; |
| 4431 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4432 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4433 | // Special case for GL_COMPLETION_STATUS_KHR: don't resolve the link. Otherwise resolve it now. |
| 4434 | Program *programObject = (pname == GL_COMPLETION_STATUS_KHR) |
| 4435 | ? GetValidProgramNoResolve(context, program) |
| 4436 | : GetValidProgram(context, program); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4437 | if (!programObject) |
| 4438 | { |
| 4439 | return false; |
| 4440 | } |
| 4441 | |
| 4442 | switch (pname) |
| 4443 | { |
| 4444 | case GL_DELETE_STATUS: |
| 4445 | case GL_LINK_STATUS: |
| 4446 | case GL_VALIDATE_STATUS: |
| 4447 | case GL_INFO_LOG_LENGTH: |
| 4448 | case GL_ATTACHED_SHADERS: |
| 4449 | case GL_ACTIVE_ATTRIBUTES: |
| 4450 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4451 | case GL_ACTIVE_UNIFORMS: |
| 4452 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4453 | break; |
| 4454 | |
| 4455 | case GL_PROGRAM_BINARY_LENGTH: |
| 4456 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4457 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4458 | context->validationError(GL_INVALID_ENUM, |
| 4459 | "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4460 | "requires GL_OES_get_program_binary or " |
| 4461 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4462 | return false; |
| 4463 | } |
| 4464 | break; |
| 4465 | |
| 4466 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4467 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4468 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4469 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4470 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4471 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4472 | if (context->getClientMajorVersion() < 3) |
| 4473 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4474 | context->validationError(GL_INVALID_ENUM, kErrorES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4475 | return false; |
| 4476 | } |
| 4477 | break; |
| 4478 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4479 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4480 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4481 | if (context->getClientVersion() < Version(3, 1)) |
| 4482 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4483 | context->validationError(GL_INVALID_ENUM, kErrorES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4484 | return false; |
| 4485 | } |
| 4486 | break; |
| 4487 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4488 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4489 | if (context->getClientVersion() < Version(3, 1)) |
| 4490 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4491 | context->validationError(GL_INVALID_ENUM, kErrorES31Required); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4492 | return false; |
| 4493 | } |
| 4494 | |
| 4495 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4496 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4497 | // program which has not been linked successfully, or which does not contain objects to |
| 4498 | // form a compute shader. |
| 4499 | if (!programObject->isLinked()) |
| 4500 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4501 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4502 | return false; |
| 4503 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4504 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4505 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4506 | context->validationError(GL_INVALID_OPERATION, kErrorNoActiveComputeShaderStage); |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4507 | return false; |
| 4508 | } |
| 4509 | break; |
| 4510 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4511 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4512 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4513 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4514 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4515 | if (!context->getExtensions().geometryShader) |
| 4516 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4517 | context->validationError(GL_INVALID_ENUM, kErrorGeometryShaderExtensionNotEnabled); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4518 | return false; |
| 4519 | } |
| 4520 | |
| 4521 | // [EXT_geometry_shader] Chapter 7.12 |
| 4522 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4523 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4524 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4525 | // successfully, or which does not contain objects to form a geometry shader. |
| 4526 | if (!programObject->isLinked()) |
| 4527 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4528 | context->validationError(GL_INVALID_OPERATION, kErrorProgramNotLinked); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4529 | return false; |
| 4530 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4531 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4532 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4533 | context->validationError(GL_INVALID_OPERATION, kErrorNoActiveGeometryShaderStage); |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4534 | return false; |
| 4535 | } |
| 4536 | break; |
| 4537 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4538 | case GL_COMPLETION_STATUS_KHR: |
| 4539 | if (!context->getExtensions().parallelShaderCompile) |
| 4540 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4541 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 4542 | return false; |
| 4543 | } |
| 4544 | break; |
| 4545 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4546 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 4547 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4548 | return false; |
| 4549 | } |
| 4550 | |
| 4551 | return true; |
| 4552 | } |
| 4553 | |
| 4554 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4555 | GLuint program, |
| 4556 | GLenum pname, |
| 4557 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4558 | GLsizei *length, |
| 4559 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4560 | { |
| 4561 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4562 | { |
| 4563 | return false; |
| 4564 | } |
| 4565 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4566 | GLsizei numParams = 0; |
| 4567 | |
| 4568 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4569 | { |
| 4570 | return false; |
| 4571 | } |
| 4572 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4573 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4574 | { |
| 4575 | return false; |
| 4576 | } |
| 4577 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4578 | SetRobustLengthParam(length, numParams); |
| 4579 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4580 | return true; |
| 4581 | } |
| 4582 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4583 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4584 | GLenum target, |
| 4585 | GLenum pname, |
| 4586 | GLsizei bufSize, |
| 4587 | GLsizei *length, |
| 4588 | GLint *params) |
| 4589 | { |
| 4590 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4591 | { |
| 4592 | return false; |
| 4593 | } |
| 4594 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4595 | GLsizei numParams = 0; |
| 4596 | |
| 4597 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4598 | { |
| 4599 | return false; |
| 4600 | } |
| 4601 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4602 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4603 | { |
| 4604 | return false; |
| 4605 | } |
| 4606 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4607 | SetRobustLengthParam(length, numParams); |
| 4608 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4609 | return true; |
| 4610 | } |
| 4611 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4612 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4613 | GLuint shader, |
| 4614 | GLenum pname, |
| 4615 | GLsizei bufSize, |
| 4616 | GLsizei *length, |
| 4617 | GLint *params) |
| 4618 | { |
| 4619 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4620 | { |
| 4621 | return false; |
| 4622 | } |
| 4623 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4624 | GLsizei numParams = 0; |
| 4625 | |
| 4626 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4627 | { |
| 4628 | return false; |
| 4629 | } |
| 4630 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4631 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4632 | { |
| 4633 | return false; |
| 4634 | } |
| 4635 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4636 | SetRobustLengthParam(length, numParams); |
| 4637 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4638 | return true; |
| 4639 | } |
| 4640 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4641 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4642 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4643 | GLenum pname, |
| 4644 | GLsizei bufSize, |
| 4645 | GLsizei *length, |
| 4646 | GLfloat *params) |
| 4647 | { |
| 4648 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4649 | { |
| 4650 | return false; |
| 4651 | } |
| 4652 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4653 | GLsizei numParams = 0; |
| 4654 | |
| 4655 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4656 | { |
| 4657 | return false; |
| 4658 | } |
| 4659 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4660 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4661 | { |
| 4662 | return false; |
| 4663 | } |
| 4664 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4665 | SetRobustLengthParam(length, numParams); |
| 4666 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4667 | return true; |
| 4668 | } |
| 4669 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4670 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4671 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4672 | GLenum pname, |
| 4673 | GLsizei bufSize, |
| 4674 | GLsizei *length, |
| 4675 | GLint *params) |
| 4676 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4677 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4678 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4679 | { |
| 4680 | return false; |
| 4681 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4682 | GLsizei numParams = 0; |
| 4683 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4684 | { |
| 4685 | return false; |
| 4686 | } |
| 4687 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4688 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4689 | { |
| 4690 | return false; |
| 4691 | } |
| 4692 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4693 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4694 | return true; |
| 4695 | } |
| 4696 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4697 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4698 | TextureType target, |
| 4699 | GLenum pname, |
| 4700 | GLsizei bufSize, |
| 4701 | GLsizei *length, |
| 4702 | GLint *params) |
| 4703 | { |
| 4704 | UNIMPLEMENTED(); |
| 4705 | return false; |
| 4706 | } |
| 4707 | |
| 4708 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4709 | TextureType target, |
| 4710 | GLenum pname, |
| 4711 | GLsizei bufSize, |
| 4712 | GLsizei *length, |
| 4713 | GLuint *params) |
| 4714 | { |
| 4715 | UNIMPLEMENTED(); |
| 4716 | return false; |
| 4717 | } |
| 4718 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4719 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4720 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4721 | GLenum pname, |
| 4722 | GLsizei bufSize, |
| 4723 | const GLfloat *params) |
| 4724 | { |
| 4725 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4726 | { |
| 4727 | return false; |
| 4728 | } |
| 4729 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4730 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4731 | } |
| 4732 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4733 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4734 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4735 | GLenum pname, |
| 4736 | GLsizei bufSize, |
| 4737 | const GLint *params) |
| 4738 | { |
| 4739 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4740 | { |
| 4741 | return false; |
| 4742 | } |
| 4743 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4744 | return ValidateTexParameterBase(context, target, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4745 | } |
| 4746 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4747 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4748 | TextureType target, |
| 4749 | GLenum pname, |
| 4750 | GLsizei bufSize, |
| 4751 | const GLint *params) |
| 4752 | { |
| 4753 | UNIMPLEMENTED(); |
| 4754 | return false; |
| 4755 | } |
| 4756 | |
| 4757 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4758 | TextureType target, |
| 4759 | GLenum pname, |
| 4760 | GLsizei bufSize, |
| 4761 | const GLuint *params) |
| 4762 | { |
| 4763 | UNIMPLEMENTED(); |
| 4764 | return false; |
| 4765 | } |
| 4766 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4767 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4768 | GLuint sampler, |
| 4769 | GLenum pname, |
Jamie Madill | 778bf09 | 2018-11-14 09:54:36 -0500 | [diff] [blame] | 4770 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4771 | GLsizei *length, |
| 4772 | GLfloat *params) |
| 4773 | { |
| 4774 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4775 | { |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4779 | GLsizei numParams = 0; |
| 4780 | |
| 4781 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4782 | { |
| 4783 | return false; |
| 4784 | } |
| 4785 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4786 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4787 | { |
| 4788 | return false; |
| 4789 | } |
| 4790 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4791 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4792 | return true; |
| 4793 | } |
| 4794 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4795 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4796 | GLuint sampler, |
| 4797 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4798 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4799 | GLsizei *length, |
| 4800 | GLint *params) |
| 4801 | { |
| 4802 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4803 | { |
| 4804 | return false; |
| 4805 | } |
| 4806 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4807 | GLsizei numParams = 0; |
| 4808 | |
| 4809 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4810 | { |
| 4811 | return false; |
| 4812 | } |
| 4813 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4814 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4815 | { |
| 4816 | return false; |
| 4817 | } |
| 4818 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4819 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4820 | return true; |
| 4821 | } |
| 4822 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4823 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4824 | GLuint sampler, |
| 4825 | GLenum pname, |
| 4826 | GLsizei bufSize, |
| 4827 | GLsizei *length, |
| 4828 | GLint *params) |
| 4829 | { |
| 4830 | UNIMPLEMENTED(); |
| 4831 | return false; |
| 4832 | } |
| 4833 | |
| 4834 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4835 | GLuint sampler, |
| 4836 | GLenum pname, |
| 4837 | GLsizei bufSize, |
| 4838 | GLsizei *length, |
| 4839 | GLuint *params) |
| 4840 | { |
| 4841 | UNIMPLEMENTED(); |
| 4842 | return false; |
| 4843 | } |
| 4844 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4845 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4846 | GLuint sampler, |
| 4847 | GLenum pname, |
| 4848 | GLsizei bufSize, |
| 4849 | const GLfloat *params) |
| 4850 | { |
| 4851 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4852 | { |
| 4853 | return false; |
| 4854 | } |
| 4855 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4856 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4857 | } |
| 4858 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4859 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4860 | GLuint sampler, |
| 4861 | GLenum pname, |
| 4862 | GLsizei bufSize, |
| 4863 | const GLint *params) |
| 4864 | { |
| 4865 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4866 | { |
| 4867 | return false; |
| 4868 | } |
| 4869 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4870 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, true, params); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4871 | } |
| 4872 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4873 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4874 | GLuint sampler, |
| 4875 | GLenum pname, |
| 4876 | GLsizei bufSize, |
| 4877 | const GLint *param) |
| 4878 | { |
| 4879 | UNIMPLEMENTED(); |
| 4880 | return false; |
| 4881 | } |
| 4882 | |
| 4883 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4884 | GLuint sampler, |
| 4885 | GLenum pname, |
| 4886 | GLsizei bufSize, |
| 4887 | const GLuint *param) |
| 4888 | { |
| 4889 | UNIMPLEMENTED(); |
| 4890 | return false; |
| 4891 | } |
| 4892 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4893 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4894 | GLuint index, |
| 4895 | GLenum pname, |
| 4896 | GLsizei bufSize, |
| 4897 | GLsizei *length, |
| 4898 | GLfloat *params) |
| 4899 | { |
| 4900 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4901 | { |
| 4902 | return false; |
| 4903 | } |
| 4904 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4905 | GLsizei writeLength = 0; |
| 4906 | |
| 4907 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4908 | { |
| 4909 | return false; |
| 4910 | } |
| 4911 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4912 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4913 | { |
| 4914 | return false; |
| 4915 | } |
| 4916 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4917 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4918 | return true; |
| 4919 | } |
| 4920 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4921 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4922 | GLuint index, |
| 4923 | GLenum pname, |
| 4924 | GLsizei bufSize, |
| 4925 | GLsizei *length, |
| 4926 | GLint *params) |
| 4927 | { |
| 4928 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4929 | { |
| 4930 | return false; |
| 4931 | } |
| 4932 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4933 | GLsizei writeLength = 0; |
| 4934 | |
| 4935 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4936 | { |
| 4937 | return false; |
| 4938 | } |
| 4939 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4940 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4941 | { |
| 4942 | return false; |
| 4943 | } |
| 4944 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4945 | SetRobustLengthParam(length, writeLength); |
| 4946 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4947 | return true; |
| 4948 | } |
| 4949 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4950 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4951 | GLuint index, |
| 4952 | GLenum pname, |
| 4953 | GLsizei bufSize, |
| 4954 | GLsizei *length, |
| 4955 | void **pointer) |
| 4956 | { |
| 4957 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4958 | { |
| 4959 | return false; |
| 4960 | } |
| 4961 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4962 | GLsizei writeLength = 0; |
| 4963 | |
| 4964 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4965 | { |
| 4966 | return false; |
| 4967 | } |
| 4968 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4969 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4970 | { |
| 4971 | return false; |
| 4972 | } |
| 4973 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4974 | SetRobustLengthParam(length, writeLength); |
| 4975 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4976 | return true; |
| 4977 | } |
| 4978 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4979 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4980 | GLuint index, |
| 4981 | GLenum pname, |
| 4982 | GLsizei bufSize, |
| 4983 | GLsizei *length, |
| 4984 | GLint *params) |
| 4985 | { |
| 4986 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4987 | { |
| 4988 | return false; |
| 4989 | } |
| 4990 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4991 | GLsizei writeLength = 0; |
| 4992 | |
| 4993 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4994 | { |
| 4995 | return false; |
| 4996 | } |
| 4997 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4998 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4999 | { |
| 5000 | return false; |
| 5001 | } |
| 5002 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5003 | SetRobustLengthParam(length, writeLength); |
| 5004 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5005 | return true; |
| 5006 | } |
| 5007 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5008 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5009 | GLuint index, |
| 5010 | GLenum pname, |
| 5011 | GLsizei bufSize, |
| 5012 | GLsizei *length, |
| 5013 | GLuint *params) |
| 5014 | { |
| 5015 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5016 | { |
| 5017 | return false; |
| 5018 | } |
| 5019 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5020 | GLsizei writeLength = 0; |
| 5021 | |
| 5022 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5023 | { |
| 5024 | return false; |
| 5025 | } |
| 5026 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5027 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5028 | { |
| 5029 | return false; |
| 5030 | } |
| 5031 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5032 | SetRobustLengthParam(length, writeLength); |
| 5033 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5034 | return true; |
| 5035 | } |
| 5036 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5037 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5038 | GLuint program, |
| 5039 | GLuint uniformBlockIndex, |
| 5040 | GLenum pname, |
| 5041 | GLsizei bufSize, |
| 5042 | GLsizei *length, |
| 5043 | GLint *params) |
| 5044 | { |
| 5045 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5046 | { |
| 5047 | return false; |
| 5048 | } |
| 5049 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5050 | GLsizei writeLength = 0; |
| 5051 | |
| 5052 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5053 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5054 | { |
| 5055 | return false; |
| 5056 | } |
| 5057 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5058 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5059 | { |
| 5060 | return false; |
| 5061 | } |
| 5062 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5063 | SetRobustLengthParam(length, writeLength); |
| 5064 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5065 | return true; |
| 5066 | } |
| 5067 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5068 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5069 | GLenum target, |
| 5070 | GLenum internalformat, |
| 5071 | GLenum pname, |
| 5072 | GLsizei bufSize, |
| 5073 | GLsizei *length, |
| 5074 | GLint *params) |
| 5075 | { |
| 5076 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5077 | { |
| 5078 | return false; |
| 5079 | } |
| 5080 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5081 | GLsizei numParams = 0; |
| 5082 | |
| 5083 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5084 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5085 | { |
| 5086 | return false; |
| 5087 | } |
| 5088 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5089 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5090 | { |
| 5091 | return false; |
| 5092 | } |
| 5093 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5094 | SetRobustLengthParam(length, numParams); |
| 5095 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5096 | return true; |
| 5097 | } |
| 5098 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5099 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5100 | GLuint attribIndex, |
| 5101 | GLint size, |
| 5102 | GLenum type, |
| 5103 | GLboolean pureInteger) |
| 5104 | { |
| 5105 | const Caps &caps = context->getCaps(); |
| 5106 | if (attribIndex >= caps.maxVertexAttributes) |
| 5107 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5108 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5109 | return false; |
| 5110 | } |
| 5111 | |
| 5112 | if (size < 1 || size > 4) |
| 5113 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5114 | context->validationError(GL_INVALID_VALUE, kErrorInvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5115 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | switch (type) |
| 5119 | { |
| 5120 | case GL_BYTE: |
| 5121 | case GL_UNSIGNED_BYTE: |
| 5122 | case GL_SHORT: |
| 5123 | case GL_UNSIGNED_SHORT: |
| 5124 | break; |
| 5125 | |
| 5126 | case GL_INT: |
| 5127 | case GL_UNSIGNED_INT: |
| 5128 | if (context->getClientMajorVersion() < 3) |
| 5129 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5130 | context->validationError(GL_INVALID_ENUM, |
| 5131 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5132 | return false; |
| 5133 | } |
| 5134 | break; |
| 5135 | |
| 5136 | case GL_FIXED: |
| 5137 | case GL_FLOAT: |
| 5138 | if (pureInteger) |
| 5139 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5140 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5141 | return false; |
| 5142 | } |
| 5143 | break; |
| 5144 | |
| 5145 | case GL_HALF_FLOAT: |
| 5146 | if (context->getClientMajorVersion() < 3) |
| 5147 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5148 | context->validationError(GL_INVALID_ENUM, |
| 5149 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5150 | return false; |
| 5151 | } |
| 5152 | if (pureInteger) |
| 5153 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5154 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5155 | return false; |
| 5156 | } |
| 5157 | break; |
| 5158 | |
| 5159 | case GL_INT_2_10_10_10_REV: |
| 5160 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5161 | if (context->getClientMajorVersion() < 3) |
| 5162 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5163 | context->validationError(GL_INVALID_ENUM, |
| 5164 | "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5165 | return false; |
| 5166 | } |
| 5167 | if (pureInteger) |
| 5168 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5169 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5170 | return false; |
| 5171 | } |
| 5172 | if (size != 4) |
| 5173 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5174 | context->validationError(GL_INVALID_OPERATION, |
| 5175 | "Type is INT_2_10_10_10_REV or " |
| 5176 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5177 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5178 | return false; |
| 5179 | } |
| 5180 | break; |
| 5181 | |
| 5182 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5183 | context->validationError(GL_INVALID_ENUM, kErrorInvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5184 | return false; |
| 5185 | } |
| 5186 | |
| 5187 | return true; |
| 5188 | } |
| 5189 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5190 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5191 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5192 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5193 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5194 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5195 | GLint drawbuffer, |
| 5196 | const GLenum *validComponentTypes, |
| 5197 | size_t validComponentTypeCount) |
| 5198 | { |
| 5199 | const FramebufferAttachment *attachment = |
| 5200 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5201 | if (attachment) |
| 5202 | { |
| 5203 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5204 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5205 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5206 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5207 | context->validationError( |
| 5208 | GL_INVALID_OPERATION, |
| 5209 | "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5210 | return false; |
| 5211 | } |
| 5212 | } |
| 5213 | |
| 5214 | return true; |
| 5215 | } |
| 5216 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5217 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5218 | { |
| 5219 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5220 | { |
| 5221 | return false; |
| 5222 | } |
| 5223 | |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5224 | Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5225 | if (pixelUnpackBuffer == nullptr) |
| 5226 | { |
| 5227 | if (dataSize < imageSize) |
| 5228 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5229 | context->validationError(GL_INVALID_OPERATION, "dataSize is too small"); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5230 | } |
| 5231 | } |
| 5232 | return true; |
| 5233 | } |
| 5234 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5235 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5236 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5237 | GLenum pname, |
| 5238 | bool pointerVersion, |
| 5239 | GLsizei *numParams) |
| 5240 | { |
| 5241 | if (numParams) |
| 5242 | { |
| 5243 | *numParams = 0; |
| 5244 | } |
| 5245 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5246 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5247 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5248 | context->validationError(GL_INVALID_ENUM, kErrorInvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5249 | return false; |
| 5250 | } |
| 5251 | |
| 5252 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5253 | if (!buffer) |
| 5254 | { |
| 5255 | // A null buffer means that "0" is bound to the requested buffer target |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5256 | context->validationError(GL_INVALID_OPERATION, kErrorBufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5257 | return false; |
| 5258 | } |
| 5259 | |
| 5260 | const Extensions &extensions = context->getExtensions(); |
| 5261 | |
| 5262 | switch (pname) |
| 5263 | { |
| 5264 | case GL_BUFFER_USAGE: |
| 5265 | case GL_BUFFER_SIZE: |
| 5266 | break; |
| 5267 | |
| 5268 | case GL_BUFFER_ACCESS_OES: |
| 5269 | if (!extensions.mapBuffer) |
| 5270 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5271 | context->validationError(GL_INVALID_ENUM, |
| 5272 | "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5273 | return false; |
| 5274 | } |
| 5275 | break; |
| 5276 | |
| 5277 | case GL_BUFFER_MAPPED: |
| 5278 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5279 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5280 | !extensions.mapBufferRange) |
| 5281 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5282 | context->validationError(GL_INVALID_ENUM, |
| 5283 | "pname requires OpenGL ES 3.0, " |
| 5284 | "GL_OES_mapbuffer or " |
| 5285 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5286 | return false; |
| 5287 | } |
| 5288 | break; |
| 5289 | |
| 5290 | case GL_BUFFER_MAP_POINTER: |
| 5291 | if (!pointerVersion) |
| 5292 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5293 | context->validationError( |
| 5294 | GL_INVALID_ENUM, |
| 5295 | "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5296 | return false; |
| 5297 | } |
| 5298 | break; |
| 5299 | |
| 5300 | case GL_BUFFER_ACCESS_FLAGS: |
| 5301 | case GL_BUFFER_MAP_OFFSET: |
| 5302 | case GL_BUFFER_MAP_LENGTH: |
| 5303 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5304 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5305 | context->validationError( |
| 5306 | 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] | 5307 | return false; |
| 5308 | } |
| 5309 | break; |
| 5310 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5311 | case GL_MEMORY_SIZE_ANGLE: |
| 5312 | if (!context->getExtensions().memorySize) |
| 5313 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5314 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5315 | return false; |
| 5316 | } |
| 5317 | break; |
| 5318 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5319 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5320 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5321 | return false; |
| 5322 | } |
| 5323 | |
| 5324 | // All buffer parameter queries return one value. |
| 5325 | if (numParams) |
| 5326 | { |
| 5327 | *numParams = 1; |
| 5328 | } |
| 5329 | |
| 5330 | return true; |
| 5331 | } |
| 5332 | |
| 5333 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5334 | GLenum target, |
| 5335 | GLenum pname, |
| 5336 | GLsizei *length) |
| 5337 | { |
| 5338 | if (length) |
| 5339 | { |
| 5340 | *length = 0; |
| 5341 | } |
| 5342 | |
| 5343 | if (target != GL_RENDERBUFFER) |
| 5344 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5345 | context->validationError(GL_INVALID_ENUM, kErrorInvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5346 | return false; |
| 5347 | } |
| 5348 | |
| 5349 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5350 | if (renderbuffer == nullptr) |
| 5351 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5352 | context->validationError(GL_INVALID_OPERATION, kErrorRenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5353 | return false; |
| 5354 | } |
| 5355 | |
| 5356 | switch (pname) |
| 5357 | { |
| 5358 | case GL_RENDERBUFFER_WIDTH: |
| 5359 | case GL_RENDERBUFFER_HEIGHT: |
| 5360 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5361 | case GL_RENDERBUFFER_RED_SIZE: |
| 5362 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5363 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5364 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5365 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5366 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5367 | break; |
| 5368 | |
| 5369 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5370 | if (!context->getExtensions().framebufferMultisample) |
| 5371 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5372 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5373 | return false; |
| 5374 | } |
| 5375 | break; |
| 5376 | |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5377 | case GL_MEMORY_SIZE_ANGLE: |
| 5378 | if (!context->getExtensions().memorySize) |
| 5379 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5380 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5381 | return false; |
| 5382 | } |
| 5383 | break; |
| 5384 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5385 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5386 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5387 | return false; |
| 5388 | } |
| 5389 | |
| 5390 | if (length) |
| 5391 | { |
| 5392 | *length = 1; |
| 5393 | } |
| 5394 | return true; |
| 5395 | } |
| 5396 | |
| 5397 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5398 | { |
| 5399 | if (length) |
| 5400 | { |
| 5401 | *length = 0; |
| 5402 | } |
| 5403 | |
| 5404 | if (GetValidShader(context, shader) == nullptr) |
| 5405 | { |
| 5406 | return false; |
| 5407 | } |
| 5408 | |
| 5409 | switch (pname) |
| 5410 | { |
| 5411 | case GL_SHADER_TYPE: |
| 5412 | case GL_DELETE_STATUS: |
| 5413 | case GL_COMPILE_STATUS: |
| 5414 | case GL_INFO_LOG_LENGTH: |
| 5415 | case GL_SHADER_SOURCE_LENGTH: |
| 5416 | break; |
| 5417 | |
| 5418 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5419 | if (!context->getExtensions().translatedShaderSource) |
| 5420 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5421 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5422 | return false; |
| 5423 | } |
| 5424 | break; |
| 5425 | |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5426 | case GL_COMPLETION_STATUS_KHR: |
| 5427 | if (!context->getExtensions().parallelShaderCompile) |
| 5428 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5429 | context->validationError(GL_INVALID_OPERATION, kErrorExtensionNotEnabled); |
Jamie Madill | 44a6fbf | 2018-10-02 13:38:56 -0400 | [diff] [blame] | 5430 | return false; |
| 5431 | } |
| 5432 | break; |
| 5433 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5434 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5435 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5436 | return false; |
| 5437 | } |
| 5438 | |
| 5439 | if (length) |
| 5440 | { |
| 5441 | *length = 1; |
| 5442 | } |
| 5443 | return true; |
| 5444 | } |
| 5445 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5446 | bool ValidateGetTexParameterBase(Context *context, |
| 5447 | TextureType target, |
| 5448 | GLenum pname, |
| 5449 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5450 | { |
| 5451 | if (length) |
| 5452 | { |
| 5453 | *length = 0; |
| 5454 | } |
| 5455 | |
| 5456 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5457 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5458 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5459 | return false; |
| 5460 | } |
| 5461 | |
| 5462 | if (context->getTargetTexture(target) == nullptr) |
| 5463 | { |
| 5464 | // Should only be possible for external textures |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5465 | context->validationError(GL_INVALID_ENUM, kErrorTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5466 | return false; |
| 5467 | } |
| 5468 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5469 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5470 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5471 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5472 | return false; |
| 5473 | } |
| 5474 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5475 | switch (pname) |
| 5476 | { |
| 5477 | case GL_TEXTURE_MAG_FILTER: |
| 5478 | case GL_TEXTURE_MIN_FILTER: |
| 5479 | case GL_TEXTURE_WRAP_S: |
| 5480 | case GL_TEXTURE_WRAP_T: |
| 5481 | break; |
| 5482 | |
| 5483 | case GL_TEXTURE_USAGE_ANGLE: |
| 5484 | if (!context->getExtensions().textureUsage) |
| 5485 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5486 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5487 | return false; |
| 5488 | } |
| 5489 | break; |
| 5490 | |
| 5491 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5492 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5493 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5494 | return false; |
| 5495 | } |
| 5496 | break; |
| 5497 | |
| 5498 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5499 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5500 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5501 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5502 | return false; |
| 5503 | } |
| 5504 | break; |
| 5505 | |
| 5506 | case GL_TEXTURE_WRAP_R: |
| 5507 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5508 | case GL_TEXTURE_SWIZZLE_R: |
| 5509 | case GL_TEXTURE_SWIZZLE_G: |
| 5510 | case GL_TEXTURE_SWIZZLE_B: |
| 5511 | case GL_TEXTURE_SWIZZLE_A: |
| 5512 | case GL_TEXTURE_BASE_LEVEL: |
| 5513 | case GL_TEXTURE_MAX_LEVEL: |
| 5514 | case GL_TEXTURE_MIN_LOD: |
| 5515 | case GL_TEXTURE_MAX_LOD: |
| 5516 | case GL_TEXTURE_COMPARE_MODE: |
| 5517 | case GL_TEXTURE_COMPARE_FUNC: |
| 5518 | if (context->getClientMajorVersion() < 3) |
| 5519 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5520 | context->validationError(GL_INVALID_ENUM, "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5521 | return false; |
| 5522 | } |
| 5523 | break; |
| 5524 | |
| 5525 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5526 | if (!context->getExtensions().textureSRGBDecode) |
| 5527 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5528 | context->validationError(GL_INVALID_ENUM, |
| 5529 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5530 | return false; |
| 5531 | } |
| 5532 | break; |
| 5533 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5534 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5535 | if (context->getClientVersion() < Version(3, 1)) |
| 5536 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5537 | context->validationError(GL_INVALID_ENUM, kErrorEnumRequiresGLES31); |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5538 | return false; |
| 5539 | } |
| 5540 | break; |
| 5541 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5542 | case GL_GENERATE_MIPMAP: |
| 5543 | case GL_TEXTURE_CROP_RECT_OES: |
| 5544 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5545 | // after GL_OES_draw_texture functionality implemented |
| 5546 | if (context->getClientMajorVersion() > 1) |
| 5547 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5548 | context->validationError(GL_INVALID_ENUM, kErrorGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5549 | return false; |
| 5550 | } |
| 5551 | break; |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5552 | |
| 5553 | case GL_MEMORY_SIZE_ANGLE: |
| 5554 | if (!context->getExtensions().memorySize) |
| 5555 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5556 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Geoff Lang | 79b9140 | 2018-10-04 15:11:30 -0400 | [diff] [blame] | 5557 | return false; |
| 5558 | } |
| 5559 | break; |
| 5560 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5561 | case GL_TEXTURE_BORDER_COLOR: |
| 5562 | if (!context->getExtensions().textureBorderClamp) |
| 5563 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5564 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5565 | return false; |
| 5566 | } |
| 5567 | break; |
| 5568 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5569 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5570 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5571 | return false; |
| 5572 | } |
| 5573 | |
| 5574 | if (length) |
| 5575 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5576 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5577 | } |
| 5578 | return true; |
| 5579 | } |
| 5580 | |
| 5581 | bool ValidateGetVertexAttribBase(Context *context, |
| 5582 | GLuint index, |
| 5583 | GLenum pname, |
| 5584 | GLsizei *length, |
| 5585 | bool pointer, |
| 5586 | bool pureIntegerEntryPoint) |
| 5587 | { |
| 5588 | if (length) |
| 5589 | { |
| 5590 | *length = 0; |
| 5591 | } |
| 5592 | |
| 5593 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5594 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5595 | 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] | 5596 | return false; |
| 5597 | } |
| 5598 | |
| 5599 | if (index >= context->getCaps().maxVertexAttributes) |
| 5600 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5601 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5602 | return false; |
| 5603 | } |
| 5604 | |
| 5605 | if (pointer) |
| 5606 | { |
| 5607 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5608 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5609 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5610 | return false; |
| 5611 | } |
| 5612 | } |
| 5613 | else |
| 5614 | { |
| 5615 | switch (pname) |
| 5616 | { |
| 5617 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5618 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5619 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5620 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5621 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5622 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5623 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5624 | break; |
| 5625 | |
| 5626 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5627 | static_assert( |
| 5628 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5629 | "ANGLE extension enums not equal to GL enums."); |
| 5630 | if (context->getClientMajorVersion() < 3 && |
| 5631 | !context->getExtensions().instancedArrays) |
| 5632 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5633 | context->validationError(GL_INVALID_ENUM, |
| 5634 | "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5635 | "requires OpenGL ES 3.0 or " |
| 5636 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5637 | return false; |
| 5638 | } |
| 5639 | break; |
| 5640 | |
| 5641 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5642 | if (context->getClientMajorVersion() < 3) |
| 5643 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5644 | context->validationError( |
| 5645 | 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] | 5646 | return false; |
| 5647 | } |
| 5648 | break; |
| 5649 | |
| 5650 | case GL_VERTEX_ATTRIB_BINDING: |
| 5651 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5652 | if (context->getClientVersion() < ES_3_1) |
| 5653 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5654 | context->validationError(GL_INVALID_ENUM, |
| 5655 | "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5656 | return false; |
| 5657 | } |
| 5658 | break; |
| 5659 | |
| 5660 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5661 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5662 | return false; |
| 5663 | } |
| 5664 | } |
| 5665 | |
| 5666 | if (length) |
| 5667 | { |
| 5668 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5669 | { |
| 5670 | *length = 4; |
| 5671 | } |
| 5672 | else |
| 5673 | { |
| 5674 | *length = 1; |
| 5675 | } |
| 5676 | } |
| 5677 | |
| 5678 | return true; |
| 5679 | } |
| 5680 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5681 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5682 | GLint x, |
| 5683 | GLint y, |
| 5684 | GLsizei width, |
| 5685 | GLsizei height, |
| 5686 | GLenum format, |
| 5687 | GLenum type, |
| 5688 | GLsizei bufSize, |
| 5689 | GLsizei *length, |
| 5690 | GLsizei *columns, |
| 5691 | GLsizei *rows, |
| 5692 | void *pixels) |
| 5693 | { |
| 5694 | if (length != nullptr) |
| 5695 | { |
| 5696 | *length = 0; |
| 5697 | } |
| 5698 | if (rows != nullptr) |
| 5699 | { |
| 5700 | *rows = 0; |
| 5701 | } |
| 5702 | if (columns != nullptr) |
| 5703 | { |
| 5704 | *columns = 0; |
| 5705 | } |
| 5706 | |
| 5707 | if (width < 0 || height < 0) |
| 5708 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5709 | context->validationError(GL_INVALID_VALUE, kErrorNegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5710 | return false; |
| 5711 | } |
| 5712 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5713 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5714 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5715 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5716 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5717 | return false; |
| 5718 | } |
| 5719 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5720 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5721 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5722 | return false; |
| 5723 | } |
| 5724 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5725 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5726 | ASSERT(framebuffer); |
| 5727 | |
| 5728 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5729 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5730 | context->validationError(GL_INVALID_OPERATION, kErrorReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5731 | return false; |
| 5732 | } |
| 5733 | |
| 5734 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5735 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5736 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5737 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5738 | // situation is an application error that would lead to a crash in ANGLE. |
| 5739 | if (readBuffer == nullptr) |
| 5740 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5741 | context->validationError(GL_INVALID_OPERATION, kErrorMissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5742 | return false; |
| 5743 | } |
| 5744 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5745 | // ANGLE_multiview, Revision 1: |
| 5746 | // 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] | 5747 | // current read framebuffer is FRAMEBUFFER_MULTIVIEW_SIDE_BY_SIDE_ANGLE or the number of views |
| 5748 | // in the current read framebuffer is more than one. |
| 5749 | if (framebuffer->readDisallowedByMultiview()) |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5750 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5751 | context->validationError(GL_INVALID_FRAMEBUFFER_OPERATION, |
| 5752 | "Attempting to read from a multi-view framebuffer."); |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5753 | return false; |
| 5754 | } |
| 5755 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5756 | if (context->getExtensions().webglCompatibility) |
| 5757 | { |
| 5758 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5759 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5760 | // and type before validating the combination of format and type. However, the |
| 5761 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5762 | // verifies that GL_INVALID_OPERATION is generated. |
| 5763 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5764 | // dEQP/WebGL. |
| 5765 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5766 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5767 | context->validationError(GL_INVALID_ENUM, kErrorInvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5768 | return false; |
| 5769 | } |
| 5770 | |
| 5771 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5772 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5773 | context->validationError(GL_INVALID_ENUM, kErrorInvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5774 | return false; |
| 5775 | } |
| 5776 | } |
| 5777 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5778 | GLenum currentFormat = GL_NONE; |
| 5779 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5780 | |
| 5781 | GLenum currentType = GL_NONE; |
| 5782 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5783 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5784 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5785 | |
| 5786 | bool validFormatTypeCombination = |
| 5787 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5788 | |
| 5789 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5790 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5791 | context->validationError(GL_INVALID_OPERATION, kErrorMismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5792 | return false; |
| 5793 | } |
| 5794 | |
| 5795 | // Check for pixel pack buffer related API errors |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5796 | Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5797 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5798 | { |
| 5799 | // ...the buffer object's data store is currently mapped. |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5800 | context->validationError(GL_INVALID_OPERATION, "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5801 | return false; |
| 5802 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5803 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5804 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5805 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5806 | context->validationError(GL_INVALID_OPERATION, |
| 5807 | kErrorPixelPackBufferBoundForTransformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5808 | return false; |
| 5809 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5810 | |
| 5811 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5812 | // would exceed the data store size. |
| 5813 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
Jamie Madill | 43da7c4 | 2018-08-01 11:34:49 -0400 | [diff] [blame] | 5814 | const Extents size(width, height, 1); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5815 | const auto &pack = context->getGLState().getPackState(); |
| 5816 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5817 | GLuint endByte = 0; |
| 5818 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5819 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5820 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5821 | return false; |
| 5822 | } |
| 5823 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5824 | if (bufSize >= 0) |
| 5825 | { |
| 5826 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5827 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5828 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5829 | return false; |
| 5830 | } |
| 5831 | } |
| 5832 | |
| 5833 | if (pixelPackBuffer != nullptr) |
| 5834 | { |
| 5835 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5836 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5837 | checkedEndByte += checkedOffset; |
| 5838 | |
| 5839 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5840 | { |
| 5841 | // Overflow past the end of the buffer |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5842 | context->validationError(GL_INVALID_OPERATION, kErrorParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5843 | return false; |
| 5844 | } |
| 5845 | } |
| 5846 | |
| 5847 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5848 | { |
| 5849 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5850 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5851 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5852 | return false; |
| 5853 | } |
| 5854 | |
| 5855 | *length = static_cast<GLsizei>(endByte); |
| 5856 | } |
| 5857 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5858 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5859 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5860 | if (start < 0) |
| 5861 | { |
| 5862 | // "subtract" the area that is less than 0 |
| 5863 | clippedExtent += start; |
| 5864 | } |
| 5865 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5866 | angle::CheckedNumeric<int> readExtent = start; |
| 5867 | readExtent += length; |
| 5868 | if (!readExtent.IsValid()) |
| 5869 | { |
| 5870 | return false; |
| 5871 | } |
| 5872 | |
| 5873 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5874 | { |
| 5875 | // Subtract the region to the right of the read buffer |
| 5876 | clippedExtent -= (readExtent - bufferSize); |
| 5877 | } |
| 5878 | |
| 5879 | if (!clippedExtent.IsValid()) |
| 5880 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5881 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5882 | } |
| 5883 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5884 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5885 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5886 | }; |
| 5887 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5888 | GLsizei writtenColumns = 0; |
| 5889 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5890 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5891 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5892 | return false; |
| 5893 | } |
| 5894 | |
| 5895 | GLsizei writtenRows = 0; |
| 5896 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5897 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5898 | context->validationError(GL_INVALID_OPERATION, kErrorIntegerOverflow); |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5899 | return false; |
| 5900 | } |
| 5901 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5902 | if (columns != nullptr) |
| 5903 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5904 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5905 | } |
| 5906 | |
| 5907 | if (rows != nullptr) |
| 5908 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5909 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | return true; |
| 5913 | } |
| 5914 | |
| 5915 | template <typename ParamType> |
| 5916 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5917 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5918 | GLenum pname, |
| 5919 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 5920 | bool vectorParams, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5921 | const ParamType *params) |
| 5922 | { |
| 5923 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5924 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5925 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5926 | return false; |
| 5927 | } |
| 5928 | |
| 5929 | if (context->getTargetTexture(target) == nullptr) |
| 5930 | { |
| 5931 | // Should only be possible for external textures |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5932 | context->validationError(GL_INVALID_ENUM, kErrorTextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5933 | return false; |
| 5934 | } |
| 5935 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5936 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5937 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5938 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5939 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5940 | return false; |
| 5941 | } |
| 5942 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5943 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5944 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5945 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5946 | return false; |
| 5947 | } |
| 5948 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5949 | switch (pname) |
| 5950 | { |
| 5951 | case GL_TEXTURE_WRAP_R: |
| 5952 | case GL_TEXTURE_SWIZZLE_R: |
| 5953 | case GL_TEXTURE_SWIZZLE_G: |
| 5954 | case GL_TEXTURE_SWIZZLE_B: |
| 5955 | case GL_TEXTURE_SWIZZLE_A: |
| 5956 | case GL_TEXTURE_BASE_LEVEL: |
| 5957 | case GL_TEXTURE_MAX_LEVEL: |
| 5958 | case GL_TEXTURE_COMPARE_MODE: |
| 5959 | case GL_TEXTURE_COMPARE_FUNC: |
| 5960 | case GL_TEXTURE_MIN_LOD: |
| 5961 | case GL_TEXTURE_MAX_LOD: |
| 5962 | if (context->getClientMajorVersion() < 3) |
| 5963 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5964 | context->validationError(GL_INVALID_ENUM, kErrorES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5965 | return false; |
| 5966 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5967 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5968 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5969 | context->validationError(GL_INVALID_ENUM, |
| 5970 | "ES3 texture parameters are not " |
| 5971 | "available without " |
| 5972 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5973 | return false; |
| 5974 | } |
| 5975 | break; |
| 5976 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5977 | case GL_GENERATE_MIPMAP: |
| 5978 | case GL_TEXTURE_CROP_RECT_OES: |
| 5979 | if (context->getClientMajorVersion() > 1) |
| 5980 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 5981 | context->validationError(GL_INVALID_ENUM, kErrorGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5982 | return false; |
| 5983 | } |
| 5984 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5985 | default: |
| 5986 | break; |
| 5987 | } |
| 5988 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 5989 | if (target == TextureType::_2DMultisample || target == TextureType::_2DMultisampleArray) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5990 | { |
| 5991 | switch (pname) |
| 5992 | { |
| 5993 | case GL_TEXTURE_MIN_FILTER: |
| 5994 | case GL_TEXTURE_MAG_FILTER: |
| 5995 | case GL_TEXTURE_WRAP_S: |
| 5996 | case GL_TEXTURE_WRAP_T: |
| 5997 | case GL_TEXTURE_WRAP_R: |
| 5998 | case GL_TEXTURE_MIN_LOD: |
| 5999 | case GL_TEXTURE_MAX_LOD: |
| 6000 | case GL_TEXTURE_COMPARE_MODE: |
| 6001 | case GL_TEXTURE_COMPARE_FUNC: |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6002 | case GL_TEXTURE_BORDER_COLOR: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6003 | context->validationError(GL_INVALID_ENUM, |
| 6004 | "Invalid parameter for 2D multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6005 | return false; |
| 6006 | } |
| 6007 | } |
| 6008 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6009 | switch (pname) |
| 6010 | { |
| 6011 | case GL_TEXTURE_WRAP_S: |
| 6012 | case GL_TEXTURE_WRAP_T: |
| 6013 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6014 | { |
| 6015 | bool restrictedWrapModes = |
| 6016 | target == TextureType::External || target == TextureType::Rectangle; |
| 6017 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6018 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6019 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6020 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6021 | } |
| 6022 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6023 | |
| 6024 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6025 | { |
| 6026 | bool restrictedMinFilter = |
| 6027 | target == TextureType::External || target == TextureType::Rectangle; |
| 6028 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6029 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6030 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6031 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6032 | } |
| 6033 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6034 | |
| 6035 | case GL_TEXTURE_MAG_FILTER: |
| 6036 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6037 | { |
| 6038 | return false; |
| 6039 | } |
| 6040 | break; |
| 6041 | |
| 6042 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6043 | if (!context->getExtensions().textureUsage) |
| 6044 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6045 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6046 | return false; |
| 6047 | } |
| 6048 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6049 | switch (ConvertToGLenum(params[0])) |
| 6050 | { |
| 6051 | case GL_NONE: |
| 6052 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6053 | break; |
| 6054 | |
| 6055 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6056 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6057 | return false; |
| 6058 | } |
| 6059 | break; |
| 6060 | |
| 6061 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6062 | { |
| 6063 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6064 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6065 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6066 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6067 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6068 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6069 | } |
| 6070 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6071 | |
| 6072 | case GL_TEXTURE_MIN_LOD: |
| 6073 | case GL_TEXTURE_MAX_LOD: |
| 6074 | // any value is permissible |
| 6075 | break; |
| 6076 | |
| 6077 | case GL_TEXTURE_COMPARE_MODE: |
| 6078 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6079 | { |
| 6080 | return false; |
| 6081 | } |
| 6082 | break; |
| 6083 | |
| 6084 | case GL_TEXTURE_COMPARE_FUNC: |
| 6085 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6086 | { |
| 6087 | return false; |
| 6088 | } |
| 6089 | break; |
| 6090 | |
| 6091 | case GL_TEXTURE_SWIZZLE_R: |
| 6092 | case GL_TEXTURE_SWIZZLE_G: |
| 6093 | case GL_TEXTURE_SWIZZLE_B: |
| 6094 | case GL_TEXTURE_SWIZZLE_A: |
| 6095 | switch (ConvertToGLenum(params[0])) |
| 6096 | { |
| 6097 | case GL_RED: |
| 6098 | case GL_GREEN: |
| 6099 | case GL_BLUE: |
| 6100 | case GL_ALPHA: |
| 6101 | case GL_ZERO: |
| 6102 | case GL_ONE: |
| 6103 | break; |
| 6104 | |
| 6105 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6106 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6107 | return false; |
| 6108 | } |
| 6109 | break; |
| 6110 | |
| 6111 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6112 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6113 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6114 | context->validationError(GL_INVALID_VALUE, "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6115 | return false; |
| 6116 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6117 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [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 external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6121 | return false; |
| 6122 | } |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6123 | if ((target == TextureType::_2DMultisample || |
| 6124 | target == TextureType::_2DMultisampleArray) && |
| 6125 | static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6126 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6127 | context->validationError(GL_INVALID_OPERATION, |
| 6128 | "Base level must be 0 for multisampled textures."); |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6129 | return false; |
| 6130 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6131 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6132 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6133 | context->validationError(GL_INVALID_OPERATION, |
| 6134 | "Base level must be 0 for rectangle textures."); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6135 | return false; |
| 6136 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6137 | break; |
| 6138 | |
| 6139 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6140 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6141 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6142 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6143 | return false; |
| 6144 | } |
| 6145 | break; |
| 6146 | |
| 6147 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6148 | if (context->getClientVersion() < Version(3, 1)) |
| 6149 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6150 | context->validationError(GL_INVALID_ENUM, kErrorEnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6151 | return false; |
| 6152 | } |
| 6153 | switch (ConvertToGLenum(params[0])) |
| 6154 | { |
| 6155 | case GL_DEPTH_COMPONENT: |
| 6156 | case GL_STENCIL_INDEX: |
| 6157 | break; |
| 6158 | |
| 6159 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6160 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6161 | return false; |
| 6162 | } |
| 6163 | break; |
| 6164 | |
| 6165 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6166 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6167 | { |
| 6168 | return false; |
| 6169 | } |
| 6170 | break; |
| 6171 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6172 | case GL_GENERATE_MIPMAP: |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6173 | if (context->getClientMajorVersion() > 1) |
| 6174 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6175 | context->validationError(GL_INVALID_ENUM, kErrorGLES1Only); |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6176 | return false; |
| 6177 | } |
| 6178 | break; |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6179 | |
| 6180 | case GL_TEXTURE_CROP_RECT_OES: |
| 6181 | if (context->getClientMajorVersion() > 1) |
| 6182 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6183 | context->validationError(GL_INVALID_ENUM, kErrorGLES1Only); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6184 | return false; |
| 6185 | } |
| 6186 | if (!vectorParams) |
| 6187 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6188 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6189 | return false; |
| 6190 | } |
| 6191 | break; |
| 6192 | |
| 6193 | case GL_TEXTURE_BORDER_COLOR: |
| 6194 | if (!context->getExtensions().textureBorderClamp) |
| 6195 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6196 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6197 | return false; |
| 6198 | } |
| 6199 | if (!vectorParams) |
| 6200 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6201 | context->validationError(GL_INVALID_ENUM, kErrorInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6202 | return false; |
| 6203 | } |
| 6204 | break; |
| 6205 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6206 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6207 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6208 | return false; |
| 6209 | } |
| 6210 | |
| 6211 | return true; |
| 6212 | } |
| 6213 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6214 | template bool ValidateTexParameterBase(Context *, |
| 6215 | TextureType, |
| 6216 | GLenum, |
| 6217 | GLsizei, |
| 6218 | bool, |
| 6219 | const GLfloat *); |
| 6220 | template bool ValidateTexParameterBase(Context *, |
| 6221 | TextureType, |
| 6222 | GLenum, |
| 6223 | GLsizei, |
| 6224 | bool, |
| 6225 | const GLint *); |
| 6226 | template bool ValidateTexParameterBase(Context *, |
| 6227 | TextureType, |
| 6228 | GLenum, |
| 6229 | GLsizei, |
| 6230 | bool, |
| 6231 | const GLuint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6232 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6233 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6234 | { |
| 6235 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6236 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6237 | context->validationError(GL_INVALID_VALUE, kErrorIndexExceedsMaxVertexAttribute); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6238 | return false; |
| 6239 | } |
| 6240 | |
| 6241 | return true; |
| 6242 | } |
| 6243 | |
| 6244 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6245 | GLuint program, |
| 6246 | GLuint uniformBlockIndex, |
| 6247 | GLenum pname, |
| 6248 | GLsizei *length) |
| 6249 | { |
| 6250 | if (length) |
| 6251 | { |
| 6252 | *length = 0; |
| 6253 | } |
| 6254 | |
| 6255 | if (context->getClientMajorVersion() < 3) |
| 6256 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6257 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6258 | return false; |
| 6259 | } |
| 6260 | |
| 6261 | Program *programObject = GetValidProgram(context, program); |
| 6262 | if (!programObject) |
| 6263 | { |
| 6264 | return false; |
| 6265 | } |
| 6266 | |
| 6267 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6268 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6269 | context->validationError(GL_INVALID_VALUE, |
| 6270 | "uniformBlockIndex exceeds active uniform block count."); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6271 | return false; |
| 6272 | } |
| 6273 | |
| 6274 | switch (pname) |
| 6275 | { |
| 6276 | case GL_UNIFORM_BLOCK_BINDING: |
| 6277 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6278 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6279 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6280 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6281 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6282 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6283 | break; |
| 6284 | |
| 6285 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6286 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6287 | return false; |
| 6288 | } |
| 6289 | |
| 6290 | if (length) |
| 6291 | { |
| 6292 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6293 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6294 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6295 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6296 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6297 | } |
| 6298 | else |
| 6299 | { |
| 6300 | *length = 1; |
| 6301 | } |
| 6302 | } |
| 6303 | |
| 6304 | return true; |
| 6305 | } |
| 6306 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6307 | template <typename ParamType> |
| 6308 | bool ValidateSamplerParameterBase(Context *context, |
| 6309 | GLuint sampler, |
| 6310 | GLenum pname, |
| 6311 | GLsizei bufSize, |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6312 | bool vectorParams, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6313 | ParamType *params) |
| 6314 | { |
| 6315 | if (context->getClientMajorVersion() < 3) |
| 6316 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6317 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6318 | return false; |
| 6319 | } |
| 6320 | |
| 6321 | if (!context->isSampler(sampler)) |
| 6322 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6323 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6324 | return false; |
| 6325 | } |
| 6326 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6327 | const GLsizei minBufSize = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6328 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6329 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6330 | context->validationError(GL_INVALID_OPERATION, kErrorInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6331 | return false; |
| 6332 | } |
| 6333 | |
| 6334 | switch (pname) |
| 6335 | { |
| 6336 | case GL_TEXTURE_WRAP_S: |
| 6337 | case GL_TEXTURE_WRAP_T: |
| 6338 | case GL_TEXTURE_WRAP_R: |
| 6339 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6340 | { |
| 6341 | return false; |
| 6342 | } |
| 6343 | break; |
| 6344 | |
| 6345 | case GL_TEXTURE_MIN_FILTER: |
| 6346 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6347 | { |
| 6348 | return false; |
| 6349 | } |
| 6350 | break; |
| 6351 | |
| 6352 | case GL_TEXTURE_MAG_FILTER: |
| 6353 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6354 | { |
| 6355 | return false; |
| 6356 | } |
| 6357 | break; |
| 6358 | |
| 6359 | case GL_TEXTURE_MIN_LOD: |
| 6360 | case GL_TEXTURE_MAX_LOD: |
| 6361 | // any value is permissible |
| 6362 | break; |
| 6363 | |
| 6364 | case GL_TEXTURE_COMPARE_MODE: |
| 6365 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6366 | { |
| 6367 | return false; |
| 6368 | } |
| 6369 | break; |
| 6370 | |
| 6371 | case GL_TEXTURE_COMPARE_FUNC: |
| 6372 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6373 | { |
| 6374 | return false; |
| 6375 | } |
| 6376 | break; |
| 6377 | |
| 6378 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6379 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6380 | { |
| 6381 | return false; |
| 6382 | } |
| 6383 | break; |
| 6384 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6385 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6386 | { |
| 6387 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6388 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6389 | { |
| 6390 | return false; |
| 6391 | } |
| 6392 | } |
| 6393 | break; |
| 6394 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6395 | case GL_TEXTURE_BORDER_COLOR: |
| 6396 | if (!context->getExtensions().textureBorderClamp) |
| 6397 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6398 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6399 | return false; |
| 6400 | } |
| 6401 | if (!vectorParams) |
| 6402 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6403 | context->validationError(GL_INVALID_ENUM, kErrorInsufficientBufferSize); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6404 | return false; |
| 6405 | } |
| 6406 | break; |
| 6407 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6408 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6409 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6410 | return false; |
| 6411 | } |
| 6412 | |
| 6413 | return true; |
| 6414 | } |
| 6415 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6416 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLfloat *); |
| 6417 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, bool, GLint *); |
| 6418 | template bool ValidateSamplerParameterBase(Context *, |
| 6419 | GLuint, |
| 6420 | GLenum, |
| 6421 | GLsizei, |
| 6422 | bool, |
| 6423 | const GLuint *); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6424 | |
| 6425 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6426 | GLuint sampler, |
| 6427 | GLenum pname, |
| 6428 | GLsizei *length) |
| 6429 | { |
| 6430 | if (length) |
| 6431 | { |
| 6432 | *length = 0; |
| 6433 | } |
| 6434 | |
| 6435 | if (context->getClientMajorVersion() < 3) |
| 6436 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6437 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6438 | return false; |
| 6439 | } |
| 6440 | |
| 6441 | if (!context->isSampler(sampler)) |
| 6442 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6443 | context->validationError(GL_INVALID_OPERATION, kErrorInvalidSampler); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6444 | return false; |
| 6445 | } |
| 6446 | |
| 6447 | switch (pname) |
| 6448 | { |
| 6449 | case GL_TEXTURE_WRAP_S: |
| 6450 | case GL_TEXTURE_WRAP_T: |
| 6451 | case GL_TEXTURE_WRAP_R: |
| 6452 | case GL_TEXTURE_MIN_FILTER: |
| 6453 | case GL_TEXTURE_MAG_FILTER: |
| 6454 | case GL_TEXTURE_MIN_LOD: |
| 6455 | case GL_TEXTURE_MAX_LOD: |
| 6456 | case GL_TEXTURE_COMPARE_MODE: |
| 6457 | case GL_TEXTURE_COMPARE_FUNC: |
| 6458 | break; |
| 6459 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6460 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6461 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6462 | { |
| 6463 | return false; |
| 6464 | } |
| 6465 | break; |
| 6466 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6467 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6468 | if (!context->getExtensions().textureSRGBDecode) |
| 6469 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6470 | context->validationError(GL_INVALID_ENUM, |
| 6471 | "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6472 | return false; |
| 6473 | } |
| 6474 | break; |
| 6475 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6476 | case GL_TEXTURE_BORDER_COLOR: |
| 6477 | if (!context->getExtensions().textureBorderClamp) |
| 6478 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6479 | context->validationError(GL_INVALID_ENUM, kErrorExtensionNotEnabled); |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6480 | return false; |
| 6481 | } |
| 6482 | break; |
| 6483 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6484 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6485 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6486 | return false; |
| 6487 | } |
| 6488 | |
| 6489 | if (length) |
| 6490 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 6491 | *length = GetSamplerParameterCount(pname); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6492 | } |
| 6493 | return true; |
| 6494 | } |
| 6495 | |
| 6496 | bool ValidateGetInternalFormativBase(Context *context, |
| 6497 | GLenum target, |
| 6498 | GLenum internalformat, |
| 6499 | GLenum pname, |
| 6500 | GLsizei bufSize, |
| 6501 | GLsizei *numParams) |
| 6502 | { |
| 6503 | if (numParams) |
| 6504 | { |
| 6505 | *numParams = 0; |
| 6506 | } |
| 6507 | |
| 6508 | if (context->getClientMajorVersion() < 3) |
| 6509 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6510 | context->validationError(GL_INVALID_OPERATION, kErrorES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6511 | return false; |
| 6512 | } |
| 6513 | |
| 6514 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6515 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6516 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6517 | context->validationError(GL_INVALID_ENUM, "Internal format is not renderable."); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6518 | return false; |
| 6519 | } |
| 6520 | |
| 6521 | switch (target) |
| 6522 | { |
| 6523 | case GL_RENDERBUFFER: |
| 6524 | break; |
| 6525 | |
| 6526 | case GL_TEXTURE_2D_MULTISAMPLE: |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6527 | if (context->getClientVersion() < ES_3_1 && |
| 6528 | !context->getExtensions().textureMultisample) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6529 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6530 | context->validationError(GL_INVALID_ENUM, |
| 6531 | kErrorMultisampleTextureExtensionOrES31Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6532 | return false; |
| 6533 | } |
| 6534 | break; |
Olli Etuaho | 064458a | 2018-08-30 14:02:02 +0300 | [diff] [blame] | 6535 | case GL_TEXTURE_2D_MULTISAMPLE_ARRAY_OES: |
| 6536 | if (!context->getExtensions().textureStorageMultisample2DArray) |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6537 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6538 | context->validationError(GL_INVALID_ENUM, kErrorMultisampleArrayExtensionRequired); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6539 | return false; |
| 6540 | } |
| 6541 | break; |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6542 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6543 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTarget); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6544 | return false; |
| 6545 | } |
| 6546 | |
| 6547 | if (bufSize < 0) |
| 6548 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6549 | context->validationError(GL_INVALID_VALUE, kErrorInsufficientBufferSize); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6550 | return false; |
| 6551 | } |
| 6552 | |
| 6553 | GLsizei maxWriteParams = 0; |
| 6554 | switch (pname) |
| 6555 | { |
| 6556 | case GL_NUM_SAMPLE_COUNTS: |
| 6557 | maxWriteParams = 1; |
| 6558 | break; |
| 6559 | |
| 6560 | case GL_SAMPLES: |
| 6561 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6562 | break; |
| 6563 | |
| 6564 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6565 | context->validationError(GL_INVALID_ENUM, kErrorEnumNotSupported); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6566 | return false; |
| 6567 | } |
| 6568 | |
| 6569 | if (numParams) |
| 6570 | { |
| 6571 | // glGetInternalFormativ will not overflow bufSize |
| 6572 | *numParams = std::min(bufSize, maxWriteParams); |
| 6573 | } |
| 6574 | |
| 6575 | return true; |
| 6576 | } |
| 6577 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6578 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6579 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6580 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6581 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6582 | context->validationError(GL_INVALID_OPERATION, |
| 6583 | kErrorInvalidMultisampledFramebufferOperation); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6584 | return false; |
| 6585 | } |
| 6586 | return true; |
| 6587 | } |
| 6588 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6589 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6590 | { |
| 6591 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6592 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6593 | context->validationError(GL_INVALID_ENUM, kErrorInvalidMultitextureUnit); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6594 | return false; |
| 6595 | } |
| 6596 | return true; |
| 6597 | } |
| 6598 | |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6599 | bool ValidateTexStorageMultisample(Context *context, |
| 6600 | TextureType target, |
| 6601 | GLsizei samples, |
| 6602 | GLint internalFormat, |
| 6603 | GLsizei width, |
| 6604 | GLsizei height) |
| 6605 | { |
| 6606 | const Caps &caps = context->getCaps(); |
| 6607 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 6608 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
| 6609 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6610 | context->validationError(GL_INVALID_VALUE, kErrorTextureWidthOrHeightOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6611 | return false; |
| 6612 | } |
| 6613 | |
| 6614 | if (samples == 0) |
| 6615 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6616 | context->validationError(GL_INVALID_VALUE, kErrorSamplesZero); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6617 | return false; |
| 6618 | } |
| 6619 | |
| 6620 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalFormat); |
| 6621 | if (!formatCaps.textureAttachment) |
| 6622 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6623 | context->validationError(GL_INVALID_ENUM, kErrorRenderableInternalFormat); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6624 | return false; |
| 6625 | } |
| 6626 | |
| 6627 | // The ES3.1 spec(section 8.8) states that an INVALID_ENUM error is generated if internalformat |
| 6628 | // is one of the unsized base internalformats listed in table 8.11. |
| 6629 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalFormat); |
| 6630 | if (formatInfo.internalFormat == GL_NONE) |
| 6631 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6632 | context->validationError(GL_INVALID_ENUM, kErrorUnsizedInternalFormatUnsupported); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6633 | return false; |
| 6634 | } |
| 6635 | |
| 6636 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 6637 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6638 | context->validationError(GL_INVALID_OPERATION, kErrorSamplesOutOfRange); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6639 | return false; |
| 6640 | } |
| 6641 | |
| 6642 | Texture *texture = context->getTargetTexture(target); |
| 6643 | if (!texture || texture->id() == 0) |
| 6644 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6645 | context->validationError(GL_INVALID_OPERATION, kErrorZeroBoundToTarget); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6646 | return false; |
| 6647 | } |
| 6648 | |
| 6649 | if (texture->getImmutableFormat()) |
| 6650 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6651 | context->validationError(GL_INVALID_OPERATION, kErrorImmutableTextureBound); |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 6652 | return false; |
| 6653 | } |
| 6654 | return true; |
| 6655 | } |
| 6656 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6657 | bool ValidateTexStorage2DMultisampleBase(Context *context, |
| 6658 | TextureType target, |
| 6659 | GLsizei samples, |
| 6660 | GLint internalFormat, |
| 6661 | GLsizei width, |
| 6662 | GLsizei height) |
| 6663 | { |
| 6664 | if (target != TextureType::_2DMultisample) |
| 6665 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6666 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTarget); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6667 | return false; |
| 6668 | } |
| 6669 | |
| 6670 | if (width < 1 || height < 1) |
| 6671 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6672 | context->validationError(GL_INVALID_VALUE, kErrorTextureSizeTooSmall); |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6673 | return false; |
| 6674 | } |
| 6675 | |
| 6676 | return ValidateTexStorageMultisample(context, target, samples, internalFormat, width, height); |
| 6677 | } |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6678 | |
| 6679 | bool ValidateGetTexLevelParameterBase(Context *context, |
| 6680 | TextureTarget target, |
| 6681 | GLint level, |
| 6682 | GLenum pname, |
| 6683 | GLsizei *length) |
| 6684 | { |
| 6685 | |
| 6686 | if (length) |
| 6687 | { |
| 6688 | *length = 0; |
| 6689 | } |
| 6690 | |
| 6691 | TextureType type = TextureTargetToType(target); |
| 6692 | |
| 6693 | if (!ValidTexLevelDestinationTarget(context, type)) |
| 6694 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6695 | context->validationError(GL_INVALID_ENUM, kErrorInvalidTextureTarget); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6696 | return false; |
| 6697 | } |
| 6698 | |
| 6699 | if (context->getTargetTexture(type) == nullptr) |
| 6700 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6701 | context->validationError(GL_INVALID_ENUM, "No texture bound."); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6702 | return false; |
| 6703 | } |
| 6704 | |
| 6705 | if (!ValidMipLevel(context, type, level)) |
| 6706 | { |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6707 | context->validationError(GL_INVALID_VALUE, kErrorInvalidMipLevel); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6708 | return false; |
| 6709 | } |
| 6710 | |
| 6711 | switch (pname) |
| 6712 | { |
| 6713 | case GL_TEXTURE_RED_TYPE: |
| 6714 | case GL_TEXTURE_GREEN_TYPE: |
| 6715 | case GL_TEXTURE_BLUE_TYPE: |
| 6716 | case GL_TEXTURE_ALPHA_TYPE: |
| 6717 | case GL_TEXTURE_DEPTH_TYPE: |
| 6718 | break; |
| 6719 | case GL_TEXTURE_RED_SIZE: |
| 6720 | case GL_TEXTURE_GREEN_SIZE: |
| 6721 | case GL_TEXTURE_BLUE_SIZE: |
| 6722 | case GL_TEXTURE_ALPHA_SIZE: |
| 6723 | case GL_TEXTURE_DEPTH_SIZE: |
| 6724 | case GL_TEXTURE_STENCIL_SIZE: |
| 6725 | case GL_TEXTURE_SHARED_SIZE: |
| 6726 | break; |
| 6727 | case GL_TEXTURE_INTERNAL_FORMAT: |
| 6728 | case GL_TEXTURE_WIDTH: |
| 6729 | case GL_TEXTURE_HEIGHT: |
| 6730 | case GL_TEXTURE_DEPTH: |
| 6731 | break; |
| 6732 | case GL_TEXTURE_SAMPLES: |
| 6733 | case GL_TEXTURE_FIXED_SAMPLE_LOCATIONS: |
| 6734 | break; |
| 6735 | case GL_TEXTURE_COMPRESSED: |
| 6736 | break; |
| 6737 | default: |
Jamie Madill | 610640f | 2018-11-21 17:28:41 -0500 | [diff] [blame] | 6738 | context->validationError(GL_INVALID_ENUM, kErrorInvalidPname); |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 6739 | return false; |
| 6740 | } |
| 6741 | |
| 6742 | if (length) |
| 6743 | { |
| 6744 | *length = 1; |
| 6745 | } |
| 6746 | return true; |
| 6747 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6748 | } // namespace gl |