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