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 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Jamie Madill | 5ea762a | 2017-06-07 14:59:51 -0400 | [diff] [blame] | 11 | #include "anglebase/numerics/safe_conversions.h" |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 12 | #include "common/mathutil.h" |
| 13 | #include "common/utilities.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 15 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Framebuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Renderbuffer.h" |
| 19 | #include "libANGLE/Texture.h" |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 20 | #include "libANGLE/VertexArray.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 21 | #include "libANGLE/formatutils.h" |
| 22 | #include "libANGLE/validationES.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 23 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 24 | using namespace angle; |
| 25 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 26 | namespace gl |
| 27 | { |
| 28 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 29 | namespace |
| 30 | { |
| 31 | bool ValidateFramebufferTextureMultiviewBaseANGLE(Context *context, |
| 32 | GLenum target, |
| 33 | GLenum attachment, |
| 34 | GLuint texture, |
| 35 | GLint level, |
| 36 | GLsizei numViews) |
| 37 | { |
| 38 | if (!context->getExtensions().multiview) |
| 39 | { |
| 40 | context->handleError(InvalidOperation() << "ANGLE_multiview is not available."); |
| 41 | return false; |
| 42 | } |
| 43 | |
| 44 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 45 | { |
| 46 | return false; |
| 47 | } |
| 48 | |
Martin Radev | 14b2126 | 2017-08-25 13:54:37 +0300 | [diff] [blame] | 49 | if (texture != 0 && numViews < 1) |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 50 | { |
| 51 | context->handleError(InvalidValue() << "numViews cannot be less than 1."); |
| 52 | return false; |
| 53 | } |
| 54 | |
| 55 | const Extensions &extensions = context->getExtensions(); |
| 56 | if (static_cast<GLuint>(numViews) > extensions.maxViews) |
| 57 | { |
| 58 | context->handleError(InvalidValue() |
| 59 | << "numViews cannot be greater than GL_MAX_VIEWS_ANGLE."); |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | return true; |
| 64 | } |
| 65 | |
| 66 | bool ValidateFramebufferTextureMultiviewLevelAndFormat(Context *context, |
| 67 | Texture *texture, |
| 68 | GLint level) |
| 69 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 70 | TextureType type = texture->getType(); |
| 71 | if (!ValidMipLevel(context, type, level)) |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 72 | { |
| 73 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
| 74 | return false; |
| 75 | } |
| 76 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 77 | const auto &format = texture->getFormat(NonCubeTextureTypeToTarget(type), level); |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 78 | if (format.info->compressed) |
| 79 | { |
| 80 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), CompressedTexturesNotAttachable); |
| 81 | return false; |
| 82 | } |
| 83 | return true; |
| 84 | } |
| 85 | |
Jamie Madill | ff325f1 | 2017-08-26 15:06:05 -0400 | [diff] [blame] | 86 | bool ValidateUniformES3(Context *context, GLenum uniformType, GLint location, GLint count) |
| 87 | { |
| 88 | if (context->getClientMajorVersion() < 3) |
| 89 | { |
| 90 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | return ValidateUniform(context, uniformType, location, count); |
| 95 | } |
| 96 | |
Jamie Madill | c8c9581 | 2017-08-26 18:40:09 -0400 | [diff] [blame] | 97 | bool ValidateUniformMatrixES3(Context *context, |
| 98 | GLenum valueType, |
| 99 | GLint location, |
| 100 | GLsizei count, |
| 101 | GLboolean transpose) |
| 102 | { |
| 103 | // Check for ES3 uniform entry points |
| 104 | if (context->getClientMajorVersion() < 3) |
| 105 | { |
| 106 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | return ValidateUniformMatrix(context, valueType, location, count, transpose); |
| 111 | } |
| 112 | |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 113 | bool ValidateGenOrDeleteES3(Context *context, GLint n) |
| 114 | { |
| 115 | if (context->getClientMajorVersion() < 3) |
| 116 | { |
| 117 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 118 | return false; |
| 119 | } |
| 120 | return ValidateGenOrDelete(context, n); |
| 121 | } |
| 122 | |
| 123 | bool ValidateGenOrDeleteCountES3(Context *context, GLint count) |
| 124 | { |
| 125 | if (context->getClientMajorVersion() < 3) |
| 126 | { |
| 127 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 128 | return false; |
| 129 | } |
| 130 | if (count < 0) |
| 131 | { |
| 132 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 133 | return false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 138 | bool ValidateCopyTexture3DCommon(Context *context, |
| 139 | const Texture *source, |
| 140 | GLint sourceLevel, |
| 141 | GLint srcInternalFormat, |
| 142 | const Texture *dest, |
| 143 | GLint destLevel, |
| 144 | GLint internalFormat, |
| 145 | TextureTarget destTarget) |
| 146 | { |
| 147 | if (context->getClientMajorVersion() < 3) |
| 148 | { |
| 149 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 150 | return false; |
| 151 | } |
| 152 | |
| 153 | if (!context->getExtensions().copyTexture3d) |
| 154 | { |
| 155 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ANGLECopyTexture3DUnavailable); |
| 156 | return false; |
| 157 | } |
| 158 | |
| 159 | if (!ValidTexture3DTarget(context, source->getType())) |
| 160 | { |
| 161 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | // Table 1.1 from the ANGLE_copy_texture_3d spec |
| 166 | switch (GetUnsizedFormat(srcInternalFormat)) |
| 167 | { |
| 168 | case GL_ALPHA: |
| 169 | case GL_LUMINANCE: |
| 170 | case GL_LUMINANCE_ALPHA: |
| 171 | case GL_RED: |
| 172 | case GL_RED_INTEGER: |
| 173 | case GL_RG: |
| 174 | case GL_RG_INTEGER: |
| 175 | case GL_RGB: |
| 176 | case GL_RGB_INTEGER: |
| 177 | case GL_RGBA: |
| 178 | case GL_RGBA_INTEGER: |
| 179 | case GL_DEPTH_COMPONENT: |
| 180 | case GL_DEPTH_STENCIL: |
| 181 | break; |
| 182 | default: |
| 183 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
| 184 | return false; |
| 185 | } |
| 186 | |
| 187 | if (!ValidTexture3DTarget(context, TextureTargetToType(destTarget))) |
| 188 | { |
| 189 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
| 190 | return false; |
| 191 | } |
| 192 | |
| 193 | // Table 1.0 from the ANGLE_copy_texture_3d spec |
| 194 | switch (internalFormat) |
| 195 | { |
| 196 | case GL_RGB: |
| 197 | case GL_RGBA: |
| 198 | case GL_LUMINANCE: |
| 199 | case GL_LUMINANCE_ALPHA: |
| 200 | case GL_ALPHA: |
| 201 | case GL_R8: |
| 202 | case GL_R8_SNORM: |
| 203 | case GL_R16F: |
| 204 | case GL_R32F: |
| 205 | case GL_R8UI: |
| 206 | case GL_R8I: |
| 207 | case GL_R16UI: |
| 208 | case GL_R16I: |
| 209 | case GL_R32UI: |
| 210 | case GL_R32I: |
| 211 | case GL_RG: |
| 212 | case GL_RG8: |
| 213 | case GL_RG8_SNORM: |
| 214 | case GL_RG16F: |
| 215 | case GL_RG32F: |
| 216 | case GL_RG8UI: |
| 217 | case GL_RG8I: |
| 218 | case GL_RG16UI: |
| 219 | case GL_RG16I: |
| 220 | case GL_RG32UI: |
| 221 | case GL_RG32I: |
| 222 | case GL_RGB8: |
| 223 | case GL_SRGB8: |
| 224 | case GL_RGB565: |
| 225 | case GL_RGB8_SNORM: |
| 226 | case GL_R11F_G11F_B10F: |
| 227 | case GL_RGB9_E5: |
| 228 | case GL_RGB16F: |
| 229 | case GL_RGB32F: |
| 230 | case GL_RGB8UI: |
| 231 | case GL_RGB8I: |
| 232 | case GL_RGB16UI: |
| 233 | case GL_RGB16I: |
| 234 | case GL_RGB32UI: |
| 235 | case GL_RGB32I: |
| 236 | case GL_RGBA8: |
| 237 | case GL_SRGB8_ALPHA8: |
| 238 | case GL_RGBA8_SNORM: |
| 239 | case GL_RGB5_A1: |
| 240 | case GL_RGBA4: |
| 241 | case GL_RGB10_A2: |
| 242 | case GL_RGBA16F: |
| 243 | case GL_RGBA32F: |
| 244 | case GL_RGBA8UI: |
| 245 | case GL_RGBA8I: |
| 246 | case GL_RGB10_A2UI: |
| 247 | case GL_RGBA16UI: |
| 248 | case GL_RGBA16I: |
| 249 | case GL_RGBA32I: |
| 250 | case GL_RGBA32UI: |
| 251 | break; |
| 252 | default: |
| 253 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
| 254 | return false; |
| 255 | } |
| 256 | |
| 257 | return true; |
| 258 | } |
Jamie Madill | ff325f1 | 2017-08-26 15:06:05 -0400 | [diff] [blame] | 259 | } // anonymous namespace |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 260 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 261 | static bool ValidateTexImageFormatCombination(gl::Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 262 | TextureType target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 263 | GLenum internalFormat, |
| 264 | GLenum format, |
| 265 | GLenum type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 266 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 267 | |
| 268 | // The type and format are valid if any supported internal format has that type and format |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 269 | if (!ValidES3Format(format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 270 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 271 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 272 | return false; |
| 273 | } |
| 274 | |
| 275 | if (!ValidES3Type(type)) |
| 276 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 277 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 278 | return false; |
| 279 | } |
| 280 | |
| 281 | // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a |
| 282 | // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE |
| 283 | // error instead of a GL_INVALID_ENUM error. As this validation function is only called in |
| 284 | // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error. |
| 285 | if (!ValidES3InternalFormat(internalFormat)) |
| 286 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 287 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 288 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 289 | } |
| 290 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 291 | // From the ES 3.0 spec section 3.8.3: |
| 292 | // Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL are supported by |
| 293 | // texture image specification commands only if target is TEXTURE_2D, TEXTURE_2D_ARRAY, or |
| 294 | // TEXTURE_CUBE_MAP.Using these formats in conjunction with any other target will result in an |
| 295 | // INVALID_OPERATION error. |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 296 | if (target == TextureType::_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 297 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 298 | context->handleError(InvalidOperation() << "Format cannot be GL_DEPTH_COMPONENT or " |
| 299 | "GL_DEPTH_STENCIL if target is " |
| 300 | "GL_TEXTURE_3D"); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 301 | return false; |
| 302 | } |
| 303 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 304 | // Check if this is a valid format combination to load texture data |
Jamie Madill | 55e9821 | 2016-10-05 16:39:13 -0400 | [diff] [blame] | 305 | if (!ValidES3FormatCombination(format, type, internalFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 306 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 307 | context->handleError(InvalidOperation() |
| 308 | << "Invalid combination of format, type and internalFormat."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 309 | return false; |
| 310 | } |
| 311 | |
| 312 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); |
| 313 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 314 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 315 | context->handleError(InvalidOperation() << "Unsupported internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 316 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | return true; |
| 320 | } |
| 321 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 322 | bool ValidateES3TexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 323 | TextureTarget target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 324 | GLint level, |
| 325 | GLenum internalformat, |
| 326 | bool isCompressed, |
| 327 | bool isSubImage, |
| 328 | GLint xoffset, |
| 329 | GLint yoffset, |
| 330 | GLint zoffset, |
| 331 | GLsizei width, |
| 332 | GLsizei height, |
| 333 | GLsizei depth, |
| 334 | GLint border, |
| 335 | GLenum format, |
| 336 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 337 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 338 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 339 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 340 | TextureType texType = TextureTargetToType(target); |
| 341 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 342 | // Validate image size |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 343 | if (!ValidImageSizeParameters(context, texType, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 344 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 345 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 346 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 349 | // Verify zero border |
| 350 | if (border != 0) |
| 351 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 352 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 353 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 354 | } |
| 355 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 356 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 357 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 358 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 359 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 360 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 361 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 362 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 365 | const gl::Caps &caps = context->getCaps(); |
| 366 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 367 | switch (texType) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 368 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 369 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 370 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 371 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 372 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 373 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 374 | return false; |
| 375 | } |
| 376 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 377 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 378 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 379 | ASSERT(level == 0); |
| 380 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 381 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize) |
| 382 | { |
| 383 | context->handleError(InvalidValue()); |
| 384 | return false; |
| 385 | } |
| 386 | if (isCompressed) |
| 387 | { |
| 388 | context->handleError(InvalidEnum() |
| 389 | << "Rectangle texture cannot have a compressed format."); |
| 390 | return false; |
| 391 | } |
| 392 | break; |
| 393 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 394 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 395 | if (!isSubImage && width != height) |
| 396 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 397 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 398 | return false; |
| 399 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 400 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 401 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 402 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 403 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 404 | return false; |
| 405 | } |
| 406 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 407 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 408 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 409 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 410 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 411 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
| 412 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 413 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 414 | return false; |
| 415 | } |
| 416 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 417 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 418 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 419 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 420 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
| 421 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
| 422 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 423 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 424 | return false; |
| 425 | } |
| 426 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 427 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 428 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 429 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 430 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 431 | } |
| 432 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 433 | gl::Texture *texture = context->getTargetTexture(texType); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 434 | if (!texture) |
| 435 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 436 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 437 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 438 | } |
| 439 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 440 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 441 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 442 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 443 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | // Validate texture formats |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 447 | GLenum actualInternalFormat = |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 448 | isSubImage ? texture->getFormat(target, level).info->internalFormat : internalformat; |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 449 | if (isSubImage && actualInternalFormat == GL_NONE) |
| 450 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 451 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 452 | return false; |
| 453 | } |
| 454 | |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 455 | const gl::InternalFormat &actualFormatInfo = isSubImage |
| 456 | ? *texture->getFormat(target, level).info |
| 457 | : GetInternalFormatInfo(internalformat, type); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 458 | if (isCompressed) |
| 459 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 460 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 461 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 462 | context->handleError( |
| 463 | InvalidEnum() << "internalformat is not a supported compressed internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 464 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 465 | } |
| 466 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 467 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 468 | { |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 469 | if (!ValidCompressedSubImageSize( |
| 470 | context, actualFormatInfo.internalFormat, xoffset, yoffset, width, height, |
| 471 | texture->getWidth(target, level), texture->getHeight(target, level))) |
| 472 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 473 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 474 | return false; |
| 475 | } |
| 476 | |
| 477 | if (format != actualInternalFormat) |
| 478 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 479 | context->handleError(InvalidOperation() |
| 480 | << "Format must match the internal format of the texture."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 481 | return false; |
| 482 | } |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 483 | |
| 484 | if (actualInternalFormat == GL_ETC1_RGB8_OES) |
| 485 | { |
| 486 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidInternalFormat); |
| 487 | return false; |
| 488 | } |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 489 | } |
| 490 | else |
| 491 | { |
| 492 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 493 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 494 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 495 | return false; |
| 496 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 499 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 500 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 501 | context->handleError(InvalidEnum()); |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 502 | return false; |
| 503 | } |
| 504 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 505 | if (texType == TextureType::_3D) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 506 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 507 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 508 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | else |
| 512 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 513 | if (!ValidateTexImageFormatCombination(context, texType, actualInternalFormat, format, |
| 514 | type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 515 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 516 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 517 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 518 | } |
| 519 | |
| 520 | // Validate sub image parameters |
| 521 | if (isSubImage) |
| 522 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 523 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 524 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 525 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 526 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 527 | } |
| 528 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 529 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 530 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 531 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 532 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 533 | } |
| 534 | |
| 535 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 536 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 537 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 538 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 539 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 540 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 541 | } |
| 542 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 543 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 544 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 545 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 546 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 547 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 548 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 549 | } |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 550 | |
| 551 | if (width > 0 && height > 0 && depth > 0 && pixels == nullptr && |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 552 | context->getGLState().getTargetBuffer(gl::BufferBinding::PixelUnpack) == nullptr) |
Geoff Lang | fb05264 | 2017-10-24 13:42:09 -0400 | [diff] [blame] | 553 | { |
| 554 | ANGLE_VALIDATION_ERR(context, InvalidValue(), PixelDataNull); |
| 555 | return false; |
| 556 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 559 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 560 | if (!ValidImageDataSize(context, texType, width, height, depth, sizeCheckFormat, type, pixels, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 561 | imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 562 | { |
| 563 | return false; |
| 564 | } |
| 565 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 566 | // Check for pixel unpack buffer related API errors |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 567 | gl::Buffer *pixelUnpackBuffer = |
| 568 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 569 | if (pixelUnpackBuffer != nullptr) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 570 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 571 | // ...data is not evenly divisible into the number of bytes needed to store in memory a |
| 572 | // datum |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 573 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 574 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 575 | { |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 576 | size_t offset = reinterpret_cast<size_t>(pixels); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 577 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 578 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 579 | if ((offset % dataBytesPerPixel) != 0) |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 580 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 581 | context->handleError(InvalidOperation() |
| 582 | << "Reads would overflow the pixel unpack buffer."); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 583 | return false; |
| 584 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 585 | } |
| 586 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 587 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 588 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 589 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 590 | context->handleError(InvalidOperation() << "Pixel unpack buffer is mapped."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 591 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 592 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 595 | return true; |
| 596 | } |
| 597 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 598 | bool ValidateES3TexImage2DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 599 | TextureTarget target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 600 | GLint level, |
| 601 | GLenum internalformat, |
| 602 | bool isCompressed, |
| 603 | bool isSubImage, |
| 604 | GLint xoffset, |
| 605 | GLint yoffset, |
| 606 | GLint zoffset, |
| 607 | GLsizei width, |
| 608 | GLsizei height, |
| 609 | GLsizei depth, |
| 610 | GLint border, |
| 611 | GLenum format, |
| 612 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 613 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 614 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 615 | { |
| 616 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 617 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 618 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 619 | return false; |
| 620 | } |
| 621 | |
| 622 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 623 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 624 | depth, border, format, type, imageSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | bool ValidateES3TexImage3DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 628 | TextureType target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 629 | GLint level, |
| 630 | GLenum internalformat, |
| 631 | bool isCompressed, |
| 632 | bool isSubImage, |
| 633 | GLint xoffset, |
| 634 | GLint yoffset, |
| 635 | GLint zoffset, |
| 636 | GLsizei width, |
| 637 | GLsizei height, |
| 638 | GLsizei depth, |
| 639 | GLint border, |
| 640 | GLenum format, |
| 641 | GLenum type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 642 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 643 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 644 | { |
| 645 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 646 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 647 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 648 | return false; |
| 649 | } |
| 650 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 651 | if (IsETC2EACFormat(format) && target != TextureType::_2DArray) |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 652 | { |
| 653 | // ES 3.1, Section 8.7, page 169. |
| 654 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InternalFormatRequiresTexture2DArray); |
| 655 | return false; |
| 656 | } |
| 657 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 658 | return ValidateES3TexImageParametersBase(context, NonCubeTextureTypeToTarget(target), level, |
| 659 | internalformat, isCompressed, isSubImage, xoffset, |
| 660 | yoffset, zoffset, width, height, depth, border, format, |
| 661 | type, bufSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 662 | } |
| 663 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 664 | struct EffectiveInternalFormatInfo |
| 665 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 666 | GLenum effectiveFormat; |
| 667 | GLenum destFormat; |
| 668 | GLuint minRedBits; |
| 669 | GLuint maxRedBits; |
| 670 | GLuint minGreenBits; |
| 671 | GLuint maxGreenBits; |
| 672 | GLuint minBlueBits; |
| 673 | GLuint maxBlueBits; |
| 674 | GLuint minAlphaBits; |
| 675 | GLuint maxAlphaBits; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 676 | }; |
| 677 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 678 | static bool QueryEffectiveFormatList(const InternalFormat &srcFormat, |
| 679 | GLenum targetFormat, |
| 680 | const EffectiveInternalFormatInfo *list, |
| 681 | size_t size, |
| 682 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 683 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 684 | for (size_t curFormat = 0; curFormat < size; ++curFormat) |
| 685 | { |
| 686 | const EffectiveInternalFormatInfo &formatInfo = list[curFormat]; |
| 687 | if ((formatInfo.destFormat == targetFormat) && |
| 688 | (formatInfo.minRedBits <= srcFormat.redBits && |
| 689 | formatInfo.maxRedBits >= srcFormat.redBits) && |
| 690 | (formatInfo.minGreenBits <= srcFormat.greenBits && |
| 691 | formatInfo.maxGreenBits >= srcFormat.greenBits) && |
| 692 | (formatInfo.minBlueBits <= srcFormat.blueBits && |
| 693 | formatInfo.maxBlueBits >= srcFormat.blueBits) && |
| 694 | (formatInfo.minAlphaBits <= srcFormat.alphaBits && |
| 695 | formatInfo.maxAlphaBits >= srcFormat.alphaBits)) |
| 696 | { |
| 697 | *outEffectiveFormat = formatInfo.effectiveFormat; |
| 698 | return true; |
| 699 | } |
| 700 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 701 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 702 | *outEffectiveFormat = GL_NONE; |
| 703 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 704 | } |
| 705 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 706 | bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 707 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 708 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 709 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 710 | // Effective internal format coresponding to destination internal format and linear source |
| 711 | // buffer component sizes. |
| 712 | // | Source channel min/max sizes | |
| 713 | // Effective Internal Format | N/A | R | G | B | A | |
| 714 | // clang-format off |
| 715 | constexpr EffectiveInternalFormatInfo list[] = { |
| 716 | { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 }, |
| 717 | { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 }, |
| 718 | { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 }, |
| 719 | { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 }, |
| 720 | { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 }, |
| 721 | { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 722 | { GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 723 | { GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 }, |
| 724 | { GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 }, |
| 725 | }; |
| 726 | // clang-format on |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 727 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 728 | return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat); |
| 729 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 730 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 731 | bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 732 | const InternalFormat &destFormat, |
| 733 | GLenum *outEffectiveFormat) |
| 734 | { |
| 735 | constexpr GLuint umax = UINT_MAX; |
| 736 | |
| 737 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 738 | // Effective internal format coresponding to destination internal format andlinear source buffer |
| 739 | // component sizes. |
| 740 | // | Source channel min/max sizes | |
| 741 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 742 | // clang-format off |
| 743 | constexpr EffectiveInternalFormatInfo list[] = { |
| 744 | { GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 }, |
| 745 | { GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax }, |
| 746 | { GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 }, |
| 747 | { GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax }, |
| 748 | { GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax }, |
| 749 | { GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 750 | { GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 751 | { GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 }, |
| 752 | }; |
| 753 | // clang-format on |
| 754 | |
| 755 | return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list), |
| 756 | outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 757 | } |
| 758 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 759 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, |
| 760 | const InternalFormat &destFormat, |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 761 | GLenum *outEffectiveFormat) |
| 762 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 763 | if (destFormat.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 764 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 765 | return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 766 | } |
| 767 | else |
| 768 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 769 | return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 770 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 771 | } |
| 772 | |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 773 | static bool EqualOrFirstZero(GLuint first, GLuint second) |
| 774 | { |
| 775 | return first == 0 || first == second; |
| 776 | } |
| 777 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 778 | static bool IsValidES3CopyTexImageCombination(const InternalFormat &textureFormatInfo, |
| 779 | const InternalFormat &framebufferFormatInfo, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 780 | GLuint readBufferHandle) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 781 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 782 | if (!ValidES3CopyConversion(textureFormatInfo.format, framebufferFormatInfo.format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 783 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 784 | return false; |
| 785 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 786 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 787 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 788 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 789 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 790 | // conversion between fixed and floating point. |
| 791 | |
| 792 | if ((textureFormatInfo.colorEncoding == GL_SRGB) != |
| 793 | (framebufferFormatInfo.colorEncoding == GL_SRGB)) |
| 794 | { |
| 795 | return false; |
| 796 | } |
| 797 | |
| 798 | if (((textureFormatInfo.componentType == GL_INT) != |
| 799 | (framebufferFormatInfo.componentType == GL_INT)) || |
| 800 | ((textureFormatInfo.componentType == GL_UNSIGNED_INT) != |
| 801 | (framebufferFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 802 | { |
| 803 | return false; |
| 804 | } |
| 805 | |
| 806 | if ((textureFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 807 | textureFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 808 | textureFormatInfo.componentType == GL_FLOAT) && |
| 809 | !(framebufferFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 810 | framebufferFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 811 | framebufferFormatInfo.componentType == GL_FLOAT)) |
| 812 | { |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 817 | // The effective internal format of the source buffer is determined with the following rules |
| 818 | // applied in order: |
| 819 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal |
| 820 | // format then the effective internal format is the source buffer's sized internal format. |
| 821 | // * If the source buffer is a texture that was created with an unsized base internal format, |
| 822 | // then the effective internal format is the source image array's effective internal |
| 823 | // format, as specified by table 3.12, which is determined from the <format> and <type> |
| 824 | // that were used when the source image array was specified by TexImage*. |
| 825 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 |
| 826 | // where Destination Internal Format matches internalformat and where the [source channel |
| 827 | // sizes] are consistent with the values of the source buffer's [channel sizes]. Table 3.17 |
| 828 | // is used if the FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the |
| 829 | // FRAMEBUFFER_ATTACHMENT_ENCODING is SRGB. |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 830 | const InternalFormat *sourceEffectiveFormat = nullptr; |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 831 | if (readBufferHandle != 0) |
| 832 | { |
| 833 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or |
| 834 | // renderbuffer |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 835 | if (framebufferFormatInfo.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 836 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 837 | sourceEffectiveFormat = &framebufferFormatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 838 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 839 | else |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 840 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 841 | // Renderbuffers cannot be created with an unsized internal format, so this must be an |
| 842 | // unsized-format texture. We can use the same table we use when creating textures to |
| 843 | // get its effective sized format. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 844 | sourceEffectiveFormat = |
| 845 | &GetSizedInternalFormatInfo(framebufferFormatInfo.sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 846 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 847 | } |
| 848 | else |
| 849 | { |
| 850 | // The effective internal format must be derived from the source framebuffer's channel |
| 851 | // sizes. This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 852 | if (framebufferFormatInfo.colorEncoding == GL_LINEAR) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 853 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 854 | GLenum effectiveFormat; |
| 855 | if (GetEffectiveInternalFormat(framebufferFormatInfo, textureFormatInfo, |
| 856 | &effectiveFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 857 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 858 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(effectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 859 | } |
| 860 | else |
| 861 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 862 | return false; |
| 863 | } |
| 864 | } |
| 865 | else if (framebufferFormatInfo.colorEncoding == GL_SRGB) |
| 866 | { |
| 867 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 868 | if (textureFormatInfo.sized && |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 869 | (framebufferFormatInfo.redBits >= 1 && framebufferFormatInfo.redBits <= 8) && |
| 870 | (framebufferFormatInfo.greenBits >= 1 && framebufferFormatInfo.greenBits <= 8) && |
| 871 | (framebufferFormatInfo.blueBits >= 1 && framebufferFormatInfo.blueBits <= 8) && |
| 872 | (framebufferFormatInfo.alphaBits >= 1 && framebufferFormatInfo.alphaBits <= 8)) |
| 873 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 874 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(GL_SRGB8_ALPHA8); |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 875 | } |
| 876 | else |
| 877 | { |
| 878 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 879 | } |
| 880 | } |
| 881 | else |
| 882 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 883 | UNREACHABLE(); |
| 884 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 885 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 886 | } |
| 887 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 888 | if (textureFormatInfo.sized) |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 889 | { |
| 890 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is |
| 891 | // sized, component sizes of the source and destination formats must exactly match if the |
| 892 | // destination format exists. |
| 893 | if (!EqualOrFirstZero(textureFormatInfo.redBits, sourceEffectiveFormat->redBits) || |
| 894 | !EqualOrFirstZero(textureFormatInfo.greenBits, sourceEffectiveFormat->greenBits) || |
| 895 | !EqualOrFirstZero(textureFormatInfo.blueBits, sourceEffectiveFormat->blueBits) || |
| 896 | !EqualOrFirstZero(textureFormatInfo.alphaBits, sourceEffectiveFormat->alphaBits)) |
| 897 | { |
| 898 | return false; |
| 899 | } |
| 900 | } |
| 901 | |
| 902 | return true; // A conversion function exists, and no rule in the specification has precluded |
| 903 | // conversion between these formats. |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 904 | } |
| 905 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 906 | bool ValidateES3CopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 907 | TextureTarget target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 908 | GLint level, |
| 909 | GLenum internalformat, |
| 910 | bool isSubImage, |
| 911 | GLint xoffset, |
| 912 | GLint yoffset, |
| 913 | GLint zoffset, |
| 914 | GLint x, |
| 915 | GLint y, |
| 916 | GLsizei width, |
| 917 | GLsizei height, |
| 918 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 919 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 920 | Format textureFormat = Format::Invalid(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 921 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 922 | xoffset, yoffset, zoffset, x, y, width, height, border, |
| 923 | &textureFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 924 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 925 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 926 | } |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 927 | ASSERT(textureFormat.valid() || !isSubImage); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 928 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 929 | const auto &state = context->getGLState(); |
| 930 | gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 931 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 932 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 933 | if (!ValidateFramebufferComplete(context, framebuffer)) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 934 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 935 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 936 | } |
| 937 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 938 | if (readFramebufferID != 0 && !ValidateFramebufferNotMultisampled(context, framebuffer)) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 939 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 940 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 941 | } |
| 942 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 943 | const FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 944 | |
Yunchao He | 096a6c8 | 2018-02-27 23:48:21 +0800 | [diff] [blame] | 945 | // According to ES 3.x spec, if the internalformat of the texture |
| 946 | // is RGB9_E5 and copy to such a texture, generate INVALID_OPERATION. |
| 947 | if (textureFormat.info->internalFormat == GL_RGB9_E5) |
| 948 | { |
| 949 | context->handleError(InvalidOperation()); |
| 950 | return false; |
| 951 | } |
| 952 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 953 | if (isSubImage) |
| 954 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 955 | if (!IsValidES3CopyTexImageCombination(*textureFormat.info, *source->getFormat().info, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 956 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 957 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 958 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 959 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 960 | } |
| 961 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 962 | else |
| 963 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 964 | // Use format/type from the source FBO. (Might not be perfect for all cases?) |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 965 | const InternalFormat &framebufferFormat = *source->getFormat().info; |
| 966 | const InternalFormat ©Format = GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 967 | if (!IsValidES3CopyTexImageCombination(copyFormat, framebufferFormat, readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 968 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 969 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 970 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 974 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 975 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 976 | } |
| 977 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 978 | bool ValidateES3CopyTexImage2DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 979 | TextureTarget target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 980 | GLint level, |
| 981 | GLenum internalformat, |
| 982 | bool isSubImage, |
| 983 | GLint xoffset, |
| 984 | GLint yoffset, |
| 985 | GLint zoffset, |
| 986 | GLint x, |
| 987 | GLint y, |
| 988 | GLsizei width, |
| 989 | GLsizei height, |
| 990 | GLint border) |
| 991 | { |
| 992 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 993 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 994 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 995 | return false; |
| 996 | } |
| 997 | |
| 998 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 999 | xoffset, yoffset, zoffset, x, y, width, height, |
| 1000 | border); |
| 1001 | } |
| 1002 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1003 | bool ValidateES3CopyTexImage3DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1004 | TextureType target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1005 | GLint level, |
| 1006 | GLenum internalformat, |
| 1007 | bool isSubImage, |
| 1008 | GLint xoffset, |
| 1009 | GLint yoffset, |
| 1010 | GLint zoffset, |
| 1011 | GLint x, |
| 1012 | GLint y, |
| 1013 | GLsizei width, |
| 1014 | GLsizei height, |
| 1015 | GLint border) |
| 1016 | { |
| 1017 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 1018 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1019 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1020 | return false; |
| 1021 | } |
| 1022 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1023 | return ValidateES3CopyTexImageParametersBase(context, NonCubeTextureTypeToTarget(target), level, |
| 1024 | internalformat, isSubImage, xoffset, yoffset, |
| 1025 | zoffset, x, y, width, height, border); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1026 | } |
| 1027 | |
| 1028 | bool ValidateES3TexStorageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1029 | TextureType target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1030 | GLsizei levels, |
| 1031 | GLenum internalformat, |
| 1032 | GLsizei width, |
| 1033 | GLsizei height, |
| 1034 | GLsizei depth) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1035 | { |
| 1036 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 1037 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1038 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1039 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1040 | } |
| 1041 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 1042 | GLsizei maxDim = std::max(width, height); |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1043 | if (target != TextureType::_2DArray) |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 1044 | { |
| 1045 | maxDim = std::max(maxDim, depth); |
| 1046 | } |
| 1047 | |
| 1048 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1049 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1050 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1051 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1052 | } |
| 1053 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1054 | const gl::Caps &caps = context->getCaps(); |
| 1055 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1056 | switch (target) |
| 1057 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1058 | case TextureType::_2D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1059 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1060 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1061 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1062 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1063 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1064 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1065 | } |
| 1066 | } |
| 1067 | break; |
| 1068 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1069 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1070 | { |
| 1071 | if (static_cast<GLuint>(width) > caps.maxRectangleTextureSize || |
| 1072 | static_cast<GLuint>(height) > caps.maxRectangleTextureSize || levels != 1) |
| 1073 | { |
| 1074 | context->handleError(InvalidValue()); |
| 1075 | return false; |
| 1076 | } |
| 1077 | } |
| 1078 | break; |
| 1079 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1080 | case TextureType::CubeMap: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1081 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1082 | if (width != height) |
| 1083 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1084 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1085 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1088 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1089 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1090 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1091 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | break; |
| 1095 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1096 | case TextureType::_3D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1097 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1098 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 1099 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 1100 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1101 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1102 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1103 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | break; |
| 1107 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1108 | case TextureType::_2DArray: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1109 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1110 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 1111 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 1112 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1113 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1114 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1115 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1116 | } |
| 1117 | } |
| 1118 | break; |
| 1119 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1120 | default: |
| 1121 | UNREACHABLE(); |
| 1122 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 1125 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1126 | if (!texture || texture->id() == 0) |
| 1127 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1128 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1129 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1130 | } |
| 1131 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 1132 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1133 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1134 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1135 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1136 | } |
| 1137 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1138 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1139 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1140 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1141 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1142 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1143 | } |
| 1144 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1145 | if (!formatInfo.sized) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1146 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1147 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1148 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1151 | if (formatInfo.compressed && target == TextureType::Rectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1152 | { |
| 1153 | context->handleError(InvalidEnum() << "Rectangle texture cannot have a compressed format."); |
| 1154 | return false; |
| 1155 | } |
| 1156 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1157 | return true; |
| 1158 | } |
| 1159 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1160 | bool ValidateES3TexStorage2DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1161 | TextureType target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1162 | GLsizei levels, |
| 1163 | GLenum internalformat, |
| 1164 | GLsizei width, |
| 1165 | GLsizei height, |
| 1166 | GLsizei depth) |
| 1167 | { |
| 1168 | if (!ValidTexture2DTarget(context, target)) |
| 1169 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1170 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1171 | return false; |
| 1172 | } |
| 1173 | |
| 1174 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 1175 | height, depth); |
| 1176 | } |
| 1177 | |
| 1178 | bool ValidateES3TexStorage3DParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1179 | TextureType target, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1180 | GLsizei levels, |
| 1181 | GLenum internalformat, |
| 1182 | GLsizei width, |
| 1183 | GLsizei height, |
| 1184 | GLsizei depth) |
| 1185 | { |
| 1186 | if (!ValidTexture3DTarget(context, target)) |
| 1187 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1188 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1189 | return false; |
| 1190 | } |
| 1191 | |
| 1192 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 1193 | height, depth); |
| 1194 | } |
| 1195 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1196 | bool ValidateBeginQuery(gl::Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1197 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1198 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1199 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1200 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
| 1204 | return ValidateBeginQueryBase(context, target, id); |
| 1205 | } |
| 1206 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1207 | bool ValidateEndQuery(gl::Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1208 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1209 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1210 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1211 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1212 | return false; |
| 1213 | } |
| 1214 | |
| 1215 | return ValidateEndQueryBase(context, target); |
| 1216 | } |
| 1217 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1218 | bool ValidateGetQueryiv(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1219 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1220 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1221 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1222 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1223 | return false; |
| 1224 | } |
| 1225 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1226 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1227 | } |
| 1228 | |
| 1229 | bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1230 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1231 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1232 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1233 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1234 | return false; |
| 1235 | } |
| 1236 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1237 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1238 | } |
| 1239 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1240 | bool ValidateFramebufferTextureLayer(Context *context, |
| 1241 | GLenum target, |
| 1242 | GLenum attachment, |
| 1243 | GLuint texture, |
| 1244 | GLint level, |
| 1245 | GLint layer) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1246 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1247 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1248 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1249 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1250 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1251 | } |
| 1252 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1253 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 1254 | { |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | const gl::Caps &caps = context->getCaps(); |
| 1259 | if (texture != 0) |
| 1260 | { |
Geoff Lang | 23e0284 | 2017-10-17 13:24:09 -0400 | [diff] [blame] | 1261 | if (layer < 0) |
| 1262 | { |
| 1263 | context->handleError(InvalidValue()); |
| 1264 | return false; |
| 1265 | } |
| 1266 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1267 | gl::Texture *tex = context->getTexture(texture); |
| 1268 | ASSERT(tex); |
| 1269 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 1270 | switch (tex->getType()) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1271 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 1272 | case TextureType::_2DArray: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1273 | { |
| 1274 | if (level > gl::log2(caps.max2DTextureSize)) |
| 1275 | { |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 1276 | ANGLE_VALIDATION_ERR(context, InvalidValue(), |
| 1277 | FramebufferTextureInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1278 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1282 | { |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 1283 | ANGLE_VALIDATION_ERR(context, InvalidValue(), FramebufferTextureInvalidLayer); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1284 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1285 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1286 | } |
| 1287 | break; |
| 1288 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 1289 | case TextureType::_3D: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1290 | { |
| 1291 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1292 | { |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 1293 | ANGLE_VALIDATION_ERR(context, InvalidValue(), |
| 1294 | FramebufferTextureInvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1295 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1299 | { |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 1300 | ANGLE_VALIDATION_ERR(context, InvalidValue(), FramebufferTextureInvalidLayer); |
| 1301 | return false; |
| 1302 | } |
| 1303 | } |
| 1304 | break; |
| 1305 | |
| 1306 | case TextureType::_2DMultisampleArray: |
| 1307 | { |
| 1308 | if (level != 0) |
| 1309 | { |
| 1310 | ANGLE_VALIDATION_ERR(context, InvalidValue(), |
| 1311 | FramebufferTextureInvalidMipLevel); |
| 1312 | return false; |
| 1313 | } |
| 1314 | |
| 1315 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1316 | { |
| 1317 | ANGLE_VALIDATION_ERR(context, InvalidValue(), FramebufferTextureInvalidLayer); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1318 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1319 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1320 | } |
| 1321 | break; |
| 1322 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1323 | default: |
Olli Etuaho | fd16210 | 2018-08-27 16:14:57 +0300 | [diff] [blame] | 1324 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 1325 | FramebufferTextureLayerIncorrectTextureType); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1326 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1327 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1328 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 1329 | const auto &format = tex->getFormat(NonCubeTextureTypeToTarget(tex->getType()), level); |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1330 | if (format.info->compressed) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1331 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1332 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1333 | return false; |
| 1334 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1338 | } |
| 1339 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1340 | bool ValidateInvalidateFramebuffer(Context *context, |
| 1341 | GLenum target, |
| 1342 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1343 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1344 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1345 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1346 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1347 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1348 | return false; |
| 1349 | } |
| 1350 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1351 | bool defaultFramebuffer = false; |
| 1352 | |
| 1353 | switch (target) |
| 1354 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1355 | case GL_DRAW_FRAMEBUFFER: |
| 1356 | case GL_FRAMEBUFFER: |
| 1357 | defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0; |
| 1358 | break; |
| 1359 | case GL_READ_FRAMEBUFFER: |
| 1360 | defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0; |
| 1361 | break; |
| 1362 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1363 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1364 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1367 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1368 | defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1369 | } |
| 1370 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 1371 | bool ValidateInvalidateSubFramebuffer(Context *context, |
| 1372 | GLenum target, |
| 1373 | GLsizei numAttachments, |
| 1374 | const GLenum *attachments, |
| 1375 | GLint x, |
| 1376 | GLint y, |
| 1377 | GLsizei width, |
| 1378 | GLsizei height) |
| 1379 | { |
Yunchao He | 2f3a0dc | 2018-02-27 22:39:44 +0800 | [diff] [blame] | 1380 | if (width < 0 || height < 0) |
| 1381 | { |
| 1382 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
| 1383 | return false; |
| 1384 | } |
| 1385 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 1386 | return ValidateInvalidateFramebuffer(context, target, numAttachments, attachments); |
| 1387 | } |
| 1388 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1389 | bool ValidateClearBuffer(Context *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1390 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1391 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1392 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1393 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1394 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1395 | } |
| 1396 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1397 | if (!ValidateFramebufferComplete(context, context->getGLState().getDrawFramebuffer())) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1398 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1399 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
| 1402 | return true; |
| 1403 | } |
| 1404 | |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1405 | bool ValidateDrawRangeElements(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 1406 | PrimitiveMode mode, |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1407 | GLuint start, |
| 1408 | GLuint end, |
| 1409 | GLsizei count, |
| 1410 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1411 | const void *indices) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1412 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1413 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1414 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1415 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1416 | return false; |
| 1417 | } |
| 1418 | |
| 1419 | if (end < start) |
| 1420 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1421 | context->handleError(InvalidValue() << "end < start"); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
| 1424 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1425 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0)) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1426 | { |
| 1427 | return false; |
| 1428 | } |
| 1429 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 1430 | // Skip range checks for no-op calls. |
| 1431 | if (count <= 0) |
| 1432 | { |
| 1433 | return true; |
| 1434 | } |
| 1435 | |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 1436 | // Note that resolving the index range is a bit slow. We should probably optimize this. |
| 1437 | IndexRange indexRange; |
| 1438 | ANGLE_VALIDATION_TRY(context->getGLState().getVertexArray()->getIndexRange( |
| 1439 | context, type, count, indices, &indexRange)); |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 1440 | |
| 1441 | if (indexRange.end > end || indexRange.start < start) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1442 | { |
| 1443 | // GL spec says that behavior in this case is undefined - generating an error is fine. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1444 | context->handleError(InvalidOperation() << "Indices are out of the start, end range."); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1450 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1451 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1452 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1453 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1454 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1455 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1456 | } |
| 1457 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1458 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1459 | } |
| 1460 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1461 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1462 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1463 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1464 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1465 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
| 1468 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1469 | const Framebuffer *readFBO = context->getGLState().getReadFramebuffer(); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1470 | |
| 1471 | if (readFBO == nullptr) |
| 1472 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1473 | context->handleError(InvalidOperation() << "No active read framebuffer."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1474 | return false; |
| 1475 | } |
| 1476 | |
| 1477 | if (src == GL_NONE) |
| 1478 | { |
| 1479 | return true; |
| 1480 | } |
| 1481 | |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1482 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1483 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1484 | context->handleError(InvalidEnum() << "Unknown enum for 'src' in ReadBuffer"); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1485 | return false; |
| 1486 | } |
| 1487 | |
| 1488 | if (readFBO->id() == 0) |
| 1489 | { |
| 1490 | if (src != GL_BACK) |
| 1491 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1492 | context->handleError( |
| 1493 | InvalidOperation() |
| 1494 | << "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1495 | return false; |
| 1496 | } |
| 1497 | } |
| 1498 | else |
| 1499 | { |
| 1500 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1501 | |
| 1502 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1503 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1504 | context->handleError(InvalidOperation() << "'src' is greater than MAX_DRAW_BUFFERS."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1505 | return false; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | return true; |
| 1510 | } |
| 1511 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1512 | bool ValidateCompressedTexImage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1513 | TextureType target, |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1514 | GLint level, |
| 1515 | GLenum internalformat, |
| 1516 | GLsizei width, |
| 1517 | GLsizei height, |
| 1518 | GLsizei depth, |
| 1519 | GLint border, |
| 1520 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1521 | const void *data) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1522 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1523 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1524 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1525 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1526 | return false; |
| 1527 | } |
| 1528 | |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1529 | if (!ValidTextureTarget(context, target)) |
| 1530 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1531 | context->handleError(InvalidEnum()); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1532 | return false; |
| 1533 | } |
| 1534 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1535 | // Validate image size |
| 1536 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, false)) |
| 1537 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1538 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1539 | return false; |
| 1540 | } |
| 1541 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1542 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1543 | if (!formatInfo.compressed) |
| 1544 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1545 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1546 | return false; |
| 1547 | } |
| 1548 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 1549 | GLuint blockSize = 0; |
| 1550 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, depth), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1551 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1552 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1553 | return false; |
| 1554 | } |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 1555 | |
| 1556 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1557 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1558 | context->handleError(InvalidValue()); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1559 | return false; |
| 1560 | } |
| 1561 | |
| 1562 | // 3D texture target validation |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1563 | if (target != TextureType::_3D && target != TextureType::_2DArray) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1564 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1565 | context->handleError(InvalidEnum() << "Must specify a valid 3D texture destination target"); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
| 1568 | |
| 1569 | // validateES3TexImageFormat sets the error code if there is an error |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1570 | if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1571 | 0, width, height, depth, border, GL_NONE, GL_NONE, -1, |
| 1572 | data)) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1573 | { |
| 1574 | return false; |
| 1575 | } |
| 1576 | |
| 1577 | return true; |
| 1578 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1579 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1580 | bool ValidateCompressedTexImage3DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1581 | TextureType target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1582 | GLint level, |
| 1583 | GLenum internalformat, |
| 1584 | GLsizei width, |
| 1585 | GLsizei height, |
| 1586 | GLsizei depth, |
| 1587 | GLint border, |
| 1588 | GLsizei imageSize, |
| 1589 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1590 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1591 | { |
| 1592 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 1593 | { |
| 1594 | return false; |
| 1595 | } |
| 1596 | |
| 1597 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 1598 | depth, border, imageSize, data); |
| 1599 | } |
| 1600 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1601 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1602 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1603 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1604 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1605 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1606 | return false; |
| 1607 | } |
| 1608 | |
| 1609 | return ValidateBindVertexArrayBase(context, array); |
| 1610 | } |
| 1611 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1612 | bool ValidateIsVertexArray(Context *context, GLuint array) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1613 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1614 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1615 | { |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 1616 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1617 | return false; |
| 1618 | } |
| 1619 | |
| 1620 | return true; |
| 1621 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1622 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1623 | static bool ValidateBindBufferCommon(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1624 | BufferBinding target, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1625 | GLuint index, |
| 1626 | GLuint buffer, |
| 1627 | GLintptr offset, |
| 1628 | GLsizeiptr size) |
| 1629 | { |
| 1630 | if (context->getClientMajorVersion() < 3) |
| 1631 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1632 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1633 | return false; |
| 1634 | } |
| 1635 | |
| 1636 | if (buffer != 0 && offset < 0) |
| 1637 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1638 | context->handleError(InvalidValue() << "buffer is non-zero and offset is negative."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1639 | return false; |
| 1640 | } |
| 1641 | |
| 1642 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 1643 | !context->isBufferGenerated(buffer)) |
| 1644 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1645 | context->handleError(InvalidOperation() << "Buffer was not generated."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1646 | return false; |
| 1647 | } |
| 1648 | |
| 1649 | const Caps &caps = context->getCaps(); |
| 1650 | switch (target) |
| 1651 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1652 | case BufferBinding::TransformFeedback: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1653 | { |
| 1654 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 1655 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1656 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1657 | "number of TRANSFORM_FEEDBACK_BUFFER " |
| 1658 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1659 | return false; |
| 1660 | } |
| 1661 | if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0)) |
| 1662 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1663 | context->handleError(InvalidValue() << "offset and size must be multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1664 | return false; |
| 1665 | } |
| 1666 | |
| 1667 | TransformFeedback *curTransformFeedback = |
| 1668 | context->getGLState().getCurrentTransformFeedback(); |
| 1669 | if (curTransformFeedback && curTransformFeedback->isActive()) |
| 1670 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1671 | context->handleError(InvalidOperation() |
| 1672 | << "target is TRANSFORM_FEEDBACK_BUFFER and transform " |
| 1673 | "feedback is currently active."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1674 | return false; |
| 1675 | } |
| 1676 | break; |
| 1677 | } |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1678 | case BufferBinding::Uniform: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1679 | { |
| 1680 | if (index >= caps.maxUniformBufferBindings) |
| 1681 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1682 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1683 | "number of UNIFORM_BUFFER indexed " |
| 1684 | "binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1685 | return false; |
| 1686 | } |
| 1687 | |
Qin Jiajia | f7af13c | 2018-06-06 14:14:54 +0800 | [diff] [blame] | 1688 | ASSERT(caps.uniformBufferOffsetAlignment); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1689 | if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0) |
| 1690 | { |
| 1691 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1692 | InvalidValue() |
| 1693 | << "offset must be multiple of value of UNIFORM_BUFFER_OFFSET_ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1694 | return false; |
| 1695 | } |
| 1696 | break; |
| 1697 | } |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1698 | case BufferBinding::AtomicCounter: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1699 | { |
| 1700 | if (context->getClientVersion() < ES_3_1) |
| 1701 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1702 | context->handleError(InvalidEnum() |
| 1703 | << "ATOMIC_COUNTER_BUFFER is not supported before GLES 3.1"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1704 | return false; |
| 1705 | } |
| 1706 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 1707 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1708 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1709 | "number of ATOMIC_COUNTER_BUFFER " |
| 1710 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1711 | return false; |
| 1712 | } |
| 1713 | if (buffer != 0 && (offset % 4) != 0) |
| 1714 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1715 | context->handleError(InvalidValue() << "offset must be a multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1716 | return false; |
| 1717 | } |
| 1718 | break; |
| 1719 | } |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1720 | case BufferBinding::ShaderStorage: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1721 | { |
| 1722 | if (context->getClientVersion() < ES_3_1) |
| 1723 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1724 | context->handleError(InvalidEnum() |
| 1725 | << "SHADER_STORAGE_BUFFER is not supported in GLES3."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1726 | return false; |
| 1727 | } |
| 1728 | if (index >= caps.maxShaderStorageBufferBindings) |
| 1729 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1730 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1731 | "number of SHADER_STORAGE_BUFFER " |
| 1732 | "indexed binding points."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1733 | return false; |
| 1734 | } |
Qin Jiajia | f7af13c | 2018-06-06 14:14:54 +0800 | [diff] [blame] | 1735 | ASSERT(caps.shaderStorageBufferOffsetAlignment); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1736 | if (buffer != 0 && (offset % caps.shaderStorageBufferOffsetAlignment) != 0) |
| 1737 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1738 | context->handleError(InvalidValue() << "offset must be multiple of value of " |
| 1739 | "SHADER_STORAGE_BUFFER_OFFSET_" |
| 1740 | "ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1741 | return false; |
| 1742 | } |
| 1743 | break; |
| 1744 | } |
| 1745 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1746 | context->handleError(InvalidEnum() << "the target is not supported."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1747 | return false; |
| 1748 | } |
| 1749 | |
| 1750 | return true; |
| 1751 | } |
| 1752 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1753 | bool ValidateBindBufferBase(Context *context, BufferBinding target, GLuint index, GLuint buffer) |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1754 | { |
| 1755 | return ValidateBindBufferCommon(context, target, index, buffer, 0, 0); |
| 1756 | } |
| 1757 | |
| 1758 | bool ValidateBindBufferRange(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1759 | BufferBinding target, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1760 | GLuint index, |
| 1761 | GLuint buffer, |
| 1762 | GLintptr offset, |
| 1763 | GLsizeiptr size) |
| 1764 | { |
| 1765 | if (buffer != 0 && size <= 0) |
| 1766 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1767 | context->handleError(InvalidValue() |
| 1768 | << "buffer is non-zero and size is less than or equal to zero."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1769 | return false; |
| 1770 | } |
| 1771 | return ValidateBindBufferCommon(context, target, index, buffer, offset, size); |
| 1772 | } |
| 1773 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1774 | bool ValidateProgramBinary(Context *context, |
| 1775 | GLuint program, |
| 1776 | GLenum binaryFormat, |
| 1777 | const void *binary, |
| 1778 | GLint length) |
| 1779 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1780 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1781 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1782 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1787 | } |
| 1788 | |
| 1789 | bool ValidateGetProgramBinary(Context *context, |
| 1790 | GLuint program, |
| 1791 | GLsizei bufSize, |
| 1792 | GLsizei *length, |
| 1793 | GLenum *binaryFormat, |
| 1794 | void *binary) |
| 1795 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1796 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1797 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1798 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1799 | return false; |
| 1800 | } |
| 1801 | |
| 1802 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1803 | } |
| 1804 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1805 | bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1806 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1807 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1808 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1809 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1810 | return false; |
| 1811 | } |
| 1812 | |
| 1813 | if (GetValidProgram(context, program) == nullptr) |
| 1814 | { |
| 1815 | return false; |
| 1816 | } |
| 1817 | |
| 1818 | switch (pname) |
| 1819 | { |
| 1820 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1821 | if (value != GL_FALSE && value != GL_TRUE) |
| 1822 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1823 | context->handleError(InvalidValue() |
| 1824 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1825 | return false; |
| 1826 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1827 | break; |
| 1828 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1829 | case GL_PROGRAM_SEPARABLE: |
| 1830 | if (context->getClientVersion() < ES_3_1) |
| 1831 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1832 | context->handleError(InvalidEnum() |
| 1833 | << "PROGRAM_SEPARABLE is not supported before GLES 3.1"); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1834 | return false; |
| 1835 | } |
| 1836 | |
| 1837 | if (value != GL_FALSE && value != GL_TRUE) |
| 1838 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1839 | context->handleError(InvalidValue() |
| 1840 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1841 | return false; |
| 1842 | } |
| 1843 | break; |
| 1844 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1845 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1846 | context->handleError(InvalidEnum() |
| 1847 | << "Invalid pname: 0x" << std::hex << std::uppercase << pname); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1848 | return false; |
| 1849 | } |
| 1850 | |
| 1851 | return true; |
| 1852 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1853 | |
| 1854 | bool ValidateBlitFramebuffer(Context *context, |
| 1855 | GLint srcX0, |
| 1856 | GLint srcY0, |
| 1857 | GLint srcX1, |
| 1858 | GLint srcY1, |
| 1859 | GLint dstX0, |
| 1860 | GLint dstY0, |
| 1861 | GLint dstX1, |
| 1862 | GLint dstY1, |
| 1863 | GLbitfield mask, |
| 1864 | GLenum filter) |
| 1865 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1866 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1867 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 1868 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1873 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1874 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1875 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1876 | bool ValidateClearBufferiv(Context *context, GLenum buffer, GLint drawbuffer, const GLint *value) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1877 | { |
| 1878 | switch (buffer) |
| 1879 | { |
| 1880 | case GL_COLOR: |
| 1881 | if (drawbuffer < 0 || |
| 1882 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1883 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1884 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1885 | return false; |
| 1886 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1887 | if (context->getExtensions().webglCompatibility) |
| 1888 | { |
| 1889 | constexpr GLenum validComponentTypes[] = {GL_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1890 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1891 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1892 | { |
| 1893 | return false; |
| 1894 | } |
| 1895 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1896 | break; |
| 1897 | |
| 1898 | case GL_STENCIL: |
| 1899 | if (drawbuffer != 0) |
| 1900 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1901 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1902 | return false; |
| 1903 | } |
| 1904 | break; |
| 1905 | |
| 1906 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1907 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1908 | return false; |
| 1909 | } |
| 1910 | |
| 1911 | return ValidateClearBuffer(context); |
| 1912 | } |
| 1913 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1914 | bool ValidateClearBufferuiv(Context *context, GLenum buffer, GLint drawbuffer, const GLuint *value) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1915 | { |
| 1916 | switch (buffer) |
| 1917 | { |
| 1918 | case GL_COLOR: |
| 1919 | if (drawbuffer < 0 || |
| 1920 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1921 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1922 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1923 | return false; |
| 1924 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1925 | if (context->getExtensions().webglCompatibility) |
| 1926 | { |
| 1927 | constexpr GLenum validComponentTypes[] = {GL_UNSIGNED_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1928 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1929 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1930 | { |
| 1931 | return false; |
| 1932 | } |
| 1933 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1934 | break; |
| 1935 | |
| 1936 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1937 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | return ValidateClearBuffer(context); |
| 1942 | } |
| 1943 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1944 | bool ValidateClearBufferfv(Context *context, GLenum buffer, GLint drawbuffer, const GLfloat *value) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1945 | { |
| 1946 | switch (buffer) |
| 1947 | { |
| 1948 | case GL_COLOR: |
| 1949 | if (drawbuffer < 0 || |
| 1950 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1951 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1952 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1953 | return false; |
| 1954 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1955 | if (context->getExtensions().webglCompatibility) |
| 1956 | { |
| 1957 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 1958 | GL_SIGNED_NORMALIZED}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1959 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1960 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1961 | { |
| 1962 | return false; |
| 1963 | } |
| 1964 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1965 | break; |
| 1966 | |
| 1967 | case GL_DEPTH: |
| 1968 | if (drawbuffer != 0) |
| 1969 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1970 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1971 | return false; |
| 1972 | } |
| 1973 | break; |
| 1974 | |
| 1975 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1976 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1977 | return false; |
| 1978 | } |
| 1979 | |
| 1980 | return ValidateClearBuffer(context); |
| 1981 | } |
| 1982 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1983 | bool ValidateClearBufferfi(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1984 | GLenum buffer, |
| 1985 | GLint drawbuffer, |
| 1986 | GLfloat depth, |
| 1987 | GLint stencil) |
| 1988 | { |
| 1989 | switch (buffer) |
| 1990 | { |
| 1991 | case GL_DEPTH_STENCIL: |
| 1992 | if (drawbuffer != 0) |
| 1993 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1994 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
| 1997 | break; |
| 1998 | |
| 1999 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2000 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2001 | return false; |
| 2002 | } |
| 2003 | |
| 2004 | return ValidateClearBuffer(context); |
| 2005 | } |
| 2006 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2007 | bool ValidateDrawBuffers(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2008 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2009 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2010 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2011 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2012 | return false; |
| 2013 | } |
| 2014 | |
| 2015 | return ValidateDrawBuffersBase(context, n, bufs); |
| 2016 | } |
| 2017 | |
| 2018 | bool ValidateCopyTexSubImage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2019 | TextureType target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2020 | GLint level, |
| 2021 | GLint xoffset, |
| 2022 | GLint yoffset, |
| 2023 | GLint zoffset, |
| 2024 | GLint x, |
| 2025 | GLint y, |
| 2026 | GLsizei width, |
| 2027 | GLsizei height) |
| 2028 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2029 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2030 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2031 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2032 | return false; |
| 2033 | } |
| 2034 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 2035 | return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset, |
| 2036 | yoffset, zoffset, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2037 | } |
| 2038 | |
Brandon Jones | 4e6f2ae | 2018-09-19 11:09:51 -0700 | [diff] [blame] | 2039 | bool ValidateCopyTexture3DANGLE(Context *context, |
| 2040 | GLuint sourceId, |
| 2041 | GLint sourceLevel, |
| 2042 | TextureTarget destTarget, |
| 2043 | GLuint destId, |
| 2044 | GLint destLevel, |
| 2045 | GLint internalFormat, |
| 2046 | GLenum destType, |
| 2047 | GLboolean unpackFlipY, |
| 2048 | GLboolean unpackPremultiplyAlpha, |
| 2049 | GLboolean unpackUnmultiplyAlpha) |
| 2050 | { |
| 2051 | const Texture *source = context->getTexture(sourceId); |
| 2052 | if (source == nullptr) |
| 2053 | { |
| 2054 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSourceTexture); |
| 2055 | return false; |
| 2056 | } |
| 2057 | |
| 2058 | TextureType sourceType = source->getType(); |
| 2059 | ASSERT(sourceType != TextureType::CubeMap); |
| 2060 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
| 2061 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 2062 | |
| 2063 | const Texture *dest = context->getTexture(destId); |
| 2064 | if (dest == nullptr) |
| 2065 | { |
| 2066 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidDestinationTexture); |
| 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | if (!ValidateCopyTexture3DCommon(context, source, sourceLevel, |
| 2071 | sourceFormat.info->internalFormat, dest, destLevel, |
| 2072 | internalFormat, destTarget)) |
| 2073 | { |
| 2074 | return false; |
| 2075 | } |
| 2076 | |
| 2077 | if (!ValidMipLevel(context, source->getType(), sourceLevel)) |
| 2078 | { |
| 2079 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSourceTextureLevel); |
| 2080 | return false; |
| 2081 | } |
| 2082 | |
| 2083 | GLsizei sourceWidth = static_cast<GLsizei>(source->getWidth(sourceTarget, sourceLevel)); |
| 2084 | GLsizei sourceHeight = static_cast<GLsizei>(source->getHeight(sourceTarget, sourceLevel)); |
| 2085 | if (sourceWidth == 0 || sourceHeight == 0) |
| 2086 | { |
| 2087 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSourceTextureSize); |
| 2088 | return false; |
| 2089 | } |
| 2090 | |
| 2091 | if (dest->getImmutableFormat()) |
| 2092 | { |
| 2093 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DestinationImmutable); |
| 2094 | return false; |
| 2095 | } |
| 2096 | |
| 2097 | return true; |
| 2098 | } |
| 2099 | |
| 2100 | bool ValidateCopySubTexture3DANGLE(Context *context, |
| 2101 | GLuint sourceId, |
| 2102 | GLint sourceLevel, |
| 2103 | TextureTarget destTarget, |
| 2104 | GLuint destId, |
| 2105 | GLint destLevel, |
| 2106 | GLint xoffset, |
| 2107 | GLint yoffset, |
| 2108 | GLint zoffset, |
| 2109 | GLint x, |
| 2110 | GLint y, |
| 2111 | GLint z, |
| 2112 | GLsizei width, |
| 2113 | GLsizei height, |
| 2114 | GLsizei depth, |
| 2115 | GLboolean unpackFlipY, |
| 2116 | GLboolean unpackPremultiplyAlpha, |
| 2117 | GLboolean unpackUnmultiplyAlpha) |
| 2118 | { |
| 2119 | const Texture *source = context->getTexture(sourceId); |
| 2120 | if (source == nullptr) |
| 2121 | { |
| 2122 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSourceTexture); |
| 2123 | return false; |
| 2124 | } |
| 2125 | |
| 2126 | TextureType sourceType = source->getType(); |
| 2127 | ASSERT(sourceType != TextureType::CubeMap); |
| 2128 | TextureTarget sourceTarget = NonCubeTextureTypeToTarget(sourceType); |
| 2129 | const Format &sourceFormat = source->getFormat(sourceTarget, sourceLevel); |
| 2130 | |
| 2131 | const Texture *dest = context->getTexture(destId); |
| 2132 | if (dest == nullptr) |
| 2133 | { |
| 2134 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidDestinationTexture); |
| 2135 | return false; |
| 2136 | } |
| 2137 | |
| 2138 | const InternalFormat &destFormat = *dest->getFormat(destTarget, destLevel).info; |
| 2139 | |
| 2140 | if (!ValidateCopyTexture3DCommon(context, source, sourceLevel, |
| 2141 | sourceFormat.info->internalFormat, dest, destLevel, |
| 2142 | destFormat.internalFormat, destTarget)) |
| 2143 | { |
| 2144 | return false; |
| 2145 | } |
| 2146 | |
| 2147 | if (x < 0 || y < 0 || z < 0) |
| 2148 | { |
| 2149 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeXYZ); |
| 2150 | return false; |
| 2151 | } |
| 2152 | |
| 2153 | if (width < 0 || height < 0 || depth < 0) |
| 2154 | { |
| 2155 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeHeightWidthDepth); |
| 2156 | return false; |
| 2157 | } |
| 2158 | |
| 2159 | if (static_cast<size_t>(x + width) > source->getWidth(sourceTarget, sourceLevel) || |
| 2160 | static_cast<size_t>(y + height) > source->getHeight(sourceTarget, sourceLevel) || |
| 2161 | static_cast<size_t>(z + depth) > source->getDepth(sourceTarget, sourceLevel)) |
| 2162 | { |
| 2163 | ANGLE_VALIDATION_ERR(context, InvalidValue(), SourceTextureTooSmall); |
| 2164 | return false; |
| 2165 | } |
| 2166 | |
| 2167 | if (TextureTargetToType(destTarget) != dest->getType()) |
| 2168 | { |
| 2169 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidDestinationTextureType); |
| 2170 | return false; |
| 2171 | } |
| 2172 | |
| 2173 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 2174 | { |
| 2175 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2176 | return false; |
| 2177 | } |
| 2178 | |
| 2179 | if (static_cast<size_t>(xoffset + width) > dest->getWidth(destTarget, destLevel) || |
| 2180 | static_cast<size_t>(yoffset + height) > dest->getHeight(destTarget, destLevel) || |
| 2181 | static_cast<size_t>(zoffset + depth) > dest->getDepth(destTarget, destLevel)) |
| 2182 | { |
| 2183 | ANGLE_VALIDATION_ERR(context, InvalidValue(), DestinationTextureTooSmall); |
| 2184 | return false; |
| 2185 | } |
| 2186 | |
| 2187 | return true; |
| 2188 | } |
| 2189 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2190 | bool ValidateTexImage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2191 | TextureType target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2192 | GLint level, |
| 2193 | GLint internalformat, |
| 2194 | GLsizei width, |
| 2195 | GLsizei height, |
| 2196 | GLsizei depth, |
| 2197 | GLint border, |
| 2198 | GLenum format, |
| 2199 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2200 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2201 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2202 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2203 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2204 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2205 | return false; |
| 2206 | } |
| 2207 | |
| 2208 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2209 | 0, 0, width, height, depth, border, format, type, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2210 | pixels); |
| 2211 | } |
| 2212 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2213 | bool ValidateTexImage3DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2214 | TextureType target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2215 | GLint level, |
| 2216 | GLint internalformat, |
| 2217 | GLsizei width, |
| 2218 | GLsizei height, |
| 2219 | GLsizei depth, |
| 2220 | GLint border, |
| 2221 | GLenum format, |
| 2222 | GLenum type, |
| 2223 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2224 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2225 | { |
| 2226 | if (context->getClientMajorVersion() < 3) |
| 2227 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2228 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2229 | return false; |
| 2230 | } |
| 2231 | |
| 2232 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2233 | { |
| 2234 | return false; |
| 2235 | } |
| 2236 | |
| 2237 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
| 2238 | 0, 0, width, height, depth, border, format, type, |
| 2239 | bufSize, pixels); |
| 2240 | } |
| 2241 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2242 | bool ValidateTexSubImage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2243 | TextureType target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2244 | GLint level, |
| 2245 | GLint xoffset, |
| 2246 | GLint yoffset, |
| 2247 | GLint zoffset, |
| 2248 | GLsizei width, |
| 2249 | GLsizei height, |
| 2250 | GLsizei depth, |
| 2251 | GLenum format, |
| 2252 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2253 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2254 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2255 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2256 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2257 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2258 | return false; |
| 2259 | } |
| 2260 | |
| 2261 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2262 | yoffset, zoffset, width, height, depth, 0, format, type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2263 | -1, pixels); |
| 2264 | } |
| 2265 | |
| 2266 | bool ValidateTexSubImage3DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2267 | TextureType target, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2268 | GLint level, |
| 2269 | GLint xoffset, |
| 2270 | GLint yoffset, |
| 2271 | GLint zoffset, |
| 2272 | GLsizei width, |
| 2273 | GLsizei height, |
| 2274 | GLsizei depth, |
| 2275 | GLenum format, |
| 2276 | GLenum type, |
| 2277 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2278 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2279 | { |
| 2280 | if (context->getClientMajorVersion() < 3) |
| 2281 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2282 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 2283 | return false; |
| 2284 | } |
| 2285 | |
| 2286 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2287 | { |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
| 2291 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 2292 | yoffset, zoffset, width, height, depth, 0, format, type, |
| 2293 | bufSize, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2294 | } |
| 2295 | |
| 2296 | bool ValidateCompressedTexSubImage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2297 | TextureType target, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2298 | GLint level, |
| 2299 | GLint xoffset, |
| 2300 | GLint yoffset, |
| 2301 | GLint zoffset, |
| 2302 | GLsizei width, |
| 2303 | GLsizei height, |
| 2304 | GLsizei depth, |
| 2305 | GLenum format, |
| 2306 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2307 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2308 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2309 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2310 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2311 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2312 | return false; |
| 2313 | } |
| 2314 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2315 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 2316 | if (!formatInfo.compressed) |
| 2317 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2318 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 2319 | return false; |
| 2320 | } |
| 2321 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2322 | GLuint blockSize = 0; |
| 2323 | if (!formatInfo.computeCompressedImageSize(gl::Extents(width, height, depth), &blockSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2324 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2325 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2326 | return false; |
| 2327 | } |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 2328 | |
| 2329 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSize) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2330 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2331 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2332 | return false; |
| 2333 | } |
| 2334 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 2335 | if (!ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, xoffset, |
| 2336 | yoffset, zoffset, width, height, depth, 0, format, GL_NONE, |
| 2337 | -1, data)) |
| 2338 | { |
| 2339 | return false; |
| 2340 | } |
| 2341 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2342 | if (!data) |
| 2343 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2344 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2345 | return false; |
| 2346 | } |
| 2347 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 2348 | return true; |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2349 | } |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 2350 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2351 | bool ValidateCompressedTexSubImage3DRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2352 | TextureType target, |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2353 | GLint level, |
| 2354 | GLint xoffset, |
| 2355 | GLint yoffset, |
| 2356 | GLint zoffset, |
| 2357 | GLsizei width, |
| 2358 | GLsizei height, |
| 2359 | GLsizei depth, |
| 2360 | GLenum format, |
| 2361 | GLsizei imageSize, |
| 2362 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2363 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 2364 | { |
| 2365 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 2366 | { |
| 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 2371 | height, depth, format, imageSize, data); |
| 2372 | } |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2373 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2374 | bool ValidateGenQueries(Context *context, GLint n, GLuint *) |
| 2375 | { |
| 2376 | return ValidateGenOrDeleteES3(context, n); |
| 2377 | } |
| 2378 | |
| 2379 | bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *) |
| 2380 | { |
| 2381 | return ValidateGenOrDeleteES3(context, n); |
| 2382 | } |
| 2383 | |
| 2384 | bool ValidateGenSamplers(Context *context, GLint count, GLuint *) |
| 2385 | { |
| 2386 | return ValidateGenOrDeleteCountES3(context, count); |
| 2387 | } |
| 2388 | |
| 2389 | bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *) |
| 2390 | { |
| 2391 | return ValidateGenOrDeleteCountES3(context, count); |
| 2392 | } |
| 2393 | |
| 2394 | bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *) |
| 2395 | { |
| 2396 | return ValidateGenOrDeleteES3(context, n); |
| 2397 | } |
| 2398 | |
| 2399 | bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids) |
| 2400 | { |
| 2401 | if (!ValidateGenOrDeleteES3(context, n)) |
| 2402 | { |
| 2403 | return false; |
| 2404 | } |
| 2405 | for (GLint i = 0; i < n; ++i) |
| 2406 | { |
| 2407 | auto *transformFeedback = context->getTransformFeedback(ids[i]); |
| 2408 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 2409 | { |
| 2410 | // ES 3.0.4 section 2.15.1 page 86 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2411 | context->handleError(InvalidOperation() |
| 2412 | << "Attempt to delete active transform feedback."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2413 | return false; |
| 2414 | } |
| 2415 | } |
| 2416 | return true; |
| 2417 | } |
| 2418 | |
| 2419 | bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *) |
| 2420 | { |
| 2421 | return ValidateGenOrDeleteES3(context, n); |
| 2422 | } |
| 2423 | |
| 2424 | bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *) |
| 2425 | { |
| 2426 | return ValidateGenOrDeleteES3(context, n); |
| 2427 | } |
| 2428 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2429 | bool ValidateBeginTransformFeedback(Context *context, PrimitiveMode primitiveMode) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2430 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2431 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2432 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2433 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2434 | return false; |
| 2435 | } |
| 2436 | switch (primitiveMode) |
| 2437 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2438 | case PrimitiveMode::Triangles: |
| 2439 | case PrimitiveMode::Lines: |
| 2440 | case PrimitiveMode::Points: |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2441 | break; |
| 2442 | |
| 2443 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2444 | context->handleError(InvalidEnum() << "Invalid primitive mode."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2445 | return false; |
| 2446 | } |
| 2447 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2448 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2449 | ASSERT(transformFeedback != nullptr); |
| 2450 | |
| 2451 | if (transformFeedback->isActive()) |
| 2452 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2453 | context->handleError(InvalidOperation() << "Transform feedback is already active."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2454 | return false; |
| 2455 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 2456 | |
| 2457 | for (size_t i = 0; i < transformFeedback->getIndexedBufferCount(); i++) |
| 2458 | { |
| 2459 | const auto &buffer = transformFeedback->getIndexedBuffer(i); |
| 2460 | if (buffer.get() && buffer->isMapped()) |
| 2461 | { |
| 2462 | context->handleError(InvalidOperation() << "Transform feedback has a mapped buffer."); |
| 2463 | return false; |
| 2464 | } |
| 2465 | } |
| 2466 | |
Jamie Madill | 785e8a0 | 2018-10-04 17:42:00 -0400 | [diff] [blame] | 2467 | Program *program = context->getGLState().getLinkedProgram(context); |
Olli Etuaho | 02032bd | 2017-10-13 18:10:17 +0300 | [diff] [blame] | 2468 | |
| 2469 | if (!program) |
| 2470 | { |
| 2471 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
| 2472 | return false; |
| 2473 | } |
| 2474 | |
| 2475 | if (program->getTransformFeedbackVaryingCount() == 0) |
| 2476 | { |
| 2477 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoTransformFeedbackOutputVariables); |
| 2478 | return false; |
| 2479 | } |
| 2480 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2481 | return true; |
| 2482 | } |
| 2483 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2484 | bool ValidateGetBufferPointerv(Context *context, BufferBinding target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2485 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2486 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
| 2487 | } |
| 2488 | |
| 2489 | bool ValidateGetBufferPointervRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2490 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2491 | GLenum pname, |
| 2492 | GLsizei bufSize, |
| 2493 | GLsizei *length, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2494 | void **params) |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2495 | { |
| 2496 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2497 | { |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2498 | return false; |
| 2499 | } |
| 2500 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2501 | GLsizei numParams = 0; |
| 2502 | |
| 2503 | if (!ValidateGetBufferPointervBase(context, target, pname, &numParams, params)) |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2504 | { |
| 2505 | return false; |
| 2506 | } |
| 2507 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2508 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2509 | { |
| 2510 | return false; |
| 2511 | } |
| 2512 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2513 | SetRobustLengthParam(length, numParams); |
| 2514 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2515 | return true; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2516 | } |
| 2517 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2518 | bool ValidateUnmapBuffer(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2519 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2520 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2521 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2522 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2523 | return false; |
| 2524 | } |
| 2525 | |
| 2526 | return ValidateUnmapBufferBase(context, target); |
| 2527 | } |
| 2528 | |
| 2529 | bool ValidateMapBufferRange(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2530 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2531 | GLintptr offset, |
| 2532 | GLsizeiptr length, |
| 2533 | GLbitfield access) |
| 2534 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2535 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2536 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2537 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2538 | return false; |
| 2539 | } |
| 2540 | |
| 2541 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2542 | } |
| 2543 | |
| 2544 | bool ValidateFlushMappedBufferRange(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2545 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2546 | GLintptr offset, |
| 2547 | GLsizeiptr length) |
| 2548 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2549 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2550 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2551 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2552 | return false; |
| 2553 | } |
| 2554 | |
| 2555 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2556 | } |
| 2557 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2558 | bool ValidateIndexedStateQuery(Context *context, GLenum pname, GLuint index, GLsizei *length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2559 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2560 | if (length) |
| 2561 | { |
| 2562 | *length = 0; |
| 2563 | } |
| 2564 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2565 | GLenum nativeType; |
| 2566 | unsigned int numParams; |
| 2567 | if (!context->getIndexedQueryParameterInfo(pname, &nativeType, &numParams)) |
| 2568 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2569 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2570 | return false; |
| 2571 | } |
| 2572 | |
| 2573 | const Caps &caps = context->getCaps(); |
| 2574 | switch (pname) |
| 2575 | { |
| 2576 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 2577 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
| 2578 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 2579 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 2580 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2581 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2582 | return false; |
| 2583 | } |
| 2584 | break; |
| 2585 | |
| 2586 | case GL_UNIFORM_BUFFER_START: |
| 2587 | case GL_UNIFORM_BUFFER_SIZE: |
| 2588 | case GL_UNIFORM_BUFFER_BINDING: |
| 2589 | if (index >= caps.maxUniformBufferBindings) |
| 2590 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2591 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2592 | return false; |
| 2593 | } |
| 2594 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2595 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2596 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 2597 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 2598 | if (index >= 3u) |
| 2599 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2600 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2601 | return false; |
| 2602 | } |
| 2603 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2604 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2605 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2606 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2607 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2608 | if (context->getClientVersion() < ES_3_1) |
| 2609 | { |
| 2610 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2611 | InvalidEnum() |
| 2612 | << "Atomic Counter buffers are not supported in this version of GL"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2613 | return false; |
| 2614 | } |
| 2615 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 2616 | { |
| 2617 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2618 | InvalidValue() |
| 2619 | << "index is outside the valid range for GL_ATOMIC_COUNTER_BUFFER_BINDING"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2620 | return false; |
| 2621 | } |
| 2622 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2623 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2624 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2625 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2626 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2627 | if (context->getClientVersion() < ES_3_1) |
| 2628 | { |
| 2629 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2630 | InvalidEnum() |
| 2631 | << "Shader storage buffers are not supported in this version of GL"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2632 | return false; |
| 2633 | } |
| 2634 | if (index >= caps.maxShaderStorageBufferBindings) |
| 2635 | { |
| 2636 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2637 | InvalidValue() |
| 2638 | << "index is outside the valid range for GL_SHADER_STORAGE_BUFFER_BINDING"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2639 | return false; |
| 2640 | } |
| 2641 | break; |
| 2642 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2643 | case GL_VERTEX_BINDING_BUFFER: |
| 2644 | case GL_VERTEX_BINDING_DIVISOR: |
| 2645 | case GL_VERTEX_BINDING_OFFSET: |
| 2646 | case GL_VERTEX_BINDING_STRIDE: |
| 2647 | if (context->getClientVersion() < ES_3_1) |
| 2648 | { |
| 2649 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2650 | InvalidEnum() |
| 2651 | << "Vertex Attrib Bindings are not supported in this version of GL"); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2652 | return false; |
| 2653 | } |
| 2654 | if (index >= caps.maxVertexAttribBindings) |
| 2655 | { |
| 2656 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2657 | InvalidValue() |
| 2658 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2659 | return false; |
| 2660 | } |
| 2661 | break; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 2662 | case GL_SAMPLE_MASK_VALUE: |
| 2663 | if (context->getClientVersion() < ES_3_1) |
| 2664 | { |
| 2665 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 2666 | return false; |
| 2667 | } |
| 2668 | if (index >= caps.maxSampleMaskWords) |
| 2669 | { |
| 2670 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidSampleMaskNumber); |
| 2671 | return false; |
| 2672 | } |
| 2673 | break; |
Xinghua Cao | 9c8e1a3 | 2017-12-06 17:59:58 +0800 | [diff] [blame] | 2674 | case GL_IMAGE_BINDING_NAME: |
| 2675 | case GL_IMAGE_BINDING_LEVEL: |
| 2676 | case GL_IMAGE_BINDING_LAYERED: |
| 2677 | case GL_IMAGE_BINDING_LAYER: |
| 2678 | case GL_IMAGE_BINDING_ACCESS: |
| 2679 | case GL_IMAGE_BINDING_FORMAT: |
| 2680 | if (context->getClientVersion() < ES_3_1) |
| 2681 | { |
| 2682 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 2683 | return false; |
| 2684 | } |
| 2685 | if (index >= caps.maxImageUnits) |
| 2686 | { |
| 2687 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidImageUnit); |
| 2688 | return false; |
| 2689 | } |
| 2690 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2691 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2692 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2693 | return false; |
| 2694 | } |
| 2695 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2696 | if (length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2697 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2698 | *length = 1; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2699 | } |
| 2700 | |
| 2701 | return true; |
| 2702 | } |
| 2703 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2704 | bool ValidateGetIntegeri_v(Context *context, GLenum target, GLuint index, GLint *data) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2705 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2706 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2707 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2708 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2709 | return false; |
| 2710 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2711 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2712 | } |
| 2713 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2714 | bool ValidateGetIntegeri_vRobustANGLE(Context *context, |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2715 | GLenum target, |
| 2716 | GLuint index, |
| 2717 | GLsizei bufSize, |
| 2718 | GLsizei *length, |
| 2719 | GLint *data) |
| 2720 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2721 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2722 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2723 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2724 | return false; |
| 2725 | } |
| 2726 | |
| 2727 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2728 | { |
| 2729 | return false; |
| 2730 | } |
| 2731 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2732 | GLsizei numParams = 0; |
| 2733 | |
| 2734 | if (!ValidateIndexedStateQuery(context, target, index, &numParams)) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2735 | { |
| 2736 | return false; |
| 2737 | } |
| 2738 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2739 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2740 | { |
| 2741 | return false; |
| 2742 | } |
| 2743 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2744 | SetRobustLengthParam(length, numParams); |
| 2745 | |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2746 | return true; |
| 2747 | } |
| 2748 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2749 | bool ValidateGetInteger64i_v(Context *context, GLenum target, GLuint index, GLint64 *data) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2750 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2751 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2752 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2753 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2754 | return false; |
| 2755 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2756 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
| 2757 | } |
| 2758 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2759 | bool ValidateGetInteger64i_vRobustANGLE(Context *context, |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2760 | GLenum target, |
| 2761 | GLuint index, |
| 2762 | GLsizei bufSize, |
| 2763 | GLsizei *length, |
| 2764 | GLint64 *data) |
| 2765 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2766 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2767 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2768 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2769 | return false; |
| 2770 | } |
| 2771 | |
| 2772 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2773 | { |
| 2774 | return false; |
| 2775 | } |
| 2776 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2777 | GLsizei numParams = 0; |
| 2778 | |
| 2779 | if (!ValidateIndexedStateQuery(context, target, index, &numParams)) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2780 | { |
| 2781 | return false; |
| 2782 | } |
| 2783 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2784 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2785 | { |
| 2786 | return false; |
| 2787 | } |
| 2788 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2789 | SetRobustLengthParam(length, numParams); |
| 2790 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2791 | return true; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2792 | } |
| 2793 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2794 | bool ValidateCopyBufferSubData(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2795 | BufferBinding readTarget, |
| 2796 | BufferBinding writeTarget, |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2797 | GLintptr readOffset, |
| 2798 | GLintptr writeOffset, |
| 2799 | GLsizeiptr size) |
| 2800 | { |
| 2801 | if (context->getClientMajorVersion() < 3) |
| 2802 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2803 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2804 | return false; |
| 2805 | } |
| 2806 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 2807 | if (!context->isValidBufferBinding(readTarget) || !context->isValidBufferBinding(writeTarget)) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2808 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2809 | context->handleError(InvalidEnum() << "Invalid buffer target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2810 | return false; |
| 2811 | } |
| 2812 | |
| 2813 | Buffer *readBuffer = context->getGLState().getTargetBuffer(readTarget); |
| 2814 | Buffer *writeBuffer = context->getGLState().getTargetBuffer(writeTarget); |
| 2815 | |
| 2816 | if (!readBuffer || !writeBuffer) |
| 2817 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2818 | context->handleError(InvalidOperation() << "No buffer bound to target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2819 | return false; |
| 2820 | } |
| 2821 | |
| 2822 | // Verify that readBuffer and writeBuffer are not currently mapped |
| 2823 | if (readBuffer->isMapped() || writeBuffer->isMapped()) |
| 2824 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2825 | context->handleError(InvalidOperation() |
| 2826 | << "Cannot call CopyBufferSubData on a mapped buffer"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2827 | return false; |
| 2828 | } |
| 2829 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2830 | if (context->getExtensions().webglCompatibility && |
| 2831 | (readBuffer->isBoundForTransformFeedbackAndOtherUse() || |
| 2832 | writeBuffer->isBoundForTransformFeedbackAndOtherUse())) |
| 2833 | { |
| 2834 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferBoundForTransformFeedback); |
| 2835 | return false; |
| 2836 | } |
| 2837 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2838 | CheckedNumeric<GLintptr> checkedReadOffset(readOffset); |
| 2839 | CheckedNumeric<GLintptr> checkedWriteOffset(writeOffset); |
| 2840 | CheckedNumeric<GLintptr> checkedSize(size); |
| 2841 | |
| 2842 | auto checkedReadSum = checkedReadOffset + checkedSize; |
| 2843 | auto checkedWriteSum = checkedWriteOffset + checkedSize; |
| 2844 | |
| 2845 | if (!checkedReadSum.IsValid() || !checkedWriteSum.IsValid() || |
| 2846 | !IsValueInRangeForNumericType<GLintptr>(readBuffer->getSize()) || |
| 2847 | !IsValueInRangeForNumericType<GLintptr>(writeBuffer->getSize())) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2848 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2849 | context->handleError(InvalidValue() << "Integer overflow when validating copy offsets."); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2850 | return false; |
| 2851 | } |
| 2852 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2853 | if (readOffset < 0 || writeOffset < 0 || size < 0) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2854 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2855 | context->handleError(InvalidValue() |
| 2856 | << "readOffset, writeOffset and size must all be non-negative"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2857 | return false; |
| 2858 | } |
| 2859 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2860 | if (checkedReadSum.ValueOrDie() > readBuffer->getSize() || |
| 2861 | checkedWriteSum.ValueOrDie() > writeBuffer->getSize()) |
| 2862 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2863 | context->handleError(InvalidValue() << "Buffer offset overflow in CopyBufferSubData"); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2864 | return false; |
| 2865 | } |
| 2866 | |
| 2867 | if (readBuffer == writeBuffer) |
| 2868 | { |
| 2869 | auto checkedOffsetDiff = (checkedReadOffset - checkedWriteOffset).Abs(); |
| 2870 | if (!checkedOffsetDiff.IsValid()) |
| 2871 | { |
| 2872 | // This shold not be possible. |
| 2873 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2874 | context->handleError(InvalidValue() |
| 2875 | << "Integer overflow when validating same buffer copy."); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2876 | return false; |
| 2877 | } |
| 2878 | |
| 2879 | if (checkedOffsetDiff.ValueOrDie() < size) |
| 2880 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2881 | context->handleError(InvalidValue()); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2882 | return false; |
| 2883 | } |
| 2884 | } |
| 2885 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2886 | return true; |
| 2887 | } |
| 2888 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2889 | bool ValidateGetStringi(Context *context, GLenum name, GLuint index) |
| 2890 | { |
| 2891 | if (context->getClientMajorVersion() < 3) |
| 2892 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2893 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2894 | return false; |
| 2895 | } |
| 2896 | |
| 2897 | switch (name) |
| 2898 | { |
| 2899 | case GL_EXTENSIONS: |
| 2900 | if (index >= context->getExtensionStringCount()) |
| 2901 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2902 | context->handleError(InvalidValue() |
| 2903 | << "index must be less than the number of extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2904 | return false; |
| 2905 | } |
| 2906 | break; |
| 2907 | |
| 2908 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2909 | if (!context->getExtensions().requestExtension) |
| 2910 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2911 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2912 | return false; |
| 2913 | } |
| 2914 | if (index >= context->getRequestableExtensionStringCount()) |
| 2915 | { |
| 2916 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2917 | InvalidValue() |
| 2918 | << "index must be less than the number of requestable extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2919 | return false; |
| 2920 | } |
| 2921 | break; |
| 2922 | |
| 2923 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2924 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidName); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2925 | return false; |
| 2926 | } |
| 2927 | |
| 2928 | return true; |
| 2929 | } |
| 2930 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2931 | bool ValidateRenderbufferStorageMultisample(Context *context, |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2932 | GLenum target, |
| 2933 | GLsizei samples, |
| 2934 | GLenum internalformat, |
| 2935 | GLsizei width, |
| 2936 | GLsizei height) |
| 2937 | { |
| 2938 | if (context->getClientMajorVersion() < 3) |
| 2939 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 2940 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2941 | return false; |
| 2942 | } |
| 2943 | |
| 2944 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, |
| 2945 | height)) |
| 2946 | { |
| 2947 | return false; |
| 2948 | } |
| 2949 | |
| 2950 | // The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer |
Yunchao He | c081020 | 2018-01-22 09:48:48 +0800 | [diff] [blame] | 2951 | // format if samples is greater than zero. In ES3.1(section 9.2.5), it can support integer |
| 2952 | // multisample renderbuffer, but the samples should not be greater than MAX_INTEGER_SAMPLES. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2953 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Yunchao He | c081020 | 2018-01-22 09:48:48 +0800 | [diff] [blame] | 2954 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT)) |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2955 | { |
Yunchao He | c081020 | 2018-01-22 09:48:48 +0800 | [diff] [blame] | 2956 | if ((samples > 0 && context->getClientVersion() == ES_3_0) || |
| 2957 | static_cast<GLuint>(samples) > context->getCaps().maxIntegerSamples) |
| 2958 | { |
| 2959 | context->handleError(InvalidOperation()); |
| 2960 | return false; |
| 2961 | } |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2962 | } |
| 2963 | |
| 2964 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 2965 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 2966 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 2967 | { |
| 2968 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2969 | InvalidOperation() |
| 2970 | << "Samples must not be greater than maximum supported value for the format."); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2971 | return false; |
| 2972 | } |
| 2973 | |
| 2974 | return true; |
| 2975 | } |
| 2976 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2977 | bool ValidateVertexAttribIPointer(Context *context, |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2978 | GLuint index, |
| 2979 | GLint size, |
| 2980 | GLenum type, |
| 2981 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2982 | const void *pointer) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2983 | { |
| 2984 | if (context->getClientMajorVersion() < 3) |
| 2985 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2986 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2987 | return false; |
| 2988 | } |
| 2989 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2990 | if (!ValidateVertexFormatBase(context, index, size, type, true)) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2991 | { |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2992 | return false; |
| 2993 | } |
| 2994 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2995 | if (stride < 0) |
| 2996 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2997 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStride); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2998 | return false; |
| 2999 | } |
| 3000 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3001 | const Caps &caps = context->getCaps(); |
| 3002 | if (context->getClientVersion() >= ES_3_1) |
| 3003 | { |
| 3004 | if (stride > caps.maxVertexAttribStride) |
| 3005 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3006 | context->handleError(InvalidValue() |
| 3007 | << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3008 | return false; |
| 3009 | } |
| 3010 | |
| 3011 | // [OpenGL ES 3.1] Section 10.3.1 page 245: |
| 3012 | // glVertexAttribBinding is part of the equivalent code of VertexAttribIPointer, so its |
| 3013 | // validation should be inherited. |
| 3014 | if (index >= caps.maxVertexAttribBindings) |
| 3015 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3016 | context->handleError(InvalidValue() |
| 3017 | << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3018 | return false; |
| 3019 | } |
| 3020 | } |
| 3021 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 3022 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 3023 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 3024 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 3025 | // and the pointer argument is not NULL. |
| 3026 | if (context->getGLState().getVertexArrayId() != 0 && |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3027 | context->getGLState().getTargetBuffer(BufferBinding::Array) == 0 && pointer != nullptr) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 3028 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3029 | context |
| 3030 | ->handleError(InvalidOperation() |
| 3031 | << "Client data cannot be used with a non-default vertex array object."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 3032 | return false; |
| 3033 | } |
| 3034 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 3035 | if (context->getExtensions().webglCompatibility) |
| 3036 | { |
| 3037 | if (!ValidateWebGLVertexAttribPointer(context, type, false, stride, pointer, true)) |
| 3038 | { |
| 3039 | return false; |
| 3040 | } |
| 3041 | } |
| 3042 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 3043 | return true; |
| 3044 | } |
| 3045 | |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3046 | bool ValidateGetSynciv(Context *context, |
| 3047 | GLsync sync, |
| 3048 | GLenum pname, |
| 3049 | GLsizei bufSize, |
| 3050 | GLsizei *length, |
| 3051 | GLint *values) |
| 3052 | { |
| 3053 | if (context->getClientMajorVersion() < 3) |
| 3054 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3055 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3056 | return false; |
| 3057 | } |
| 3058 | |
| 3059 | if (bufSize < 0) |
| 3060 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3061 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3062 | return false; |
| 3063 | } |
| 3064 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 3065 | Sync *syncObject = context->getSync(sync); |
| 3066 | if (!syncObject) |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3067 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3068 | context->handleError(InvalidValue() << "Invalid sync object."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3069 | return false; |
| 3070 | } |
| 3071 | |
| 3072 | switch (pname) |
| 3073 | { |
| 3074 | case GL_OBJECT_TYPE: |
| 3075 | case GL_SYNC_CONDITION: |
| 3076 | case GL_SYNC_FLAGS: |
| 3077 | case GL_SYNC_STATUS: |
| 3078 | break; |
| 3079 | |
| 3080 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3081 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 3082 | return false; |
| 3083 | } |
| 3084 | |
| 3085 | return true; |
| 3086 | } |
| 3087 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3088 | bool ValidateDrawElementsInstanced(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3089 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3090 | GLsizei count, |
| 3091 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3092 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3093 | GLsizei instanceCount) |
| 3094 | { |
| 3095 | if (context->getClientMajorVersion() < 3) |
| 3096 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3097 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3098 | return false; |
| 3099 | } |
| 3100 | |
| 3101 | return ValidateDrawElementsInstancedCommon(context, mode, count, type, indices, instanceCount); |
| 3102 | } |
| 3103 | |
Austin Eng | 1bf18ce | 2018-10-19 15:34:02 -0700 | [diff] [blame^] | 3104 | bool ValidateMultiDrawArraysInstancedANGLE(Context *context, |
| 3105 | PrimitiveMode mode, |
| 3106 | const GLint *firsts, |
| 3107 | const GLsizei *counts, |
| 3108 | const GLsizei *instanceCounts, |
| 3109 | GLsizei drawcount) |
| 3110 | { |
| 3111 | if (!context->getExtensions().multiDraw) |
| 3112 | { |
| 3113 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3114 | return false; |
| 3115 | } |
| 3116 | if (context->getClientMajorVersion() < 3) |
| 3117 | { |
| 3118 | if (!context->getExtensions().instancedArrays) |
| 3119 | { |
| 3120 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3121 | return false; |
| 3122 | } |
| 3123 | if (!ValidateDrawInstancedANGLE(context)) |
| 3124 | { |
| 3125 | return false; |
| 3126 | } |
| 3127 | } |
| 3128 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 3129 | { |
| 3130 | if (!ValidateDrawArraysInstancedBase(context, mode, firsts[drawID], counts[drawID], |
| 3131 | instanceCounts[drawID])) |
| 3132 | { |
| 3133 | return false; |
| 3134 | } |
| 3135 | } |
| 3136 | return true; |
| 3137 | } |
| 3138 | |
| 3139 | bool ValidateMultiDrawElementsInstancedANGLE(Context *context, |
| 3140 | PrimitiveMode mode, |
| 3141 | const GLsizei *counts, |
| 3142 | GLenum type, |
| 3143 | const GLsizei *offsets, |
| 3144 | const GLsizei *instanceCounts, |
| 3145 | GLsizei drawcount) |
| 3146 | { |
| 3147 | if (!context->getExtensions().multiDraw) |
| 3148 | { |
| 3149 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3150 | return false; |
| 3151 | } |
| 3152 | if (context->getClientMajorVersion() < 3) |
| 3153 | { |
| 3154 | if (!context->getExtensions().instancedArrays) |
| 3155 | { |
| 3156 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3157 | return false; |
| 3158 | } |
| 3159 | if (!ValidateDrawInstancedANGLE(context)) |
| 3160 | { |
| 3161 | return false; |
| 3162 | } |
| 3163 | } |
| 3164 | for (GLsizei drawID = 0; drawID < drawcount; ++drawID) |
| 3165 | { |
| 3166 | const void *indices = reinterpret_cast<void *>(static_cast<long>(offsets[drawID])); |
| 3167 | if (!ValidateDrawElementsInstancedCommon(context, mode, counts[drawID], type, indices, |
| 3168 | instanceCounts[drawID])) |
| 3169 | { |
| 3170 | return false; |
| 3171 | } |
| 3172 | } |
| 3173 | return true; |
| 3174 | } |
| 3175 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3176 | bool ValidateFramebufferTextureMultiviewLayeredANGLE(Context *context, |
| 3177 | GLenum target, |
| 3178 | GLenum attachment, |
| 3179 | GLuint texture, |
| 3180 | GLint level, |
| 3181 | GLint baseViewIndex, |
| 3182 | GLsizei numViews) |
| 3183 | { |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3184 | if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level, |
| 3185 | numViews)) |
| 3186 | { |
| 3187 | return false; |
| 3188 | } |
| 3189 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3190 | if (texture != 0) |
| 3191 | { |
Martin Radev | 14b2126 | 2017-08-25 13:54:37 +0300 | [diff] [blame] | 3192 | if (baseViewIndex < 0) |
| 3193 | { |
| 3194 | context->handleError(InvalidValue() << "baseViewIndex cannot be less than 0."); |
| 3195 | return false; |
| 3196 | } |
| 3197 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3198 | Texture *tex = context->getTexture(texture); |
| 3199 | ASSERT(tex); |
| 3200 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 3201 | switch (tex->getType()) |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3202 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 3203 | case TextureType::_2DArray: |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 3204 | case TextureType::_2DMultisampleArray: |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3205 | { |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 3206 | if (tex->getType() == TextureType::_2DMultisampleArray) |
| 3207 | { |
| 3208 | if (!context->getExtensions().multiviewMultisample) |
| 3209 | { |
| 3210 | context->handleError(InvalidOperation() |
| 3211 | << "Texture's target must be GL_TEXTURE_2D_ARRAY."); |
| 3212 | return false; |
| 3213 | } |
| 3214 | } |
| 3215 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3216 | const Caps &caps = context->getCaps(); |
| 3217 | if (static_cast<GLuint>(baseViewIndex + numViews) > caps.maxArrayTextureLayers) |
| 3218 | { |
| 3219 | context->handleError(InvalidValue() << "baseViewIndex+numViews cannot be " |
| 3220 | "greater than " |
| 3221 | "GL_MAX_ARRAY_TEXTURE_LAYERS."); |
| 3222 | return false; |
| 3223 | } |
Olli Etuaho | 2c8f084 | 2018-09-12 14:44:55 +0300 | [diff] [blame] | 3224 | |
| 3225 | break; |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3226 | } |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3227 | default: |
| 3228 | context->handleError(InvalidOperation() |
| 3229 | << "Texture's target must be GL_TEXTURE_2D_ARRAY."); |
| 3230 | return false; |
| 3231 | } |
| 3232 | |
| 3233 | if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level)) |
| 3234 | { |
| 3235 | return false; |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | return true; |
| 3240 | } |
| 3241 | |
| 3242 | bool ValidateFramebufferTextureMultiviewSideBySideANGLE(Context *context, |
| 3243 | GLenum target, |
| 3244 | GLenum attachment, |
| 3245 | GLuint texture, |
| 3246 | GLint level, |
| 3247 | GLsizei numViews, |
| 3248 | const GLint *viewportOffsets) |
| 3249 | { |
| 3250 | if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level, |
| 3251 | numViews)) |
| 3252 | { |
| 3253 | return false; |
| 3254 | } |
| 3255 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3256 | if (texture != 0) |
| 3257 | { |
Martin Radev | 14b2126 | 2017-08-25 13:54:37 +0300 | [diff] [blame] | 3258 | const GLsizei numViewportOffsetValues = numViews * 2; |
| 3259 | for (GLsizei i = 0; i < numViewportOffsetValues; ++i) |
| 3260 | { |
| 3261 | if (viewportOffsets[i] < 0) |
| 3262 | { |
| 3263 | context->handleError(InvalidValue() |
| 3264 | << "viewportOffsets cannot contain negative values."); |
| 3265 | return false; |
| 3266 | } |
| 3267 | } |
| 3268 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3269 | Texture *tex = context->getTexture(texture); |
| 3270 | ASSERT(tex); |
| 3271 | |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 3272 | switch (tex->getType()) |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3273 | { |
Corentin Wallez | 99d492c | 2018-02-27 15:17:10 -0500 | [diff] [blame] | 3274 | case TextureType::_2D: |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3275 | break; |
| 3276 | default: |
| 3277 | context->handleError(InvalidOperation() |
| 3278 | << "Texture's target must be GL_TEXTURE_2D."); |
| 3279 | return false; |
| 3280 | } |
| 3281 | |
| 3282 | if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level)) |
| 3283 | { |
| 3284 | return false; |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | return true; |
| 3289 | } |
| 3290 | |
Jamie Madill | ff325f1 | 2017-08-26 15:06:05 -0400 | [diff] [blame] | 3291 | bool ValidateUniform1ui(Context *context, GLint location, GLuint v0) |
| 3292 | { |
| 3293 | return ValidateUniformES3(context, GL_UNSIGNED_INT, location, 1); |
| 3294 | } |
| 3295 | |
| 3296 | bool ValidateUniform2ui(Context *context, GLint location, GLuint v0, GLuint v1) |
| 3297 | { |
| 3298 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC2, location, 1); |
| 3299 | } |
| 3300 | |
| 3301 | bool ValidateUniform3ui(Context *context, GLint location, GLuint v0, GLuint v1, GLuint v2) |
| 3302 | { |
| 3303 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC3, location, 1); |
| 3304 | } |
| 3305 | |
| 3306 | bool ValidateUniform4ui(Context *context, |
| 3307 | GLint location, |
| 3308 | GLuint v0, |
| 3309 | GLuint v1, |
| 3310 | GLuint v2, |
| 3311 | GLuint v3) |
| 3312 | { |
| 3313 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC4, location, 1); |
| 3314 | } |
| 3315 | |
| 3316 | bool ValidateUniform1uiv(Context *context, GLint location, GLsizei count, const GLuint *value) |
| 3317 | { |
| 3318 | return ValidateUniformES3(context, GL_UNSIGNED_INT, location, count); |
| 3319 | } |
| 3320 | |
| 3321 | bool ValidateUniform2uiv(Context *context, GLint location, GLsizei count, const GLuint *value) |
| 3322 | { |
| 3323 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC2, location, count); |
| 3324 | } |
| 3325 | |
| 3326 | bool ValidateUniform3uiv(Context *context, GLint location, GLsizei count, const GLuint *value) |
| 3327 | { |
| 3328 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC3, location, count); |
| 3329 | } |
| 3330 | |
| 3331 | bool ValidateUniform4uiv(Context *context, GLint location, GLsizei count, const GLuint *value) |
| 3332 | { |
| 3333 | return ValidateUniformES3(context, GL_UNSIGNED_INT_VEC4, location, count); |
| 3334 | } |
| 3335 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 3336 | bool ValidateIsQuery(Context *context, GLuint id) |
| 3337 | { |
| 3338 | if (context->getClientMajorVersion() < 3) |
| 3339 | { |
| 3340 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3341 | return false; |
| 3342 | } |
| 3343 | |
| 3344 | return true; |
| 3345 | } |
| 3346 | |
Jamie Madill | c8c9581 | 2017-08-26 18:40:09 -0400 | [diff] [blame] | 3347 | bool ValidateUniformMatrix2x3fv(Context *context, |
| 3348 | GLint location, |
| 3349 | GLsizei count, |
| 3350 | GLboolean transpose, |
| 3351 | const GLfloat *value) |
| 3352 | { |
| 3353 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT2x3, location, count, transpose); |
| 3354 | } |
| 3355 | |
| 3356 | bool ValidateUniformMatrix3x2fv(Context *context, |
| 3357 | GLint location, |
| 3358 | GLsizei count, |
| 3359 | GLboolean transpose, |
| 3360 | const GLfloat *value) |
| 3361 | { |
| 3362 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT3x2, location, count, transpose); |
| 3363 | } |
| 3364 | |
| 3365 | bool ValidateUniformMatrix2x4fv(Context *context, |
| 3366 | GLint location, |
| 3367 | GLsizei count, |
| 3368 | GLboolean transpose, |
| 3369 | const GLfloat *value) |
| 3370 | { |
| 3371 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT2x4, location, count, transpose); |
| 3372 | } |
| 3373 | |
| 3374 | bool ValidateUniformMatrix4x2fv(Context *context, |
| 3375 | GLint location, |
| 3376 | GLsizei count, |
| 3377 | GLboolean transpose, |
| 3378 | const GLfloat *value) |
| 3379 | { |
| 3380 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT4x2, location, count, transpose); |
| 3381 | } |
| 3382 | |
| 3383 | bool ValidateUniformMatrix3x4fv(Context *context, |
| 3384 | GLint location, |
| 3385 | GLsizei count, |
| 3386 | GLboolean transpose, |
| 3387 | const GLfloat *value) |
| 3388 | { |
| 3389 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT3x4, location, count, transpose); |
| 3390 | } |
| 3391 | |
| 3392 | bool ValidateUniformMatrix4x3fv(Context *context, |
| 3393 | GLint location, |
| 3394 | GLsizei count, |
| 3395 | GLboolean transpose, |
| 3396 | const GLfloat *value) |
| 3397 | { |
| 3398 | return ValidateUniformMatrixES3(context, GL_FLOAT_MAT4x3, location, count, transpose); |
| 3399 | } |
| 3400 | |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 3401 | bool ValidateEndTransformFeedback(Context *context) |
| 3402 | { |
| 3403 | if (context->getClientMajorVersion() < 3) |
| 3404 | { |
| 3405 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3406 | return false; |
| 3407 | } |
| 3408 | |
| 3409 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3410 | ASSERT(transformFeedback != nullptr); |
| 3411 | |
| 3412 | if (!transformFeedback->isActive()) |
| 3413 | { |
| 3414 | context->handleError(InvalidOperation()); |
| 3415 | return false; |
| 3416 | } |
| 3417 | |
| 3418 | return true; |
| 3419 | } |
| 3420 | |
| 3421 | bool ValidateTransformFeedbackVaryings(Context *context, |
| 3422 | GLuint program, |
| 3423 | GLsizei count, |
| 3424 | const GLchar *const *varyings, |
| 3425 | GLenum bufferMode) |
| 3426 | { |
| 3427 | if (context->getClientMajorVersion() < 3) |
| 3428 | { |
| 3429 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3430 | return false; |
| 3431 | } |
| 3432 | |
| 3433 | if (count < 0) |
| 3434 | { |
| 3435 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3436 | return false; |
| 3437 | } |
| 3438 | |
| 3439 | switch (bufferMode) |
| 3440 | { |
| 3441 | case GL_INTERLEAVED_ATTRIBS: |
| 3442 | break; |
| 3443 | case GL_SEPARATE_ATTRIBS: |
| 3444 | { |
| 3445 | const Caps &caps = context->getCaps(); |
| 3446 | if (static_cast<GLuint>(count) > caps.maxTransformFeedbackSeparateAttributes) |
| 3447 | { |
| 3448 | context->handleError(InvalidValue()); |
| 3449 | return false; |
| 3450 | } |
| 3451 | break; |
| 3452 | } |
| 3453 | default: |
| 3454 | context->handleError(InvalidEnum()); |
| 3455 | return false; |
| 3456 | } |
| 3457 | |
| 3458 | Program *programObject = GetValidProgram(context, program); |
| 3459 | if (!programObject) |
| 3460 | { |
| 3461 | return false; |
| 3462 | } |
| 3463 | |
| 3464 | return true; |
| 3465 | } |
| 3466 | |
| 3467 | bool ValidateGetTransformFeedbackVarying(Context *context, |
| 3468 | GLuint program, |
| 3469 | GLuint index, |
| 3470 | GLsizei bufSize, |
| 3471 | GLsizei *length, |
| 3472 | GLsizei *size, |
| 3473 | GLenum *type, |
| 3474 | GLchar *name) |
| 3475 | { |
| 3476 | if (context->getClientMajorVersion() < 3) |
| 3477 | { |
| 3478 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3479 | return false; |
| 3480 | } |
| 3481 | |
| 3482 | if (bufSize < 0) |
| 3483 | { |
| 3484 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
| 3485 | return false; |
| 3486 | } |
| 3487 | |
| 3488 | Program *programObject = GetValidProgram(context, program); |
| 3489 | if (!programObject) |
| 3490 | { |
| 3491 | return false; |
| 3492 | } |
| 3493 | |
| 3494 | if (index >= static_cast<GLuint>(programObject->getTransformFeedbackVaryingCount())) |
| 3495 | { |
| 3496 | context->handleError(InvalidValue()); |
| 3497 | return false; |
| 3498 | } |
| 3499 | |
| 3500 | return true; |
| 3501 | } |
| 3502 | |
| 3503 | bool ValidateBindTransformFeedback(Context *context, GLenum target, GLuint id) |
| 3504 | { |
| 3505 | if (context->getClientMajorVersion() < 3) |
| 3506 | { |
| 3507 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3508 | return false; |
| 3509 | } |
| 3510 | |
| 3511 | switch (target) |
| 3512 | { |
| 3513 | case GL_TRANSFORM_FEEDBACK: |
| 3514 | { |
| 3515 | // Cannot bind a transform feedback object if the current one is started and not |
| 3516 | // paused (3.0.2 pg 85 section 2.14.1) |
| 3517 | TransformFeedback *curTransformFeedback = |
| 3518 | context->getGLState().getCurrentTransformFeedback(); |
| 3519 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 3520 | !curTransformFeedback->isPaused()) |
| 3521 | { |
| 3522 | context->handleError(InvalidOperation()); |
| 3523 | return false; |
| 3524 | } |
| 3525 | |
| 3526 | // Cannot bind a transform feedback object that does not exist (3.0.2 pg 85 section |
| 3527 | // 2.14.1) |
| 3528 | if (!context->isTransformFeedbackGenerated(id)) |
| 3529 | { |
| 3530 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackDoesNotExist); |
| 3531 | return false; |
| 3532 | } |
| 3533 | } |
| 3534 | break; |
| 3535 | |
| 3536 | default: |
| 3537 | context->handleError(InvalidEnum()); |
| 3538 | return false; |
| 3539 | } |
| 3540 | |
| 3541 | return true; |
| 3542 | } |
| 3543 | |
| 3544 | bool ValidateIsTransformFeedback(Context *context, GLuint id) |
| 3545 | { |
| 3546 | if (context->getClientMajorVersion() < 3) |
| 3547 | { |
| 3548 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3549 | return false; |
| 3550 | } |
| 3551 | |
| 3552 | return true; |
| 3553 | } |
| 3554 | |
| 3555 | bool ValidatePauseTransformFeedback(Context *context) |
| 3556 | { |
| 3557 | if (context->getClientMajorVersion() < 3) |
| 3558 | { |
| 3559 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3560 | return false; |
| 3561 | } |
| 3562 | |
| 3563 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3564 | ASSERT(transformFeedback != nullptr); |
| 3565 | |
| 3566 | // Current transform feedback must be active and not paused in order to pause (3.0.2 pg 86) |
| 3567 | if (!transformFeedback->isActive() || transformFeedback->isPaused()) |
| 3568 | { |
| 3569 | context->handleError(InvalidOperation()); |
| 3570 | return false; |
| 3571 | } |
| 3572 | |
| 3573 | return true; |
| 3574 | } |
| 3575 | |
| 3576 | bool ValidateResumeTransformFeedback(Context *context) |
| 3577 | { |
| 3578 | if (context->getClientMajorVersion() < 3) |
| 3579 | { |
| 3580 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3581 | return false; |
| 3582 | } |
| 3583 | |
| 3584 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
| 3585 | ASSERT(transformFeedback != nullptr); |
| 3586 | |
| 3587 | // Current transform feedback must be active and paused in order to resume (3.0.2 pg 86) |
| 3588 | if (!transformFeedback->isActive() || !transformFeedback->isPaused()) |
| 3589 | { |
| 3590 | context->handleError(InvalidOperation()); |
| 3591 | return false; |
| 3592 | } |
| 3593 | |
| 3594 | return true; |
| 3595 | } |
| 3596 | |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 3597 | bool ValidateVertexAttribI4i(Context *context, GLuint index, GLint x, GLint y, GLint z, GLint w) |
| 3598 | { |
| 3599 | if (context->getClientMajorVersion() < 3) |
| 3600 | { |
| 3601 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3602 | return false; |
| 3603 | } |
| 3604 | |
| 3605 | return ValidateVertexAttribIndex(context, index); |
| 3606 | } |
| 3607 | |
| 3608 | bool ValidateVertexAttribI4ui(Context *context, |
| 3609 | GLuint index, |
| 3610 | GLuint x, |
| 3611 | GLuint y, |
| 3612 | GLuint z, |
| 3613 | GLuint w) |
| 3614 | { |
| 3615 | if (context->getClientMajorVersion() < 3) |
| 3616 | { |
| 3617 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3618 | return false; |
| 3619 | } |
| 3620 | |
| 3621 | return ValidateVertexAttribIndex(context, index); |
| 3622 | } |
| 3623 | |
| 3624 | bool ValidateVertexAttribI4iv(Context *context, GLuint index, const GLint *v) |
| 3625 | { |
| 3626 | if (context->getClientMajorVersion() < 3) |
| 3627 | { |
| 3628 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3629 | return false; |
| 3630 | } |
| 3631 | |
| 3632 | return ValidateVertexAttribIndex(context, index); |
| 3633 | } |
| 3634 | |
| 3635 | bool ValidateVertexAttribI4uiv(Context *context, GLuint index, const GLuint *v) |
| 3636 | { |
| 3637 | if (context->getClientMajorVersion() < 3) |
| 3638 | { |
| 3639 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3640 | return false; |
| 3641 | } |
| 3642 | |
| 3643 | return ValidateVertexAttribIndex(context, index); |
| 3644 | } |
| 3645 | |
| 3646 | bool ValidateGetFragDataLocation(Context *context, GLuint program, const GLchar *name) |
| 3647 | { |
| 3648 | if (context->getClientMajorVersion() < 3) |
| 3649 | { |
| 3650 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3651 | return false; |
| 3652 | } |
| 3653 | |
| 3654 | Program *programObject = GetValidProgram(context, program); |
| 3655 | if (!programObject) |
| 3656 | { |
| 3657 | return false; |
| 3658 | } |
| 3659 | |
| 3660 | if (!programObject->isLinked()) |
| 3661 | { |
| 3662 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 3663 | return false; |
| 3664 | } |
| 3665 | |
| 3666 | return true; |
| 3667 | } |
| 3668 | |
| 3669 | bool ValidateGetUniformIndices(Context *context, |
| 3670 | GLuint program, |
| 3671 | GLsizei uniformCount, |
| 3672 | const GLchar *const *uniformNames, |
| 3673 | GLuint *uniformIndices) |
| 3674 | { |
| 3675 | if (context->getClientMajorVersion() < 3) |
| 3676 | { |
| 3677 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3678 | return false; |
| 3679 | } |
| 3680 | |
| 3681 | if (uniformCount < 0) |
| 3682 | { |
| 3683 | context->handleError(InvalidValue()); |
| 3684 | return false; |
| 3685 | } |
| 3686 | |
| 3687 | Program *programObject = GetValidProgram(context, program); |
| 3688 | if (!programObject) |
| 3689 | { |
| 3690 | return false; |
| 3691 | } |
| 3692 | |
| 3693 | return true; |
| 3694 | } |
| 3695 | |
| 3696 | bool ValidateGetActiveUniformsiv(Context *context, |
| 3697 | GLuint program, |
| 3698 | GLsizei uniformCount, |
| 3699 | const GLuint *uniformIndices, |
| 3700 | GLenum pname, |
| 3701 | GLint *params) |
| 3702 | { |
| 3703 | if (context->getClientMajorVersion() < 3) |
| 3704 | { |
| 3705 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3706 | return false; |
| 3707 | } |
| 3708 | |
| 3709 | if (uniformCount < 0) |
| 3710 | { |
| 3711 | context->handleError(InvalidValue()); |
| 3712 | return false; |
| 3713 | } |
| 3714 | |
| 3715 | Program *programObject = GetValidProgram(context, program); |
| 3716 | if (!programObject) |
| 3717 | { |
| 3718 | return false; |
| 3719 | } |
| 3720 | |
| 3721 | switch (pname) |
| 3722 | { |
| 3723 | case GL_UNIFORM_TYPE: |
| 3724 | case GL_UNIFORM_SIZE: |
Bryan Bernhart | 22f7aaf | 2018-08-23 14:13:51 -0700 | [diff] [blame] | 3725 | break; |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 3726 | case GL_UNIFORM_NAME_LENGTH: |
Bryan Bernhart | 22f7aaf | 2018-08-23 14:13:51 -0700 | [diff] [blame] | 3727 | if (context->getExtensions().webglCompatibility) |
| 3728 | { |
| 3729 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 3730 | return false; |
| 3731 | } |
| 3732 | break; |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 3733 | case GL_UNIFORM_BLOCK_INDEX: |
| 3734 | case GL_UNIFORM_OFFSET: |
| 3735 | case GL_UNIFORM_ARRAY_STRIDE: |
| 3736 | case GL_UNIFORM_MATRIX_STRIDE: |
| 3737 | case GL_UNIFORM_IS_ROW_MAJOR: |
| 3738 | break; |
| 3739 | |
| 3740 | default: |
| 3741 | context->handleError(InvalidEnum()); |
| 3742 | return false; |
| 3743 | } |
| 3744 | |
| 3745 | if (uniformCount > programObject->getActiveUniformCount()) |
| 3746 | { |
| 3747 | context->handleError(InvalidValue()); |
| 3748 | return false; |
| 3749 | } |
| 3750 | |
| 3751 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 3752 | { |
| 3753 | const GLuint index = uniformIndices[uniformId]; |
| 3754 | |
| 3755 | if (index >= static_cast<GLuint>(programObject->getActiveUniformCount())) |
| 3756 | { |
| 3757 | context->handleError(InvalidValue()); |
| 3758 | return false; |
| 3759 | } |
| 3760 | } |
| 3761 | |
| 3762 | return true; |
| 3763 | } |
| 3764 | |
| 3765 | bool ValidateGetUniformBlockIndex(Context *context, GLuint program, const GLchar *uniformBlockName) |
| 3766 | { |
| 3767 | if (context->getClientMajorVersion() < 3) |
| 3768 | { |
| 3769 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3770 | return false; |
| 3771 | } |
| 3772 | |
| 3773 | Program *programObject = GetValidProgram(context, program); |
| 3774 | if (!programObject) |
| 3775 | { |
| 3776 | return false; |
| 3777 | } |
| 3778 | |
| 3779 | return true; |
| 3780 | } |
| 3781 | |
| 3782 | bool ValidateGetActiveUniformBlockiv(Context *context, |
| 3783 | GLuint program, |
| 3784 | GLuint uniformBlockIndex, |
| 3785 | GLenum pname, |
| 3786 | GLint *params) |
| 3787 | { |
| 3788 | return ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, nullptr); |
| 3789 | } |
| 3790 | |
| 3791 | bool ValidateGetActiveUniformBlockName(Context *context, |
| 3792 | GLuint program, |
| 3793 | GLuint uniformBlockIndex, |
| 3794 | GLsizei bufSize, |
| 3795 | GLsizei *length, |
| 3796 | GLchar *uniformBlockName) |
| 3797 | { |
| 3798 | if (context->getClientMajorVersion() < 3) |
| 3799 | { |
| 3800 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3801 | return false; |
| 3802 | } |
| 3803 | |
| 3804 | Program *programObject = GetValidProgram(context, program); |
| 3805 | if (!programObject) |
| 3806 | { |
| 3807 | return false; |
| 3808 | } |
| 3809 | |
| 3810 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 3811 | { |
| 3812 | context->handleError(InvalidValue()); |
| 3813 | return false; |
| 3814 | } |
| 3815 | |
| 3816 | return true; |
| 3817 | } |
| 3818 | |
| 3819 | bool ValidateUniformBlockBinding(Context *context, |
| 3820 | GLuint program, |
| 3821 | GLuint uniformBlockIndex, |
| 3822 | GLuint uniformBlockBinding) |
| 3823 | { |
| 3824 | if (context->getClientMajorVersion() < 3) |
| 3825 | { |
| 3826 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3827 | return false; |
| 3828 | } |
| 3829 | |
| 3830 | if (uniformBlockBinding >= context->getCaps().maxUniformBufferBindings) |
| 3831 | { |
| 3832 | context->handleError(InvalidValue()); |
| 3833 | return false; |
| 3834 | } |
| 3835 | |
| 3836 | Program *programObject = GetValidProgram(context, program); |
| 3837 | if (!programObject) |
| 3838 | { |
| 3839 | return false; |
| 3840 | } |
| 3841 | |
| 3842 | // if never linked, there won't be any uniform blocks |
| 3843 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 3844 | { |
| 3845 | context->handleError(InvalidValue()); |
| 3846 | return false; |
| 3847 | } |
| 3848 | |
| 3849 | return true; |
| 3850 | } |
| 3851 | |
| 3852 | bool ValidateDrawArraysInstanced(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3853 | PrimitiveMode mode, |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 3854 | GLint first, |
| 3855 | GLsizei count, |
| 3856 | GLsizei primcount) |
| 3857 | { |
| 3858 | if (context->getClientMajorVersion() < 3) |
| 3859 | { |
| 3860 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3861 | return false; |
| 3862 | } |
| 3863 | |
| 3864 | return ValidateDrawArraysInstancedBase(context, mode, first, count, primcount); |
| 3865 | } |
| 3866 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 3867 | bool ValidateFenceSync(Context *context, GLenum condition, GLbitfield flags) |
| 3868 | { |
| 3869 | if (context->getClientMajorVersion() < 3) |
| 3870 | { |
| 3871 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3872 | return false; |
| 3873 | } |
| 3874 | |
| 3875 | if (condition != GL_SYNC_GPU_COMMANDS_COMPLETE) |
| 3876 | { |
| 3877 | context->handleError(InvalidEnum()); |
| 3878 | return false; |
| 3879 | } |
| 3880 | |
| 3881 | if (flags != 0) |
| 3882 | { |
| 3883 | context->handleError(InvalidValue()); |
| 3884 | return false; |
| 3885 | } |
| 3886 | |
| 3887 | return true; |
| 3888 | } |
| 3889 | |
| 3890 | bool ValidateIsSync(Context *context, GLsync sync) |
| 3891 | { |
| 3892 | if (context->getClientMajorVersion() < 3) |
| 3893 | { |
| 3894 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3895 | return false; |
| 3896 | } |
| 3897 | |
| 3898 | return true; |
| 3899 | } |
| 3900 | |
| 3901 | bool ValidateDeleteSync(Context *context, GLsync sync) |
| 3902 | { |
| 3903 | if (context->getClientMajorVersion() < 3) |
| 3904 | { |
| 3905 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3906 | return false; |
| 3907 | } |
| 3908 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 3909 | if (sync != static_cast<GLsync>(0) && !context->getSync(sync)) |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 3910 | { |
| 3911 | context->handleError(InvalidValue()); |
| 3912 | return false; |
| 3913 | } |
| 3914 | |
| 3915 | return true; |
| 3916 | } |
| 3917 | |
| 3918 | bool ValidateClientWaitSync(Context *context, GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 3919 | { |
| 3920 | if (context->getClientMajorVersion() < 3) |
| 3921 | { |
| 3922 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3923 | return false; |
| 3924 | } |
| 3925 | |
| 3926 | if ((flags & ~(GL_SYNC_FLUSH_COMMANDS_BIT)) != 0) |
| 3927 | { |
| 3928 | context->handleError(InvalidValue()); |
| 3929 | return false; |
| 3930 | } |
| 3931 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 3932 | Sync *clientWaitSync = context->getSync(sync); |
| 3933 | if (!clientWaitSync) |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 3934 | { |
| 3935 | context->handleError(InvalidValue()); |
| 3936 | return false; |
| 3937 | } |
| 3938 | |
| 3939 | return true; |
| 3940 | } |
| 3941 | |
| 3942 | bool ValidateWaitSync(Context *context, GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 3943 | { |
| 3944 | if (context->getClientMajorVersion() < 3) |
| 3945 | { |
| 3946 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3947 | return false; |
| 3948 | } |
| 3949 | |
| 3950 | if (flags != 0) |
| 3951 | { |
| 3952 | context->handleError(InvalidValue()); |
| 3953 | return false; |
| 3954 | } |
| 3955 | |
| 3956 | if (timeout != GL_TIMEOUT_IGNORED) |
| 3957 | { |
| 3958 | context->handleError(InvalidValue()); |
| 3959 | return false; |
| 3960 | } |
| 3961 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 3962 | Sync *waitSync = context->getSync(sync); |
| 3963 | if (!waitSync) |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 3964 | { |
| 3965 | context->handleError(InvalidValue()); |
| 3966 | return false; |
| 3967 | } |
| 3968 | |
| 3969 | return true; |
| 3970 | } |
| 3971 | |
| 3972 | bool ValidateGetInteger64v(Context *context, GLenum pname, GLint64 *params) |
| 3973 | { |
| 3974 | if (context->getClientMajorVersion() < 3) |
| 3975 | { |
| 3976 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 3977 | return false; |
| 3978 | } |
| 3979 | |
| 3980 | GLenum nativeType = GL_NONE; |
| 3981 | unsigned int numParams = 0; |
| 3982 | if (!ValidateStateQuery(context, pname, &nativeType, &numParams)) |
| 3983 | { |
| 3984 | return false; |
| 3985 | } |
| 3986 | |
| 3987 | return true; |
| 3988 | } |
| 3989 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 3990 | bool ValidateIsSampler(Context *context, GLuint sampler) |
| 3991 | { |
| 3992 | if (context->getClientMajorVersion() < 3) |
| 3993 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3994 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 3995 | return false; |
| 3996 | } |
| 3997 | |
| 3998 | return true; |
| 3999 | } |
| 4000 | |
| 4001 | bool ValidateBindSampler(Context *context, GLuint unit, GLuint sampler) |
| 4002 | { |
| 4003 | if (context->getClientMajorVersion() < 3) |
| 4004 | { |
| 4005 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4006 | return false; |
| 4007 | } |
| 4008 | |
| 4009 | if (sampler != 0 && !context->isSampler(sampler)) |
| 4010 | { |
| 4011 | context->handleError(InvalidOperation()); |
| 4012 | return false; |
| 4013 | } |
| 4014 | |
| 4015 | if (unit >= context->getCaps().maxCombinedTextureImageUnits) |
| 4016 | { |
| 4017 | context->handleError(InvalidValue()); |
| 4018 | return false; |
| 4019 | } |
| 4020 | |
| 4021 | return true; |
| 4022 | } |
| 4023 | |
| 4024 | bool ValidateVertexAttribDivisor(Context *context, GLuint index, GLuint divisor) |
| 4025 | { |
| 4026 | if (context->getClientMajorVersion() < 3) |
| 4027 | { |
| 4028 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4029 | return false; |
| 4030 | } |
| 4031 | |
| 4032 | return ValidateVertexAttribIndex(context, index); |
| 4033 | } |
| 4034 | |
| 4035 | bool ValidateTexStorage2D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4036 | TextureType target, |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 4037 | GLsizei levels, |
| 4038 | GLenum internalformat, |
| 4039 | GLsizei width, |
| 4040 | GLsizei height) |
| 4041 | { |
| 4042 | if (context->getClientMajorVersion() < 3) |
| 4043 | { |
| 4044 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4045 | return false; |
| 4046 | } |
| 4047 | |
| 4048 | if (!ValidateES3TexStorage2DParameters(context, target, levels, internalformat, width, height, |
| 4049 | 1)) |
| 4050 | { |
| 4051 | return false; |
| 4052 | } |
| 4053 | |
| 4054 | return true; |
| 4055 | } |
| 4056 | |
| 4057 | bool ValidateTexStorage3D(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4058 | TextureType target, |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 4059 | GLsizei levels, |
| 4060 | GLenum internalformat, |
| 4061 | GLsizei width, |
| 4062 | GLsizei height, |
| 4063 | GLsizei depth) |
| 4064 | { |
| 4065 | if (context->getClientMajorVersion() < 3) |
| 4066 | { |
| 4067 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4068 | return false; |
| 4069 | } |
| 4070 | |
| 4071 | if (!ValidateES3TexStorage3DParameters(context, target, levels, internalformat, width, height, |
| 4072 | depth)) |
| 4073 | { |
| 4074 | return false; |
| 4075 | } |
| 4076 | |
| 4077 | return true; |
| 4078 | } |
| 4079 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4080 | bool ValidateGetBufferParameteri64v(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4081 | BufferBinding target, |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4082 | GLenum pname, |
| 4083 | GLint64 *params) |
| 4084 | { |
| 4085 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 4086 | } |
| 4087 | |
| 4088 | bool ValidateGetSamplerParameterfv(Context *context, GLuint sampler, GLenum pname, GLfloat *params) |
| 4089 | { |
| 4090 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 4091 | } |
| 4092 | |
| 4093 | bool ValidateGetSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, GLint *params) |
| 4094 | { |
| 4095 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 4096 | } |
| 4097 | |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4098 | bool ValidateGetSamplerParameterIivOES(Context *context, |
| 4099 | GLuint sampler, |
| 4100 | GLenum pname, |
| 4101 | const GLint *params) |
| 4102 | { |
| 4103 | if (context->getClientMajorVersion() < 3) |
| 4104 | { |
| 4105 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4106 | return false; |
| 4107 | } |
| 4108 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 4109 | } |
| 4110 | |
| 4111 | bool ValidateGetSamplerParameterIuivOES(Context *context, |
| 4112 | GLuint sampler, |
| 4113 | GLenum pname, |
| 4114 | const GLuint *params) |
| 4115 | { |
| 4116 | if (context->getClientMajorVersion() < 3) |
| 4117 | { |
| 4118 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4119 | return false; |
| 4120 | } |
| 4121 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 4122 | } |
| 4123 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4124 | bool ValidateSamplerParameterf(Context *context, GLuint sampler, GLenum pname, GLfloat param) |
| 4125 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4126 | return ValidateSamplerParameterBase(context, sampler, pname, -1, false, ¶m); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4127 | } |
| 4128 | |
| 4129 | bool ValidateSamplerParameterfv(Context *context, |
| 4130 | GLuint sampler, |
| 4131 | GLenum pname, |
| 4132 | const GLfloat *params) |
| 4133 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4134 | return ValidateSamplerParameterBase(context, sampler, pname, -1, true, params); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4135 | } |
| 4136 | |
| 4137 | bool ValidateSamplerParameteri(Context *context, GLuint sampler, GLenum pname, GLint param) |
| 4138 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4139 | return ValidateSamplerParameterBase(context, sampler, pname, -1, false, ¶m); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4140 | } |
| 4141 | |
| 4142 | bool ValidateSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, const GLint *params) |
| 4143 | { |
Till Rathmann | b854363 | 2018-10-02 19:46:14 +0200 | [diff] [blame] | 4144 | return ValidateSamplerParameterBase(context, sampler, pname, -1, true, params); |
| 4145 | } |
| 4146 | |
| 4147 | bool ValidateSamplerParameterIivOES(Context *context, |
| 4148 | GLuint sampler, |
| 4149 | GLenum pname, |
| 4150 | const GLint *params) |
| 4151 | { |
| 4152 | if (context->getClientMajorVersion() < 3) |
| 4153 | { |
| 4154 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4155 | return false; |
| 4156 | } |
| 4157 | return ValidateSamplerParameterBase(context, sampler, pname, -1, true, params); |
| 4158 | } |
| 4159 | |
| 4160 | bool ValidateSamplerParameterIuivOES(Context *context, |
| 4161 | GLuint sampler, |
| 4162 | GLenum pname, |
| 4163 | const GLuint *params) |
| 4164 | { |
| 4165 | if (context->getClientMajorVersion() < 3) |
| 4166 | { |
| 4167 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4168 | return false; |
| 4169 | } |
| 4170 | return ValidateSamplerParameterBase(context, sampler, pname, -1, true, params); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | bool ValidateGetVertexAttribIiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 4174 | { |
| 4175 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true); |
| 4176 | } |
| 4177 | |
| 4178 | bool ValidateGetVertexAttribIuiv(Context *context, GLuint index, GLenum pname, GLuint *params) |
| 4179 | { |
| 4180 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true); |
| 4181 | } |
| 4182 | |
| 4183 | bool ValidateGetInternalformativ(Context *context, |
| 4184 | GLenum target, |
| 4185 | GLenum internalformat, |
| 4186 | GLenum pname, |
| 4187 | GLsizei bufSize, |
| 4188 | GLint *params) |
| 4189 | { |
| 4190 | return ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 4191 | nullptr); |
| 4192 | } |
| 4193 | |
Olli Etuaho | 0ca0975 | 2018-09-24 11:00:50 +0300 | [diff] [blame] | 4194 | bool ValidateBindFragDataLocationIndexedEXT(Context *context, |
| 4195 | GLuint program, |
| 4196 | GLuint colorNumber, |
| 4197 | GLuint index, |
| 4198 | const char *name) |
| 4199 | { |
| 4200 | if (!context->getExtensions().blendFuncExtended) |
| 4201 | { |
| 4202 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 4203 | return false; |
| 4204 | } |
| 4205 | if (context->getClientMajorVersion() < 3) |
| 4206 | { |
| 4207 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4208 | return false; |
| 4209 | } |
| 4210 | if (index < 0 || index > 1) |
| 4211 | { |
| 4212 | // This error is not explicitly specified but the spec does say that "<index> may be zero or |
| 4213 | // one to specify that the color be used as either the first or second color input to the |
| 4214 | // blend equation, respectively" |
| 4215 | ANGLE_VALIDATION_ERR(context, InvalidValue(), FragDataBindingIndexOutOfRange); |
| 4216 | return false; |
| 4217 | } |
| 4218 | if (index == 1) |
| 4219 | { |
| 4220 | if (colorNumber >= context->getExtensions().maxDualSourceDrawBuffers) |
| 4221 | { |
| 4222 | ANGLE_VALIDATION_ERR(context, InvalidValue(), |
| 4223 | ColorNumberGreaterThanMaxDualSourceDrawBuffers); |
| 4224 | return false; |
| 4225 | } |
| 4226 | } |
| 4227 | else |
| 4228 | { |
| 4229 | if (colorNumber >= context->getCaps().maxDrawBuffers) |
| 4230 | { |
| 4231 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ColorNumberGreaterThanMaxDrawBuffers); |
| 4232 | return false; |
| 4233 | } |
| 4234 | } |
| 4235 | Program *programObject = GetValidProgram(context, program); |
| 4236 | if (!programObject) |
| 4237 | { |
| 4238 | return false; |
| 4239 | } |
| 4240 | return true; |
| 4241 | } |
| 4242 | |
| 4243 | bool ValidateBindFragDataLocationEXT(Context *context, |
| 4244 | GLuint program, |
| 4245 | GLuint colorNumber, |
| 4246 | const char *name) |
| 4247 | { |
| 4248 | return ValidateBindFragDataLocationIndexedEXT(context, program, colorNumber, 0u, name); |
| 4249 | } |
| 4250 | |
| 4251 | bool ValidateGetFragDataIndexEXT(Context *context, GLuint program, const char *name) |
| 4252 | { |
| 4253 | if (!context->getExtensions().blendFuncExtended) |
| 4254 | { |
| 4255 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 4256 | return false; |
| 4257 | } |
| 4258 | if (context->getClientMajorVersion() < 3) |
| 4259 | { |
| 4260 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 4261 | return false; |
| 4262 | } |
| 4263 | Program *programObject = GetValidProgram(context, program); |
| 4264 | if (!programObject) |
| 4265 | { |
| 4266 | return false; |
| 4267 | } |
| 4268 | if (!programObject->isLinked()) |
| 4269 | { |
| 4270 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4271 | return false; |
| 4272 | } |
| 4273 | return true; |
| 4274 | } |
| 4275 | |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 4276 | bool ValidateTexStorage2DMultisampleANGLE(Context *context, |
| 4277 | TextureType target, |
| 4278 | GLsizei samples, |
| 4279 | GLint internalFormat, |
| 4280 | GLsizei width, |
| 4281 | GLsizei height, |
| 4282 | GLboolean fixedSampleLocations) |
| 4283 | { |
| 4284 | if (!context->getExtensions().textureMultisample) |
| 4285 | { |
| 4286 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 4287 | MultisampleTextureExtensionOrES31Required); |
| 4288 | return false; |
| 4289 | } |
| 4290 | |
| 4291 | return ValidateTexStorage2DMultisampleBase(context, target, samples, internalFormat, width, |
| 4292 | height); |
| 4293 | } |
| 4294 | |
Yizhou Jiang | c0b6c63 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 4295 | bool ValidateGetTexLevelParameterfvANGLE(Context *context, |
| 4296 | TextureTarget target, |
| 4297 | GLint level, |
| 4298 | GLenum pname, |
| 4299 | GLfloat *params) |
| 4300 | { |
| 4301 | if (!context->getExtensions().textureMultisample) |
| 4302 | { |
| 4303 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 4304 | MultisampleTextureExtensionOrES31Required); |
| 4305 | return false; |
| 4306 | } |
| 4307 | |
| 4308 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 4309 | } |
| 4310 | |
| 4311 | bool ValidateGetTexLevelParameterivANGLE(Context *context, |
| 4312 | TextureTarget target, |
| 4313 | GLint level, |
| 4314 | GLenum pname, |
| 4315 | GLint *params) |
| 4316 | { |
| 4317 | if (!context->getExtensions().textureMultisample) |
| 4318 | { |
| 4319 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 4320 | MultisampleTextureExtensionOrES31Required); |
| 4321 | return false; |
| 4322 | } |
| 4323 | |
| 4324 | return ValidateGetTexLevelParameterBase(context, target, level, pname, nullptr); |
| 4325 | } |
| 4326 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4327 | } // namespace gl |