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