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