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