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