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