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