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