Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Jamie Madill | 5ea762a | 2017-06-07 14:59:51 -0400 | [diff] [blame] | 11 | #include "anglebase/numerics/safe_conversions.h" |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 12 | #include "common/mathutil.h" |
| 13 | #include "common/utilities.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 15 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/Framebuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Renderbuffer.h" |
| 19 | #include "libANGLE/Texture.h" |
| 20 | #include "libANGLE/formatutils.h" |
| 21 | #include "libANGLE/validationES.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 22 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 23 | using namespace angle; |
| 24 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 25 | namespace gl |
| 26 | { |
| 27 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 28 | namespace |
| 29 | { |
| 30 | bool ValidateFramebufferTextureMultiviewBaseANGLE(Context *context, |
| 31 | GLenum target, |
| 32 | GLenum attachment, |
| 33 | GLuint texture, |
| 34 | GLint level, |
| 35 | GLsizei numViews) |
| 36 | { |
| 37 | if (!context->getExtensions().multiview) |
| 38 | { |
| 39 | context->handleError(InvalidOperation() << "ANGLE_multiview is not available."); |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 44 | { |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | if (numViews < 1) |
| 49 | { |
| 50 | context->handleError(InvalidValue() << "numViews cannot be less than 1."); |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | const Extensions &extensions = context->getExtensions(); |
| 55 | if (static_cast<GLuint>(numViews) > extensions.maxViews) |
| 56 | { |
| 57 | context->handleError(InvalidValue() |
| 58 | << "numViews cannot be greater than GL_MAX_VIEWS_ANGLE."); |
| 59 | return false; |
| 60 | } |
| 61 | |
| 62 | return true; |
| 63 | } |
| 64 | |
| 65 | bool ValidateFramebufferTextureMultiviewLevelAndFormat(Context *context, |
| 66 | Texture *texture, |
| 67 | GLint level) |
| 68 | { |
| 69 | GLenum texTarget = texture->getTarget(); |
| 70 | if (!ValidMipLevel(context, texTarget, level)) |
| 71 | { |
| 72 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
| 73 | return false; |
| 74 | } |
| 75 | |
| 76 | const auto &format = texture->getFormat(texTarget, level); |
| 77 | if (format.info->compressed) |
| 78 | { |
| 79 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), CompressedTexturesNotAttachable); |
| 80 | return false; |
| 81 | } |
| 82 | return true; |
| 83 | } |
| 84 | |
| 85 | } // namespace |
| 86 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 87 | static bool ValidateTexImageFormatCombination(gl::Context *context, |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 88 | GLenum target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 89 | GLenum internalFormat, |
| 90 | GLenum format, |
| 91 | GLenum type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 92 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 93 | |
| 94 | // 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] | 95 | if (!ValidES3Format(format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 96 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 97 | context->handleError(InvalidEnum() << "Invalid format."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 98 | return false; |
| 99 | } |
| 100 | |
| 101 | if (!ValidES3Type(type)) |
| 102 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 103 | context->handleError(InvalidEnum() << "Invalid type."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 104 | return false; |
| 105 | } |
| 106 | |
| 107 | // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a |
| 108 | // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE |
| 109 | // error instead of a GL_INVALID_ENUM error. As this validation function is only called in |
| 110 | // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error. |
| 111 | if (!ValidES3InternalFormat(internalFormat)) |
| 112 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 113 | context->handleError(InvalidValue() << "Invalid internalFormat."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 114 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 115 | } |
| 116 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 117 | // From the ES 3.0 spec section 3.8.3: |
| 118 | // Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL are supported by |
| 119 | // texture image specification commands only if target is TEXTURE_2D, TEXTURE_2D_ARRAY, or |
| 120 | // TEXTURE_CUBE_MAP.Using these formats in conjunction with any other target will result in an |
| 121 | // INVALID_OPERATION error. |
| 122 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 123 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 124 | context->handleError(InvalidOperation() << "Format cannot be GL_DEPTH_COMPONENT or " |
| 125 | "GL_DEPTH_STENCIL if target is " |
| 126 | "GL_TEXTURE_3D"); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 130 | // Check if this is a valid format combination to load texture data |
Jamie Madill | 55e9821 | 2016-10-05 16:39:13 -0400 | [diff] [blame] | 131 | if (!ValidES3FormatCombination(format, type, internalFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 132 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 133 | context->handleError(InvalidOperation() |
| 134 | << "Invalid combination of format, type and internalFormat."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 135 | return false; |
| 136 | } |
| 137 | |
| 138 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); |
| 139 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 140 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 141 | context->handleError(InvalidOperation() << "Unsupported internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 142 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | return true; |
| 146 | } |
| 147 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 148 | bool ValidateES3TexImageParametersBase(Context *context, |
| 149 | GLenum target, |
| 150 | GLint level, |
| 151 | GLenum internalformat, |
| 152 | bool isCompressed, |
| 153 | bool isSubImage, |
| 154 | GLint xoffset, |
| 155 | GLint yoffset, |
| 156 | GLint zoffset, |
| 157 | GLsizei width, |
| 158 | GLsizei height, |
| 159 | GLsizei depth, |
| 160 | GLint border, |
| 161 | GLenum format, |
| 162 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 163 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 164 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 165 | { |
| 166 | // Validate image size |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 167 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 168 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 169 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 170 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 171 | } |
| 172 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 173 | // Verify zero border |
| 174 | if (border != 0) |
| 175 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 176 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 177 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 178 | } |
| 179 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 180 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 181 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 182 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 183 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 184 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 185 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 186 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 187 | } |
| 188 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 189 | const gl::Caps &caps = context->getCaps(); |
| 190 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 191 | switch (target) |
| 192 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 193 | case GL_TEXTURE_2D: |
| 194 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 195 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 196 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 197 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 198 | return false; |
| 199 | } |
| 200 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 201 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 202 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 203 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 204 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 205 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 206 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 207 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 208 | if (!isSubImage && width != height) |
| 209 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 210 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 211 | return false; |
| 212 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 213 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 214 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 215 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 216 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 217 | return false; |
| 218 | } |
| 219 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 220 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 221 | case GL_TEXTURE_3D: |
| 222 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 223 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 224 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
| 225 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 226 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 227 | return false; |
| 228 | } |
| 229 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 230 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 231 | case GL_TEXTURE_2D_ARRAY: |
| 232 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 233 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
| 234 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
| 235 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 236 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 237 | return false; |
| 238 | } |
| 239 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 240 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 241 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 242 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 243 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 244 | } |
| 245 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 246 | gl::Texture *texture = |
| 247 | context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 248 | if (!texture) |
| 249 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 250 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 251 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 252 | } |
| 253 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 254 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 255 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 256 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 257 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Validate texture formats |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 261 | GLenum actualInternalFormat = |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 262 | isSubImage ? texture->getFormat(target, level).info->internalFormat : internalformat; |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 263 | if (isSubImage && actualInternalFormat == GL_NONE) |
| 264 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 265 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 266 | return false; |
| 267 | } |
| 268 | |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 269 | const gl::InternalFormat &actualFormatInfo = isSubImage |
| 270 | ? *texture->getFormat(target, level).info |
| 271 | : GetInternalFormatInfo(internalformat, type); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 272 | if (isCompressed) |
| 273 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 274 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 275 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 276 | context->handleError( |
| 277 | InvalidEnum() << "internalformat is not a supported compressed internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 278 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 279 | } |
| 280 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 281 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 282 | { |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 283 | if (!ValidCompressedSubImageSize( |
| 284 | context, actualFormatInfo.internalFormat, xoffset, yoffset, width, height, |
| 285 | texture->getWidth(target, level), texture->getHeight(target, level))) |
| 286 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 287 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 288 | return false; |
| 289 | } |
| 290 | |
| 291 | if (format != actualInternalFormat) |
| 292 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 293 | context->handleError(InvalidOperation() |
| 294 | << "Format must match the internal format of the texture."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 295 | return false; |
| 296 | } |
| 297 | } |
| 298 | else |
| 299 | { |
| 300 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 301 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 302 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 303 | return false; |
| 304 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 307 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 308 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 309 | context->handleError(InvalidEnum()); |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 310 | return false; |
| 311 | } |
| 312 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 313 | if (target == GL_TEXTURE_3D) |
| 314 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 315 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 316 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | else |
| 320 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 321 | if (!ValidateTexImageFormatCombination(context, target, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 322 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 323 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 324 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | // Validate sub image parameters |
| 328 | if (isSubImage) |
| 329 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 330 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 331 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 332 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 333 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 336 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 337 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 338 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 339 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 343 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 344 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 345 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 346 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 347 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 348 | } |
| 349 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 350 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 351 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 352 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 353 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 354 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 355 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 356 | } |
| 357 | } |
| 358 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 359 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 360 | if (!ValidImageDataSize(context, target, width, height, depth, sizeCheckFormat, type, pixels, |
| 361 | imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 362 | { |
| 363 | return false; |
| 364 | } |
| 365 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 366 | // Check for pixel unpack buffer related API errors |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 367 | gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 368 | if (pixelUnpackBuffer != nullptr) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 369 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 370 | // ...data is not evenly divisible into the number of bytes needed to store in memory a |
| 371 | // datum |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 372 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 373 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 374 | { |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 375 | size_t offset = reinterpret_cast<size_t>(pixels); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 376 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 377 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 378 | if ((offset % dataBytesPerPixel) != 0) |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 379 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 380 | context->handleError(InvalidOperation() |
| 381 | << "Reads would overflow the pixel unpack buffer."); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 382 | return false; |
| 383 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 384 | } |
| 385 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 386 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 387 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 388 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 389 | context->handleError(InvalidOperation() << "Pixel unpack buffer is mapped."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 390 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 391 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 394 | return true; |
| 395 | } |
| 396 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 397 | bool ValidateES3TexImage2DParameters(Context *context, |
| 398 | GLenum target, |
| 399 | GLint level, |
| 400 | GLenum internalformat, |
| 401 | bool isCompressed, |
| 402 | bool isSubImage, |
| 403 | GLint xoffset, |
| 404 | GLint yoffset, |
| 405 | GLint zoffset, |
| 406 | GLsizei width, |
| 407 | GLsizei height, |
| 408 | GLsizei depth, |
| 409 | GLint border, |
| 410 | GLenum format, |
| 411 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 412 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 413 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 414 | { |
| 415 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 416 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 417 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 418 | return false; |
| 419 | } |
| 420 | |
| 421 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 422 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 423 | depth, border, format, type, imageSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | bool ValidateES3TexImage3DParameters(Context *context, |
| 427 | GLenum target, |
| 428 | GLint level, |
| 429 | GLenum internalformat, |
| 430 | bool isCompressed, |
| 431 | bool isSubImage, |
| 432 | GLint xoffset, |
| 433 | GLint yoffset, |
| 434 | GLint zoffset, |
| 435 | GLsizei width, |
| 436 | GLsizei height, |
| 437 | GLsizei depth, |
| 438 | GLint border, |
| 439 | GLenum format, |
| 440 | GLenum type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 441 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 442 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 443 | { |
| 444 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 445 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 446 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 447 | return false; |
| 448 | } |
| 449 | |
| 450 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 451 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 452 | depth, border, format, type, bufSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 453 | } |
| 454 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 455 | struct EffectiveInternalFormatInfo |
| 456 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 457 | GLenum effectiveFormat; |
| 458 | GLenum destFormat; |
| 459 | GLuint minRedBits; |
| 460 | GLuint maxRedBits; |
| 461 | GLuint minGreenBits; |
| 462 | GLuint maxGreenBits; |
| 463 | GLuint minBlueBits; |
| 464 | GLuint maxBlueBits; |
| 465 | GLuint minAlphaBits; |
| 466 | GLuint maxAlphaBits; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 467 | }; |
| 468 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 469 | static bool QueryEffectiveFormatList(const InternalFormat &srcFormat, |
| 470 | GLenum targetFormat, |
| 471 | const EffectiveInternalFormatInfo *list, |
| 472 | size_t size, |
| 473 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 474 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 475 | for (size_t curFormat = 0; curFormat < size; ++curFormat) |
| 476 | { |
| 477 | const EffectiveInternalFormatInfo &formatInfo = list[curFormat]; |
| 478 | if ((formatInfo.destFormat == targetFormat) && |
| 479 | (formatInfo.minRedBits <= srcFormat.redBits && |
| 480 | formatInfo.maxRedBits >= srcFormat.redBits) && |
| 481 | (formatInfo.minGreenBits <= srcFormat.greenBits && |
| 482 | formatInfo.maxGreenBits >= srcFormat.greenBits) && |
| 483 | (formatInfo.minBlueBits <= srcFormat.blueBits && |
| 484 | formatInfo.maxBlueBits >= srcFormat.blueBits) && |
| 485 | (formatInfo.minAlphaBits <= srcFormat.alphaBits && |
| 486 | formatInfo.maxAlphaBits >= srcFormat.alphaBits)) |
| 487 | { |
| 488 | *outEffectiveFormat = formatInfo.effectiveFormat; |
| 489 | return true; |
| 490 | } |
| 491 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 492 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 493 | *outEffectiveFormat = GL_NONE; |
| 494 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 495 | } |
| 496 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 497 | bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 498 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 499 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 500 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 501 | // Effective internal format coresponding to destination internal format and linear source |
| 502 | // buffer component sizes. |
| 503 | // | Source channel min/max sizes | |
| 504 | // Effective Internal Format | N/A | R | G | B | A | |
| 505 | // clang-format off |
| 506 | constexpr EffectiveInternalFormatInfo list[] = { |
| 507 | { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 }, |
| 508 | { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 }, |
| 509 | { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 }, |
| 510 | { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 }, |
| 511 | { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 }, |
| 512 | { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 513 | { GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 514 | { GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 }, |
| 515 | { GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 }, |
| 516 | }; |
| 517 | // clang-format on |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 518 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 519 | return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat); |
| 520 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 521 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 522 | bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 523 | const InternalFormat &destFormat, |
| 524 | GLenum *outEffectiveFormat) |
| 525 | { |
| 526 | constexpr GLuint umax = UINT_MAX; |
| 527 | |
| 528 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 529 | // Effective internal format coresponding to destination internal format andlinear source buffer |
| 530 | // component sizes. |
| 531 | // | Source channel min/max sizes | |
| 532 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 533 | // clang-format off |
| 534 | constexpr EffectiveInternalFormatInfo list[] = { |
| 535 | { GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 }, |
| 536 | { GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax }, |
| 537 | { GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 }, |
| 538 | { GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax }, |
| 539 | { GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax }, |
| 540 | { GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 541 | { GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 542 | { GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 }, |
| 543 | }; |
| 544 | // clang-format on |
| 545 | |
| 546 | return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list), |
| 547 | outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 548 | } |
| 549 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 550 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, |
| 551 | const InternalFormat &destFormat, |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 552 | GLenum *outEffectiveFormat) |
| 553 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 554 | if (destFormat.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 555 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 556 | return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 557 | } |
| 558 | else |
| 559 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 560 | return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 561 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 564 | static bool EqualOrFirstZero(GLuint first, GLuint second) |
| 565 | { |
| 566 | return first == 0 || first == second; |
| 567 | } |
| 568 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 569 | static bool IsValidES3CopyTexImageCombination(const InternalFormat &textureFormatInfo, |
| 570 | const InternalFormat &framebufferFormatInfo, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 571 | GLuint readBufferHandle) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 572 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 573 | if (!ValidES3CopyConversion(textureFormatInfo.format, framebufferFormatInfo.format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 574 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 575 | return false; |
| 576 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 577 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 578 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 579 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 580 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 581 | // conversion between fixed and floating point. |
| 582 | |
| 583 | if ((textureFormatInfo.colorEncoding == GL_SRGB) != |
| 584 | (framebufferFormatInfo.colorEncoding == GL_SRGB)) |
| 585 | { |
| 586 | return false; |
| 587 | } |
| 588 | |
| 589 | if (((textureFormatInfo.componentType == GL_INT) != |
| 590 | (framebufferFormatInfo.componentType == GL_INT)) || |
| 591 | ((textureFormatInfo.componentType == GL_UNSIGNED_INT) != |
| 592 | (framebufferFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 593 | { |
| 594 | return false; |
| 595 | } |
| 596 | |
| 597 | if ((textureFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 598 | textureFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 599 | textureFormatInfo.componentType == GL_FLOAT) && |
| 600 | !(framebufferFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 601 | framebufferFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 602 | framebufferFormatInfo.componentType == GL_FLOAT)) |
| 603 | { |
| 604 | return false; |
| 605 | } |
| 606 | |
| 607 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 608 | // The effective internal format of the source buffer is determined with the following rules |
| 609 | // applied in order: |
| 610 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal |
| 611 | // format then the effective internal format is the source buffer's sized internal format. |
| 612 | // * If the source buffer is a texture that was created with an unsized base internal format, |
| 613 | // then the effective internal format is the source image array's effective internal |
| 614 | // format, as specified by table 3.12, which is determined from the <format> and <type> |
| 615 | // that were used when the source image array was specified by TexImage*. |
| 616 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 |
| 617 | // where Destination Internal Format matches internalformat and where the [source channel |
| 618 | // sizes] are consistent with the values of the source buffer's [channel sizes]. Table 3.17 |
| 619 | // is used if the FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the |
| 620 | // FRAMEBUFFER_ATTACHMENT_ENCODING is SRGB. |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 621 | const InternalFormat *sourceEffectiveFormat = nullptr; |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 622 | if (readBufferHandle != 0) |
| 623 | { |
| 624 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or |
| 625 | // renderbuffer |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 626 | if (framebufferFormatInfo.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 627 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 628 | sourceEffectiveFormat = &framebufferFormatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 629 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 630 | else |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 631 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 632 | // Renderbuffers cannot be created with an unsized internal format, so this must be an |
| 633 | // unsized-format texture. We can use the same table we use when creating textures to |
| 634 | // get its effective sized format. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 635 | sourceEffectiveFormat = |
| 636 | &GetSizedInternalFormatInfo(framebufferFormatInfo.sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 637 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 638 | } |
| 639 | else |
| 640 | { |
| 641 | // The effective internal format must be derived from the source framebuffer's channel |
| 642 | // sizes. This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 643 | if (framebufferFormatInfo.colorEncoding == GL_LINEAR) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 644 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 645 | GLenum effectiveFormat; |
| 646 | if (GetEffectiveInternalFormat(framebufferFormatInfo, textureFormatInfo, |
| 647 | &effectiveFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 648 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 649 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(effectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 650 | } |
| 651 | else |
| 652 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 653 | return false; |
| 654 | } |
| 655 | } |
| 656 | else if (framebufferFormatInfo.colorEncoding == GL_SRGB) |
| 657 | { |
| 658 | // 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] | 659 | if (textureFormatInfo.sized && |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 660 | (framebufferFormatInfo.redBits >= 1 && framebufferFormatInfo.redBits <= 8) && |
| 661 | (framebufferFormatInfo.greenBits >= 1 && framebufferFormatInfo.greenBits <= 8) && |
| 662 | (framebufferFormatInfo.blueBits >= 1 && framebufferFormatInfo.blueBits <= 8) && |
| 663 | (framebufferFormatInfo.alphaBits >= 1 && framebufferFormatInfo.alphaBits <= 8)) |
| 664 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 665 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(GL_SRGB8_ALPHA8); |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 666 | } |
| 667 | else |
| 668 | { |
| 669 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | else |
| 673 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 674 | UNREACHABLE(); |
| 675 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 676 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 677 | } |
| 678 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 679 | if (textureFormatInfo.sized) |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 680 | { |
| 681 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is |
| 682 | // sized, component sizes of the source and destination formats must exactly match if the |
| 683 | // destination format exists. |
| 684 | if (!EqualOrFirstZero(textureFormatInfo.redBits, sourceEffectiveFormat->redBits) || |
| 685 | !EqualOrFirstZero(textureFormatInfo.greenBits, sourceEffectiveFormat->greenBits) || |
| 686 | !EqualOrFirstZero(textureFormatInfo.blueBits, sourceEffectiveFormat->blueBits) || |
| 687 | !EqualOrFirstZero(textureFormatInfo.alphaBits, sourceEffectiveFormat->alphaBits)) |
| 688 | { |
| 689 | return false; |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | return true; // A conversion function exists, and no rule in the specification has precluded |
| 694 | // conversion between these formats. |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 695 | } |
| 696 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 697 | bool ValidateES3CopyTexImageParametersBase(ValidationContext *context, |
| 698 | GLenum target, |
| 699 | GLint level, |
| 700 | GLenum internalformat, |
| 701 | bool isSubImage, |
| 702 | GLint xoffset, |
| 703 | GLint yoffset, |
| 704 | GLint zoffset, |
| 705 | GLint x, |
| 706 | GLint y, |
| 707 | GLsizei width, |
| 708 | GLsizei height, |
| 709 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 710 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 711 | Format textureFormat = Format::Invalid(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 712 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 713 | xoffset, yoffset, zoffset, x, y, width, height, border, |
| 714 | &textureFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 715 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 716 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 717 | } |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 718 | ASSERT(textureFormat.valid() || !isSubImage); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 719 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 720 | const auto &state = context->getGLState(); |
| 721 | gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 722 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 723 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 724 | if (framebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 725 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 726 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 727 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 730 | if (readFramebufferID != 0 && framebuffer->getSamples(context) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 731 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 732 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 733 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 736 | const FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 737 | |
| 738 | if (isSubImage) |
| 739 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 740 | if (!IsValidES3CopyTexImageCombination(*textureFormat.info, *source->getFormat().info, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 741 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 742 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 743 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 744 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 745 | } |
| 746 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 747 | else |
| 748 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 749 | // 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] | 750 | const InternalFormat &framebufferFormat = *source->getFormat().info; |
| 751 | const InternalFormat ©Format = GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 752 | if (!IsValidES3CopyTexImageCombination(copyFormat, framebufferFormat, readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 753 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 754 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 755 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 759 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 760 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 763 | bool ValidateES3CopyTexImage2DParameters(ValidationContext *context, |
| 764 | GLenum target, |
| 765 | GLint level, |
| 766 | GLenum internalformat, |
| 767 | bool isSubImage, |
| 768 | GLint xoffset, |
| 769 | GLint yoffset, |
| 770 | GLint zoffset, |
| 771 | GLint x, |
| 772 | GLint y, |
| 773 | GLsizei width, |
| 774 | GLsizei height, |
| 775 | GLint border) |
| 776 | { |
| 777 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 778 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 779 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 780 | return false; |
| 781 | } |
| 782 | |
| 783 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 784 | xoffset, yoffset, zoffset, x, y, width, height, |
| 785 | border); |
| 786 | } |
| 787 | |
| 788 | bool ValidateES3CopyTexImage3DParameters(ValidationContext *context, |
| 789 | GLenum target, |
| 790 | GLint level, |
| 791 | GLenum internalformat, |
| 792 | bool isSubImage, |
| 793 | GLint xoffset, |
| 794 | GLint yoffset, |
| 795 | GLint zoffset, |
| 796 | GLint x, |
| 797 | GLint y, |
| 798 | GLsizei width, |
| 799 | GLsizei height, |
| 800 | GLint border) |
| 801 | { |
| 802 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 803 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 804 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 805 | return false; |
| 806 | } |
| 807 | |
| 808 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 809 | xoffset, yoffset, zoffset, x, y, width, height, |
| 810 | border); |
| 811 | } |
| 812 | |
| 813 | bool ValidateES3TexStorageParametersBase(Context *context, |
| 814 | GLenum target, |
| 815 | GLsizei levels, |
| 816 | GLenum internalformat, |
| 817 | GLsizei width, |
| 818 | GLsizei height, |
| 819 | GLsizei depth) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 820 | { |
| 821 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 822 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 823 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 824 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 827 | GLsizei maxDim = std::max(width, height); |
| 828 | if (target != GL_TEXTURE_2D_ARRAY) |
| 829 | { |
| 830 | maxDim = std::max(maxDim, depth); |
| 831 | } |
| 832 | |
| 833 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 834 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 835 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 836 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 839 | const gl::Caps &caps = context->getCaps(); |
| 840 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 841 | switch (target) |
| 842 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 843 | case GL_TEXTURE_2D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 844 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 845 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 846 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 847 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 848 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 849 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 850 | } |
| 851 | } |
| 852 | break; |
| 853 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 854 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 855 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 856 | if (width != height) |
| 857 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 858 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 859 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 860 | } |
| 861 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 862 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 863 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 864 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 865 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | break; |
| 869 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 870 | case GL_TEXTURE_3D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 871 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 872 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 873 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 874 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 875 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 876 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 877 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 878 | } |
| 879 | } |
| 880 | break; |
| 881 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 882 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 883 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 884 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 885 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 886 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 887 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 888 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 889 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | break; |
| 893 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 894 | default: |
| 895 | UNREACHABLE(); |
| 896 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 897 | } |
| 898 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 899 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 900 | if (!texture || texture->id() == 0) |
| 901 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 902 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 903 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 904 | } |
| 905 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 906 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 907 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 908 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 909 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 910 | } |
| 911 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 912 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 913 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 914 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 915 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 916 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 917 | } |
| 918 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 919 | if (!formatInfo.sized) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 920 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 921 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 922 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 923 | } |
| 924 | |
| 925 | return true; |
| 926 | } |
| 927 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 928 | bool ValidateES3TexStorage2DParameters(Context *context, |
| 929 | GLenum target, |
| 930 | GLsizei levels, |
| 931 | GLenum internalformat, |
| 932 | GLsizei width, |
| 933 | GLsizei height, |
| 934 | GLsizei depth) |
| 935 | { |
| 936 | if (!ValidTexture2DTarget(context, target)) |
| 937 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 938 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 939 | return false; |
| 940 | } |
| 941 | |
| 942 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 943 | height, depth); |
| 944 | } |
| 945 | |
| 946 | bool ValidateES3TexStorage3DParameters(Context *context, |
| 947 | GLenum target, |
| 948 | GLsizei levels, |
| 949 | GLenum internalformat, |
| 950 | GLsizei width, |
| 951 | GLsizei height, |
| 952 | GLsizei depth) |
| 953 | { |
| 954 | if (!ValidTexture3DTarget(context, target)) |
| 955 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 956 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 957 | return false; |
| 958 | } |
| 959 | |
| 960 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 961 | height, depth); |
| 962 | } |
| 963 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 964 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 965 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 966 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 967 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 968 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 969 | return false; |
| 970 | } |
| 971 | |
| 972 | return ValidateBeginQueryBase(context, target, id); |
| 973 | } |
| 974 | |
| 975 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 976 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 977 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 978 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 979 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 980 | return false; |
| 981 | } |
| 982 | |
| 983 | return ValidateEndQueryBase(context, target); |
| 984 | } |
| 985 | |
| 986 | bool ValidateGetQueryiv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 987 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 988 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 989 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 990 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 991 | return false; |
| 992 | } |
| 993 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 994 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 998 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 999 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1000 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1001 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1002 | return false; |
| 1003 | } |
| 1004 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1005 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1008 | bool ValidateFramebufferTextureLayer(Context *context, |
| 1009 | GLenum target, |
| 1010 | GLenum attachment, |
| 1011 | GLuint texture, |
| 1012 | GLint level, |
| 1013 | GLint layer) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1014 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1015 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1016 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1017 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1018 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1019 | } |
| 1020 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1021 | if (layer < 0) |
| 1022 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1023 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1024 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 1028 | { |
| 1029 | return false; |
| 1030 | } |
| 1031 | |
| 1032 | const gl::Caps &caps = context->getCaps(); |
| 1033 | if (texture != 0) |
| 1034 | { |
| 1035 | gl::Texture *tex = context->getTexture(texture); |
| 1036 | ASSERT(tex); |
| 1037 | |
| 1038 | switch (tex->getTarget()) |
| 1039 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1040 | case GL_TEXTURE_2D_ARRAY: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1041 | { |
| 1042 | if (level > gl::log2(caps.max2DTextureSize)) |
| 1043 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1044 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1045 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 1049 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1050 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1051 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1052 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1053 | } |
| 1054 | break; |
| 1055 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1056 | case GL_TEXTURE_3D: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1057 | { |
| 1058 | if (level > gl::log2(caps.max3DTextureSize)) |
| 1059 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1060 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1061 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1065 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1066 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1067 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1068 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1069 | } |
| 1070 | break; |
| 1071 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1072 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1073 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1074 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1075 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1076 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1077 | const auto &format = tex->getFormat(tex->getTarget(), level); |
| 1078 | if (format.info->compressed) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1079 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1080 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1081 | return false; |
| 1082 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1083 | } |
| 1084 | |
| 1085 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1086 | } |
| 1087 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1088 | bool ValidateInvalidateFramebuffer(Context *context, |
| 1089 | GLenum target, |
| 1090 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1091 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1092 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1093 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1094 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1095 | context->handleError(InvalidOperation() << "Operation only supported on ES 3.0 and above"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1096 | return false; |
| 1097 | } |
| 1098 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1099 | bool defaultFramebuffer = false; |
| 1100 | |
| 1101 | switch (target) |
| 1102 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1103 | case GL_DRAW_FRAMEBUFFER: |
| 1104 | case GL_FRAMEBUFFER: |
| 1105 | defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0; |
| 1106 | break; |
| 1107 | case GL_READ_FRAMEBUFFER: |
| 1108 | defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0; |
| 1109 | break; |
| 1110 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1111 | context->handleError(InvalidEnum() << "Invalid framebuffer target"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1112 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1113 | } |
| 1114 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1115 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1116 | defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1117 | } |
| 1118 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1119 | bool ValidateClearBuffer(ValidationContext *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1120 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1121 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1122 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1123 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1124 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1127 | if (context->getGLState().getDrawFramebuffer()->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1128 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1129 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1130 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | return true; |
| 1134 | } |
| 1135 | |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1136 | bool ValidateDrawRangeElements(Context *context, |
| 1137 | GLenum mode, |
| 1138 | GLuint start, |
| 1139 | GLuint end, |
| 1140 | GLsizei count, |
| 1141 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1142 | const void *indices) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1143 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1144 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1145 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1146 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1147 | return false; |
| 1148 | } |
| 1149 | |
| 1150 | if (end < start) |
| 1151 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1152 | context->handleError(InvalidValue() << "end < start"); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1153 | return false; |
| 1154 | } |
| 1155 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1156 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0)) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1157 | { |
| 1158 | return false; |
| 1159 | } |
| 1160 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1161 | // Use the parameter buffer to retrieve and cache the index range. |
| 1162 | const auto ¶ms = context->getParams<HasIndexRange>(); |
| 1163 | const auto &indexRangeOpt = params.getIndexRange(); |
| 1164 | if (!indexRangeOpt.valid()) |
| 1165 | { |
| 1166 | // Unexpected error. |
| 1167 | return false; |
| 1168 | } |
| 1169 | |
| 1170 | if (indexRangeOpt.value().end > end || indexRangeOpt.value().start < start) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1171 | { |
| 1172 | // GL spec says that behavior in this case is undefined - generating an error is fine. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1173 | context->handleError(InvalidOperation() << "Indices are out of the start, end range."); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1174 | return false; |
| 1175 | } |
| 1176 | return true; |
| 1177 | } |
| 1178 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1179 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1180 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1181 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1182 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1183 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1184 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1185 | } |
| 1186 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1187 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1188 | } |
| 1189 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1190 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1191 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1192 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1193 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1194 | context->handleError(InvalidOperation()); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1195 | return false; |
| 1196 | } |
| 1197 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1198 | const Framebuffer *readFBO = context->getGLState().getReadFramebuffer(); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1199 | |
| 1200 | if (readFBO == nullptr) |
| 1201 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1202 | context->handleError(InvalidOperation() << "No active read framebuffer."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1203 | return false; |
| 1204 | } |
| 1205 | |
| 1206 | if (src == GL_NONE) |
| 1207 | { |
| 1208 | return true; |
| 1209 | } |
| 1210 | |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1211 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1212 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1213 | context->handleError(InvalidEnum() << "Unknown enum for 'src' in ReadBuffer"); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1214 | return false; |
| 1215 | } |
| 1216 | |
| 1217 | if (readFBO->id() == 0) |
| 1218 | { |
| 1219 | if (src != GL_BACK) |
| 1220 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1221 | context->handleError( |
| 1222 | InvalidOperation() |
| 1223 | << "'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] | 1224 | return false; |
| 1225 | } |
| 1226 | } |
| 1227 | else |
| 1228 | { |
| 1229 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1230 | |
| 1231 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1232 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1233 | context->handleError(InvalidOperation() << "'src' is greater than MAX_DRAW_BUFFERS."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1234 | return false; |
| 1235 | } |
| 1236 | } |
| 1237 | |
| 1238 | return true; |
| 1239 | } |
| 1240 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1241 | bool ValidateCompressedTexImage3D(Context *context, |
| 1242 | GLenum target, |
| 1243 | GLint level, |
| 1244 | GLenum internalformat, |
| 1245 | GLsizei width, |
| 1246 | GLsizei height, |
| 1247 | GLsizei depth, |
| 1248 | GLint border, |
| 1249 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1250 | const void *data) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1251 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1252 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1253 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1254 | context->handleError(InvalidOperation()); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1255 | return false; |
| 1256 | } |
| 1257 | |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1258 | if (!ValidTextureTarget(context, target)) |
| 1259 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1260 | context->handleError(InvalidEnum()); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1261 | return false; |
| 1262 | } |
| 1263 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1264 | // Validate image size |
| 1265 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, false)) |
| 1266 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1267 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1268 | return false; |
| 1269 | } |
| 1270 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1271 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1272 | if (!formatInfo.compressed) |
| 1273 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1274 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1275 | return false; |
| 1276 | } |
| 1277 | |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1278 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1279 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1280 | if (blockSizeOrErr.isError()) |
| 1281 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1282 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1283 | return false; |
| 1284 | } |
| 1285 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1286 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1287 | context->handleError(InvalidValue()); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1288 | return false; |
| 1289 | } |
| 1290 | |
| 1291 | // 3D texture target validation |
| 1292 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1293 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1294 | context->handleError(InvalidEnum() << "Must specify a valid 3D texture destination target"); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1295 | return false; |
| 1296 | } |
| 1297 | |
| 1298 | // validateES3TexImageFormat sets the error code if there is an error |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1299 | if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1300 | 0, width, height, depth, border, GL_NONE, GL_NONE, -1, |
| 1301 | data)) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1302 | { |
| 1303 | return false; |
| 1304 | } |
| 1305 | |
| 1306 | return true; |
| 1307 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1308 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1309 | bool ValidateCompressedTexImage3DRobustANGLE(Context *context, |
| 1310 | GLenum target, |
| 1311 | GLint level, |
| 1312 | GLenum internalformat, |
| 1313 | GLsizei width, |
| 1314 | GLsizei height, |
| 1315 | GLsizei depth, |
| 1316 | GLint border, |
| 1317 | GLsizei imageSize, |
| 1318 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1319 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1320 | { |
| 1321 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 1322 | { |
| 1323 | return false; |
| 1324 | } |
| 1325 | |
| 1326 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 1327 | depth, border, imageSize, data); |
| 1328 | } |
| 1329 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1330 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1331 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1332 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1333 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1334 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1335 | return false; |
| 1336 | } |
| 1337 | |
| 1338 | return ValidateBindVertexArrayBase(context, array); |
| 1339 | } |
| 1340 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1341 | bool ValidateIsVertexArray(Context *context) |
| 1342 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1343 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1344 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1345 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1346 | return false; |
| 1347 | } |
| 1348 | |
| 1349 | return true; |
| 1350 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1351 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1352 | static bool ValidateBindBufferCommon(Context *context, |
| 1353 | GLenum target, |
| 1354 | GLuint index, |
| 1355 | GLuint buffer, |
| 1356 | GLintptr offset, |
| 1357 | GLsizeiptr size) |
| 1358 | { |
| 1359 | if (context->getClientMajorVersion() < 3) |
| 1360 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1361 | context->handleError(InvalidOperation()); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1362 | return false; |
| 1363 | } |
| 1364 | |
| 1365 | if (buffer != 0 && offset < 0) |
| 1366 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1367 | context->handleError(InvalidValue() << "buffer is non-zero and offset is negative."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1368 | return false; |
| 1369 | } |
| 1370 | |
| 1371 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 1372 | !context->isBufferGenerated(buffer)) |
| 1373 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1374 | context->handleError(InvalidOperation() << "Buffer was not generated."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1375 | return false; |
| 1376 | } |
| 1377 | |
| 1378 | const Caps &caps = context->getCaps(); |
| 1379 | switch (target) |
| 1380 | { |
| 1381 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 1382 | { |
| 1383 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 1384 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1385 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1386 | "number of TRANSFORM_FEEDBACK_BUFFER " |
| 1387 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1388 | return false; |
| 1389 | } |
| 1390 | if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0)) |
| 1391 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1392 | context->handleError(InvalidValue() << "offset and size must be multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1393 | return false; |
| 1394 | } |
| 1395 | |
| 1396 | TransformFeedback *curTransformFeedback = |
| 1397 | context->getGLState().getCurrentTransformFeedback(); |
| 1398 | if (curTransformFeedback && curTransformFeedback->isActive()) |
| 1399 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1400 | context->handleError(InvalidOperation() |
| 1401 | << "target is TRANSFORM_FEEDBACK_BUFFER and transform " |
| 1402 | "feedback is currently active."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1403 | return false; |
| 1404 | } |
| 1405 | break; |
| 1406 | } |
| 1407 | case GL_UNIFORM_BUFFER: |
| 1408 | { |
| 1409 | if (index >= caps.maxUniformBufferBindings) |
| 1410 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1411 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1412 | "number of UNIFORM_BUFFER indexed " |
| 1413 | "binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1414 | return false; |
| 1415 | } |
| 1416 | |
| 1417 | if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0) |
| 1418 | { |
| 1419 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1420 | InvalidValue() |
| 1421 | << "offset must be multiple of value of UNIFORM_BUFFER_OFFSET_ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1422 | return false; |
| 1423 | } |
| 1424 | break; |
| 1425 | } |
| 1426 | case GL_ATOMIC_COUNTER_BUFFER: |
| 1427 | { |
| 1428 | if (context->getClientVersion() < ES_3_1) |
| 1429 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1430 | context->handleError(InvalidEnum() |
| 1431 | << "ATOMIC_COUNTER_BUFFER is not supported before GLES 3.1"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1432 | return false; |
| 1433 | } |
| 1434 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 1435 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1436 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1437 | "number of ATOMIC_COUNTER_BUFFER " |
| 1438 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1439 | return false; |
| 1440 | } |
| 1441 | if (buffer != 0 && (offset % 4) != 0) |
| 1442 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1443 | context->handleError(InvalidValue() << "offset must be a multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1444 | return false; |
| 1445 | } |
| 1446 | break; |
| 1447 | } |
| 1448 | case GL_SHADER_STORAGE_BUFFER: |
| 1449 | { |
| 1450 | if (context->getClientVersion() < ES_3_1) |
| 1451 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1452 | context->handleError(InvalidEnum() |
| 1453 | << "SHADER_STORAGE_BUFFER is not supported in GLES3."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1454 | return false; |
| 1455 | } |
| 1456 | if (index >= caps.maxShaderStorageBufferBindings) |
| 1457 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1458 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1459 | "number of SHADER_STORAGE_BUFFER " |
| 1460 | "indexed binding points."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1461 | return false; |
| 1462 | } |
| 1463 | if (buffer != 0 && (offset % caps.shaderStorageBufferOffsetAlignment) != 0) |
| 1464 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1465 | context->handleError(InvalidValue() << "offset must be multiple of value of " |
| 1466 | "SHADER_STORAGE_BUFFER_OFFSET_" |
| 1467 | "ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1468 | return false; |
| 1469 | } |
| 1470 | break; |
| 1471 | } |
| 1472 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1473 | context->handleError(InvalidEnum() << "the target is not supported."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1474 | return false; |
| 1475 | } |
| 1476 | |
| 1477 | return true; |
| 1478 | } |
| 1479 | |
| 1480 | bool ValidateBindBufferBase(Context *context, GLenum target, GLuint index, GLuint buffer) |
| 1481 | { |
| 1482 | return ValidateBindBufferCommon(context, target, index, buffer, 0, 0); |
| 1483 | } |
| 1484 | |
| 1485 | bool ValidateBindBufferRange(Context *context, |
| 1486 | GLenum target, |
| 1487 | GLuint index, |
| 1488 | GLuint buffer, |
| 1489 | GLintptr offset, |
| 1490 | GLsizeiptr size) |
| 1491 | { |
| 1492 | if (buffer != 0 && size <= 0) |
| 1493 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1494 | context->handleError(InvalidValue() |
| 1495 | << "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] | 1496 | return false; |
| 1497 | } |
| 1498 | return ValidateBindBufferCommon(context, target, index, buffer, offset, size); |
| 1499 | } |
| 1500 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1501 | bool ValidateProgramBinary(Context *context, |
| 1502 | GLuint program, |
| 1503 | GLenum binaryFormat, |
| 1504 | const void *binary, |
| 1505 | GLint length) |
| 1506 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1507 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1508 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1509 | context->handleError(InvalidOperation()); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | |
| 1513 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1514 | } |
| 1515 | |
| 1516 | bool ValidateGetProgramBinary(Context *context, |
| 1517 | GLuint program, |
| 1518 | GLsizei bufSize, |
| 1519 | GLsizei *length, |
| 1520 | GLenum *binaryFormat, |
| 1521 | void *binary) |
| 1522 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1523 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1524 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1525 | context->handleError(InvalidOperation()); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1526 | return false; |
| 1527 | } |
| 1528 | |
| 1529 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1530 | } |
| 1531 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1532 | bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1533 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1534 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1535 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1536 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1537 | return false; |
| 1538 | } |
| 1539 | |
| 1540 | if (GetValidProgram(context, program) == nullptr) |
| 1541 | { |
| 1542 | return false; |
| 1543 | } |
| 1544 | |
| 1545 | switch (pname) |
| 1546 | { |
| 1547 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1548 | if (value != GL_FALSE && value != GL_TRUE) |
| 1549 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1550 | context->handleError(InvalidValue() |
| 1551 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1552 | return false; |
| 1553 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1554 | break; |
| 1555 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1556 | case GL_PROGRAM_SEPARABLE: |
| 1557 | if (context->getClientVersion() < ES_3_1) |
| 1558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1559 | context->handleError(InvalidEnum() |
| 1560 | << "PROGRAM_SEPARABLE is not supported before GLES 3.1"); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1561 | return false; |
| 1562 | } |
| 1563 | |
| 1564 | if (value != GL_FALSE && value != GL_TRUE) |
| 1565 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1566 | context->handleError(InvalidValue() |
| 1567 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1568 | return false; |
| 1569 | } |
| 1570 | break; |
| 1571 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1572 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1573 | context->handleError(InvalidEnum() |
| 1574 | << "Invalid pname: 0x" << std::hex << std::uppercase << pname); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1575 | return false; |
| 1576 | } |
| 1577 | |
| 1578 | return true; |
| 1579 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1580 | |
| 1581 | bool ValidateBlitFramebuffer(Context *context, |
| 1582 | GLint srcX0, |
| 1583 | GLint srcY0, |
| 1584 | GLint srcX1, |
| 1585 | GLint srcY1, |
| 1586 | GLint dstX0, |
| 1587 | GLint dstY0, |
| 1588 | GLint dstX1, |
| 1589 | GLint dstY1, |
| 1590 | GLbitfield mask, |
| 1591 | GLenum filter) |
| 1592 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1593 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1594 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1595 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1596 | return false; |
| 1597 | } |
| 1598 | |
| 1599 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1600 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1601 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1602 | |
| 1603 | bool ValidateClearBufferiv(ValidationContext *context, |
| 1604 | GLenum buffer, |
| 1605 | GLint drawbuffer, |
| 1606 | const GLint *value) |
| 1607 | { |
| 1608 | switch (buffer) |
| 1609 | { |
| 1610 | case GL_COLOR: |
| 1611 | if (drawbuffer < 0 || |
| 1612 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1613 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1614 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1615 | return false; |
| 1616 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1617 | if (context->getExtensions().webglCompatibility) |
| 1618 | { |
| 1619 | constexpr GLenum validComponentTypes[] = {GL_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1620 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1621 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1622 | { |
| 1623 | return false; |
| 1624 | } |
| 1625 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1626 | break; |
| 1627 | |
| 1628 | case GL_STENCIL: |
| 1629 | if (drawbuffer != 0) |
| 1630 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1631 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1632 | return false; |
| 1633 | } |
| 1634 | break; |
| 1635 | |
| 1636 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1637 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1638 | return false; |
| 1639 | } |
| 1640 | |
| 1641 | return ValidateClearBuffer(context); |
| 1642 | } |
| 1643 | |
| 1644 | bool ValidateClearBufferuiv(ValidationContext *context, |
| 1645 | GLenum buffer, |
| 1646 | GLint drawbuffer, |
| 1647 | const GLuint *value) |
| 1648 | { |
| 1649 | switch (buffer) |
| 1650 | { |
| 1651 | case GL_COLOR: |
| 1652 | if (drawbuffer < 0 || |
| 1653 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1654 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1655 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1656 | return false; |
| 1657 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1658 | if (context->getExtensions().webglCompatibility) |
| 1659 | { |
| 1660 | constexpr GLenum validComponentTypes[] = {GL_UNSIGNED_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1661 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1662 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1663 | { |
| 1664 | return false; |
| 1665 | } |
| 1666 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1667 | break; |
| 1668 | |
| 1669 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1670 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1671 | return false; |
| 1672 | } |
| 1673 | |
| 1674 | return ValidateClearBuffer(context); |
| 1675 | } |
| 1676 | |
| 1677 | bool ValidateClearBufferfv(ValidationContext *context, |
| 1678 | GLenum buffer, |
| 1679 | GLint drawbuffer, |
| 1680 | const GLfloat *value) |
| 1681 | { |
| 1682 | switch (buffer) |
| 1683 | { |
| 1684 | case GL_COLOR: |
| 1685 | if (drawbuffer < 0 || |
| 1686 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1687 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1688 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1689 | return false; |
| 1690 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1691 | if (context->getExtensions().webglCompatibility) |
| 1692 | { |
| 1693 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 1694 | GL_SIGNED_NORMALIZED}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1695 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1696 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1697 | { |
| 1698 | return false; |
| 1699 | } |
| 1700 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1701 | break; |
| 1702 | |
| 1703 | case GL_DEPTH: |
| 1704 | if (drawbuffer != 0) |
| 1705 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1706 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1707 | return false; |
| 1708 | } |
| 1709 | break; |
| 1710 | |
| 1711 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1712 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1713 | return false; |
| 1714 | } |
| 1715 | |
| 1716 | return ValidateClearBuffer(context); |
| 1717 | } |
| 1718 | |
| 1719 | bool ValidateClearBufferfi(ValidationContext *context, |
| 1720 | GLenum buffer, |
| 1721 | GLint drawbuffer, |
| 1722 | GLfloat depth, |
| 1723 | GLint stencil) |
| 1724 | { |
| 1725 | switch (buffer) |
| 1726 | { |
| 1727 | case GL_DEPTH_STENCIL: |
| 1728 | if (drawbuffer != 0) |
| 1729 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1730 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1731 | return false; |
| 1732 | } |
| 1733 | break; |
| 1734 | |
| 1735 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1736 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1737 | return false; |
| 1738 | } |
| 1739 | |
| 1740 | return ValidateClearBuffer(context); |
| 1741 | } |
| 1742 | |
| 1743 | bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1744 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1745 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1746 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1747 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1748 | return false; |
| 1749 | } |
| 1750 | |
| 1751 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1752 | } |
| 1753 | |
| 1754 | bool ValidateCopyTexSubImage3D(Context *context, |
| 1755 | GLenum target, |
| 1756 | GLint level, |
| 1757 | GLint xoffset, |
| 1758 | GLint yoffset, |
| 1759 | GLint zoffset, |
| 1760 | GLint x, |
| 1761 | GLint y, |
| 1762 | GLsizei width, |
| 1763 | GLsizei height) |
| 1764 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1765 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1766 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1767 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1768 | return false; |
| 1769 | } |
| 1770 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1771 | return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset, |
| 1772 | yoffset, zoffset, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1773 | } |
| 1774 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1775 | bool ValidateTexImage3D(Context *context, |
| 1776 | GLenum target, |
| 1777 | GLint level, |
| 1778 | GLint internalformat, |
| 1779 | GLsizei width, |
| 1780 | GLsizei height, |
| 1781 | GLsizei depth, |
| 1782 | GLint border, |
| 1783 | GLenum format, |
| 1784 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1785 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1786 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1787 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1788 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1789 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1790 | return false; |
| 1791 | } |
| 1792 | |
| 1793 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1794 | 0, 0, width, height, depth, border, format, type, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1795 | pixels); |
| 1796 | } |
| 1797 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1798 | bool ValidateTexImage3DRobustANGLE(Context *context, |
| 1799 | GLenum target, |
| 1800 | GLint level, |
| 1801 | GLint internalformat, |
| 1802 | GLsizei width, |
| 1803 | GLsizei height, |
| 1804 | GLsizei depth, |
| 1805 | GLint border, |
| 1806 | GLenum format, |
| 1807 | GLenum type, |
| 1808 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1809 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1810 | { |
| 1811 | if (context->getClientMajorVersion() < 3) |
| 1812 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1813 | context->handleError(InvalidOperation()); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1814 | return false; |
| 1815 | } |
| 1816 | |
| 1817 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1818 | { |
| 1819 | return false; |
| 1820 | } |
| 1821 | |
| 1822 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
| 1823 | 0, 0, width, height, depth, border, format, type, |
| 1824 | bufSize, pixels); |
| 1825 | } |
| 1826 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1827 | bool ValidateTexSubImage3D(Context *context, |
| 1828 | GLenum target, |
| 1829 | GLint level, |
| 1830 | GLint xoffset, |
| 1831 | GLint yoffset, |
| 1832 | GLint zoffset, |
| 1833 | GLsizei width, |
| 1834 | GLsizei height, |
| 1835 | GLsizei depth, |
| 1836 | GLenum format, |
| 1837 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1838 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1839 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1840 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1841 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1842 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1847 | yoffset, zoffset, width, height, depth, 0, format, type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1848 | -1, pixels); |
| 1849 | } |
| 1850 | |
| 1851 | bool ValidateTexSubImage3DRobustANGLE(Context *context, |
| 1852 | GLenum target, |
| 1853 | GLint level, |
| 1854 | GLint xoffset, |
| 1855 | GLint yoffset, |
| 1856 | GLint zoffset, |
| 1857 | GLsizei width, |
| 1858 | GLsizei height, |
| 1859 | GLsizei depth, |
| 1860 | GLenum format, |
| 1861 | GLenum type, |
| 1862 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1863 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1864 | { |
| 1865 | if (context->getClientMajorVersion() < 3) |
| 1866 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1867 | context->handleError(InvalidOperation()); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1868 | return false; |
| 1869 | } |
| 1870 | |
| 1871 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1872 | { |
| 1873 | return false; |
| 1874 | } |
| 1875 | |
| 1876 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1877 | yoffset, zoffset, width, height, depth, 0, format, type, |
| 1878 | bufSize, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1879 | } |
| 1880 | |
| 1881 | bool ValidateCompressedTexSubImage3D(Context *context, |
| 1882 | GLenum target, |
| 1883 | GLint level, |
| 1884 | GLint xoffset, |
| 1885 | GLint yoffset, |
| 1886 | GLint zoffset, |
| 1887 | GLsizei width, |
| 1888 | GLsizei height, |
| 1889 | GLsizei depth, |
| 1890 | GLenum format, |
| 1891 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1892 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1893 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1894 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1895 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1896 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
| 1899 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1900 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 1901 | if (!formatInfo.compressed) |
| 1902 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1903 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 1904 | return false; |
| 1905 | } |
| 1906 | |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1907 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1908 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1909 | if (blockSizeOrErr.isError()) |
| 1910 | { |
| 1911 | context->handleError(blockSizeOrErr.getError()); |
| 1912 | return false; |
| 1913 | } |
| 1914 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1915 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1916 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1917 | return false; |
| 1918 | } |
| 1919 | |
| 1920 | if (!data) |
| 1921 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1922 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1923 | return false; |
| 1924 | } |
| 1925 | |
| 1926 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, 0, 0, 0, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1927 | width, height, depth, 0, format, GL_NONE, -1, data); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1928 | } |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1929 | bool ValidateCompressedTexSubImage3DRobustANGLE(Context *context, |
| 1930 | GLenum target, |
| 1931 | GLint level, |
| 1932 | GLint xoffset, |
| 1933 | GLint yoffset, |
| 1934 | GLint zoffset, |
| 1935 | GLsizei width, |
| 1936 | GLsizei height, |
| 1937 | GLsizei depth, |
| 1938 | GLenum format, |
| 1939 | GLsizei imageSize, |
| 1940 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1941 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1942 | { |
| 1943 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 1944 | { |
| 1945 | return false; |
| 1946 | } |
| 1947 | |
| 1948 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 1949 | height, depth, format, imageSize, data); |
| 1950 | } |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1951 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1952 | bool ValidateGenQueries(Context *context, GLint n, GLuint *) |
| 1953 | { |
| 1954 | return ValidateGenOrDeleteES3(context, n); |
| 1955 | } |
| 1956 | |
| 1957 | bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *) |
| 1958 | { |
| 1959 | return ValidateGenOrDeleteES3(context, n); |
| 1960 | } |
| 1961 | |
| 1962 | bool ValidateGenSamplers(Context *context, GLint count, GLuint *) |
| 1963 | { |
| 1964 | return ValidateGenOrDeleteCountES3(context, count); |
| 1965 | } |
| 1966 | |
| 1967 | bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *) |
| 1968 | { |
| 1969 | return ValidateGenOrDeleteCountES3(context, count); |
| 1970 | } |
| 1971 | |
| 1972 | bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *) |
| 1973 | { |
| 1974 | return ValidateGenOrDeleteES3(context, n); |
| 1975 | } |
| 1976 | |
| 1977 | bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids) |
| 1978 | { |
| 1979 | if (!ValidateGenOrDeleteES3(context, n)) |
| 1980 | { |
| 1981 | return false; |
| 1982 | } |
| 1983 | for (GLint i = 0; i < n; ++i) |
| 1984 | { |
| 1985 | auto *transformFeedback = context->getTransformFeedback(ids[i]); |
| 1986 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 1987 | { |
| 1988 | // ES 3.0.4 section 2.15.1 page 86 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1989 | context->handleError(InvalidOperation() |
| 1990 | << "Attempt to delete active transform feedback."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1991 | return false; |
| 1992 | } |
| 1993 | } |
| 1994 | return true; |
| 1995 | } |
| 1996 | |
| 1997 | bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *) |
| 1998 | { |
| 1999 | return ValidateGenOrDeleteES3(context, n); |
| 2000 | } |
| 2001 | |
| 2002 | bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *) |
| 2003 | { |
| 2004 | return ValidateGenOrDeleteES3(context, n); |
| 2005 | } |
| 2006 | |
| 2007 | bool ValidateGenOrDeleteES3(Context *context, GLint n) |
| 2008 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2009 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2010 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2011 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2012 | return false; |
| 2013 | } |
| 2014 | return ValidateGenOrDelete(context, n); |
| 2015 | } |
| 2016 | |
| 2017 | bool ValidateGenOrDeleteCountES3(Context *context, GLint count) |
| 2018 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2019 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2020 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2021 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2022 | return false; |
| 2023 | } |
| 2024 | if (count < 0) |
| 2025 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2026 | context->handleError(InvalidValue() << "count < 0"); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2027 | return false; |
| 2028 | } |
| 2029 | return true; |
| 2030 | } |
| 2031 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2032 | bool ValidateBeginTransformFeedback(Context *context, GLenum primitiveMode) |
| 2033 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2034 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2035 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2036 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2037 | return false; |
| 2038 | } |
| 2039 | switch (primitiveMode) |
| 2040 | { |
| 2041 | case GL_TRIANGLES: |
| 2042 | case GL_LINES: |
| 2043 | case GL_POINTS: |
| 2044 | break; |
| 2045 | |
| 2046 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2047 | context->handleError(InvalidEnum() << "Invalid primitive mode."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2048 | return false; |
| 2049 | } |
| 2050 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2051 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2052 | ASSERT(transformFeedback != nullptr); |
| 2053 | |
| 2054 | if (transformFeedback->isActive()) |
| 2055 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2056 | context->handleError(InvalidOperation() << "Transform feedback is already active."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
| 2059 | return true; |
| 2060 | } |
| 2061 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2062 | bool ValidateGetBufferPointerv(Context *context, GLenum target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2063 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2064 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
| 2065 | } |
| 2066 | |
| 2067 | bool ValidateGetBufferPointervRobustANGLE(Context *context, |
| 2068 | GLenum target, |
| 2069 | GLenum pname, |
| 2070 | GLsizei bufSize, |
| 2071 | GLsizei *length, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2072 | void **params) |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2073 | { |
| 2074 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2075 | { |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2076 | return false; |
| 2077 | } |
| 2078 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2079 | if (!ValidateGetBufferPointervBase(context, target, pname, length, params)) |
| 2080 | { |
| 2081 | return false; |
| 2082 | } |
| 2083 | |
| 2084 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2085 | { |
| 2086 | return false; |
| 2087 | } |
| 2088 | |
| 2089 | return true; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2090 | } |
| 2091 | |
| 2092 | bool ValidateUnmapBuffer(Context *context, GLenum target) |
| 2093 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2094 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2095 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2096 | context->handleError(InvalidOperation()); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2097 | return false; |
| 2098 | } |
| 2099 | |
| 2100 | return ValidateUnmapBufferBase(context, target); |
| 2101 | } |
| 2102 | |
| 2103 | bool ValidateMapBufferRange(Context *context, |
| 2104 | GLenum target, |
| 2105 | GLintptr offset, |
| 2106 | GLsizeiptr length, |
| 2107 | GLbitfield access) |
| 2108 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2109 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2110 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2111 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2112 | return false; |
| 2113 | } |
| 2114 | |
| 2115 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2116 | } |
| 2117 | |
| 2118 | bool ValidateFlushMappedBufferRange(Context *context, |
| 2119 | GLenum target, |
| 2120 | GLintptr offset, |
| 2121 | GLsizeiptr length) |
| 2122 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2123 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2124 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2125 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2126 | return false; |
| 2127 | } |
| 2128 | |
| 2129 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2130 | } |
| 2131 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2132 | bool ValidateIndexedStateQuery(ValidationContext *context, |
| 2133 | GLenum pname, |
| 2134 | GLuint index, |
| 2135 | GLsizei *length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2136 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2137 | if (length) |
| 2138 | { |
| 2139 | *length = 0; |
| 2140 | } |
| 2141 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2142 | GLenum nativeType; |
| 2143 | unsigned int numParams; |
| 2144 | if (!context->getIndexedQueryParameterInfo(pname, &nativeType, &numParams)) |
| 2145 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2146 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2147 | return false; |
| 2148 | } |
| 2149 | |
| 2150 | const Caps &caps = context->getCaps(); |
| 2151 | switch (pname) |
| 2152 | { |
| 2153 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 2154 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
| 2155 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 2156 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 2157 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2158 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2159 | return false; |
| 2160 | } |
| 2161 | break; |
| 2162 | |
| 2163 | case GL_UNIFORM_BUFFER_START: |
| 2164 | case GL_UNIFORM_BUFFER_SIZE: |
| 2165 | case GL_UNIFORM_BUFFER_BINDING: |
| 2166 | if (index >= caps.maxUniformBufferBindings) |
| 2167 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2168 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2169 | return false; |
| 2170 | } |
| 2171 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2172 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2173 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 2174 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 2175 | if (index >= 3u) |
| 2176 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2177 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2178 | return false; |
| 2179 | } |
| 2180 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2181 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2182 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2183 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2184 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2185 | if (context->getClientVersion() < ES_3_1) |
| 2186 | { |
| 2187 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2188 | InvalidEnum() |
| 2189 | << "Atomic Counter buffers are not supported in this version of GL"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2190 | return false; |
| 2191 | } |
| 2192 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 2193 | { |
| 2194 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2195 | InvalidValue() |
| 2196 | << "index is outside the valid range for GL_ATOMIC_COUNTER_BUFFER_BINDING"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2197 | return false; |
| 2198 | } |
| 2199 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2200 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2201 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2202 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2203 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2204 | if (context->getClientVersion() < ES_3_1) |
| 2205 | { |
| 2206 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2207 | InvalidEnum() |
| 2208 | << "Shader storage buffers are not supported in this version of GL"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2209 | return false; |
| 2210 | } |
| 2211 | if (index >= caps.maxShaderStorageBufferBindings) |
| 2212 | { |
| 2213 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2214 | InvalidValue() |
| 2215 | << "index is outside the valid range for GL_SHADER_STORAGE_BUFFER_BINDING"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2216 | return false; |
| 2217 | } |
| 2218 | break; |
| 2219 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2220 | case GL_VERTEX_BINDING_BUFFER: |
| 2221 | case GL_VERTEX_BINDING_DIVISOR: |
| 2222 | case GL_VERTEX_BINDING_OFFSET: |
| 2223 | case GL_VERTEX_BINDING_STRIDE: |
| 2224 | if (context->getClientVersion() < ES_3_1) |
| 2225 | { |
| 2226 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2227 | InvalidEnum() |
| 2228 | << "Vertex Attrib Bindings are not supported in this version of GL"); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2229 | return false; |
| 2230 | } |
| 2231 | if (index >= caps.maxVertexAttribBindings) |
| 2232 | { |
| 2233 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2234 | InvalidValue() |
| 2235 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2236 | return false; |
| 2237 | } |
| 2238 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2239 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2240 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2241 | return false; |
| 2242 | } |
| 2243 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2244 | if (length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2245 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2246 | *length = 1; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2247 | } |
| 2248 | |
| 2249 | return true; |
| 2250 | } |
| 2251 | |
| 2252 | bool ValidateGetIntegeri_v(ValidationContext *context, GLenum target, GLuint index, GLint *data) |
| 2253 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2254 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2255 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2256 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2257 | return false; |
| 2258 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2259 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2260 | } |
| 2261 | |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2262 | bool ValidateGetIntegeri_vRobustANGLE(ValidationContext *context, |
| 2263 | GLenum target, |
| 2264 | GLuint index, |
| 2265 | GLsizei bufSize, |
| 2266 | GLsizei *length, |
| 2267 | GLint *data) |
| 2268 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2269 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2270 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2271 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2272 | return false; |
| 2273 | } |
| 2274 | |
| 2275 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2276 | { |
| 2277 | return false; |
| 2278 | } |
| 2279 | |
| 2280 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 2281 | { |
| 2282 | return false; |
| 2283 | } |
| 2284 | |
| 2285 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2286 | { |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | return true; |
| 2291 | } |
| 2292 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2293 | bool ValidateGetInteger64i_v(ValidationContext *context, GLenum target, GLuint index, GLint64 *data) |
| 2294 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2295 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2296 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2297 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2298 | return false; |
| 2299 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2300 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
| 2301 | } |
| 2302 | |
| 2303 | bool ValidateGetInteger64i_vRobustANGLE(ValidationContext *context, |
| 2304 | GLenum target, |
| 2305 | GLuint index, |
| 2306 | GLsizei bufSize, |
| 2307 | GLsizei *length, |
| 2308 | GLint64 *data) |
| 2309 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2310 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2311 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2312 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2313 | return false; |
| 2314 | } |
| 2315 | |
| 2316 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2317 | { |
| 2318 | return false; |
| 2319 | } |
| 2320 | |
| 2321 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 2322 | { |
| 2323 | return false; |
| 2324 | } |
| 2325 | |
| 2326 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2327 | { |
| 2328 | return false; |
| 2329 | } |
| 2330 | |
| 2331 | return true; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2332 | } |
| 2333 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2334 | bool ValidateCopyBufferSubData(ValidationContext *context, |
| 2335 | GLenum readTarget, |
| 2336 | GLenum writeTarget, |
| 2337 | GLintptr readOffset, |
| 2338 | GLintptr writeOffset, |
| 2339 | GLsizeiptr size) |
| 2340 | { |
| 2341 | if (context->getClientMajorVersion() < 3) |
| 2342 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2343 | context->handleError(InvalidOperation() << "CopyBufferSubData requires ES 3 or greater"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2344 | return false; |
| 2345 | } |
| 2346 | |
| 2347 | if (!ValidBufferTarget(context, readTarget) || !ValidBufferTarget(context, writeTarget)) |
| 2348 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2349 | context->handleError(InvalidEnum() << "Invalid buffer target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2350 | return false; |
| 2351 | } |
| 2352 | |
| 2353 | Buffer *readBuffer = context->getGLState().getTargetBuffer(readTarget); |
| 2354 | Buffer *writeBuffer = context->getGLState().getTargetBuffer(writeTarget); |
| 2355 | |
| 2356 | if (!readBuffer || !writeBuffer) |
| 2357 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2358 | context->handleError(InvalidOperation() << "No buffer bound to target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | // Verify that readBuffer and writeBuffer are not currently mapped |
| 2363 | if (readBuffer->isMapped() || writeBuffer->isMapped()) |
| 2364 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2365 | context->handleError(InvalidOperation() |
| 2366 | << "Cannot call CopyBufferSubData on a mapped buffer"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2367 | return false; |
| 2368 | } |
| 2369 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2370 | CheckedNumeric<GLintptr> checkedReadOffset(readOffset); |
| 2371 | CheckedNumeric<GLintptr> checkedWriteOffset(writeOffset); |
| 2372 | CheckedNumeric<GLintptr> checkedSize(size); |
| 2373 | |
| 2374 | auto checkedReadSum = checkedReadOffset + checkedSize; |
| 2375 | auto checkedWriteSum = checkedWriteOffset + checkedSize; |
| 2376 | |
| 2377 | if (!checkedReadSum.IsValid() || !checkedWriteSum.IsValid() || |
| 2378 | !IsValueInRangeForNumericType<GLintptr>(readBuffer->getSize()) || |
| 2379 | !IsValueInRangeForNumericType<GLintptr>(writeBuffer->getSize())) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2380 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2381 | context->handleError(InvalidValue() << "Integer overflow when validating copy offsets."); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2382 | return false; |
| 2383 | } |
| 2384 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2385 | if (readOffset < 0 || writeOffset < 0 || size < 0) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2386 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2387 | context->handleError(InvalidValue() |
| 2388 | << "readOffset, writeOffset and size must all be non-negative"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2389 | return false; |
| 2390 | } |
| 2391 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2392 | if (checkedReadSum.ValueOrDie() > readBuffer->getSize() || |
| 2393 | checkedWriteSum.ValueOrDie() > writeBuffer->getSize()) |
| 2394 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2395 | context->handleError(InvalidValue() << "Buffer offset overflow in CopyBufferSubData"); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2396 | return false; |
| 2397 | } |
| 2398 | |
| 2399 | if (readBuffer == writeBuffer) |
| 2400 | { |
| 2401 | auto checkedOffsetDiff = (checkedReadOffset - checkedWriteOffset).Abs(); |
| 2402 | if (!checkedOffsetDiff.IsValid()) |
| 2403 | { |
| 2404 | // This shold not be possible. |
| 2405 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2406 | context->handleError(InvalidValue() |
| 2407 | << "Integer overflow when validating same buffer copy."); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2408 | return false; |
| 2409 | } |
| 2410 | |
| 2411 | if (checkedOffsetDiff.ValueOrDie() < size) |
| 2412 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2413 | context->handleError(InvalidValue()); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2414 | return false; |
| 2415 | } |
| 2416 | } |
| 2417 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2418 | return true; |
| 2419 | } |
| 2420 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2421 | bool ValidateGetStringi(Context *context, GLenum name, GLuint index) |
| 2422 | { |
| 2423 | if (context->getClientMajorVersion() < 3) |
| 2424 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2425 | context->handleError(InvalidOperation() |
| 2426 | << "glGetStringi requires OpenGL ES 3.0 or higher."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2427 | return false; |
| 2428 | } |
| 2429 | |
| 2430 | switch (name) |
| 2431 | { |
| 2432 | case GL_EXTENSIONS: |
| 2433 | if (index >= context->getExtensionStringCount()) |
| 2434 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2435 | context->handleError(InvalidValue() |
| 2436 | << "index must be less than the number of extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2437 | return false; |
| 2438 | } |
| 2439 | break; |
| 2440 | |
| 2441 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2442 | if (!context->getExtensions().requestExtension) |
| 2443 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2444 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2445 | return false; |
| 2446 | } |
| 2447 | if (index >= context->getRequestableExtensionStringCount()) |
| 2448 | { |
| 2449 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2450 | InvalidValue() |
| 2451 | << "index must be less than the number of requestable extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | break; |
| 2455 | |
| 2456 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2457 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2458 | return false; |
| 2459 | } |
| 2460 | |
| 2461 | return true; |
| 2462 | } |
| 2463 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2464 | bool ValidateRenderbufferStorageMultisample(ValidationContext *context, |
| 2465 | GLenum target, |
| 2466 | GLsizei samples, |
| 2467 | GLenum internalformat, |
| 2468 | GLsizei width, |
| 2469 | GLsizei height) |
| 2470 | { |
| 2471 | if (context->getClientMajorVersion() < 3) |
| 2472 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2473 | context->handleError(InvalidOperation()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2474 | return false; |
| 2475 | } |
| 2476 | |
| 2477 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, |
| 2478 | height)) |
| 2479 | { |
| 2480 | return false; |
| 2481 | } |
| 2482 | |
| 2483 | // The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer |
| 2484 | // format if samples is greater than zero. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2485 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2486 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && |
| 2487 | samples > 0) |
| 2488 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2489 | context->handleError(InvalidOperation()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2490 | return false; |
| 2491 | } |
| 2492 | |
| 2493 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 2494 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 2495 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 2496 | { |
| 2497 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2498 | InvalidOperation() |
| 2499 | << "Samples must not be greater than maximum supported value for the format."); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2500 | return false; |
| 2501 | } |
| 2502 | |
| 2503 | return true; |
| 2504 | } |
| 2505 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2506 | bool ValidateVertexAttribIPointer(ValidationContext *context, |
| 2507 | GLuint index, |
| 2508 | GLint size, |
| 2509 | GLenum type, |
| 2510 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2511 | const void *pointer) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2512 | { |
| 2513 | if (context->getClientMajorVersion() < 3) |
| 2514 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2515 | context->handleError(InvalidOperation() |
| 2516 | << "VertexAttribIPointer requires OpenGL ES 3.0 or higher."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2517 | return false; |
| 2518 | } |
| 2519 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2520 | if (!ValidateVertexFormatBase(context, index, size, type, true)) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2521 | { |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2522 | return false; |
| 2523 | } |
| 2524 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2525 | if (stride < 0) |
| 2526 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2527 | context->handleError(InvalidValue() << "stride cannot be negative."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2528 | return false; |
| 2529 | } |
| 2530 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2531 | const Caps &caps = context->getCaps(); |
| 2532 | if (context->getClientVersion() >= ES_3_1) |
| 2533 | { |
| 2534 | if (stride > caps.maxVertexAttribStride) |
| 2535 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2536 | context->handleError(InvalidValue() |
| 2537 | << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2538 | return false; |
| 2539 | } |
| 2540 | |
| 2541 | // [OpenGL ES 3.1] Section 10.3.1 page 245: |
| 2542 | // glVertexAttribBinding is part of the equivalent code of VertexAttribIPointer, so its |
| 2543 | // validation should be inherited. |
| 2544 | if (index >= caps.maxVertexAttribBindings) |
| 2545 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2546 | context->handleError(InvalidValue() |
| 2547 | << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2548 | return false; |
| 2549 | } |
| 2550 | } |
| 2551 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2552 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 2553 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 2554 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 2555 | // and the pointer argument is not NULL. |
| 2556 | if (context->getGLState().getVertexArrayId() != 0 && |
| 2557 | context->getGLState().getArrayBufferId() == 0 && pointer != nullptr) |
| 2558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2559 | context |
| 2560 | ->handleError(InvalidOperation() |
| 2561 | << "Client data cannot be used with a non-default vertex array object."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2562 | return false; |
| 2563 | } |
| 2564 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 2565 | if (context->getExtensions().webglCompatibility) |
| 2566 | { |
| 2567 | if (!ValidateWebGLVertexAttribPointer(context, type, false, stride, pointer, true)) |
| 2568 | { |
| 2569 | return false; |
| 2570 | } |
| 2571 | } |
| 2572 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2573 | return true; |
| 2574 | } |
| 2575 | |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2576 | bool ValidateGetSynciv(Context *context, |
| 2577 | GLsync sync, |
| 2578 | GLenum pname, |
| 2579 | GLsizei bufSize, |
| 2580 | GLsizei *length, |
| 2581 | GLint *values) |
| 2582 | { |
| 2583 | if (context->getClientMajorVersion() < 3) |
| 2584 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2585 | context->handleError(InvalidOperation() << "GetSynciv requires OpenGL ES 3.0 or higher."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2586 | return false; |
| 2587 | } |
| 2588 | |
| 2589 | if (bufSize < 0) |
| 2590 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2591 | context->handleError(InvalidValue() << "bufSize cannot be negative."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2592 | return false; |
| 2593 | } |
| 2594 | |
| 2595 | FenceSync *fenceSync = context->getFenceSync(sync); |
| 2596 | if (!fenceSync) |
| 2597 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2598 | context->handleError(InvalidValue() << "Invalid sync object."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2599 | return false; |
| 2600 | } |
| 2601 | |
| 2602 | switch (pname) |
| 2603 | { |
| 2604 | case GL_OBJECT_TYPE: |
| 2605 | case GL_SYNC_CONDITION: |
| 2606 | case GL_SYNC_FLAGS: |
| 2607 | case GL_SYNC_STATUS: |
| 2608 | break; |
| 2609 | |
| 2610 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2611 | context->handleError(InvalidEnum() << "Invalid pname."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2612 | return false; |
| 2613 | } |
| 2614 | |
| 2615 | return true; |
| 2616 | } |
| 2617 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2618 | bool ValidateDrawElementsInstanced(ValidationContext *context, |
| 2619 | GLenum mode, |
| 2620 | GLsizei count, |
| 2621 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2622 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2623 | GLsizei instanceCount) |
| 2624 | { |
| 2625 | if (context->getClientMajorVersion() < 3) |
| 2626 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2627 | context->handleError(InvalidOperation() << "Requires a GLES 3.0 or higher context."); |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2628 | return false; |
| 2629 | } |
| 2630 | |
| 2631 | return ValidateDrawElementsInstancedCommon(context, mode, count, type, indices, instanceCount); |
| 2632 | } |
| 2633 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 2634 | bool ValidateFramebufferTextureMultiviewLayeredANGLE(Context *context, |
| 2635 | GLenum target, |
| 2636 | GLenum attachment, |
| 2637 | GLuint texture, |
| 2638 | GLint level, |
| 2639 | GLint baseViewIndex, |
| 2640 | GLsizei numViews) |
| 2641 | { |
| 2642 | |
| 2643 | if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level, |
| 2644 | numViews)) |
| 2645 | { |
| 2646 | return false; |
| 2647 | } |
| 2648 | |
| 2649 | if (baseViewIndex < 0) |
| 2650 | { |
| 2651 | context->handleError(InvalidValue() << "baseViewIndex cannot be less than 0."); |
| 2652 | return false; |
| 2653 | } |
| 2654 | |
| 2655 | if (texture != 0) |
| 2656 | { |
| 2657 | Texture *tex = context->getTexture(texture); |
| 2658 | ASSERT(tex); |
| 2659 | |
| 2660 | switch (tex->getTarget()) |
| 2661 | { |
| 2662 | case GL_TEXTURE_2D_ARRAY: |
| 2663 | { |
| 2664 | const Caps &caps = context->getCaps(); |
| 2665 | if (static_cast<GLuint>(baseViewIndex + numViews) > caps.maxArrayTextureLayers) |
| 2666 | { |
| 2667 | context->handleError(InvalidValue() << "baseViewIndex+numViews cannot be " |
| 2668 | "greater than " |
| 2669 | "GL_MAX_ARRAY_TEXTURE_LAYERS."); |
| 2670 | return false; |
| 2671 | } |
| 2672 | } |
| 2673 | break; |
| 2674 | default: |
| 2675 | context->handleError(InvalidOperation() |
| 2676 | << "Texture's target must be GL_TEXTURE_2D_ARRAY."); |
| 2677 | return false; |
| 2678 | } |
| 2679 | |
| 2680 | if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level)) |
| 2681 | { |
| 2682 | return false; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | return true; |
| 2687 | } |
| 2688 | |
| 2689 | bool ValidateFramebufferTextureMultiviewSideBySideANGLE(Context *context, |
| 2690 | GLenum target, |
| 2691 | GLenum attachment, |
| 2692 | GLuint texture, |
| 2693 | GLint level, |
| 2694 | GLsizei numViews, |
| 2695 | const GLint *viewportOffsets) |
| 2696 | { |
| 2697 | if (!ValidateFramebufferTextureMultiviewBaseANGLE(context, target, attachment, texture, level, |
| 2698 | numViews)) |
| 2699 | { |
| 2700 | return false; |
| 2701 | } |
| 2702 | |
| 2703 | const GLsizei numViewportOffsetValues = numViews * 2; |
| 2704 | for (GLsizei i = 0; i < numViewportOffsetValues; ++i) |
| 2705 | { |
| 2706 | if (viewportOffsets[i] < 0) |
| 2707 | { |
| 2708 | context->handleError(InvalidValue() |
| 2709 | << "viewportOffsets cannot contain negative values."); |
| 2710 | return false; |
| 2711 | } |
| 2712 | } |
| 2713 | |
| 2714 | if (texture != 0) |
| 2715 | { |
| 2716 | Texture *tex = context->getTexture(texture); |
| 2717 | ASSERT(tex); |
| 2718 | |
| 2719 | switch (tex->getTarget()) |
| 2720 | { |
| 2721 | case GL_TEXTURE_2D: |
| 2722 | break; |
| 2723 | default: |
| 2724 | context->handleError(InvalidOperation() |
| 2725 | << "Texture's target must be GL_TEXTURE_2D."); |
| 2726 | return false; |
| 2727 | } |
| 2728 | |
| 2729 | if (!ValidateFramebufferTextureMultiviewLevelAndFormat(context, tex, level)) |
| 2730 | { |
| 2731 | return false; |
| 2732 | } |
| 2733 | } |
| 2734 | |
| 2735 | return true; |
| 2736 | } |
| 2737 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2738 | } // namespace gl |