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 | |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 191 | if (!ValidCompressedImageSize(context, actualInternalFormat, width, height)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 192 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 193 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 194 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 195 | } |
| 196 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 197 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 198 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 199 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 200 | return false; |
| 201 | } |
| 202 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 203 | if (target == GL_TEXTURE_3D) |
| 204 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 205 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 206 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | else |
| 210 | { |
Geoff Lang | baadf23 | 2014-08-04 13:58:02 -0400 | [diff] [blame] | 211 | if (!ValidateTexImageFormatCombination(context, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 212 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 213 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 217 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 218 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 219 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | // Validate sub image parameters |
| 224 | if (isSubImage) |
| 225 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 226 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 227 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 228 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 229 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 232 | if (width == 0 || height == 0 || depth == 0) |
| 233 | { |
| 234 | return false; |
| 235 | } |
| 236 | |
| 237 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 238 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 239 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 240 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 244 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 245 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 246 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 247 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 248 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 249 | } |
| 250 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 251 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 252 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 253 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 254 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 255 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 256 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 260 | if (!ValidImageDataSize(context, target, width, height, 1, actualInternalFormat, type, pixels, |
| 261 | imageSize)) |
| 262 | { |
| 263 | return false; |
| 264 | } |
| 265 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 266 | // Check for pixel unpack buffer related API errors |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 267 | gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 268 | if (pixelUnpackBuffer != nullptr) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 269 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 270 | // ...data is not evenly divisible into the number of bytes needed to store in memory a |
| 271 | // datum |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 272 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 273 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 274 | { |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 275 | size_t offset = reinterpret_cast<size_t>(pixels); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 276 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 277 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 278 | if ((offset % dataBytesPerPixel) != 0) |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 279 | { |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 280 | context->handleError( |
| 281 | Error(GL_INVALID_OPERATION, "Reads would overflow the pixel unpack buffer.")); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 282 | return false; |
| 283 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 286 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 287 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 288 | { |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 289 | context->handleError(Error(GL_INVALID_OPERATION, "Pixel unpack buffer is mapped.")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 290 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 291 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 292 | } |
| 293 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 294 | return true; |
| 295 | } |
| 296 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 297 | bool ValidateES3TexImage2DParameters(Context *context, |
| 298 | GLenum target, |
| 299 | GLint level, |
| 300 | GLenum internalformat, |
| 301 | bool isCompressed, |
| 302 | bool isSubImage, |
| 303 | GLint xoffset, |
| 304 | GLint yoffset, |
| 305 | GLint zoffset, |
| 306 | GLsizei width, |
| 307 | GLsizei height, |
| 308 | GLsizei depth, |
| 309 | GLint border, |
| 310 | GLenum format, |
| 311 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 312 | GLsizei imageSize, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 313 | const GLvoid *pixels) |
| 314 | { |
| 315 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 316 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 317 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 318 | return false; |
| 319 | } |
| 320 | |
| 321 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 322 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 323 | depth, border, format, type, imageSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | bool ValidateES3TexImage3DParameters(Context *context, |
| 327 | GLenum target, |
| 328 | GLint level, |
| 329 | GLenum internalformat, |
| 330 | bool isCompressed, |
| 331 | bool isSubImage, |
| 332 | GLint xoffset, |
| 333 | GLint yoffset, |
| 334 | GLint zoffset, |
| 335 | GLsizei width, |
| 336 | GLsizei height, |
| 337 | GLsizei depth, |
| 338 | GLint border, |
| 339 | GLenum format, |
| 340 | GLenum type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 341 | GLsizei bufSize, |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 342 | const GLvoid *pixels) |
| 343 | { |
| 344 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 345 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 346 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 347 | return false; |
| 348 | } |
| 349 | |
| 350 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 351 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 352 | depth, border, format, type, bufSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 353 | } |
| 354 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 355 | struct EffectiveInternalFormatInfo |
| 356 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 357 | GLenum effectiveFormat; |
| 358 | GLenum destFormat; |
| 359 | GLuint minRedBits; |
| 360 | GLuint maxRedBits; |
| 361 | GLuint minGreenBits; |
| 362 | GLuint maxGreenBits; |
| 363 | GLuint minBlueBits; |
| 364 | GLuint maxBlueBits; |
| 365 | GLuint minAlphaBits; |
| 366 | GLuint maxAlphaBits; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 367 | }; |
| 368 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 369 | static bool QueryEffectiveFormatList(const InternalFormat &srcFormat, |
| 370 | GLenum targetFormat, |
| 371 | const EffectiveInternalFormatInfo *list, |
| 372 | size_t size, |
| 373 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 374 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 375 | for (size_t curFormat = 0; curFormat < size; ++curFormat) |
| 376 | { |
| 377 | const EffectiveInternalFormatInfo &formatInfo = list[curFormat]; |
| 378 | if ((formatInfo.destFormat == targetFormat) && |
| 379 | (formatInfo.minRedBits <= srcFormat.redBits && |
| 380 | formatInfo.maxRedBits >= srcFormat.redBits) && |
| 381 | (formatInfo.minGreenBits <= srcFormat.greenBits && |
| 382 | formatInfo.maxGreenBits >= srcFormat.greenBits) && |
| 383 | (formatInfo.minBlueBits <= srcFormat.blueBits && |
| 384 | formatInfo.maxBlueBits >= srcFormat.blueBits) && |
| 385 | (formatInfo.minAlphaBits <= srcFormat.alphaBits && |
| 386 | formatInfo.maxAlphaBits >= srcFormat.alphaBits)) |
| 387 | { |
| 388 | *outEffectiveFormat = formatInfo.effectiveFormat; |
| 389 | return true; |
| 390 | } |
| 391 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 392 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 393 | *outEffectiveFormat = GL_NONE; |
| 394 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 395 | } |
| 396 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 397 | bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 398 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 399 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 400 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 401 | // Effective internal format coresponding to destination internal format and linear source |
| 402 | // buffer component sizes. |
| 403 | // | Source channel min/max sizes | |
| 404 | // Effective Internal Format | N/A | R | G | B | A | |
| 405 | // clang-format off |
| 406 | constexpr EffectiveInternalFormatInfo list[] = { |
| 407 | { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 }, |
| 408 | { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 }, |
| 409 | { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 }, |
| 410 | { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 }, |
| 411 | { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 }, |
| 412 | { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 413 | { GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 414 | { GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 }, |
| 415 | { GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 }, |
| 416 | }; |
| 417 | // clang-format on |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 418 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 419 | return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat); |
| 420 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 421 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 422 | bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 423 | const InternalFormat &destFormat, |
| 424 | GLenum *outEffectiveFormat) |
| 425 | { |
| 426 | constexpr GLuint umax = UINT_MAX; |
| 427 | |
| 428 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 429 | // Effective internal format coresponding to destination internal format andlinear source buffer |
| 430 | // component sizes. |
| 431 | // | Source channel min/max sizes | |
| 432 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 433 | // clang-format off |
| 434 | constexpr EffectiveInternalFormatInfo list[] = { |
| 435 | { GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 }, |
| 436 | { GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax }, |
| 437 | { GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 }, |
| 438 | { GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax }, |
| 439 | { GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax }, |
| 440 | { GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 441 | { GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 442 | { GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 }, |
| 443 | }; |
| 444 | // clang-format on |
| 445 | |
| 446 | return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list), |
| 447 | outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 448 | } |
| 449 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 450 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, |
| 451 | const InternalFormat &destFormat, |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 452 | GLenum *outEffectiveFormat) |
| 453 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 454 | if (destFormat.pixelBytes > 0) |
| 455 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 456 | return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 457 | } |
| 458 | else |
| 459 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 460 | return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 461 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 462 | } |
| 463 | |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 464 | static bool EqualOrFirstZero(GLuint first, GLuint second) |
| 465 | { |
| 466 | return first == 0 || first == second; |
| 467 | } |
| 468 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 469 | static bool IsValidES3CopyTexImageCombination(const Format &textureFormat, |
| 470 | const Format &framebufferFormat, |
| 471 | GLuint readBufferHandle) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 472 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 473 | const auto &textureFormatInfo = *textureFormat.info; |
| 474 | const auto &framebufferFormatInfo = *framebufferFormat.info; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 475 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 476 | if (!ValidES3CopyConversion(textureFormatInfo.format, framebufferFormatInfo.format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 477 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 478 | return false; |
| 479 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 480 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 481 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 482 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 483 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 484 | // conversion between fixed and floating point. |
| 485 | |
| 486 | if ((textureFormatInfo.colorEncoding == GL_SRGB) != |
| 487 | (framebufferFormatInfo.colorEncoding == GL_SRGB)) |
| 488 | { |
| 489 | return false; |
| 490 | } |
| 491 | |
| 492 | if (((textureFormatInfo.componentType == GL_INT) != |
| 493 | (framebufferFormatInfo.componentType == GL_INT)) || |
| 494 | ((textureFormatInfo.componentType == GL_UNSIGNED_INT) != |
| 495 | (framebufferFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 496 | { |
| 497 | return false; |
| 498 | } |
| 499 | |
| 500 | if ((textureFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 501 | textureFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 502 | textureFormatInfo.componentType == GL_FLOAT) && |
| 503 | !(framebufferFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 504 | framebufferFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 505 | framebufferFormatInfo.componentType == GL_FLOAT)) |
| 506 | { |
| 507 | return false; |
| 508 | } |
| 509 | |
| 510 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 511 | // The effective internal format of the source buffer is determined with the following rules |
| 512 | // applied in order: |
| 513 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal |
| 514 | // format then the effective internal format is the source buffer's sized internal format. |
| 515 | // * If the source buffer is a texture that was created with an unsized base internal format, |
| 516 | // then the effective internal format is the source image array's effective internal |
| 517 | // format, as specified by table 3.12, which is determined from the <format> and <type> |
| 518 | // that were used when the source image array was specified by TexImage*. |
| 519 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 |
| 520 | // where Destination Internal Format matches internalformat and where the [source channel |
| 521 | // sizes] are consistent with the values of the source buffer's [channel sizes]. Table 3.17 |
| 522 | // is used if the FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the |
| 523 | // FRAMEBUFFER_ATTACHMENT_ENCODING is SRGB. |
| 524 | const InternalFormat *sourceEffectiveFormat = NULL; |
| 525 | if (readBufferHandle != 0) |
| 526 | { |
| 527 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or |
| 528 | // renderbuffer |
| 529 | if (framebufferFormat.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 530 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 531 | sourceEffectiveFormat = &framebufferFormatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 532 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 533 | else |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 534 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 535 | // Renderbuffers cannot be created with an unsized internal format, so this must be an |
| 536 | // unsized-format texture. We can use the same table we use when creating textures to |
| 537 | // get its effective sized format. |
| 538 | GLenum sizedInternalFormat = |
| 539 | GetSizedInternalFormat(framebufferFormatInfo.format, framebufferFormatInfo.type); |
| 540 | sourceEffectiveFormat = &GetInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 541 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 542 | } |
| 543 | else |
| 544 | { |
| 545 | // The effective internal format must be derived from the source framebuffer's channel |
| 546 | // sizes. This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 547 | if (framebufferFormatInfo.colorEncoding == GL_LINEAR) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 548 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 549 | GLenum effectiveFormat; |
| 550 | if (GetEffectiveInternalFormat(framebufferFormatInfo, textureFormatInfo, |
| 551 | &effectiveFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 552 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 553 | sourceEffectiveFormat = &GetInternalFormatInfo(effectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 554 | } |
| 555 | else |
| 556 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 557 | return false; |
| 558 | } |
| 559 | } |
| 560 | else if (framebufferFormatInfo.colorEncoding == GL_SRGB) |
| 561 | { |
| 562 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
| 563 | if (textureFormat.sized && |
| 564 | (framebufferFormatInfo.redBits >= 1 && framebufferFormatInfo.redBits <= 8) && |
| 565 | (framebufferFormatInfo.greenBits >= 1 && framebufferFormatInfo.greenBits <= 8) && |
| 566 | (framebufferFormatInfo.blueBits >= 1 && framebufferFormatInfo.blueBits <= 8) && |
| 567 | (framebufferFormatInfo.alphaBits >= 1 && framebufferFormatInfo.alphaBits <= 8)) |
| 568 | { |
| 569 | sourceEffectiveFormat = &GetInternalFormatInfo(GL_SRGB8_ALPHA8); |
| 570 | } |
| 571 | else |
| 572 | { |
| 573 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | else |
| 577 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 578 | UNREACHABLE(); |
| 579 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 580 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 581 | } |
| 582 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 583 | if (textureFormat.sized) |
| 584 | { |
| 585 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is |
| 586 | // sized, component sizes of the source and destination formats must exactly match if the |
| 587 | // destination format exists. |
| 588 | if (!EqualOrFirstZero(textureFormatInfo.redBits, sourceEffectiveFormat->redBits) || |
| 589 | !EqualOrFirstZero(textureFormatInfo.greenBits, sourceEffectiveFormat->greenBits) || |
| 590 | !EqualOrFirstZero(textureFormatInfo.blueBits, sourceEffectiveFormat->blueBits) || |
| 591 | !EqualOrFirstZero(textureFormatInfo.alphaBits, sourceEffectiveFormat->alphaBits)) |
| 592 | { |
| 593 | return false; |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | return true; // A conversion function exists, and no rule in the specification has precluded |
| 598 | // conversion between these formats. |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 601 | bool ValidateES3CopyTexImageParametersBase(ValidationContext *context, |
| 602 | GLenum target, |
| 603 | GLint level, |
| 604 | GLenum internalformat, |
| 605 | bool isSubImage, |
| 606 | GLint xoffset, |
| 607 | GLint yoffset, |
| 608 | GLint zoffset, |
| 609 | GLint x, |
| 610 | GLint y, |
| 611 | GLsizei width, |
| 612 | GLsizei height, |
| 613 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 614 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 615 | Format textureFormat = Format::Invalid(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 616 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 617 | xoffset, yoffset, zoffset, x, y, width, height, border, |
| 618 | &textureFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 619 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 620 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 621 | } |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 622 | ASSERT(textureFormat.valid() || !isSubImage); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 623 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 624 | const auto &state = context->getGLState(); |
| 625 | gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 626 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 627 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 628 | if (framebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 629 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 630 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 631 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 632 | } |
| 633 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 634 | if (readFramebufferID != 0 && framebuffer->getSamples(context->getContextState()) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 635 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 636 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 637 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 640 | const FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 641 | |
| 642 | if (isSubImage) |
| 643 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 644 | if (!IsValidES3CopyTexImageCombination(textureFormat, source->getFormat(), |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 645 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 646 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 647 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 648 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 649 | } |
| 650 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 651 | else |
| 652 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 653 | // Use format/type from the source FBO. (Might not be perfect for all cases?) |
| 654 | const auto framebufferFormat = source->getFormat(); |
| 655 | Format copyFormat(internalformat, framebufferFormat.format, framebufferFormat.type); |
| 656 | if (!IsValidES3CopyTexImageCombination(copyFormat, framebufferFormat, readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 657 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 658 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 659 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 660 | } |
| 661 | } |
| 662 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 663 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 664 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 665 | } |
| 666 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 667 | bool ValidateES3CopyTexImage2DParameters(ValidationContext *context, |
| 668 | GLenum target, |
| 669 | GLint level, |
| 670 | GLenum internalformat, |
| 671 | bool isSubImage, |
| 672 | GLint xoffset, |
| 673 | GLint yoffset, |
| 674 | GLint zoffset, |
| 675 | GLint x, |
| 676 | GLint y, |
| 677 | GLsizei width, |
| 678 | GLsizei height, |
| 679 | GLint border) |
| 680 | { |
| 681 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 682 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 683 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | |
| 687 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 688 | xoffset, yoffset, zoffset, x, y, width, height, |
| 689 | border); |
| 690 | } |
| 691 | |
| 692 | bool ValidateES3CopyTexImage3DParameters(ValidationContext *context, |
| 693 | GLenum target, |
| 694 | GLint level, |
| 695 | GLenum internalformat, |
| 696 | bool isSubImage, |
| 697 | GLint xoffset, |
| 698 | GLint yoffset, |
| 699 | GLint zoffset, |
| 700 | GLint x, |
| 701 | GLint y, |
| 702 | GLsizei width, |
| 703 | GLsizei height, |
| 704 | GLint border) |
| 705 | { |
| 706 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 707 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 708 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 709 | return false; |
| 710 | } |
| 711 | |
| 712 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 713 | xoffset, yoffset, zoffset, x, y, width, height, |
| 714 | border); |
| 715 | } |
| 716 | |
| 717 | bool ValidateES3TexStorageParametersBase(Context *context, |
| 718 | GLenum target, |
| 719 | GLsizei levels, |
| 720 | GLenum internalformat, |
| 721 | GLsizei width, |
| 722 | GLsizei height, |
| 723 | GLsizei depth) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 724 | { |
| 725 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 726 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 727 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 728 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 729 | } |
| 730 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 731 | GLsizei maxDim = std::max(width, height); |
| 732 | if (target != GL_TEXTURE_2D_ARRAY) |
| 733 | { |
| 734 | maxDim = std::max(maxDim, depth); |
| 735 | } |
| 736 | |
| 737 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 738 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 739 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 740 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 741 | } |
| 742 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 743 | const gl::Caps &caps = context->getCaps(); |
| 744 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 745 | switch (target) |
| 746 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 747 | case GL_TEXTURE_2D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 748 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 749 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 750 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 751 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 752 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 753 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 754 | } |
| 755 | } |
| 756 | break; |
| 757 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 758 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 759 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 760 | if (width != height) |
| 761 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 762 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 763 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 766 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 767 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 768 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 769 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 770 | } |
| 771 | } |
| 772 | break; |
| 773 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 774 | case GL_TEXTURE_3D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 775 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 776 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 777 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 778 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 779 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 780 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 781 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 782 | } |
| 783 | } |
| 784 | break; |
| 785 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 786 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 787 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 788 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 789 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 790 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 791 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 792 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 793 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 794 | } |
| 795 | } |
| 796 | break; |
| 797 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 798 | default: |
| 799 | UNREACHABLE(); |
| 800 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 801 | } |
| 802 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 803 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 804 | if (!texture || texture->id() == 0) |
| 805 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 806 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 807 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 808 | } |
| 809 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 810 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 811 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 812 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 813 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 814 | } |
| 815 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 816 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 817 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 818 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 819 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 820 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 821 | } |
| 822 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 823 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 824 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 825 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 826 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | return true; |
| 830 | } |
| 831 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 832 | bool ValidateES3TexStorage2DParameters(Context *context, |
| 833 | GLenum target, |
| 834 | GLsizei levels, |
| 835 | GLenum internalformat, |
| 836 | GLsizei width, |
| 837 | GLsizei height, |
| 838 | GLsizei depth) |
| 839 | { |
| 840 | if (!ValidTexture2DTarget(context, target)) |
| 841 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 842 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 843 | return false; |
| 844 | } |
| 845 | |
| 846 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 847 | height, depth); |
| 848 | } |
| 849 | |
| 850 | bool ValidateES3TexStorage3DParameters(Context *context, |
| 851 | GLenum target, |
| 852 | GLsizei levels, |
| 853 | GLenum internalformat, |
| 854 | GLsizei width, |
| 855 | GLsizei height, |
| 856 | GLsizei depth) |
| 857 | { |
| 858 | if (!ValidTexture3DTarget(context, target)) |
| 859 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 860 | context->handleError(Error(GL_INVALID_ENUM)); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 861 | return false; |
| 862 | } |
| 863 | |
| 864 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 865 | height, depth); |
| 866 | } |
| 867 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 868 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 869 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 870 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 871 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 872 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 873 | return false; |
| 874 | } |
| 875 | |
| 876 | return ValidateBeginQueryBase(context, target, id); |
| 877 | } |
| 878 | |
| 879 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 880 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 881 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 882 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 883 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 884 | return false; |
| 885 | } |
| 886 | |
| 887 | return ValidateEndQueryBase(context, target); |
| 888 | } |
| 889 | |
| 890 | bool ValidateGetQueryiv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 891 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 892 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 893 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 894 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 895 | return false; |
| 896 | } |
| 897 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 898 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 902 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 903 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 904 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 905 | context->handleError(Error(GL_INVALID_OPERATION, "GLES version < 3.0")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 906 | return false; |
| 907 | } |
| 908 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 909 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 910 | } |
| 911 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 912 | bool ValidateFramebufferTextureLayer(Context *context, |
| 913 | GLenum target, |
| 914 | GLenum attachment, |
| 915 | GLuint texture, |
| 916 | GLint level, |
| 917 | GLint layer) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 918 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 919 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 920 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 921 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 922 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 923 | } |
| 924 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 925 | if (layer < 0) |
| 926 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 927 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 928 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 932 | { |
| 933 | return false; |
| 934 | } |
| 935 | |
| 936 | const gl::Caps &caps = context->getCaps(); |
| 937 | if (texture != 0) |
| 938 | { |
| 939 | gl::Texture *tex = context->getTexture(texture); |
| 940 | ASSERT(tex); |
| 941 | |
| 942 | switch (tex->getTarget()) |
| 943 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 944 | case GL_TEXTURE_2D_ARRAY: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 945 | { |
| 946 | if (level > gl::log2(caps.max2DTextureSize)) |
| 947 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 948 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 949 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 953 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 954 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 955 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 956 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 957 | } |
| 958 | break; |
| 959 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 960 | case GL_TEXTURE_3D: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 961 | { |
| 962 | if (level > gl::log2(caps.max3DTextureSize)) |
| 963 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 964 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 965 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 969 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 970 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 971 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 972 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 973 | } |
| 974 | break; |
| 975 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 976 | default: |
| 977 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 978 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 979 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 980 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 981 | const auto &format = tex->getFormat(tex->getTarget(), level); |
| 982 | if (format.info->compressed) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 983 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 984 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 985 | return false; |
| 986 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 987 | } |
| 988 | |
| 989 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 990 | } |
| 991 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 992 | bool ValidateES3RenderbufferStorageParameters(gl::Context *context, |
| 993 | GLenum target, |
| 994 | GLsizei samples, |
| 995 | GLenum internalformat, |
| 996 | GLsizei width, |
| 997 | GLsizei height) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 998 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 999 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, |
| 1000 | height)) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1001 | { |
| 1002 | return false; |
| 1003 | } |
| 1004 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1005 | // The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer |
| 1006 | // format if samples is greater than zero. |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1007 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1008 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && |
| 1009 | samples > 0) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1010 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1011 | context->handleError(Error(GL_INVALID_OPERATION)); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1012 | return false; |
| 1013 | } |
| 1014 | |
| 1015 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 1016 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1017 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1018 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1019 | context->handleError( |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1020 | Error(GL_INVALID_OPERATION, |
| 1021 | "Samples must not be greater than maximum supported value for the format.")); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1022 | return false; |
| 1023 | } |
| 1024 | |
| 1025 | return true; |
| 1026 | } |
| 1027 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1028 | bool ValidateInvalidateFramebuffer(Context *context, |
| 1029 | GLenum target, |
| 1030 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1031 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1032 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1033 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1034 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1035 | context->handleError( |
| 1036 | Error(GL_INVALID_OPERATION, "Operation only supported on ES 3.0 and above")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1037 | return false; |
| 1038 | } |
| 1039 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1040 | bool defaultFramebuffer = false; |
| 1041 | |
| 1042 | switch (target) |
| 1043 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1044 | case GL_DRAW_FRAMEBUFFER: |
| 1045 | case GL_FRAMEBUFFER: |
| 1046 | defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0; |
| 1047 | break; |
| 1048 | case GL_READ_FRAMEBUFFER: |
| 1049 | defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0; |
| 1050 | break; |
| 1051 | default: |
| 1052 | context->handleError(Error(GL_INVALID_ENUM, "Invalid framebuffer target")); |
| 1053 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1054 | } |
| 1055 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1056 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1057 | defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1058 | } |
| 1059 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1060 | bool ValidateClearBuffer(ValidationContext *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1061 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1062 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1063 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1064 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1065 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1066 | } |
| 1067 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1068 | if (context->getGLState().getDrawFramebuffer()->checkStatus(context->getContextState()) != |
| 1069 | GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1070 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1071 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1072 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | return true; |
| 1076 | } |
| 1077 | |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1078 | bool ValidateDrawRangeElements(Context *context, |
| 1079 | GLenum mode, |
| 1080 | GLuint start, |
| 1081 | GLuint end, |
| 1082 | GLsizei count, |
| 1083 | GLenum type, |
| 1084 | const GLvoid *indices, |
| 1085 | IndexRange *indexRange) |
| 1086 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1087 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1088 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1089 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1090 | return false; |
| 1091 | } |
| 1092 | |
| 1093 | if (end < start) |
| 1094 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1095 | context->handleError(Error(GL_INVALID_VALUE, "end < start")); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1096 | return false; |
| 1097 | } |
| 1098 | |
| 1099 | if (!ValidateDrawElements(context, mode, count, type, indices, 0, indexRange)) |
| 1100 | { |
| 1101 | return false; |
| 1102 | } |
| 1103 | |
| 1104 | if (indexRange->end > end || indexRange->start < start) |
| 1105 | { |
| 1106 | // 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] | 1107 | context->handleError( |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1108 | Error(GL_INVALID_OPERATION, "Indices are out of the start, end range.")); |
| 1109 | return false; |
| 1110 | } |
| 1111 | return true; |
| 1112 | } |
| 1113 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1114 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1115 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1116 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1117 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1118 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1119 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1120 | } |
| 1121 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1122 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1123 | } |
| 1124 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1125 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1126 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1127 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1128 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1129 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1130 | return false; |
| 1131 | } |
| 1132 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1133 | const Framebuffer *readFBO = context->getGLState().getReadFramebuffer(); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1134 | |
| 1135 | if (readFBO == nullptr) |
| 1136 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1137 | context->handleError(gl::Error(GL_INVALID_OPERATION, "No active read framebuffer.")); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1138 | return false; |
| 1139 | } |
| 1140 | |
| 1141 | if (src == GL_NONE) |
| 1142 | { |
| 1143 | return true; |
| 1144 | } |
| 1145 | |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1146 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1147 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1148 | 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] | 1149 | return false; |
| 1150 | } |
| 1151 | |
| 1152 | if (readFBO->id() == 0) |
| 1153 | { |
| 1154 | if (src != GL_BACK) |
| 1155 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame^] | 1156 | const char *errorMsg = |
| 1157 | "'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] | 1158 | context->handleError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1159 | return false; |
| 1160 | } |
| 1161 | } |
| 1162 | else |
| 1163 | { |
| 1164 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1165 | |
| 1166 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1167 | { |
| 1168 | const char *errorMsg = "'src' is greater than MAX_DRAW_BUFFERS."; |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1169 | context->handleError(gl::Error(GL_INVALID_OPERATION, errorMsg)); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1170 | return false; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | return true; |
| 1175 | } |
| 1176 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1177 | bool ValidateCompressedTexImage3D(Context *context, |
| 1178 | GLenum target, |
| 1179 | GLint level, |
| 1180 | GLenum internalformat, |
| 1181 | GLsizei width, |
| 1182 | GLsizei height, |
| 1183 | GLsizei depth, |
| 1184 | GLint border, |
| 1185 | GLsizei imageSize, |
| 1186 | const GLvoid *data) |
| 1187 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1188 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1189 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1190 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1191 | return false; |
| 1192 | } |
| 1193 | |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1194 | if (!ValidTextureTarget(context, target)) |
| 1195 | { |
| 1196 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1200 | // Validate image size |
| 1201 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, false)) |
| 1202 | { |
| 1203 | context->handleError(Error(GL_INVALID_VALUE)); |
| 1204 | return false; |
| 1205 | } |
| 1206 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1207 | const InternalFormat &formatInfo = GetInternalFormatInfo(internalformat); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1208 | if (!formatInfo.compressed) |
| 1209 | { |
| 1210 | context->handleError(Error(GL_INVALID_ENUM, "Not a valid compressed texture format")); |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1214 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1215 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1216 | if (blockSizeOrErr.isError()) |
| 1217 | { |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1218 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1219 | return false; |
| 1220 | } |
| 1221 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1222 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1223 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1224 | return false; |
| 1225 | } |
| 1226 | |
| 1227 | // 3D texture target validation |
| 1228 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1229 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1230 | context->handleError( |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1231 | Error(GL_INVALID_ENUM, "Must specify a valid 3D texture destination target")); |
| 1232 | return false; |
| 1233 | } |
| 1234 | |
| 1235 | // validateES3TexImageFormat sets the error code if there is an error |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1236 | if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1237 | 0, width, height, depth, border, GL_NONE, GL_NONE, -1, |
| 1238 | data)) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1239 | { |
| 1240 | return false; |
| 1241 | } |
| 1242 | |
| 1243 | return true; |
| 1244 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1245 | |
| 1246 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1247 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1248 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1249 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1250 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1251 | return false; |
| 1252 | } |
| 1253 | |
| 1254 | return ValidateBindVertexArrayBase(context, array); |
| 1255 | } |
| 1256 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1257 | bool ValidateIsVertexArray(Context *context) |
| 1258 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1259 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1260 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1261 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1262 | return false; |
| 1263 | } |
| 1264 | |
| 1265 | return true; |
| 1266 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1267 | |
| 1268 | bool ValidateProgramBinary(Context *context, |
| 1269 | GLuint program, |
| 1270 | GLenum binaryFormat, |
| 1271 | const void *binary, |
| 1272 | GLint length) |
| 1273 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1274 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1275 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1276 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1277 | return false; |
| 1278 | } |
| 1279 | |
| 1280 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1281 | } |
| 1282 | |
| 1283 | bool ValidateGetProgramBinary(Context *context, |
| 1284 | GLuint program, |
| 1285 | GLsizei bufSize, |
| 1286 | GLsizei *length, |
| 1287 | GLenum *binaryFormat, |
| 1288 | void *binary) |
| 1289 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1290 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1291 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1292 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1293 | return false; |
| 1294 | } |
| 1295 | |
| 1296 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1297 | } |
| 1298 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1299 | bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1300 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1301 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1302 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1303 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1304 | return false; |
| 1305 | } |
| 1306 | |
| 1307 | if (GetValidProgram(context, program) == nullptr) |
| 1308 | { |
| 1309 | return false; |
| 1310 | } |
| 1311 | |
| 1312 | switch (pname) |
| 1313 | { |
| 1314 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1315 | if (value != GL_FALSE && value != GL_TRUE) |
| 1316 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1317 | context->handleError(Error( |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1318 | GL_INVALID_VALUE, "Invalid value, expected GL_FALSE or GL_TRUE: %i", value)); |
| 1319 | return false; |
| 1320 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1324 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname: 0x%X", pname)); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1325 | return false; |
| 1326 | } |
| 1327 | |
| 1328 | return true; |
| 1329 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1330 | |
| 1331 | bool ValidateBlitFramebuffer(Context *context, |
| 1332 | GLint srcX0, |
| 1333 | GLint srcY0, |
| 1334 | GLint srcX1, |
| 1335 | GLint srcY1, |
| 1336 | GLint dstX0, |
| 1337 | GLint dstY0, |
| 1338 | GLint dstX1, |
| 1339 | GLint dstY1, |
| 1340 | GLbitfield mask, |
| 1341 | GLenum filter) |
| 1342 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1343 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1344 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1345 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1346 | return false; |
| 1347 | } |
| 1348 | |
| 1349 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1350 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1351 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1352 | |
| 1353 | bool ValidateClearBufferiv(ValidationContext *context, |
| 1354 | GLenum buffer, |
| 1355 | GLint drawbuffer, |
| 1356 | const GLint *value) |
| 1357 | { |
| 1358 | switch (buffer) |
| 1359 | { |
| 1360 | case GL_COLOR: |
| 1361 | if (drawbuffer < 0 || |
| 1362 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1363 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1364 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1365 | return false; |
| 1366 | } |
| 1367 | break; |
| 1368 | |
| 1369 | case GL_STENCIL: |
| 1370 | if (drawbuffer != 0) |
| 1371 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1372 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1373 | return false; |
| 1374 | } |
| 1375 | break; |
| 1376 | |
| 1377 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1378 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
| 1381 | |
| 1382 | return ValidateClearBuffer(context); |
| 1383 | } |
| 1384 | |
| 1385 | bool ValidateClearBufferuiv(ValidationContext *context, |
| 1386 | GLenum buffer, |
| 1387 | GLint drawbuffer, |
| 1388 | const GLuint *value) |
| 1389 | { |
| 1390 | switch (buffer) |
| 1391 | { |
| 1392 | case GL_COLOR: |
| 1393 | if (drawbuffer < 0 || |
| 1394 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1395 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1396 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1397 | return false; |
| 1398 | } |
| 1399 | break; |
| 1400 | |
| 1401 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1402 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1403 | return false; |
| 1404 | } |
| 1405 | |
| 1406 | return ValidateClearBuffer(context); |
| 1407 | } |
| 1408 | |
| 1409 | bool ValidateClearBufferfv(ValidationContext *context, |
| 1410 | GLenum buffer, |
| 1411 | GLint drawbuffer, |
| 1412 | const GLfloat *value) |
| 1413 | { |
| 1414 | switch (buffer) |
| 1415 | { |
| 1416 | case GL_COLOR: |
| 1417 | if (drawbuffer < 0 || |
| 1418 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1419 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1420 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1421 | return false; |
| 1422 | } |
| 1423 | break; |
| 1424 | |
| 1425 | case GL_DEPTH: |
| 1426 | if (drawbuffer != 0) |
| 1427 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1428 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1429 | return false; |
| 1430 | } |
| 1431 | break; |
| 1432 | |
| 1433 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1434 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1435 | return false; |
| 1436 | } |
| 1437 | |
| 1438 | return ValidateClearBuffer(context); |
| 1439 | } |
| 1440 | |
| 1441 | bool ValidateClearBufferfi(ValidationContext *context, |
| 1442 | GLenum buffer, |
| 1443 | GLint drawbuffer, |
| 1444 | GLfloat depth, |
| 1445 | GLint stencil) |
| 1446 | { |
| 1447 | switch (buffer) |
| 1448 | { |
| 1449 | case GL_DEPTH_STENCIL: |
| 1450 | if (drawbuffer != 0) |
| 1451 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1452 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1453 | return false; |
| 1454 | } |
| 1455 | break; |
| 1456 | |
| 1457 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1458 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1459 | return false; |
| 1460 | } |
| 1461 | |
| 1462 | return ValidateClearBuffer(context); |
| 1463 | } |
| 1464 | |
| 1465 | bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1466 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1467 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1468 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1469 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1470 | return false; |
| 1471 | } |
| 1472 | |
| 1473 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1474 | } |
| 1475 | |
| 1476 | bool ValidateCopyTexSubImage3D(Context *context, |
| 1477 | GLenum target, |
| 1478 | GLint level, |
| 1479 | GLint xoffset, |
| 1480 | GLint yoffset, |
| 1481 | GLint zoffset, |
| 1482 | GLint x, |
| 1483 | GLint y, |
| 1484 | GLsizei width, |
| 1485 | GLsizei height) |
| 1486 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1487 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1488 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1489 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1490 | return false; |
| 1491 | } |
| 1492 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1493 | return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset, |
| 1494 | yoffset, zoffset, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1495 | } |
| 1496 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1497 | bool ValidateTexImage3D(Context *context, |
| 1498 | GLenum target, |
| 1499 | GLint level, |
| 1500 | GLint internalformat, |
| 1501 | GLsizei width, |
| 1502 | GLsizei height, |
| 1503 | GLsizei depth, |
| 1504 | GLint border, |
| 1505 | GLenum format, |
| 1506 | GLenum type, |
| 1507 | const GLvoid *pixels) |
| 1508 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1509 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1510 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1511 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1512 | return false; |
| 1513 | } |
| 1514 | |
| 1515 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1516 | 0, 0, width, height, depth, border, format, type, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1517 | pixels); |
| 1518 | } |
| 1519 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1520 | bool ValidateTexImage3DRobustANGLE(Context *context, |
| 1521 | GLenum target, |
| 1522 | GLint level, |
| 1523 | GLint internalformat, |
| 1524 | GLsizei width, |
| 1525 | GLsizei height, |
| 1526 | GLsizei depth, |
| 1527 | GLint border, |
| 1528 | GLenum format, |
| 1529 | GLenum type, |
| 1530 | GLsizei bufSize, |
| 1531 | const GLvoid *pixels) |
| 1532 | { |
| 1533 | if (context->getClientMajorVersion() < 3) |
| 1534 | { |
| 1535 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1540 | { |
| 1541 | return false; |
| 1542 | } |
| 1543 | |
| 1544 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
| 1545 | 0, 0, width, height, depth, border, format, type, |
| 1546 | bufSize, pixels); |
| 1547 | } |
| 1548 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1549 | bool ValidateTexSubImage3D(Context *context, |
| 1550 | GLenum target, |
| 1551 | GLint level, |
| 1552 | GLint xoffset, |
| 1553 | GLint yoffset, |
| 1554 | GLint zoffset, |
| 1555 | GLsizei width, |
| 1556 | GLsizei height, |
| 1557 | GLsizei depth, |
| 1558 | GLenum format, |
| 1559 | GLenum type, |
| 1560 | const GLvoid *pixels) |
| 1561 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1562 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1563 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1564 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1569 | yoffset, zoffset, width, height, depth, 0, format, type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1570 | -1, pixels); |
| 1571 | } |
| 1572 | |
| 1573 | bool ValidateTexSubImage3DRobustANGLE(Context *context, |
| 1574 | GLenum target, |
| 1575 | GLint level, |
| 1576 | GLint xoffset, |
| 1577 | GLint yoffset, |
| 1578 | GLint zoffset, |
| 1579 | GLsizei width, |
| 1580 | GLsizei height, |
| 1581 | GLsizei depth, |
| 1582 | GLenum format, |
| 1583 | GLenum type, |
| 1584 | GLsizei bufSize, |
| 1585 | const GLvoid *pixels) |
| 1586 | { |
| 1587 | if (context->getClientMajorVersion() < 3) |
| 1588 | { |
| 1589 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 1590 | return false; |
| 1591 | } |
| 1592 | |
| 1593 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1594 | { |
| 1595 | return false; |
| 1596 | } |
| 1597 | |
| 1598 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1599 | yoffset, zoffset, width, height, depth, 0, format, type, |
| 1600 | bufSize, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | bool ValidateCompressedTexSubImage3D(Context *context, |
| 1604 | GLenum target, |
| 1605 | GLint level, |
| 1606 | GLint xoffset, |
| 1607 | GLint yoffset, |
| 1608 | GLint zoffset, |
| 1609 | GLsizei width, |
| 1610 | GLsizei height, |
| 1611 | GLsizei depth, |
| 1612 | GLenum format, |
| 1613 | GLsizei imageSize, |
| 1614 | const GLvoid *data) |
| 1615 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1616 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1617 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1618 | context->handleError(Error(GL_INVALID_OPERATION)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | |
| 1622 | const InternalFormat &formatInfo = GetInternalFormatInfo(format); |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1623 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1624 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1625 | if (blockSizeOrErr.isError()) |
| 1626 | { |
| 1627 | context->handleError(blockSizeOrErr.getError()); |
| 1628 | return false; |
| 1629 | } |
| 1630 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1631 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1632 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1633 | return false; |
| 1634 | } |
| 1635 | |
| 1636 | if (!data) |
| 1637 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1638 | context->handleError(Error(GL_INVALID_VALUE)); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1639 | return false; |
| 1640 | } |
| 1641 | |
| 1642 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, 0, 0, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1643 | width, height, depth, 0, GL_NONE, GL_NONE, -1, data); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1644 | } |
| 1645 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1646 | bool ValidateGenQueries(Context *context, GLint n, GLuint *) |
| 1647 | { |
| 1648 | return ValidateGenOrDeleteES3(context, n); |
| 1649 | } |
| 1650 | |
| 1651 | bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *) |
| 1652 | { |
| 1653 | return ValidateGenOrDeleteES3(context, n); |
| 1654 | } |
| 1655 | |
| 1656 | bool ValidateGenSamplers(Context *context, GLint count, GLuint *) |
| 1657 | { |
| 1658 | return ValidateGenOrDeleteCountES3(context, count); |
| 1659 | } |
| 1660 | |
| 1661 | bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *) |
| 1662 | { |
| 1663 | return ValidateGenOrDeleteCountES3(context, count); |
| 1664 | } |
| 1665 | |
| 1666 | bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *) |
| 1667 | { |
| 1668 | return ValidateGenOrDeleteES3(context, n); |
| 1669 | } |
| 1670 | |
| 1671 | bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids) |
| 1672 | { |
| 1673 | if (!ValidateGenOrDeleteES3(context, n)) |
| 1674 | { |
| 1675 | return false; |
| 1676 | } |
| 1677 | for (GLint i = 0; i < n; ++i) |
| 1678 | { |
| 1679 | auto *transformFeedback = context->getTransformFeedback(ids[i]); |
| 1680 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 1681 | { |
| 1682 | // ES 3.0.4 section 2.15.1 page 86 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1683 | context->handleError( |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1684 | Error(GL_INVALID_OPERATION, "Attempt to delete active transform feedback.")); |
| 1685 | return false; |
| 1686 | } |
| 1687 | } |
| 1688 | return true; |
| 1689 | } |
| 1690 | |
| 1691 | bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *) |
| 1692 | { |
| 1693 | return ValidateGenOrDeleteES3(context, n); |
| 1694 | } |
| 1695 | |
| 1696 | bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *) |
| 1697 | { |
| 1698 | return ValidateGenOrDeleteES3(context, n); |
| 1699 | } |
| 1700 | |
| 1701 | bool ValidateGenOrDeleteES3(Context *context, GLint n) |
| 1702 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1703 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1704 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1705 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1706 | return false; |
| 1707 | } |
| 1708 | return ValidateGenOrDelete(context, n); |
| 1709 | } |
| 1710 | |
| 1711 | bool ValidateGenOrDeleteCountES3(Context *context, GLint count) |
| 1712 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1713 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1714 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1715 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1716 | return false; |
| 1717 | } |
| 1718 | if (count < 0) |
| 1719 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1720 | context->handleError(Error(GL_INVALID_VALUE, "count < 0")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1721 | return false; |
| 1722 | } |
| 1723 | return true; |
| 1724 | } |
| 1725 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1726 | bool ValidateBeginTransformFeedback(Context *context, GLenum primitiveMode) |
| 1727 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1728 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1729 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1730 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1731 | return false; |
| 1732 | } |
| 1733 | switch (primitiveMode) |
| 1734 | { |
| 1735 | case GL_TRIANGLES: |
| 1736 | case GL_LINES: |
| 1737 | case GL_POINTS: |
| 1738 | break; |
| 1739 | |
| 1740 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1741 | context->handleError(Error(GL_INVALID_ENUM, "Invalid primitive mode.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1742 | return false; |
| 1743 | } |
| 1744 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1745 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1746 | ASSERT(transformFeedback != nullptr); |
| 1747 | |
| 1748 | if (transformFeedback->isActive()) |
| 1749 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1750 | context->handleError(Error(GL_INVALID_OPERATION, "Transform feedback is already active.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1751 | return false; |
| 1752 | } |
| 1753 | return true; |
| 1754 | } |
| 1755 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1756 | bool ValidateGetBufferPointerv(Context *context, GLenum target, GLenum pname, GLvoid **params) |
| 1757 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 1758 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
| 1759 | } |
| 1760 | |
| 1761 | bool ValidateGetBufferPointervRobustANGLE(Context *context, |
| 1762 | GLenum target, |
| 1763 | GLenum pname, |
| 1764 | GLsizei bufSize, |
| 1765 | GLsizei *length, |
| 1766 | GLvoid **params) |
| 1767 | { |
| 1768 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1769 | { |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1770 | return false; |
| 1771 | } |
| 1772 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 1773 | if (!ValidateGetBufferPointervBase(context, target, pname, length, params)) |
| 1774 | { |
| 1775 | return false; |
| 1776 | } |
| 1777 | |
| 1778 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1779 | { |
| 1780 | return false; |
| 1781 | } |
| 1782 | |
| 1783 | return true; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1784 | } |
| 1785 | |
| 1786 | bool ValidateUnmapBuffer(Context *context, GLenum target) |
| 1787 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1788 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1789 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1790 | context->handleError(Error(GL_INVALID_OPERATION)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1791 | return false; |
| 1792 | } |
| 1793 | |
| 1794 | return ValidateUnmapBufferBase(context, target); |
| 1795 | } |
| 1796 | |
| 1797 | bool ValidateMapBufferRange(Context *context, |
| 1798 | GLenum target, |
| 1799 | GLintptr offset, |
| 1800 | GLsizeiptr length, |
| 1801 | GLbitfield access) |
| 1802 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1803 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1804 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1805 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1806 | return false; |
| 1807 | } |
| 1808 | |
| 1809 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 1810 | } |
| 1811 | |
| 1812 | bool ValidateFlushMappedBufferRange(Context *context, |
| 1813 | GLenum target, |
| 1814 | GLintptr offset, |
| 1815 | GLsizeiptr length) |
| 1816 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1817 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1818 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1819 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
| 1822 | |
| 1823 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 1824 | } |
| 1825 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1826 | bool ValidateIndexedStateQuery(ValidationContext *context, |
| 1827 | GLenum pname, |
| 1828 | GLuint index, |
| 1829 | GLsizei *length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1830 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1831 | if (length) |
| 1832 | { |
| 1833 | *length = 0; |
| 1834 | } |
| 1835 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1836 | GLenum nativeType; |
| 1837 | unsigned int numParams; |
| 1838 | if (!context->getIndexedQueryParameterInfo(pname, &nativeType, &numParams)) |
| 1839 | { |
| 1840 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1841 | return false; |
| 1842 | } |
| 1843 | |
| 1844 | const Caps &caps = context->getCaps(); |
| 1845 | switch (pname) |
| 1846 | { |
| 1847 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 1848 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
| 1849 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 1850 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 1851 | { |
| 1852 | context->handleError(Error(GL_INVALID_VALUE)); |
| 1853 | return false; |
| 1854 | } |
| 1855 | break; |
| 1856 | |
| 1857 | case GL_UNIFORM_BUFFER_START: |
| 1858 | case GL_UNIFORM_BUFFER_SIZE: |
| 1859 | case GL_UNIFORM_BUFFER_BINDING: |
| 1860 | if (index >= caps.maxUniformBufferBindings) |
| 1861 | { |
| 1862 | context->handleError(Error(GL_INVALID_VALUE)); |
| 1863 | return false; |
| 1864 | } |
| 1865 | break; |
| 1866 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 1867 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 1868 | if (index >= 3u) |
| 1869 | { |
| 1870 | context->handleError(Error(GL_INVALID_VALUE)); |
| 1871 | return false; |
| 1872 | } |
| 1873 | break; |
| 1874 | default: |
| 1875 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1876 | return false; |
| 1877 | } |
| 1878 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1879 | if (length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1880 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1881 | *length = 1; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | return true; |
| 1885 | } |
| 1886 | |
| 1887 | bool ValidateGetIntegeri_v(ValidationContext *context, GLenum target, GLuint index, GLint *data) |
| 1888 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1889 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1890 | { |
| 1891 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.0")); |
| 1892 | return false; |
| 1893 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1894 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1895 | } |
| 1896 | |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 1897 | bool ValidateGetIntegeri_vRobustANGLE(ValidationContext *context, |
| 1898 | GLenum target, |
| 1899 | GLuint index, |
| 1900 | GLsizei bufSize, |
| 1901 | GLsizei *length, |
| 1902 | GLint *data) |
| 1903 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1904 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 1905 | { |
| 1906 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.0")); |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
| 1910 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1911 | { |
| 1912 | return false; |
| 1913 | } |
| 1914 | |
| 1915 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 1916 | { |
| 1917 | return false; |
| 1918 | } |
| 1919 | |
| 1920 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1921 | { |
| 1922 | return false; |
| 1923 | } |
| 1924 | |
| 1925 | return true; |
| 1926 | } |
| 1927 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1928 | bool ValidateGetInteger64i_v(ValidationContext *context, GLenum target, GLuint index, GLint64 *data) |
| 1929 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1930 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1931 | { |
| 1932 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.0")); |
| 1933 | return false; |
| 1934 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1935 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
| 1936 | } |
| 1937 | |
| 1938 | bool ValidateGetInteger64i_vRobustANGLE(ValidationContext *context, |
| 1939 | GLenum target, |
| 1940 | GLuint index, |
| 1941 | GLsizei bufSize, |
| 1942 | GLsizei *length, |
| 1943 | GLint64 *data) |
| 1944 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1945 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 1946 | { |
| 1947 | context->handleError(Error(GL_INVALID_OPERATION, "Context does not support GLES3.0")); |
| 1948 | return false; |
| 1949 | } |
| 1950 | |
| 1951 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1952 | { |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
| 1956 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 1957 | { |
| 1958 | return false; |
| 1959 | } |
| 1960 | |
| 1961 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1962 | { |
| 1963 | return false; |
| 1964 | } |
| 1965 | |
| 1966 | return true; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1967 | } |
| 1968 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 1969 | bool ValidateCopyBufferSubData(ValidationContext *context, |
| 1970 | GLenum readTarget, |
| 1971 | GLenum writeTarget, |
| 1972 | GLintptr readOffset, |
| 1973 | GLintptr writeOffset, |
| 1974 | GLsizeiptr size) |
| 1975 | { |
| 1976 | if (context->getClientMajorVersion() < 3) |
| 1977 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 1978 | context->handleError( |
| 1979 | Error(GL_INVALID_OPERATION, "CopyBufferSubData requires ES 3 or greater")); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 1980 | return false; |
| 1981 | } |
| 1982 | |
| 1983 | if (!ValidBufferTarget(context, readTarget) || !ValidBufferTarget(context, writeTarget)) |
| 1984 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 1985 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target")); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 1986 | return false; |
| 1987 | } |
| 1988 | |
| 1989 | Buffer *readBuffer = context->getGLState().getTargetBuffer(readTarget); |
| 1990 | Buffer *writeBuffer = context->getGLState().getTargetBuffer(writeTarget); |
| 1991 | |
| 1992 | if (!readBuffer || !writeBuffer) |
| 1993 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 1994 | context->handleError(Error(GL_INVALID_OPERATION, "No buffer bound to target")); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 1995 | return false; |
| 1996 | } |
| 1997 | |
| 1998 | // Verify that readBuffer and writeBuffer are not currently mapped |
| 1999 | if (readBuffer->isMapped() || writeBuffer->isMapped()) |
| 2000 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2001 | context->handleError( |
| 2002 | Error(GL_INVALID_OPERATION, "Cannot call CopyBufferSubData on a mapped buffer")); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2003 | return false; |
| 2004 | } |
| 2005 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2006 | CheckedNumeric<GLintptr> checkedReadOffset(readOffset); |
| 2007 | CheckedNumeric<GLintptr> checkedWriteOffset(writeOffset); |
| 2008 | CheckedNumeric<GLintptr> checkedSize(size); |
| 2009 | |
| 2010 | auto checkedReadSum = checkedReadOffset + checkedSize; |
| 2011 | auto checkedWriteSum = checkedWriteOffset + checkedSize; |
| 2012 | |
| 2013 | if (!checkedReadSum.IsValid() || !checkedWriteSum.IsValid() || |
| 2014 | !IsValueInRangeForNumericType<GLintptr>(readBuffer->getSize()) || |
| 2015 | !IsValueInRangeForNumericType<GLintptr>(writeBuffer->getSize())) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2016 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2017 | context->handleError( |
| 2018 | Error(GL_INVALID_VALUE, "Integer overflow when validating copy offsets.")); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2019 | return false; |
| 2020 | } |
| 2021 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2022 | if (readOffset < 0 || writeOffset < 0 || size < 0) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2023 | { |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2024 | context->handleError( |
| 2025 | 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] | 2026 | return false; |
| 2027 | } |
| 2028 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2029 | if (checkedReadSum.ValueOrDie() > readBuffer->getSize() || |
| 2030 | checkedWriteSum.ValueOrDie() > writeBuffer->getSize()) |
| 2031 | { |
| 2032 | context->handleError( |
| 2033 | Error(GL_INVALID_VALUE, "Buffer offset overflow in CopyBufferSubData")); |
| 2034 | return false; |
| 2035 | } |
| 2036 | |
| 2037 | if (readBuffer == writeBuffer) |
| 2038 | { |
| 2039 | auto checkedOffsetDiff = (checkedReadOffset - checkedWriteOffset).Abs(); |
| 2040 | if (!checkedOffsetDiff.IsValid()) |
| 2041 | { |
| 2042 | // This shold not be possible. |
| 2043 | UNREACHABLE(); |
| 2044 | context->handleError( |
| 2045 | Error(GL_INVALID_VALUE, "Integer overflow when validating same buffer copy.")); |
| 2046 | return false; |
| 2047 | } |
| 2048 | |
| 2049 | if (checkedOffsetDiff.ValueOrDie() < size) |
| 2050 | { |
| 2051 | context->handleError(Error(GL_INVALID_VALUE)); |
| 2052 | return false; |
| 2053 | } |
| 2054 | } |
| 2055 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2056 | return true; |
| 2057 | } |
| 2058 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2059 | } // namespace gl |