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