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