Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1 | // |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2 | // Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved. |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
| 7 | // validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES3.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Jamie Madill | 5ea762a | 2017-06-07 14:59:51 -0400 | [diff] [blame] | 11 | #include "anglebase/numerics/safe_conversions.h" |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 12 | #include "common/mathutil.h" |
| 13 | #include "common/utilities.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Context.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 15 | #include "libANGLE/Framebuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 16 | #include "libANGLE/FramebufferAttachment.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 17 | #include "libANGLE/Renderbuffer.h" |
| 18 | #include "libANGLE/Texture.h" |
| 19 | #include "libANGLE/formatutils.h" |
| 20 | #include "libANGLE/validationES.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 21 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 22 | using namespace angle; |
| 23 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 24 | namespace gl |
| 25 | { |
| 26 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 27 | static bool ValidateTexImageFormatCombination(gl::Context *context, |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 28 | GLenum target, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 29 | GLenum internalFormat, |
| 30 | GLenum format, |
| 31 | GLenum type) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 32 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 33 | |
| 34 | // The type and format are valid if any supported internal format has that type and format |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 35 | if (!ValidES3Format(format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 36 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 37 | context->handleError(InvalidEnum() << "Invalid format."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 38 | return false; |
| 39 | } |
| 40 | |
| 41 | if (!ValidES3Type(type)) |
| 42 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 43 | context->handleError(InvalidEnum() << "Invalid type."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 44 | return false; |
| 45 | } |
| 46 | |
| 47 | // For historical reasons, glTexImage2D and glTexImage3D pass in their internal format as a |
| 48 | // GLint instead of a GLenum. Therefor an invalid internal format gives a GL_INVALID_VALUE |
| 49 | // error instead of a GL_INVALID_ENUM error. As this validation function is only called in |
| 50 | // the validation codepaths for glTexImage2D/3D, we record a GL_INVALID_VALUE error. |
| 51 | if (!ValidES3InternalFormat(internalFormat)) |
| 52 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 53 | context->handleError(InvalidValue() << "Invalid internalFormat."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 54 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 55 | } |
| 56 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 57 | // From the ES 3.0 spec section 3.8.3: |
| 58 | // Textures with a base internal format of DEPTH_COMPONENT or DEPTH_STENCIL are supported by |
| 59 | // texture image specification commands only if target is TEXTURE_2D, TEXTURE_2D_ARRAY, or |
| 60 | // TEXTURE_CUBE_MAP.Using these formats in conjunction with any other target will result in an |
| 61 | // INVALID_OPERATION error. |
| 62 | if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL)) |
| 63 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 64 | context->handleError(InvalidOperation() << "Format cannot be GL_DEPTH_COMPONENT or " |
| 65 | "GL_DEPTH_STENCIL if target is " |
| 66 | "GL_TEXTURE_3D"); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 67 | return false; |
| 68 | } |
| 69 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 70 | // Check if this is a valid format combination to load texture data |
Jamie Madill | 55e9821 | 2016-10-05 16:39:13 -0400 | [diff] [blame] | 71 | if (!ValidES3FormatCombination(format, type, internalFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 72 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 73 | context->handleError(InvalidOperation() |
| 74 | << "Invalid combination of format, type and internalFormat."); |
Geoff Lang | 6d1ccf0 | 2017-04-24 14:09:58 -0400 | [diff] [blame] | 75 | return false; |
| 76 | } |
| 77 | |
| 78 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); |
| 79 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
| 80 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 81 | context->handleError(InvalidOperation() << "Unsupported internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 82 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | return true; |
| 86 | } |
| 87 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 88 | bool ValidateES3TexImageParametersBase(Context *context, |
| 89 | GLenum target, |
| 90 | GLint level, |
| 91 | GLenum internalformat, |
| 92 | bool isCompressed, |
| 93 | bool isSubImage, |
| 94 | GLint xoffset, |
| 95 | GLint yoffset, |
| 96 | GLint zoffset, |
| 97 | GLsizei width, |
| 98 | GLsizei height, |
| 99 | GLsizei depth, |
| 100 | GLint border, |
| 101 | GLenum format, |
| 102 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 103 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 104 | const void *pixels) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 105 | { |
| 106 | // Validate image size |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 107 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, isSubImage)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 108 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 109 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 110 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 113 | // Verify zero border |
| 114 | if (border != 0) |
| 115 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 116 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 117 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 118 | } |
| 119 | |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 120 | if (xoffset < 0 || yoffset < 0 || zoffset < 0 || |
| 121 | std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 122 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 123 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 124 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 125 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 126 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 127 | } |
| 128 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 129 | const gl::Caps &caps = context->getCaps(); |
| 130 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 131 | switch (target) |
| 132 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 133 | case GL_TEXTURE_2D: |
| 134 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 135 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level)) |
| 136 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 137 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 138 | return false; |
| 139 | } |
| 140 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 141 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 142 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 143 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 144 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 145 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 146 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 147 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 148 | if (!isSubImage && width != height) |
| 149 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 150 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 151 | return false; |
| 152 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 153 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 154 | if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level)) |
| 155 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 156 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 157 | return false; |
| 158 | } |
| 159 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 160 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 161 | case GL_TEXTURE_3D: |
| 162 | if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) || |
| 163 | static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) || |
| 164 | static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level)) |
| 165 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 166 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 167 | return false; |
| 168 | } |
| 169 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 170 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 171 | case GL_TEXTURE_2D_ARRAY: |
| 172 | if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) || |
| 173 | static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) || |
| 174 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
| 175 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 176 | context->handleError(InvalidValue()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 177 | return false; |
| 178 | } |
| 179 | break; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 180 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 181 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 182 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 183 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 184 | } |
| 185 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 186 | gl::Texture *texture = |
| 187 | context->getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 188 | if (!texture) |
| 189 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 190 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 191 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 192 | } |
| 193 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 194 | if (texture->getImmutableFormat() && !isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 195 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 196 | context->handleError(InvalidOperation()); |
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 | // Validate texture formats |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 201 | GLenum actualInternalFormat = |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 202 | isSubImage ? texture->getFormat(target, level).info->internalFormat : internalformat; |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 203 | if (isSubImage && actualInternalFormat == GL_NONE) |
| 204 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 205 | context->handleError(InvalidOperation() << "Texture level does not exist."); |
Geoff Lang | c51642b | 2016-11-14 16:18:26 -0500 | [diff] [blame] | 206 | return false; |
| 207 | } |
| 208 | |
Geoff Lang | c4e9366 | 2017-05-01 10:45:59 -0400 | [diff] [blame] | 209 | const gl::InternalFormat &actualFormatInfo = isSubImage |
| 210 | ? *texture->getFormat(target, level).info |
| 211 | : GetInternalFormatInfo(internalformat, type); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 212 | if (isCompressed) |
| 213 | { |
tmartino | 7c10269 | 2015-10-02 16:43:40 -0400 | [diff] [blame] | 214 | if (!actualFormatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 215 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 216 | context->handleError( |
| 217 | InvalidEnum() << "internalformat is not a supported compressed internal format."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 218 | return false; |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 219 | } |
| 220 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 221 | if (isSubImage) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 222 | { |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 223 | if (!ValidCompressedSubImageSize( |
| 224 | context, actualFormatInfo.internalFormat, xoffset, yoffset, width, height, |
| 225 | texture->getWidth(target, level), texture->getHeight(target, level))) |
| 226 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 227 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 228 | return false; |
| 229 | } |
| 230 | |
| 231 | if (format != actualInternalFormat) |
| 232 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 233 | context->handleError(InvalidOperation() |
| 234 | << "Format must match the internal format of the texture."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 235 | return false; |
| 236 | } |
| 237 | } |
| 238 | else |
| 239 | { |
| 240 | if (!ValidCompressedImageSize(context, actualInternalFormat, level, width, height)) |
| 241 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 242 | context->handleError(InvalidOperation() << "Invalid compressed format dimension."); |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 243 | return false; |
| 244 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 247 | if (!actualFormatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 248 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 249 | context->handleError(InvalidEnum()); |
Geoff Lang | 839ce0b | 2015-10-23 13:13:12 -0400 | [diff] [blame] | 250 | return false; |
| 251 | } |
| 252 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 253 | if (target == GL_TEXTURE_3D) |
| 254 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 255 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 256 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 257 | } |
| 258 | } |
| 259 | else |
| 260 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 261 | if (!ValidateTexImageFormatCombination(context, target, actualInternalFormat, format, type)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 262 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 263 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 264 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | // Validate sub image parameters |
| 268 | if (isSubImage) |
| 269 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 270 | if (isCompressed != actualFormatInfo.compressed) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 271 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 272 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 273 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 274 | } |
| 275 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 276 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
| 277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 278 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 279 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 283 | std::numeric_limits<GLsizei>::max() - yoffset < height || |
| 284 | std::numeric_limits<GLsizei>::max() - zoffset < depth) |
| 285 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 286 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 287 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 288 | } |
| 289 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 290 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 291 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 292 | static_cast<size_t>(zoffset + depth) > texture->getDepth(target, level)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 293 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 294 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 295 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 296 | } |
| 297 | } |
| 298 | |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 299 | GLenum sizeCheckFormat = isSubImage ? format : internalformat; |
| 300 | if (!ValidImageDataSize(context, target, width, height, depth, sizeCheckFormat, type, pixels, |
| 301 | imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 302 | { |
| 303 | return false; |
| 304 | } |
| 305 | |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 306 | // Check for pixel unpack buffer related API errors |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 307 | gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
Corentin Wallez | ece7c5a | 2016-09-21 15:28:23 -0400 | [diff] [blame] | 308 | if (pixelUnpackBuffer != nullptr) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 309 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 310 | // ...data is not evenly divisible into the number of bytes needed to store in memory a |
| 311 | // datum |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 312 | // indicated by type. |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 313 | if (!isCompressed) |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 314 | { |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 315 | size_t offset = reinterpret_cast<size_t>(pixels); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 316 | size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeInfo(type).bytes); |
| 317 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 318 | if ((offset % dataBytesPerPixel) != 0) |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 319 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 320 | context->handleError(InvalidOperation() |
| 321 | << "Reads would overflow the pixel unpack buffer."); |
Jamie Madill | c751d1e | 2014-10-21 17:46:29 -0400 | [diff] [blame] | 322 | return false; |
| 323 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 326 | // ...the buffer object's data store is currently mapped. |
Brandon Jones | d38f926 | 2014-06-18 16:26:45 -0700 | [diff] [blame] | 327 | if (pixelUnpackBuffer->isMapped()) |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 328 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 329 | context->handleError(InvalidOperation() << "Pixel unpack buffer is mapped."); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 330 | return false; |
Jamie Madill | 7a5f738 | 2014-03-05 15:01:24 -0500 | [diff] [blame] | 331 | } |
Jamie Madill | efb2a6f | 2013-09-24 10:22:42 -0400 | [diff] [blame] | 332 | } |
| 333 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 334 | return true; |
| 335 | } |
| 336 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 337 | bool ValidateES3TexImage2DParameters(Context *context, |
| 338 | GLenum target, |
| 339 | GLint level, |
| 340 | GLenum internalformat, |
| 341 | bool isCompressed, |
| 342 | bool isSubImage, |
| 343 | GLint xoffset, |
| 344 | GLint yoffset, |
| 345 | GLint zoffset, |
| 346 | GLsizei width, |
| 347 | GLsizei height, |
| 348 | GLsizei depth, |
| 349 | GLint border, |
| 350 | GLenum format, |
| 351 | GLenum type, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 352 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 353 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 354 | { |
| 355 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 356 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 357 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 358 | return false; |
| 359 | } |
| 360 | |
| 361 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 362 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 363 | depth, border, format, type, imageSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | bool ValidateES3TexImage3DParameters(Context *context, |
| 367 | GLenum target, |
| 368 | GLint level, |
| 369 | GLenum internalformat, |
| 370 | bool isCompressed, |
| 371 | bool isSubImage, |
| 372 | GLint xoffset, |
| 373 | GLint yoffset, |
| 374 | GLint zoffset, |
| 375 | GLsizei width, |
| 376 | GLsizei height, |
| 377 | GLsizei depth, |
| 378 | GLint border, |
| 379 | GLenum format, |
| 380 | GLenum type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 381 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 382 | const void *pixels) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 383 | { |
| 384 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 385 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 386 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 387 | return false; |
| 388 | } |
| 389 | |
| 390 | return ValidateES3TexImageParametersBase(context, target, level, internalformat, isCompressed, |
| 391 | isSubImage, xoffset, yoffset, zoffset, width, height, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 392 | depth, border, format, type, bufSize, pixels); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 393 | } |
| 394 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 395 | struct EffectiveInternalFormatInfo |
| 396 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 397 | GLenum effectiveFormat; |
| 398 | GLenum destFormat; |
| 399 | GLuint minRedBits; |
| 400 | GLuint maxRedBits; |
| 401 | GLuint minGreenBits; |
| 402 | GLuint maxGreenBits; |
| 403 | GLuint minBlueBits; |
| 404 | GLuint maxBlueBits; |
| 405 | GLuint minAlphaBits; |
| 406 | GLuint maxAlphaBits; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 407 | }; |
| 408 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 409 | static bool QueryEffectiveFormatList(const InternalFormat &srcFormat, |
| 410 | GLenum targetFormat, |
| 411 | const EffectiveInternalFormatInfo *list, |
| 412 | size_t size, |
| 413 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 414 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 415 | for (size_t curFormat = 0; curFormat < size; ++curFormat) |
| 416 | { |
| 417 | const EffectiveInternalFormatInfo &formatInfo = list[curFormat]; |
| 418 | if ((formatInfo.destFormat == targetFormat) && |
| 419 | (formatInfo.minRedBits <= srcFormat.redBits && |
| 420 | formatInfo.maxRedBits >= srcFormat.redBits) && |
| 421 | (formatInfo.minGreenBits <= srcFormat.greenBits && |
| 422 | formatInfo.maxGreenBits >= srcFormat.greenBits) && |
| 423 | (formatInfo.minBlueBits <= srcFormat.blueBits && |
| 424 | formatInfo.maxBlueBits >= srcFormat.blueBits) && |
| 425 | (formatInfo.minAlphaBits <= srcFormat.alphaBits && |
| 426 | formatInfo.maxAlphaBits >= srcFormat.alphaBits)) |
| 427 | { |
| 428 | *outEffectiveFormat = formatInfo.effectiveFormat; |
| 429 | return true; |
| 430 | } |
| 431 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 432 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 433 | *outEffectiveFormat = GL_NONE; |
| 434 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 435 | } |
| 436 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 437 | bool GetSizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 438 | GLenum *outEffectiveFormat) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 439 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 440 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 441 | // Effective internal format coresponding to destination internal format and linear source |
| 442 | // buffer component sizes. |
| 443 | // | Source channel min/max sizes | |
| 444 | // Effective Internal Format | N/A | R | G | B | A | |
| 445 | // clang-format off |
| 446 | constexpr EffectiveInternalFormatInfo list[] = { |
| 447 | { GL_ALPHA8_EXT, GL_NONE, 0, 0, 0, 0, 0, 0, 1, 8 }, |
| 448 | { GL_R8, GL_NONE, 1, 8, 0, 0, 0, 0, 0, 0 }, |
| 449 | { GL_RG8, GL_NONE, 1, 8, 1, 8, 0, 0, 0, 0 }, |
| 450 | { GL_RGB565, GL_NONE, 1, 5, 1, 6, 1, 5, 0, 0 }, |
| 451 | { GL_RGB8, GL_NONE, 6, 8, 7, 8, 6, 8, 0, 0 }, |
| 452 | { GL_RGBA4, GL_NONE, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 453 | { GL_RGB5_A1, GL_NONE, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 454 | { GL_RGBA8, GL_NONE, 5, 8, 5, 8, 5, 8, 2, 8 }, |
| 455 | { GL_RGB10_A2, GL_NONE, 9, 10, 9, 10, 9, 10, 2, 2 }, |
| 456 | }; |
| 457 | // clang-format on |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 458 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 459 | return QueryEffectiveFormatList(srcFormat, GL_NONE, list, ArraySize(list), outEffectiveFormat); |
| 460 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 461 | |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 462 | bool GetUnsizedEffectiveInternalFormatInfo(const InternalFormat &srcFormat, |
| 463 | const InternalFormat &destFormat, |
| 464 | GLenum *outEffectiveFormat) |
| 465 | { |
| 466 | constexpr GLuint umax = UINT_MAX; |
| 467 | |
| 468 | // OpenGL ES 3.0.3 Specification, Table 3.17, pg 141: |
| 469 | // Effective internal format coresponding to destination internal format andlinear source buffer |
| 470 | // component sizes. |
| 471 | // | Source channel min/max sizes | |
| 472 | // Effective Internal Format | Dest Format | R | G | B | A | |
| 473 | // clang-format off |
| 474 | constexpr EffectiveInternalFormatInfo list[] = { |
| 475 | { GL_ALPHA8_EXT, GL_ALPHA, 0, umax, 0, umax, 0, umax, 1, 8 }, |
| 476 | { GL_LUMINANCE8_EXT, GL_LUMINANCE, 1, 8, 0, umax, 0, umax, 0, umax }, |
| 477 | { GL_LUMINANCE8_ALPHA8_EXT, GL_LUMINANCE_ALPHA, 1, 8, 0, umax, 0, umax, 1, 8 }, |
| 478 | { GL_RGB565, GL_RGB, 1, 5, 1, 6, 1, 5, 0, umax }, |
| 479 | { GL_RGB8, GL_RGB, 6, 8, 7, 8, 6, 8, 0, umax }, |
| 480 | { GL_RGBA4, GL_RGBA, 1, 4, 1, 4, 1, 4, 1, 4 }, |
| 481 | { GL_RGB5_A1, GL_RGBA, 5, 5, 5, 5, 5, 5, 1, 1 }, |
| 482 | { GL_RGBA8, GL_RGBA, 5, 8, 5, 8, 5, 8, 5, 8 }, |
| 483 | }; |
| 484 | // clang-format on |
| 485 | |
| 486 | return QueryEffectiveFormatList(srcFormat, destFormat.format, list, ArraySize(list), |
| 487 | outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 488 | } |
| 489 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 490 | static bool GetEffectiveInternalFormat(const InternalFormat &srcFormat, |
| 491 | const InternalFormat &destFormat, |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 492 | GLenum *outEffectiveFormat) |
| 493 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 494 | if (destFormat.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 495 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 496 | return GetSizedEffectiveInternalFormatInfo(srcFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 497 | } |
| 498 | else |
| 499 | { |
Jamie Madill | 76648fe | 2016-10-05 17:01:41 -0400 | [diff] [blame] | 500 | return GetUnsizedEffectiveInternalFormatInfo(srcFormat, destFormat, outEffectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 501 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 502 | } |
| 503 | |
Corentin Wallez | 7628768 | 2016-04-25 09:23:38 -0400 | [diff] [blame] | 504 | static bool EqualOrFirstZero(GLuint first, GLuint second) |
| 505 | { |
| 506 | return first == 0 || first == second; |
| 507 | } |
| 508 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 509 | static bool IsValidES3CopyTexImageCombination(const InternalFormat &textureFormatInfo, |
| 510 | const InternalFormat &framebufferFormatInfo, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 511 | GLuint readBufferHandle) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 512 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 513 | if (!ValidES3CopyConversion(textureFormatInfo.format, framebufferFormatInfo.format)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 514 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 515 | return false; |
| 516 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 517 | |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 518 | // Section 3.8.5 of the GLES 3.0.3 spec states that source and destination formats |
| 519 | // must both be signed, unsigned, or fixed point and both source and destinations |
| 520 | // must be either both SRGB or both not SRGB. EXT_color_buffer_float adds allowed |
| 521 | // conversion between fixed and floating point. |
| 522 | |
| 523 | if ((textureFormatInfo.colorEncoding == GL_SRGB) != |
| 524 | (framebufferFormatInfo.colorEncoding == GL_SRGB)) |
| 525 | { |
| 526 | return false; |
| 527 | } |
| 528 | |
| 529 | if (((textureFormatInfo.componentType == GL_INT) != |
| 530 | (framebufferFormatInfo.componentType == GL_INT)) || |
| 531 | ((textureFormatInfo.componentType == GL_UNSIGNED_INT) != |
| 532 | (framebufferFormatInfo.componentType == GL_UNSIGNED_INT))) |
| 533 | { |
| 534 | return false; |
| 535 | } |
| 536 | |
| 537 | if ((textureFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 538 | textureFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 539 | textureFormatInfo.componentType == GL_FLOAT) && |
| 540 | !(framebufferFormatInfo.componentType == GL_UNSIGNED_NORMALIZED || |
| 541 | framebufferFormatInfo.componentType == GL_SIGNED_NORMALIZED || |
| 542 | framebufferFormatInfo.componentType == GL_FLOAT)) |
| 543 | { |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | // GLES specification 3.0.3, sec 3.8.5, pg 139-140: |
| 548 | // The effective internal format of the source buffer is determined with the following rules |
| 549 | // applied in order: |
| 550 | // * If the source buffer is a texture or renderbuffer that was created with a sized internal |
| 551 | // format then the effective internal format is the source buffer's sized internal format. |
| 552 | // * If the source buffer is a texture that was created with an unsized base internal format, |
| 553 | // then the effective internal format is the source image array's effective internal |
| 554 | // format, as specified by table 3.12, which is determined from the <format> and <type> |
| 555 | // that were used when the source image array was specified by TexImage*. |
| 556 | // * Otherwise the effective internal format is determined by the row in table 3.17 or 3.18 |
| 557 | // where Destination Internal Format matches internalformat and where the [source channel |
| 558 | // sizes] are consistent with the values of the source buffer's [channel sizes]. Table 3.17 |
| 559 | // is used if the FRAMEBUFFER_ATTACHMENT_ENCODING is LINEAR and table 3.18 is used if the |
| 560 | // FRAMEBUFFER_ATTACHMENT_ENCODING is SRGB. |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 561 | const InternalFormat *sourceEffectiveFormat = nullptr; |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 562 | if (readBufferHandle != 0) |
| 563 | { |
| 564 | // Not the default framebuffer, therefore the read buffer must be a user-created texture or |
| 565 | // renderbuffer |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 566 | if (framebufferFormatInfo.sized) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 567 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 568 | sourceEffectiveFormat = &framebufferFormatInfo; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 569 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 570 | else |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 571 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 572 | // Renderbuffers cannot be created with an unsized internal format, so this must be an |
| 573 | // unsized-format texture. We can use the same table we use when creating textures to |
| 574 | // get its effective sized format. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 575 | sourceEffectiveFormat = |
| 576 | &GetSizedInternalFormatInfo(framebufferFormatInfo.sizedInternalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 577 | } |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 578 | } |
| 579 | else |
| 580 | { |
| 581 | // The effective internal format must be derived from the source framebuffer's channel |
| 582 | // sizes. This is done in GetEffectiveInternalFormat for linear buffers (table 3.17) |
| 583 | if (framebufferFormatInfo.colorEncoding == GL_LINEAR) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 584 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 585 | GLenum effectiveFormat; |
| 586 | if (GetEffectiveInternalFormat(framebufferFormatInfo, textureFormatInfo, |
| 587 | &effectiveFormat)) |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 588 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 589 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(effectiveFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 590 | } |
| 591 | else |
| 592 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 593 | return false; |
| 594 | } |
| 595 | } |
| 596 | else if (framebufferFormatInfo.colorEncoding == GL_SRGB) |
| 597 | { |
| 598 | // SRGB buffers can only be copied to sized format destinations according to table 3.18 |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 599 | if (textureFormatInfo.sized && |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 600 | (framebufferFormatInfo.redBits >= 1 && framebufferFormatInfo.redBits <= 8) && |
| 601 | (framebufferFormatInfo.greenBits >= 1 && framebufferFormatInfo.greenBits <= 8) && |
| 602 | (framebufferFormatInfo.blueBits >= 1 && framebufferFormatInfo.blueBits <= 8) && |
| 603 | (framebufferFormatInfo.alphaBits >= 1 && framebufferFormatInfo.alphaBits <= 8)) |
| 604 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 605 | sourceEffectiveFormat = &GetSizedInternalFormatInfo(GL_SRGB8_ALPHA8); |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 606 | } |
| 607 | else |
| 608 | { |
| 609 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 610 | } |
| 611 | } |
| 612 | else |
| 613 | { |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 614 | UNREACHABLE(); |
| 615 | return false; |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 616 | } |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 619 | if (textureFormatInfo.sized) |
Jamie Madill | 21b786b | 2016-11-01 17:41:31 -0400 | [diff] [blame] | 620 | { |
| 621 | // Section 3.8.5 of the GLES 3.0.3 spec, pg 139, requires that, if the destination format is |
| 622 | // sized, component sizes of the source and destination formats must exactly match if the |
| 623 | // destination format exists. |
| 624 | if (!EqualOrFirstZero(textureFormatInfo.redBits, sourceEffectiveFormat->redBits) || |
| 625 | !EqualOrFirstZero(textureFormatInfo.greenBits, sourceEffectiveFormat->greenBits) || |
| 626 | !EqualOrFirstZero(textureFormatInfo.blueBits, sourceEffectiveFormat->blueBits) || |
| 627 | !EqualOrFirstZero(textureFormatInfo.alphaBits, sourceEffectiveFormat->alphaBits)) |
| 628 | { |
| 629 | return false; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | return true; // A conversion function exists, and no rule in the specification has precluded |
| 634 | // conversion between these formats. |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 635 | } |
| 636 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 637 | bool ValidateES3CopyTexImageParametersBase(ValidationContext *context, |
| 638 | GLenum target, |
| 639 | GLint level, |
| 640 | GLenum internalformat, |
| 641 | bool isSubImage, |
| 642 | GLint xoffset, |
| 643 | GLint yoffset, |
| 644 | GLint zoffset, |
| 645 | GLint x, |
| 646 | GLint y, |
| 647 | GLsizei width, |
| 648 | GLsizei height, |
| 649 | GLint border) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 650 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 651 | Format textureFormat = Format::Invalid(); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 652 | if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 653 | xoffset, yoffset, zoffset, x, y, width, height, border, |
| 654 | &textureFormat)) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 655 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 656 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 657 | } |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 658 | ASSERT(textureFormat.valid() || !isSubImage); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 659 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 660 | const auto &state = context->getGLState(); |
| 661 | gl::Framebuffer *framebuffer = state.getReadFramebuffer(); |
| 662 | GLuint readFramebufferID = framebuffer->id(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 663 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 664 | if (framebuffer->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 665 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 666 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 667 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 668 | } |
| 669 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 670 | if (readFramebufferID != 0 && framebuffer->getSamples(context) != 0) |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 671 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 672 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 673 | return false; |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 674 | } |
| 675 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 676 | const FramebufferAttachment *source = framebuffer->getReadColorbuffer(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 677 | |
| 678 | if (isSubImage) |
| 679 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 680 | if (!IsValidES3CopyTexImageCombination(*textureFormat.info, *source->getFormat().info, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 681 | readFramebufferID)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 682 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 683 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 684 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 685 | } |
| 686 | } |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 687 | else |
| 688 | { |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 689 | // Use format/type from the source FBO. (Might not be perfect for all cases?) |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 690 | const InternalFormat &framebufferFormat = *source->getFormat().info; |
| 691 | const InternalFormat ©Format = GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 692 | if (!IsValidES3CopyTexImageCombination(copyFormat, framebufferFormat, readFramebufferID)) |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 693 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 694 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 695 | return false; |
Shannon Woods | 4d161ba | 2014-03-17 18:13:30 -0400 | [diff] [blame] | 696 | } |
| 697 | } |
| 698 | |
Geoff Lang | 784a8fd | 2013-09-24 12:33:16 -0400 | [diff] [blame] | 699 | // If width or height is zero, it is a no-op. Return false without setting an error. |
| 700 | return (width > 0 && height > 0); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 701 | } |
| 702 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 703 | bool ValidateES3CopyTexImage2DParameters(ValidationContext *context, |
| 704 | GLenum target, |
| 705 | GLint level, |
| 706 | GLenum internalformat, |
| 707 | bool isSubImage, |
| 708 | GLint xoffset, |
| 709 | GLint yoffset, |
| 710 | GLint zoffset, |
| 711 | GLint x, |
| 712 | GLint y, |
| 713 | GLsizei width, |
| 714 | GLsizei height, |
| 715 | GLint border) |
| 716 | { |
| 717 | if (!ValidTexture2DDestinationTarget(context, target)) |
| 718 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 719 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 720 | return false; |
| 721 | } |
| 722 | |
| 723 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 724 | xoffset, yoffset, zoffset, x, y, width, height, |
| 725 | border); |
| 726 | } |
| 727 | |
| 728 | bool ValidateES3CopyTexImage3DParameters(ValidationContext *context, |
| 729 | GLenum target, |
| 730 | GLint level, |
| 731 | GLenum internalformat, |
| 732 | bool isSubImage, |
| 733 | GLint xoffset, |
| 734 | GLint yoffset, |
| 735 | GLint zoffset, |
| 736 | GLint x, |
| 737 | GLint y, |
| 738 | GLsizei width, |
| 739 | GLsizei height, |
| 740 | GLint border) |
| 741 | { |
| 742 | if (!ValidTexture3DDestinationTarget(context, target)) |
| 743 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 744 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 745 | return false; |
| 746 | } |
| 747 | |
| 748 | return ValidateES3CopyTexImageParametersBase(context, target, level, internalformat, isSubImage, |
| 749 | xoffset, yoffset, zoffset, x, y, width, height, |
| 750 | border); |
| 751 | } |
| 752 | |
| 753 | bool ValidateES3TexStorageParametersBase(Context *context, |
| 754 | GLenum target, |
| 755 | GLsizei levels, |
| 756 | GLenum internalformat, |
| 757 | GLsizei width, |
| 758 | GLsizei height, |
| 759 | GLsizei depth) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 760 | { |
| 761 | if (width < 1 || height < 1 || depth < 1 || levels < 1) |
| 762 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 763 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 764 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Geoff Lang | b92c133 | 2015-09-04 12:54:55 -0400 | [diff] [blame] | 767 | GLsizei maxDim = std::max(width, height); |
| 768 | if (target != GL_TEXTURE_2D_ARRAY) |
| 769 | { |
| 770 | maxDim = std::max(maxDim, depth); |
| 771 | } |
| 772 | |
| 773 | if (levels > gl::log2(maxDim) + 1) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 774 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 775 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 776 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 779 | const gl::Caps &caps = context->getCaps(); |
| 780 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 781 | switch (target) |
| 782 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 783 | case GL_TEXTURE_2D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 784 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 785 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 786 | static_cast<GLuint>(height) > caps.max2DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 787 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 788 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 789 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | break; |
| 793 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 794 | case GL_TEXTURE_CUBE_MAP: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 795 | { |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 796 | if (width != height) |
| 797 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 798 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 799 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 800 | } |
| 801 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 802 | if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 803 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 804 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 805 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 806 | } |
| 807 | } |
| 808 | break; |
| 809 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 810 | case GL_TEXTURE_3D: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 811 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 812 | if (static_cast<GLuint>(width) > caps.max3DTextureSize || |
| 813 | static_cast<GLuint>(height) > caps.max3DTextureSize || |
| 814 | static_cast<GLuint>(depth) > caps.max3DTextureSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 815 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 816 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 817 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | break; |
| 821 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 822 | case GL_TEXTURE_2D_ARRAY: |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 823 | { |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 824 | if (static_cast<GLuint>(width) > caps.max2DTextureSize || |
| 825 | static_cast<GLuint>(height) > caps.max2DTextureSize || |
| 826 | static_cast<GLuint>(depth) > caps.maxArrayTextureLayers) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 827 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 828 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 829 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 830 | } |
| 831 | } |
| 832 | break; |
| 833 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 834 | default: |
| 835 | UNREACHABLE(); |
| 836 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 837 | } |
| 838 | |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 839 | gl::Texture *texture = context->getTargetTexture(target); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 840 | if (!texture || texture->id() == 0) |
| 841 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 842 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 843 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 844 | } |
| 845 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 846 | if (texture->getImmutableFormat()) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 847 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 848 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 849 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 850 | } |
| 851 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 852 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 853 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 854 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 855 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 856 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 857 | } |
| 858 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 859 | if (!formatInfo.sized) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 860 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 861 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 862 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | return true; |
| 866 | } |
| 867 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 868 | bool ValidateES3TexStorage2DParameters(Context *context, |
| 869 | GLenum target, |
| 870 | GLsizei levels, |
| 871 | GLenum internalformat, |
| 872 | GLsizei width, |
| 873 | GLsizei height, |
| 874 | GLsizei depth) |
| 875 | { |
| 876 | if (!ValidTexture2DTarget(context, target)) |
| 877 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 878 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 879 | return false; |
| 880 | } |
| 881 | |
| 882 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 883 | height, depth); |
| 884 | } |
| 885 | |
| 886 | bool ValidateES3TexStorage3DParameters(Context *context, |
| 887 | GLenum target, |
| 888 | GLsizei levels, |
| 889 | GLenum internalformat, |
| 890 | GLsizei width, |
| 891 | GLsizei height, |
| 892 | GLsizei depth) |
| 893 | { |
| 894 | if (!ValidTexture3DTarget(context, target)) |
| 895 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 896 | context->handleError(InvalidEnum()); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 897 | return false; |
| 898 | } |
| 899 | |
| 900 | return ValidateES3TexStorageParametersBase(context, target, levels, internalformat, width, |
| 901 | height, depth); |
| 902 | } |
| 903 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 904 | bool ValidateBeginQuery(gl::Context *context, GLenum target, GLuint id) |
| 905 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 906 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 907 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 908 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 909 | return false; |
| 910 | } |
| 911 | |
| 912 | return ValidateBeginQueryBase(context, target, id); |
| 913 | } |
| 914 | |
| 915 | bool ValidateEndQuery(gl::Context *context, GLenum target) |
| 916 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 917 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 918 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 919 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 920 | return false; |
| 921 | } |
| 922 | |
| 923 | return ValidateEndQueryBase(context, target); |
| 924 | } |
| 925 | |
| 926 | bool ValidateGetQueryiv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 927 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 928 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 929 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 930 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 931 | return false; |
| 932 | } |
| 933 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 934 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | bool ValidateGetQueryObjectuiv(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 938 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 939 | if (context->getClientMajorVersion() < 3) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 940 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 941 | context->handleError(InvalidOperation() << "GLES version < 3.0"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 942 | return false; |
| 943 | } |
| 944 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 945 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 946 | } |
| 947 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 948 | bool ValidateFramebufferTextureLayer(Context *context, |
| 949 | GLenum target, |
| 950 | GLenum attachment, |
| 951 | GLuint texture, |
| 952 | GLint level, |
| 953 | GLint layer) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 954 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 955 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 956 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 957 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 958 | return false; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 959 | } |
| 960 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 961 | if (layer < 0) |
| 962 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 963 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 964 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
| 968 | { |
| 969 | return false; |
| 970 | } |
| 971 | |
| 972 | const gl::Caps &caps = context->getCaps(); |
| 973 | if (texture != 0) |
| 974 | { |
| 975 | gl::Texture *tex = context->getTexture(texture); |
| 976 | ASSERT(tex); |
| 977 | |
| 978 | switch (tex->getTarget()) |
| 979 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 980 | case GL_TEXTURE_2D_ARRAY: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 981 | { |
| 982 | if (level > gl::log2(caps.max2DTextureSize)) |
| 983 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 984 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 985 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers) |
| 989 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 990 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 991 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 992 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 993 | } |
| 994 | break; |
| 995 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 996 | case GL_TEXTURE_3D: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 997 | { |
| 998 | if (level > gl::log2(caps.max3DTextureSize)) |
| 999 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1000 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1001 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | if (static_cast<GLuint>(layer) >= caps.max3DTextureSize) |
| 1005 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1006 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1007 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1008 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1009 | } |
| 1010 | break; |
| 1011 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1012 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1013 | context->handleError(InvalidOperation()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1014 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1015 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1016 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1017 | const auto &format = tex->getFormat(tex->getTarget(), level); |
| 1018 | if (format.info->compressed) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1019 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1020 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 1021 | return false; |
| 1022 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | return true; |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1028 | bool ValidateInvalidateFramebuffer(Context *context, |
| 1029 | GLenum target, |
| 1030 | GLsizei numAttachments, |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1031 | const GLenum *attachments) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1032 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1033 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1034 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1035 | context->handleError(InvalidOperation() << "Operation only supported on ES 3.0 and above"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 1036 | return false; |
| 1037 | } |
| 1038 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1039 | bool defaultFramebuffer = false; |
| 1040 | |
| 1041 | switch (target) |
| 1042 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1043 | case GL_DRAW_FRAMEBUFFER: |
| 1044 | case GL_FRAMEBUFFER: |
| 1045 | defaultFramebuffer = context->getGLState().getDrawFramebuffer()->id() == 0; |
| 1046 | break; |
| 1047 | case GL_READ_FRAMEBUFFER: |
| 1048 | defaultFramebuffer = context->getGLState().getReadFramebuffer()->id() == 0; |
| 1049 | break; |
| 1050 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1051 | context->handleError(InvalidEnum() << "Invalid framebuffer target"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1052 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1053 | } |
| 1054 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1055 | return ValidateDiscardFramebufferBase(context, target, numAttachments, attachments, |
| 1056 | defaultFramebuffer); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1057 | } |
| 1058 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1059 | bool ValidateClearBuffer(ValidationContext *context) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1060 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1061 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1062 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1063 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1064 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1065 | } |
| 1066 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1067 | if (context->getGLState().getDrawFramebuffer()->checkStatus(context) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1068 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1069 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1070 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | return true; |
| 1074 | } |
| 1075 | |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1076 | bool ValidateDrawRangeElements(Context *context, |
| 1077 | GLenum mode, |
| 1078 | GLuint start, |
| 1079 | GLuint end, |
| 1080 | GLsizei count, |
| 1081 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1082 | const void *indices) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1083 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1084 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1085 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1086 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1087 | return false; |
| 1088 | } |
| 1089 | |
| 1090 | if (end < start) |
| 1091 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1092 | context->handleError(InvalidValue() << "end < start"); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1093 | return false; |
| 1094 | } |
| 1095 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1096 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, 0)) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1097 | { |
| 1098 | return false; |
| 1099 | } |
| 1100 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1101 | // Use the parameter buffer to retrieve and cache the index range. |
| 1102 | const auto ¶ms = context->getParams<HasIndexRange>(); |
| 1103 | const auto &indexRangeOpt = params.getIndexRange(); |
| 1104 | if (!indexRangeOpt.valid()) |
| 1105 | { |
| 1106 | // Unexpected error. |
| 1107 | return false; |
| 1108 | } |
| 1109 | |
| 1110 | if (indexRangeOpt.value().end > end || indexRangeOpt.value().start < start) |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1111 | { |
| 1112 | // GL spec says that behavior in this case is undefined - generating an error is fine. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1113 | context->handleError(InvalidOperation() << "Indices are out of the start, end range."); |
Olli Etuaho | 71dfb36 | 2016-03-10 14:04:27 +0200 | [diff] [blame] | 1114 | return false; |
| 1115 | } |
| 1116 | return true; |
| 1117 | } |
| 1118 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1119 | bool ValidateGetUniformuiv(Context *context, GLuint program, GLint location, GLuint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1120 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1121 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1122 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1123 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1124 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1125 | } |
| 1126 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 1127 | return ValidateGetUniformBase(context, program, location); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 1128 | } |
| 1129 | |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1130 | bool ValidateReadBuffer(Context *context, GLenum src) |
| 1131 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1132 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1133 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1134 | context->handleError(InvalidOperation()); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1135 | return false; |
| 1136 | } |
| 1137 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1138 | const Framebuffer *readFBO = context->getGLState().getReadFramebuffer(); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1139 | |
| 1140 | if (readFBO == nullptr) |
| 1141 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1142 | context->handleError(InvalidOperation() << "No active read framebuffer."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1143 | return false; |
| 1144 | } |
| 1145 | |
| 1146 | if (src == GL_NONE) |
| 1147 | { |
| 1148 | return true; |
| 1149 | } |
| 1150 | |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 1151 | if (src != GL_BACK && (src < GL_COLOR_ATTACHMENT0 || src > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1152 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1153 | context->handleError(InvalidEnum() << "Unknown enum for 'src' in ReadBuffer"); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1154 | return false; |
| 1155 | } |
| 1156 | |
| 1157 | if (readFBO->id() == 0) |
| 1158 | { |
| 1159 | if (src != GL_BACK) |
| 1160 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1161 | context->handleError( |
| 1162 | InvalidOperation() |
| 1163 | << "'src' must be GL_NONE or GL_BACK when reading from the default framebuffer."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1164 | return false; |
| 1165 | } |
| 1166 | } |
| 1167 | else |
| 1168 | { |
| 1169 | GLuint drawBuffer = static_cast<GLuint>(src - GL_COLOR_ATTACHMENT0); |
| 1170 | |
| 1171 | if (drawBuffer >= context->getCaps().maxDrawBuffers) |
| 1172 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1173 | context->handleError(InvalidOperation() << "'src' is greater than MAX_DRAW_BUFFERS."); |
Jamie Madill | b885e57 | 2015-02-03 16:16:04 -0500 | [diff] [blame] | 1174 | return false; |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | return true; |
| 1179 | } |
| 1180 | |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1181 | bool ValidateCompressedTexImage3D(Context *context, |
| 1182 | GLenum target, |
| 1183 | GLint level, |
| 1184 | GLenum internalformat, |
| 1185 | GLsizei width, |
| 1186 | GLsizei height, |
| 1187 | GLsizei depth, |
| 1188 | GLint border, |
| 1189 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1190 | const void *data) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1191 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1192 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1193 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1194 | context->handleError(InvalidOperation()); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1195 | return false; |
| 1196 | } |
| 1197 | |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1198 | if (!ValidTextureTarget(context, target)) |
| 1199 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1200 | context->handleError(InvalidEnum()); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1201 | return false; |
| 1202 | } |
| 1203 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1204 | // Validate image size |
| 1205 | if (!ValidImageSizeParameters(context, target, level, width, height, depth, false)) |
| 1206 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1207 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1208 | return false; |
| 1209 | } |
| 1210 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1211 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1212 | if (!formatInfo.compressed) |
| 1213 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1214 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1215 | return false; |
| 1216 | } |
| 1217 | |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1218 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1219 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1220 | if (blockSizeOrErr.isError()) |
| 1221 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1222 | context->handleError(InvalidValue()); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1223 | return false; |
| 1224 | } |
| 1225 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1226 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1227 | context->handleError(InvalidValue()); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1228 | return false; |
| 1229 | } |
| 1230 | |
| 1231 | // 3D texture target validation |
| 1232 | if (target != GL_TEXTURE_3D && target != GL_TEXTURE_2D_ARRAY) |
| 1233 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1234 | context->handleError(InvalidEnum() << "Must specify a valid 3D texture destination target"); |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1235 | return false; |
| 1236 | } |
| 1237 | |
| 1238 | // validateES3TexImageFormat sets the error code if there is an error |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1239 | if (!ValidateES3TexImage3DParameters(context, target, level, internalformat, true, false, 0, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1240 | 0, width, height, depth, border, GL_NONE, GL_NONE, -1, |
| 1241 | data)) |
Jamie Madill | 86af3d2 | 2015-07-21 15:14:07 -0400 | [diff] [blame] | 1242 | { |
| 1243 | return false; |
| 1244 | } |
| 1245 | |
| 1246 | return true; |
| 1247 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1248 | |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1249 | bool ValidateCompressedTexImage3DRobustANGLE(Context *context, |
| 1250 | GLenum target, |
| 1251 | GLint level, |
| 1252 | GLenum internalformat, |
| 1253 | GLsizei width, |
| 1254 | GLsizei height, |
| 1255 | GLsizei depth, |
| 1256 | GLint border, |
| 1257 | GLsizei imageSize, |
| 1258 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1259 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1260 | { |
| 1261 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 1262 | { |
| 1263 | return false; |
| 1264 | } |
| 1265 | |
| 1266 | return ValidateCompressedTexImage3D(context, target, level, internalformat, width, height, |
| 1267 | depth, border, imageSize, data); |
| 1268 | } |
| 1269 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1270 | bool ValidateBindVertexArray(Context *context, GLuint array) |
| 1271 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1272 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1273 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1274 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1275 | return false; |
| 1276 | } |
| 1277 | |
| 1278 | return ValidateBindVertexArrayBase(context, array); |
| 1279 | } |
| 1280 | |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1281 | bool ValidateIsVertexArray(Context *context) |
| 1282 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1283 | if (context->getClientMajorVersion() < 3) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1284 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1285 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 1286 | return false; |
| 1287 | } |
| 1288 | |
| 1289 | return true; |
| 1290 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1291 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1292 | static bool ValidateBindBufferCommon(Context *context, |
| 1293 | GLenum target, |
| 1294 | GLuint index, |
| 1295 | GLuint buffer, |
| 1296 | GLintptr offset, |
| 1297 | GLsizeiptr size) |
| 1298 | { |
| 1299 | if (context->getClientMajorVersion() < 3) |
| 1300 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1301 | context->handleError(InvalidOperation()); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1302 | return false; |
| 1303 | } |
| 1304 | |
| 1305 | if (buffer != 0 && offset < 0) |
| 1306 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1307 | context->handleError(InvalidValue() << "buffer is non-zero and offset is negative."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1308 | return false; |
| 1309 | } |
| 1310 | |
| 1311 | if (!context->getGLState().isBindGeneratesResourceEnabled() && |
| 1312 | !context->isBufferGenerated(buffer)) |
| 1313 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1314 | context->handleError(InvalidOperation() << "Buffer was not generated."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1315 | return false; |
| 1316 | } |
| 1317 | |
| 1318 | const Caps &caps = context->getCaps(); |
| 1319 | switch (target) |
| 1320 | { |
| 1321 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 1322 | { |
| 1323 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 1324 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1325 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1326 | "number of TRANSFORM_FEEDBACK_BUFFER " |
| 1327 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1328 | return false; |
| 1329 | } |
| 1330 | if (buffer != 0 && ((offset % 4) != 0 || (size % 4) != 0)) |
| 1331 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1332 | context->handleError(InvalidValue() << "offset and size must be multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1333 | return false; |
| 1334 | } |
| 1335 | |
| 1336 | TransformFeedback *curTransformFeedback = |
| 1337 | context->getGLState().getCurrentTransformFeedback(); |
| 1338 | if (curTransformFeedback && curTransformFeedback->isActive()) |
| 1339 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1340 | context->handleError(InvalidOperation() |
| 1341 | << "target is TRANSFORM_FEEDBACK_BUFFER and transform " |
| 1342 | "feedback is currently active."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1343 | return false; |
| 1344 | } |
| 1345 | break; |
| 1346 | } |
| 1347 | case GL_UNIFORM_BUFFER: |
| 1348 | { |
| 1349 | if (index >= caps.maxUniformBufferBindings) |
| 1350 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1351 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1352 | "number of UNIFORM_BUFFER indexed " |
| 1353 | "binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1354 | return false; |
| 1355 | } |
| 1356 | |
| 1357 | if (buffer != 0 && (offset % caps.uniformBufferOffsetAlignment) != 0) |
| 1358 | { |
| 1359 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1360 | InvalidValue() |
| 1361 | << "offset must be multiple of value of UNIFORM_BUFFER_OFFSET_ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1362 | return false; |
| 1363 | } |
| 1364 | break; |
| 1365 | } |
| 1366 | case GL_ATOMIC_COUNTER_BUFFER: |
| 1367 | { |
| 1368 | if (context->getClientVersion() < ES_3_1) |
| 1369 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1370 | context->handleError(InvalidEnum() |
| 1371 | << "ATOMIC_COUNTER_BUFFER is not supported before GLES 3.1"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1372 | return false; |
| 1373 | } |
| 1374 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 1375 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1376 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1377 | "number of ATOMIC_COUNTER_BUFFER " |
| 1378 | "indexed binding points."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1379 | return false; |
| 1380 | } |
| 1381 | if (buffer != 0 && (offset % 4) != 0) |
| 1382 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1383 | context->handleError(InvalidValue() << "offset must be a multiple of 4."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1384 | return false; |
| 1385 | } |
| 1386 | break; |
| 1387 | } |
| 1388 | case GL_SHADER_STORAGE_BUFFER: |
| 1389 | { |
| 1390 | if (context->getClientVersion() < ES_3_1) |
| 1391 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1392 | context->handleError(InvalidEnum() |
| 1393 | << "SHADER_STORAGE_BUFFER is not supported in GLES3."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1394 | return false; |
| 1395 | } |
| 1396 | if (index >= caps.maxShaderStorageBufferBindings) |
| 1397 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1398 | context->handleError(InvalidValue() << "index is greater than or equal to the " |
| 1399 | "number of SHADER_STORAGE_BUFFER " |
| 1400 | "indexed binding points."); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1401 | return false; |
| 1402 | } |
| 1403 | if (buffer != 0 && (offset % caps.shaderStorageBufferOffsetAlignment) != 0) |
| 1404 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1405 | context->handleError(InvalidValue() << "offset must be multiple of value of " |
| 1406 | "SHADER_STORAGE_BUFFER_OFFSET_" |
| 1407 | "ALIGNMENT."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1408 | return false; |
| 1409 | } |
| 1410 | break; |
| 1411 | } |
| 1412 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1413 | context->handleError(InvalidEnum() << "the target is not supported."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1414 | return false; |
| 1415 | } |
| 1416 | |
| 1417 | return true; |
| 1418 | } |
| 1419 | |
| 1420 | bool ValidateBindBufferBase(Context *context, GLenum target, GLuint index, GLuint buffer) |
| 1421 | { |
| 1422 | return ValidateBindBufferCommon(context, target, index, buffer, 0, 0); |
| 1423 | } |
| 1424 | |
| 1425 | bool ValidateBindBufferRange(Context *context, |
| 1426 | GLenum target, |
| 1427 | GLuint index, |
| 1428 | GLuint buffer, |
| 1429 | GLintptr offset, |
| 1430 | GLsizeiptr size) |
| 1431 | { |
| 1432 | if (buffer != 0 && size <= 0) |
| 1433 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1434 | context->handleError(InvalidValue() |
| 1435 | << "buffer is non-zero and size is less than or equal to zero."); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1436 | return false; |
| 1437 | } |
| 1438 | return ValidateBindBufferCommon(context, target, index, buffer, offset, size); |
| 1439 | } |
| 1440 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1441 | bool ValidateProgramBinary(Context *context, |
| 1442 | GLuint program, |
| 1443 | GLenum binaryFormat, |
| 1444 | const void *binary, |
| 1445 | GLint length) |
| 1446 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1447 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1448 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1449 | context->handleError(InvalidOperation()); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1450 | return false; |
| 1451 | } |
| 1452 | |
| 1453 | return ValidateProgramBinaryBase(context, program, binaryFormat, binary, length); |
| 1454 | } |
| 1455 | |
| 1456 | bool ValidateGetProgramBinary(Context *context, |
| 1457 | GLuint program, |
| 1458 | GLsizei bufSize, |
| 1459 | GLsizei *length, |
| 1460 | GLenum *binaryFormat, |
| 1461 | void *binary) |
| 1462 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1463 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1464 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1465 | context->handleError(InvalidOperation()); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1466 | return false; |
| 1467 | } |
| 1468 | |
| 1469 | return ValidateGetProgramBinaryBase(context, program, bufSize, length, binaryFormat, binary); |
| 1470 | } |
| 1471 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1472 | bool ValidateProgramParameteri(Context *context, GLuint program, GLenum pname, GLint value) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1473 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1474 | if (context->getClientMajorVersion() < 3) |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1475 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1476 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1477 | return false; |
| 1478 | } |
| 1479 | |
| 1480 | if (GetValidProgram(context, program) == nullptr) |
| 1481 | { |
| 1482 | return false; |
| 1483 | } |
| 1484 | |
| 1485 | switch (pname) |
| 1486 | { |
| 1487 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1488 | if (value != GL_FALSE && value != GL_TRUE) |
| 1489 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1490 | context->handleError(InvalidValue() |
| 1491 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 1492 | return false; |
| 1493 | } |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1494 | break; |
| 1495 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1496 | case GL_PROGRAM_SEPARABLE: |
| 1497 | if (context->getClientVersion() < ES_3_1) |
| 1498 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1499 | context->handleError(InvalidEnum() |
| 1500 | << "PROGRAM_SEPARABLE is not supported before GLES 3.1"); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1501 | return false; |
| 1502 | } |
| 1503 | |
| 1504 | if (value != GL_FALSE && value != GL_TRUE) |
| 1505 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1506 | context->handleError(InvalidValue() |
| 1507 | << "Invalid value, expected GL_FALSE or GL_TRUE: " << value); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 1508 | return false; |
| 1509 | } |
| 1510 | break; |
| 1511 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1512 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1513 | context->handleError(InvalidEnum() |
| 1514 | << "Invalid pname: 0x" << std::hex << std::uppercase << pname); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 1515 | return false; |
| 1516 | } |
| 1517 | |
| 1518 | return true; |
| 1519 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1520 | |
| 1521 | bool ValidateBlitFramebuffer(Context *context, |
| 1522 | GLint srcX0, |
| 1523 | GLint srcY0, |
| 1524 | GLint srcX1, |
| 1525 | GLint srcY1, |
| 1526 | GLint dstX0, |
| 1527 | GLint dstY0, |
| 1528 | GLint dstX1, |
| 1529 | GLint dstY1, |
| 1530 | GLbitfield mask, |
| 1531 | GLenum filter) |
| 1532 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1533 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1534 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1535 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1536 | return false; |
| 1537 | } |
| 1538 | |
| 1539 | return ValidateBlitFramebufferParameters(context, srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, |
| 1540 | dstX1, dstY1, mask, filter); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1541 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1542 | |
| 1543 | bool ValidateClearBufferiv(ValidationContext *context, |
| 1544 | GLenum buffer, |
| 1545 | GLint drawbuffer, |
| 1546 | const GLint *value) |
| 1547 | { |
| 1548 | switch (buffer) |
| 1549 | { |
| 1550 | case GL_COLOR: |
| 1551 | if (drawbuffer < 0 || |
| 1552 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1553 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1554 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1557 | if (context->getExtensions().webglCompatibility) |
| 1558 | { |
| 1559 | constexpr GLenum validComponentTypes[] = {GL_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1560 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1561 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1562 | { |
| 1563 | return false; |
| 1564 | } |
| 1565 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1566 | break; |
| 1567 | |
| 1568 | case GL_STENCIL: |
| 1569 | if (drawbuffer != 0) |
| 1570 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1571 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1572 | return false; |
| 1573 | } |
| 1574 | break; |
| 1575 | |
| 1576 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1577 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1578 | return false; |
| 1579 | } |
| 1580 | |
| 1581 | return ValidateClearBuffer(context); |
| 1582 | } |
| 1583 | |
| 1584 | bool ValidateClearBufferuiv(ValidationContext *context, |
| 1585 | GLenum buffer, |
| 1586 | GLint drawbuffer, |
| 1587 | const GLuint *value) |
| 1588 | { |
| 1589 | switch (buffer) |
| 1590 | { |
| 1591 | case GL_COLOR: |
| 1592 | if (drawbuffer < 0 || |
| 1593 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1594 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1595 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1596 | return false; |
| 1597 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1598 | if (context->getExtensions().webglCompatibility) |
| 1599 | { |
| 1600 | constexpr GLenum validComponentTypes[] = {GL_UNSIGNED_INT}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1601 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1602 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1603 | { |
| 1604 | return false; |
| 1605 | } |
| 1606 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1607 | break; |
| 1608 | |
| 1609 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1610 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1611 | return false; |
| 1612 | } |
| 1613 | |
| 1614 | return ValidateClearBuffer(context); |
| 1615 | } |
| 1616 | |
| 1617 | bool ValidateClearBufferfv(ValidationContext *context, |
| 1618 | GLenum buffer, |
| 1619 | GLint drawbuffer, |
| 1620 | const GLfloat *value) |
| 1621 | { |
| 1622 | switch (buffer) |
| 1623 | { |
| 1624 | case GL_COLOR: |
| 1625 | if (drawbuffer < 0 || |
| 1626 | static_cast<GLuint>(drawbuffer) >= context->getCaps().maxDrawBuffers) |
| 1627 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1628 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1629 | return false; |
| 1630 | } |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1631 | if (context->getExtensions().webglCompatibility) |
| 1632 | { |
| 1633 | constexpr GLenum validComponentTypes[] = {GL_FLOAT, GL_UNSIGNED_NORMALIZED, |
| 1634 | GL_SIGNED_NORMALIZED}; |
Geoff Lang | 0fb0864 | 2017-07-04 15:07:23 -0400 | [diff] [blame] | 1635 | if (!ValidateWebGLFramebufferAttachmentClearType( |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 1636 | context, drawbuffer, validComponentTypes, ArraySize(validComponentTypes))) |
| 1637 | { |
| 1638 | return false; |
| 1639 | } |
| 1640 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1641 | break; |
| 1642 | |
| 1643 | case GL_DEPTH: |
| 1644 | if (drawbuffer != 0) |
| 1645 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1646 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1647 | return false; |
| 1648 | } |
| 1649 | break; |
| 1650 | |
| 1651 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1652 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1653 | return false; |
| 1654 | } |
| 1655 | |
| 1656 | return ValidateClearBuffer(context); |
| 1657 | } |
| 1658 | |
| 1659 | bool ValidateClearBufferfi(ValidationContext *context, |
| 1660 | GLenum buffer, |
| 1661 | GLint drawbuffer, |
| 1662 | GLfloat depth, |
| 1663 | GLint stencil) |
| 1664 | { |
| 1665 | switch (buffer) |
| 1666 | { |
| 1667 | case GL_DEPTH_STENCIL: |
| 1668 | if (drawbuffer != 0) |
| 1669 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1670 | context->handleError(InvalidValue()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1671 | return false; |
| 1672 | } |
| 1673 | break; |
| 1674 | |
| 1675 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1676 | context->handleError(InvalidEnum()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1677 | return false; |
| 1678 | } |
| 1679 | |
| 1680 | return ValidateClearBuffer(context); |
| 1681 | } |
| 1682 | |
| 1683 | bool ValidateDrawBuffers(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 1684 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1685 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1686 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1687 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1688 | return false; |
| 1689 | } |
| 1690 | |
| 1691 | return ValidateDrawBuffersBase(context, n, bufs); |
| 1692 | } |
| 1693 | |
| 1694 | bool ValidateCopyTexSubImage3D(Context *context, |
| 1695 | GLenum target, |
| 1696 | GLint level, |
| 1697 | GLint xoffset, |
| 1698 | GLint yoffset, |
| 1699 | GLint zoffset, |
| 1700 | GLint x, |
| 1701 | GLint y, |
| 1702 | GLsizei width, |
| 1703 | GLsizei height) |
| 1704 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1705 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1706 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1707 | context->handleError(InvalidOperation()); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1708 | return false; |
| 1709 | } |
| 1710 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1711 | return ValidateES3CopyTexImage3DParameters(context, target, level, GL_NONE, true, xoffset, |
| 1712 | yoffset, zoffset, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1713 | } |
| 1714 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1715 | bool ValidateTexImage3D(Context *context, |
| 1716 | GLenum target, |
| 1717 | GLint level, |
| 1718 | GLint internalformat, |
| 1719 | GLsizei width, |
| 1720 | GLsizei height, |
| 1721 | GLsizei depth, |
| 1722 | GLint border, |
| 1723 | GLenum format, |
| 1724 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1725 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1726 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1727 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1728 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1729 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1730 | return false; |
| 1731 | } |
| 1732 | |
| 1733 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1734 | 0, 0, width, height, depth, border, format, type, -1, |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1735 | pixels); |
| 1736 | } |
| 1737 | |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1738 | bool ValidateTexImage3DRobustANGLE(Context *context, |
| 1739 | GLenum target, |
| 1740 | GLint level, |
| 1741 | GLint internalformat, |
| 1742 | GLsizei width, |
| 1743 | GLsizei height, |
| 1744 | GLsizei depth, |
| 1745 | GLint border, |
| 1746 | GLenum format, |
| 1747 | GLenum type, |
| 1748 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1749 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1750 | { |
| 1751 | if (context->getClientMajorVersion() < 3) |
| 1752 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1753 | context->handleError(InvalidOperation()); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | |
| 1757 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1758 | { |
| 1759 | return false; |
| 1760 | } |
| 1761 | |
| 1762 | return ValidateES3TexImage3DParameters(context, target, level, internalformat, false, false, 0, |
| 1763 | 0, 0, width, height, depth, border, format, type, |
| 1764 | bufSize, pixels); |
| 1765 | } |
| 1766 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1767 | bool ValidateTexSubImage3D(Context *context, |
| 1768 | GLenum target, |
| 1769 | GLint level, |
| 1770 | GLint xoffset, |
| 1771 | GLint yoffset, |
| 1772 | GLint zoffset, |
| 1773 | GLsizei width, |
| 1774 | GLsizei height, |
| 1775 | GLsizei depth, |
| 1776 | GLenum format, |
| 1777 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1778 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1779 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1780 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1781 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1782 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1787 | yoffset, zoffset, width, height, depth, 0, format, type, |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1788 | -1, pixels); |
| 1789 | } |
| 1790 | |
| 1791 | bool ValidateTexSubImage3DRobustANGLE(Context *context, |
| 1792 | GLenum target, |
| 1793 | GLint level, |
| 1794 | GLint xoffset, |
| 1795 | GLint yoffset, |
| 1796 | GLint zoffset, |
| 1797 | GLsizei width, |
| 1798 | GLsizei height, |
| 1799 | GLsizei depth, |
| 1800 | GLenum format, |
| 1801 | GLenum type, |
| 1802 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1803 | const void *pixels) |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1804 | { |
| 1805 | if (context->getClientMajorVersion() < 3) |
| 1806 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1807 | context->handleError(InvalidOperation()); |
Geoff Lang | c52f6f1 | 2016-10-14 10:18:00 -0400 | [diff] [blame] | 1808 | return false; |
| 1809 | } |
| 1810 | |
| 1811 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1812 | { |
| 1813 | return false; |
| 1814 | } |
| 1815 | |
| 1816 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, false, true, xoffset, |
| 1817 | yoffset, zoffset, width, height, depth, 0, format, type, |
| 1818 | bufSize, pixels); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | bool ValidateCompressedTexSubImage3D(Context *context, |
| 1822 | GLenum target, |
| 1823 | GLint level, |
| 1824 | GLint xoffset, |
| 1825 | GLint yoffset, |
| 1826 | GLint zoffset, |
| 1827 | GLsizei width, |
| 1828 | GLsizei height, |
| 1829 | GLsizei depth, |
| 1830 | GLenum format, |
| 1831 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1832 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1833 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1834 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1835 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1836 | context->handleError(InvalidOperation()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1837 | return false; |
| 1838 | } |
| 1839 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1840 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(format); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 1841 | if (!formatInfo.compressed) |
| 1842 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1843 | context->handleError(InvalidEnum() << "Not a valid compressed texture format"); |
Geoff Lang | c5508d6 | 2017-02-10 14:58:38 -0500 | [diff] [blame] | 1844 | return false; |
| 1845 | } |
| 1846 | |
Jamie Madill | 513558d | 2016-06-02 13:04:11 -0400 | [diff] [blame] | 1847 | auto blockSizeOrErr = |
Jamie Madill | 4b4cdff | 2016-06-06 13:53:38 -0700 | [diff] [blame] | 1848 | formatInfo.computeCompressedImageSize(GL_UNSIGNED_BYTE, gl::Extents(width, height, depth)); |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1849 | if (blockSizeOrErr.isError()) |
| 1850 | { |
| 1851 | context->handleError(blockSizeOrErr.getError()); |
| 1852 | return false; |
| 1853 | } |
| 1854 | if (imageSize < 0 || static_cast<GLuint>(imageSize) != blockSizeOrErr.getResult()) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1855 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1856 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1857 | return false; |
| 1858 | } |
| 1859 | |
| 1860 | if (!data) |
| 1861 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1862 | context->handleError(InvalidValue()); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1863 | return false; |
| 1864 | } |
| 1865 | |
| 1866 | return ValidateES3TexImage3DParameters(context, target, level, GL_NONE, true, true, 0, 0, 0, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 1867 | width, height, depth, 0, format, GL_NONE, -1, data); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1868 | } |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1869 | bool ValidateCompressedTexSubImage3DRobustANGLE(Context *context, |
| 1870 | GLenum target, |
| 1871 | GLint level, |
| 1872 | GLint xoffset, |
| 1873 | GLint yoffset, |
| 1874 | GLint zoffset, |
| 1875 | GLsizei width, |
| 1876 | GLsizei height, |
| 1877 | GLsizei depth, |
| 1878 | GLenum format, |
| 1879 | GLsizei imageSize, |
| 1880 | GLsizei dataSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1881 | const void *data) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 1882 | { |
| 1883 | if (!ValidateRobustCompressedTexImageBase(context, imageSize, dataSize)) |
| 1884 | { |
| 1885 | return false; |
| 1886 | } |
| 1887 | |
| 1888 | return ValidateCompressedTexSubImage3D(context, target, level, xoffset, yoffset, zoffset, width, |
| 1889 | height, depth, format, imageSize, data); |
| 1890 | } |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 1891 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1892 | bool ValidateGenQueries(Context *context, GLint n, GLuint *) |
| 1893 | { |
| 1894 | return ValidateGenOrDeleteES3(context, n); |
| 1895 | } |
| 1896 | |
| 1897 | bool ValidateDeleteQueries(Context *context, GLint n, const GLuint *) |
| 1898 | { |
| 1899 | return ValidateGenOrDeleteES3(context, n); |
| 1900 | } |
| 1901 | |
| 1902 | bool ValidateGenSamplers(Context *context, GLint count, GLuint *) |
| 1903 | { |
| 1904 | return ValidateGenOrDeleteCountES3(context, count); |
| 1905 | } |
| 1906 | |
| 1907 | bool ValidateDeleteSamplers(Context *context, GLint count, const GLuint *) |
| 1908 | { |
| 1909 | return ValidateGenOrDeleteCountES3(context, count); |
| 1910 | } |
| 1911 | |
| 1912 | bool ValidateGenTransformFeedbacks(Context *context, GLint n, GLuint *) |
| 1913 | { |
| 1914 | return ValidateGenOrDeleteES3(context, n); |
| 1915 | } |
| 1916 | |
| 1917 | bool ValidateDeleteTransformFeedbacks(Context *context, GLint n, const GLuint *ids) |
| 1918 | { |
| 1919 | if (!ValidateGenOrDeleteES3(context, n)) |
| 1920 | { |
| 1921 | return false; |
| 1922 | } |
| 1923 | for (GLint i = 0; i < n; ++i) |
| 1924 | { |
| 1925 | auto *transformFeedback = context->getTransformFeedback(ids[i]); |
| 1926 | if (transformFeedback != nullptr && transformFeedback->isActive()) |
| 1927 | { |
| 1928 | // ES 3.0.4 section 2.15.1 page 86 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1929 | context->handleError(InvalidOperation() |
| 1930 | << "Attempt to delete active transform feedback."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1931 | return false; |
| 1932 | } |
| 1933 | } |
| 1934 | return true; |
| 1935 | } |
| 1936 | |
| 1937 | bool ValidateGenVertexArrays(Context *context, GLint n, GLuint *) |
| 1938 | { |
| 1939 | return ValidateGenOrDeleteES3(context, n); |
| 1940 | } |
| 1941 | |
| 1942 | bool ValidateDeleteVertexArrays(Context *context, GLint n, const GLuint *) |
| 1943 | { |
| 1944 | return ValidateGenOrDeleteES3(context, n); |
| 1945 | } |
| 1946 | |
| 1947 | bool ValidateGenOrDeleteES3(Context *context, GLint n) |
| 1948 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1949 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1950 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1951 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1952 | return false; |
| 1953 | } |
| 1954 | return ValidateGenOrDelete(context, n); |
| 1955 | } |
| 1956 | |
| 1957 | bool ValidateGenOrDeleteCountES3(Context *context, GLint count) |
| 1958 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1959 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1960 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1961 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1962 | return false; |
| 1963 | } |
| 1964 | if (count < 0) |
| 1965 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1966 | context->handleError(InvalidValue() << "count < 0"); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1967 | return false; |
| 1968 | } |
| 1969 | return true; |
| 1970 | } |
| 1971 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1972 | bool ValidateBeginTransformFeedback(Context *context, GLenum primitiveMode) |
| 1973 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1974 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1975 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1976 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1977 | return false; |
| 1978 | } |
| 1979 | switch (primitiveMode) |
| 1980 | { |
| 1981 | case GL_TRIANGLES: |
| 1982 | case GL_LINES: |
| 1983 | case GL_POINTS: |
| 1984 | break; |
| 1985 | |
| 1986 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1987 | context->handleError(InvalidEnum() << "Invalid primitive mode."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1988 | return false; |
| 1989 | } |
| 1990 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1991 | TransformFeedback *transformFeedback = context->getGLState().getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1992 | ASSERT(transformFeedback != nullptr); |
| 1993 | |
| 1994 | if (transformFeedback->isActive()) |
| 1995 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1996 | context->handleError(InvalidOperation() << "Transform feedback is already active."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 1997 | return false; |
| 1998 | } |
| 1999 | return true; |
| 2000 | } |
| 2001 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2002 | bool ValidateGetBufferPointerv(Context *context, GLenum target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2003 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2004 | return ValidateGetBufferPointervBase(context, target, pname, nullptr, params); |
| 2005 | } |
| 2006 | |
| 2007 | bool ValidateGetBufferPointervRobustANGLE(Context *context, |
| 2008 | GLenum target, |
| 2009 | GLenum pname, |
| 2010 | GLsizei bufSize, |
| 2011 | GLsizei *length, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2012 | void **params) |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2013 | { |
| 2014 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2015 | { |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2016 | return false; |
| 2017 | } |
| 2018 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 2019 | if (!ValidateGetBufferPointervBase(context, target, pname, length, params)) |
| 2020 | { |
| 2021 | return false; |
| 2022 | } |
| 2023 | |
| 2024 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2025 | { |
| 2026 | return false; |
| 2027 | } |
| 2028 | |
| 2029 | return true; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | bool ValidateUnmapBuffer(Context *context, GLenum target) |
| 2033 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2034 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2035 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2036 | context->handleError(InvalidOperation()); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2037 | return false; |
| 2038 | } |
| 2039 | |
| 2040 | return ValidateUnmapBufferBase(context, target); |
| 2041 | } |
| 2042 | |
| 2043 | bool ValidateMapBufferRange(Context *context, |
| 2044 | GLenum target, |
| 2045 | GLintptr offset, |
| 2046 | GLsizeiptr length, |
| 2047 | GLbitfield access) |
| 2048 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2049 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2050 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2051 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2052 | return false; |
| 2053 | } |
| 2054 | |
| 2055 | return ValidateMapBufferRangeBase(context, target, offset, length, access); |
| 2056 | } |
| 2057 | |
| 2058 | bool ValidateFlushMappedBufferRange(Context *context, |
| 2059 | GLenum target, |
| 2060 | GLintptr offset, |
| 2061 | GLsizeiptr length) |
| 2062 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2063 | if (context->getClientMajorVersion() < 3) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2064 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2065 | context->handleError(InvalidOperation() << "Context does not support GLES3."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 2066 | return false; |
| 2067 | } |
| 2068 | |
| 2069 | return ValidateFlushMappedBufferRangeBase(context, target, offset, length); |
| 2070 | } |
| 2071 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2072 | bool ValidateIndexedStateQuery(ValidationContext *context, |
| 2073 | GLenum pname, |
| 2074 | GLuint index, |
| 2075 | GLsizei *length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2076 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2077 | if (length) |
| 2078 | { |
| 2079 | *length = 0; |
| 2080 | } |
| 2081 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2082 | GLenum nativeType; |
| 2083 | unsigned int numParams; |
| 2084 | if (!context->getIndexedQueryParameterInfo(pname, &nativeType, &numParams)) |
| 2085 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2086 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2087 | return false; |
| 2088 | } |
| 2089 | |
| 2090 | const Caps &caps = context->getCaps(); |
| 2091 | switch (pname) |
| 2092 | { |
| 2093 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 2094 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
| 2095 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 2096 | if (index >= caps.maxTransformFeedbackSeparateAttributes) |
| 2097 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2098 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2099 | return false; |
| 2100 | } |
| 2101 | break; |
| 2102 | |
| 2103 | case GL_UNIFORM_BUFFER_START: |
| 2104 | case GL_UNIFORM_BUFFER_SIZE: |
| 2105 | case GL_UNIFORM_BUFFER_BINDING: |
| 2106 | if (index >= caps.maxUniformBufferBindings) |
| 2107 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2108 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2109 | return false; |
| 2110 | } |
| 2111 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2112 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2113 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 2114 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 2115 | if (index >= 3u) |
| 2116 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2117 | context->handleError(InvalidValue()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2118 | return false; |
| 2119 | } |
| 2120 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2121 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2122 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2123 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2124 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2125 | if (context->getClientVersion() < ES_3_1) |
| 2126 | { |
| 2127 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2128 | InvalidEnum() |
| 2129 | << "Atomic Counter buffers are not supported in this version of GL"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2130 | return false; |
| 2131 | } |
| 2132 | if (index >= caps.maxAtomicCounterBufferBindings) |
| 2133 | { |
| 2134 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2135 | InvalidValue() |
| 2136 | << "index is outside the valid range for GL_ATOMIC_COUNTER_BUFFER_BINDING"); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2137 | return false; |
| 2138 | } |
| 2139 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2140 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2141 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2142 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2143 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2144 | if (context->getClientVersion() < ES_3_1) |
| 2145 | { |
| 2146 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2147 | InvalidEnum() |
| 2148 | << "Shader storage buffers are not supported in this version of GL"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2149 | return false; |
| 2150 | } |
| 2151 | if (index >= caps.maxShaderStorageBufferBindings) |
| 2152 | { |
| 2153 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2154 | InvalidValue() |
| 2155 | << "index is outside the valid range for GL_SHADER_STORAGE_BUFFER_BINDING"); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2156 | return false; |
| 2157 | } |
| 2158 | break; |
| 2159 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2160 | case GL_VERTEX_BINDING_BUFFER: |
| 2161 | case GL_VERTEX_BINDING_DIVISOR: |
| 2162 | case GL_VERTEX_BINDING_OFFSET: |
| 2163 | case GL_VERTEX_BINDING_STRIDE: |
| 2164 | if (context->getClientVersion() < ES_3_1) |
| 2165 | { |
| 2166 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2167 | InvalidEnum() |
| 2168 | << "Vertex Attrib Bindings are not supported in this version of GL"); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2169 | return false; |
| 2170 | } |
| 2171 | if (index >= caps.maxVertexAttribBindings) |
| 2172 | { |
| 2173 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2174 | InvalidValue() |
| 2175 | << "bindingindex must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2176 | return false; |
| 2177 | } |
| 2178 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2179 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2180 | context->handleError(InvalidEnum()); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2181 | return false; |
| 2182 | } |
| 2183 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2184 | if (length) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2185 | { |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2186 | *length = 1; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | return true; |
| 2190 | } |
| 2191 | |
| 2192 | bool ValidateGetIntegeri_v(ValidationContext *context, GLenum target, GLuint index, GLint *data) |
| 2193 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2194 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2195 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2196 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2197 | return false; |
| 2198 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2199 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2200 | } |
| 2201 | |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2202 | bool ValidateGetIntegeri_vRobustANGLE(ValidationContext *context, |
| 2203 | GLenum target, |
| 2204 | GLuint index, |
| 2205 | GLsizei bufSize, |
| 2206 | GLsizei *length, |
| 2207 | GLint *data) |
| 2208 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2209 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2210 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2211 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Geoff Lang | cf255ea | 2016-10-20 11:39:09 -0700 | [diff] [blame] | 2212 | return false; |
| 2213 | } |
| 2214 | |
| 2215 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2216 | { |
| 2217 | return false; |
| 2218 | } |
| 2219 | |
| 2220 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 2221 | { |
| 2222 | return false; |
| 2223 | } |
| 2224 | |
| 2225 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2226 | { |
| 2227 | return false; |
| 2228 | } |
| 2229 | |
| 2230 | return true; |
| 2231 | } |
| 2232 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2233 | bool ValidateGetInteger64i_v(ValidationContext *context, GLenum target, GLuint index, GLint64 *data) |
| 2234 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2235 | if (context->getClientVersion() < ES_3_0) |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2236 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2237 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2238 | return false; |
| 2239 | } |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2240 | return ValidateIndexedStateQuery(context, target, index, nullptr); |
| 2241 | } |
| 2242 | |
| 2243 | bool ValidateGetInteger64i_vRobustANGLE(ValidationContext *context, |
| 2244 | GLenum target, |
| 2245 | GLuint index, |
| 2246 | GLsizei bufSize, |
| 2247 | GLsizei *length, |
| 2248 | GLint64 *data) |
| 2249 | { |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2250 | if (context->getClientVersion() < ES_3_0) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2251 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2252 | context->handleError(InvalidOperation() << "Context does not support GLES3.0"); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 2253 | return false; |
| 2254 | } |
| 2255 | |
| 2256 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2257 | { |
| 2258 | return false; |
| 2259 | } |
| 2260 | |
| 2261 | if (!ValidateIndexedStateQuery(context, target, index, length)) |
| 2262 | { |
| 2263 | return false; |
| 2264 | } |
| 2265 | |
| 2266 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2267 | { |
| 2268 | return false; |
| 2269 | } |
| 2270 | |
| 2271 | return true; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2272 | } |
| 2273 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2274 | bool ValidateCopyBufferSubData(ValidationContext *context, |
| 2275 | GLenum readTarget, |
| 2276 | GLenum writeTarget, |
| 2277 | GLintptr readOffset, |
| 2278 | GLintptr writeOffset, |
| 2279 | GLsizeiptr size) |
| 2280 | { |
| 2281 | if (context->getClientMajorVersion() < 3) |
| 2282 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2283 | context->handleError(InvalidOperation() << "CopyBufferSubData requires ES 3 or greater"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2284 | return false; |
| 2285 | } |
| 2286 | |
| 2287 | if (!ValidBufferTarget(context, readTarget) || !ValidBufferTarget(context, writeTarget)) |
| 2288 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2289 | context->handleError(InvalidEnum() << "Invalid buffer target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2290 | return false; |
| 2291 | } |
| 2292 | |
| 2293 | Buffer *readBuffer = context->getGLState().getTargetBuffer(readTarget); |
| 2294 | Buffer *writeBuffer = context->getGLState().getTargetBuffer(writeTarget); |
| 2295 | |
| 2296 | if (!readBuffer || !writeBuffer) |
| 2297 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2298 | context->handleError(InvalidOperation() << "No buffer bound to target"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2299 | return false; |
| 2300 | } |
| 2301 | |
| 2302 | // Verify that readBuffer and writeBuffer are not currently mapped |
| 2303 | if (readBuffer->isMapped() || writeBuffer->isMapped()) |
| 2304 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2305 | context->handleError(InvalidOperation() |
| 2306 | << "Cannot call CopyBufferSubData on a mapped buffer"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2307 | return false; |
| 2308 | } |
| 2309 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2310 | CheckedNumeric<GLintptr> checkedReadOffset(readOffset); |
| 2311 | CheckedNumeric<GLintptr> checkedWriteOffset(writeOffset); |
| 2312 | CheckedNumeric<GLintptr> checkedSize(size); |
| 2313 | |
| 2314 | auto checkedReadSum = checkedReadOffset + checkedSize; |
| 2315 | auto checkedWriteSum = checkedWriteOffset + checkedSize; |
| 2316 | |
| 2317 | if (!checkedReadSum.IsValid() || !checkedWriteSum.IsValid() || |
| 2318 | !IsValueInRangeForNumericType<GLintptr>(readBuffer->getSize()) || |
| 2319 | !IsValueInRangeForNumericType<GLintptr>(writeBuffer->getSize())) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2320 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2321 | context->handleError(InvalidValue() << "Integer overflow when validating copy offsets."); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2322 | return false; |
| 2323 | } |
| 2324 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2325 | if (readOffset < 0 || writeOffset < 0 || size < 0) |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2326 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2327 | context->handleError(InvalidValue() |
| 2328 | << "readOffset, writeOffset and size must all be non-negative"); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2329 | return false; |
| 2330 | } |
| 2331 | |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2332 | if (checkedReadSum.ValueOrDie() > readBuffer->getSize() || |
| 2333 | checkedWriteSum.ValueOrDie() > writeBuffer->getSize()) |
| 2334 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2335 | context->handleError(InvalidValue() << "Buffer offset overflow in CopyBufferSubData"); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2336 | return false; |
| 2337 | } |
| 2338 | |
| 2339 | if (readBuffer == writeBuffer) |
| 2340 | { |
| 2341 | auto checkedOffsetDiff = (checkedReadOffset - checkedWriteOffset).Abs(); |
| 2342 | if (!checkedOffsetDiff.IsValid()) |
| 2343 | { |
| 2344 | // This shold not be possible. |
| 2345 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2346 | context->handleError(InvalidValue() |
| 2347 | << "Integer overflow when validating same buffer copy."); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2348 | return false; |
| 2349 | } |
| 2350 | |
| 2351 | if (checkedOffsetDiff.ValueOrDie() < size) |
| 2352 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2353 | context->handleError(InvalidValue()); |
Jamie Madill | d2f0c74 | 2016-11-02 10:34:41 -0400 | [diff] [blame] | 2354 | return false; |
| 2355 | } |
| 2356 | } |
| 2357 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 2358 | return true; |
| 2359 | } |
| 2360 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2361 | bool ValidateGetStringi(Context *context, GLenum name, GLuint index) |
| 2362 | { |
| 2363 | if (context->getClientMajorVersion() < 3) |
| 2364 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2365 | context->handleError(InvalidOperation() |
| 2366 | << "glGetStringi requires OpenGL ES 3.0 or higher."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2367 | return false; |
| 2368 | } |
| 2369 | |
| 2370 | switch (name) |
| 2371 | { |
| 2372 | case GL_EXTENSIONS: |
| 2373 | if (index >= context->getExtensionStringCount()) |
| 2374 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2375 | context->handleError(InvalidValue() |
| 2376 | << "index must be less than the number of extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2377 | return false; |
| 2378 | } |
| 2379 | break; |
| 2380 | |
| 2381 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2382 | if (!context->getExtensions().requestExtension) |
| 2383 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2384 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2385 | return false; |
| 2386 | } |
| 2387 | if (index >= context->getRequestableExtensionStringCount()) |
| 2388 | { |
| 2389 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2390 | InvalidValue() |
| 2391 | << "index must be less than the number of requestable extension strings."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2392 | return false; |
| 2393 | } |
| 2394 | break; |
| 2395 | |
| 2396 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2397 | context->handleError(InvalidEnum() << "Invalid name."); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2398 | return false; |
| 2399 | } |
| 2400 | |
| 2401 | return true; |
| 2402 | } |
| 2403 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2404 | bool ValidateRenderbufferStorageMultisample(ValidationContext *context, |
| 2405 | GLenum target, |
| 2406 | GLsizei samples, |
| 2407 | GLenum internalformat, |
| 2408 | GLsizei width, |
| 2409 | GLsizei height) |
| 2410 | { |
| 2411 | if (context->getClientMajorVersion() < 3) |
| 2412 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2413 | context->handleError(InvalidOperation()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2414 | return false; |
| 2415 | } |
| 2416 | |
| 2417 | if (!ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, width, |
| 2418 | height)) |
| 2419 | { |
| 2420 | return false; |
| 2421 | } |
| 2422 | |
| 2423 | // The ES3 spec(section 4.4.2) states that the internal format must be sized and not an integer |
| 2424 | // format if samples is greater than zero. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2425 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalformat); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2426 | if ((formatInfo.componentType == GL_UNSIGNED_INT || formatInfo.componentType == GL_INT) && |
| 2427 | samples > 0) |
| 2428 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2429 | context->handleError(InvalidOperation()); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2430 | return false; |
| 2431 | } |
| 2432 | |
| 2433 | // The behavior is different than the ANGLE version, which would generate a GL_OUT_OF_MEMORY. |
| 2434 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 2435 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 2436 | { |
| 2437 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2438 | InvalidOperation() |
| 2439 | << "Samples must not be greater than maximum supported value for the format."); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 2440 | return false; |
| 2441 | } |
| 2442 | |
| 2443 | return true; |
| 2444 | } |
| 2445 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2446 | bool ValidateVertexAttribIPointer(ValidationContext *context, |
| 2447 | GLuint index, |
| 2448 | GLint size, |
| 2449 | GLenum type, |
| 2450 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2451 | const void *pointer) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2452 | { |
| 2453 | if (context->getClientMajorVersion() < 3) |
| 2454 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2455 | context->handleError(InvalidOperation() |
| 2456 | << "VertexAttribIPointer requires OpenGL ES 3.0 or higher."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2457 | return false; |
| 2458 | } |
| 2459 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2460 | if (!ValidateVertexFormatBase(context, index, size, type, true)) |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2461 | { |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2462 | return false; |
| 2463 | } |
| 2464 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2465 | if (stride < 0) |
| 2466 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2467 | context->handleError(InvalidValue() << "stride cannot be negative."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2468 | return false; |
| 2469 | } |
| 2470 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2471 | const Caps &caps = context->getCaps(); |
| 2472 | if (context->getClientVersion() >= ES_3_1) |
| 2473 | { |
| 2474 | if (stride > caps.maxVertexAttribStride) |
| 2475 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2476 | context->handleError(InvalidValue() |
| 2477 | << "stride cannot be greater than MAX_VERTEX_ATTRIB_STRIDE."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2478 | return false; |
| 2479 | } |
| 2480 | |
| 2481 | // [OpenGL ES 3.1] Section 10.3.1 page 245: |
| 2482 | // glVertexAttribBinding is part of the equivalent code of VertexAttribIPointer, so its |
| 2483 | // validation should be inherited. |
| 2484 | if (index >= caps.maxVertexAttribBindings) |
| 2485 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2486 | context->handleError(InvalidValue() |
| 2487 | << "index must be smaller than MAX_VERTEX_ATTRIB_BINDINGS."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 2488 | return false; |
| 2489 | } |
| 2490 | } |
| 2491 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2492 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 2493 | // An INVALID_OPERATION error is generated when a non-zero vertex array object |
| 2494 | // is bound, zero is bound to the ARRAY_BUFFER buffer object binding point, |
| 2495 | // and the pointer argument is not NULL. |
| 2496 | if (context->getGLState().getVertexArrayId() != 0 && |
| 2497 | context->getGLState().getArrayBufferId() == 0 && pointer != nullptr) |
| 2498 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2499 | context |
| 2500 | ->handleError(InvalidOperation() |
| 2501 | << "Client data cannot be used with a non-default vertex array object."); |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2502 | return false; |
| 2503 | } |
| 2504 | |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 2505 | if (context->getExtensions().webglCompatibility) |
| 2506 | { |
| 2507 | if (!ValidateWebGLVertexAttribPointer(context, type, false, stride, pointer, true)) |
| 2508 | { |
| 2509 | return false; |
| 2510 | } |
| 2511 | } |
| 2512 | |
Geoff Lang | aa086d6 | 2017-03-23 16:47:21 -0400 | [diff] [blame] | 2513 | return true; |
| 2514 | } |
| 2515 | |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2516 | bool ValidateGetSynciv(Context *context, |
| 2517 | GLsync sync, |
| 2518 | GLenum pname, |
| 2519 | GLsizei bufSize, |
| 2520 | GLsizei *length, |
| 2521 | GLint *values) |
| 2522 | { |
| 2523 | if (context->getClientMajorVersion() < 3) |
| 2524 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2525 | context->handleError(InvalidOperation() << "GetSynciv requires OpenGL ES 3.0 or higher."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2526 | return false; |
| 2527 | } |
| 2528 | |
| 2529 | if (bufSize < 0) |
| 2530 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2531 | context->handleError(InvalidValue() << "bufSize cannot be negative."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2532 | return false; |
| 2533 | } |
| 2534 | |
| 2535 | FenceSync *fenceSync = context->getFenceSync(sync); |
| 2536 | if (!fenceSync) |
| 2537 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2538 | context->handleError(InvalidValue() << "Invalid sync object."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2539 | return false; |
| 2540 | } |
| 2541 | |
| 2542 | switch (pname) |
| 2543 | { |
| 2544 | case GL_OBJECT_TYPE: |
| 2545 | case GL_SYNC_CONDITION: |
| 2546 | case GL_SYNC_FLAGS: |
| 2547 | case GL_SYNC_STATUS: |
| 2548 | break; |
| 2549 | |
| 2550 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2551 | context->handleError(InvalidEnum() << "Invalid pname."); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 2552 | return false; |
| 2553 | } |
| 2554 | |
| 2555 | return true; |
| 2556 | } |
| 2557 | |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2558 | bool ValidateDrawElementsInstanced(ValidationContext *context, |
| 2559 | GLenum mode, |
| 2560 | GLsizei count, |
| 2561 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2562 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2563 | GLsizei instanceCount) |
| 2564 | { |
| 2565 | if (context->getClientMajorVersion() < 3) |
| 2566 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2567 | context->handleError(InvalidOperation() << "Requires a GLES 3.0 or higher context."); |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2568 | return false; |
| 2569 | } |
| 2570 | |
| 2571 | return ValidateDrawElementsInstancedCommon(context, mode, count, type, indices, instanceCount); |
| 2572 | } |
| 2573 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2574 | } // namespace gl |