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