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 | // validationES.h: Validation functions for generic OpenGL ES entry point parameters |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/validationES.h" |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 10 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 12 | #include "libANGLE/Display.h" |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 13 | #include "libANGLE/ErrorStrings.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/Framebuffer.h" |
| 15 | #include "libANGLE/FramebufferAttachment.h" |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 16 | #include "libANGLE/Image.h" |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 17 | #include "libANGLE/Program.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 18 | #include "libANGLE/Query.h" |
| 19 | #include "libANGLE/Texture.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/TransformFeedback.h" |
| 21 | #include "libANGLE/VertexArray.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 22 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 23 | #include "libANGLE/queryconversions.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 24 | #include "libANGLE/validationES2.h" |
| 25 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 26 | |
| 27 | #include "common/mathutil.h" |
| 28 | #include "common/utilities.h" |
| 29 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 30 | using namespace angle; |
| 31 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 32 | namespace gl |
| 33 | { |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 34 | namespace |
| 35 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 36 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 37 | { |
| 38 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 39 | // the compressed block size. |
| 40 | switch (internalFormat) |
| 41 | { |
| 42 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 43 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 44 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 46 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 47 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 48 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 50 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 51 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 52 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 53 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 57 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 58 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 59 | default: |
| 60 | return false; |
| 61 | } |
| 62 | } |
| 63 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 64 | { |
| 65 | // Compressed sub textures have additional formats that requires exact size. |
| 66 | // ES 3.1, Section 8.7, Page 171 |
| 67 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 68 | IsETC2EACFormat(internalFormat); |
| 69 | } |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 70 | bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex, GLint vertexCount) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 71 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 72 | const gl::State &state = context->getGLState(); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 73 | const gl::Program *program = state.getProgram(); |
| 74 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 75 | bool webglCompatibility = context->getExtensions().webglCompatibility; |
| 76 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 77 | const VertexArray *vao = state.getVertexArray(); |
| 78 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 79 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | d078c68 | 2018-01-02 11:50:24 -0500 | [diff] [blame] | 80 | for (size_t attributeIndex : vao->getEnabledAttributesMask()) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 81 | { |
| 82 | const VertexAttribute &attrib = vertexAttribs[attributeIndex]; |
Corentin Wallez | 672f7f3 | 2017-06-15 17:42:17 -0400 | [diff] [blame] | 83 | |
| 84 | // No need to range check for disabled attribs. |
| 85 | if (!attrib.enabled) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 86 | { |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 87 | continue; |
| 88 | } |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 89 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 90 | // If we have no buffer, then we either get an error, or there are no more checks to be |
| 91 | // done. |
Corentin Wallez | 672f7f3 | 2017-06-15 17:42:17 -0400 | [diff] [blame] | 92 | const VertexBinding &binding = vertexBindings[attrib.bindingIndex]; |
| 93 | gl::Buffer *buffer = binding.getBuffer().get(); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 94 | if (!buffer) |
| 95 | { |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 96 | if (webglCompatibility || !state.areClientArraysEnabled()) |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 97 | { |
| 98 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 99 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but |
| 100 | // no buffer is bound to that attribute via bindBuffer and vertexAttribPointer, |
| 101 | // then calls to drawArrays or drawElements will generate an INVALID_OPERATION |
| 102 | // error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 103 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBuffer); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 104 | return false; |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 105 | } |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 106 | else if (attrib.pointer == nullptr) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 107 | { |
| 108 | // This is an application error that would normally result in a crash, |
| 109 | // but we catch it and return an error |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 110 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBufferPointer); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 111 | return false; |
| 112 | } |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 113 | continue; |
| 114 | } |
| 115 | |
Corentin Wallez | 672f7f3 | 2017-06-15 17:42:17 -0400 | [diff] [blame] | 116 | // This needs to come after the check for client arrays as even unused attributes cannot use |
| 117 | // client-side arrays |
| 118 | if (!program->isAttribLocationActive(attributeIndex)) |
| 119 | { |
| 120 | continue; |
| 121 | } |
| 122 | |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 123 | // If we're drawing zero vertices, we have enough data. |
| 124 | if (vertexCount <= 0 || primcount <= 0) |
| 125 | { |
| 126 | continue; |
| 127 | } |
| 128 | |
| 129 | GLint maxVertexElement = 0; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 130 | GLuint divisor = binding.getDivisor(); |
| 131 | if (divisor == 0) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 132 | { |
| 133 | maxVertexElement = maxVertex; |
| 134 | } |
| 135 | else |
| 136 | { |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 137 | maxVertexElement = (primcount - 1) / divisor; |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | // We do manual overflow checks here instead of using safe_math.h because it was |
| 141 | // a bottleneck. Thanks to some properties of GL we know inequalities that can |
| 142 | // help us make the overflow checks faster. |
| 143 | |
| 144 | // The max possible attribSize is 16 for a vector of 4 32 bit values. |
| 145 | constexpr uint64_t kMaxAttribSize = 16; |
| 146 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 147 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 148 | |
| 149 | // We know attribStride is given as a GLsizei which is typedefed to int. |
| 150 | // We also know an upper bound for attribSize. |
| 151 | static_assert(std::is_same<int, GLsizei>::value, ""); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 152 | uint64_t attribStride = ComputeVertexAttributeStride(attrib, binding); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 153 | uint64_t attribSize = ComputeVertexAttributeTypeSize(attrib); |
| 154 | ASSERT(attribStride <= kIntMax && attribSize <= kMaxAttribSize); |
| 155 | |
| 156 | // Computing the max offset using uint64_t without attrib.offset is overflow |
| 157 | // safe. Note: Last vertex element does not take the full stride! |
| 158 | static_assert(kIntMax * kIntMax < kUint64Max - kMaxAttribSize, ""); |
| 159 | uint64_t attribDataSizeNoOffset = maxVertexElement * attribStride + attribSize; |
| 160 | |
| 161 | // An overflow can happen when adding the offset, check for it. |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 162 | uint64_t attribOffset = ComputeVertexAttributeOffset(attrib, binding); |
| 163 | if (attribDataSizeNoOffset > kUint64Max - attribOffset) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 164 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 165 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | uint64_t attribDataSizeWithOffset = attribDataSizeNoOffset + attribOffset; |
| 169 | |
| 170 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
| 171 | // We can return INVALID_OPERATION if our vertex attribute does not have |
| 172 | // enough backing data. |
| 173 | if (attribDataSizeWithOffset > static_cast<uint64_t>(buffer->getSize())) |
| 174 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 175 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 176 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 177 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 178 | |
| 179 | if (webglCompatibility && buffer->isBoundForTransformFeedbackAndOtherUse()) |
| 180 | { |
| 181 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 182 | VertexBufferBoundForTransformFeedback); |
| 183 | return false; |
| 184 | } |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | return true; |
| 188 | } |
| 189 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 190 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 191 | { |
| 192 | switch (type) |
| 193 | { |
| 194 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 195 | case GL_UNSIGNED_BYTE: |
| 196 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 197 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 198 | case GL_UNSIGNED_SHORT_5_6_5: |
| 199 | return context->getClientVersion() >= ES_2_0; |
| 200 | |
| 201 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 202 | case GL_BYTE: |
| 203 | case GL_INT: |
| 204 | case GL_SHORT: |
| 205 | case GL_UNSIGNED_INT: |
| 206 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 207 | case GL_UNSIGNED_INT_24_8: |
| 208 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 209 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 210 | case GL_UNSIGNED_SHORT: |
| 211 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 212 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 213 | return context->getClientVersion() >= ES_3_0; |
| 214 | |
| 215 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 216 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 217 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 218 | |
| 219 | case GL_HALF_FLOAT: |
| 220 | return context->getClientVersion() >= ES_3_0 || |
| 221 | context->getExtensions().textureHalfFloat; |
| 222 | |
| 223 | case GL_HALF_FLOAT_OES: |
| 224 | return context->getExtensions().colorBufferHalfFloat; |
| 225 | |
| 226 | default: |
| 227 | return false; |
| 228 | } |
| 229 | } |
| 230 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 231 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 232 | { |
| 233 | switch (format) |
| 234 | { |
| 235 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 236 | case GL_RGBA: |
| 237 | case GL_RGB: |
| 238 | case GL_ALPHA: |
| 239 | return context->getClientVersion() >= ES_2_0; |
| 240 | |
| 241 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 242 | case GL_RG: |
| 243 | case GL_RED: |
| 244 | case GL_RGBA_INTEGER: |
| 245 | case GL_RGB_INTEGER: |
| 246 | case GL_RG_INTEGER: |
| 247 | case GL_RED_INTEGER: |
| 248 | return context->getClientVersion() >= ES_3_0; |
| 249 | |
| 250 | case GL_SRGB_ALPHA_EXT: |
| 251 | case GL_SRGB_EXT: |
| 252 | return context->getExtensions().sRGB; |
| 253 | |
| 254 | case GL_BGRA_EXT: |
| 255 | return context->getExtensions().readFormatBGRA; |
| 256 | |
| 257 | default: |
| 258 | return false; |
| 259 | } |
| 260 | } |
| 261 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 262 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 263 | GLenum framebufferComponentType, |
| 264 | GLenum format, |
| 265 | GLenum type) |
| 266 | { |
| 267 | switch (framebufferComponentType) |
| 268 | { |
| 269 | case GL_UNSIGNED_NORMALIZED: |
| 270 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 271 | // ReadPixels with BGRA even if the extension is not present |
| 272 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 273 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 274 | type == GL_UNSIGNED_BYTE); |
| 275 | |
| 276 | case GL_SIGNED_NORMALIZED: |
| 277 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 278 | |
| 279 | case GL_INT: |
| 280 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 281 | |
| 282 | case GL_UNSIGNED_INT: |
| 283 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 284 | |
| 285 | case GL_FLOAT: |
| 286 | return (format == GL_RGBA && type == GL_FLOAT); |
| 287 | |
| 288 | default: |
| 289 | UNREACHABLE(); |
| 290 | return false; |
| 291 | } |
| 292 | } |
| 293 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 294 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 295 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 296 | { |
| 297 | switch (ConvertToGLenum(params[0])) |
| 298 | { |
| 299 | case GL_CLAMP_TO_EDGE: |
| 300 | break; |
| 301 | |
| 302 | case GL_REPEAT: |
| 303 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 304 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 305 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 306 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 307 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | break; |
| 311 | |
| 312 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 313 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 314 | return false; |
| 315 | } |
| 316 | |
| 317 | return true; |
| 318 | } |
| 319 | |
| 320 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 321 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 322 | { |
| 323 | switch (ConvertToGLenum(params[0])) |
| 324 | { |
| 325 | case GL_NEAREST: |
| 326 | case GL_LINEAR: |
| 327 | break; |
| 328 | |
| 329 | case GL_NEAREST_MIPMAP_NEAREST: |
| 330 | case GL_LINEAR_MIPMAP_NEAREST: |
| 331 | case GL_NEAREST_MIPMAP_LINEAR: |
| 332 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 333 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 334 | { |
| 335 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 336 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 337 | return false; |
| 338 | } |
| 339 | break; |
| 340 | |
| 341 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 342 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 343 | return false; |
| 344 | } |
| 345 | |
| 346 | return true; |
| 347 | } |
| 348 | |
| 349 | template <typename ParamType> |
| 350 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 351 | { |
| 352 | switch (ConvertToGLenum(params[0])) |
| 353 | { |
| 354 | case GL_NEAREST: |
| 355 | case GL_LINEAR: |
| 356 | break; |
| 357 | |
| 358 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 359 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 360 | return false; |
| 361 | } |
| 362 | |
| 363 | return true; |
| 364 | } |
| 365 | |
| 366 | template <typename ParamType> |
| 367 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 368 | { |
| 369 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 370 | switch (ConvertToGLenum(params[0])) |
| 371 | { |
| 372 | case GL_NONE: |
| 373 | case GL_COMPARE_REF_TO_TEXTURE: |
| 374 | break; |
| 375 | |
| 376 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 377 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 378 | return false; |
| 379 | } |
| 380 | |
| 381 | return true; |
| 382 | } |
| 383 | |
| 384 | template <typename ParamType> |
| 385 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 386 | { |
| 387 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 388 | switch (ConvertToGLenum(params[0])) |
| 389 | { |
| 390 | case GL_LEQUAL: |
| 391 | case GL_GEQUAL: |
| 392 | case GL_LESS: |
| 393 | case GL_GREATER: |
| 394 | case GL_EQUAL: |
| 395 | case GL_NOTEQUAL: |
| 396 | case GL_ALWAYS: |
| 397 | case GL_NEVER: |
| 398 | break; |
| 399 | |
| 400 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 401 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 402 | return false; |
| 403 | } |
| 404 | |
| 405 | return true; |
| 406 | } |
| 407 | |
| 408 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 409 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 410 | { |
| 411 | if (!context->getExtensions().textureSRGBDecode) |
| 412 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 413 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 414 | return false; |
| 415 | } |
| 416 | |
| 417 | switch (ConvertToGLenum(params[0])) |
| 418 | { |
| 419 | case GL_DECODE_EXT: |
| 420 | case GL_SKIP_DECODE_EXT: |
| 421 | break; |
| 422 | |
| 423 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 424 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 425 | return false; |
| 426 | } |
| 427 | |
| 428 | return true; |
| 429 | } |
| 430 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 431 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 432 | { |
| 433 | if (!context->getExtensions().textureFilterAnisotropic) |
| 434 | { |
| 435 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 436 | return false; |
| 437 | } |
| 438 | |
| 439 | return true; |
| 440 | } |
| 441 | |
| 442 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 443 | { |
| 444 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 445 | { |
| 446 | return false; |
| 447 | } |
| 448 | |
| 449 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 450 | |
| 451 | if (paramValue < 1 || paramValue > largest) |
| 452 | { |
| 453 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 454 | return false; |
| 455 | } |
| 456 | |
| 457 | return true; |
| 458 | } |
| 459 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 460 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 461 | { |
| 462 | const Program *program = context->getGLState().getProgram(); |
| 463 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 464 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 465 | if (!ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 466 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 467 | program->getActiveOutputVariables().to_ulong(), |
| 468 | framebuffer->getDrawBufferMask().to_ulong())) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 469 | { |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 470 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DrawBufferTypeMismatch); |
| 471 | return false; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | return true; |
| 475 | } |
| 476 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 477 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 478 | { |
Jamie Madill | cac94a9 | 2017-11-10 10:09:32 -0500 | [diff] [blame] | 479 | const auto &glState = context->getGLState(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 480 | const Program *program = context->getGLState().getProgram(); |
| 481 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 482 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 483 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 484 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 485 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 486 | |
| 487 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 488 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 489 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 490 | |
| 491 | if (!ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), vaoAttribTypeBits, |
| 492 | program->getAttributesMask().to_ulong(), 0xFFFF)) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 493 | { |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 494 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexShaderTypeMismatch); |
| 495 | return false; |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 496 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 497 | return true; |
| 498 | } |
| 499 | |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame^] | 500 | bool IsCompatibleDrawModeWithGeometryShader(GLenum drawMode, |
| 501 | GLenum geometryShaderInputPrimitiveType) |
| 502 | { |
| 503 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
| 504 | switch (geometryShaderInputPrimitiveType) |
| 505 | { |
| 506 | case GL_POINTS: |
| 507 | return drawMode == GL_POINTS; |
| 508 | case GL_LINES: |
| 509 | return drawMode == GL_LINES || drawMode == GL_LINE_STRIP || drawMode == GL_LINE_LOOP; |
| 510 | case GL_LINES_ADJACENCY_EXT: |
| 511 | return drawMode == GL_LINES_ADJACENCY_EXT || drawMode == GL_LINE_STRIP_ADJACENCY_EXT; |
| 512 | case GL_TRIANGLES: |
| 513 | return drawMode == GL_TRIANGLES || drawMode == GL_TRIANGLE_FAN || |
| 514 | drawMode == GL_TRIANGLE_STRIP; |
| 515 | case GL_TRIANGLES_ADJACENCY_EXT: |
| 516 | return drawMode == GL_TRIANGLES_ADJACENCY_EXT || |
| 517 | drawMode == GL_TRIANGLE_STRIP_ADJACENCY_EXT; |
| 518 | default: |
| 519 | UNREACHABLE(); |
| 520 | return false; |
| 521 | } |
| 522 | } |
| 523 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 524 | } // anonymous namespace |
| 525 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 526 | bool IsETC2EACFormat(const GLenum format) |
| 527 | { |
| 528 | // ES 3.1, Table 8.19 |
| 529 | switch (format) |
| 530 | { |
| 531 | case GL_COMPRESSED_R11_EAC: |
| 532 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 533 | case GL_COMPRESSED_RG11_EAC: |
| 534 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 535 | case GL_COMPRESSED_RGB8_ETC2: |
| 536 | case GL_COMPRESSED_SRGB8_ETC2: |
| 537 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 538 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 539 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 540 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 541 | return true; |
| 542 | |
| 543 | default: |
| 544 | return false; |
| 545 | } |
| 546 | } |
| 547 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 548 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 549 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 550 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 551 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 552 | case TextureType::_2D: |
| 553 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 554 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 555 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 556 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 557 | return context->getExtensions().textureRectangle; |
| 558 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 559 | case TextureType::_3D: |
| 560 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 561 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 562 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 563 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 564 | return (context->getClientVersion() >= Version(3, 1)); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 565 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 566 | default: |
| 567 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 568 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 569 | } |
| 570 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 571 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 572 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 573 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 574 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 575 | case TextureType::_2D: |
| 576 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 577 | return true; |
| 578 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 579 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 580 | return context->getExtensions().textureRectangle; |
| 581 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 582 | default: |
| 583 | return false; |
| 584 | } |
| 585 | } |
| 586 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 587 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 588 | { |
| 589 | switch (target) |
| 590 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 591 | case TextureType::_3D: |
| 592 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 593 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 594 | |
| 595 | default: |
| 596 | return false; |
| 597 | } |
| 598 | } |
| 599 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 600 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 601 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 602 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 603 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 604 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 605 | (context->getExtensions().eglImageExternal || |
| 606 | context->getExtensions().eglStreamConsumerExternal); |
| 607 | } |
| 608 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 609 | // This function differs from ValidTextureTarget in that the target must be |
| 610 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 611 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 612 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 613 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 614 | { |
| 615 | switch (target) |
| 616 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 617 | case TextureTarget::_2D: |
| 618 | case TextureTarget::CubeMapNegativeX: |
| 619 | case TextureTarget::CubeMapNegativeY: |
| 620 | case TextureTarget::CubeMapNegativeZ: |
| 621 | case TextureTarget::CubeMapPositiveX: |
| 622 | case TextureTarget::CubeMapPositiveY: |
| 623 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 624 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 625 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 626 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 627 | default: |
| 628 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 629 | } |
| 630 | } |
| 631 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 632 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 633 | GLenum mode, |
| 634 | GLsizei count, |
| 635 | GLenum type, |
| 636 | const GLvoid *indices, |
| 637 | GLsizei primcount) |
| 638 | { |
| 639 | if (primcount < 0) |
| 640 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 641 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 642 | return false; |
| 643 | } |
| 644 | |
| 645 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 646 | { |
| 647 | return false; |
| 648 | } |
| 649 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 650 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | bool ValidateDrawArraysInstancedBase(Context *context, |
| 654 | GLenum mode, |
| 655 | GLint first, |
| 656 | GLsizei count, |
| 657 | GLsizei primcount) |
| 658 | { |
| 659 | if (primcount < 0) |
| 660 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 661 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 662 | return false; |
| 663 | } |
| 664 | |
| 665 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 666 | { |
| 667 | return false; |
| 668 | } |
| 669 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 670 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 673 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 674 | { |
| 675 | // Verify there is at least one active attribute with a divisor of zero |
| 676 | const State &state = context->getGLState(); |
| 677 | |
| 678 | Program *program = state.getProgram(); |
| 679 | |
| 680 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 681 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 682 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 683 | { |
| 684 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 685 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 686 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 687 | { |
| 688 | return true; |
| 689 | } |
| 690 | } |
| 691 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 692 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 693 | return false; |
| 694 | } |
| 695 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 696 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 697 | { |
| 698 | switch (target) |
| 699 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 700 | case TextureType::_3D: |
| 701 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 702 | return true; |
| 703 | default: |
| 704 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 708 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 709 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 710 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 711 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 712 | case TextureType::_2D: |
| 713 | case TextureType::_2DArray: |
| 714 | case TextureType::_2DMultisample: |
| 715 | case TextureType::CubeMap: |
| 716 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 717 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 718 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 719 | return context->getExtensions().textureRectangle; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 720 | default: |
| 721 | return false; |
| 722 | } |
| 723 | } |
| 724 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 725 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 726 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 727 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 728 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 729 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 730 | |
| 731 | switch (target) |
| 732 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 733 | case GL_FRAMEBUFFER: |
| 734 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 735 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 736 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 737 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 738 | return (context->getExtensions().framebufferBlit || |
| 739 | context->getClientMajorVersion() >= 3); |
| 740 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 741 | default: |
| 742 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 743 | } |
| 744 | } |
| 745 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 746 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 747 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 748 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 749 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 750 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 751 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 752 | case TextureType::_2D: |
| 753 | case TextureType::_2DArray: |
| 754 | case TextureType::_2DMultisample: |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 755 | maxDimension = caps.max2DTextureSize; |
| 756 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 757 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 758 | maxDimension = caps.maxCubeMapTextureSize; |
| 759 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 760 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 761 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 762 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 763 | maxDimension = caps.max3DTextureSize; |
| 764 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 765 | default: |
| 766 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 767 | } |
| 768 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 769 | return level <= gl::log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 770 | } |
| 771 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 772 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 773 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 774 | GLint level, |
| 775 | GLsizei width, |
| 776 | GLsizei height, |
| 777 | GLsizei depth, |
| 778 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 779 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 780 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 781 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 782 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 783 | return false; |
| 784 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 785 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 786 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 787 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 788 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 789 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 790 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 791 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 792 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 793 | return false; |
| 794 | } |
| 795 | |
| 796 | if (!ValidMipLevel(context, target, level)) |
| 797 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 798 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 799 | return false; |
| 800 | } |
| 801 | |
| 802 | return true; |
| 803 | } |
| 804 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 805 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 806 | { |
| 807 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 808 | (size % blockSize == 0); |
| 809 | } |
| 810 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 811 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 812 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 813 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 814 | GLsizei width, |
| 815 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 816 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 817 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 818 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 819 | { |
| 820 | return false; |
| 821 | } |
| 822 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 823 | if (width < 0 || height < 0) |
| 824 | { |
| 825 | return false; |
| 826 | } |
| 827 | |
| 828 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 829 | { |
| 830 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 831 | // block size for level 0 but WebGL disallows this. |
| 832 | bool smallerThanBlockSizeAllowed = |
| 833 | level > 0 || !context->getExtensions().webglCompatibility; |
| 834 | |
| 835 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 836 | smallerThanBlockSizeAllowed) || |
| 837 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 838 | smallerThanBlockSizeAllowed)) |
| 839 | { |
| 840 | return false; |
| 841 | } |
| 842 | } |
| 843 | |
| 844 | return true; |
| 845 | } |
| 846 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 847 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 848 | GLenum internalFormat, |
| 849 | GLint xoffset, |
| 850 | GLint yoffset, |
| 851 | GLsizei width, |
| 852 | GLsizei height, |
| 853 | size_t textureWidth, |
| 854 | size_t textureHeight) |
| 855 | { |
| 856 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
| 857 | if (!formatInfo.compressed) |
| 858 | { |
| 859 | return false; |
| 860 | } |
| 861 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 862 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 863 | { |
| 864 | return false; |
| 865 | } |
| 866 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 867 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 868 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 869 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 870 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 871 | { |
| 872 | return false; |
| 873 | } |
| 874 | |
| 875 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 876 | // size but fills the entire mip |
| 877 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 878 | static_cast<size_t>(width) == textureWidth && |
| 879 | static_cast<size_t>(height) == textureHeight; |
| 880 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 881 | (height % formatInfo.compressedBlockHeight) == 0; |
| 882 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 883 | { |
| 884 | return false; |
| 885 | } |
| 886 | } |
| 887 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 888 | return true; |
| 889 | } |
| 890 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 891 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 892 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 893 | GLsizei width, |
| 894 | GLsizei height, |
| 895 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 896 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 897 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 898 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 899 | GLsizei imageSize) |
| 900 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 901 | gl::Buffer *pixelUnpackBuffer = |
| 902 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 903 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 904 | { |
| 905 | // Checks are not required |
| 906 | return true; |
| 907 | } |
| 908 | |
| 909 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 910 | // would exceed the data store size. |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 911 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format, type); |
| 912 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 913 | const gl::Extents size(width, height, depth); |
| 914 | const auto &unpack = context->getGLState().getUnpackState(); |
| 915 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 916 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 917 | auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D); |
| 918 | if (endByteOrErr.isError()) |
| 919 | { |
| 920 | context->handleError(endByteOrErr.getError()); |
| 921 | return false; |
| 922 | } |
| 923 | |
| 924 | GLuint endByte = endByteOrErr.getResult(); |
| 925 | |
| 926 | if (pixelUnpackBuffer) |
| 927 | { |
| 928 | CheckedNumeric<size_t> checkedEndByte(endByteOrErr.getResult()); |
| 929 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 930 | checkedEndByte += checkedOffset; |
| 931 | |
| 932 | if (!checkedEndByte.IsValid() || |
| 933 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 934 | { |
| 935 | // Overflow past the end of the buffer |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 936 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 937 | return false; |
| 938 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 939 | if (context->getExtensions().webglCompatibility && |
| 940 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 941 | { |
| 942 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 943 | PixelUnpackBufferBoundForTransformFeedback); |
| 944 | return false; |
| 945 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 946 | } |
| 947 | else |
| 948 | { |
| 949 | ASSERT(imageSize >= 0); |
| 950 | if (pixels == nullptr && imageSize != 0) |
| 951 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 952 | context->handleError(InvalidOperation() |
| 953 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 954 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 955 | } |
| 956 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 957 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 958 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 959 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 960 | return false; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | return true; |
| 965 | } |
| 966 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 967 | bool ValidQueryType(const Context *context, GLenum queryType) |
| 968 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 969 | static_assert(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT, |
| 970 | "GL extension enums not equal."); |
| 971 | static_assert(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 972 | "GL extension enums not equal."); |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 973 | |
| 974 | switch (queryType) |
| 975 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 976 | case GL_ANY_SAMPLES_PASSED: |
| 977 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 978 | return context->getClientMajorVersion() >= 3 || |
| 979 | context->getExtensions().occlusionQueryBoolean; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 980 | case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
| 981 | return (context->getClientMajorVersion() >= 3); |
| 982 | case GL_TIME_ELAPSED_EXT: |
| 983 | return context->getExtensions().disjointTimerQuery; |
| 984 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 985 | return context->getExtensions().syncQuery; |
| 986 | default: |
| 987 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 988 | } |
| 989 | } |
| 990 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 991 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 992 | GLenum type, |
| 993 | GLboolean normalized, |
| 994 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 995 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 996 | bool pureInteger) |
| 997 | { |
| 998 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 999 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1000 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1001 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1002 | // parameter exceeds 255. |
| 1003 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1004 | if (stride > kMaxWebGLStride) |
| 1005 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1006 | context->handleError(InvalidValue() |
| 1007 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1008 | return false; |
| 1009 | } |
| 1010 | |
| 1011 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1012 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1013 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1014 | // or an INVALID_OPERATION error is generated. |
| 1015 | VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger); |
| 1016 | size_t typeSize = GetVertexFormatTypeSize(internalType); |
| 1017 | |
| 1018 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1019 | size_t sizeMask = (typeSize - 1); |
| 1020 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1021 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1022 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1023 | return false; |
| 1024 | } |
| 1025 | |
| 1026 | if ((stride & sizeMask) != 0) |
| 1027 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1028 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1029 | return false; |
| 1030 | } |
| 1031 | |
| 1032 | return true; |
| 1033 | } |
| 1034 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1035 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1036 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1037 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1038 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1039 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1040 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1041 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1042 | Program *validProgram = context->getProgram(id); |
| 1043 | |
| 1044 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1045 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1046 | if (context->getShader(id)) |
| 1047 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1048 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1049 | } |
| 1050 | else |
| 1051 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1052 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1053 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1054 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1055 | |
| 1056 | return validProgram; |
| 1057 | } |
| 1058 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1059 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1060 | { |
| 1061 | // See ValidProgram for spec details. |
| 1062 | |
| 1063 | Shader *validShader = context->getShader(id); |
| 1064 | |
| 1065 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1066 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1067 | if (context->getProgram(id)) |
| 1068 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1069 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1070 | } |
| 1071 | else |
| 1072 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1073 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1074 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1075 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1076 | |
| 1077 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1078 | } |
| 1079 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1080 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1081 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1082 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1083 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1084 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1085 | { |
| 1086 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1087 | return false; |
| 1088 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1089 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1090 | // Color attachment 0 is validated below because it is always valid |
| 1091 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1092 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1093 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1094 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1095 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | else |
| 1099 | { |
| 1100 | switch (attachment) |
| 1101 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1102 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1103 | case GL_DEPTH_ATTACHMENT: |
| 1104 | case GL_STENCIL_ATTACHMENT: |
| 1105 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1106 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1107 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1108 | if (!context->getExtensions().webglCompatibility && |
| 1109 | context->getClientMajorVersion() < 3) |
| 1110 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1111 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1112 | return false; |
| 1113 | } |
| 1114 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1115 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1116 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1117 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1118 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
| 1122 | return true; |
| 1123 | } |
| 1124 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1125 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1126 | GLenum target, |
| 1127 | GLsizei samples, |
| 1128 | GLenum internalformat, |
| 1129 | GLsizei width, |
| 1130 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1131 | { |
| 1132 | switch (target) |
| 1133 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1134 | case GL_RENDERBUFFER: |
| 1135 | break; |
| 1136 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1137 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1138 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1139 | } |
| 1140 | |
| 1141 | if (width < 0 || height < 0 || samples < 0) |
| 1142 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1143 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1144 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1145 | } |
| 1146 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1147 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1148 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1149 | |
| 1150 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 1151 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1152 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1153 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1154 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1155 | } |
| 1156 | |
| 1157 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1158 | // sized but it does state that the format must be in the ES2.0 spec table 4.5 which contains |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1159 | // only sized internal formats. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1160 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(convertedInternalFormat); |
| 1161 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1162 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1163 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1164 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1165 | } |
| 1166 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1167 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1168 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1169 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1170 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1171 | } |
| 1172 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1173 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1174 | if (handle == 0) |
| 1175 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1176 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1177 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | return true; |
| 1181 | } |
| 1182 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1183 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, |
| 1184 | GLenum target, |
| 1185 | GLenum attachment, |
| 1186 | GLenum renderbuffertarget, |
| 1187 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1188 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1189 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1190 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1191 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1192 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1193 | } |
| 1194 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1195 | gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1196 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1197 | ASSERT(framebuffer); |
| 1198 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1199 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1200 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1201 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1202 | } |
| 1203 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1204 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1205 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1206 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1207 | } |
| 1208 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1209 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1210 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1211 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1212 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1213 | if (renderbuffer != 0) |
| 1214 | { |
| 1215 | if (!context->getRenderbuffer(renderbuffer)) |
| 1216 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1217 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1218 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1219 | } |
| 1220 | } |
| 1221 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1222 | return true; |
| 1223 | } |
| 1224 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1225 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1226 | GLint srcX0, |
| 1227 | GLint srcY0, |
| 1228 | GLint srcX1, |
| 1229 | GLint srcY1, |
| 1230 | GLint dstX0, |
| 1231 | GLint dstY0, |
| 1232 | GLint dstX1, |
| 1233 | GLint dstY1, |
| 1234 | GLbitfield mask, |
| 1235 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1236 | { |
| 1237 | switch (filter) |
| 1238 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1239 | case GL_NEAREST: |
| 1240 | break; |
| 1241 | case GL_LINEAR: |
| 1242 | break; |
| 1243 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1244 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1245 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1249 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1250 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1251 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1252 | } |
| 1253 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1254 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1255 | // color buffer, leaving only nearest being unfiltered from above |
| 1256 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1257 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1258 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1259 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1262 | const auto &glState = context->getGLState(); |
| 1263 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1264 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1265 | |
| 1266 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1267 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1268 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1269 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1272 | if (!ValidateFramebufferComplete(context, readFramebuffer, true)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1273 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1274 | return false; |
| 1275 | } |
| 1276 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1277 | if (!ValidateFramebufferComplete(context, drawFramebuffer, true)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1278 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1279 | return false; |
| 1280 | } |
| 1281 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1282 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1283 | { |
| 1284 | context->handleError(InvalidOperation()); |
| 1285 | return false; |
| 1286 | } |
| 1287 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1288 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1289 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1290 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1293 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1294 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1295 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1296 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1297 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1298 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1300 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1301 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1302 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1303 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1304 | for (size_t drawbufferIdx = 0; |
| 1305 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1307 | const FramebufferAttachment *attachment = |
| 1308 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1309 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1310 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1311 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1313 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1314 | // 1) If the read buffer is fixed point format, the draw buffer must be as well |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1315 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1316 | // as well |
| 1317 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1318 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1319 | // Changes with EXT_color_buffer_float: |
| 1320 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1321 | GLenum readComponentType = readFormat.info->componentType; |
| 1322 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1323 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1324 | readComponentType == GL_SIGNED_NORMALIZED); |
| 1325 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
| 1326 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1327 | |
| 1328 | if (extensions.colorBufferFloat) |
| 1329 | { |
| 1330 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1331 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1332 | |
| 1333 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1334 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1335 | context->handleError(InvalidOperation() |
| 1336 | << "If the read buffer contains fixed-point or " |
| 1337 | "floating-point values, the draw buffer must " |
| 1338 | "as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1339 | return false; |
| 1340 | } |
| 1341 | } |
| 1342 | else if (readFixedPoint != drawFixedPoint) |
| 1343 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1344 | context->handleError(InvalidOperation() |
| 1345 | << "If the read buffer contains fixed-point values, " |
| 1346 | "the draw buffer must as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1347 | return false; |
| 1348 | } |
| 1349 | |
| 1350 | if (readComponentType == GL_UNSIGNED_INT && |
| 1351 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1352 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1353 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1354 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1355 | } |
| 1356 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1357 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1358 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1359 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1360 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1361 | } |
| 1362 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1363 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1364 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1365 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1366 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1367 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1368 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1369 | |
| 1370 | if (context->getExtensions().webglCompatibility && |
| 1371 | *readColorBuffer == *attachment) |
| 1372 | { |
| 1373 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1374 | InvalidOperation() |
| 1375 | << "Read and write color attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1376 | return false; |
| 1377 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1378 | } |
| 1379 | } |
| 1380 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1381 | if ((readFormat.info->componentType == GL_INT || |
| 1382 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1383 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1384 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1385 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1386 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1387 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1388 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1389 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1390 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1391 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1392 | // situation is an application error that would lead to a crash in ANGLE. |
| 1393 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1394 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1395 | context->handleError( |
| 1396 | InvalidOperation() |
| 1397 | << "Attempt to read from a missing color attachment of a complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1398 | return false; |
| 1399 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1400 | } |
| 1401 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1402 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1403 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1404 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1405 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1406 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1407 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1408 | const gl::FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1409 | readFramebuffer->getAttachment(context, attachments[i]); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1410 | const gl::FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1411 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1412 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1413 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1414 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1415 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1416 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1417 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1418 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1419 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1420 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1421 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1422 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1423 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1424 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1425 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1426 | |
| 1427 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1428 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1429 | context->handleError( |
| 1430 | InvalidOperation() |
| 1431 | << "Read and write depth stencil attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1432 | return false; |
| 1433 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1434 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1435 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1436 | else if (drawBuffer) |
| 1437 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1438 | context->handleError(InvalidOperation() << "Attempt to read from a missing " |
| 1439 | "depth/stencil attachment of a " |
| 1440 | "complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1441 | return false; |
| 1442 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1443 | } |
| 1444 | } |
| 1445 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1446 | // ANGLE_multiview, Revision 1: |
| 1447 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
| 1448 | // multi-view layout of the current draw framebuffer or read framebuffer is not NONE. |
| 1449 | if (readFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1450 | { |
| 1451 | context->handleError(InvalidFramebufferOperation() |
| 1452 | << "Attempt to read from a multi-view framebuffer."); |
| 1453 | return false; |
| 1454 | } |
| 1455 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1456 | { |
| 1457 | context->handleError(InvalidFramebufferOperation() |
| 1458 | << "Attempt to write to a multi-view framebuffer."); |
| 1459 | return false; |
| 1460 | } |
| 1461 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1462 | return true; |
| 1463 | } |
| 1464 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1465 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1466 | GLint x, |
| 1467 | GLint y, |
| 1468 | GLsizei width, |
| 1469 | GLsizei height, |
| 1470 | GLenum format, |
| 1471 | GLenum type, |
| 1472 | GLsizei bufSize, |
| 1473 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1474 | GLsizei *columns, |
| 1475 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1476 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1477 | { |
| 1478 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1479 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1480 | return false; |
| 1481 | } |
| 1482 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1483 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1484 | columns, rows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1485 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1486 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1487 | } |
| 1488 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1489 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1490 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1491 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1492 | } |
| 1493 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1494 | return true; |
| 1495 | } |
| 1496 | |
| 1497 | bool ValidateReadnPixelsEXT(Context *context, |
| 1498 | GLint x, |
| 1499 | GLint y, |
| 1500 | GLsizei width, |
| 1501 | GLsizei height, |
| 1502 | GLenum format, |
| 1503 | GLenum type, |
| 1504 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1505 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1506 | { |
| 1507 | if (bufSize < 0) |
| 1508 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1509 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1510 | return false; |
| 1511 | } |
| 1512 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1513 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1514 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1515 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1516 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1517 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1518 | GLint x, |
| 1519 | GLint y, |
| 1520 | GLsizei width, |
| 1521 | GLsizei height, |
| 1522 | GLenum format, |
| 1523 | GLenum type, |
| 1524 | GLsizei bufSize, |
| 1525 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1526 | GLsizei *columns, |
| 1527 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1528 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1529 | { |
| 1530 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1531 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1532 | return false; |
| 1533 | } |
| 1534 | |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1535 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length, |
| 1536 | columns, rows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1537 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1538 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1541 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1542 | { |
| 1543 | return false; |
| 1544 | } |
| 1545 | |
| 1546 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1547 | } |
| 1548 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1549 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1550 | { |
| 1551 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1552 | !context->getExtensions().disjointTimerQuery) |
| 1553 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1554 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1555 | return false; |
| 1556 | } |
| 1557 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1558 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1559 | } |
| 1560 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1561 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1562 | { |
| 1563 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1564 | !context->getExtensions().disjointTimerQuery) |
| 1565 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1566 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1567 | return false; |
| 1568 | } |
| 1569 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1570 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1571 | } |
| 1572 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1573 | bool ValidateIsQueryEXT(gl::Context *context, GLuint id) |
| 1574 | { |
| 1575 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1576 | !context->getExtensions().disjointTimerQuery) |
| 1577 | { |
| 1578 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1579 | return false; |
| 1580 | } |
| 1581 | |
| 1582 | return true; |
| 1583 | } |
| 1584 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1585 | bool ValidateBeginQueryBase(gl::Context *context, GLenum target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1586 | { |
| 1587 | if (!ValidQueryType(context, target)) |
| 1588 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1589 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1590 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | if (id == 0) |
| 1594 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1595 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1596 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1600 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1601 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1602 | // the active query for either target is non-zero), if <id> is the name of an |
| 1603 | // existing query object whose type does not match <target>, or if <id> is the |
| 1604 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1605 | // generated. |
| 1606 | |
| 1607 | // Ensure no other queries are active |
| 1608 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1609 | // separately that: |
| 1610 | // a) The query ID passed is not the current active query for any target/type |
| 1611 | // b) There are no active queries for the requested target (and in the case |
| 1612 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1613 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1614 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1615 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1616 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1617 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1618 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | Query *queryObject = context->getQuery(id, true, target); |
| 1622 | |
| 1623 | // check that name was obtained with glGenQueries |
| 1624 | if (!queryObject) |
| 1625 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1626 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1627 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | // check for type mismatch |
| 1631 | if (queryObject->getType() != target) |
| 1632 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1633 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1634 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1635 | } |
| 1636 | |
| 1637 | return true; |
| 1638 | } |
| 1639 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1640 | bool ValidateBeginQueryEXT(gl::Context *context, GLenum target, GLuint id) |
| 1641 | { |
| 1642 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1643 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1644 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1645 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1646 | return false; |
| 1647 | } |
| 1648 | |
| 1649 | return ValidateBeginQueryBase(context, target, id); |
| 1650 | } |
| 1651 | |
| 1652 | bool ValidateEndQueryBase(gl::Context *context, GLenum target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1653 | { |
| 1654 | if (!ValidQueryType(context, target)) |
| 1655 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1656 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1657 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1658 | } |
| 1659 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1660 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1661 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1662 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1663 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1664 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1665 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1668 | return true; |
| 1669 | } |
| 1670 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1671 | bool ValidateEndQueryEXT(gl::Context *context, GLenum target) |
| 1672 | { |
| 1673 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1674 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1675 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1676 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1677 | return false; |
| 1678 | } |
| 1679 | |
| 1680 | return ValidateEndQueryBase(context, target); |
| 1681 | } |
| 1682 | |
| 1683 | bool ValidateQueryCounterEXT(Context *context, GLuint id, GLenum target) |
| 1684 | { |
| 1685 | if (!context->getExtensions().disjointTimerQuery) |
| 1686 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1687 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1688 | return false; |
| 1689 | } |
| 1690 | |
| 1691 | if (target != GL_TIMESTAMP_EXT) |
| 1692 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1693 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1694 | return false; |
| 1695 | } |
| 1696 | |
| 1697 | Query *queryObject = context->getQuery(id, true, target); |
| 1698 | if (queryObject == nullptr) |
| 1699 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1700 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1701 | return false; |
| 1702 | } |
| 1703 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1704 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1705 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1706 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1707 | return false; |
| 1708 | } |
| 1709 | |
| 1710 | return true; |
| 1711 | } |
| 1712 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1713 | bool ValidateGetQueryivBase(Context *context, GLenum target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1714 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1715 | if (numParams) |
| 1716 | { |
| 1717 | *numParams = 0; |
| 1718 | } |
| 1719 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1720 | if (!ValidQueryType(context, target) && target != GL_TIMESTAMP_EXT) |
| 1721 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1722 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
| 1725 | |
| 1726 | switch (pname) |
| 1727 | { |
| 1728 | case GL_CURRENT_QUERY_EXT: |
| 1729 | if (target == GL_TIMESTAMP_EXT) |
| 1730 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1731 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1732 | return false; |
| 1733 | } |
| 1734 | break; |
| 1735 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1736 | if (!context->getExtensions().disjointTimerQuery || |
| 1737 | (target != GL_TIMESTAMP_EXT && target != GL_TIME_ELAPSED_EXT)) |
| 1738 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1739 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1740 | return false; |
| 1741 | } |
| 1742 | break; |
| 1743 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1744 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1745 | return false; |
| 1746 | } |
| 1747 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1748 | if (numParams) |
| 1749 | { |
| 1750 | // All queries return only one value |
| 1751 | *numParams = 1; |
| 1752 | } |
| 1753 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1754 | return true; |
| 1755 | } |
| 1756 | |
| 1757 | bool ValidateGetQueryivEXT(Context *context, GLenum target, GLenum pname, GLint *params) |
| 1758 | { |
| 1759 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1760 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1761 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1762 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1763 | return false; |
| 1764 | } |
| 1765 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1766 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1767 | } |
| 1768 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1769 | bool ValidateGetQueryivRobustANGLE(Context *context, |
| 1770 | GLenum target, |
| 1771 | GLenum pname, |
| 1772 | GLsizei bufSize, |
| 1773 | GLsizei *length, |
| 1774 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1775 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1776 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1777 | { |
| 1778 | return false; |
| 1779 | } |
| 1780 | |
| 1781 | if (!ValidateGetQueryivBase(context, target, pname, length)) |
| 1782 | { |
| 1783 | return false; |
| 1784 | } |
| 1785 | |
| 1786 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1787 | { |
| 1788 | return false; |
| 1789 | } |
| 1790 | |
| 1791 | return true; |
| 1792 | } |
| 1793 | |
| 1794 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1795 | { |
| 1796 | if (numParams) |
| 1797 | { |
| 1798 | *numParams = 0; |
| 1799 | } |
| 1800 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1801 | Query *queryObject = context->getQuery(id, false, GL_NONE); |
| 1802 | |
| 1803 | if (!queryObject) |
| 1804 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1805 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1806 | return false; |
| 1807 | } |
| 1808 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1809 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1810 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1811 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1812 | return false; |
| 1813 | } |
| 1814 | |
| 1815 | switch (pname) |
| 1816 | { |
| 1817 | case GL_QUERY_RESULT_EXT: |
| 1818 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1819 | break; |
| 1820 | |
| 1821 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1822 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1823 | return false; |
| 1824 | } |
| 1825 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1826 | if (numParams) |
| 1827 | { |
| 1828 | *numParams = 1; |
| 1829 | } |
| 1830 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1831 | return true; |
| 1832 | } |
| 1833 | |
| 1834 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1835 | { |
| 1836 | if (!context->getExtensions().disjointTimerQuery) |
| 1837 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1838 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1839 | return false; |
| 1840 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1841 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1842 | } |
| 1843 | |
| 1844 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1845 | GLuint id, |
| 1846 | GLenum pname, |
| 1847 | GLsizei bufSize, |
| 1848 | GLsizei *length, |
| 1849 | GLint *params) |
| 1850 | { |
| 1851 | if (!context->getExtensions().disjointTimerQuery) |
| 1852 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1853 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1854 | return false; |
| 1855 | } |
| 1856 | |
| 1857 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1858 | { |
| 1859 | return false; |
| 1860 | } |
| 1861 | |
| 1862 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 1863 | { |
| 1864 | return false; |
| 1865 | } |
| 1866 | |
| 1867 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1868 | { |
| 1869 | return false; |
| 1870 | } |
| 1871 | |
| 1872 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1876 | { |
| 1877 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1878 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1879 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1880 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1881 | return false; |
| 1882 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1883 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1884 | } |
| 1885 | |
| 1886 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1887 | GLuint id, |
| 1888 | GLenum pname, |
| 1889 | GLsizei bufSize, |
| 1890 | GLsizei *length, |
| 1891 | GLuint *params) |
| 1892 | { |
| 1893 | if (!context->getExtensions().disjointTimerQuery && |
| 1894 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1895 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1896 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1897 | return false; |
| 1898 | } |
| 1899 | |
| 1900 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1901 | { |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
| 1905 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 1906 | { |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
| 1910 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1911 | { |
| 1912 | return false; |
| 1913 | } |
| 1914 | |
| 1915 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1916 | } |
| 1917 | |
| 1918 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1919 | { |
| 1920 | if (!context->getExtensions().disjointTimerQuery) |
| 1921 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1922 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1923 | return false; |
| 1924 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1925 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1926 | } |
| 1927 | |
| 1928 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 1929 | GLuint id, |
| 1930 | GLenum pname, |
| 1931 | GLsizei bufSize, |
| 1932 | GLsizei *length, |
| 1933 | GLint64 *params) |
| 1934 | { |
| 1935 | if (!context->getExtensions().disjointTimerQuery) |
| 1936 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1937 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1938 | return false; |
| 1939 | } |
| 1940 | |
| 1941 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1942 | { |
| 1943 | return false; |
| 1944 | } |
| 1945 | |
| 1946 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 1947 | { |
| 1948 | return false; |
| 1949 | } |
| 1950 | |
| 1951 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1952 | { |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
| 1956 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 1960 | { |
| 1961 | if (!context->getExtensions().disjointTimerQuery) |
| 1962 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1963 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1964 | return false; |
| 1965 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1966 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1967 | } |
| 1968 | |
| 1969 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 1970 | GLuint id, |
| 1971 | GLenum pname, |
| 1972 | GLsizei bufSize, |
| 1973 | GLsizei *length, |
| 1974 | GLuint64 *params) |
| 1975 | { |
| 1976 | if (!context->getExtensions().disjointTimerQuery) |
| 1977 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1978 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1979 | return false; |
| 1980 | } |
| 1981 | |
| 1982 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1983 | { |
| 1984 | return false; |
| 1985 | } |
| 1986 | |
| 1987 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 1988 | { |
| 1989 | return false; |
| 1990 | } |
| 1991 | |
| 1992 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 1993 | { |
| 1994 | return false; |
| 1995 | } |
| 1996 | |
| 1997 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1998 | } |
| 1999 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2000 | bool ValidateUniformCommonBase(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2001 | gl::Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2002 | GLint location, |
| 2003 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2004 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2005 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2006 | // TODO(Jiajia): Add image uniform check in future. |
| 2007 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2008 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2009 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2010 | return false; |
| 2011 | } |
| 2012 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2013 | if (!program) |
| 2014 | { |
| 2015 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2016 | return false; |
| 2017 | } |
| 2018 | |
| 2019 | if (!program->isLinked()) |
| 2020 | { |
| 2021 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2022 | return false; |
| 2023 | } |
| 2024 | |
| 2025 | if (location == -1) |
| 2026 | { |
| 2027 | // Silently ignore the uniform command |
| 2028 | return false; |
| 2029 | } |
| 2030 | |
| 2031 | const auto &uniformLocations = program->getUniformLocations(); |
| 2032 | size_t castedLocation = static_cast<size_t>(location); |
| 2033 | if (castedLocation >= uniformLocations.size()) |
| 2034 | { |
| 2035 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2036 | return false; |
| 2037 | } |
| 2038 | |
| 2039 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2040 | if (uniformLocation.ignored) |
| 2041 | { |
| 2042 | // Silently ignore the uniform command |
| 2043 | return false; |
| 2044 | } |
| 2045 | |
| 2046 | if (!uniformLocation.used()) |
| 2047 | { |
| 2048 | context->handleError(InvalidOperation()); |
| 2049 | return false; |
| 2050 | } |
| 2051 | |
| 2052 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2053 | |
| 2054 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
| 2055 | if (!uniform.isArray() && count > 1) |
| 2056 | { |
| 2057 | context->handleError(InvalidOperation()); |
| 2058 | return false; |
| 2059 | } |
| 2060 | |
| 2061 | *uniformOut = &uniform; |
| 2062 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2063 | } |
| 2064 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2065 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2066 | GLenum uniformType, |
| 2067 | GLsizei count, |
| 2068 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2069 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2070 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2071 | // It is compatible with INT or BOOL. |
| 2072 | // Do these cheap tests first, for a little extra speed. |
| 2073 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2074 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2075 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2076 | } |
| 2077 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2078 | if (IsSamplerType(uniformType)) |
| 2079 | { |
| 2080 | // Check that the values are in range. |
| 2081 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2082 | for (GLsizei i = 0; i < count; ++i) |
| 2083 | { |
| 2084 | if (value[i] < 0 || value[i] >= max) |
| 2085 | { |
| 2086 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2087 | return false; |
| 2088 | } |
| 2089 | } |
| 2090 | return true; |
| 2091 | } |
| 2092 | |
| 2093 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2094 | return false; |
| 2095 | } |
| 2096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2097 | bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2098 | { |
| 2099 | // Check that the value type is compatible with uniform type. |
| 2100 | // Do the cheaper test first, for a little extra speed. |
| 2101 | if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType) |
| 2102 | { |
| 2103 | return true; |
| 2104 | } |
| 2105 | |
| 2106 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch); |
| 2107 | return false; |
| 2108 | } |
| 2109 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2110 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2111 | { |
| 2112 | // Check that the value type is compatible with uniform type. |
| 2113 | if (valueType == uniformType) |
| 2114 | { |
| 2115 | return true; |
| 2116 | } |
| 2117 | |
| 2118 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2119 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2120 | } |
| 2121 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2122 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2123 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2124 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2125 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2126 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2127 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2128 | } |
| 2129 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2130 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2131 | { |
| 2132 | const LinkedUniform *uniform = nullptr; |
| 2133 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2134 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2135 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2136 | } |
| 2137 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2138 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2139 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2140 | GLint location, |
| 2141 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2142 | GLboolean transpose) |
| 2143 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2144 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2145 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2146 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2147 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2148 | } |
| 2149 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2150 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2151 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2152 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2153 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2154 | } |
| 2155 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2156 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2157 | { |
| 2158 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2159 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2160 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2161 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2164 | const Caps &caps = context->getCaps(); |
| 2165 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2166 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2167 | { |
| 2168 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2169 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2170 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2171 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2172 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2173 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | switch (pname) |
| 2178 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2179 | case GL_TEXTURE_BINDING_2D: |
| 2180 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2181 | case GL_TEXTURE_BINDING_3D: |
| 2182 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2183 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2184 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2185 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2186 | if (!context->getExtensions().textureRectangle) |
| 2187 | { |
| 2188 | context->handleError(InvalidEnum() |
| 2189 | << "ANGLE_texture_rectangle extension not present"); |
| 2190 | return false; |
| 2191 | } |
| 2192 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2193 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2194 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2195 | !context->getExtensions().eglImageExternal) |
| 2196 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2197 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2198 | "nor GL_OES_EGL_image_external " |
| 2199 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2200 | return false; |
| 2201 | } |
| 2202 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2203 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2204 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2205 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2206 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2207 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2208 | ASSERT(readFramebuffer); |
| 2209 | |
| 2210 | if (!ValidateFramebufferComplete(context, readFramebuffer, false)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2211 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2212 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2213 | } |
| 2214 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2215 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2216 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2217 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2218 | return false; |
| 2219 | } |
| 2220 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2221 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2222 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2223 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2224 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2225 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2226 | } |
| 2227 | } |
| 2228 | break; |
| 2229 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2230 | default: |
| 2231 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2235 | if (*numParams == 0) |
| 2236 | { |
| 2237 | return false; |
| 2238 | } |
| 2239 | |
| 2240 | return true; |
| 2241 | } |
| 2242 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2243 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2244 | GLenum pname, |
| 2245 | GLsizei bufSize, |
| 2246 | GLenum *nativeType, |
| 2247 | unsigned int *numParams) |
| 2248 | { |
| 2249 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2250 | { |
| 2251 | return false; |
| 2252 | } |
| 2253 | |
| 2254 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2255 | { |
| 2256 | return false; |
| 2257 | } |
| 2258 | |
| 2259 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2260 | { |
| 2261 | return false; |
| 2262 | } |
| 2263 | |
| 2264 | return true; |
| 2265 | } |
| 2266 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2267 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2268 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2269 | GLint level, |
| 2270 | GLenum internalformat, |
| 2271 | bool isSubImage, |
| 2272 | GLint xoffset, |
| 2273 | GLint yoffset, |
| 2274 | GLint zoffset, |
| 2275 | GLint x, |
| 2276 | GLint y, |
| 2277 | GLsizei width, |
| 2278 | GLsizei height, |
| 2279 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2280 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2281 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2282 | TextureType texType = TextureTargetToType(target); |
| 2283 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2284 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2285 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2286 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2287 | return false; |
| 2288 | } |
| 2289 | |
| 2290 | if (width < 0 || height < 0) |
| 2291 | { |
| 2292 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2293 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2294 | } |
| 2295 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2296 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2297 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2298 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2299 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2300 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | if (border != 0) |
| 2304 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2305 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2306 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2307 | } |
| 2308 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2309 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2310 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2311 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2312 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2313 | } |
| 2314 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2315 | const gl::State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2316 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2317 | if (!ValidateFramebufferComplete(context, readFramebuffer, true)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2318 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2319 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2320 | } |
| 2321 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2322 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2323 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2324 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2325 | } |
| 2326 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2327 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2328 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2329 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2330 | return false; |
| 2331 | } |
| 2332 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2333 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2334 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2335 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2336 | // situation is an application error that would lead to a crash in ANGLE. |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2337 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2338 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2339 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2340 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2341 | return false; |
| 2342 | } |
| 2343 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2344 | // ANGLE_multiview spec, Revision 1: |
| 2345 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2346 | // INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the current read framebuffer |
| 2347 | // is not NONE. |
| 2348 | if (source->getMultiviewLayout() != GL_NONE) |
| 2349 | { |
| 2350 | context->handleError(InvalidFramebufferOperation() |
| 2351 | << "The active read framebuffer object has multiview attachments."); |
| 2352 | return false; |
| 2353 | } |
| 2354 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2355 | const gl::Caps &caps = context->getCaps(); |
| 2356 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2357 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2358 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2359 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2360 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2361 | maxDimension = caps.max2DTextureSize; |
| 2362 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2363 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2364 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2365 | maxDimension = caps.maxCubeMapTextureSize; |
| 2366 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2367 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2368 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2369 | maxDimension = caps.maxRectangleTextureSize; |
| 2370 | break; |
| 2371 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2372 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2373 | maxDimension = caps.max2DTextureSize; |
| 2374 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2375 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2376 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2377 | maxDimension = caps.max3DTextureSize; |
| 2378 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2379 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2380 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2381 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2382 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2383 | } |
| 2384 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2385 | gl::Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2386 | if (!texture) |
| 2387 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2388 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2389 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2390 | } |
| 2391 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2392 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2393 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2394 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2395 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2396 | } |
| 2397 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2398 | const gl::InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2399 | isSubImage ? *texture->getFormat(target, level).info |
| 2400 | : gl::GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2401 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2402 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2403 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2404 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2405 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | if (isSubImage) |
| 2409 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2410 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2411 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2412 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2413 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2414 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2415 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2416 | } |
| 2417 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2418 | else |
| 2419 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2420 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2421 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2422 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2423 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2424 | } |
| 2425 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2426 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2427 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2428 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2429 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2430 | } |
| 2431 | |
| 2432 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2433 | if (static_cast<int>(width) > maxLevelDimension || |
| 2434 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2435 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2436 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2437 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2438 | } |
| 2439 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2440 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2441 | if (textureFormatOut) |
| 2442 | { |
| 2443 | *textureFormatOut = texture->getFormat(target, level); |
| 2444 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2445 | |
| 2446 | // Detect texture copying feedback loops for WebGL. |
| 2447 | if (context->getExtensions().webglCompatibility) |
| 2448 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2449 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2450 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2451 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2452 | return false; |
| 2453 | } |
| 2454 | } |
| 2455 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2456 | return true; |
| 2457 | } |
| 2458 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2459 | bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2460 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame^] | 2461 | const Extensions &extensions = context->getExtensions(); |
| 2462 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2463 | switch (mode) |
| 2464 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2465 | case GL_POINTS: |
| 2466 | case GL_LINES: |
| 2467 | case GL_LINE_LOOP: |
| 2468 | case GL_LINE_STRIP: |
| 2469 | case GL_TRIANGLES: |
| 2470 | case GL_TRIANGLE_STRIP: |
| 2471 | case GL_TRIANGLE_FAN: |
| 2472 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame^] | 2473 | |
| 2474 | case GL_LINES_ADJACENCY_EXT: |
| 2475 | case GL_LINE_STRIP_ADJACENCY_EXT: |
| 2476 | case GL_TRIANGLES_ADJACENCY_EXT: |
| 2477 | case GL_TRIANGLE_STRIP_ADJACENCY_EXT: |
| 2478 | if (!extensions.geometryShader) |
| 2479 | { |
| 2480 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2481 | return false; |
| 2482 | } |
| 2483 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2484 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2485 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2486 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2487 | } |
| 2488 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2489 | if (count < 0) |
| 2490 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2491 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2492 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2493 | } |
| 2494 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2495 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2496 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2497 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2498 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2499 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2500 | if (!extensions.webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2501 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2502 | // Check for mapped buffers |
| 2503 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2504 | if (state.hasMappedBuffer(BufferBinding::Array)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2505 | { |
| 2506 | context->handleError(InvalidOperation()); |
| 2507 | return false; |
| 2508 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2509 | } |
| 2510 | |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2511 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2512 | // Section 6.10 of the WebGL 1.0 spec. |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2513 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2514 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2515 | { |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 2516 | const FramebufferAttachment *dsAttachment = |
| 2517 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 2518 | GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2519 | GLuint minimumRequiredStencilMask = (1 << stencilBits) - 1; |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 2520 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 2521 | |
| 2522 | bool differentRefs = state.getStencilRef() != state.getStencilBackRef(); |
| 2523 | bool differentWritemasks = |
| 2524 | (depthStencilState.stencilWritemask & minimumRequiredStencilMask) != |
| 2525 | (depthStencilState.stencilBackWritemask & minimumRequiredStencilMask); |
| 2526 | bool differentMasks = (depthStencilState.stencilMask & minimumRequiredStencilMask) != |
| 2527 | (depthStencilState.stencilBackMask & minimumRequiredStencilMask); |
| 2528 | |
| 2529 | if (differentRefs || differentWritemasks || differentMasks) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2530 | { |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2531 | if (!extensions.webglCompatibility) |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2532 | { |
Yuly Novikov | d73f852 | 2017-01-13 17:48:57 -0500 | [diff] [blame] | 2533 | ERR() << "This ANGLE implementation does not support separate front/back stencil " |
| 2534 | "writemasks, reference values, or stencil mask values."; |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2535 | } |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2536 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StencilReferenceMaskOrMismatch); |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2537 | return false; |
| 2538 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2539 | } |
| 2540 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2541 | if (!ValidateFramebufferComplete(context, framebuffer, true)) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2542 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2543 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2544 | } |
| 2545 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2546 | gl::Program *program = state.getProgram(); |
| 2547 | if (!program) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2548 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2549 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2550 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2551 | } |
| 2552 | |
Yunchao He | cddcb59 | 2017-11-13 15:27:35 +0800 | [diff] [blame] | 2553 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2554 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2555 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2556 | // produce undefined result. |
Yunchao He | ece1253 | 2017-11-21 15:50:21 +0800 | [diff] [blame] | 2557 | if (!program->hasLinkedVertexShader() || !program->hasLinkedFragmentShader()) |
Yunchao He | cddcb59 | 2017-11-13 15:27:35 +0800 | [diff] [blame] | 2558 | { |
| 2559 | context->handleError(InvalidOperation() << "It is a undefined behaviour to render without " |
| 2560 | "vertex shader stage or fragment shader stage."); |
| 2561 | return false; |
| 2562 | } |
| 2563 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 2564 | if (!program->validateSamplers(nullptr, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2565 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2566 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2567 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2568 | } |
| 2569 | |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2570 | if (extensions.multiview) |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2571 | { |
Martin Radev | da8e257 | 2017-09-12 17:21:16 +0300 | [diff] [blame] | 2572 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2573 | const int framebufferNumViews = framebuffer->getNumViews(); |
Martin Radev | da8e257 | 2017-09-12 17:21:16 +0300 | [diff] [blame] | 2574 | if (framebufferNumViews != programNumViews) |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2575 | { |
| 2576 | context->handleError(InvalidOperation() << "The number of views in the active program " |
| 2577 | "and draw framebuffer does not match."); |
| 2578 | return false; |
| 2579 | } |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2580 | |
| 2581 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2582 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2583 | framebufferNumViews > 1) |
| 2584 | { |
| 2585 | context->handleError(InvalidOperation() |
| 2586 | << "There is an active transform feedback object " |
| 2587 | "when the number of views in the active draw " |
| 2588 | "framebuffer is greater than 1."); |
| 2589 | return false; |
| 2590 | } |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2591 | |
| 2592 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2593 | state.isQueryActive(GL_TIME_ELAPSED_EXT)) |
| 2594 | { |
| 2595 | context->handleError(InvalidOperation() << "There is an active query for target " |
| 2596 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2597 | "views in the active draw framebuffer is " |
| 2598 | "greater than 1."); |
| 2599 | return false; |
| 2600 | } |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2601 | } |
| 2602 | |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame^] | 2603 | // Do geometry shader specific validations |
| 2604 | if (program->hasLinkedGeometryShader()) |
| 2605 | { |
| 2606 | if (!IsCompatibleDrawModeWithGeometryShader(mode, |
| 2607 | program->getGeometryShaderInputPrimitiveType())) |
| 2608 | { |
| 2609 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2610 | IncompatibleDrawModeAgainstGeometryShader); |
| 2611 | return false; |
| 2612 | } |
| 2613 | } |
| 2614 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2615 | // Uniform buffer validation |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2616 | for (unsigned int uniformBlockIndex = 0; |
| 2617 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2618 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 2619 | const gl::InterfaceBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2620 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 2621 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2622 | state.getIndexedUniformBuffer(blockBinding); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2623 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 2624 | if (uniformBuffer.get() == nullptr) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2625 | { |
| 2626 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2627 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2628 | InvalidOperation() |
| 2629 | << "It is undefined behaviour to have a used but unbound uniform buffer."); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2630 | return false; |
| 2631 | } |
| 2632 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 2633 | size_t uniformBufferSize = uniformBuffer.getSize(); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2634 | if (uniformBufferSize == 0) |
| 2635 | { |
| 2636 | // Bind the whole buffer. |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 2637 | uniformBufferSize = static_cast<size_t>(uniformBuffer->getSize()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2638 | } |
| 2639 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2640 | if (uniformBufferSize < uniformBlock.dataSize) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2641 | { |
| 2642 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2643 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2644 | InvalidOperation() |
| 2645 | << "It is undefined behaviour to use a uniform buffer that is too small."); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2646 | return false; |
| 2647 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2648 | |
| 2649 | if (extensions.webglCompatibility && |
| 2650 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2651 | { |
| 2652 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2653 | UniformBufferBoundForTransformFeedback); |
| 2654 | return false; |
| 2655 | } |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2656 | } |
| 2657 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2658 | // Do some additonal WebGL-specific validation |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2659 | if (extensions.webglCompatibility) |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2660 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2661 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2662 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2663 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2664 | { |
| 2665 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferDoubleBound); |
| 2666 | return false; |
| 2667 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2668 | // Detect rendering feedback loops for WebGL. |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2669 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2670 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2671 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2672 | return false; |
| 2673 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2674 | |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2675 | // Detect that the vertex shader input types match the attribute types |
| 2676 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2677 | { |
| 2678 | return false; |
| 2679 | } |
| 2680 | |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2681 | // Detect that the color buffer types match the fragment shader output types |
| 2682 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2683 | { |
| 2684 | return false; |
| 2685 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2686 | } |
| 2687 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2688 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2689 | } |
| 2690 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2691 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2692 | GLenum mode, |
| 2693 | GLint first, |
| 2694 | GLsizei count, |
| 2695 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2696 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2697 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2698 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2699 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2700 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2701 | } |
| 2702 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2703 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2704 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2705 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2706 | !curTransformFeedback->isPaused() && curTransformFeedback->getPrimitiveMode() != mode) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2707 | { |
| 2708 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2709 | // that does not match the current transform feedback object's draw mode (if transform |
| 2710 | // feedback |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2711 | // is active), (3.0.2, section 2.14, pg 86) |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2712 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2713 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2714 | } |
| 2715 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2716 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2717 | { |
| 2718 | return false; |
| 2719 | } |
| 2720 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2721 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2722 | // - first < 0 has been checked as an error condition. |
| 2723 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2724 | // From this we know maxVertex will be positive, and only need to check if it overflows GLint. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2725 | ASSERT(first >= 0); |
| 2726 | if (count > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2727 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2728 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2729 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2730 | { |
| 2731 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2732 | return false; |
| 2733 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2734 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2735 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex), count)) |
| 2736 | { |
| 2737 | return false; |
| 2738 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | return true; |
| 2742 | } |
| 2743 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2744 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
| 2745 | GLenum mode, |
| 2746 | GLint first, |
| 2747 | GLsizei count, |
| 2748 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2749 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2750 | if (!context->getExtensions().instancedArrays) |
| 2751 | { |
| 2752 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2753 | return false; |
| 2754 | } |
| 2755 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2756 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2757 | { |
| 2758 | return false; |
| 2759 | } |
| 2760 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2761 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2762 | } |
| 2763 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2764 | bool ValidateDrawElementsBase(Context *context, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2765 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2766 | switch (type) |
| 2767 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2768 | case GL_UNSIGNED_BYTE: |
| 2769 | case GL_UNSIGNED_SHORT: |
| 2770 | break; |
| 2771 | case GL_UNSIGNED_INT: |
| 2772 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2773 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2774 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2775 | return false; |
| 2776 | } |
| 2777 | break; |
| 2778 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2779 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2780 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2781 | } |
| 2782 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2783 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2784 | |
| 2785 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2786 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2787 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2788 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2789 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2790 | // DrawElementsInstanced |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2791 | // while transform feedback is active, (3.0.2, section 2.14, pg 86) |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2792 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2793 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2796 | return true; |
| 2797 | } |
| 2798 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2799 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2800 | GLenum mode, |
| 2801 | GLsizei count, |
| 2802 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2803 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2804 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2805 | { |
| 2806 | if (!ValidateDrawElementsBase(context, type)) |
| 2807 | return false; |
| 2808 | |
| 2809 | const State &state = context->getGLState(); |
| 2810 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2811 | if (!ValidateDrawBase(context, mode, count)) |
| 2812 | { |
| 2813 | return false; |
| 2814 | } |
| 2815 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2816 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2817 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2818 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2819 | if (!context->getExtensions().webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2820 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2821 | // Check for mapped buffers |
| 2822 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2823 | if (state.hasMappedBuffer(gl::BufferBinding::ElementArray)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2824 | { |
| 2825 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 2826 | return false; |
| 2827 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2828 | } |
| 2829 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2830 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2831 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2832 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2833 | GLuint typeBytes = gl::GetTypeInfo(type).bytes; |
| 2834 | |
| 2835 | if (context->getExtensions().webglCompatibility) |
| 2836 | { |
| 2837 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 2838 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 2839 | { |
| 2840 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 2841 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 2842 | // data type passed to the call, or an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2843 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2844 | return false; |
| 2845 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 2846 | |
| 2847 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 2848 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 2849 | // error is generated. |
| 2850 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 2851 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2852 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 2853 | return false; |
| 2854 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | if (context->getExtensions().webglCompatibility || |
| 2858 | !context->getGLState().areClientArraysEnabled()) |
| 2859 | { |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2860 | if (!elementArrayBuffer && count > 0) |
| 2861 | { |
| 2862 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
| 2863 | // If drawElements is called with a count greater than zero, and no WebGLBuffer is bound |
| 2864 | // to the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2865 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 2866 | return false; |
| 2867 | } |
| 2868 | } |
| 2869 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2870 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2871 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2872 | // This is an application error that would normally result in a crash, but we catch it and |
| 2873 | // return an error |
| 2874 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 2875 | return false; |
| 2876 | } |
| 2877 | |
| 2878 | if (count > 0 && elementArrayBuffer) |
| 2879 | { |
| 2880 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 2881 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 2882 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 2883 | constexpr uint64_t kMaxTypeSize = 8; |
| 2884 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 2885 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 2886 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 2887 | |
| 2888 | uint64_t typeSize = typeBytes; |
| 2889 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 2890 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 2891 | |
| 2892 | // Doing the multiplication here is overflow-safe |
| 2893 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 2894 | |
| 2895 | // The offset can be any value, check for overflows |
| 2896 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 2897 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2898 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2899 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2900 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 2901 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2902 | |
| 2903 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 2904 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 2905 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2906 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 2907 | return false; |
| 2908 | } |
| 2909 | |
| 2910 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 2911 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 2912 | { |
| 2913 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2914 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2915 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2916 | |
| 2917 | if (context->getExtensions().webglCompatibility && |
| 2918 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2919 | { |
| 2920 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2921 | ElementArrayBufferBoundForTransformFeedback); |
| 2922 | return false; |
| 2923 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 2924 | } |
| 2925 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2926 | if (context->getExtensions().robustBufferAccessBehavior) |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 2927 | { |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2928 | // Here we use maxVertex = 0 and vertexCount = 1 to avoid retrieving IndexRange when robust |
| 2929 | // access is enabled. |
| 2930 | if (!ValidateDrawAttribs(context, primcount, 0, 1)) |
| 2931 | { |
| 2932 | return false; |
| 2933 | } |
| 2934 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2935 | else if (count == 0) |
| 2936 | { |
| 2937 | // ValidateDrawAttribs also does some extra validation that is independent of the vertex |
| 2938 | // count. |
| 2939 | if (!ValidateDrawAttribs(context, 0, 0, 0)) |
| 2940 | { |
| 2941 | return false; |
| 2942 | } |
| 2943 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2944 | else |
| 2945 | { |
| 2946 | // Use the parameter buffer to retrieve and cache the index range. |
| 2947 | const auto ¶ms = context->getParams<HasIndexRange>(); |
| 2948 | const auto &indexRangeOpt = params.getIndexRange(); |
| 2949 | if (!indexRangeOpt.valid()) |
| 2950 | { |
| 2951 | // Unexpected error. |
| 2952 | return false; |
| 2953 | } |
| 2954 | |
| 2955 | // If we use an index greater than our maximum supported index range, return an error. |
| 2956 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 2957 | // return an error if possible here. |
| 2958 | if (static_cast<GLuint64>(indexRangeOpt.value().end) >= context->getCaps().maxElementIndex) |
| 2959 | { |
| 2960 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 2961 | return false; |
| 2962 | } |
| 2963 | |
| 2964 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRangeOpt.value().end), |
| 2965 | static_cast<GLint>(indexRangeOpt.value().vertexCount()))) |
| 2966 | { |
| 2967 | return false; |
| 2968 | } |
| 2969 | |
| 2970 | // No op if there are no real indices in the index data (all are primitive restart). |
| 2971 | return (indexRangeOpt.value().vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 2972 | } |
| 2973 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2974 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2975 | } |
| 2976 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2977 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2978 | GLenum mode, |
| 2979 | GLsizei count, |
| 2980 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2981 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2982 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2983 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2984 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2985 | } |
| 2986 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 2987 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
| 2988 | GLenum mode, |
| 2989 | GLsizei count, |
| 2990 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2991 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2992 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2993 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2994 | if (!context->getExtensions().instancedArrays) |
| 2995 | { |
| 2996 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2997 | return false; |
| 2998 | } |
| 2999 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3000 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3001 | { |
| 3002 | return false; |
| 3003 | } |
| 3004 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3005 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3008 | bool ValidateFramebufferTextureBase(Context *context, |
| 3009 | GLenum target, |
| 3010 | GLenum attachment, |
| 3011 | GLuint texture, |
| 3012 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3013 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3014 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3015 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3016 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3017 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3018 | } |
| 3019 | |
| 3020 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3021 | { |
| 3022 | return false; |
| 3023 | } |
| 3024 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3025 | if (texture != 0) |
| 3026 | { |
| 3027 | gl::Texture *tex = context->getTexture(texture); |
| 3028 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3029 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3030 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3031 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3032 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3033 | } |
| 3034 | |
| 3035 | if (level < 0) |
| 3036 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3037 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3038 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3042 | const gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3043 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3044 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3045 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3046 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3047 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3048 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | return true; |
| 3052 | } |
| 3053 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3054 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3055 | { |
| 3056 | if (program == 0) |
| 3057 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3058 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3059 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3062 | gl::Program *programObject = GetValidProgram(context, program); |
| 3063 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3064 | { |
| 3065 | return false; |
| 3066 | } |
| 3067 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3068 | if (!programObject || !programObject->isLinked()) |
| 3069 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3070 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3071 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3072 | } |
| 3073 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3074 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3075 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3076 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3077 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3078 | } |
| 3079 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3080 | return true; |
| 3081 | } |
| 3082 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3083 | static bool ValidateSizedGetUniform(Context *context, |
| 3084 | GLuint program, |
| 3085 | GLint location, |
| 3086 | GLsizei bufSize, |
| 3087 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3088 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3089 | if (length) |
| 3090 | { |
| 3091 | *length = 0; |
| 3092 | } |
| 3093 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3094 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3095 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3096 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3097 | } |
| 3098 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3099 | if (bufSize < 0) |
| 3100 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3101 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3102 | return false; |
| 3103 | } |
| 3104 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3105 | gl::Program *programObject = context->getProgram(program); |
| 3106 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3107 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3108 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3109 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3110 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3111 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3112 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3113 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3114 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3115 | } |
| 3116 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3117 | if (length) |
| 3118 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3119 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3120 | } |
| 3121 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3122 | return true; |
| 3123 | } |
| 3124 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3125 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3126 | GLuint program, |
| 3127 | GLint location, |
| 3128 | GLsizei bufSize, |
| 3129 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3130 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3131 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3132 | } |
| 3133 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3134 | bool ValidateGetnUniformivEXT(Context *context, |
| 3135 | GLuint program, |
| 3136 | GLint location, |
| 3137 | GLsizei bufSize, |
| 3138 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3139 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3140 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3141 | } |
| 3142 | |
| 3143 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3144 | GLuint program, |
| 3145 | GLint location, |
| 3146 | GLsizei bufSize, |
| 3147 | GLsizei *length, |
| 3148 | GLfloat *params) |
| 3149 | { |
| 3150 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3151 | { |
| 3152 | return false; |
| 3153 | } |
| 3154 | |
| 3155 | // bufSize is validated in ValidateSizedGetUniform |
| 3156 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
| 3157 | } |
| 3158 | |
| 3159 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3160 | GLuint program, |
| 3161 | GLint location, |
| 3162 | GLsizei bufSize, |
| 3163 | GLsizei *length, |
| 3164 | GLint *params) |
| 3165 | { |
| 3166 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3167 | { |
| 3168 | return false; |
| 3169 | } |
| 3170 | |
| 3171 | // bufSize is validated in ValidateSizedGetUniform |
| 3172 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
| 3173 | } |
| 3174 | |
| 3175 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3176 | GLuint program, |
| 3177 | GLint location, |
| 3178 | GLsizei bufSize, |
| 3179 | GLsizei *length, |
| 3180 | GLuint *params) |
| 3181 | { |
| 3182 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3183 | { |
| 3184 | return false; |
| 3185 | } |
| 3186 | |
| 3187 | if (context->getClientMajorVersion() < 3) |
| 3188 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3189 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3190 | return false; |
| 3191 | } |
| 3192 | |
| 3193 | // bufSize is validated in ValidateSizedGetUniform |
| 3194 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3195 | } |
| 3196 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3197 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3198 | GLenum target, |
| 3199 | GLsizei numAttachments, |
| 3200 | const GLenum *attachments, |
| 3201 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3202 | { |
| 3203 | if (numAttachments < 0) |
| 3204 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3205 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3206 | return false; |
| 3207 | } |
| 3208 | |
| 3209 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3210 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3211 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3212 | { |
| 3213 | if (defaultFramebuffer) |
| 3214 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3215 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3216 | return false; |
| 3217 | } |
| 3218 | |
| 3219 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3220 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3221 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3222 | "greater than the maximum supported " |
| 3223 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3224 | return false; |
| 3225 | } |
| 3226 | } |
| 3227 | else |
| 3228 | { |
| 3229 | switch (attachments[i]) |
| 3230 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3231 | case GL_DEPTH_ATTACHMENT: |
| 3232 | case GL_STENCIL_ATTACHMENT: |
| 3233 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3234 | if (defaultFramebuffer) |
| 3235 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3236 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3237 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3238 | return false; |
| 3239 | } |
| 3240 | break; |
| 3241 | case GL_COLOR: |
| 3242 | case GL_DEPTH: |
| 3243 | case GL_STENCIL: |
| 3244 | if (!defaultFramebuffer) |
| 3245 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3246 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3247 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3248 | return false; |
| 3249 | } |
| 3250 | break; |
| 3251 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3252 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3253 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3254 | } |
| 3255 | } |
| 3256 | } |
| 3257 | |
| 3258 | return true; |
| 3259 | } |
| 3260 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3261 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3262 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3263 | if (!context->getExtensions().debugMarker) |
| 3264 | { |
| 3265 | // The debug marker calls should not set error state |
| 3266 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3267 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3268 | return false; |
| 3269 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3270 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3271 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3272 | if (length < 0) |
| 3273 | { |
| 3274 | return false; |
| 3275 | } |
| 3276 | |
| 3277 | if (marker == nullptr) |
| 3278 | { |
| 3279 | return false; |
| 3280 | } |
| 3281 | |
| 3282 | return true; |
| 3283 | } |
| 3284 | |
| 3285 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3286 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3287 | if (!context->getExtensions().debugMarker) |
| 3288 | { |
| 3289 | // The debug marker calls should not set error state |
| 3290 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3291 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3292 | return false; |
| 3293 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3294 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3295 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3296 | if (length < 0) |
| 3297 | { |
| 3298 | return false; |
| 3299 | } |
| 3300 | |
| 3301 | if (length > 0 && marker == nullptr) |
| 3302 | { |
| 3303 | return false; |
| 3304 | } |
| 3305 | |
| 3306 | return true; |
| 3307 | } |
| 3308 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3309 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3310 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3311 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3312 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3313 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3314 | return false; |
| 3315 | } |
| 3316 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3317 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3318 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3319 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3320 | if (!context->getExtensions().eglImage) |
| 3321 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3322 | context->handleError(InvalidEnum() |
| 3323 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3324 | } |
| 3325 | break; |
| 3326 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3327 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3328 | if (!context->getExtensions().eglImageExternal) |
| 3329 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3330 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3331 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3332 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3333 | break; |
| 3334 | |
| 3335 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3336 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3337 | return false; |
| 3338 | } |
| 3339 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3340 | egl::Image *imageObject = reinterpret_cast<egl::Image *>(image); |
| 3341 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3342 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3343 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3344 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3345 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3346 | return false; |
| 3347 | } |
| 3348 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3349 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3350 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3351 | context->handleError(InvalidOperation() |
| 3352 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3353 | return false; |
| 3354 | } |
| 3355 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3356 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3357 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3358 | if (!textureCaps.texturable) |
| 3359 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3360 | context->handleError(InvalidOperation() |
| 3361 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3362 | return false; |
| 3363 | } |
| 3364 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3365 | return true; |
| 3366 | } |
| 3367 | |
| 3368 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3369 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3370 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3371 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3372 | if (!context->getExtensions().eglImage) |
| 3373 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3374 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3375 | return false; |
| 3376 | } |
| 3377 | |
| 3378 | switch (target) |
| 3379 | { |
| 3380 | case GL_RENDERBUFFER: |
| 3381 | break; |
| 3382 | |
| 3383 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3384 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3385 | return false; |
| 3386 | } |
| 3387 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3388 | egl::Image *imageObject = reinterpret_cast<egl::Image *>(image); |
| 3389 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3390 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3391 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3392 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3393 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3394 | return false; |
| 3395 | } |
| 3396 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3397 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3398 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3399 | if (!textureCaps.renderable) |
| 3400 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3401 | context->handleError(InvalidOperation() |
| 3402 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3403 | return false; |
| 3404 | } |
| 3405 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3406 | return true; |
| 3407 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3408 | |
| 3409 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3410 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3411 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3412 | { |
| 3413 | // The default VAO should always exist |
| 3414 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3415 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3416 | return false; |
| 3417 | } |
| 3418 | |
| 3419 | return true; |
| 3420 | } |
| 3421 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3422 | bool ValidateProgramBinaryBase(Context *context, |
| 3423 | GLuint program, |
| 3424 | GLenum binaryFormat, |
| 3425 | const void *binary, |
| 3426 | GLint length) |
| 3427 | { |
| 3428 | Program *programObject = GetValidProgram(context, program); |
| 3429 | if (programObject == nullptr) |
| 3430 | { |
| 3431 | return false; |
| 3432 | } |
| 3433 | |
| 3434 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3435 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3436 | programBinaryFormats.end()) |
| 3437 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3438 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3439 | return false; |
| 3440 | } |
| 3441 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3442 | if (context->hasActiveTransformFeedback(program)) |
| 3443 | { |
| 3444 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3445 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3446 | "is associated with an active transform " |
| 3447 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3448 | return false; |
| 3449 | } |
| 3450 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3451 | return true; |
| 3452 | } |
| 3453 | |
| 3454 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3455 | GLuint program, |
| 3456 | GLsizei bufSize, |
| 3457 | GLsizei *length, |
| 3458 | GLenum *binaryFormat, |
| 3459 | void *binary) |
| 3460 | { |
| 3461 | Program *programObject = GetValidProgram(context, program); |
| 3462 | if (programObject == nullptr) |
| 3463 | { |
| 3464 | return false; |
| 3465 | } |
| 3466 | |
| 3467 | if (!programObject->isLinked()) |
| 3468 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3469 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3470 | return false; |
| 3471 | } |
| 3472 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3473 | if (context->getCaps().programBinaryFormats.empty()) |
| 3474 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3475 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3476 | return false; |
| 3477 | } |
| 3478 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3479 | return true; |
| 3480 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3481 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3482 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3483 | { |
| 3484 | // INVALID_VALUE is generated if n is negative or greater than value of MAX_DRAW_BUFFERS |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3485 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3486 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3487 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3488 | return false; |
| 3489 | } |
| 3490 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3491 | { |
| 3492 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3493 | return false; |
| 3494 | } |
| 3495 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3496 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3497 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3498 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3499 | |
| 3500 | // This should come first before the check for the default frame buffer |
| 3501 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3502 | // rather than INVALID_OPERATION |
| 3503 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3504 | { |
| 3505 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3506 | |
| 3507 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3508 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3509 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3510 | { |
| 3511 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3512 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3513 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3514 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3515 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3516 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3517 | return false; |
| 3518 | } |
| 3519 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3520 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3521 | context->handleError(InvalidOperation() |
| 3522 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3523 | return false; |
| 3524 | } |
| 3525 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3526 | frameBufferId != 0) |
| 3527 | { |
| 3528 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3529 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3530 | context->handleError(InvalidOperation() |
| 3531 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3532 | return false; |
| 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3537 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3538 | if (frameBufferId == 0) |
| 3539 | { |
| 3540 | if (n != 1) |
| 3541 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3542 | context->handleError(InvalidOperation() |
| 3543 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3544 | return false; |
| 3545 | } |
| 3546 | |
| 3547 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3548 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3549 | context->handleError( |
| 3550 | InvalidOperation() |
| 3551 | << "Only NONE or BACK are valid values when drawing to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3552 | return false; |
| 3553 | } |
| 3554 | } |
| 3555 | |
| 3556 | return true; |
| 3557 | } |
| 3558 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3559 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3560 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3561 | GLenum pname, |
| 3562 | GLsizei *length, |
| 3563 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3564 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3565 | if (length) |
| 3566 | { |
| 3567 | *length = 0; |
| 3568 | } |
| 3569 | |
| 3570 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3571 | { |
| 3572 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3573 | InvalidOperation() |
| 3574 | << "Context does not support OpenGL ES 3.0 or GL_OES_mapbuffer is not enabled."); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3575 | return false; |
| 3576 | } |
| 3577 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3578 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3579 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3580 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3584 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3585 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3586 | case GL_BUFFER_MAP_POINTER: |
| 3587 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3588 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3589 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3590 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3593 | |
| 3594 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3595 | // target bound to zero generate an INVALID_OPERATION error." |
| 3596 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3597 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3598 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3599 | context->handleError(InvalidOperation() |
| 3600 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3601 | return false; |
| 3602 | } |
| 3603 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3604 | if (length) |
| 3605 | { |
| 3606 | *length = 1; |
| 3607 | } |
| 3608 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3609 | return true; |
| 3610 | } |
| 3611 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3612 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3613 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3614 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3615 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3616 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3617 | return false; |
| 3618 | } |
| 3619 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3620 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3621 | |
| 3622 | if (buffer == nullptr || !buffer->isMapped()) |
| 3623 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3624 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3625 | return false; |
| 3626 | } |
| 3627 | |
| 3628 | return true; |
| 3629 | } |
| 3630 | |
| 3631 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3632 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3633 | GLintptr offset, |
| 3634 | GLsizeiptr length, |
| 3635 | GLbitfield access) |
| 3636 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3637 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3638 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3639 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3640 | return false; |
| 3641 | } |
| 3642 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3643 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3644 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3645 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3646 | return false; |
| 3647 | } |
| 3648 | |
| 3649 | if (length < 0) |
| 3650 | { |
| 3651 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3652 | return false; |
| 3653 | } |
| 3654 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3655 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3656 | |
| 3657 | if (!buffer) |
| 3658 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3659 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3660 | return false; |
| 3661 | } |
| 3662 | |
| 3663 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3664 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3665 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3666 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3667 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3668 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3669 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | // Check for invalid bits in the mask |
| 3674 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3675 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3676 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3677 | |
| 3678 | if (access & ~(allAccessBits)) |
| 3679 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3680 | context->handleError(InvalidValue() |
| 3681 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3682 | return false; |
| 3683 | } |
| 3684 | |
| 3685 | if (length == 0) |
| 3686 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3687 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3688 | return false; |
| 3689 | } |
| 3690 | |
| 3691 | if (buffer->isMapped()) |
| 3692 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3693 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3694 | return false; |
| 3695 | } |
| 3696 | |
| 3697 | // Check for invalid bit combinations |
| 3698 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3699 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3700 | context->handleError(InvalidOperation() |
| 3701 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3702 | return false; |
| 3703 | } |
| 3704 | |
| 3705 | GLbitfield writeOnlyBits = |
| 3706 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3707 | |
| 3708 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3709 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3710 | context->handleError(InvalidOperation() |
| 3711 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3712 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3713 | return false; |
| 3714 | } |
| 3715 | |
| 3716 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3717 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3718 | context->handleError( |
| 3719 | InvalidOperation() |
| 3720 | << "The explicit flushing bit may only be set if the buffer is mapped for writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3721 | return false; |
| 3722 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3723 | |
| 3724 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3725 | } |
| 3726 | |
| 3727 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3728 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3729 | GLintptr offset, |
| 3730 | GLsizeiptr length) |
| 3731 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3732 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3733 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3734 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3735 | return false; |
| 3736 | } |
| 3737 | |
| 3738 | if (length < 0) |
| 3739 | { |
| 3740 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3741 | return false; |
| 3742 | } |
| 3743 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3744 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3745 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3746 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3747 | return false; |
| 3748 | } |
| 3749 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3750 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3751 | |
| 3752 | if (buffer == nullptr) |
| 3753 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3754 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3755 | return false; |
| 3756 | } |
| 3757 | |
| 3758 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 3759 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3760 | context->handleError(InvalidOperation() |
| 3761 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3762 | return false; |
| 3763 | } |
| 3764 | |
| 3765 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3766 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3767 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3768 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3769 | if (!checkedSize.IsValid() || |
| 3770 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3771 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3772 | context->handleError(InvalidValue() |
| 3773 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3774 | return false; |
| 3775 | } |
| 3776 | |
| 3777 | return true; |
| 3778 | } |
| 3779 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3780 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 3781 | { |
| 3782 | if (n < 0) |
| 3783 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3784 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 3785 | return false; |
| 3786 | } |
| 3787 | return true; |
| 3788 | } |
| 3789 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3790 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3791 | { |
| 3792 | if (!context->getExtensions().robustClientMemory) |
| 3793 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3794 | context->handleError(InvalidOperation() |
| 3795 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3796 | return false; |
| 3797 | } |
| 3798 | |
| 3799 | if (bufSize < 0) |
| 3800 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3801 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3802 | return false; |
| 3803 | } |
| 3804 | |
| 3805 | return true; |
| 3806 | } |
| 3807 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3808 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3809 | { |
| 3810 | if (bufSize < numParams) |
| 3811 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3812 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 3813 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 3814 | return false; |
| 3815 | } |
| 3816 | |
| 3817 | return true; |
| 3818 | } |
| 3819 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 3820 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 3821 | GLenum target, |
| 3822 | GLenum attachment, |
| 3823 | GLenum pname, |
| 3824 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3825 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3826 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3827 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3828 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3829 | return false; |
| 3830 | } |
| 3831 | |
| 3832 | int clientVersion = context->getClientMajorVersion(); |
| 3833 | |
| 3834 | switch (pname) |
| 3835 | { |
| 3836 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 3837 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 3838 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 3839 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 3840 | break; |
| 3841 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 3842 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 3843 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 3844 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 3845 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 3846 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 3847 | { |
| 3848 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 3849 | return false; |
| 3850 | } |
| 3851 | break; |
| 3852 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3853 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 3854 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 3855 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3856 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3857 | return false; |
| 3858 | } |
| 3859 | break; |
| 3860 | |
| 3861 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 3862 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 3863 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 3864 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 3865 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 3866 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 3867 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 3868 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 3869 | if (clientVersion < 3) |
| 3870 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3871 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3872 | return false; |
| 3873 | } |
| 3874 | break; |
| 3875 | |
| 3876 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3877 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3878 | return false; |
| 3879 | } |
| 3880 | |
| 3881 | // Determine if the attachment is a valid enum |
| 3882 | switch (attachment) |
| 3883 | { |
| 3884 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3885 | case GL_DEPTH: |
| 3886 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3887 | if (clientVersion < 3) |
| 3888 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3889 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3890 | return false; |
| 3891 | } |
| 3892 | break; |
| 3893 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 3894 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3895 | if (clientVersion < 3 && !context->isWebGL1()) |
| 3896 | { |
| 3897 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 3898 | return false; |
| 3899 | } |
| 3900 | break; |
| 3901 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3902 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3903 | case GL_DEPTH_ATTACHMENT: |
| 3904 | case GL_STENCIL_ATTACHMENT: |
| 3905 | break; |
| 3906 | |
| 3907 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3908 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 3909 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3910 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 3911 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 3912 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3913 | return false; |
| 3914 | } |
| 3915 | break; |
| 3916 | } |
| 3917 | |
| 3918 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 3919 | ASSERT(framebuffer); |
| 3920 | |
| 3921 | if (framebuffer->id() == 0) |
| 3922 | { |
| 3923 | if (clientVersion < 3) |
| 3924 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3925 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3926 | return false; |
| 3927 | } |
| 3928 | |
| 3929 | switch (attachment) |
| 3930 | { |
| 3931 | case GL_BACK: |
| 3932 | case GL_DEPTH: |
| 3933 | case GL_STENCIL: |
| 3934 | break; |
| 3935 | |
| 3936 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3937 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3938 | return false; |
| 3939 | } |
| 3940 | } |
| 3941 | else |
| 3942 | { |
| 3943 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 3944 | { |
| 3945 | // Valid attachment query |
| 3946 | } |
| 3947 | else |
| 3948 | { |
| 3949 | switch (attachment) |
| 3950 | { |
| 3951 | case GL_DEPTH_ATTACHMENT: |
| 3952 | case GL_STENCIL_ATTACHMENT: |
| 3953 | break; |
| 3954 | |
| 3955 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 3956 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3957 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3958 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3959 | return false; |
| 3960 | } |
| 3961 | break; |
| 3962 | |
| 3963 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3964 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3965 | return false; |
| 3966 | } |
| 3967 | } |
| 3968 | } |
| 3969 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 3970 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3971 | if (attachmentObject) |
| 3972 | { |
| 3973 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 3974 | attachmentObject->type() == GL_TEXTURE || |
| 3975 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 3976 | |
| 3977 | switch (pname) |
| 3978 | { |
| 3979 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 3980 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 3981 | attachmentObject->type() != GL_TEXTURE) |
| 3982 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3983 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3984 | return false; |
| 3985 | } |
| 3986 | break; |
| 3987 | |
| 3988 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 3989 | if (attachmentObject->type() != GL_TEXTURE) |
| 3990 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3991 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 3992 | return false; |
| 3993 | } |
| 3994 | break; |
| 3995 | |
| 3996 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 3997 | if (attachmentObject->type() != GL_TEXTURE) |
| 3998 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3999 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4000 | return false; |
| 4001 | } |
| 4002 | break; |
| 4003 | |
| 4004 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4005 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4006 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4007 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4008 | return false; |
| 4009 | } |
| 4010 | break; |
| 4011 | |
| 4012 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4013 | if (attachmentObject->type() != GL_TEXTURE) |
| 4014 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4015 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4016 | return false; |
| 4017 | } |
| 4018 | break; |
| 4019 | |
| 4020 | default: |
| 4021 | break; |
| 4022 | } |
| 4023 | } |
| 4024 | else |
| 4025 | { |
| 4026 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4027 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4028 | |
| 4029 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4030 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4031 | // INVALID_OPERATION for all other pnames |
| 4032 | |
| 4033 | switch (pname) |
| 4034 | { |
| 4035 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4036 | break; |
| 4037 | |
| 4038 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4039 | if (clientVersion < 3) |
| 4040 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4041 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4042 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4043 | return false; |
| 4044 | } |
| 4045 | break; |
| 4046 | |
| 4047 | default: |
| 4048 | if (clientVersion < 3) |
| 4049 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4050 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4051 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4052 | return false; |
| 4053 | } |
| 4054 | else |
| 4055 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4056 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4057 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4058 | return false; |
| 4059 | } |
| 4060 | } |
| 4061 | } |
| 4062 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4063 | if (numParams) |
| 4064 | { |
| 4065 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4066 | { |
| 4067 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4068 | // parameters. |
| 4069 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4070 | *numParams = numViews * 2; |
| 4071 | } |
| 4072 | else |
| 4073 | { |
| 4074 | // For all other queries we can have only one output parameter. |
| 4075 | *numParams = 1; |
| 4076 | } |
| 4077 | } |
| 4078 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4079 | return true; |
| 4080 | } |
| 4081 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4082 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4083 | GLenum target, |
| 4084 | GLenum attachment, |
| 4085 | GLenum pname, |
| 4086 | GLsizei bufSize, |
| 4087 | GLsizei *numParams) |
| 4088 | { |
| 4089 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4090 | { |
| 4091 | return false; |
| 4092 | } |
| 4093 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4094 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
| 4095 | numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4096 | { |
| 4097 | return false; |
| 4098 | } |
| 4099 | |
| 4100 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
| 4101 | { |
| 4102 | return false; |
| 4103 | } |
| 4104 | |
| 4105 | return true; |
| 4106 | } |
| 4107 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4108 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4109 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4110 | GLenum pname, |
| 4111 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4112 | GLsizei *length, |
| 4113 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4114 | { |
| 4115 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4116 | { |
| 4117 | return false; |
| 4118 | } |
| 4119 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4120 | if (!ValidateGetBufferParameterBase(context, target, pname, false, length)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4121 | { |
| 4122 | return false; |
| 4123 | } |
| 4124 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4125 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4126 | { |
| 4127 | return false; |
| 4128 | } |
| 4129 | |
| 4130 | return true; |
| 4131 | } |
| 4132 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4133 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4134 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4135 | GLenum pname, |
| 4136 | GLsizei bufSize, |
| 4137 | GLsizei *length, |
| 4138 | GLint64 *params) |
| 4139 | { |
| 4140 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4141 | { |
| 4142 | return false; |
| 4143 | } |
| 4144 | |
| 4145 | if (!ValidateGetBufferParameterBase(context, target, pname, false, length)) |
| 4146 | { |
| 4147 | return false; |
| 4148 | } |
| 4149 | |
| 4150 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4151 | { |
| 4152 | return false; |
| 4153 | } |
| 4154 | |
| 4155 | return true; |
| 4156 | } |
| 4157 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4158 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4159 | { |
| 4160 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4161 | if (numParams) |
| 4162 | { |
| 4163 | *numParams = 1; |
| 4164 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4165 | |
| 4166 | Program *programObject = GetValidProgram(context, program); |
| 4167 | if (!programObject) |
| 4168 | { |
| 4169 | return false; |
| 4170 | } |
| 4171 | |
| 4172 | switch (pname) |
| 4173 | { |
| 4174 | case GL_DELETE_STATUS: |
| 4175 | case GL_LINK_STATUS: |
| 4176 | case GL_VALIDATE_STATUS: |
| 4177 | case GL_INFO_LOG_LENGTH: |
| 4178 | case GL_ATTACHED_SHADERS: |
| 4179 | case GL_ACTIVE_ATTRIBUTES: |
| 4180 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4181 | case GL_ACTIVE_UNIFORMS: |
| 4182 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4183 | break; |
| 4184 | |
| 4185 | case GL_PROGRAM_BINARY_LENGTH: |
| 4186 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4187 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4188 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4189 | "requires GL_OES_get_program_binary or " |
| 4190 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | break; |
| 4194 | |
| 4195 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4196 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4197 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4198 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4199 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4200 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4201 | if (context->getClientMajorVersion() < 3) |
| 4202 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4203 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4204 | return false; |
| 4205 | } |
| 4206 | break; |
| 4207 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4208 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4209 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4210 | if (context->getClientVersion() < Version(3, 1)) |
| 4211 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4212 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4213 | return false; |
| 4214 | } |
| 4215 | break; |
| 4216 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4217 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4218 | if (context->getClientVersion() < Version(3, 1)) |
| 4219 | { |
| 4220 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4221 | return false; |
| 4222 | } |
| 4223 | |
| 4224 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4225 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4226 | // program which has not been linked successfully, or which does not contain objects to |
| 4227 | // form a compute shader. |
| 4228 | if (!programObject->isLinked()) |
| 4229 | { |
| 4230 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4231 | return false; |
| 4232 | } |
| 4233 | if (!programObject->hasLinkedComputeShader()) |
| 4234 | { |
| 4235 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4236 | return false; |
| 4237 | } |
| 4238 | break; |
| 4239 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4240 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4241 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4242 | return false; |
| 4243 | } |
| 4244 | |
| 4245 | return true; |
| 4246 | } |
| 4247 | |
| 4248 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4249 | GLuint program, |
| 4250 | GLenum pname, |
| 4251 | GLsizei bufSize, |
| 4252 | GLsizei *numParams) |
| 4253 | { |
| 4254 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4255 | { |
| 4256 | return false; |
| 4257 | } |
| 4258 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4259 | if (!ValidateGetProgramivBase(context, program, pname, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4260 | { |
| 4261 | return false; |
| 4262 | } |
| 4263 | |
| 4264 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
| 4265 | { |
| 4266 | return false; |
| 4267 | } |
| 4268 | |
| 4269 | return true; |
| 4270 | } |
| 4271 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4272 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4273 | GLenum target, |
| 4274 | GLenum pname, |
| 4275 | GLsizei bufSize, |
| 4276 | GLsizei *length, |
| 4277 | GLint *params) |
| 4278 | { |
| 4279 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4280 | { |
| 4281 | return false; |
| 4282 | } |
| 4283 | |
| 4284 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, length)) |
| 4285 | { |
| 4286 | return false; |
| 4287 | } |
| 4288 | |
| 4289 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4290 | { |
| 4291 | return false; |
| 4292 | } |
| 4293 | |
| 4294 | return true; |
| 4295 | } |
| 4296 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4297 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4298 | GLuint shader, |
| 4299 | GLenum pname, |
| 4300 | GLsizei bufSize, |
| 4301 | GLsizei *length, |
| 4302 | GLint *params) |
| 4303 | { |
| 4304 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4305 | { |
| 4306 | return false; |
| 4307 | } |
| 4308 | |
| 4309 | if (!ValidateGetShaderivBase(context, shader, pname, length)) |
| 4310 | { |
| 4311 | return false; |
| 4312 | } |
| 4313 | |
| 4314 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4315 | { |
| 4316 | return false; |
| 4317 | } |
| 4318 | |
| 4319 | return true; |
| 4320 | } |
| 4321 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4322 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4323 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4324 | GLenum pname, |
| 4325 | GLsizei bufSize, |
| 4326 | GLsizei *length, |
| 4327 | GLfloat *params) |
| 4328 | { |
| 4329 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4330 | { |
| 4331 | return false; |
| 4332 | } |
| 4333 | |
| 4334 | if (!ValidateGetTexParameterBase(context, target, pname, length)) |
| 4335 | { |
| 4336 | return false; |
| 4337 | } |
| 4338 | |
| 4339 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4340 | { |
| 4341 | return false; |
| 4342 | } |
| 4343 | |
| 4344 | return true; |
| 4345 | } |
| 4346 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4347 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4348 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4349 | GLenum pname, |
| 4350 | GLsizei bufSize, |
| 4351 | GLsizei *length, |
| 4352 | GLint *params) |
| 4353 | { |
| 4354 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4355 | { |
| 4356 | return false; |
| 4357 | } |
| 4358 | |
| 4359 | if (!ValidateGetTexParameterBase(context, target, pname, length)) |
| 4360 | { |
| 4361 | return false; |
| 4362 | } |
| 4363 | |
| 4364 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4365 | { |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
| 4369 | return true; |
| 4370 | } |
| 4371 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4372 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4373 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4374 | GLenum pname, |
| 4375 | GLsizei bufSize, |
| 4376 | const GLfloat *params) |
| 4377 | { |
| 4378 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4379 | { |
| 4380 | return false; |
| 4381 | } |
| 4382 | |
| 4383 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4384 | } |
| 4385 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4386 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4387 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4388 | GLenum pname, |
| 4389 | GLsizei bufSize, |
| 4390 | const GLint *params) |
| 4391 | { |
| 4392 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4393 | { |
| 4394 | return false; |
| 4395 | } |
| 4396 | |
| 4397 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4398 | } |
| 4399 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4400 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4401 | GLuint sampler, |
| 4402 | GLenum pname, |
| 4403 | GLuint bufSize, |
| 4404 | GLsizei *length, |
| 4405 | GLfloat *params) |
| 4406 | { |
| 4407 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4408 | { |
| 4409 | return false; |
| 4410 | } |
| 4411 | |
| 4412 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, length)) |
| 4413 | { |
| 4414 | return false; |
| 4415 | } |
| 4416 | |
| 4417 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4418 | { |
| 4419 | return false; |
| 4420 | } |
| 4421 | |
| 4422 | return true; |
| 4423 | } |
| 4424 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4425 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4426 | GLuint sampler, |
| 4427 | GLenum pname, |
| 4428 | GLuint bufSize, |
| 4429 | GLsizei *length, |
| 4430 | GLint *params) |
| 4431 | { |
| 4432 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4433 | { |
| 4434 | return false; |
| 4435 | } |
| 4436 | |
| 4437 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, length)) |
| 4438 | { |
| 4439 | return false; |
| 4440 | } |
| 4441 | |
| 4442 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4443 | { |
| 4444 | return false; |
| 4445 | } |
| 4446 | |
| 4447 | return true; |
| 4448 | } |
| 4449 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4450 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4451 | GLuint sampler, |
| 4452 | GLenum pname, |
| 4453 | GLsizei bufSize, |
| 4454 | const GLfloat *params) |
| 4455 | { |
| 4456 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4457 | { |
| 4458 | return false; |
| 4459 | } |
| 4460 | |
| 4461 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4462 | } |
| 4463 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4464 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4465 | GLuint sampler, |
| 4466 | GLenum pname, |
| 4467 | GLsizei bufSize, |
| 4468 | const GLint *params) |
| 4469 | { |
| 4470 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4471 | { |
| 4472 | return false; |
| 4473 | } |
| 4474 | |
| 4475 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4476 | } |
| 4477 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4478 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4479 | GLuint index, |
| 4480 | GLenum pname, |
| 4481 | GLsizei bufSize, |
| 4482 | GLsizei *length, |
| 4483 | GLfloat *params) |
| 4484 | { |
| 4485 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4486 | { |
| 4487 | return false; |
| 4488 | } |
| 4489 | |
| 4490 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, false)) |
| 4491 | { |
| 4492 | return false; |
| 4493 | } |
| 4494 | |
| 4495 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4496 | { |
| 4497 | return false; |
| 4498 | } |
| 4499 | |
| 4500 | return true; |
| 4501 | } |
| 4502 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4503 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4504 | GLuint index, |
| 4505 | GLenum pname, |
| 4506 | GLsizei bufSize, |
| 4507 | GLsizei *length, |
| 4508 | GLint *params) |
| 4509 | { |
| 4510 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4511 | { |
| 4512 | return false; |
| 4513 | } |
| 4514 | |
| 4515 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, false)) |
| 4516 | { |
| 4517 | return false; |
| 4518 | } |
| 4519 | |
| 4520 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4521 | { |
| 4522 | return false; |
| 4523 | } |
| 4524 | |
| 4525 | return true; |
| 4526 | } |
| 4527 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4528 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4529 | GLuint index, |
| 4530 | GLenum pname, |
| 4531 | GLsizei bufSize, |
| 4532 | GLsizei *length, |
| 4533 | void **pointer) |
| 4534 | { |
| 4535 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4536 | { |
| 4537 | return false; |
| 4538 | } |
| 4539 | |
| 4540 | if (!ValidateGetVertexAttribBase(context, index, pname, length, true, false)) |
| 4541 | { |
| 4542 | return false; |
| 4543 | } |
| 4544 | |
| 4545 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4546 | { |
| 4547 | return false; |
| 4548 | } |
| 4549 | |
| 4550 | return true; |
| 4551 | } |
| 4552 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4553 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4554 | GLuint index, |
| 4555 | GLenum pname, |
| 4556 | GLsizei bufSize, |
| 4557 | GLsizei *length, |
| 4558 | GLint *params) |
| 4559 | { |
| 4560 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4561 | { |
| 4562 | return false; |
| 4563 | } |
| 4564 | |
| 4565 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, true)) |
| 4566 | { |
| 4567 | return false; |
| 4568 | } |
| 4569 | |
| 4570 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4571 | { |
| 4572 | return false; |
| 4573 | } |
| 4574 | |
| 4575 | return true; |
| 4576 | } |
| 4577 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4578 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 4579 | GLuint index, |
| 4580 | GLenum pname, |
| 4581 | GLsizei bufSize, |
| 4582 | GLsizei *length, |
| 4583 | GLuint *params) |
| 4584 | { |
| 4585 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4586 | { |
| 4587 | return false; |
| 4588 | } |
| 4589 | |
| 4590 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, true)) |
| 4591 | { |
| 4592 | return false; |
| 4593 | } |
| 4594 | |
| 4595 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4596 | { |
| 4597 | return false; |
| 4598 | } |
| 4599 | |
| 4600 | return true; |
| 4601 | } |
| 4602 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 4603 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 4604 | GLuint program, |
| 4605 | GLuint uniformBlockIndex, |
| 4606 | GLenum pname, |
| 4607 | GLsizei bufSize, |
| 4608 | GLsizei *length, |
| 4609 | GLint *params) |
| 4610 | { |
| 4611 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4612 | { |
| 4613 | return false; |
| 4614 | } |
| 4615 | |
| 4616 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, length)) |
| 4617 | { |
| 4618 | return false; |
| 4619 | } |
| 4620 | |
| 4621 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4622 | { |
| 4623 | return false; |
| 4624 | } |
| 4625 | |
| 4626 | return true; |
| 4627 | } |
| 4628 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 4629 | bool ValidateGetInternalFormativRobustANGLE(Context *context, |
| 4630 | GLenum target, |
| 4631 | GLenum internalformat, |
| 4632 | GLenum pname, |
| 4633 | GLsizei bufSize, |
| 4634 | GLsizei *length, |
| 4635 | GLint *params) |
| 4636 | { |
| 4637 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4638 | { |
| 4639 | return false; |
| 4640 | } |
| 4641 | |
| 4642 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, length)) |
| 4643 | { |
| 4644 | return false; |
| 4645 | } |
| 4646 | |
| 4647 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4648 | { |
| 4649 | return false; |
| 4650 | } |
| 4651 | |
| 4652 | return true; |
| 4653 | } |
| 4654 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4655 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4656 | GLuint attribIndex, |
| 4657 | GLint size, |
| 4658 | GLenum type, |
| 4659 | GLboolean pureInteger) |
| 4660 | { |
| 4661 | const Caps &caps = context->getCaps(); |
| 4662 | if (attribIndex >= caps.maxVertexAttributes) |
| 4663 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4664 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4665 | return false; |
| 4666 | } |
| 4667 | |
| 4668 | if (size < 1 || size > 4) |
| 4669 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4670 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 4671 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4672 | } |
| 4673 | |
| 4674 | switch (type) |
| 4675 | { |
| 4676 | case GL_BYTE: |
| 4677 | case GL_UNSIGNED_BYTE: |
| 4678 | case GL_SHORT: |
| 4679 | case GL_UNSIGNED_SHORT: |
| 4680 | break; |
| 4681 | |
| 4682 | case GL_INT: |
| 4683 | case GL_UNSIGNED_INT: |
| 4684 | if (context->getClientMajorVersion() < 3) |
| 4685 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4686 | context->handleError(InvalidEnum() |
| 4687 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4688 | return false; |
| 4689 | } |
| 4690 | break; |
| 4691 | |
| 4692 | case GL_FIXED: |
| 4693 | case GL_FLOAT: |
| 4694 | if (pureInteger) |
| 4695 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4696 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4697 | return false; |
| 4698 | } |
| 4699 | break; |
| 4700 | |
| 4701 | case GL_HALF_FLOAT: |
| 4702 | if (context->getClientMajorVersion() < 3) |
| 4703 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4704 | context->handleError(InvalidEnum() |
| 4705 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4706 | return false; |
| 4707 | } |
| 4708 | if (pureInteger) |
| 4709 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4710 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4711 | return false; |
| 4712 | } |
| 4713 | break; |
| 4714 | |
| 4715 | case GL_INT_2_10_10_10_REV: |
| 4716 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 4717 | if (context->getClientMajorVersion() < 3) |
| 4718 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4719 | context->handleError(InvalidEnum() |
| 4720 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4721 | return false; |
| 4722 | } |
| 4723 | if (pureInteger) |
| 4724 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4725 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4726 | return false; |
| 4727 | } |
| 4728 | if (size != 4) |
| 4729 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4730 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 4731 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 4732 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4733 | return false; |
| 4734 | } |
| 4735 | break; |
| 4736 | |
| 4737 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4738 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 4739 | return false; |
| 4740 | } |
| 4741 | |
| 4742 | return true; |
| 4743 | } |
| 4744 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4745 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 4746 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 4747 | // specified clear value and the type of a buffer that is being cleared generates an |
| 4748 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4749 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4750 | GLint drawbuffer, |
| 4751 | const GLenum *validComponentTypes, |
| 4752 | size_t validComponentTypeCount) |
| 4753 | { |
| 4754 | const FramebufferAttachment *attachment = |
| 4755 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 4756 | if (attachment) |
| 4757 | { |
| 4758 | GLenum componentType = attachment->getFormat().info->componentType; |
| 4759 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 4760 | if (std::find(validComponentTypes, end, componentType) == end) |
| 4761 | { |
| 4762 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4763 | InvalidOperation() |
| 4764 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 4765 | return false; |
| 4766 | } |
| 4767 | } |
| 4768 | |
| 4769 | return true; |
| 4770 | } |
| 4771 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4772 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4773 | { |
| 4774 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 4775 | { |
| 4776 | return false; |
| 4777 | } |
| 4778 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4779 | gl::Buffer *pixelUnpackBuffer = |
| 4780 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4781 | if (pixelUnpackBuffer == nullptr) |
| 4782 | { |
| 4783 | if (dataSize < imageSize) |
| 4784 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4785 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 4786 | } |
| 4787 | } |
| 4788 | return true; |
| 4789 | } |
| 4790 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4791 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4792 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4793 | GLenum pname, |
| 4794 | bool pointerVersion, |
| 4795 | GLsizei *numParams) |
| 4796 | { |
| 4797 | if (numParams) |
| 4798 | { |
| 4799 | *numParams = 0; |
| 4800 | } |
| 4801 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4802 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4803 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4804 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4805 | return false; |
| 4806 | } |
| 4807 | |
| 4808 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 4809 | if (!buffer) |
| 4810 | { |
| 4811 | // A null buffer means that "0" is bound to the requested buffer target |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4812 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4813 | return false; |
| 4814 | } |
| 4815 | |
| 4816 | const Extensions &extensions = context->getExtensions(); |
| 4817 | |
| 4818 | switch (pname) |
| 4819 | { |
| 4820 | case GL_BUFFER_USAGE: |
| 4821 | case GL_BUFFER_SIZE: |
| 4822 | break; |
| 4823 | |
| 4824 | case GL_BUFFER_ACCESS_OES: |
| 4825 | if (!extensions.mapBuffer) |
| 4826 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4827 | context->handleError(InvalidEnum() |
| 4828 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4829 | return false; |
| 4830 | } |
| 4831 | break; |
| 4832 | |
| 4833 | case GL_BUFFER_MAPPED: |
| 4834 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 4835 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 4836 | !extensions.mapBufferRange) |
| 4837 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4838 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 4839 | "GL_OES_mapbuffer or " |
| 4840 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4841 | return false; |
| 4842 | } |
| 4843 | break; |
| 4844 | |
| 4845 | case GL_BUFFER_MAP_POINTER: |
| 4846 | if (!pointerVersion) |
| 4847 | { |
| 4848 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4849 | InvalidEnum() |
| 4850 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4851 | return false; |
| 4852 | } |
| 4853 | break; |
| 4854 | |
| 4855 | case GL_BUFFER_ACCESS_FLAGS: |
| 4856 | case GL_BUFFER_MAP_OFFSET: |
| 4857 | case GL_BUFFER_MAP_LENGTH: |
| 4858 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 4859 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4860 | context->handleError(InvalidEnum() |
| 4861 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4862 | return false; |
| 4863 | } |
| 4864 | break; |
| 4865 | |
| 4866 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4867 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4868 | return false; |
| 4869 | } |
| 4870 | |
| 4871 | // All buffer parameter queries return one value. |
| 4872 | if (numParams) |
| 4873 | { |
| 4874 | *numParams = 1; |
| 4875 | } |
| 4876 | |
| 4877 | return true; |
| 4878 | } |
| 4879 | |
| 4880 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 4881 | GLenum target, |
| 4882 | GLenum pname, |
| 4883 | GLsizei *length) |
| 4884 | { |
| 4885 | if (length) |
| 4886 | { |
| 4887 | *length = 0; |
| 4888 | } |
| 4889 | |
| 4890 | if (target != GL_RENDERBUFFER) |
| 4891 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4892 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4893 | return false; |
| 4894 | } |
| 4895 | |
| 4896 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 4897 | if (renderbuffer == nullptr) |
| 4898 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4899 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4900 | return false; |
| 4901 | } |
| 4902 | |
| 4903 | switch (pname) |
| 4904 | { |
| 4905 | case GL_RENDERBUFFER_WIDTH: |
| 4906 | case GL_RENDERBUFFER_HEIGHT: |
| 4907 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 4908 | case GL_RENDERBUFFER_RED_SIZE: |
| 4909 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 4910 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 4911 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 4912 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 4913 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 4914 | break; |
| 4915 | |
| 4916 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 4917 | if (!context->getExtensions().framebufferMultisample) |
| 4918 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4919 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4920 | return false; |
| 4921 | } |
| 4922 | break; |
| 4923 | |
| 4924 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4925 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4926 | return false; |
| 4927 | } |
| 4928 | |
| 4929 | if (length) |
| 4930 | { |
| 4931 | *length = 1; |
| 4932 | } |
| 4933 | return true; |
| 4934 | } |
| 4935 | |
| 4936 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 4937 | { |
| 4938 | if (length) |
| 4939 | { |
| 4940 | *length = 0; |
| 4941 | } |
| 4942 | |
| 4943 | if (GetValidShader(context, shader) == nullptr) |
| 4944 | { |
| 4945 | return false; |
| 4946 | } |
| 4947 | |
| 4948 | switch (pname) |
| 4949 | { |
| 4950 | case GL_SHADER_TYPE: |
| 4951 | case GL_DELETE_STATUS: |
| 4952 | case GL_COMPILE_STATUS: |
| 4953 | case GL_INFO_LOG_LENGTH: |
| 4954 | case GL_SHADER_SOURCE_LENGTH: |
| 4955 | break; |
| 4956 | |
| 4957 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 4958 | if (!context->getExtensions().translatedShaderSource) |
| 4959 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4960 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4961 | return false; |
| 4962 | } |
| 4963 | break; |
| 4964 | |
| 4965 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4966 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4967 | return false; |
| 4968 | } |
| 4969 | |
| 4970 | if (length) |
| 4971 | { |
| 4972 | *length = 1; |
| 4973 | } |
| 4974 | return true; |
| 4975 | } |
| 4976 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4977 | bool ValidateGetTexParameterBase(Context *context, |
| 4978 | TextureType target, |
| 4979 | GLenum pname, |
| 4980 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4981 | { |
| 4982 | if (length) |
| 4983 | { |
| 4984 | *length = 0; |
| 4985 | } |
| 4986 | |
| 4987 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 4988 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4989 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4990 | return false; |
| 4991 | } |
| 4992 | |
| 4993 | if (context->getTargetTexture(target) == nullptr) |
| 4994 | { |
| 4995 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4996 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4997 | return false; |
| 4998 | } |
| 4999 | |
| 5000 | switch (pname) |
| 5001 | { |
| 5002 | case GL_TEXTURE_MAG_FILTER: |
| 5003 | case GL_TEXTURE_MIN_FILTER: |
| 5004 | case GL_TEXTURE_WRAP_S: |
| 5005 | case GL_TEXTURE_WRAP_T: |
| 5006 | break; |
| 5007 | |
| 5008 | case GL_TEXTURE_USAGE_ANGLE: |
| 5009 | if (!context->getExtensions().textureUsage) |
| 5010 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5011 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5012 | return false; |
| 5013 | } |
| 5014 | break; |
| 5015 | |
| 5016 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5017 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5018 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5019 | return false; |
| 5020 | } |
| 5021 | break; |
| 5022 | |
| 5023 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5024 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5025 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5026 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5027 | return false; |
| 5028 | } |
| 5029 | break; |
| 5030 | |
| 5031 | case GL_TEXTURE_WRAP_R: |
| 5032 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5033 | case GL_TEXTURE_SWIZZLE_R: |
| 5034 | case GL_TEXTURE_SWIZZLE_G: |
| 5035 | case GL_TEXTURE_SWIZZLE_B: |
| 5036 | case GL_TEXTURE_SWIZZLE_A: |
| 5037 | case GL_TEXTURE_BASE_LEVEL: |
| 5038 | case GL_TEXTURE_MAX_LEVEL: |
| 5039 | case GL_TEXTURE_MIN_LOD: |
| 5040 | case GL_TEXTURE_MAX_LOD: |
| 5041 | case GL_TEXTURE_COMPARE_MODE: |
| 5042 | case GL_TEXTURE_COMPARE_FUNC: |
| 5043 | if (context->getClientMajorVersion() < 3) |
| 5044 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5045 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5046 | return false; |
| 5047 | } |
| 5048 | break; |
| 5049 | |
| 5050 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5051 | if (!context->getExtensions().textureSRGBDecode) |
| 5052 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5053 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5054 | return false; |
| 5055 | } |
| 5056 | break; |
| 5057 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5058 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5059 | if (context->getClientVersion() < Version(3, 1)) |
| 5060 | { |
| 5061 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5062 | return false; |
| 5063 | } |
| 5064 | break; |
| 5065 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5066 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5067 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5068 | return false; |
| 5069 | } |
| 5070 | |
| 5071 | if (length) |
| 5072 | { |
| 5073 | *length = 1; |
| 5074 | } |
| 5075 | return true; |
| 5076 | } |
| 5077 | |
| 5078 | bool ValidateGetVertexAttribBase(Context *context, |
| 5079 | GLuint index, |
| 5080 | GLenum pname, |
| 5081 | GLsizei *length, |
| 5082 | bool pointer, |
| 5083 | bool pureIntegerEntryPoint) |
| 5084 | { |
| 5085 | if (length) |
| 5086 | { |
| 5087 | *length = 0; |
| 5088 | } |
| 5089 | |
| 5090 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5091 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5092 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5093 | return false; |
| 5094 | } |
| 5095 | |
| 5096 | if (index >= context->getCaps().maxVertexAttributes) |
| 5097 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5098 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5099 | return false; |
| 5100 | } |
| 5101 | |
| 5102 | if (pointer) |
| 5103 | { |
| 5104 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5105 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5106 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5107 | return false; |
| 5108 | } |
| 5109 | } |
| 5110 | else |
| 5111 | { |
| 5112 | switch (pname) |
| 5113 | { |
| 5114 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5115 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5116 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5117 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5118 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5119 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5120 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5121 | break; |
| 5122 | |
| 5123 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5124 | static_assert( |
| 5125 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5126 | "ANGLE extension enums not equal to GL enums."); |
| 5127 | if (context->getClientMajorVersion() < 3 && |
| 5128 | !context->getExtensions().instancedArrays) |
| 5129 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5130 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5131 | "requires OpenGL ES 3.0 or " |
| 5132 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5133 | return false; |
| 5134 | } |
| 5135 | break; |
| 5136 | |
| 5137 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5138 | if (context->getClientMajorVersion() < 3) |
| 5139 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5140 | context->handleError( |
| 5141 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5142 | return false; |
| 5143 | } |
| 5144 | break; |
| 5145 | |
| 5146 | case GL_VERTEX_ATTRIB_BINDING: |
| 5147 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5148 | if (context->getClientVersion() < ES_3_1) |
| 5149 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5150 | context->handleError(InvalidEnum() |
| 5151 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5152 | return false; |
| 5153 | } |
| 5154 | break; |
| 5155 | |
| 5156 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5157 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5158 | return false; |
| 5159 | } |
| 5160 | } |
| 5161 | |
| 5162 | if (length) |
| 5163 | { |
| 5164 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5165 | { |
| 5166 | *length = 4; |
| 5167 | } |
| 5168 | else |
| 5169 | { |
| 5170 | *length = 1; |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | return true; |
| 5175 | } |
| 5176 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5177 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5178 | GLint x, |
| 5179 | GLint y, |
| 5180 | GLsizei width, |
| 5181 | GLsizei height, |
| 5182 | GLenum format, |
| 5183 | GLenum type, |
| 5184 | GLsizei bufSize, |
| 5185 | GLsizei *length, |
| 5186 | GLsizei *columns, |
| 5187 | GLsizei *rows, |
| 5188 | void *pixels) |
| 5189 | { |
| 5190 | if (length != nullptr) |
| 5191 | { |
| 5192 | *length = 0; |
| 5193 | } |
| 5194 | if (rows != nullptr) |
| 5195 | { |
| 5196 | *rows = 0; |
| 5197 | } |
| 5198 | if (columns != nullptr) |
| 5199 | { |
| 5200 | *columns = 0; |
| 5201 | } |
| 5202 | |
| 5203 | if (width < 0 || height < 0) |
| 5204 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5205 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5206 | return false; |
| 5207 | } |
| 5208 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5209 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5210 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5211 | if (!ValidateFramebufferComplete(context, readFramebuffer, true)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5212 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5213 | return false; |
| 5214 | } |
| 5215 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5216 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5217 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5218 | return false; |
| 5219 | } |
| 5220 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5221 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5222 | ASSERT(framebuffer); |
| 5223 | |
| 5224 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5225 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5226 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5227 | return false; |
| 5228 | } |
| 5229 | |
| 5230 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5231 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5232 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5233 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5234 | // situation is an application error that would lead to a crash in ANGLE. |
| 5235 | if (readBuffer == nullptr) |
| 5236 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5237 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5238 | return false; |
| 5239 | } |
| 5240 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5241 | // ANGLE_multiview, Revision 1: |
| 5242 | // ReadPixels generates an INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the |
| 5243 | // current read framebuffer is not NONE. |
| 5244 | if (readBuffer->getMultiviewLayout() != GL_NONE) |
| 5245 | { |
| 5246 | context->handleError(InvalidFramebufferOperation() |
| 5247 | << "Attempting to read from a multi-view framebuffer."); |
| 5248 | return false; |
| 5249 | } |
| 5250 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5251 | if (context->getExtensions().webglCompatibility) |
| 5252 | { |
| 5253 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5254 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5255 | // and type before validating the combination of format and type. However, the |
| 5256 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5257 | // verifies that GL_INVALID_OPERATION is generated. |
| 5258 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5259 | // dEQP/WebGL. |
| 5260 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5261 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5262 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5263 | return false; |
| 5264 | } |
| 5265 | |
| 5266 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5267 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5268 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5269 | return false; |
| 5270 | } |
| 5271 | } |
| 5272 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5273 | GLenum currentFormat = GL_NONE; |
| 5274 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5275 | |
| 5276 | GLenum currentType = GL_NONE; |
| 5277 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5278 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5279 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5280 | |
| 5281 | bool validFormatTypeCombination = |
| 5282 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5283 | |
| 5284 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5285 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5286 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5287 | return false; |
| 5288 | } |
| 5289 | |
| 5290 | // Check for pixel pack buffer related API errors |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5291 | gl::Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5292 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5293 | { |
| 5294 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5295 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5296 | return false; |
| 5297 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5298 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5299 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5300 | { |
| 5301 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5302 | return false; |
| 5303 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5304 | |
| 5305 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5306 | // would exceed the data store size. |
| 5307 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
| 5308 | const gl::Extents size(width, height, 1); |
| 5309 | const auto &pack = context->getGLState().getPackState(); |
| 5310 | |
| 5311 | auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, pack, false); |
| 5312 | if (endByteOrErr.isError()) |
| 5313 | { |
| 5314 | context->handleError(endByteOrErr.getError()); |
| 5315 | return false; |
| 5316 | } |
| 5317 | |
| 5318 | size_t endByte = endByteOrErr.getResult(); |
| 5319 | if (bufSize >= 0) |
| 5320 | { |
| 5321 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5322 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5323 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5324 | return false; |
| 5325 | } |
| 5326 | } |
| 5327 | |
| 5328 | if (pixelPackBuffer != nullptr) |
| 5329 | { |
| 5330 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5331 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5332 | checkedEndByte += checkedOffset; |
| 5333 | |
| 5334 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5335 | { |
| 5336 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5338 | return false; |
| 5339 | } |
| 5340 | } |
| 5341 | |
| 5342 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5343 | { |
| 5344 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5345 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5346 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5347 | return false; |
| 5348 | } |
| 5349 | |
| 5350 | *length = static_cast<GLsizei>(endByte); |
| 5351 | } |
| 5352 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5353 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5354 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5355 | if (start < 0) |
| 5356 | { |
| 5357 | // "subtract" the area that is less than 0 |
| 5358 | clippedExtent += start; |
| 5359 | } |
| 5360 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5361 | angle::CheckedNumeric<int> readExtent = start; |
| 5362 | readExtent += length; |
| 5363 | if (!readExtent.IsValid()) |
| 5364 | { |
| 5365 | return false; |
| 5366 | } |
| 5367 | |
| 5368 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5369 | { |
| 5370 | // Subtract the region to the right of the read buffer |
| 5371 | clippedExtent -= (readExtent - bufferSize); |
| 5372 | } |
| 5373 | |
| 5374 | if (!clippedExtent.IsValid()) |
| 5375 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5376 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5377 | } |
| 5378 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5379 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5380 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5381 | }; |
| 5382 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5383 | GLsizei writtenColumns = 0; |
| 5384 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5385 | { |
| 5386 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5387 | return false; |
| 5388 | } |
| 5389 | |
| 5390 | GLsizei writtenRows = 0; |
| 5391 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5392 | { |
| 5393 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5394 | return false; |
| 5395 | } |
| 5396 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5397 | if (columns != nullptr) |
| 5398 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5399 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5400 | } |
| 5401 | |
| 5402 | if (rows != nullptr) |
| 5403 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5404 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5405 | } |
| 5406 | |
| 5407 | return true; |
| 5408 | } |
| 5409 | |
| 5410 | template <typename ParamType> |
| 5411 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5412 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5413 | GLenum pname, |
| 5414 | GLsizei bufSize, |
| 5415 | const ParamType *params) |
| 5416 | { |
| 5417 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5418 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5419 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5420 | return false; |
| 5421 | } |
| 5422 | |
| 5423 | if (context->getTargetTexture(target) == nullptr) |
| 5424 | { |
| 5425 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5426 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5427 | return false; |
| 5428 | } |
| 5429 | |
| 5430 | const GLsizei minBufSize = 1; |
| 5431 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5432 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5433 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5434 | return false; |
| 5435 | } |
| 5436 | |
| 5437 | switch (pname) |
| 5438 | { |
| 5439 | case GL_TEXTURE_WRAP_R: |
| 5440 | case GL_TEXTURE_SWIZZLE_R: |
| 5441 | case GL_TEXTURE_SWIZZLE_G: |
| 5442 | case GL_TEXTURE_SWIZZLE_B: |
| 5443 | case GL_TEXTURE_SWIZZLE_A: |
| 5444 | case GL_TEXTURE_BASE_LEVEL: |
| 5445 | case GL_TEXTURE_MAX_LEVEL: |
| 5446 | case GL_TEXTURE_COMPARE_MODE: |
| 5447 | case GL_TEXTURE_COMPARE_FUNC: |
| 5448 | case GL_TEXTURE_MIN_LOD: |
| 5449 | case GL_TEXTURE_MAX_LOD: |
| 5450 | if (context->getClientMajorVersion() < 3) |
| 5451 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5452 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5453 | return false; |
| 5454 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5455 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5456 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5457 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5458 | "available without " |
| 5459 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5460 | return false; |
| 5461 | } |
| 5462 | break; |
| 5463 | |
| 5464 | default: |
| 5465 | break; |
| 5466 | } |
| 5467 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5468 | if (target == TextureType::_2DMultisample) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5469 | { |
| 5470 | switch (pname) |
| 5471 | { |
| 5472 | case GL_TEXTURE_MIN_FILTER: |
| 5473 | case GL_TEXTURE_MAG_FILTER: |
| 5474 | case GL_TEXTURE_WRAP_S: |
| 5475 | case GL_TEXTURE_WRAP_T: |
| 5476 | case GL_TEXTURE_WRAP_R: |
| 5477 | case GL_TEXTURE_MIN_LOD: |
| 5478 | case GL_TEXTURE_MAX_LOD: |
| 5479 | case GL_TEXTURE_COMPARE_MODE: |
| 5480 | case GL_TEXTURE_COMPARE_FUNC: |
| 5481 | context->handleError(InvalidEnum() |
| 5482 | << "Invalid parameter for 2D multisampled textures."); |
| 5483 | return false; |
| 5484 | } |
| 5485 | } |
| 5486 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5487 | switch (pname) |
| 5488 | { |
| 5489 | case GL_TEXTURE_WRAP_S: |
| 5490 | case GL_TEXTURE_WRAP_T: |
| 5491 | case GL_TEXTURE_WRAP_R: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5492 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5493 | bool restrictedWrapModes = |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5494 | target == TextureType::External || target == TextureType::Rectangle; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5495 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
| 5496 | { |
| 5497 | return false; |
| 5498 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5499 | } |
| 5500 | break; |
| 5501 | |
| 5502 | case GL_TEXTURE_MIN_FILTER: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5503 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5504 | bool restrictedMinFilter = |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5505 | target == TextureType::External || target == TextureType::Rectangle; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5506 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
| 5507 | { |
| 5508 | return false; |
| 5509 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5510 | } |
| 5511 | break; |
| 5512 | |
| 5513 | case GL_TEXTURE_MAG_FILTER: |
| 5514 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5515 | { |
| 5516 | return false; |
| 5517 | } |
| 5518 | break; |
| 5519 | |
| 5520 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5521 | if (!context->getExtensions().textureUsage) |
| 5522 | { |
| 5523 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5524 | return false; |
| 5525 | } |
| 5526 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5527 | switch (ConvertToGLenum(params[0])) |
| 5528 | { |
| 5529 | case GL_NONE: |
| 5530 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5531 | break; |
| 5532 | |
| 5533 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5534 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | break; |
| 5538 | |
| 5539 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5540 | { |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5541 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5542 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 5543 | { |
| 5544 | return false; |
| 5545 | } |
| 5546 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5547 | } |
| 5548 | break; |
| 5549 | |
| 5550 | case GL_TEXTURE_MIN_LOD: |
| 5551 | case GL_TEXTURE_MAX_LOD: |
| 5552 | // any value is permissible |
| 5553 | break; |
| 5554 | |
| 5555 | case GL_TEXTURE_COMPARE_MODE: |
| 5556 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5557 | { |
| 5558 | return false; |
| 5559 | } |
| 5560 | break; |
| 5561 | |
| 5562 | case GL_TEXTURE_COMPARE_FUNC: |
| 5563 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5564 | { |
| 5565 | return false; |
| 5566 | } |
| 5567 | break; |
| 5568 | |
| 5569 | case GL_TEXTURE_SWIZZLE_R: |
| 5570 | case GL_TEXTURE_SWIZZLE_G: |
| 5571 | case GL_TEXTURE_SWIZZLE_B: |
| 5572 | case GL_TEXTURE_SWIZZLE_A: |
| 5573 | switch (ConvertToGLenum(params[0])) |
| 5574 | { |
| 5575 | case GL_RED: |
| 5576 | case GL_GREEN: |
| 5577 | case GL_BLUE: |
| 5578 | case GL_ALPHA: |
| 5579 | case GL_ZERO: |
| 5580 | case GL_ONE: |
| 5581 | break; |
| 5582 | |
| 5583 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5584 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5585 | return false; |
| 5586 | } |
| 5587 | break; |
| 5588 | |
| 5589 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5590 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5591 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5592 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5593 | return false; |
| 5594 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5595 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5597 | context->handleError(InvalidOperation() |
| 5598 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5599 | return false; |
| 5600 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5601 | if (target == TextureType::_2DMultisample && static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5602 | { |
| 5603 | context->handleError(InvalidOperation() |
| 5604 | << "Base level must be 0 for multisampled textures."); |
| 5605 | return false; |
| 5606 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5607 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 5608 | { |
| 5609 | context->handleError(InvalidOperation() |
| 5610 | << "Base level must be 0 for rectangle textures."); |
| 5611 | return false; |
| 5612 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5613 | break; |
| 5614 | |
| 5615 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 5616 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5617 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5618 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5619 | return false; |
| 5620 | } |
| 5621 | break; |
| 5622 | |
| 5623 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5624 | if (context->getClientVersion() < Version(3, 1)) |
| 5625 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5626 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5627 | return false; |
| 5628 | } |
| 5629 | switch (ConvertToGLenum(params[0])) |
| 5630 | { |
| 5631 | case GL_DEPTH_COMPONENT: |
| 5632 | case GL_STENCIL_INDEX: |
| 5633 | break; |
| 5634 | |
| 5635 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5636 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5637 | return false; |
| 5638 | } |
| 5639 | break; |
| 5640 | |
| 5641 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5642 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 5643 | { |
| 5644 | return false; |
| 5645 | } |
| 5646 | break; |
| 5647 | |
| 5648 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5649 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5650 | return false; |
| 5651 | } |
| 5652 | |
| 5653 | return true; |
| 5654 | } |
| 5655 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5656 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 5657 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5658 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5659 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5660 | { |
| 5661 | if (index >= MAX_VERTEX_ATTRIBS) |
| 5662 | { |
| 5663 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 5664 | return false; |
| 5665 | } |
| 5666 | |
| 5667 | return true; |
| 5668 | } |
| 5669 | |
| 5670 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 5671 | GLuint program, |
| 5672 | GLuint uniformBlockIndex, |
| 5673 | GLenum pname, |
| 5674 | GLsizei *length) |
| 5675 | { |
| 5676 | if (length) |
| 5677 | { |
| 5678 | *length = 0; |
| 5679 | } |
| 5680 | |
| 5681 | if (context->getClientMajorVersion() < 3) |
| 5682 | { |
| 5683 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 5684 | return false; |
| 5685 | } |
| 5686 | |
| 5687 | Program *programObject = GetValidProgram(context, program); |
| 5688 | if (!programObject) |
| 5689 | { |
| 5690 | return false; |
| 5691 | } |
| 5692 | |
| 5693 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 5694 | { |
| 5695 | context->handleError(InvalidValue() |
| 5696 | << "uniformBlockIndex exceeds active uniform block count."); |
| 5697 | return false; |
| 5698 | } |
| 5699 | |
| 5700 | switch (pname) |
| 5701 | { |
| 5702 | case GL_UNIFORM_BLOCK_BINDING: |
| 5703 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 5704 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 5705 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 5706 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 5707 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 5708 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 5709 | break; |
| 5710 | |
| 5711 | default: |
| 5712 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5713 | return false; |
| 5714 | } |
| 5715 | |
| 5716 | if (length) |
| 5717 | { |
| 5718 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 5719 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 5720 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5721 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 5722 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 5723 | } |
| 5724 | else |
| 5725 | { |
| 5726 | *length = 1; |
| 5727 | } |
| 5728 | } |
| 5729 | |
| 5730 | return true; |
| 5731 | } |
| 5732 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5733 | template <typename ParamType> |
| 5734 | bool ValidateSamplerParameterBase(Context *context, |
| 5735 | GLuint sampler, |
| 5736 | GLenum pname, |
| 5737 | GLsizei bufSize, |
| 5738 | ParamType *params) |
| 5739 | { |
| 5740 | if (context->getClientMajorVersion() < 3) |
| 5741 | { |
| 5742 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 5743 | return false; |
| 5744 | } |
| 5745 | |
| 5746 | if (!context->isSampler(sampler)) |
| 5747 | { |
| 5748 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 5749 | return false; |
| 5750 | } |
| 5751 | |
| 5752 | const GLsizei minBufSize = 1; |
| 5753 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5754 | { |
| 5755 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 5756 | return false; |
| 5757 | } |
| 5758 | |
| 5759 | switch (pname) |
| 5760 | { |
| 5761 | case GL_TEXTURE_WRAP_S: |
| 5762 | case GL_TEXTURE_WRAP_T: |
| 5763 | case GL_TEXTURE_WRAP_R: |
| 5764 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 5765 | { |
| 5766 | return false; |
| 5767 | } |
| 5768 | break; |
| 5769 | |
| 5770 | case GL_TEXTURE_MIN_FILTER: |
| 5771 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 5772 | { |
| 5773 | return false; |
| 5774 | } |
| 5775 | break; |
| 5776 | |
| 5777 | case GL_TEXTURE_MAG_FILTER: |
| 5778 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5779 | { |
| 5780 | return false; |
| 5781 | } |
| 5782 | break; |
| 5783 | |
| 5784 | case GL_TEXTURE_MIN_LOD: |
| 5785 | case GL_TEXTURE_MAX_LOD: |
| 5786 | // any value is permissible |
| 5787 | break; |
| 5788 | |
| 5789 | case GL_TEXTURE_COMPARE_MODE: |
| 5790 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5791 | { |
| 5792 | return false; |
| 5793 | } |
| 5794 | break; |
| 5795 | |
| 5796 | case GL_TEXTURE_COMPARE_FUNC: |
| 5797 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 5798 | { |
| 5799 | return false; |
| 5800 | } |
| 5801 | break; |
| 5802 | |
| 5803 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5804 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 5805 | { |
| 5806 | return false; |
| 5807 | } |
| 5808 | break; |
| 5809 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5810 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 5811 | { |
| 5812 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5813 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 5814 | { |
| 5815 | return false; |
| 5816 | } |
| 5817 | } |
| 5818 | break; |
| 5819 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5820 | default: |
| 5821 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5822 | return false; |
| 5823 | } |
| 5824 | |
| 5825 | return true; |
| 5826 | } |
| 5827 | |
| 5828 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 5829 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 5830 | |
| 5831 | bool ValidateGetSamplerParameterBase(Context *context, |
| 5832 | GLuint sampler, |
| 5833 | GLenum pname, |
| 5834 | GLsizei *length) |
| 5835 | { |
| 5836 | if (length) |
| 5837 | { |
| 5838 | *length = 0; |
| 5839 | } |
| 5840 | |
| 5841 | if (context->getClientMajorVersion() < 3) |
| 5842 | { |
| 5843 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 5844 | return false; |
| 5845 | } |
| 5846 | |
| 5847 | if (!context->isSampler(sampler)) |
| 5848 | { |
| 5849 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 5850 | return false; |
| 5851 | } |
| 5852 | |
| 5853 | switch (pname) |
| 5854 | { |
| 5855 | case GL_TEXTURE_WRAP_S: |
| 5856 | case GL_TEXTURE_WRAP_T: |
| 5857 | case GL_TEXTURE_WRAP_R: |
| 5858 | case GL_TEXTURE_MIN_FILTER: |
| 5859 | case GL_TEXTURE_MAG_FILTER: |
| 5860 | case GL_TEXTURE_MIN_LOD: |
| 5861 | case GL_TEXTURE_MAX_LOD: |
| 5862 | case GL_TEXTURE_COMPARE_MODE: |
| 5863 | case GL_TEXTURE_COMPARE_FUNC: |
| 5864 | break; |
| 5865 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5866 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 5867 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 5868 | { |
| 5869 | return false; |
| 5870 | } |
| 5871 | break; |
| 5872 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5873 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5874 | if (!context->getExtensions().textureSRGBDecode) |
| 5875 | { |
| 5876 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 5877 | return false; |
| 5878 | } |
| 5879 | break; |
| 5880 | |
| 5881 | default: |
| 5882 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5883 | return false; |
| 5884 | } |
| 5885 | |
| 5886 | if (length) |
| 5887 | { |
| 5888 | *length = 1; |
| 5889 | } |
| 5890 | return true; |
| 5891 | } |
| 5892 | |
| 5893 | bool ValidateGetInternalFormativBase(Context *context, |
| 5894 | GLenum target, |
| 5895 | GLenum internalformat, |
| 5896 | GLenum pname, |
| 5897 | GLsizei bufSize, |
| 5898 | GLsizei *numParams) |
| 5899 | { |
| 5900 | if (numParams) |
| 5901 | { |
| 5902 | *numParams = 0; |
| 5903 | } |
| 5904 | |
| 5905 | if (context->getClientMajorVersion() < 3) |
| 5906 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 5907 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 5908 | return false; |
| 5909 | } |
| 5910 | |
| 5911 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 5912 | if (!formatCaps.renderable) |
| 5913 | { |
| 5914 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 5915 | return false; |
| 5916 | } |
| 5917 | |
| 5918 | switch (target) |
| 5919 | { |
| 5920 | case GL_RENDERBUFFER: |
| 5921 | break; |
| 5922 | |
| 5923 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 5924 | if (context->getClientVersion() < ES_3_1) |
| 5925 | { |
| 5926 | context->handleError(InvalidOperation() |
| 5927 | << "Texture target requires at least OpenGL ES 3.1."); |
| 5928 | return false; |
| 5929 | } |
| 5930 | break; |
| 5931 | |
| 5932 | default: |
| 5933 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 5934 | return false; |
| 5935 | } |
| 5936 | |
| 5937 | if (bufSize < 0) |
| 5938 | { |
| 5939 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 5940 | return false; |
| 5941 | } |
| 5942 | |
| 5943 | GLsizei maxWriteParams = 0; |
| 5944 | switch (pname) |
| 5945 | { |
| 5946 | case GL_NUM_SAMPLE_COUNTS: |
| 5947 | maxWriteParams = 1; |
| 5948 | break; |
| 5949 | |
| 5950 | case GL_SAMPLES: |
| 5951 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 5952 | break; |
| 5953 | |
| 5954 | default: |
| 5955 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5956 | return false; |
| 5957 | } |
| 5958 | |
| 5959 | if (numParams) |
| 5960 | { |
| 5961 | // glGetInternalFormativ will not overflow bufSize |
| 5962 | *numParams = std::min(bufSize, maxWriteParams); |
| 5963 | } |
| 5964 | |
| 5965 | return true; |
| 5966 | } |
| 5967 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5968 | // We should check with Khronos if returning INVALID_FRAMEBUFFER_OPERATION is OK when querying |
| 5969 | // implementation format info for incomplete framebuffers. It seems like these queries are |
| 5970 | // incongruent with the other errors. |
| 5971 | bool ValidateFramebufferComplete(Context *context, Framebuffer *framebuffer, bool isFramebufferOp) |
| 5972 | { |
| 5973 | bool complete = false; |
| 5974 | ANGLE_VALIDATION_TRY(framebuffer->isComplete(context, &complete)); |
| 5975 | if (!complete) |
| 5976 | { |
| 5977 | if (isFramebufferOp) |
| 5978 | { |
| 5979 | context->handleError(InvalidFramebufferOperation()); |
| 5980 | } |
| 5981 | else |
| 5982 | { |
| 5983 | context->handleError(InvalidOperation()); |
| 5984 | } |
| 5985 | return false; |
| 5986 | } |
| 5987 | return true; |
| 5988 | } |
| 5989 | |
| 5990 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 5991 | { |
| 5992 | GLint samples = 0; |
| 5993 | ANGLE_VALIDATION_TRY(framebuffer->getSamples(context, &samples)); |
| 5994 | if (samples != 0) |
| 5995 | { |
| 5996 | context->handleError(InvalidOperation()); |
| 5997 | return false; |
| 5998 | } |
| 5999 | return true; |
| 6000 | } |
| 6001 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6002 | } // namespace gl |