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