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" |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 22 | #include "libANGLE/angletypes.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 23 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 24 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 25 | #include "libANGLE/queryutils.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 26 | #include "libANGLE/validationES2.h" |
| 27 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 28 | |
| 29 | #include "common/mathutil.h" |
| 30 | #include "common/utilities.h" |
| 31 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 32 | using namespace angle; |
| 33 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 34 | namespace gl |
| 35 | { |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 36 | namespace |
| 37 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 38 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 39 | { |
| 40 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 41 | // the compressed block size. |
| 42 | switch (internalFormat) |
| 43 | { |
| 44 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 47 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 48 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 51 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 52 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 53 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 57 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 58 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 59 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 60 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 61 | default: |
| 62 | return false; |
| 63 | } |
| 64 | } |
| 65 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 66 | { |
| 67 | // Compressed sub textures have additional formats that requires exact size. |
| 68 | // ES 3.1, Section 8.7, Page 171 |
| 69 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 70 | IsETC2EACFormat(internalFormat); |
| 71 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 72 | |
| 73 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 74 | { |
| 75 | CheckedNumeric<GLint> checkedA(a); |
| 76 | checkedA -= b; |
| 77 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 78 | checkedA = -checkedA; |
| 79 | return !checkedA.IsValid(); |
| 80 | } |
| 81 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 82 | bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex, GLint vertexCount) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 83 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 84 | const gl::State &state = context->getGLState(); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 85 | const gl::Program *program = state.getProgram(); |
| 86 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 87 | bool webglCompatibility = context->getExtensions().webglCompatibility; |
| 88 | |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 89 | const VertexArray *vao = state.getVertexArray(); |
| 90 | const AttributesMask &clientAttribs = vao->getEnabledClientMemoryAttribsMask(); |
| 91 | |
| 92 | if (clientAttribs.any()) |
| 93 | { |
| 94 | if (webglCompatibility || !state.areClientArraysEnabled()) |
| 95 | { |
| 96 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 97 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 98 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 99 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
| 100 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBuffer); |
| 101 | return false; |
| 102 | } |
| 103 | else if (vao->hasEnabledNullPointerClientArray()) |
| 104 | { |
| 105 | // This is an application error that would normally result in a crash, but we catch it |
| 106 | // and return an error |
| 107 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBufferPointer); |
| 108 | return false; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | // If we're drawing zero vertices, we have enough data. |
| 113 | if (vertexCount <= 0 || primcount <= 0) |
| 114 | { |
| 115 | return true; |
| 116 | } |
| 117 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 118 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 119 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 120 | |
Jamie Madill | 2eb6503 | 2018-07-30 10:25:57 -0400 | [diff] [blame^] | 121 | const AttributesMask &activeAttribs = context->getActiveBufferedAttribsMask(); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 122 | |
| 123 | for (size_t attributeIndex : activeAttribs) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 124 | { |
| 125 | const VertexAttribute &attrib = vertexAttribs[attributeIndex]; |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 126 | ASSERT(attrib.enabled); |
Corentin Wallez | 672f7f3 | 2017-06-15 17:42:17 -0400 | [diff] [blame] | 127 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 128 | const VertexBinding &binding = vertexBindings[attrib.bindingIndex]; |
Jamie Madill | 2eb6503 | 2018-07-30 10:25:57 -0400 | [diff] [blame^] | 129 | ASSERT(context->isGLES1() || program->isAttribLocationActive(attributeIndex)); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 130 | |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 131 | GLint maxVertexElement = maxVertex; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 132 | GLuint divisor = binding.getDivisor(); |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 133 | if (divisor != 0) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 134 | { |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 135 | maxVertexElement = (primcount - 1) / divisor; |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | // We do manual overflow checks here instead of using safe_math.h because it was |
| 139 | // a bottleneck. Thanks to some properties of GL we know inequalities that can |
| 140 | // help us make the overflow checks faster. |
| 141 | |
| 142 | // The max possible attribSize is 16 for a vector of 4 32 bit values. |
| 143 | constexpr uint64_t kMaxAttribSize = 16; |
| 144 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 145 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 146 | |
| 147 | // We know attribStride is given as a GLsizei which is typedefed to int. |
| 148 | // We also know an upper bound for attribSize. |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 149 | static_assert(std::is_same<int, GLsizei>::value, "Unexpected type"); |
| 150 | ASSERT(ComputeVertexAttributeStride(attrib, binding) == binding.getStride()); |
| 151 | uint64_t attribStride = binding.getStride(); |
| 152 | ASSERT(attribStride <= kIntMax && ComputeVertexAttributeTypeSize(attrib) <= kMaxAttribSize); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 153 | |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 154 | // Computing the product of two 32-bit ints will fit in 64 bits without overflow. |
| 155 | static_assert(kIntMax * kIntMax < kUint64Max, "Unexpected overflow"); |
| 156 | uint64_t attribDataSizeMinusAttribSize = maxVertexElement * attribStride; |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 157 | |
| 158 | // An overflow can happen when adding the offset, check for it. |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 159 | if (attribDataSizeMinusAttribSize > kUint64Max - attrib.cachedSizePlusRelativeOffset) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 160 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 161 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 162 | return false; |
| 163 | } |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 164 | |
| 165 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 166 | // We can return INVALID_OPERATION if our array buffer does not have enough backing data. |
| 167 | if (attribDataSizeMinusAttribSize + attrib.cachedSizePlusRelativeOffset > |
| 168 | binding.getCachedBufferSizeMinusOffset()) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 169 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 170 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 171 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 172 | } |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 173 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 174 | |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 175 | if (webglCompatibility && vao->hasTransformFeedbackBindingConflict(activeAttribs)) |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 176 | { |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 177 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexBufferBoundForTransformFeedback); |
| 178 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | return true; |
| 182 | } |
| 183 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 184 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 185 | { |
| 186 | switch (type) |
| 187 | { |
| 188 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 189 | case GL_UNSIGNED_BYTE: |
| 190 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 191 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 192 | case GL_UNSIGNED_SHORT_5_6_5: |
| 193 | return context->getClientVersion() >= ES_2_0; |
| 194 | |
| 195 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 196 | case GL_BYTE: |
| 197 | case GL_INT: |
| 198 | case GL_SHORT: |
| 199 | case GL_UNSIGNED_INT: |
| 200 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 201 | case GL_UNSIGNED_INT_24_8: |
| 202 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 203 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 204 | case GL_UNSIGNED_SHORT: |
| 205 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 206 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 207 | return context->getClientVersion() >= ES_3_0; |
| 208 | |
| 209 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 210 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 211 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 212 | |
| 213 | case GL_HALF_FLOAT: |
| 214 | return context->getClientVersion() >= ES_3_0 || |
| 215 | context->getExtensions().textureHalfFloat; |
| 216 | |
| 217 | case GL_HALF_FLOAT_OES: |
| 218 | return context->getExtensions().colorBufferHalfFloat; |
| 219 | |
| 220 | default: |
| 221 | return false; |
| 222 | } |
| 223 | } |
| 224 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 225 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 226 | { |
| 227 | switch (format) |
| 228 | { |
| 229 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 230 | case GL_RGBA: |
| 231 | case GL_RGB: |
| 232 | case GL_ALPHA: |
| 233 | return context->getClientVersion() >= ES_2_0; |
| 234 | |
| 235 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 236 | case GL_RG: |
| 237 | case GL_RED: |
| 238 | case GL_RGBA_INTEGER: |
| 239 | case GL_RGB_INTEGER: |
| 240 | case GL_RG_INTEGER: |
| 241 | case GL_RED_INTEGER: |
| 242 | return context->getClientVersion() >= ES_3_0; |
| 243 | |
| 244 | case GL_SRGB_ALPHA_EXT: |
| 245 | case GL_SRGB_EXT: |
| 246 | return context->getExtensions().sRGB; |
| 247 | |
| 248 | case GL_BGRA_EXT: |
| 249 | return context->getExtensions().readFormatBGRA; |
| 250 | |
| 251 | default: |
| 252 | return false; |
| 253 | } |
| 254 | } |
| 255 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 256 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 257 | GLenum framebufferComponentType, |
| 258 | GLenum format, |
| 259 | GLenum type) |
| 260 | { |
| 261 | switch (framebufferComponentType) |
| 262 | { |
| 263 | case GL_UNSIGNED_NORMALIZED: |
| 264 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 265 | // ReadPixels with BGRA even if the extension is not present |
| 266 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 267 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 268 | type == GL_UNSIGNED_BYTE); |
| 269 | |
| 270 | case GL_SIGNED_NORMALIZED: |
| 271 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 272 | |
| 273 | case GL_INT: |
| 274 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 275 | |
| 276 | case GL_UNSIGNED_INT: |
| 277 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 278 | |
| 279 | case GL_FLOAT: |
| 280 | return (format == GL_RGBA && type == GL_FLOAT); |
| 281 | |
| 282 | default: |
| 283 | UNREACHABLE(); |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 288 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 289 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 290 | { |
| 291 | switch (ConvertToGLenum(params[0])) |
| 292 | { |
| 293 | case GL_CLAMP_TO_EDGE: |
| 294 | break; |
| 295 | |
| 296 | case GL_REPEAT: |
| 297 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 298 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 299 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 300 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 301 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 302 | return false; |
| 303 | } |
| 304 | break; |
| 305 | |
| 306 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 307 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 308 | return false; |
| 309 | } |
| 310 | |
| 311 | return true; |
| 312 | } |
| 313 | |
| 314 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 315 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 316 | { |
| 317 | switch (ConvertToGLenum(params[0])) |
| 318 | { |
| 319 | case GL_NEAREST: |
| 320 | case GL_LINEAR: |
| 321 | break; |
| 322 | |
| 323 | case GL_NEAREST_MIPMAP_NEAREST: |
| 324 | case GL_LINEAR_MIPMAP_NEAREST: |
| 325 | case GL_NEAREST_MIPMAP_LINEAR: |
| 326 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 327 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 328 | { |
| 329 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 330 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 331 | return false; |
| 332 | } |
| 333 | break; |
| 334 | |
| 335 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 336 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 337 | return false; |
| 338 | } |
| 339 | |
| 340 | return true; |
| 341 | } |
| 342 | |
| 343 | template <typename ParamType> |
| 344 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 345 | { |
| 346 | switch (ConvertToGLenum(params[0])) |
| 347 | { |
| 348 | case GL_NEAREST: |
| 349 | case GL_LINEAR: |
| 350 | break; |
| 351 | |
| 352 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 353 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 354 | return false; |
| 355 | } |
| 356 | |
| 357 | return true; |
| 358 | } |
| 359 | |
| 360 | template <typename ParamType> |
| 361 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 362 | { |
| 363 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 364 | switch (ConvertToGLenum(params[0])) |
| 365 | { |
| 366 | case GL_NONE: |
| 367 | case GL_COMPARE_REF_TO_TEXTURE: |
| 368 | break; |
| 369 | |
| 370 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 371 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 372 | return false; |
| 373 | } |
| 374 | |
| 375 | return true; |
| 376 | } |
| 377 | |
| 378 | template <typename ParamType> |
| 379 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 380 | { |
| 381 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 382 | switch (ConvertToGLenum(params[0])) |
| 383 | { |
| 384 | case GL_LEQUAL: |
| 385 | case GL_GEQUAL: |
| 386 | case GL_LESS: |
| 387 | case GL_GREATER: |
| 388 | case GL_EQUAL: |
| 389 | case GL_NOTEQUAL: |
| 390 | case GL_ALWAYS: |
| 391 | case GL_NEVER: |
| 392 | break; |
| 393 | |
| 394 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 395 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 396 | return false; |
| 397 | } |
| 398 | |
| 399 | return true; |
| 400 | } |
| 401 | |
| 402 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 403 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 404 | { |
| 405 | if (!context->getExtensions().textureSRGBDecode) |
| 406 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 407 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
| 411 | switch (ConvertToGLenum(params[0])) |
| 412 | { |
| 413 | case GL_DECODE_EXT: |
| 414 | case GL_SKIP_DECODE_EXT: |
| 415 | break; |
| 416 | |
| 417 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 418 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 419 | return false; |
| 420 | } |
| 421 | |
| 422 | return true; |
| 423 | } |
| 424 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 425 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 426 | { |
| 427 | if (!context->getExtensions().textureFilterAnisotropic) |
| 428 | { |
| 429 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 430 | return false; |
| 431 | } |
| 432 | |
| 433 | return true; |
| 434 | } |
| 435 | |
| 436 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 437 | { |
| 438 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 439 | { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 444 | |
| 445 | if (paramValue < 1 || paramValue > largest) |
| 446 | { |
| 447 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 448 | return false; |
| 449 | } |
| 450 | |
| 451 | return true; |
| 452 | } |
| 453 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 454 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 455 | { |
| 456 | const Program *program = context->getGLState().getProgram(); |
| 457 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 458 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 459 | if (!ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 460 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 461 | program->getActiveOutputVariables().to_ulong(), |
| 462 | framebuffer->getDrawBufferMask().to_ulong())) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 463 | { |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 464 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DrawBufferTypeMismatch); |
| 465 | return false; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | return true; |
| 469 | } |
| 470 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 471 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 472 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 473 | const auto &glState = context->getGLState(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 474 | const Program *program = context->getGLState().getProgram(); |
| 475 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 476 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 477 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 478 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 479 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 480 | |
| 481 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 482 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 483 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 484 | |
| 485 | if (!ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), vaoAttribTypeBits, |
| 486 | program->getAttributesMask().to_ulong(), 0xFFFF)) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 487 | { |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 488 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexShaderTypeMismatch); |
| 489 | return false; |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 490 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 491 | return true; |
| 492 | } |
| 493 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 494 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 495 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 496 | { |
| 497 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 498 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 499 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 500 | case PrimitiveMode::Points: |
| 501 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 502 | case PrimitiveMode::Lines: |
| 503 | case PrimitiveMode::LineStrip: |
| 504 | case PrimitiveMode::LineLoop: |
| 505 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 506 | case PrimitiveMode::LinesAdjacency: |
| 507 | case PrimitiveMode::LineStripAdjacency: |
| 508 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 509 | case PrimitiveMode::Triangles: |
| 510 | case PrimitiveMode::TriangleFan: |
| 511 | case PrimitiveMode::TriangleStrip: |
| 512 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 513 | case PrimitiveMode::TrianglesAdjacency: |
| 514 | case PrimitiveMode::TriangleStripAdjacency: |
| 515 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 516 | default: |
| 517 | UNREACHABLE(); |
| 518 | return false; |
| 519 | } |
| 520 | } |
| 521 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 522 | // GLES1 texture parameters are a small subset of the others |
| 523 | bool IsValidGLES1TextureParameter(GLenum pname) |
| 524 | { |
| 525 | switch (pname) |
| 526 | { |
| 527 | case GL_TEXTURE_MAG_FILTER: |
| 528 | case GL_TEXTURE_MIN_FILTER: |
| 529 | case GL_TEXTURE_WRAP_S: |
| 530 | case GL_TEXTURE_WRAP_T: |
| 531 | case GL_TEXTURE_WRAP_R: |
| 532 | case GL_GENERATE_MIPMAP: |
| 533 | case GL_TEXTURE_CROP_RECT_OES: |
| 534 | return true; |
| 535 | default: |
| 536 | return false; |
| 537 | } |
| 538 | } |
| 539 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 540 | } // anonymous namespace |
| 541 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 542 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 543 | { |
| 544 | if (length) |
| 545 | { |
| 546 | *length = value; |
| 547 | } |
| 548 | } |
| 549 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 550 | bool IsETC2EACFormat(const GLenum format) |
| 551 | { |
| 552 | // ES 3.1, Table 8.19 |
| 553 | switch (format) |
| 554 | { |
| 555 | case GL_COMPRESSED_R11_EAC: |
| 556 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 557 | case GL_COMPRESSED_RG11_EAC: |
| 558 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 559 | case GL_COMPRESSED_RGB8_ETC2: |
| 560 | case GL_COMPRESSED_SRGB8_ETC2: |
| 561 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 562 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 563 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 564 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 565 | return true; |
| 566 | |
| 567 | default: |
| 568 | return false; |
| 569 | } |
| 570 | } |
| 571 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 572 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 573 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 574 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 575 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 576 | case TextureType::_2D: |
| 577 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 578 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 579 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 580 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 581 | return context->getExtensions().textureRectangle; |
| 582 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 583 | case TextureType::_3D: |
| 584 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 585 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 586 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 587 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 588 | return (context->getClientVersion() >= Version(3, 1)); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 589 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 590 | default: |
| 591 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 592 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 595 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 596 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 597 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 598 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 599 | case TextureType::_2D: |
| 600 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 601 | return true; |
| 602 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 603 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 604 | return context->getExtensions().textureRectangle; |
| 605 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 606 | default: |
| 607 | return false; |
| 608 | } |
| 609 | } |
| 610 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 611 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 612 | { |
| 613 | switch (target) |
| 614 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 615 | case TextureType::_3D: |
| 616 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 617 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 618 | |
| 619 | default: |
| 620 | return false; |
| 621 | } |
| 622 | } |
| 623 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 624 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 625 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 626 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 627 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 628 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 629 | (context->getExtensions().eglImageExternal || |
| 630 | context->getExtensions().eglStreamConsumerExternal); |
| 631 | } |
| 632 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 633 | // This function differs from ValidTextureTarget in that the target must be |
| 634 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 635 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 636 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 637 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 638 | { |
| 639 | switch (target) |
| 640 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 641 | case TextureTarget::_2D: |
| 642 | case TextureTarget::CubeMapNegativeX: |
| 643 | case TextureTarget::CubeMapNegativeY: |
| 644 | case TextureTarget::CubeMapNegativeZ: |
| 645 | case TextureTarget::CubeMapPositiveX: |
| 646 | case TextureTarget::CubeMapPositiveY: |
| 647 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 648 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 649 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 650 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 651 | default: |
| 652 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 653 | } |
| 654 | } |
| 655 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 656 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 657 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 658 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 659 | { |
| 660 | ASSERT(context); |
| 661 | |
| 662 | if (!context->getExtensions().geometryShader) |
| 663 | { |
| 664 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 665 | // that does not match the current transform feedback object's draw mode (if transform |
| 666 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 667 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 668 | } |
| 669 | |
| 670 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 671 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 672 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 673 | case PrimitiveMode::Points: |
| 674 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 675 | case PrimitiveMode::Lines: |
| 676 | case PrimitiveMode::LineStrip: |
| 677 | case PrimitiveMode::LineLoop: |
| 678 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 679 | case PrimitiveMode::Triangles: |
| 680 | case PrimitiveMode::TriangleFan: |
| 681 | case PrimitiveMode::TriangleStrip: |
| 682 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 683 | default: |
| 684 | UNREACHABLE(); |
| 685 | return false; |
| 686 | } |
| 687 | } |
| 688 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 689 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 690 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 691 | GLsizei count, |
| 692 | GLenum type, |
| 693 | const GLvoid *indices, |
| 694 | GLsizei primcount) |
| 695 | { |
| 696 | if (primcount < 0) |
| 697 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 698 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 699 | return false; |
| 700 | } |
| 701 | |
| 702 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 703 | { |
| 704 | return false; |
| 705 | } |
| 706 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 707 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 711 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 712 | GLint first, |
| 713 | GLsizei count, |
| 714 | GLsizei primcount) |
| 715 | { |
| 716 | if (primcount < 0) |
| 717 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 718 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 719 | return false; |
| 720 | } |
| 721 | |
| 722 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 723 | { |
| 724 | return false; |
| 725 | } |
| 726 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 727 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 728 | } |
| 729 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 730 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 731 | { |
| 732 | // Verify there is at least one active attribute with a divisor of zero |
| 733 | const State &state = context->getGLState(); |
| 734 | |
| 735 | Program *program = state.getProgram(); |
| 736 | |
| 737 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 738 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 739 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 740 | { |
| 741 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 742 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 743 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 744 | { |
| 745 | return true; |
| 746 | } |
| 747 | } |
| 748 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 749 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 750 | return false; |
| 751 | } |
| 752 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 753 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 754 | { |
| 755 | switch (target) |
| 756 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 757 | case TextureType::_3D: |
| 758 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 759 | return true; |
| 760 | default: |
| 761 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 765 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 766 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 767 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 768 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 769 | case TextureType::_2D: |
| 770 | case TextureType::_2DArray: |
| 771 | case TextureType::_2DMultisample: |
| 772 | case TextureType::CubeMap: |
| 773 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 774 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 775 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 776 | return context->getExtensions().textureRectangle; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 777 | default: |
| 778 | return false; |
| 779 | } |
| 780 | } |
| 781 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 782 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 783 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 784 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 785 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 786 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 787 | |
| 788 | switch (target) |
| 789 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 790 | case GL_FRAMEBUFFER: |
| 791 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 792 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 793 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 794 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 795 | return (context->getExtensions().framebufferBlit || |
| 796 | context->getClientMajorVersion() >= 3); |
| 797 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 798 | default: |
| 799 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 803 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 804 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 805 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 806 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 807 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 808 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 809 | case TextureType::_2D: |
| 810 | case TextureType::_2DArray: |
| 811 | case TextureType::_2DMultisample: |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 812 | maxDimension = caps.max2DTextureSize; |
| 813 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 814 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 815 | maxDimension = caps.maxCubeMapTextureSize; |
| 816 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 817 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 818 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 819 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 820 | maxDimension = caps.max3DTextureSize; |
| 821 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 822 | default: |
| 823 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 826 | return level <= gl::log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 827 | } |
| 828 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 829 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 830 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 831 | GLint level, |
| 832 | GLsizei width, |
| 833 | GLsizei height, |
| 834 | GLsizei depth, |
| 835 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 836 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 837 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 838 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 839 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 840 | return false; |
| 841 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 842 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 843 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 844 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 845 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 846 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 847 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 848 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 849 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 850 | return false; |
| 851 | } |
| 852 | |
| 853 | if (!ValidMipLevel(context, target, level)) |
| 854 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 855 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 856 | return false; |
| 857 | } |
| 858 | |
| 859 | return true; |
| 860 | } |
| 861 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 862 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 863 | { |
| 864 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 865 | (size % blockSize == 0); |
| 866 | } |
| 867 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 868 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 869 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 870 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 871 | GLsizei width, |
| 872 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 873 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 874 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 875 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 876 | { |
| 877 | return false; |
| 878 | } |
| 879 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 880 | if (width < 0 || height < 0) |
| 881 | { |
| 882 | return false; |
| 883 | } |
| 884 | |
| 885 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 886 | { |
| 887 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 888 | // block size for level 0 but WebGL disallows this. |
| 889 | bool smallerThanBlockSizeAllowed = |
| 890 | level > 0 || !context->getExtensions().webglCompatibility; |
| 891 | |
| 892 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 893 | smallerThanBlockSizeAllowed) || |
| 894 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 895 | smallerThanBlockSizeAllowed)) |
| 896 | { |
| 897 | return false; |
| 898 | } |
| 899 | } |
| 900 | |
| 901 | return true; |
| 902 | } |
| 903 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 904 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 905 | GLenum internalFormat, |
| 906 | GLint xoffset, |
| 907 | GLint yoffset, |
| 908 | GLsizei width, |
| 909 | GLsizei height, |
| 910 | size_t textureWidth, |
| 911 | size_t textureHeight) |
| 912 | { |
| 913 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
| 914 | if (!formatInfo.compressed) |
| 915 | { |
| 916 | return false; |
| 917 | } |
| 918 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 919 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 920 | { |
| 921 | return false; |
| 922 | } |
| 923 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 924 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 925 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 926 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 927 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 928 | { |
| 929 | return false; |
| 930 | } |
| 931 | |
| 932 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 933 | // size but fills the entire mip |
| 934 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 935 | static_cast<size_t>(width) == textureWidth && |
| 936 | static_cast<size_t>(height) == textureHeight; |
| 937 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 938 | (height % formatInfo.compressedBlockHeight) == 0; |
| 939 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 940 | { |
| 941 | return false; |
| 942 | } |
| 943 | } |
| 944 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 945 | return true; |
| 946 | } |
| 947 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 948 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 949 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 950 | GLsizei width, |
| 951 | GLsizei height, |
| 952 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 953 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 954 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 955 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 956 | GLsizei imageSize) |
| 957 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 958 | gl::Buffer *pixelUnpackBuffer = |
| 959 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 960 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 961 | { |
| 962 | // Checks are not required |
| 963 | return true; |
| 964 | } |
| 965 | |
| 966 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 967 | // would exceed the data store size. |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 968 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format, type); |
| 969 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 970 | const gl::Extents size(width, height, depth); |
| 971 | const auto &unpack = context->getGLState().getUnpackState(); |
| 972 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 973 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 974 | GLuint endByte = 0; |
| 975 | if (!formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D, &endByte)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 976 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 977 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 978 | return false; |
| 979 | } |
| 980 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 981 | if (pixelUnpackBuffer) |
| 982 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 983 | CheckedNumeric<size_t> checkedEndByte(endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 984 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 985 | checkedEndByte += checkedOffset; |
| 986 | |
| 987 | if (!checkedEndByte.IsValid() || |
| 988 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 989 | { |
| 990 | // Overflow past the end of the buffer |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 991 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 992 | return false; |
| 993 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 994 | if (context->getExtensions().webglCompatibility && |
| 995 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 996 | { |
| 997 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 998 | PixelUnpackBufferBoundForTransformFeedback); |
| 999 | return false; |
| 1000 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1001 | } |
| 1002 | else |
| 1003 | { |
| 1004 | ASSERT(imageSize >= 0); |
| 1005 | if (pixels == nullptr && imageSize != 0) |
| 1006 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1007 | context->handleError(InvalidOperation() |
| 1008 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 1009 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1010 | } |
| 1011 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 1012 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1013 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1014 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1015 | return false; |
| 1016 | } |
| 1017 | } |
| 1018 | |
| 1019 | return true; |
| 1020 | } |
| 1021 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1022 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1023 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1024 | switch (queryType) |
| 1025 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1026 | case QueryType::AnySamples: |
| 1027 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 1028 | return context->getClientMajorVersion() >= 3 || |
| 1029 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1030 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1031 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1032 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1033 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1034 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1035 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1036 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 1037 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1038 | default: |
| 1039 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1043 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1044 | GLenum type, |
| 1045 | GLboolean normalized, |
| 1046 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1047 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1048 | bool pureInteger) |
| 1049 | { |
| 1050 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1051 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1052 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1053 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1054 | // parameter exceeds 255. |
| 1055 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1056 | if (stride > kMaxWebGLStride) |
| 1057 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1058 | context->handleError(InvalidValue() |
| 1059 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1060 | return false; |
| 1061 | } |
| 1062 | |
| 1063 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1064 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1065 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1066 | // or an INVALID_OPERATION error is generated. |
| 1067 | VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger); |
| 1068 | size_t typeSize = GetVertexFormatTypeSize(internalType); |
| 1069 | |
| 1070 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1071 | size_t sizeMask = (typeSize - 1); |
| 1072 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1073 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1074 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1075 | return false; |
| 1076 | } |
| 1077 | |
| 1078 | if ((stride & sizeMask) != 0) |
| 1079 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1080 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1081 | return false; |
| 1082 | } |
| 1083 | |
| 1084 | return true; |
| 1085 | } |
| 1086 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1087 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1088 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1089 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1090 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1091 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1092 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1093 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1094 | Program *validProgram = context->getProgram(id); |
| 1095 | |
| 1096 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1097 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1098 | if (context->getShader(id)) |
| 1099 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1100 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1101 | } |
| 1102 | else |
| 1103 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1104 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1105 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1106 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1107 | |
| 1108 | return validProgram; |
| 1109 | } |
| 1110 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1111 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1112 | { |
| 1113 | // See ValidProgram for spec details. |
| 1114 | |
| 1115 | Shader *validShader = context->getShader(id); |
| 1116 | |
| 1117 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1118 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1119 | if (context->getProgram(id)) |
| 1120 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1121 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1122 | } |
| 1123 | else |
| 1124 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1125 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1126 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1127 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1128 | |
| 1129 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1130 | } |
| 1131 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1132 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1133 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1134 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1135 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1136 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1137 | { |
| 1138 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1139 | return false; |
| 1140 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1141 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1142 | // Color attachment 0 is validated below because it is always valid |
| 1143 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1144 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1145 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1146 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1147 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | switch (attachment) |
| 1153 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1154 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1155 | case GL_DEPTH_ATTACHMENT: |
| 1156 | case GL_STENCIL_ATTACHMENT: |
| 1157 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1158 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1159 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1160 | if (!context->getExtensions().webglCompatibility && |
| 1161 | context->getClientMajorVersion() < 3) |
| 1162 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1163 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1164 | return false; |
| 1165 | } |
| 1166 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1167 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1168 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1169 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1170 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | return true; |
| 1175 | } |
| 1176 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1177 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1178 | GLenum target, |
| 1179 | GLsizei samples, |
| 1180 | GLenum internalformat, |
| 1181 | GLsizei width, |
| 1182 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1183 | { |
| 1184 | switch (target) |
| 1185 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1186 | case GL_RENDERBUFFER: |
| 1187 | break; |
| 1188 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1189 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1190 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | if (width < 0 || height < 0 || samples < 0) |
| 1194 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1195 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1196 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1197 | } |
| 1198 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1199 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1200 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1201 | |
| 1202 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1203 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1204 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1205 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1206 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
| 1209 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1210 | // 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] | 1211 | // only sized internal formats. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1212 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(convertedInternalFormat); |
| 1213 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1214 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1215 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1216 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1217 | } |
| 1218 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1219 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1220 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1221 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1222 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1223 | } |
| 1224 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1225 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1226 | if (handle == 0) |
| 1227 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1228 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1229 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | return true; |
| 1233 | } |
| 1234 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1235 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, |
| 1236 | GLenum target, |
| 1237 | GLenum attachment, |
| 1238 | GLenum renderbuffertarget, |
| 1239 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1240 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1241 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1242 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1243 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1244 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1245 | } |
| 1246 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1247 | gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1248 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1249 | ASSERT(framebuffer); |
| 1250 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1251 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1252 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1253 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1254 | } |
| 1255 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1256 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1257 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1258 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1259 | } |
| 1260 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1261 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1262 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1263 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1264 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1265 | if (renderbuffer != 0) |
| 1266 | { |
| 1267 | if (!context->getRenderbuffer(renderbuffer)) |
| 1268 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1269 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1270 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1271 | } |
| 1272 | } |
| 1273 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1274 | return true; |
| 1275 | } |
| 1276 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1277 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1278 | GLint srcX0, |
| 1279 | GLint srcY0, |
| 1280 | GLint srcX1, |
| 1281 | GLint srcY1, |
| 1282 | GLint dstX0, |
| 1283 | GLint dstY0, |
| 1284 | GLint dstX1, |
| 1285 | GLint dstY1, |
| 1286 | GLbitfield mask, |
| 1287 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1288 | { |
| 1289 | switch (filter) |
| 1290 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1291 | case GL_NEAREST: |
| 1292 | break; |
| 1293 | case GL_LINEAR: |
| 1294 | break; |
| 1295 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1296 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1297 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1301 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1302 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1303 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1304 | } |
| 1305 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1307 | // color buffer, leaving only nearest being unfiltered from above |
| 1308 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1309 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1310 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1311 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1312 | } |
| 1313 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1314 | const auto &glState = context->getGLState(); |
| 1315 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1316 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1317 | |
| 1318 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1319 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1320 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1321 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1322 | } |
| 1323 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1324 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1325 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1326 | return false; |
| 1327 | } |
| 1328 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1329 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1330 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1331 | return false; |
| 1332 | } |
| 1333 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1334 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1335 | { |
| 1336 | context->handleError(InvalidOperation()); |
| 1337 | return false; |
| 1338 | } |
| 1339 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1340 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1341 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1342 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1343 | } |
| 1344 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1345 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1346 | // always run it in order to avoid triggering driver bugs. |
| 1347 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1348 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1349 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1350 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1351 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1352 | } |
| 1353 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1354 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1355 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1356 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1357 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1358 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1359 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1360 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1361 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1362 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1363 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1364 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1365 | for (size_t drawbufferIdx = 0; |
| 1366 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1367 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1368 | const FramebufferAttachment *attachment = |
| 1369 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1370 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1371 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1372 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1373 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1374 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1375 | // 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] | 1376 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1377 | // as well |
| 1378 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1379 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1380 | // Changes with EXT_color_buffer_float: |
| 1381 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1382 | GLenum readComponentType = readFormat.info->componentType; |
| 1383 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1384 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1385 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1386 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1387 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1388 | |
| 1389 | if (extensions.colorBufferFloat) |
| 1390 | { |
| 1391 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1392 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1393 | |
| 1394 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1395 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1396 | context->handleError(InvalidOperation() |
| 1397 | << "If the read buffer contains fixed-point or " |
| 1398 | "floating-point values, the draw buffer must " |
| 1399 | "as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1400 | return false; |
| 1401 | } |
| 1402 | } |
| 1403 | else if (readFixedPoint != drawFixedPoint) |
| 1404 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1405 | context->handleError(InvalidOperation() |
| 1406 | << "If the read buffer contains fixed-point values, " |
| 1407 | "the draw buffer must as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1408 | return false; |
| 1409 | } |
| 1410 | |
| 1411 | if (readComponentType == GL_UNSIGNED_INT && |
| 1412 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1413 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1414 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1415 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1416 | } |
| 1417 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1418 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1419 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1420 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1421 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1422 | } |
| 1423 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1424 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1425 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
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 | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1430 | |
| 1431 | if (context->getExtensions().webglCompatibility && |
| 1432 | *readColorBuffer == *attachment) |
| 1433 | { |
| 1434 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1435 | InvalidOperation() |
| 1436 | << "Read and write color attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1437 | return false; |
| 1438 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1442 | if ((readFormat.info->componentType == GL_INT || |
| 1443 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1444 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1445 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1446 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1447 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1448 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1449 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1450 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1451 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1452 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1453 | // situation is an application error that would lead to a crash in ANGLE. |
| 1454 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1455 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1456 | context->handleError( |
| 1457 | InvalidOperation() |
| 1458 | << "Attempt to read from a missing color attachment of a complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1459 | return false; |
| 1460 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1461 | } |
| 1462 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1463 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1464 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1465 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1466 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1467 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1468 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1469 | const gl::FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1470 | readFramebuffer->getAttachment(context, attachments[i]); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1471 | const gl::FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1472 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1473 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1474 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1475 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1476 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1477 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1478 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1479 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1480 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1481 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1482 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1483 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1484 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1485 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1486 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1487 | |
| 1488 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1489 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1490 | context->handleError( |
| 1491 | InvalidOperation() |
| 1492 | << "Read and write depth stencil attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1493 | return false; |
| 1494 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1495 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1496 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1497 | else if (drawBuffer) |
| 1498 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1499 | context->handleError(InvalidOperation() << "Attempt to read from a missing " |
| 1500 | "depth/stencil attachment of a " |
| 1501 | "complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1502 | return false; |
| 1503 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1507 | // ANGLE_multiview, Revision 1: |
| 1508 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
| 1509 | // multi-view layout of the current draw framebuffer or read framebuffer is not NONE. |
| 1510 | if (readFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1511 | { |
| 1512 | context->handleError(InvalidFramebufferOperation() |
| 1513 | << "Attempt to read from a multi-view framebuffer."); |
| 1514 | return false; |
| 1515 | } |
| 1516 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1517 | { |
| 1518 | context->handleError(InvalidFramebufferOperation() |
| 1519 | << "Attempt to write to a multi-view framebuffer."); |
| 1520 | return false; |
| 1521 | } |
| 1522 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1523 | return true; |
| 1524 | } |
| 1525 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1526 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1527 | GLint x, |
| 1528 | GLint y, |
| 1529 | GLsizei width, |
| 1530 | GLsizei height, |
| 1531 | GLenum format, |
| 1532 | GLenum type, |
| 1533 | GLsizei bufSize, |
| 1534 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1535 | GLsizei *columns, |
| 1536 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1537 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1538 | { |
| 1539 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1540 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1541 | return false; |
| 1542 | } |
| 1543 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1544 | GLsizei writeLength = 0; |
| 1545 | GLsizei writeColumns = 0; |
| 1546 | GLsizei writeRows = 0; |
| 1547 | |
| 1548 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1549 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1550 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1551 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1552 | } |
| 1553 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1554 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1555 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1556 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1557 | } |
| 1558 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1559 | SetRobustLengthParam(length, writeLength); |
| 1560 | SetRobustLengthParam(columns, writeColumns); |
| 1561 | SetRobustLengthParam(rows, writeRows); |
| 1562 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1563 | return true; |
| 1564 | } |
| 1565 | |
| 1566 | bool ValidateReadnPixelsEXT(Context *context, |
| 1567 | GLint x, |
| 1568 | GLint y, |
| 1569 | GLsizei width, |
| 1570 | GLsizei height, |
| 1571 | GLenum format, |
| 1572 | GLenum type, |
| 1573 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1574 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1575 | { |
| 1576 | if (bufSize < 0) |
| 1577 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1578 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1579 | return false; |
| 1580 | } |
| 1581 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1582 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1583 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1584 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1585 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1586 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1587 | GLint x, |
| 1588 | GLint y, |
| 1589 | GLsizei width, |
| 1590 | GLsizei height, |
| 1591 | GLenum format, |
| 1592 | GLenum type, |
| 1593 | GLsizei bufSize, |
| 1594 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1595 | GLsizei *columns, |
| 1596 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1597 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1598 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1599 | GLsizei writeLength = 0; |
| 1600 | GLsizei writeColumns = 0; |
| 1601 | GLsizei writeRows = 0; |
| 1602 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1603 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1604 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1605 | return false; |
| 1606 | } |
| 1607 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1608 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1609 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1610 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1611 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1612 | } |
| 1613 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1614 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1615 | { |
| 1616 | return false; |
| 1617 | } |
| 1618 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1619 | SetRobustLengthParam(length, writeLength); |
| 1620 | SetRobustLengthParam(columns, writeColumns); |
| 1621 | SetRobustLengthParam(rows, writeRows); |
| 1622 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1623 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1624 | } |
| 1625 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1626 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1627 | { |
| 1628 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1629 | !context->getExtensions().disjointTimerQuery) |
| 1630 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1631 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1632 | return false; |
| 1633 | } |
| 1634 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1635 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1636 | } |
| 1637 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1638 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1639 | { |
| 1640 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1641 | !context->getExtensions().disjointTimerQuery) |
| 1642 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1643 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1644 | return false; |
| 1645 | } |
| 1646 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1647 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1648 | } |
| 1649 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1650 | bool ValidateIsQueryEXT(gl::Context *context, GLuint id) |
| 1651 | { |
| 1652 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1653 | !context->getExtensions().disjointTimerQuery) |
| 1654 | { |
| 1655 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1656 | return false; |
| 1657 | } |
| 1658 | |
| 1659 | return true; |
| 1660 | } |
| 1661 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1662 | bool ValidateBeginQueryBase(gl::Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1663 | { |
| 1664 | if (!ValidQueryType(context, target)) |
| 1665 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1666 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1667 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1668 | } |
| 1669 | |
| 1670 | if (id == 0) |
| 1671 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1672 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1673 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1677 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1678 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1679 | // the active query for either target is non-zero), if <id> is the name of an |
| 1680 | // existing query object whose type does not match <target>, or if <id> is the |
| 1681 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1682 | // generated. |
| 1683 | |
| 1684 | // Ensure no other queries are active |
| 1685 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1686 | // separately that: |
| 1687 | // a) The query ID passed is not the current active query for any target/type |
| 1688 | // b) There are no active queries for the requested target (and in the case |
| 1689 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1690 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1691 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1692 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1693 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1694 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1695 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1696 | } |
| 1697 | |
| 1698 | Query *queryObject = context->getQuery(id, true, target); |
| 1699 | |
| 1700 | // check that name was obtained with glGenQueries |
| 1701 | if (!queryObject) |
| 1702 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1703 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1704 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | // check for type mismatch |
| 1708 | if (queryObject->getType() != target) |
| 1709 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1710 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1711 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | return true; |
| 1715 | } |
| 1716 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1717 | bool ValidateBeginQueryEXT(gl::Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1718 | { |
| 1719 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1720 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1721 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1722 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
| 1725 | |
| 1726 | return ValidateBeginQueryBase(context, target, id); |
| 1727 | } |
| 1728 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1729 | bool ValidateEndQueryBase(gl::Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1730 | { |
| 1731 | if (!ValidQueryType(context, target)) |
| 1732 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1733 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1734 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1735 | } |
| 1736 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1737 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1738 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1739 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1740 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1741 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1742 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1743 | } |
| 1744 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1745 | return true; |
| 1746 | } |
| 1747 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1748 | bool ValidateEndQueryEXT(gl::Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1749 | { |
| 1750 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1751 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1752 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1753 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1754 | return false; |
| 1755 | } |
| 1756 | |
| 1757 | return ValidateEndQueryBase(context, target); |
| 1758 | } |
| 1759 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1760 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1761 | { |
| 1762 | if (!context->getExtensions().disjointTimerQuery) |
| 1763 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1764 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1765 | return false; |
| 1766 | } |
| 1767 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1768 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1769 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1770 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1771 | return false; |
| 1772 | } |
| 1773 | |
| 1774 | Query *queryObject = context->getQuery(id, true, target); |
| 1775 | if (queryObject == nullptr) |
| 1776 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1777 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1778 | return false; |
| 1779 | } |
| 1780 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1781 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1782 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1783 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1784 | return false; |
| 1785 | } |
| 1786 | |
| 1787 | return true; |
| 1788 | } |
| 1789 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1790 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1791 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1792 | if (numParams) |
| 1793 | { |
| 1794 | *numParams = 0; |
| 1795 | } |
| 1796 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1797 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1798 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1799 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1800 | return false; |
| 1801 | } |
| 1802 | |
| 1803 | switch (pname) |
| 1804 | { |
| 1805 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1806 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1807 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1808 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1809 | return false; |
| 1810 | } |
| 1811 | break; |
| 1812 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1813 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1814 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1815 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1816 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1817 | return false; |
| 1818 | } |
| 1819 | break; |
| 1820 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1821 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1822 | return false; |
| 1823 | } |
| 1824 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1825 | if (numParams) |
| 1826 | { |
| 1827 | // All queries return only one value |
| 1828 | *numParams = 1; |
| 1829 | } |
| 1830 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1831 | return true; |
| 1832 | } |
| 1833 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1834 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1835 | { |
| 1836 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1837 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1838 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1839 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1840 | return false; |
| 1841 | } |
| 1842 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1843 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1844 | } |
| 1845 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1846 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1847 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1848 | GLenum pname, |
| 1849 | GLsizei bufSize, |
| 1850 | GLsizei *length, |
| 1851 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1852 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1853 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1854 | { |
| 1855 | return false; |
| 1856 | } |
| 1857 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1858 | GLsizei numParams = 0; |
| 1859 | |
| 1860 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1861 | { |
| 1862 | return false; |
| 1863 | } |
| 1864 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1865 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1866 | { |
| 1867 | return false; |
| 1868 | } |
| 1869 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1870 | SetRobustLengthParam(length, numParams); |
| 1871 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1872 | return true; |
| 1873 | } |
| 1874 | |
| 1875 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1876 | { |
| 1877 | if (numParams) |
| 1878 | { |
| 1879 | *numParams = 0; |
| 1880 | } |
| 1881 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1882 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1883 | |
| 1884 | if (!queryObject) |
| 1885 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1886 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1887 | return false; |
| 1888 | } |
| 1889 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1890 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1891 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1892 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1893 | return false; |
| 1894 | } |
| 1895 | |
| 1896 | switch (pname) |
| 1897 | { |
| 1898 | case GL_QUERY_RESULT_EXT: |
| 1899 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1900 | break; |
| 1901 | |
| 1902 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1903 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1904 | return false; |
| 1905 | } |
| 1906 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1907 | if (numParams) |
| 1908 | { |
| 1909 | *numParams = 1; |
| 1910 | } |
| 1911 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1912 | return true; |
| 1913 | } |
| 1914 | |
| 1915 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1916 | { |
| 1917 | if (!context->getExtensions().disjointTimerQuery) |
| 1918 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1919 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1920 | return false; |
| 1921 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1922 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1923 | } |
| 1924 | |
| 1925 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1926 | GLuint id, |
| 1927 | GLenum pname, |
| 1928 | GLsizei bufSize, |
| 1929 | GLsizei *length, |
| 1930 | GLint *params) |
| 1931 | { |
| 1932 | if (!context->getExtensions().disjointTimerQuery) |
| 1933 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1934 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1935 | return false; |
| 1936 | } |
| 1937 | |
| 1938 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1939 | { |
| 1940 | return false; |
| 1941 | } |
| 1942 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1943 | GLsizei numParams = 0; |
| 1944 | |
| 1945 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1946 | { |
| 1947 | return false; |
| 1948 | } |
| 1949 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1950 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1951 | { |
| 1952 | return false; |
| 1953 | } |
| 1954 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1955 | SetRobustLengthParam(length, numParams); |
| 1956 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1957 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1961 | { |
| 1962 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1963 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1964 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1965 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1966 | return false; |
| 1967 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1968 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1969 | } |
| 1970 | |
| 1971 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1972 | GLuint id, |
| 1973 | GLenum pname, |
| 1974 | GLsizei bufSize, |
| 1975 | GLsizei *length, |
| 1976 | GLuint *params) |
| 1977 | { |
| 1978 | if (!context->getExtensions().disjointTimerQuery && |
| 1979 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1980 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1981 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1982 | return false; |
| 1983 | } |
| 1984 | |
| 1985 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1986 | { |
| 1987 | return false; |
| 1988 | } |
| 1989 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1990 | GLsizei numParams = 0; |
| 1991 | |
| 1992 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1993 | { |
| 1994 | return false; |
| 1995 | } |
| 1996 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1997 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1998 | { |
| 1999 | return false; |
| 2000 | } |
| 2001 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2002 | SetRobustLengthParam(length, numParams); |
| 2003 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2004 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2005 | } |
| 2006 | |
| 2007 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 2008 | { |
| 2009 | if (!context->getExtensions().disjointTimerQuery) |
| 2010 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2011 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2012 | return false; |
| 2013 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2014 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2015 | } |
| 2016 | |
| 2017 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 2018 | GLuint id, |
| 2019 | GLenum pname, |
| 2020 | GLsizei bufSize, |
| 2021 | GLsizei *length, |
| 2022 | GLint64 *params) |
| 2023 | { |
| 2024 | if (!context->getExtensions().disjointTimerQuery) |
| 2025 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2026 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2027 | return false; |
| 2028 | } |
| 2029 | |
| 2030 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2031 | { |
| 2032 | return false; |
| 2033 | } |
| 2034 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2035 | GLsizei numParams = 0; |
| 2036 | |
| 2037 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2038 | { |
| 2039 | return false; |
| 2040 | } |
| 2041 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2042 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2043 | { |
| 2044 | return false; |
| 2045 | } |
| 2046 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2047 | SetRobustLengthParam(length, numParams); |
| 2048 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2049 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2053 | { |
| 2054 | if (!context->getExtensions().disjointTimerQuery) |
| 2055 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2056 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2057 | return false; |
| 2058 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2059 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2060 | } |
| 2061 | |
| 2062 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2063 | GLuint id, |
| 2064 | GLenum pname, |
| 2065 | GLsizei bufSize, |
| 2066 | GLsizei *length, |
| 2067 | GLuint64 *params) |
| 2068 | { |
| 2069 | if (!context->getExtensions().disjointTimerQuery) |
| 2070 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2071 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2072 | return false; |
| 2073 | } |
| 2074 | |
| 2075 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2076 | { |
| 2077 | return false; |
| 2078 | } |
| 2079 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2080 | GLsizei numParams = 0; |
| 2081 | |
| 2082 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2083 | { |
| 2084 | return false; |
| 2085 | } |
| 2086 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2087 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2088 | { |
| 2089 | return false; |
| 2090 | } |
| 2091 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2092 | SetRobustLengthParam(length, numParams); |
| 2093 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2094 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2095 | } |
| 2096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2097 | bool ValidateUniformCommonBase(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2098 | gl::Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2099 | GLint location, |
| 2100 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2101 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2102 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2103 | // TODO(Jiajia): Add image uniform check in future. |
| 2104 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2105 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2106 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2107 | return false; |
| 2108 | } |
| 2109 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2110 | if (!program) |
| 2111 | { |
| 2112 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2113 | return false; |
| 2114 | } |
| 2115 | |
| 2116 | if (!program->isLinked()) |
| 2117 | { |
| 2118 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2119 | return false; |
| 2120 | } |
| 2121 | |
| 2122 | if (location == -1) |
| 2123 | { |
| 2124 | // Silently ignore the uniform command |
| 2125 | return false; |
| 2126 | } |
| 2127 | |
| 2128 | const auto &uniformLocations = program->getUniformLocations(); |
| 2129 | size_t castedLocation = static_cast<size_t>(location); |
| 2130 | if (castedLocation >= uniformLocations.size()) |
| 2131 | { |
| 2132 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2133 | return false; |
| 2134 | } |
| 2135 | |
| 2136 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2137 | if (uniformLocation.ignored) |
| 2138 | { |
| 2139 | // Silently ignore the uniform command |
| 2140 | return false; |
| 2141 | } |
| 2142 | |
| 2143 | if (!uniformLocation.used()) |
| 2144 | { |
| 2145 | context->handleError(InvalidOperation()); |
| 2146 | return false; |
| 2147 | } |
| 2148 | |
| 2149 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2150 | |
| 2151 | // attempting to write an array to a non-array uniform is an INVALID_OPERATION |
Jamie Madill | 2fc0806 | 2018-05-10 15:10:55 -0400 | [diff] [blame] | 2152 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2153 | { |
| 2154 | context->handleError(InvalidOperation()); |
| 2155 | return false; |
| 2156 | } |
| 2157 | |
| 2158 | *uniformOut = &uniform; |
| 2159 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2160 | } |
| 2161 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2162 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2163 | GLenum uniformType, |
| 2164 | GLsizei count, |
| 2165 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2166 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2167 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2168 | // It is compatible with INT or BOOL. |
| 2169 | // Do these cheap tests first, for a little extra speed. |
| 2170 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2171 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2172 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2173 | } |
| 2174 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2175 | if (IsSamplerType(uniformType)) |
| 2176 | { |
| 2177 | // Check that the values are in range. |
| 2178 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2179 | for (GLsizei i = 0; i < count; ++i) |
| 2180 | { |
| 2181 | if (value[i] < 0 || value[i] >= max) |
| 2182 | { |
| 2183 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2184 | return false; |
| 2185 | } |
| 2186 | } |
| 2187 | return true; |
| 2188 | } |
| 2189 | |
| 2190 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2191 | return false; |
| 2192 | } |
| 2193 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2194 | bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2195 | { |
| 2196 | // Check that the value type is compatible with uniform type. |
| 2197 | // Do the cheaper test first, for a little extra speed. |
| 2198 | if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType) |
| 2199 | { |
| 2200 | return true; |
| 2201 | } |
| 2202 | |
| 2203 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch); |
| 2204 | return false; |
| 2205 | } |
| 2206 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2207 | bool ValidateUniformMatrixValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2208 | { |
| 2209 | // Check that the value type is compatible with uniform type. |
| 2210 | if (valueType == uniformType) |
| 2211 | { |
| 2212 | return true; |
| 2213 | } |
| 2214 | |
| 2215 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2216 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2217 | } |
| 2218 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2219 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2220 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2221 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2222 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2223 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2224 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2225 | } |
| 2226 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2227 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2228 | { |
| 2229 | const LinkedUniform *uniform = nullptr; |
| 2230 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2231 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2232 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2233 | } |
| 2234 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2235 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2236 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2237 | GLint location, |
| 2238 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2239 | GLboolean transpose) |
| 2240 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2241 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2242 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2243 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2244 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2245 | } |
| 2246 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2247 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2248 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2249 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2250 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2251 | } |
| 2252 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2253 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2254 | { |
| 2255 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2256 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2257 | context->handleError(InvalidEnum()); |
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 | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2261 | const Caps &caps = context->getCaps(); |
| 2262 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2263 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2264 | { |
| 2265 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2266 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2267 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2268 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2269 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2270 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2271 | } |
| 2272 | } |
| 2273 | |
| 2274 | switch (pname) |
| 2275 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2276 | case GL_TEXTURE_BINDING_2D: |
| 2277 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2278 | case GL_TEXTURE_BINDING_3D: |
| 2279 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2280 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2281 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2282 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2283 | if (!context->getExtensions().textureRectangle) |
| 2284 | { |
| 2285 | context->handleError(InvalidEnum() |
| 2286 | << "ANGLE_texture_rectangle extension not present"); |
| 2287 | return false; |
| 2288 | } |
| 2289 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2290 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2291 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2292 | !context->getExtensions().eglImageExternal) |
| 2293 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2294 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2295 | "nor GL_OES_EGL_image_external " |
| 2296 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2297 | return false; |
| 2298 | } |
| 2299 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2300 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2301 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2302 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2303 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2304 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2305 | ASSERT(readFramebuffer); |
| 2306 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2307 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2308 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2309 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2312 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2313 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2314 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2315 | return false; |
| 2316 | } |
| 2317 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2318 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2319 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2320 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2321 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2322 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2323 | } |
| 2324 | } |
| 2325 | break; |
| 2326 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2327 | default: |
| 2328 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2332 | if (*numParams == 0) |
| 2333 | { |
| 2334 | return false; |
| 2335 | } |
| 2336 | |
| 2337 | return true; |
| 2338 | } |
| 2339 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2340 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2341 | GLenum pname, |
| 2342 | GLsizei bufSize, |
| 2343 | GLsizei *length, |
| 2344 | GLboolean *params) |
| 2345 | { |
| 2346 | GLenum nativeType; |
| 2347 | unsigned int numParams = 0; |
| 2348 | |
| 2349 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2350 | { |
| 2351 | return false; |
| 2352 | } |
| 2353 | |
| 2354 | SetRobustLengthParam(length, numParams); |
| 2355 | |
| 2356 | return true; |
| 2357 | } |
| 2358 | |
| 2359 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2360 | GLenum pname, |
| 2361 | GLsizei bufSize, |
| 2362 | GLsizei *length, |
| 2363 | GLfloat *params) |
| 2364 | { |
| 2365 | GLenum nativeType; |
| 2366 | unsigned int numParams = 0; |
| 2367 | |
| 2368 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2369 | { |
| 2370 | return false; |
| 2371 | } |
| 2372 | |
| 2373 | SetRobustLengthParam(length, numParams); |
| 2374 | |
| 2375 | return true; |
| 2376 | } |
| 2377 | |
| 2378 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2379 | GLenum pname, |
| 2380 | GLsizei bufSize, |
| 2381 | GLsizei *length, |
| 2382 | GLint *data) |
| 2383 | { |
| 2384 | GLenum nativeType; |
| 2385 | unsigned int numParams = 0; |
| 2386 | |
| 2387 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2388 | { |
| 2389 | return false; |
| 2390 | } |
| 2391 | |
| 2392 | SetRobustLengthParam(length, numParams); |
| 2393 | |
| 2394 | return true; |
| 2395 | } |
| 2396 | |
| 2397 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2398 | GLenum pname, |
| 2399 | GLsizei bufSize, |
| 2400 | GLsizei *length, |
| 2401 | GLint64 *data) |
| 2402 | { |
| 2403 | GLenum nativeType; |
| 2404 | unsigned int numParams = 0; |
| 2405 | |
| 2406 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2407 | { |
| 2408 | return false; |
| 2409 | } |
| 2410 | |
| 2411 | if (nativeType == GL_INT_64_ANGLEX) |
| 2412 | { |
| 2413 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2414 | return false; |
| 2415 | } |
| 2416 | |
| 2417 | SetRobustLengthParam(length, numParams); |
| 2418 | return true; |
| 2419 | } |
| 2420 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2421 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2422 | GLenum pname, |
| 2423 | GLsizei bufSize, |
| 2424 | GLenum *nativeType, |
| 2425 | unsigned int *numParams) |
| 2426 | { |
| 2427 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2428 | { |
| 2429 | return false; |
| 2430 | } |
| 2431 | |
| 2432 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2433 | { |
| 2434 | return false; |
| 2435 | } |
| 2436 | |
| 2437 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2438 | { |
| 2439 | return false; |
| 2440 | } |
| 2441 | |
| 2442 | return true; |
| 2443 | } |
| 2444 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2445 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2446 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2447 | GLint level, |
| 2448 | GLenum internalformat, |
| 2449 | bool isSubImage, |
| 2450 | GLint xoffset, |
| 2451 | GLint yoffset, |
| 2452 | GLint zoffset, |
| 2453 | GLint x, |
| 2454 | GLint y, |
| 2455 | GLsizei width, |
| 2456 | GLsizei height, |
| 2457 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2458 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2459 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2460 | TextureType texType = TextureTargetToType(target); |
| 2461 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2462 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2463 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2464 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2465 | return false; |
| 2466 | } |
| 2467 | |
| 2468 | if (width < 0 || height < 0) |
| 2469 | { |
| 2470 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2471 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2472 | } |
| 2473 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2474 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2475 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2476 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2477 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2478 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | if (border != 0) |
| 2482 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2483 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2484 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2485 | } |
| 2486 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2487 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2488 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2489 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2490 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2491 | } |
| 2492 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2493 | const gl::State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2494 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2495 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2496 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2497 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2498 | } |
| 2499 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2500 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2501 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2502 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2503 | } |
| 2504 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2505 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2506 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2507 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2508 | return false; |
| 2509 | } |
| 2510 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2511 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2512 | // 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] | 2513 | // 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] | 2514 | // 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] | 2515 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2516 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2517 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2518 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2519 | return false; |
| 2520 | } |
| 2521 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2522 | // ANGLE_multiview spec, Revision 1: |
| 2523 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2524 | // INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the current read framebuffer |
| 2525 | // is not NONE. |
| 2526 | if (source->getMultiviewLayout() != GL_NONE) |
| 2527 | { |
| 2528 | context->handleError(InvalidFramebufferOperation() |
| 2529 | << "The active read framebuffer object has multiview attachments."); |
| 2530 | return false; |
| 2531 | } |
| 2532 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2533 | const gl::Caps &caps = context->getCaps(); |
| 2534 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2535 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2536 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2537 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2538 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2539 | maxDimension = caps.max2DTextureSize; |
| 2540 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2541 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2542 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2543 | maxDimension = caps.maxCubeMapTextureSize; |
| 2544 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2545 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2546 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2547 | maxDimension = caps.maxRectangleTextureSize; |
| 2548 | break; |
| 2549 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2550 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2551 | maxDimension = caps.max2DTextureSize; |
| 2552 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2553 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2554 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2555 | maxDimension = caps.max3DTextureSize; |
| 2556 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2557 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2558 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2559 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2560 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2561 | } |
| 2562 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2563 | gl::Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2564 | if (!texture) |
| 2565 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2566 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2567 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2568 | } |
| 2569 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2570 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2571 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2572 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2573 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2574 | } |
| 2575 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2576 | const gl::InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2577 | isSubImage ? *texture->getFormat(target, level).info |
| 2578 | : gl::GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2579 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2580 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2581 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2582 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2583 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | if (isSubImage) |
| 2587 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2588 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2589 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2590 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2591 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2592 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2593 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2594 | } |
| 2595 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2596 | else |
| 2597 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2598 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2599 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2600 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2601 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2602 | } |
| 2603 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2604 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2605 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2606 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2607 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2608 | } |
| 2609 | |
| 2610 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2611 | if (static_cast<int>(width) > maxLevelDimension || |
| 2612 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2613 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2614 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2615 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2616 | } |
| 2617 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2618 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2619 | if (textureFormatOut) |
| 2620 | { |
| 2621 | *textureFormatOut = texture->getFormat(target, level); |
| 2622 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2623 | |
| 2624 | // Detect texture copying feedback loops for WebGL. |
| 2625 | if (context->getExtensions().webglCompatibility) |
| 2626 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2627 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2628 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2629 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2630 | return false; |
| 2631 | } |
| 2632 | } |
| 2633 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2634 | return true; |
| 2635 | } |
| 2636 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2637 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2638 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2639 | const Extensions &extensions = context->getExtensions(); |
| 2640 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2641 | switch (mode) |
| 2642 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2643 | case PrimitiveMode::Points: |
| 2644 | case PrimitiveMode::Lines: |
| 2645 | case PrimitiveMode::LineLoop: |
| 2646 | case PrimitiveMode::LineStrip: |
| 2647 | case PrimitiveMode::Triangles: |
| 2648 | case PrimitiveMode::TriangleStrip: |
| 2649 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2650 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2651 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2652 | case PrimitiveMode::LinesAdjacency: |
| 2653 | case PrimitiveMode::LineStripAdjacency: |
| 2654 | case PrimitiveMode::TrianglesAdjacency: |
| 2655 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2656 | if (!extensions.geometryShader) |
| 2657 | { |
| 2658 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2659 | return false; |
| 2660 | } |
| 2661 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2662 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2663 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2664 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2665 | } |
| 2666 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2667 | if (count < 0) |
| 2668 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2669 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2670 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2671 | } |
| 2672 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2673 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2674 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2675 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2676 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2677 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2678 | if (!extensions.webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2679 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2680 | // Check for mapped buffers |
| 2681 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2682 | if (state.hasMappedBuffer(BufferBinding::Array)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2683 | { |
| 2684 | context->handleError(InvalidOperation()); |
| 2685 | return false; |
| 2686 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2687 | } |
| 2688 | |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2689 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2690 | // Section 6.10 of the WebGL 1.0 spec. |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2691 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2692 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2693 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2694 | ASSERT(framebuffer); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 2695 | const FramebufferAttachment *dsAttachment = |
| 2696 | framebuffer->getStencilOrDepthStencilAttachment(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2697 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2698 | ASSERT(stencilBits <= 8); |
| 2699 | |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 2700 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2701 | if (depthStencilState.stencilTest && stencilBits > 0) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2702 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2703 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2704 | |
| 2705 | bool differentRefs = |
| 2706 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2707 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2708 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2709 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2710 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2711 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2712 | |
| 2713 | if (differentRefs || differentWritemasks || differentMasks) |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2714 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2715 | if (!extensions.webglCompatibility) |
| 2716 | { |
Jamie Madill | a2f043d | 2018-07-10 17:21:20 -0400 | [diff] [blame] | 2717 | WARN() << "This ANGLE implementation does not support separate front/back " |
| 2718 | "stencil writemasks, reference values, or stencil mask values."; |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2719 | } |
| 2720 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StencilReferenceMaskOrMismatch); |
| 2721 | return false; |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2722 | } |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2723 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2724 | } |
| 2725 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2726 | if (!ValidateFramebufferComplete(context, framebuffer)) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2727 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2728 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2729 | } |
| 2730 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2731 | // If we are running GLES1, there is no current program. |
| 2732 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2733 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2734 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2735 | gl::Program *program = state.getProgram(); |
| 2736 | if (!program) |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2737 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2738 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2739 | return false; |
| 2740 | } |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2741 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2742 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2743 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2744 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2745 | // produce undefined result. |
| 2746 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2747 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2748 | { |
| 2749 | context->handleError(InvalidOperation() |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2750 | << "It is a undefined behaviour to render without " |
| 2751 | "vertex shader stage or fragment shader stage."); |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2752 | return false; |
| 2753 | } |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2754 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2755 | if (!program->validateSamplers(nullptr, context->getCaps())) |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2756 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2757 | context->handleError(InvalidOperation()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2758 | return false; |
| 2759 | } |
| 2760 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2761 | if (extensions.multiview) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2762 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2763 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2764 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2765 | if (framebufferNumViews != programNumViews) |
| 2766 | { |
| 2767 | context->handleError(InvalidOperation() |
| 2768 | << "The number of views in the active program " |
| 2769 | "and draw framebuffer does not match."); |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2774 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2775 | framebufferNumViews > 1) |
| 2776 | { |
| 2777 | context->handleError(InvalidOperation() |
| 2778 | << "There is an active transform feedback object " |
| 2779 | "when the number of views in the active draw " |
| 2780 | "framebuffer is greater than 1."); |
| 2781 | return false; |
| 2782 | } |
| 2783 | |
| 2784 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2785 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2786 | { |
| 2787 | context->handleError(InvalidOperation() |
| 2788 | << "There is an active query for target " |
| 2789 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2790 | "views in the active draw framebuffer is " |
| 2791 | "greater than 1."); |
| 2792 | return false; |
| 2793 | } |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2794 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2795 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2796 | // Do geometry shader specific validations |
| 2797 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2798 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2799 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2800 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2801 | { |
| 2802 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2803 | IncompatibleDrawModeAgainstGeometryShader); |
| 2804 | return false; |
| 2805 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2806 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2807 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2808 | // Uniform buffer validation |
| 2809 | for (unsigned int uniformBlockIndex = 0; |
| 2810 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2811 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2812 | const gl::InterfaceBlock &uniformBlock = |
| 2813 | program->getUniformBlockByIndex(uniformBlockIndex); |
| 2814 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
| 2815 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2816 | state.getIndexedUniformBuffer(blockBinding); |
| 2817 | |
| 2818 | if (uniformBuffer.get() == nullptr) |
| 2819 | { |
| 2820 | // undefined behaviour |
| 2821 | context->handleError( |
| 2822 | InvalidOperation() |
| 2823 | << "It is undefined behaviour to have a used but unbound uniform buffer."); |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2828 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2829 | { |
| 2830 | // undefined behaviour |
| 2831 | context->handleError( |
| 2832 | InvalidOperation() |
| 2833 | << "It is undefined behaviour to use a uniform buffer that is too small."); |
| 2834 | return false; |
| 2835 | } |
| 2836 | |
| 2837 | if (extensions.webglCompatibility && |
| 2838 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2839 | { |
| 2840 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2841 | UniformBufferBoundForTransformFeedback); |
| 2842 | return false; |
| 2843 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2844 | } |
| 2845 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2846 | // Do some additonal WebGL-specific validation |
| 2847 | if (extensions.webglCompatibility) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2848 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2849 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2850 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2851 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2852 | { |
| 2853 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2854 | TransformFeedbackBufferDoubleBound); |
| 2855 | return false; |
| 2856 | } |
| 2857 | // Detect rendering feedback loops for WebGL. |
| 2858 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2859 | { |
| 2860 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
| 2861 | return false; |
| 2862 | } |
| 2863 | |
| 2864 | // Detect that the vertex shader input types match the attribute types |
| 2865 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2866 | { |
| 2867 | return false; |
| 2868 | } |
| 2869 | |
| 2870 | // Detect that the color buffer types match the fragment shader output types |
| 2871 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2872 | { |
| 2873 | return false; |
| 2874 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2875 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2876 | } |
| 2877 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2878 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2879 | } |
| 2880 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2881 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2882 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2883 | GLint first, |
| 2884 | GLsizei count, |
| 2885 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2886 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2887 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2888 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2889 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2890 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2891 | } |
| 2892 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2893 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2894 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2895 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2896 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2897 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2898 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2899 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2900 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2901 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2902 | return false; |
| 2903 | } |
| 2904 | |
| 2905 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2906 | { |
| 2907 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2908 | return false; |
| 2909 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2910 | } |
| 2911 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2912 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2913 | { |
| 2914 | return false; |
| 2915 | } |
| 2916 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2917 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2918 | // - first < 0 has been checked as an error condition. |
| 2919 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2920 | // 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] | 2921 | ASSERT(first >= 0); |
| 2922 | if (count > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2923 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2924 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2925 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2926 | { |
| 2927 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2928 | return false; |
| 2929 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2930 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2931 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex), count)) |
| 2932 | { |
| 2933 | return false; |
| 2934 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2935 | } |
| 2936 | |
| 2937 | return true; |
| 2938 | } |
| 2939 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2940 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2941 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2942 | GLint first, |
| 2943 | GLsizei count, |
| 2944 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2945 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2946 | if (!context->getExtensions().instancedArrays) |
| 2947 | { |
| 2948 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2949 | return false; |
| 2950 | } |
| 2951 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2952 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2953 | { |
| 2954 | return false; |
| 2955 | } |
| 2956 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2957 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2958 | } |
| 2959 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2960 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2961 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2962 | switch (type) |
| 2963 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2964 | case GL_UNSIGNED_BYTE: |
| 2965 | case GL_UNSIGNED_SHORT: |
| 2966 | break; |
| 2967 | case GL_UNSIGNED_INT: |
| 2968 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2969 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2970 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2971 | return false; |
| 2972 | } |
| 2973 | break; |
| 2974 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2975 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2976 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2977 | } |
| 2978 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2979 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2980 | |
| 2981 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2982 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2983 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2984 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2985 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2986 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2987 | if (context->getExtensions().geometryShader) |
| 2988 | { |
| 2989 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2990 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2991 | { |
| 2992 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2993 | return false; |
| 2994 | } |
| 2995 | } |
| 2996 | else |
| 2997 | { |
| 2998 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2999 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 3000 | // 86) |
| 3001 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3002 | UnsupportedDrawModeForTransformFeedback); |
| 3003 | return false; |
| 3004 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3005 | } |
| 3006 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3007 | return true; |
| 3008 | } |
| 3009 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3010 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3011 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3012 | GLsizei count, |
| 3013 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3014 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3015 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3016 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3017 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3018 | return false; |
| 3019 | |
| 3020 | const State &state = context->getGLState(); |
| 3021 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3022 | if (!ValidateDrawBase(context, mode, count)) |
| 3023 | { |
| 3024 | return false; |
| 3025 | } |
| 3026 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3027 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 3028 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3029 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3030 | if (!context->getExtensions().webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3031 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3032 | // Check for mapped buffers |
| 3033 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3034 | if (state.hasMappedBuffer(gl::BufferBinding::ElementArray)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3035 | { |
| 3036 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3037 | return false; |
| 3038 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3039 | } |
| 3040 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3041 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 3042 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3043 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3044 | GLuint typeBytes = gl::GetTypeInfo(type).bytes; |
| 3045 | |
| 3046 | if (context->getExtensions().webglCompatibility) |
| 3047 | { |
| 3048 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3049 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3050 | { |
| 3051 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3052 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3053 | // 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] | 3054 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3055 | return false; |
| 3056 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3057 | |
| 3058 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3059 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3060 | // error is generated. |
| 3061 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3062 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3063 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3064 | return false; |
| 3065 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3066 | } |
| 3067 | |
| 3068 | if (context->getExtensions().webglCompatibility || |
| 3069 | !context->getGLState().areClientArraysEnabled()) |
| 3070 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3071 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3072 | { |
| 3073 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3074 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3075 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3076 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3077 | return false; |
| 3078 | } |
| 3079 | } |
| 3080 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3081 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3082 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3083 | // This is an application error that would normally result in a crash, but we catch it and |
| 3084 | // return an error |
| 3085 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3086 | return false; |
| 3087 | } |
| 3088 | |
| 3089 | if (count > 0 && elementArrayBuffer) |
| 3090 | { |
| 3091 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3092 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3093 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3094 | constexpr uint64_t kMaxTypeSize = 8; |
| 3095 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3096 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3097 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3098 | |
| 3099 | uint64_t typeSize = typeBytes; |
| 3100 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3101 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3102 | |
| 3103 | // Doing the multiplication here is overflow-safe |
| 3104 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3105 | |
| 3106 | // The offset can be any value, check for overflows |
| 3107 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3108 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3109 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3110 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3111 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3112 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3113 | |
| 3114 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3115 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3116 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3117 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3118 | return false; |
| 3119 | } |
| 3120 | |
| 3121 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3122 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3123 | { |
| 3124 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3125 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3126 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3127 | |
| 3128 | if (context->getExtensions().webglCompatibility && |
| 3129 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3130 | { |
| 3131 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3132 | ElementArrayBufferBoundForTransformFeedback); |
| 3133 | return false; |
| 3134 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3135 | } |
| 3136 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3137 | if (context->getExtensions().robustBufferAccessBehavior) |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3138 | { |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3139 | // Here we use maxVertex = 0 and vertexCount = 1 to avoid retrieving IndexRange when robust |
| 3140 | // access is enabled. |
| 3141 | if (!ValidateDrawAttribs(context, primcount, 0, 1)) |
| 3142 | { |
| 3143 | return false; |
| 3144 | } |
| 3145 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3146 | else if (count == 0) |
| 3147 | { |
| 3148 | // ValidateDrawAttribs also does some extra validation that is independent of the vertex |
| 3149 | // count. |
| 3150 | if (!ValidateDrawAttribs(context, 0, 0, 0)) |
| 3151 | { |
| 3152 | return false; |
| 3153 | } |
| 3154 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3155 | else |
| 3156 | { |
| 3157 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3158 | const DrawCallParams ¶ms = context->getParams<DrawCallParams>(); |
| 3159 | ANGLE_VALIDATION_TRY(params.ensureIndexRangeResolved(context)); |
| 3160 | const IndexRange &indexRange = params.getIndexRange(); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3161 | |
| 3162 | // If we use an index greater than our maximum supported index range, return an error. |
| 3163 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3164 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3165 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3166 | { |
| 3167 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3168 | return false; |
| 3169 | } |
| 3170 | |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3171 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end), |
| 3172 | static_cast<GLint>(indexRange.vertexCount()))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3173 | { |
| 3174 | return false; |
| 3175 | } |
| 3176 | |
| 3177 | // 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] | 3178 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3179 | } |
| 3180 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3181 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3182 | } |
| 3183 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3184 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3185 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3186 | GLsizei count, |
| 3187 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3188 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3189 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3190 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3191 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3192 | } |
| 3193 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3194 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3195 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3196 | GLsizei count, |
| 3197 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3198 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3199 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3200 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3201 | if (!context->getExtensions().instancedArrays) |
| 3202 | { |
| 3203 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3204 | return false; |
| 3205 | } |
| 3206 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3207 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3208 | { |
| 3209 | return false; |
| 3210 | } |
| 3211 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3212 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3213 | } |
| 3214 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3215 | bool ValidateFramebufferTextureBase(Context *context, |
| 3216 | GLenum target, |
| 3217 | GLenum attachment, |
| 3218 | GLuint texture, |
| 3219 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3220 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3221 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3222 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3223 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3224 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3225 | } |
| 3226 | |
| 3227 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3228 | { |
| 3229 | return false; |
| 3230 | } |
| 3231 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3232 | if (texture != 0) |
| 3233 | { |
| 3234 | gl::Texture *tex = context->getTexture(texture); |
| 3235 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3236 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3237 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3238 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3239 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3240 | } |
| 3241 | |
| 3242 | if (level < 0) |
| 3243 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3244 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3245 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3246 | } |
| 3247 | } |
| 3248 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3249 | const gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3250 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3251 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3252 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3253 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3254 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3255 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | return true; |
| 3259 | } |
| 3260 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3261 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3262 | { |
| 3263 | if (program == 0) |
| 3264 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3265 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3266 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3267 | } |
| 3268 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3269 | gl::Program *programObject = GetValidProgram(context, program); |
| 3270 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3271 | { |
| 3272 | return false; |
| 3273 | } |
| 3274 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3275 | if (!programObject || !programObject->isLinked()) |
| 3276 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3277 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3278 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3279 | } |
| 3280 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3281 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3282 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3283 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3284 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3285 | } |
| 3286 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3287 | return true; |
| 3288 | } |
| 3289 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3290 | static bool ValidateSizedGetUniform(Context *context, |
| 3291 | GLuint program, |
| 3292 | GLint location, |
| 3293 | GLsizei bufSize, |
| 3294 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3295 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3296 | if (length) |
| 3297 | { |
| 3298 | *length = 0; |
| 3299 | } |
| 3300 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3301 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3302 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3303 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3304 | } |
| 3305 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3306 | if (bufSize < 0) |
| 3307 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3308 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3309 | return false; |
| 3310 | } |
| 3311 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3312 | gl::Program *programObject = context->getProgram(program); |
| 3313 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3314 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3315 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3316 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3317 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3318 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3319 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3320 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3321 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3322 | } |
| 3323 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3324 | if (length) |
| 3325 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3326 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3327 | } |
| 3328 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3329 | return true; |
| 3330 | } |
| 3331 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3332 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3333 | GLuint program, |
| 3334 | GLint location, |
| 3335 | GLsizei bufSize, |
| 3336 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3337 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3338 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3339 | } |
| 3340 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3341 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3342 | GLuint program, |
| 3343 | GLint location, |
| 3344 | GLsizei bufSize, |
| 3345 | GLsizei *length, |
| 3346 | GLfloat *params) |
| 3347 | { |
| 3348 | UNIMPLEMENTED(); |
| 3349 | return false; |
| 3350 | } |
| 3351 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3352 | bool ValidateGetnUniformivEXT(Context *context, |
| 3353 | GLuint program, |
| 3354 | GLint location, |
| 3355 | GLsizei bufSize, |
| 3356 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3357 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3358 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3359 | } |
| 3360 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3361 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3362 | GLuint program, |
| 3363 | GLint location, |
| 3364 | GLsizei bufSize, |
| 3365 | GLsizei *length, |
| 3366 | GLint *params) |
| 3367 | { |
| 3368 | UNIMPLEMENTED(); |
| 3369 | return false; |
| 3370 | } |
| 3371 | |
| 3372 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3373 | GLuint program, |
| 3374 | GLint location, |
| 3375 | GLsizei bufSize, |
| 3376 | GLsizei *length, |
| 3377 | GLuint *params) |
| 3378 | { |
| 3379 | UNIMPLEMENTED(); |
| 3380 | return false; |
| 3381 | } |
| 3382 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3383 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3384 | GLuint program, |
| 3385 | GLint location, |
| 3386 | GLsizei bufSize, |
| 3387 | GLsizei *length, |
| 3388 | GLfloat *params) |
| 3389 | { |
| 3390 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3391 | { |
| 3392 | return false; |
| 3393 | } |
| 3394 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3395 | GLsizei writeLength = 0; |
| 3396 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3397 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3398 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3399 | { |
| 3400 | return false; |
| 3401 | } |
| 3402 | |
| 3403 | SetRobustLengthParam(length, writeLength); |
| 3404 | |
| 3405 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3409 | GLuint program, |
| 3410 | GLint location, |
| 3411 | GLsizei bufSize, |
| 3412 | GLsizei *length, |
| 3413 | GLint *params) |
| 3414 | { |
| 3415 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3416 | { |
| 3417 | return false; |
| 3418 | } |
| 3419 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3420 | GLsizei writeLength = 0; |
| 3421 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3422 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3423 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3424 | { |
| 3425 | return false; |
| 3426 | } |
| 3427 | |
| 3428 | SetRobustLengthParam(length, writeLength); |
| 3429 | |
| 3430 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3431 | } |
| 3432 | |
| 3433 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3434 | GLuint program, |
| 3435 | GLint location, |
| 3436 | GLsizei bufSize, |
| 3437 | GLsizei *length, |
| 3438 | GLuint *params) |
| 3439 | { |
| 3440 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3441 | { |
| 3442 | return false; |
| 3443 | } |
| 3444 | |
| 3445 | if (context->getClientMajorVersion() < 3) |
| 3446 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3447 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3448 | return false; |
| 3449 | } |
| 3450 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3451 | GLsizei writeLength = 0; |
| 3452 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3453 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3454 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3455 | { |
| 3456 | return false; |
| 3457 | } |
| 3458 | |
| 3459 | SetRobustLengthParam(length, writeLength); |
| 3460 | |
| 3461 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3462 | } |
| 3463 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3464 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3465 | GLenum target, |
| 3466 | GLsizei numAttachments, |
| 3467 | const GLenum *attachments, |
| 3468 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3469 | { |
| 3470 | if (numAttachments < 0) |
| 3471 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3472 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3473 | return false; |
| 3474 | } |
| 3475 | |
| 3476 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3477 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3478 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3479 | { |
| 3480 | if (defaultFramebuffer) |
| 3481 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3482 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3483 | return false; |
| 3484 | } |
| 3485 | |
| 3486 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3487 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3488 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3489 | "greater than the maximum supported " |
| 3490 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3491 | return false; |
| 3492 | } |
| 3493 | } |
| 3494 | else |
| 3495 | { |
| 3496 | switch (attachments[i]) |
| 3497 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3498 | case GL_DEPTH_ATTACHMENT: |
| 3499 | case GL_STENCIL_ATTACHMENT: |
| 3500 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3501 | if (defaultFramebuffer) |
| 3502 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3503 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3504 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3505 | return false; |
| 3506 | } |
| 3507 | break; |
| 3508 | case GL_COLOR: |
| 3509 | case GL_DEPTH: |
| 3510 | case GL_STENCIL: |
| 3511 | if (!defaultFramebuffer) |
| 3512 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3513 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3514 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3515 | return false; |
| 3516 | } |
| 3517 | break; |
| 3518 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3519 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3520 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3521 | } |
| 3522 | } |
| 3523 | } |
| 3524 | |
| 3525 | return true; |
| 3526 | } |
| 3527 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3528 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3529 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3530 | if (!context->getExtensions().debugMarker) |
| 3531 | { |
| 3532 | // The debug marker calls should not set error state |
| 3533 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3534 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3535 | return false; |
| 3536 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3537 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3538 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3539 | if (length < 0) |
| 3540 | { |
| 3541 | return false; |
| 3542 | } |
| 3543 | |
| 3544 | if (marker == nullptr) |
| 3545 | { |
| 3546 | return false; |
| 3547 | } |
| 3548 | |
| 3549 | return true; |
| 3550 | } |
| 3551 | |
| 3552 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3553 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3554 | if (!context->getExtensions().debugMarker) |
| 3555 | { |
| 3556 | // The debug marker calls should not set error state |
| 3557 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3558 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3559 | return false; |
| 3560 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3561 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3562 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3563 | if (length < 0) |
| 3564 | { |
| 3565 | return false; |
| 3566 | } |
| 3567 | |
| 3568 | if (length > 0 && marker == nullptr) |
| 3569 | { |
| 3570 | return false; |
| 3571 | } |
| 3572 | |
| 3573 | return true; |
| 3574 | } |
| 3575 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3576 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3577 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3578 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3579 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3580 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3581 | return false; |
| 3582 | } |
| 3583 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3584 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3585 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3586 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3587 | if (!context->getExtensions().eglImage) |
| 3588 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3589 | context->handleError(InvalidEnum() |
| 3590 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3591 | } |
| 3592 | break; |
| 3593 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3594 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3595 | if (!context->getExtensions().eglImageExternal) |
| 3596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3597 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3598 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3599 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3600 | break; |
| 3601 | |
| 3602 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3603 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3604 | return false; |
| 3605 | } |
| 3606 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3607 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3608 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3609 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3610 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3611 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3612 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3613 | return false; |
| 3614 | } |
| 3615 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3616 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3617 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3618 | context->handleError(InvalidOperation() |
| 3619 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3620 | return false; |
| 3621 | } |
| 3622 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3623 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3624 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3625 | if (!textureCaps.texturable) |
| 3626 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3627 | context->handleError(InvalidOperation() |
| 3628 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3629 | return false; |
| 3630 | } |
| 3631 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3632 | return true; |
| 3633 | } |
| 3634 | |
| 3635 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3636 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3637 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3638 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3639 | if (!context->getExtensions().eglImage) |
| 3640 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3641 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3642 | return false; |
| 3643 | } |
| 3644 | |
| 3645 | switch (target) |
| 3646 | { |
| 3647 | case GL_RENDERBUFFER: |
| 3648 | break; |
| 3649 | |
| 3650 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3651 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3652 | return false; |
| 3653 | } |
| 3654 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3655 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3656 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3657 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3658 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3659 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3660 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3661 | return false; |
| 3662 | } |
| 3663 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3664 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3665 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 3666 | if (!textureCaps.renderbuffer) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3667 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3668 | context->handleError(InvalidOperation() |
| 3669 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3670 | return false; |
| 3671 | } |
| 3672 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3673 | return true; |
| 3674 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3675 | |
| 3676 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3677 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3678 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3679 | { |
| 3680 | // The default VAO should always exist |
| 3681 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3682 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3683 | return false; |
| 3684 | } |
| 3685 | |
| 3686 | return true; |
| 3687 | } |
| 3688 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3689 | bool ValidateProgramBinaryBase(Context *context, |
| 3690 | GLuint program, |
| 3691 | GLenum binaryFormat, |
| 3692 | const void *binary, |
| 3693 | GLint length) |
| 3694 | { |
| 3695 | Program *programObject = GetValidProgram(context, program); |
| 3696 | if (programObject == nullptr) |
| 3697 | { |
| 3698 | return false; |
| 3699 | } |
| 3700 | |
| 3701 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3702 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3703 | programBinaryFormats.end()) |
| 3704 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3705 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3706 | return false; |
| 3707 | } |
| 3708 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3709 | if (context->hasActiveTransformFeedback(program)) |
| 3710 | { |
| 3711 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3712 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3713 | "is associated with an active transform " |
| 3714 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3715 | return false; |
| 3716 | } |
| 3717 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3718 | return true; |
| 3719 | } |
| 3720 | |
| 3721 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3722 | GLuint program, |
| 3723 | GLsizei bufSize, |
| 3724 | GLsizei *length, |
| 3725 | GLenum *binaryFormat, |
| 3726 | void *binary) |
| 3727 | { |
| 3728 | Program *programObject = GetValidProgram(context, program); |
| 3729 | if (programObject == nullptr) |
| 3730 | { |
| 3731 | return false; |
| 3732 | } |
| 3733 | |
| 3734 | if (!programObject->isLinked()) |
| 3735 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3736 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3737 | return false; |
| 3738 | } |
| 3739 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3740 | if (context->getCaps().programBinaryFormats.empty()) |
| 3741 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3742 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3743 | return false; |
| 3744 | } |
| 3745 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3746 | return true; |
| 3747 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3748 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3749 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3750 | { |
| 3751 | // 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] | 3752 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3753 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3754 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3755 | return false; |
| 3756 | } |
| 3757 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3758 | { |
| 3759 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3760 | return false; |
| 3761 | } |
| 3762 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3763 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3764 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3765 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3766 | |
| 3767 | // This should come first before the check for the default frame buffer |
| 3768 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3769 | // rather than INVALID_OPERATION |
| 3770 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3771 | { |
| 3772 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3773 | |
| 3774 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3775 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3776 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3777 | { |
| 3778 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3779 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3780 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3781 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3782 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3783 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3784 | return false; |
| 3785 | } |
| 3786 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3787 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3788 | context->handleError(InvalidOperation() |
| 3789 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3790 | return false; |
| 3791 | } |
| 3792 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3793 | frameBufferId != 0) |
| 3794 | { |
| 3795 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3796 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3797 | context->handleError(InvalidOperation() |
| 3798 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3799 | return false; |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3804 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3805 | if (frameBufferId == 0) |
| 3806 | { |
| 3807 | if (n != 1) |
| 3808 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3809 | context->handleError(InvalidOperation() |
| 3810 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3811 | return false; |
| 3812 | } |
| 3813 | |
| 3814 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3815 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3816 | context->handleError( |
| 3817 | InvalidOperation() |
| 3818 | << "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] | 3819 | return false; |
| 3820 | } |
| 3821 | } |
| 3822 | |
| 3823 | return true; |
| 3824 | } |
| 3825 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3826 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3827 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3828 | GLenum pname, |
| 3829 | GLsizei *length, |
| 3830 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3831 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3832 | if (length) |
| 3833 | { |
| 3834 | *length = 0; |
| 3835 | } |
| 3836 | |
| 3837 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3838 | { |
| 3839 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3840 | InvalidOperation() |
| 3841 | << "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] | 3842 | return false; |
| 3843 | } |
| 3844 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3845 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3846 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3847 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3848 | return false; |
| 3849 | } |
| 3850 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3851 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3852 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3853 | case GL_BUFFER_MAP_POINTER: |
| 3854 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3855 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3856 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3857 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3858 | return false; |
| 3859 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3860 | |
| 3861 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3862 | // target bound to zero generate an INVALID_OPERATION error." |
| 3863 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3864 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3865 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3866 | context->handleError(InvalidOperation() |
| 3867 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3868 | return false; |
| 3869 | } |
| 3870 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3871 | if (length) |
| 3872 | { |
| 3873 | *length = 1; |
| 3874 | } |
| 3875 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3876 | return true; |
| 3877 | } |
| 3878 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3879 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3880 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3881 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3882 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3883 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3884 | return false; |
| 3885 | } |
| 3886 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3887 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3888 | |
| 3889 | if (buffer == nullptr || !buffer->isMapped()) |
| 3890 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3891 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3892 | return false; |
| 3893 | } |
| 3894 | |
| 3895 | return true; |
| 3896 | } |
| 3897 | |
| 3898 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3899 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3900 | GLintptr offset, |
| 3901 | GLsizeiptr length, |
| 3902 | GLbitfield access) |
| 3903 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3904 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3905 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3906 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3907 | return false; |
| 3908 | } |
| 3909 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3910 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3911 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3912 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3913 | return false; |
| 3914 | } |
| 3915 | |
| 3916 | if (length < 0) |
| 3917 | { |
| 3918 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3919 | return false; |
| 3920 | } |
| 3921 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3922 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3923 | |
| 3924 | if (!buffer) |
| 3925 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3926 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3927 | return false; |
| 3928 | } |
| 3929 | |
| 3930 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3931 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3932 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3933 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3934 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3935 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3936 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3937 | return false; |
| 3938 | } |
| 3939 | |
| 3940 | // Check for invalid bits in the mask |
| 3941 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3942 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3943 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3944 | |
| 3945 | if (access & ~(allAccessBits)) |
| 3946 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3947 | context->handleError(InvalidValue() |
| 3948 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3949 | return false; |
| 3950 | } |
| 3951 | |
| 3952 | if (length == 0) |
| 3953 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3954 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3955 | return false; |
| 3956 | } |
| 3957 | |
| 3958 | if (buffer->isMapped()) |
| 3959 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3960 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3961 | return false; |
| 3962 | } |
| 3963 | |
| 3964 | // Check for invalid bit combinations |
| 3965 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3966 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3967 | context->handleError(InvalidOperation() |
| 3968 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3969 | return false; |
| 3970 | } |
| 3971 | |
| 3972 | GLbitfield writeOnlyBits = |
| 3973 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3974 | |
| 3975 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3976 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3977 | context->handleError(InvalidOperation() |
| 3978 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3979 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3980 | return false; |
| 3981 | } |
| 3982 | |
| 3983 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3984 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3985 | context->handleError( |
| 3986 | InvalidOperation() |
| 3987 | << "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] | 3988 | return false; |
| 3989 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3990 | |
| 3991 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3992 | } |
| 3993 | |
| 3994 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3995 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3996 | GLintptr offset, |
| 3997 | GLsizeiptr length) |
| 3998 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3999 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4000 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4001 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 4002 | return false; |
| 4003 | } |
| 4004 | |
| 4005 | if (length < 0) |
| 4006 | { |
| 4007 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4008 | return false; |
| 4009 | } |
| 4010 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 4011 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4012 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4013 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4014 | return false; |
| 4015 | } |
| 4016 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4017 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4018 | |
| 4019 | if (buffer == nullptr) |
| 4020 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4021 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4022 | return false; |
| 4023 | } |
| 4024 | |
| 4025 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4026 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4027 | context->handleError(InvalidOperation() |
| 4028 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4029 | return false; |
| 4030 | } |
| 4031 | |
| 4032 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4033 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4034 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4035 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4036 | if (!checkedSize.IsValid() || |
| 4037 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4038 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4039 | context->handleError(InvalidValue() |
| 4040 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4041 | return false; |
| 4042 | } |
| 4043 | |
| 4044 | return true; |
| 4045 | } |
| 4046 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4047 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4048 | { |
| 4049 | if (n < 0) |
| 4050 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4051 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4052 | return false; |
| 4053 | } |
| 4054 | return true; |
| 4055 | } |
| 4056 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4057 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4058 | { |
| 4059 | if (!context->getExtensions().robustClientMemory) |
| 4060 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4061 | context->handleError(InvalidOperation() |
| 4062 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4063 | return false; |
| 4064 | } |
| 4065 | |
| 4066 | if (bufSize < 0) |
| 4067 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4068 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4069 | return false; |
| 4070 | } |
| 4071 | |
| 4072 | return true; |
| 4073 | } |
| 4074 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4075 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4076 | { |
| 4077 | if (bufSize < numParams) |
| 4078 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4079 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 4080 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4081 | return false; |
| 4082 | } |
| 4083 | |
| 4084 | return true; |
| 4085 | } |
| 4086 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4087 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4088 | GLenum target, |
| 4089 | GLenum attachment, |
| 4090 | GLenum pname, |
| 4091 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4092 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4093 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4094 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4095 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4096 | return false; |
| 4097 | } |
| 4098 | |
| 4099 | int clientVersion = context->getClientMajorVersion(); |
| 4100 | |
| 4101 | switch (pname) |
| 4102 | { |
| 4103 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4104 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4105 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4106 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4107 | break; |
| 4108 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4109 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4110 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4111 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4112 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4113 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4114 | { |
| 4115 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4116 | return false; |
| 4117 | } |
| 4118 | break; |
| 4119 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4120 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4121 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4122 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4123 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4124 | return false; |
| 4125 | } |
| 4126 | break; |
| 4127 | |
| 4128 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4129 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4130 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4131 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4132 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4133 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4134 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4135 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4136 | if (clientVersion < 3) |
| 4137 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4138 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4139 | return false; |
| 4140 | } |
| 4141 | break; |
| 4142 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4143 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4144 | if (!context->getExtensions().geometryShader) |
| 4145 | { |
| 4146 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4147 | return false; |
| 4148 | } |
| 4149 | break; |
| 4150 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4151 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4152 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4153 | return false; |
| 4154 | } |
| 4155 | |
| 4156 | // Determine if the attachment is a valid enum |
| 4157 | switch (attachment) |
| 4158 | { |
| 4159 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4160 | case GL_DEPTH: |
| 4161 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4162 | if (clientVersion < 3) |
| 4163 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4164 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4165 | return false; |
| 4166 | } |
| 4167 | break; |
| 4168 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4169 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4170 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4171 | { |
| 4172 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4173 | return false; |
| 4174 | } |
| 4175 | break; |
| 4176 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4177 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4178 | case GL_DEPTH_ATTACHMENT: |
| 4179 | case GL_STENCIL_ATTACHMENT: |
| 4180 | break; |
| 4181 | |
| 4182 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4183 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4184 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4185 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4186 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4187 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | break; |
| 4191 | } |
| 4192 | |
| 4193 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4194 | ASSERT(framebuffer); |
| 4195 | |
| 4196 | if (framebuffer->id() == 0) |
| 4197 | { |
| 4198 | if (clientVersion < 3) |
| 4199 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4200 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4201 | return false; |
| 4202 | } |
| 4203 | |
| 4204 | switch (attachment) |
| 4205 | { |
| 4206 | case GL_BACK: |
| 4207 | case GL_DEPTH: |
| 4208 | case GL_STENCIL: |
| 4209 | break; |
| 4210 | |
| 4211 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4212 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4213 | return false; |
| 4214 | } |
| 4215 | } |
| 4216 | else |
| 4217 | { |
| 4218 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4219 | { |
| 4220 | // Valid attachment query |
| 4221 | } |
| 4222 | else |
| 4223 | { |
| 4224 | switch (attachment) |
| 4225 | { |
| 4226 | case GL_DEPTH_ATTACHMENT: |
| 4227 | case GL_STENCIL_ATTACHMENT: |
| 4228 | break; |
| 4229 | |
| 4230 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4231 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4232 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4233 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4234 | return false; |
| 4235 | } |
| 4236 | break; |
| 4237 | |
| 4238 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4239 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4240 | return false; |
| 4241 | } |
| 4242 | } |
| 4243 | } |
| 4244 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4245 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4246 | if (attachmentObject) |
| 4247 | { |
| 4248 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4249 | attachmentObject->type() == GL_TEXTURE || |
| 4250 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4251 | |
| 4252 | switch (pname) |
| 4253 | { |
| 4254 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4255 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4256 | attachmentObject->type() != GL_TEXTURE) |
| 4257 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4258 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4259 | return false; |
| 4260 | } |
| 4261 | break; |
| 4262 | |
| 4263 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4264 | if (attachmentObject->type() != GL_TEXTURE) |
| 4265 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4266 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4267 | return false; |
| 4268 | } |
| 4269 | break; |
| 4270 | |
| 4271 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4272 | if (attachmentObject->type() != GL_TEXTURE) |
| 4273 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4274 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4275 | return false; |
| 4276 | } |
| 4277 | break; |
| 4278 | |
| 4279 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4280 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4281 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4282 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4283 | return false; |
| 4284 | } |
| 4285 | break; |
| 4286 | |
| 4287 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4288 | if (attachmentObject->type() != GL_TEXTURE) |
| 4289 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4290 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4291 | return false; |
| 4292 | } |
| 4293 | break; |
| 4294 | |
| 4295 | default: |
| 4296 | break; |
| 4297 | } |
| 4298 | } |
| 4299 | else |
| 4300 | { |
| 4301 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4302 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4303 | |
| 4304 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4305 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4306 | // INVALID_OPERATION for all other pnames |
| 4307 | |
| 4308 | switch (pname) |
| 4309 | { |
| 4310 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4311 | break; |
| 4312 | |
| 4313 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4314 | if (clientVersion < 3) |
| 4315 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4316 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4317 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4318 | return false; |
| 4319 | } |
| 4320 | break; |
| 4321 | |
| 4322 | default: |
| 4323 | if (clientVersion < 3) |
| 4324 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4325 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4326 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4327 | return false; |
| 4328 | } |
| 4329 | else |
| 4330 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4331 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4332 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4333 | return false; |
| 4334 | } |
| 4335 | } |
| 4336 | } |
| 4337 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4338 | if (numParams) |
| 4339 | { |
| 4340 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4341 | { |
| 4342 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4343 | // parameters. |
| 4344 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4345 | *numParams = numViews * 2; |
| 4346 | } |
| 4347 | else |
| 4348 | { |
| 4349 | // For all other queries we can have only one output parameter. |
| 4350 | *numParams = 1; |
| 4351 | } |
| 4352 | } |
| 4353 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4354 | return true; |
| 4355 | } |
| 4356 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4357 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4358 | GLenum target, |
| 4359 | GLenum attachment, |
| 4360 | GLenum pname, |
| 4361 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4362 | GLsizei *length, |
| 4363 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4364 | { |
| 4365 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4366 | { |
| 4367 | return false; |
| 4368 | } |
| 4369 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4370 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4371 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4372 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4373 | { |
| 4374 | return false; |
| 4375 | } |
| 4376 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4377 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4378 | { |
| 4379 | return false; |
| 4380 | } |
| 4381 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4382 | SetRobustLengthParam(length, numParams); |
| 4383 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4384 | return true; |
| 4385 | } |
| 4386 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4387 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4388 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4389 | GLenum pname, |
| 4390 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4391 | GLsizei *length, |
| 4392 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4393 | { |
| 4394 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4395 | { |
| 4396 | return false; |
| 4397 | } |
| 4398 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4399 | GLsizei numParams = 0; |
| 4400 | |
| 4401 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4402 | { |
| 4403 | return false; |
| 4404 | } |
| 4405 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4406 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4407 | { |
| 4408 | return false; |
| 4409 | } |
| 4410 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4411 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4412 | return true; |
| 4413 | } |
| 4414 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4415 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4416 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4417 | GLenum pname, |
| 4418 | GLsizei bufSize, |
| 4419 | GLsizei *length, |
| 4420 | GLint64 *params) |
| 4421 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4422 | GLsizei numParams = 0; |
| 4423 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4424 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4425 | { |
| 4426 | return false; |
| 4427 | } |
| 4428 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4429 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4430 | { |
| 4431 | return false; |
| 4432 | } |
| 4433 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4434 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4435 | { |
| 4436 | return false; |
| 4437 | } |
| 4438 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4439 | SetRobustLengthParam(length, numParams); |
| 4440 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4441 | return true; |
| 4442 | } |
| 4443 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4444 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4445 | { |
| 4446 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4447 | if (numParams) |
| 4448 | { |
| 4449 | *numParams = 1; |
| 4450 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4451 | |
| 4452 | Program *programObject = GetValidProgram(context, program); |
| 4453 | if (!programObject) |
| 4454 | { |
| 4455 | return false; |
| 4456 | } |
| 4457 | |
| 4458 | switch (pname) |
| 4459 | { |
| 4460 | case GL_DELETE_STATUS: |
| 4461 | case GL_LINK_STATUS: |
| 4462 | case GL_VALIDATE_STATUS: |
| 4463 | case GL_INFO_LOG_LENGTH: |
| 4464 | case GL_ATTACHED_SHADERS: |
| 4465 | case GL_ACTIVE_ATTRIBUTES: |
| 4466 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4467 | case GL_ACTIVE_UNIFORMS: |
| 4468 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4469 | break; |
| 4470 | |
| 4471 | case GL_PROGRAM_BINARY_LENGTH: |
| 4472 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4473 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4474 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4475 | "requires GL_OES_get_program_binary or " |
| 4476 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4477 | return false; |
| 4478 | } |
| 4479 | break; |
| 4480 | |
| 4481 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4482 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4483 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4484 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4485 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4486 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4487 | if (context->getClientMajorVersion() < 3) |
| 4488 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4489 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4490 | return false; |
| 4491 | } |
| 4492 | break; |
| 4493 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4494 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4495 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4496 | if (context->getClientVersion() < Version(3, 1)) |
| 4497 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4498 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4499 | return false; |
| 4500 | } |
| 4501 | break; |
| 4502 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4503 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4504 | if (context->getClientVersion() < Version(3, 1)) |
| 4505 | { |
| 4506 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4507 | return false; |
| 4508 | } |
| 4509 | |
| 4510 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4511 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4512 | // program which has not been linked successfully, or which does not contain objects to |
| 4513 | // form a compute shader. |
| 4514 | if (!programObject->isLinked()) |
| 4515 | { |
| 4516 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4517 | return false; |
| 4518 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4519 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4520 | { |
| 4521 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4522 | return false; |
| 4523 | } |
| 4524 | break; |
| 4525 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4526 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4527 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4528 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4529 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4530 | if (!context->getExtensions().geometryShader) |
| 4531 | { |
| 4532 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4533 | return false; |
| 4534 | } |
| 4535 | |
| 4536 | // [EXT_geometry_shader] Chapter 7.12 |
| 4537 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4538 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4539 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4540 | // successfully, or which does not contain objects to form a geometry shader. |
| 4541 | if (!programObject->isLinked()) |
| 4542 | { |
| 4543 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4544 | return false; |
| 4545 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4546 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4547 | { |
| 4548 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4549 | return false; |
| 4550 | } |
| 4551 | break; |
| 4552 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4553 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4554 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4555 | return false; |
| 4556 | } |
| 4557 | |
| 4558 | return true; |
| 4559 | } |
| 4560 | |
| 4561 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4562 | GLuint program, |
| 4563 | GLenum pname, |
| 4564 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4565 | GLsizei *length, |
| 4566 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4567 | { |
| 4568 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4569 | { |
| 4570 | return false; |
| 4571 | } |
| 4572 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4573 | GLsizei numParams = 0; |
| 4574 | |
| 4575 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4576 | { |
| 4577 | return false; |
| 4578 | } |
| 4579 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4580 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4581 | { |
| 4582 | return false; |
| 4583 | } |
| 4584 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4585 | SetRobustLengthParam(length, numParams); |
| 4586 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4587 | return true; |
| 4588 | } |
| 4589 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4590 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4591 | GLenum target, |
| 4592 | GLenum pname, |
| 4593 | GLsizei bufSize, |
| 4594 | GLsizei *length, |
| 4595 | GLint *params) |
| 4596 | { |
| 4597 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4598 | { |
| 4599 | return false; |
| 4600 | } |
| 4601 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4602 | GLsizei numParams = 0; |
| 4603 | |
| 4604 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4605 | { |
| 4606 | return false; |
| 4607 | } |
| 4608 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4609 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4610 | { |
| 4611 | return false; |
| 4612 | } |
| 4613 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4614 | SetRobustLengthParam(length, numParams); |
| 4615 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4616 | return true; |
| 4617 | } |
| 4618 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4619 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4620 | GLuint shader, |
| 4621 | GLenum pname, |
| 4622 | GLsizei bufSize, |
| 4623 | GLsizei *length, |
| 4624 | GLint *params) |
| 4625 | { |
| 4626 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4627 | { |
| 4628 | return false; |
| 4629 | } |
| 4630 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4631 | GLsizei numParams = 0; |
| 4632 | |
| 4633 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4634 | { |
| 4635 | return false; |
| 4636 | } |
| 4637 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4638 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4639 | { |
| 4640 | return false; |
| 4641 | } |
| 4642 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4643 | SetRobustLengthParam(length, numParams); |
| 4644 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4645 | return true; |
| 4646 | } |
| 4647 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4648 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4649 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4650 | GLenum pname, |
| 4651 | GLsizei bufSize, |
| 4652 | GLsizei *length, |
| 4653 | GLfloat *params) |
| 4654 | { |
| 4655 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4656 | { |
| 4657 | return false; |
| 4658 | } |
| 4659 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4660 | GLsizei numParams = 0; |
| 4661 | |
| 4662 | if (!ValidateGetTexParameterBase(context, target, pname, &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 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4668 | { |
| 4669 | return false; |
| 4670 | } |
| 4671 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4672 | SetRobustLengthParam(length, numParams); |
| 4673 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4674 | return true; |
| 4675 | } |
| 4676 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4677 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4678 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4679 | GLenum pname, |
| 4680 | GLsizei bufSize, |
| 4681 | GLsizei *length, |
| 4682 | GLint *params) |
| 4683 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4684 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4685 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4686 | { |
| 4687 | return false; |
| 4688 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4689 | GLsizei numParams = 0; |
| 4690 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4691 | { |
| 4692 | return false; |
| 4693 | } |
| 4694 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4695 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4696 | { |
| 4697 | return false; |
| 4698 | } |
| 4699 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4700 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4701 | return true; |
| 4702 | } |
| 4703 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4704 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4705 | TextureType target, |
| 4706 | GLenum pname, |
| 4707 | GLsizei bufSize, |
| 4708 | GLsizei *length, |
| 4709 | GLint *params) |
| 4710 | { |
| 4711 | UNIMPLEMENTED(); |
| 4712 | return false; |
| 4713 | } |
| 4714 | |
| 4715 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4716 | TextureType target, |
| 4717 | GLenum pname, |
| 4718 | GLsizei bufSize, |
| 4719 | GLsizei *length, |
| 4720 | GLuint *params) |
| 4721 | { |
| 4722 | UNIMPLEMENTED(); |
| 4723 | return false; |
| 4724 | } |
| 4725 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4726 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4727 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4728 | GLenum pname, |
| 4729 | GLsizei bufSize, |
| 4730 | const GLfloat *params) |
| 4731 | { |
| 4732 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4733 | { |
| 4734 | return false; |
| 4735 | } |
| 4736 | |
| 4737 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4738 | } |
| 4739 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4740 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4741 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4742 | GLenum pname, |
| 4743 | GLsizei bufSize, |
| 4744 | const GLint *params) |
| 4745 | { |
| 4746 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4747 | { |
| 4748 | return false; |
| 4749 | } |
| 4750 | |
| 4751 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4752 | } |
| 4753 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4754 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4755 | TextureType target, |
| 4756 | GLenum pname, |
| 4757 | GLsizei bufSize, |
| 4758 | const GLint *params) |
| 4759 | { |
| 4760 | UNIMPLEMENTED(); |
| 4761 | return false; |
| 4762 | } |
| 4763 | |
| 4764 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4765 | TextureType target, |
| 4766 | GLenum pname, |
| 4767 | GLsizei bufSize, |
| 4768 | const GLuint *params) |
| 4769 | { |
| 4770 | UNIMPLEMENTED(); |
| 4771 | return false; |
| 4772 | } |
| 4773 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4774 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4775 | GLuint sampler, |
| 4776 | GLenum pname, |
| 4777 | GLuint bufSize, |
| 4778 | GLsizei *length, |
| 4779 | GLfloat *params) |
| 4780 | { |
| 4781 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4782 | { |
| 4783 | return false; |
| 4784 | } |
| 4785 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4786 | GLsizei numParams = 0; |
| 4787 | |
| 4788 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4789 | { |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4793 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4794 | { |
| 4795 | return false; |
| 4796 | } |
| 4797 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4798 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4799 | return true; |
| 4800 | } |
| 4801 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4802 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4803 | GLuint sampler, |
| 4804 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4805 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4806 | GLsizei *length, |
| 4807 | GLint *params) |
| 4808 | { |
| 4809 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4810 | { |
| 4811 | return false; |
| 4812 | } |
| 4813 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4814 | GLsizei numParams = 0; |
| 4815 | |
| 4816 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4817 | { |
| 4818 | return false; |
| 4819 | } |
| 4820 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4821 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4822 | { |
| 4823 | return false; |
| 4824 | } |
| 4825 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4826 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4827 | return true; |
| 4828 | } |
| 4829 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4830 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4831 | GLuint sampler, |
| 4832 | GLenum pname, |
| 4833 | GLsizei bufSize, |
| 4834 | GLsizei *length, |
| 4835 | GLint *params) |
| 4836 | { |
| 4837 | UNIMPLEMENTED(); |
| 4838 | return false; |
| 4839 | } |
| 4840 | |
| 4841 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4842 | GLuint sampler, |
| 4843 | GLenum pname, |
| 4844 | GLsizei bufSize, |
| 4845 | GLsizei *length, |
| 4846 | GLuint *params) |
| 4847 | { |
| 4848 | UNIMPLEMENTED(); |
| 4849 | return false; |
| 4850 | } |
| 4851 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4852 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4853 | GLuint sampler, |
| 4854 | GLenum pname, |
| 4855 | GLsizei bufSize, |
| 4856 | const GLfloat *params) |
| 4857 | { |
| 4858 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4859 | { |
| 4860 | return false; |
| 4861 | } |
| 4862 | |
| 4863 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4864 | } |
| 4865 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4866 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4867 | GLuint sampler, |
| 4868 | GLenum pname, |
| 4869 | GLsizei bufSize, |
| 4870 | const GLint *params) |
| 4871 | { |
| 4872 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4873 | { |
| 4874 | return false; |
| 4875 | } |
| 4876 | |
| 4877 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4878 | } |
| 4879 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4880 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4881 | GLuint sampler, |
| 4882 | GLenum pname, |
| 4883 | GLsizei bufSize, |
| 4884 | const GLint *param) |
| 4885 | { |
| 4886 | UNIMPLEMENTED(); |
| 4887 | return false; |
| 4888 | } |
| 4889 | |
| 4890 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4891 | GLuint sampler, |
| 4892 | GLenum pname, |
| 4893 | GLsizei bufSize, |
| 4894 | const GLuint *param) |
| 4895 | { |
| 4896 | UNIMPLEMENTED(); |
| 4897 | return false; |
| 4898 | } |
| 4899 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4900 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4901 | GLuint index, |
| 4902 | GLenum pname, |
| 4903 | GLsizei bufSize, |
| 4904 | GLsizei *length, |
| 4905 | GLfloat *params) |
| 4906 | { |
| 4907 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4908 | { |
| 4909 | return false; |
| 4910 | } |
| 4911 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4912 | GLsizei writeLength = 0; |
| 4913 | |
| 4914 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4915 | { |
| 4916 | return false; |
| 4917 | } |
| 4918 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4919 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4920 | { |
| 4921 | return false; |
| 4922 | } |
| 4923 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4924 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4925 | return true; |
| 4926 | } |
| 4927 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4928 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4929 | GLuint index, |
| 4930 | GLenum pname, |
| 4931 | GLsizei bufSize, |
| 4932 | GLsizei *length, |
| 4933 | GLint *params) |
| 4934 | { |
| 4935 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4936 | { |
| 4937 | return false; |
| 4938 | } |
| 4939 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4940 | GLsizei writeLength = 0; |
| 4941 | |
| 4942 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4943 | { |
| 4944 | return false; |
| 4945 | } |
| 4946 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4947 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4948 | { |
| 4949 | return false; |
| 4950 | } |
| 4951 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4952 | SetRobustLengthParam(length, writeLength); |
| 4953 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4954 | return true; |
| 4955 | } |
| 4956 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4957 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4958 | GLuint index, |
| 4959 | GLenum pname, |
| 4960 | GLsizei bufSize, |
| 4961 | GLsizei *length, |
| 4962 | void **pointer) |
| 4963 | { |
| 4964 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4965 | { |
| 4966 | return false; |
| 4967 | } |
| 4968 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4969 | GLsizei writeLength = 0; |
| 4970 | |
| 4971 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4972 | { |
| 4973 | return false; |
| 4974 | } |
| 4975 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4976 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4977 | { |
| 4978 | return false; |
| 4979 | } |
| 4980 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4981 | SetRobustLengthParam(length, writeLength); |
| 4982 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4983 | return true; |
| 4984 | } |
| 4985 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4986 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4987 | GLuint index, |
| 4988 | GLenum pname, |
| 4989 | GLsizei bufSize, |
| 4990 | GLsizei *length, |
| 4991 | GLint *params) |
| 4992 | { |
| 4993 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4994 | { |
| 4995 | return false; |
| 4996 | } |
| 4997 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4998 | GLsizei writeLength = 0; |
| 4999 | |
| 5000 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5001 | { |
| 5002 | return false; |
| 5003 | } |
| 5004 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5005 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5006 | { |
| 5007 | return false; |
| 5008 | } |
| 5009 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5010 | SetRobustLengthParam(length, writeLength); |
| 5011 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5012 | return true; |
| 5013 | } |
| 5014 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5015 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5016 | GLuint index, |
| 5017 | GLenum pname, |
| 5018 | GLsizei bufSize, |
| 5019 | GLsizei *length, |
| 5020 | GLuint *params) |
| 5021 | { |
| 5022 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5023 | { |
| 5024 | return false; |
| 5025 | } |
| 5026 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5027 | GLsizei writeLength = 0; |
| 5028 | |
| 5029 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5030 | { |
| 5031 | return false; |
| 5032 | } |
| 5033 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5034 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5035 | { |
| 5036 | return false; |
| 5037 | } |
| 5038 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5039 | SetRobustLengthParam(length, writeLength); |
| 5040 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5041 | return true; |
| 5042 | } |
| 5043 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5044 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5045 | GLuint program, |
| 5046 | GLuint uniformBlockIndex, |
| 5047 | GLenum pname, |
| 5048 | GLsizei bufSize, |
| 5049 | GLsizei *length, |
| 5050 | GLint *params) |
| 5051 | { |
| 5052 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5053 | { |
| 5054 | return false; |
| 5055 | } |
| 5056 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5057 | GLsizei writeLength = 0; |
| 5058 | |
| 5059 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5060 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5061 | { |
| 5062 | return false; |
| 5063 | } |
| 5064 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5065 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5066 | { |
| 5067 | return false; |
| 5068 | } |
| 5069 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5070 | SetRobustLengthParam(length, writeLength); |
| 5071 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5072 | return true; |
| 5073 | } |
| 5074 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5075 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5076 | GLenum target, |
| 5077 | GLenum internalformat, |
| 5078 | GLenum pname, |
| 5079 | GLsizei bufSize, |
| 5080 | GLsizei *length, |
| 5081 | GLint *params) |
| 5082 | { |
| 5083 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5084 | { |
| 5085 | return false; |
| 5086 | } |
| 5087 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5088 | GLsizei numParams = 0; |
| 5089 | |
| 5090 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5091 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5092 | { |
| 5093 | return false; |
| 5094 | } |
| 5095 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5096 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5097 | { |
| 5098 | return false; |
| 5099 | } |
| 5100 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5101 | SetRobustLengthParam(length, numParams); |
| 5102 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5103 | return true; |
| 5104 | } |
| 5105 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5106 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5107 | GLuint attribIndex, |
| 5108 | GLint size, |
| 5109 | GLenum type, |
| 5110 | GLboolean pureInteger) |
| 5111 | { |
| 5112 | const Caps &caps = context->getCaps(); |
| 5113 | if (attribIndex >= caps.maxVertexAttributes) |
| 5114 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5115 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5116 | return false; |
| 5117 | } |
| 5118 | |
| 5119 | if (size < 1 || size > 4) |
| 5120 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5121 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5122 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5123 | } |
| 5124 | |
| 5125 | switch (type) |
| 5126 | { |
| 5127 | case GL_BYTE: |
| 5128 | case GL_UNSIGNED_BYTE: |
| 5129 | case GL_SHORT: |
| 5130 | case GL_UNSIGNED_SHORT: |
| 5131 | break; |
| 5132 | |
| 5133 | case GL_INT: |
| 5134 | case GL_UNSIGNED_INT: |
| 5135 | if (context->getClientMajorVersion() < 3) |
| 5136 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5137 | context->handleError(InvalidEnum() |
| 5138 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5139 | return false; |
| 5140 | } |
| 5141 | break; |
| 5142 | |
| 5143 | case GL_FIXED: |
| 5144 | case GL_FLOAT: |
| 5145 | if (pureInteger) |
| 5146 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5147 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5148 | return false; |
| 5149 | } |
| 5150 | break; |
| 5151 | |
| 5152 | case GL_HALF_FLOAT: |
| 5153 | if (context->getClientMajorVersion() < 3) |
| 5154 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5155 | context->handleError(InvalidEnum() |
| 5156 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5157 | return false; |
| 5158 | } |
| 5159 | if (pureInteger) |
| 5160 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5161 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5162 | return false; |
| 5163 | } |
| 5164 | break; |
| 5165 | |
| 5166 | case GL_INT_2_10_10_10_REV: |
| 5167 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5168 | if (context->getClientMajorVersion() < 3) |
| 5169 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5170 | context->handleError(InvalidEnum() |
| 5171 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5172 | return false; |
| 5173 | } |
| 5174 | if (pureInteger) |
| 5175 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5176 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | if (size != 4) |
| 5180 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5181 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5182 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5183 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5184 | return false; |
| 5185 | } |
| 5186 | break; |
| 5187 | |
| 5188 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5189 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5190 | return false; |
| 5191 | } |
| 5192 | |
| 5193 | return true; |
| 5194 | } |
| 5195 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5196 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5197 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5198 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5199 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5200 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5201 | GLint drawbuffer, |
| 5202 | const GLenum *validComponentTypes, |
| 5203 | size_t validComponentTypeCount) |
| 5204 | { |
| 5205 | const FramebufferAttachment *attachment = |
| 5206 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5207 | if (attachment) |
| 5208 | { |
| 5209 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5210 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5211 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5212 | { |
| 5213 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5214 | InvalidOperation() |
| 5215 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5216 | return false; |
| 5217 | } |
| 5218 | } |
| 5219 | |
| 5220 | return true; |
| 5221 | } |
| 5222 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5223 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5224 | { |
| 5225 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5226 | { |
| 5227 | return false; |
| 5228 | } |
| 5229 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5230 | gl::Buffer *pixelUnpackBuffer = |
| 5231 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5232 | if (pixelUnpackBuffer == nullptr) |
| 5233 | { |
| 5234 | if (dataSize < imageSize) |
| 5235 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5236 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5237 | } |
| 5238 | } |
| 5239 | return true; |
| 5240 | } |
| 5241 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5242 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5243 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5244 | GLenum pname, |
| 5245 | bool pointerVersion, |
| 5246 | GLsizei *numParams) |
| 5247 | { |
| 5248 | if (numParams) |
| 5249 | { |
| 5250 | *numParams = 0; |
| 5251 | } |
| 5252 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5253 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5254 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5255 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5256 | return false; |
| 5257 | } |
| 5258 | |
| 5259 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5260 | if (!buffer) |
| 5261 | { |
| 5262 | // 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] | 5263 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5264 | return false; |
| 5265 | } |
| 5266 | |
| 5267 | const Extensions &extensions = context->getExtensions(); |
| 5268 | |
| 5269 | switch (pname) |
| 5270 | { |
| 5271 | case GL_BUFFER_USAGE: |
| 5272 | case GL_BUFFER_SIZE: |
| 5273 | break; |
| 5274 | |
| 5275 | case GL_BUFFER_ACCESS_OES: |
| 5276 | if (!extensions.mapBuffer) |
| 5277 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5278 | context->handleError(InvalidEnum() |
| 5279 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5280 | return false; |
| 5281 | } |
| 5282 | break; |
| 5283 | |
| 5284 | case GL_BUFFER_MAPPED: |
| 5285 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5286 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5287 | !extensions.mapBufferRange) |
| 5288 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5289 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5290 | "GL_OES_mapbuffer or " |
| 5291 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5292 | return false; |
| 5293 | } |
| 5294 | break; |
| 5295 | |
| 5296 | case GL_BUFFER_MAP_POINTER: |
| 5297 | if (!pointerVersion) |
| 5298 | { |
| 5299 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5300 | InvalidEnum() |
| 5301 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5302 | return false; |
| 5303 | } |
| 5304 | break; |
| 5305 | |
| 5306 | case GL_BUFFER_ACCESS_FLAGS: |
| 5307 | case GL_BUFFER_MAP_OFFSET: |
| 5308 | case GL_BUFFER_MAP_LENGTH: |
| 5309 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5310 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5311 | context->handleError(InvalidEnum() |
| 5312 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5313 | return false; |
| 5314 | } |
| 5315 | break; |
| 5316 | |
| 5317 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5318 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5319 | return false; |
| 5320 | } |
| 5321 | |
| 5322 | // All buffer parameter queries return one value. |
| 5323 | if (numParams) |
| 5324 | { |
| 5325 | *numParams = 1; |
| 5326 | } |
| 5327 | |
| 5328 | return true; |
| 5329 | } |
| 5330 | |
| 5331 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5332 | GLenum target, |
| 5333 | GLenum pname, |
| 5334 | GLsizei *length) |
| 5335 | { |
| 5336 | if (length) |
| 5337 | { |
| 5338 | *length = 0; |
| 5339 | } |
| 5340 | |
| 5341 | if (target != GL_RENDERBUFFER) |
| 5342 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5343 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5344 | return false; |
| 5345 | } |
| 5346 | |
| 5347 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5348 | if (renderbuffer == nullptr) |
| 5349 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5350 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5351 | return false; |
| 5352 | } |
| 5353 | |
| 5354 | switch (pname) |
| 5355 | { |
| 5356 | case GL_RENDERBUFFER_WIDTH: |
| 5357 | case GL_RENDERBUFFER_HEIGHT: |
| 5358 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5359 | case GL_RENDERBUFFER_RED_SIZE: |
| 5360 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5361 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5362 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5363 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5364 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5365 | break; |
| 5366 | |
| 5367 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5368 | if (!context->getExtensions().framebufferMultisample) |
| 5369 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5370 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5371 | return false; |
| 5372 | } |
| 5373 | break; |
| 5374 | |
| 5375 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5376 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5377 | return false; |
| 5378 | } |
| 5379 | |
| 5380 | if (length) |
| 5381 | { |
| 5382 | *length = 1; |
| 5383 | } |
| 5384 | return true; |
| 5385 | } |
| 5386 | |
| 5387 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5388 | { |
| 5389 | if (length) |
| 5390 | { |
| 5391 | *length = 0; |
| 5392 | } |
| 5393 | |
| 5394 | if (GetValidShader(context, shader) == nullptr) |
| 5395 | { |
| 5396 | return false; |
| 5397 | } |
| 5398 | |
| 5399 | switch (pname) |
| 5400 | { |
| 5401 | case GL_SHADER_TYPE: |
| 5402 | case GL_DELETE_STATUS: |
| 5403 | case GL_COMPILE_STATUS: |
| 5404 | case GL_INFO_LOG_LENGTH: |
| 5405 | case GL_SHADER_SOURCE_LENGTH: |
| 5406 | break; |
| 5407 | |
| 5408 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5409 | if (!context->getExtensions().translatedShaderSource) |
| 5410 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5411 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5412 | return false; |
| 5413 | } |
| 5414 | break; |
| 5415 | |
| 5416 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5417 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5418 | return false; |
| 5419 | } |
| 5420 | |
| 5421 | if (length) |
| 5422 | { |
| 5423 | *length = 1; |
| 5424 | } |
| 5425 | return true; |
| 5426 | } |
| 5427 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5428 | bool ValidateGetTexParameterBase(Context *context, |
| 5429 | TextureType target, |
| 5430 | GLenum pname, |
| 5431 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5432 | { |
| 5433 | if (length) |
| 5434 | { |
| 5435 | *length = 0; |
| 5436 | } |
| 5437 | |
| 5438 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5439 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5440 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5441 | return false; |
| 5442 | } |
| 5443 | |
| 5444 | if (context->getTargetTexture(target) == nullptr) |
| 5445 | { |
| 5446 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5447 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5448 | return false; |
| 5449 | } |
| 5450 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5451 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5452 | { |
| 5453 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5454 | return false; |
| 5455 | } |
| 5456 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5457 | switch (pname) |
| 5458 | { |
| 5459 | case GL_TEXTURE_MAG_FILTER: |
| 5460 | case GL_TEXTURE_MIN_FILTER: |
| 5461 | case GL_TEXTURE_WRAP_S: |
| 5462 | case GL_TEXTURE_WRAP_T: |
| 5463 | break; |
| 5464 | |
| 5465 | case GL_TEXTURE_USAGE_ANGLE: |
| 5466 | if (!context->getExtensions().textureUsage) |
| 5467 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5468 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5469 | return false; |
| 5470 | } |
| 5471 | break; |
| 5472 | |
| 5473 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5474 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5475 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5476 | return false; |
| 5477 | } |
| 5478 | break; |
| 5479 | |
| 5480 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5481 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5482 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5483 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5484 | return false; |
| 5485 | } |
| 5486 | break; |
| 5487 | |
| 5488 | case GL_TEXTURE_WRAP_R: |
| 5489 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5490 | case GL_TEXTURE_SWIZZLE_R: |
| 5491 | case GL_TEXTURE_SWIZZLE_G: |
| 5492 | case GL_TEXTURE_SWIZZLE_B: |
| 5493 | case GL_TEXTURE_SWIZZLE_A: |
| 5494 | case GL_TEXTURE_BASE_LEVEL: |
| 5495 | case GL_TEXTURE_MAX_LEVEL: |
| 5496 | case GL_TEXTURE_MIN_LOD: |
| 5497 | case GL_TEXTURE_MAX_LOD: |
| 5498 | case GL_TEXTURE_COMPARE_MODE: |
| 5499 | case GL_TEXTURE_COMPARE_FUNC: |
| 5500 | if (context->getClientMajorVersion() < 3) |
| 5501 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5502 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5503 | return false; |
| 5504 | } |
| 5505 | break; |
| 5506 | |
| 5507 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5508 | if (!context->getExtensions().textureSRGBDecode) |
| 5509 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5510 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5511 | return false; |
| 5512 | } |
| 5513 | break; |
| 5514 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5515 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5516 | if (context->getClientVersion() < Version(3, 1)) |
| 5517 | { |
| 5518 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5519 | return false; |
| 5520 | } |
| 5521 | break; |
| 5522 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5523 | case GL_GENERATE_MIPMAP: |
| 5524 | case GL_TEXTURE_CROP_RECT_OES: |
| 5525 | // TODO(lfy@google.com): Restrict to GL_OES_draw_texture |
| 5526 | // after GL_OES_draw_texture functionality implemented |
| 5527 | if (context->getClientMajorVersion() > 1) |
| 5528 | { |
| 5529 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5530 | return false; |
| 5531 | } |
| 5532 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5533 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5534 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5535 | return false; |
| 5536 | } |
| 5537 | |
| 5538 | if (length) |
| 5539 | { |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5540 | *length = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5541 | } |
| 5542 | return true; |
| 5543 | } |
| 5544 | |
| 5545 | bool ValidateGetVertexAttribBase(Context *context, |
| 5546 | GLuint index, |
| 5547 | GLenum pname, |
| 5548 | GLsizei *length, |
| 5549 | bool pointer, |
| 5550 | bool pureIntegerEntryPoint) |
| 5551 | { |
| 5552 | if (length) |
| 5553 | { |
| 5554 | *length = 0; |
| 5555 | } |
| 5556 | |
| 5557 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5559 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5560 | return false; |
| 5561 | } |
| 5562 | |
| 5563 | if (index >= context->getCaps().maxVertexAttributes) |
| 5564 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5565 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5566 | return false; |
| 5567 | } |
| 5568 | |
| 5569 | if (pointer) |
| 5570 | { |
| 5571 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5572 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5573 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5574 | return false; |
| 5575 | } |
| 5576 | } |
| 5577 | else |
| 5578 | { |
| 5579 | switch (pname) |
| 5580 | { |
| 5581 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5582 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5583 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5584 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5585 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5586 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5587 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5588 | break; |
| 5589 | |
| 5590 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5591 | static_assert( |
| 5592 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5593 | "ANGLE extension enums not equal to GL enums."); |
| 5594 | if (context->getClientMajorVersion() < 3 && |
| 5595 | !context->getExtensions().instancedArrays) |
| 5596 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5597 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5598 | "requires OpenGL ES 3.0 or " |
| 5599 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5600 | return false; |
| 5601 | } |
| 5602 | break; |
| 5603 | |
| 5604 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5605 | if (context->getClientMajorVersion() < 3) |
| 5606 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5607 | context->handleError( |
| 5608 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5609 | return false; |
| 5610 | } |
| 5611 | break; |
| 5612 | |
| 5613 | case GL_VERTEX_ATTRIB_BINDING: |
| 5614 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5615 | if (context->getClientVersion() < ES_3_1) |
| 5616 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5617 | context->handleError(InvalidEnum() |
| 5618 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5619 | return false; |
| 5620 | } |
| 5621 | break; |
| 5622 | |
| 5623 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5624 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5625 | return false; |
| 5626 | } |
| 5627 | } |
| 5628 | |
| 5629 | if (length) |
| 5630 | { |
| 5631 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5632 | { |
| 5633 | *length = 4; |
| 5634 | } |
| 5635 | else |
| 5636 | { |
| 5637 | *length = 1; |
| 5638 | } |
| 5639 | } |
| 5640 | |
| 5641 | return true; |
| 5642 | } |
| 5643 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5644 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5645 | GLint x, |
| 5646 | GLint y, |
| 5647 | GLsizei width, |
| 5648 | GLsizei height, |
| 5649 | GLenum format, |
| 5650 | GLenum type, |
| 5651 | GLsizei bufSize, |
| 5652 | GLsizei *length, |
| 5653 | GLsizei *columns, |
| 5654 | GLsizei *rows, |
| 5655 | void *pixels) |
| 5656 | { |
| 5657 | if (length != nullptr) |
| 5658 | { |
| 5659 | *length = 0; |
| 5660 | } |
| 5661 | if (rows != nullptr) |
| 5662 | { |
| 5663 | *rows = 0; |
| 5664 | } |
| 5665 | if (columns != nullptr) |
| 5666 | { |
| 5667 | *columns = 0; |
| 5668 | } |
| 5669 | |
| 5670 | if (width < 0 || height < 0) |
| 5671 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5672 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5673 | return false; |
| 5674 | } |
| 5675 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5676 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5677 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5678 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5679 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5680 | return false; |
| 5681 | } |
| 5682 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5683 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5684 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5685 | return false; |
| 5686 | } |
| 5687 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5688 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5689 | ASSERT(framebuffer); |
| 5690 | |
| 5691 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5692 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5693 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5694 | return false; |
| 5695 | } |
| 5696 | |
| 5697 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5698 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5699 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5700 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5701 | // situation is an application error that would lead to a crash in ANGLE. |
| 5702 | if (readBuffer == nullptr) |
| 5703 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5704 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5705 | return false; |
| 5706 | } |
| 5707 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5708 | // ANGLE_multiview, Revision 1: |
| 5709 | // ReadPixels generates an INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the |
| 5710 | // current read framebuffer is not NONE. |
| 5711 | if (readBuffer->getMultiviewLayout() != GL_NONE) |
| 5712 | { |
| 5713 | context->handleError(InvalidFramebufferOperation() |
| 5714 | << "Attempting to read from a multi-view framebuffer."); |
| 5715 | return false; |
| 5716 | } |
| 5717 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5718 | if (context->getExtensions().webglCompatibility) |
| 5719 | { |
| 5720 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5721 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5722 | // and type before validating the combination of format and type. However, the |
| 5723 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5724 | // verifies that GL_INVALID_OPERATION is generated. |
| 5725 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5726 | // dEQP/WebGL. |
| 5727 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5728 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5729 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5730 | return false; |
| 5731 | } |
| 5732 | |
| 5733 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5734 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5735 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5736 | return false; |
| 5737 | } |
| 5738 | } |
| 5739 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5740 | GLenum currentFormat = GL_NONE; |
| 5741 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5742 | |
| 5743 | GLenum currentType = GL_NONE; |
| 5744 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5745 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5746 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5747 | |
| 5748 | bool validFormatTypeCombination = |
| 5749 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5750 | |
| 5751 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5752 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5753 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5754 | return false; |
| 5755 | } |
| 5756 | |
| 5757 | // Check for pixel pack buffer related API errors |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5758 | gl::Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5759 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5760 | { |
| 5761 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5762 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5763 | return false; |
| 5764 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5765 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5766 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5767 | { |
| 5768 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5769 | return false; |
| 5770 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5771 | |
| 5772 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5773 | // would exceed the data store size. |
| 5774 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
| 5775 | const gl::Extents size(width, height, 1); |
| 5776 | const auto &pack = context->getGLState().getPackState(); |
| 5777 | |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5778 | GLuint endByte = 0; |
| 5779 | if (!formatInfo.computePackUnpackEndByte(type, size, pack, false, &endByte)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5780 | { |
Jamie Madill | ca2ff38 | 2018-07-11 09:01:17 -0400 | [diff] [blame] | 5781 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5782 | return false; |
| 5783 | } |
| 5784 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5785 | if (bufSize >= 0) |
| 5786 | { |
| 5787 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5788 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5789 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5790 | return false; |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | if (pixelPackBuffer != nullptr) |
| 5795 | { |
| 5796 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5797 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5798 | checkedEndByte += checkedOffset; |
| 5799 | |
| 5800 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5801 | { |
| 5802 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5803 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5804 | return false; |
| 5805 | } |
| 5806 | } |
| 5807 | |
| 5808 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5809 | { |
| 5810 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5811 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5812 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5813 | return false; |
| 5814 | } |
| 5815 | |
| 5816 | *length = static_cast<GLsizei>(endByte); |
| 5817 | } |
| 5818 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5819 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5820 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5821 | if (start < 0) |
| 5822 | { |
| 5823 | // "subtract" the area that is less than 0 |
| 5824 | clippedExtent += start; |
| 5825 | } |
| 5826 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5827 | angle::CheckedNumeric<int> readExtent = start; |
| 5828 | readExtent += length; |
| 5829 | if (!readExtent.IsValid()) |
| 5830 | { |
| 5831 | return false; |
| 5832 | } |
| 5833 | |
| 5834 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5835 | { |
| 5836 | // Subtract the region to the right of the read buffer |
| 5837 | clippedExtent -= (readExtent - bufferSize); |
| 5838 | } |
| 5839 | |
| 5840 | if (!clippedExtent.IsValid()) |
| 5841 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5842 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5843 | } |
| 5844 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5845 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5846 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5847 | }; |
| 5848 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5849 | GLsizei writtenColumns = 0; |
| 5850 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5851 | { |
| 5852 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5853 | return false; |
| 5854 | } |
| 5855 | |
| 5856 | GLsizei writtenRows = 0; |
| 5857 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5858 | { |
| 5859 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5860 | return false; |
| 5861 | } |
| 5862 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5863 | if (columns != nullptr) |
| 5864 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5865 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5866 | } |
| 5867 | |
| 5868 | if (rows != nullptr) |
| 5869 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5870 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5871 | } |
| 5872 | |
| 5873 | return true; |
| 5874 | } |
| 5875 | |
| 5876 | template <typename ParamType> |
| 5877 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5878 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5879 | GLenum pname, |
| 5880 | GLsizei bufSize, |
| 5881 | const ParamType *params) |
| 5882 | { |
| 5883 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5884 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5885 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5886 | return false; |
| 5887 | } |
| 5888 | |
| 5889 | if (context->getTargetTexture(target) == nullptr) |
| 5890 | { |
| 5891 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5892 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5893 | return false; |
| 5894 | } |
| 5895 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5896 | const GLsizei minBufSize = GetTexParameterCount(pname); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5897 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5898 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5899 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5900 | return false; |
| 5901 | } |
| 5902 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5903 | if (context->getClientMajorVersion() == 1 && !IsValidGLES1TextureParameter(pname)) |
| 5904 | { |
| 5905 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5906 | return false; |
| 5907 | } |
| 5908 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5909 | switch (pname) |
| 5910 | { |
| 5911 | case GL_TEXTURE_WRAP_R: |
| 5912 | case GL_TEXTURE_SWIZZLE_R: |
| 5913 | case GL_TEXTURE_SWIZZLE_G: |
| 5914 | case GL_TEXTURE_SWIZZLE_B: |
| 5915 | case GL_TEXTURE_SWIZZLE_A: |
| 5916 | case GL_TEXTURE_BASE_LEVEL: |
| 5917 | case GL_TEXTURE_MAX_LEVEL: |
| 5918 | case GL_TEXTURE_COMPARE_MODE: |
| 5919 | case GL_TEXTURE_COMPARE_FUNC: |
| 5920 | case GL_TEXTURE_MIN_LOD: |
| 5921 | case GL_TEXTURE_MAX_LOD: |
| 5922 | if (context->getClientMajorVersion() < 3) |
| 5923 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5924 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5925 | return false; |
| 5926 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5927 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5928 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5929 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5930 | "available without " |
| 5931 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5932 | return false; |
| 5933 | } |
| 5934 | break; |
| 5935 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 5936 | case GL_GENERATE_MIPMAP: |
| 5937 | case GL_TEXTURE_CROP_RECT_OES: |
| 5938 | if (context->getClientMajorVersion() > 1) |
| 5939 | { |
| 5940 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 5941 | return false; |
| 5942 | } |
| 5943 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5944 | default: |
| 5945 | break; |
| 5946 | } |
| 5947 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5948 | if (target == TextureType::_2DMultisample) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5949 | { |
| 5950 | switch (pname) |
| 5951 | { |
| 5952 | case GL_TEXTURE_MIN_FILTER: |
| 5953 | case GL_TEXTURE_MAG_FILTER: |
| 5954 | case GL_TEXTURE_WRAP_S: |
| 5955 | case GL_TEXTURE_WRAP_T: |
| 5956 | case GL_TEXTURE_WRAP_R: |
| 5957 | case GL_TEXTURE_MIN_LOD: |
| 5958 | case GL_TEXTURE_MAX_LOD: |
| 5959 | case GL_TEXTURE_COMPARE_MODE: |
| 5960 | case GL_TEXTURE_COMPARE_FUNC: |
| 5961 | context->handleError(InvalidEnum() |
| 5962 | << "Invalid parameter for 2D multisampled textures."); |
| 5963 | return false; |
| 5964 | } |
| 5965 | } |
| 5966 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5967 | switch (pname) |
| 5968 | { |
| 5969 | case GL_TEXTURE_WRAP_S: |
| 5970 | case GL_TEXTURE_WRAP_T: |
| 5971 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5972 | { |
| 5973 | bool restrictedWrapModes = |
| 5974 | target == TextureType::External || target == TextureType::Rectangle; |
| 5975 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5976 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5977 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5978 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5979 | } |
| 5980 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5981 | |
| 5982 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5983 | { |
| 5984 | bool restrictedMinFilter = |
| 5985 | target == TextureType::External || target == TextureType::Rectangle; |
| 5986 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5987 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5988 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5989 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5990 | } |
| 5991 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5992 | |
| 5993 | case GL_TEXTURE_MAG_FILTER: |
| 5994 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5995 | { |
| 5996 | return false; |
| 5997 | } |
| 5998 | break; |
| 5999 | |
| 6000 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 6001 | if (!context->getExtensions().textureUsage) |
| 6002 | { |
| 6003 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6004 | return false; |
| 6005 | } |
| 6006 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6007 | switch (ConvertToGLenum(params[0])) |
| 6008 | { |
| 6009 | case GL_NONE: |
| 6010 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 6011 | break; |
| 6012 | |
| 6013 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6014 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6015 | return false; |
| 6016 | } |
| 6017 | break; |
| 6018 | |
| 6019 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6020 | { |
| 6021 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6022 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6023 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6024 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6025 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6026 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 6027 | } |
| 6028 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6029 | |
| 6030 | case GL_TEXTURE_MIN_LOD: |
| 6031 | case GL_TEXTURE_MAX_LOD: |
| 6032 | // any value is permissible |
| 6033 | break; |
| 6034 | |
| 6035 | case GL_TEXTURE_COMPARE_MODE: |
| 6036 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6037 | { |
| 6038 | return false; |
| 6039 | } |
| 6040 | break; |
| 6041 | |
| 6042 | case GL_TEXTURE_COMPARE_FUNC: |
| 6043 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6044 | { |
| 6045 | return false; |
| 6046 | } |
| 6047 | break; |
| 6048 | |
| 6049 | case GL_TEXTURE_SWIZZLE_R: |
| 6050 | case GL_TEXTURE_SWIZZLE_G: |
| 6051 | case GL_TEXTURE_SWIZZLE_B: |
| 6052 | case GL_TEXTURE_SWIZZLE_A: |
| 6053 | switch (ConvertToGLenum(params[0])) |
| 6054 | { |
| 6055 | case GL_RED: |
| 6056 | case GL_GREEN: |
| 6057 | case GL_BLUE: |
| 6058 | case GL_ALPHA: |
| 6059 | case GL_ZERO: |
| 6060 | case GL_ONE: |
| 6061 | break; |
| 6062 | |
| 6063 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6064 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6065 | return false; |
| 6066 | } |
| 6067 | break; |
| 6068 | |
| 6069 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6070 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6071 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6072 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6073 | return false; |
| 6074 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6075 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6076 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6077 | context->handleError(InvalidOperation() |
| 6078 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6079 | return false; |
| 6080 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6081 | if (target == TextureType::_2DMultisample && static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6082 | { |
| 6083 | context->handleError(InvalidOperation() |
| 6084 | << "Base level must be 0 for multisampled textures."); |
| 6085 | return false; |
| 6086 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6087 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6088 | { |
| 6089 | context->handleError(InvalidOperation() |
| 6090 | << "Base level must be 0 for rectangle textures."); |
| 6091 | return false; |
| 6092 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6093 | break; |
| 6094 | |
| 6095 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6096 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6097 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6098 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6099 | return false; |
| 6100 | } |
| 6101 | break; |
| 6102 | |
| 6103 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6104 | if (context->getClientVersion() < Version(3, 1)) |
| 6105 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6106 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6107 | return false; |
| 6108 | } |
| 6109 | switch (ConvertToGLenum(params[0])) |
| 6110 | { |
| 6111 | case GL_DEPTH_COMPONENT: |
| 6112 | case GL_STENCIL_INDEX: |
| 6113 | break; |
| 6114 | |
| 6115 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6116 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6117 | return false; |
| 6118 | } |
| 6119 | break; |
| 6120 | |
| 6121 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6122 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6123 | { |
| 6124 | return false; |
| 6125 | } |
| 6126 | break; |
| 6127 | |
Lingfeng Yang | f97641c | 2018-06-21 19:22:45 -0700 | [diff] [blame] | 6128 | case GL_GENERATE_MIPMAP: |
| 6129 | case GL_TEXTURE_CROP_RECT_OES: |
| 6130 | if (context->getClientMajorVersion() > 1) |
| 6131 | { |
| 6132 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GLES1Only); |
| 6133 | return false; |
| 6134 | } |
| 6135 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6136 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6137 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6138 | return false; |
| 6139 | } |
| 6140 | |
| 6141 | return true; |
| 6142 | } |
| 6143 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6144 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 6145 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6146 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6147 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6148 | { |
| 6149 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6150 | { |
| 6151 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6152 | return false; |
| 6153 | } |
| 6154 | |
| 6155 | return true; |
| 6156 | } |
| 6157 | |
| 6158 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6159 | GLuint program, |
| 6160 | GLuint uniformBlockIndex, |
| 6161 | GLenum pname, |
| 6162 | GLsizei *length) |
| 6163 | { |
| 6164 | if (length) |
| 6165 | { |
| 6166 | *length = 0; |
| 6167 | } |
| 6168 | |
| 6169 | if (context->getClientMajorVersion() < 3) |
| 6170 | { |
| 6171 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6172 | return false; |
| 6173 | } |
| 6174 | |
| 6175 | Program *programObject = GetValidProgram(context, program); |
| 6176 | if (!programObject) |
| 6177 | { |
| 6178 | return false; |
| 6179 | } |
| 6180 | |
| 6181 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6182 | { |
| 6183 | context->handleError(InvalidValue() |
| 6184 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6185 | return false; |
| 6186 | } |
| 6187 | |
| 6188 | switch (pname) |
| 6189 | { |
| 6190 | case GL_UNIFORM_BLOCK_BINDING: |
| 6191 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6192 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6193 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6194 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6195 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6196 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6197 | break; |
| 6198 | |
| 6199 | default: |
| 6200 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6201 | return false; |
| 6202 | } |
| 6203 | |
| 6204 | if (length) |
| 6205 | { |
| 6206 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6207 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6208 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6209 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6210 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6211 | } |
| 6212 | else |
| 6213 | { |
| 6214 | *length = 1; |
| 6215 | } |
| 6216 | } |
| 6217 | |
| 6218 | return true; |
| 6219 | } |
| 6220 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6221 | template <typename ParamType> |
| 6222 | bool ValidateSamplerParameterBase(Context *context, |
| 6223 | GLuint sampler, |
| 6224 | GLenum pname, |
| 6225 | GLsizei bufSize, |
| 6226 | ParamType *params) |
| 6227 | { |
| 6228 | if (context->getClientMajorVersion() < 3) |
| 6229 | { |
| 6230 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6231 | return false; |
| 6232 | } |
| 6233 | |
| 6234 | if (!context->isSampler(sampler)) |
| 6235 | { |
| 6236 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6237 | return false; |
| 6238 | } |
| 6239 | |
| 6240 | const GLsizei minBufSize = 1; |
| 6241 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6242 | { |
| 6243 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6244 | return false; |
| 6245 | } |
| 6246 | |
| 6247 | switch (pname) |
| 6248 | { |
| 6249 | case GL_TEXTURE_WRAP_S: |
| 6250 | case GL_TEXTURE_WRAP_T: |
| 6251 | case GL_TEXTURE_WRAP_R: |
| 6252 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6253 | { |
| 6254 | return false; |
| 6255 | } |
| 6256 | break; |
| 6257 | |
| 6258 | case GL_TEXTURE_MIN_FILTER: |
| 6259 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6260 | { |
| 6261 | return false; |
| 6262 | } |
| 6263 | break; |
| 6264 | |
| 6265 | case GL_TEXTURE_MAG_FILTER: |
| 6266 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6267 | { |
| 6268 | return false; |
| 6269 | } |
| 6270 | break; |
| 6271 | |
| 6272 | case GL_TEXTURE_MIN_LOD: |
| 6273 | case GL_TEXTURE_MAX_LOD: |
| 6274 | // any value is permissible |
| 6275 | break; |
| 6276 | |
| 6277 | case GL_TEXTURE_COMPARE_MODE: |
| 6278 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6279 | { |
| 6280 | return false; |
| 6281 | } |
| 6282 | break; |
| 6283 | |
| 6284 | case GL_TEXTURE_COMPARE_FUNC: |
| 6285 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6286 | { |
| 6287 | return false; |
| 6288 | } |
| 6289 | break; |
| 6290 | |
| 6291 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6292 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6293 | { |
| 6294 | return false; |
| 6295 | } |
| 6296 | break; |
| 6297 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6298 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6299 | { |
| 6300 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6301 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6302 | { |
| 6303 | return false; |
| 6304 | } |
| 6305 | } |
| 6306 | break; |
| 6307 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6308 | default: |
| 6309 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6310 | return false; |
| 6311 | } |
| 6312 | |
| 6313 | return true; |
| 6314 | } |
| 6315 | |
| 6316 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 6317 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 6318 | |
| 6319 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6320 | GLuint sampler, |
| 6321 | GLenum pname, |
| 6322 | GLsizei *length) |
| 6323 | { |
| 6324 | if (length) |
| 6325 | { |
| 6326 | *length = 0; |
| 6327 | } |
| 6328 | |
| 6329 | if (context->getClientMajorVersion() < 3) |
| 6330 | { |
| 6331 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6332 | return false; |
| 6333 | } |
| 6334 | |
| 6335 | if (!context->isSampler(sampler)) |
| 6336 | { |
| 6337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6338 | return false; |
| 6339 | } |
| 6340 | |
| 6341 | switch (pname) |
| 6342 | { |
| 6343 | case GL_TEXTURE_WRAP_S: |
| 6344 | case GL_TEXTURE_WRAP_T: |
| 6345 | case GL_TEXTURE_WRAP_R: |
| 6346 | case GL_TEXTURE_MIN_FILTER: |
| 6347 | case GL_TEXTURE_MAG_FILTER: |
| 6348 | case GL_TEXTURE_MIN_LOD: |
| 6349 | case GL_TEXTURE_MAX_LOD: |
| 6350 | case GL_TEXTURE_COMPARE_MODE: |
| 6351 | case GL_TEXTURE_COMPARE_FUNC: |
| 6352 | break; |
| 6353 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6354 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6355 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6356 | { |
| 6357 | return false; |
| 6358 | } |
| 6359 | break; |
| 6360 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6361 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6362 | if (!context->getExtensions().textureSRGBDecode) |
| 6363 | { |
| 6364 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6365 | return false; |
| 6366 | } |
| 6367 | break; |
| 6368 | |
| 6369 | default: |
| 6370 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6371 | return false; |
| 6372 | } |
| 6373 | |
| 6374 | if (length) |
| 6375 | { |
| 6376 | *length = 1; |
| 6377 | } |
| 6378 | return true; |
| 6379 | } |
| 6380 | |
| 6381 | bool ValidateGetInternalFormativBase(Context *context, |
| 6382 | GLenum target, |
| 6383 | GLenum internalformat, |
| 6384 | GLenum pname, |
| 6385 | GLsizei bufSize, |
| 6386 | GLsizei *numParams) |
| 6387 | { |
| 6388 | if (numParams) |
| 6389 | { |
| 6390 | *numParams = 0; |
| 6391 | } |
| 6392 | |
| 6393 | if (context->getClientMajorVersion() < 3) |
| 6394 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6395 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6396 | return false; |
| 6397 | } |
| 6398 | |
| 6399 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6400 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6401 | { |
| 6402 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6403 | return false; |
| 6404 | } |
| 6405 | |
| 6406 | switch (target) |
| 6407 | { |
| 6408 | case GL_RENDERBUFFER: |
| 6409 | break; |
| 6410 | |
| 6411 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 6412 | if (context->getClientVersion() < ES_3_1) |
| 6413 | { |
| 6414 | context->handleError(InvalidOperation() |
| 6415 | << "Texture target requires at least OpenGL ES 3.1."); |
| 6416 | return false; |
| 6417 | } |
| 6418 | break; |
| 6419 | |
| 6420 | default: |
| 6421 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6422 | return false; |
| 6423 | } |
| 6424 | |
| 6425 | if (bufSize < 0) |
| 6426 | { |
| 6427 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6428 | return false; |
| 6429 | } |
| 6430 | |
| 6431 | GLsizei maxWriteParams = 0; |
| 6432 | switch (pname) |
| 6433 | { |
| 6434 | case GL_NUM_SAMPLE_COUNTS: |
| 6435 | maxWriteParams = 1; |
| 6436 | break; |
| 6437 | |
| 6438 | case GL_SAMPLES: |
| 6439 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6440 | break; |
| 6441 | |
| 6442 | default: |
| 6443 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6444 | return false; |
| 6445 | } |
| 6446 | |
| 6447 | if (numParams) |
| 6448 | { |
| 6449 | // glGetInternalFormativ will not overflow bufSize |
| 6450 | *numParams = std::min(bufSize, maxWriteParams); |
| 6451 | } |
| 6452 | |
| 6453 | return true; |
| 6454 | } |
| 6455 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6456 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6457 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6458 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6459 | { |
| 6460 | context->handleError(InvalidOperation()); |
| 6461 | return false; |
| 6462 | } |
| 6463 | return true; |
| 6464 | } |
| 6465 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6466 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6467 | { |
| 6468 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6469 | { |
| 6470 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6471 | return false; |
| 6472 | } |
| 6473 | return true; |
| 6474 | } |
| 6475 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6476 | } // namespace gl |