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" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 25 | #include "libANGLE/validationES2.h" |
| 26 | #include "libANGLE/validationES3.h" |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 27 | |
| 28 | #include "common/mathutil.h" |
| 29 | #include "common/utilities.h" |
| 30 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 31 | using namespace angle; |
| 32 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 33 | namespace gl |
| 34 | { |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 35 | namespace |
| 36 | { |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 37 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 38 | { |
| 39 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 40 | // the compressed block size. |
| 41 | switch (internalFormat) |
| 42 | { |
| 43 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 44 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 45 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 46 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
| 47 | case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: |
| 48 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: |
| 49 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: |
| 50 | case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: |
| 51 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
| 52 | case GL_COMPRESSED_RGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 53 | case GL_COMPRESSED_SRGB8_LOSSY_DECODE_ETC2_ANGLE: |
| 54 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 55 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_LOSSY_DECODE_ETC2_ANGLE: |
| 56 | case GL_COMPRESSED_RGBA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 57 | case GL_COMPRESSED_SRGB8_ALPHA8_LOSSY_DECODE_ETC2_EAC_ANGLE: |
| 58 | return true; |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 59 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 60 | default: |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | bool CompressedSubTextureFormatRequiresExactSize(GLenum internalFormat) |
| 65 | { |
| 66 | // Compressed sub textures have additional formats that requires exact size. |
| 67 | // ES 3.1, Section 8.7, Page 171 |
| 68 | return CompressedTextureFormatRequiresExactSize(internalFormat) || |
| 69 | IsETC2EACFormat(internalFormat); |
| 70 | } |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 71 | |
| 72 | bool DifferenceCanOverflow(GLint a, GLint b) |
| 73 | { |
| 74 | CheckedNumeric<GLint> checkedA(a); |
| 75 | checkedA -= b; |
| 76 | // Use negation to make sure that the difference can't overflow regardless of the order. |
| 77 | checkedA = -checkedA; |
| 78 | return !checkedA.IsValid(); |
| 79 | } |
| 80 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 81 | bool ValidateDrawAttribs(Context *context, GLint primcount, GLint maxVertex, GLint vertexCount) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 82 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 83 | const gl::State &state = context->getGLState(); |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 84 | const gl::Program *program = state.getProgram(); |
| 85 | |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 86 | bool webglCompatibility = context->getExtensions().webglCompatibility; |
| 87 | |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 88 | const VertexArray *vao = state.getVertexArray(); |
| 89 | const AttributesMask &clientAttribs = vao->getEnabledClientMemoryAttribsMask(); |
| 90 | |
| 91 | if (clientAttribs.any()) |
| 92 | { |
| 93 | if (webglCompatibility || !state.areClientArraysEnabled()) |
| 94 | { |
| 95 | // [WebGL 1.0] Section 6.5 Enabled Vertex Attributes and Range Checking |
| 96 | // If a vertex attribute is enabled as an array via enableVertexAttribArray but no |
| 97 | // buffer is bound to that attribute via bindBuffer and vertexAttribPointer, then calls |
| 98 | // to drawArrays or drawElements will generate an INVALID_OPERATION error. |
| 99 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBuffer); |
| 100 | return false; |
| 101 | } |
| 102 | else if (vao->hasEnabledNullPointerClientArray()) |
| 103 | { |
| 104 | // This is an application error that would normally result in a crash, but we catch it |
| 105 | // and return an error |
| 106 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexArrayNoBufferPointer); |
| 107 | return false; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | // If we're drawing zero vertices, we have enough data. |
| 112 | if (vertexCount <= 0 || primcount <= 0) |
| 113 | { |
| 114 | return true; |
| 115 | } |
| 116 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 117 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 118 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 119 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 120 | bool isGLES1 = context->getClientVersion() < Version(2, 0); |
| 121 | |
| 122 | const AttributesMask &activeAttribs = ((isGLES1 ? context->getVertexArraysAttributeMask() |
| 123 | : program->getActiveAttribLocationsMask()) & |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 124 | vao->getEnabledAttributesMask() & ~clientAttribs); |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 125 | |
| 126 | for (size_t attributeIndex : activeAttribs) |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 127 | { |
| 128 | const VertexAttribute &attrib = vertexAttribs[attributeIndex]; |
Jamie Madill | 51af38b | 2018-04-15 08:50:56 -0400 | [diff] [blame] | 129 | ASSERT(attrib.enabled); |
Corentin Wallez | 672f7f3 | 2017-06-15 17:42:17 -0400 | [diff] [blame] | 130 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 131 | const VertexBinding &binding = vertexBindings[attrib.bindingIndex]; |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 132 | ASSERT(isGLES1 || program->isAttribLocationActive(attributeIndex)); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 133 | |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 134 | GLint maxVertexElement = maxVertex; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 135 | GLuint divisor = binding.getDivisor(); |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 136 | if (divisor != 0) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 137 | { |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 138 | maxVertexElement = (primcount - 1) / divisor; |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | // We do manual overflow checks here instead of using safe_math.h because it was |
| 142 | // a bottleneck. Thanks to some properties of GL we know inequalities that can |
| 143 | // help us make the overflow checks faster. |
| 144 | |
| 145 | // The max possible attribSize is 16 for a vector of 4 32 bit values. |
| 146 | constexpr uint64_t kMaxAttribSize = 16; |
| 147 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 148 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 149 | |
| 150 | // We know attribStride is given as a GLsizei which is typedefed to int. |
| 151 | // We also know an upper bound for attribSize. |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 152 | static_assert(std::is_same<int, GLsizei>::value, "Unexpected type"); |
| 153 | ASSERT(ComputeVertexAttributeStride(attrib, binding) == binding.getStride()); |
| 154 | uint64_t attribStride = binding.getStride(); |
| 155 | ASSERT(attribStride <= kIntMax && ComputeVertexAttributeTypeSize(attrib) <= kMaxAttribSize); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 156 | |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 157 | // Computing the product of two 32-bit ints will fit in 64 bits without overflow. |
| 158 | static_assert(kIntMax * kIntMax < kUint64Max, "Unexpected overflow"); |
| 159 | uint64_t attribDataSizeMinusAttribSize = maxVertexElement * attribStride; |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 160 | |
| 161 | // An overflow can happen when adding the offset, check for it. |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 162 | if (attribDataSizeMinusAttribSize > kUint64Max - attrib.cachedSizePlusRelativeOffset) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 163 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 164 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 165 | return false; |
| 166 | } |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 167 | |
| 168 | // [OpenGL ES 3.0.2] section 2.9.4 page 40: |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 169 | // We can return INVALID_OPERATION if our array buffer does not have enough backing data. |
| 170 | if (attribDataSizeMinusAttribSize + attrib.cachedSizePlusRelativeOffset > |
| 171 | binding.getCachedBufferSizeMinusOffset()) |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 172 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 173 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientVertexBufferSize); |
Corentin Wallez | fd45644 | 2016-12-21 17:57:00 -0500 | [diff] [blame] | 174 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 175 | } |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 176 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 177 | |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 178 | if (webglCompatibility && vao->hasTransformFeedbackBindingConflict(activeAttribs)) |
Jamie Madill | 02c9c04 | 2018-04-17 13:43:48 -0400 | [diff] [blame] | 179 | { |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 180 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexBufferBoundForTransformFeedback); |
| 181 | return false; |
Jamie Madill | 1ca7467 | 2015-07-21 15:14:11 -0400 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | return true; |
| 185 | } |
| 186 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 187 | bool ValidReadPixelsTypeEnum(Context *context, GLenum type) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 188 | { |
| 189 | switch (type) |
| 190 | { |
| 191 | // Types referenced in Table 3.4 of the ES 2.0.25 spec |
| 192 | case GL_UNSIGNED_BYTE: |
| 193 | case GL_UNSIGNED_SHORT_4_4_4_4: |
| 194 | case GL_UNSIGNED_SHORT_5_5_5_1: |
| 195 | case GL_UNSIGNED_SHORT_5_6_5: |
| 196 | return context->getClientVersion() >= ES_2_0; |
| 197 | |
| 198 | // Types referenced in Table 3.2 of the ES 3.0.5 spec (Except depth stencil) |
| 199 | case GL_BYTE: |
| 200 | case GL_INT: |
| 201 | case GL_SHORT: |
| 202 | case GL_UNSIGNED_INT: |
| 203 | case GL_UNSIGNED_INT_10F_11F_11F_REV: |
| 204 | case GL_UNSIGNED_INT_24_8: |
| 205 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 206 | case GL_UNSIGNED_INT_5_9_9_9_REV: |
| 207 | case GL_UNSIGNED_SHORT: |
| 208 | case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT: |
| 209 | case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT: |
| 210 | return context->getClientVersion() >= ES_3_0; |
| 211 | |
| 212 | case GL_FLOAT: |
Geoff Lang | 7d4602f | 2017-09-13 10:45:09 -0400 | [diff] [blame] | 213 | return context->getClientVersion() >= ES_3_0 || context->getExtensions().textureFloat || |
| 214 | context->getExtensions().colorBufferHalfFloat; |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 215 | |
| 216 | case GL_HALF_FLOAT: |
| 217 | return context->getClientVersion() >= ES_3_0 || |
| 218 | context->getExtensions().textureHalfFloat; |
| 219 | |
| 220 | case GL_HALF_FLOAT_OES: |
| 221 | return context->getExtensions().colorBufferHalfFloat; |
| 222 | |
| 223 | default: |
| 224 | return false; |
| 225 | } |
| 226 | } |
| 227 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 228 | bool ValidReadPixelsFormatEnum(Context *context, GLenum format) |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 229 | { |
| 230 | switch (format) |
| 231 | { |
| 232 | // Formats referenced in Table 3.4 of the ES 2.0.25 spec (Except luminance) |
| 233 | case GL_RGBA: |
| 234 | case GL_RGB: |
| 235 | case GL_ALPHA: |
| 236 | return context->getClientVersion() >= ES_2_0; |
| 237 | |
| 238 | // Formats referenced in Table 3.2 of the ES 3.0.5 spec |
| 239 | case GL_RG: |
| 240 | case GL_RED: |
| 241 | case GL_RGBA_INTEGER: |
| 242 | case GL_RGB_INTEGER: |
| 243 | case GL_RG_INTEGER: |
| 244 | case GL_RED_INTEGER: |
| 245 | return context->getClientVersion() >= ES_3_0; |
| 246 | |
| 247 | case GL_SRGB_ALPHA_EXT: |
| 248 | case GL_SRGB_EXT: |
| 249 | return context->getExtensions().sRGB; |
| 250 | |
| 251 | case GL_BGRA_EXT: |
| 252 | return context->getExtensions().readFormatBGRA; |
| 253 | |
| 254 | default: |
| 255 | return false; |
| 256 | } |
| 257 | } |
| 258 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 259 | bool ValidReadPixelsFormatType(Context *context, |
Geoff Lang | f607c60 | 2016-09-21 11:46:48 -0400 | [diff] [blame] | 260 | GLenum framebufferComponentType, |
| 261 | GLenum format, |
| 262 | GLenum type) |
| 263 | { |
| 264 | switch (framebufferComponentType) |
| 265 | { |
| 266 | case GL_UNSIGNED_NORMALIZED: |
| 267 | // TODO(geofflang): Don't accept BGRA here. Some chrome internals appear to try to use |
| 268 | // ReadPixels with BGRA even if the extension is not present |
| 269 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE) || |
| 270 | (context->getExtensions().readFormatBGRA && format == GL_BGRA_EXT && |
| 271 | type == GL_UNSIGNED_BYTE); |
| 272 | |
| 273 | case GL_SIGNED_NORMALIZED: |
| 274 | return (format == GL_RGBA && type == GL_UNSIGNED_BYTE); |
| 275 | |
| 276 | case GL_INT: |
| 277 | return (format == GL_RGBA_INTEGER && type == GL_INT); |
| 278 | |
| 279 | case GL_UNSIGNED_INT: |
| 280 | return (format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT); |
| 281 | |
| 282 | case GL_FLOAT: |
| 283 | return (format == GL_RGBA && type == GL_FLOAT); |
| 284 | |
| 285 | default: |
| 286 | UNREACHABLE(); |
| 287 | return false; |
| 288 | } |
| 289 | } |
| 290 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 291 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 292 | bool ValidateTextureWrapModeValue(Context *context, ParamType *params, bool restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 293 | { |
| 294 | switch (ConvertToGLenum(params[0])) |
| 295 | { |
| 296 | case GL_CLAMP_TO_EDGE: |
| 297 | break; |
| 298 | |
| 299 | case GL_REPEAT: |
| 300 | case GL_MIRRORED_REPEAT: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 301 | if (restrictedWrapModes) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 302 | { |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 303 | // OES_EGL_image_external and ANGLE_texture_rectangle specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 304 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidWrapModeTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 305 | return false; |
| 306 | } |
| 307 | break; |
| 308 | |
| 309 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 310 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureWrap); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 311 | return false; |
| 312 | } |
| 313 | |
| 314 | return true; |
| 315 | } |
| 316 | |
| 317 | template <typename ParamType> |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 318 | bool ValidateTextureMinFilterValue(Context *context, ParamType *params, bool restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 319 | { |
| 320 | switch (ConvertToGLenum(params[0])) |
| 321 | { |
| 322 | case GL_NEAREST: |
| 323 | case GL_LINEAR: |
| 324 | break; |
| 325 | |
| 326 | case GL_NEAREST_MIPMAP_NEAREST: |
| 327 | case GL_LINEAR_MIPMAP_NEAREST: |
| 328 | case GL_NEAREST_MIPMAP_LINEAR: |
| 329 | case GL_LINEAR_MIPMAP_LINEAR: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 330 | if (restrictedMinFilter) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 331 | { |
| 332 | // OES_EGL_image_external specifies this error. |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 333 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFilterTexture); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 334 | return false; |
| 335 | } |
| 336 | break; |
| 337 | |
| 338 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 339 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 340 | return false; |
| 341 | } |
| 342 | |
| 343 | return true; |
| 344 | } |
| 345 | |
| 346 | template <typename ParamType> |
| 347 | bool ValidateTextureMagFilterValue(Context *context, ParamType *params) |
| 348 | { |
| 349 | switch (ConvertToGLenum(params[0])) |
| 350 | { |
| 351 | case GL_NEAREST: |
| 352 | case GL_LINEAR: |
| 353 | break; |
| 354 | |
| 355 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 356 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureFilterParam); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 357 | return false; |
| 358 | } |
| 359 | |
| 360 | return true; |
| 361 | } |
| 362 | |
| 363 | template <typename ParamType> |
| 364 | bool ValidateTextureCompareModeValue(Context *context, ParamType *params) |
| 365 | { |
| 366 | // Acceptable mode parameters from GLES 3.0.2 spec, table 3.17 |
| 367 | switch (ConvertToGLenum(params[0])) |
| 368 | { |
| 369 | case GL_NONE: |
| 370 | case GL_COMPARE_REF_TO_TEXTURE: |
| 371 | break; |
| 372 | |
| 373 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 374 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 375 | return false; |
| 376 | } |
| 377 | |
| 378 | return true; |
| 379 | } |
| 380 | |
| 381 | template <typename ParamType> |
| 382 | bool ValidateTextureCompareFuncValue(Context *context, ParamType *params) |
| 383 | { |
| 384 | // Acceptable function parameters from GLES 3.0.2 spec, table 3.17 |
| 385 | switch (ConvertToGLenum(params[0])) |
| 386 | { |
| 387 | case GL_LEQUAL: |
| 388 | case GL_GEQUAL: |
| 389 | case GL_LESS: |
| 390 | case GL_GREATER: |
| 391 | case GL_EQUAL: |
| 392 | case GL_NOTEQUAL: |
| 393 | case GL_ALWAYS: |
| 394 | case GL_NEVER: |
| 395 | break; |
| 396 | |
| 397 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 398 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 399 | return false; |
| 400 | } |
| 401 | |
| 402 | return true; |
| 403 | } |
| 404 | |
| 405 | template <typename ParamType> |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 406 | bool ValidateTextureSRGBDecodeValue(Context *context, ParamType *params) |
| 407 | { |
| 408 | if (!context->getExtensions().textureSRGBDecode) |
| 409 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 410 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 411 | return false; |
| 412 | } |
| 413 | |
| 414 | switch (ConvertToGLenum(params[0])) |
| 415 | { |
| 416 | case GL_DECODE_EXT: |
| 417 | case GL_SKIP_DECODE_EXT: |
| 418 | break; |
| 419 | |
| 420 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 421 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), UnknownParameter); |
Geoff Lang | 81c6b57 | 2016-10-19 14:07:52 -0700 | [diff] [blame] | 422 | return false; |
| 423 | } |
| 424 | |
| 425 | return true; |
| 426 | } |
| 427 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 428 | bool ValidateTextureMaxAnisotropyExtensionEnabled(Context *context) |
| 429 | { |
| 430 | if (!context->getExtensions().textureFilterAnisotropic) |
| 431 | { |
| 432 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
| 433 | return false; |
| 434 | } |
| 435 | |
| 436 | return true; |
| 437 | } |
| 438 | |
| 439 | bool ValidateTextureMaxAnisotropyValue(Context *context, GLfloat paramValue) |
| 440 | { |
| 441 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 442 | { |
| 443 | return false; |
| 444 | } |
| 445 | |
| 446 | GLfloat largest = context->getExtensions().maxTextureAnisotropy; |
| 447 | |
| 448 | if (paramValue < 1 || paramValue > largest) |
| 449 | { |
| 450 | ANGLE_VALIDATION_ERR(context, InvalidValue(), OutsideOfBounds); |
| 451 | return false; |
| 452 | } |
| 453 | |
| 454 | return true; |
| 455 | } |
| 456 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 457 | bool ValidateFragmentShaderColorBufferTypeMatch(Context *context) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 458 | { |
| 459 | const Program *program = context->getGLState().getProgram(); |
| 460 | const Framebuffer *framebuffer = context->getGLState().getDrawFramebuffer(); |
| 461 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 462 | if (!ComponentTypeMask::Validate(program->getDrawBufferTypeMask().to_ulong(), |
| 463 | framebuffer->getDrawBufferTypeMask().to_ulong(), |
| 464 | program->getActiveOutputVariables().to_ulong(), |
| 465 | framebuffer->getDrawBufferMask().to_ulong())) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 466 | { |
Brandon Jones | 76746f9 | 2017-11-22 11:44:41 -0800 | [diff] [blame] | 467 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DrawBufferTypeMismatch); |
| 468 | return false; |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | return true; |
| 472 | } |
| 473 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 474 | bool ValidateVertexShaderAttributeTypeMatch(Context *context) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 475 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 476 | const auto &glState = context->getGLState(); |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 477 | const Program *program = context->getGLState().getProgram(); |
| 478 | const VertexArray *vao = context->getGLState().getVertexArray(); |
| 479 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 480 | unsigned long stateCurrentValuesTypeBits = glState.getCurrentValuesTypeMask().to_ulong(); |
| 481 | unsigned long vaoAttribTypeBits = vao->getAttributesTypeMask().to_ulong(); |
| 482 | unsigned long vaoAttribEnabledMask = vao->getAttributesMask().to_ulong(); |
| 483 | |
| 484 | vaoAttribEnabledMask |= vaoAttribEnabledMask << MAX_COMPONENT_TYPE_MASK_INDEX; |
| 485 | vaoAttribTypeBits = (vaoAttribEnabledMask & vaoAttribTypeBits); |
| 486 | vaoAttribTypeBits |= (~vaoAttribEnabledMask & stateCurrentValuesTypeBits); |
| 487 | |
| 488 | if (!ComponentTypeMask::Validate(program->getAttributesTypeMask().to_ulong(), vaoAttribTypeBits, |
| 489 | program->getAttributesMask().to_ulong(), 0xFFFF)) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 490 | { |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 491 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), VertexShaderTypeMismatch); |
| 492 | return false; |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 493 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 494 | return true; |
| 495 | } |
| 496 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 497 | bool IsCompatibleDrawModeWithGeometryShader(PrimitiveMode drawMode, |
| 498 | PrimitiveMode geometryShaderInputPrimitiveType) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 499 | { |
| 500 | // [EXT_geometry_shader] Section 11.1gs.1, Geometry Shader Input Primitives |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 501 | switch (drawMode) |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 502 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 503 | case PrimitiveMode::Points: |
| 504 | return geometryShaderInputPrimitiveType == PrimitiveMode::Points; |
| 505 | case PrimitiveMode::Lines: |
| 506 | case PrimitiveMode::LineStrip: |
| 507 | case PrimitiveMode::LineLoop: |
| 508 | return geometryShaderInputPrimitiveType == PrimitiveMode::Lines; |
| 509 | case PrimitiveMode::LinesAdjacency: |
| 510 | case PrimitiveMode::LineStripAdjacency: |
| 511 | return geometryShaderInputPrimitiveType == PrimitiveMode::LinesAdjacency; |
| 512 | case PrimitiveMode::Triangles: |
| 513 | case PrimitiveMode::TriangleFan: |
| 514 | case PrimitiveMode::TriangleStrip: |
| 515 | return geometryShaderInputPrimitiveType == PrimitiveMode::Triangles; |
| 516 | case PrimitiveMode::TrianglesAdjacency: |
| 517 | case PrimitiveMode::TriangleStripAdjacency: |
| 518 | return geometryShaderInputPrimitiveType == PrimitiveMode::TrianglesAdjacency; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 519 | default: |
| 520 | UNREACHABLE(); |
| 521 | return false; |
| 522 | } |
| 523 | } |
| 524 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 525 | } // anonymous namespace |
| 526 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 527 | void SetRobustLengthParam(GLsizei *length, GLsizei value) |
| 528 | { |
| 529 | if (length) |
| 530 | { |
| 531 | *length = value; |
| 532 | } |
| 533 | } |
| 534 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 535 | bool IsETC2EACFormat(const GLenum format) |
| 536 | { |
| 537 | // ES 3.1, Table 8.19 |
| 538 | switch (format) |
| 539 | { |
| 540 | case GL_COMPRESSED_R11_EAC: |
| 541 | case GL_COMPRESSED_SIGNED_R11_EAC: |
| 542 | case GL_COMPRESSED_RG11_EAC: |
| 543 | case GL_COMPRESSED_SIGNED_RG11_EAC: |
| 544 | case GL_COMPRESSED_RGB8_ETC2: |
| 545 | case GL_COMPRESSED_SRGB8_ETC2: |
| 546 | case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 547 | case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: |
| 548 | case GL_COMPRESSED_RGBA8_ETC2_EAC: |
| 549 | case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: |
| 550 | return true; |
| 551 | |
| 552 | default: |
| 553 | return false; |
| 554 | } |
| 555 | } |
| 556 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 557 | bool ValidTextureTarget(const Context *context, TextureType type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 558 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 559 | switch (type) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 560 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 561 | case TextureType::_2D: |
| 562 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 563 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 564 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 565 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 566 | return context->getExtensions().textureRectangle; |
| 567 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 568 | case TextureType::_3D: |
| 569 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 570 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 571 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 572 | case TextureType::_2DMultisample: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 573 | return (context->getClientVersion() >= Version(3, 1)); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 574 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 575 | default: |
| 576 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 577 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 578 | } |
| 579 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 580 | bool ValidTexture2DTarget(const Context *context, TextureType type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 581 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 582 | switch (type) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 583 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 584 | case TextureType::_2D: |
| 585 | case TextureType::CubeMap: |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 586 | return true; |
| 587 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 588 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 589 | return context->getExtensions().textureRectangle; |
| 590 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 591 | default: |
| 592 | return false; |
| 593 | } |
| 594 | } |
| 595 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 596 | bool ValidTexture3DTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 597 | { |
| 598 | switch (target) |
| 599 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 600 | case TextureType::_3D: |
| 601 | case TextureType::_2DArray: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 602 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 603 | |
| 604 | default: |
| 605 | return false; |
| 606 | } |
| 607 | } |
| 608 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 609 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 610 | // function for use in the GL calls that do |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 611 | bool ValidTextureExternalTarget(const Context *context, TextureType target) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 612 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 613 | return (target == TextureType::External) && |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 614 | (context->getExtensions().eglImageExternal || |
| 615 | context->getExtensions().eglStreamConsumerExternal); |
| 616 | } |
| 617 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 618 | // This function differs from ValidTextureTarget in that the target must be |
| 619 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 620 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 621 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 622 | bool ValidTexture2DDestinationTarget(const Context *context, TextureTarget target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 623 | { |
| 624 | switch (target) |
| 625 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 626 | case TextureTarget::_2D: |
| 627 | case TextureTarget::CubeMapNegativeX: |
| 628 | case TextureTarget::CubeMapNegativeY: |
| 629 | case TextureTarget::CubeMapNegativeZ: |
| 630 | case TextureTarget::CubeMapPositiveX: |
| 631 | case TextureTarget::CubeMapPositiveY: |
| 632 | case TextureTarget::CubeMapPositiveZ: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 633 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 634 | case TextureTarget::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 635 | return context->getExtensions().textureRectangle; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 636 | default: |
| 637 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 641 | bool ValidateTransformFeedbackPrimitiveMode(const Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 642 | PrimitiveMode transformFeedbackPrimitiveMode, |
| 643 | PrimitiveMode renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 644 | { |
| 645 | ASSERT(context); |
| 646 | |
| 647 | if (!context->getExtensions().geometryShader) |
| 648 | { |
| 649 | // It is an invalid operation to call DrawArrays or DrawArraysInstanced with a draw mode |
| 650 | // that does not match the current transform feedback object's draw mode (if transform |
| 651 | // feedback is active), (3.0.2, section 2.14, pg 86) |
| 652 | return transformFeedbackPrimitiveMode == renderPrimitiveMode; |
| 653 | } |
| 654 | |
| 655 | // [GL_EXT_geometry_shader] Table 12.1gs |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 656 | switch (renderPrimitiveMode) |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 657 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 658 | case PrimitiveMode::Points: |
| 659 | return transformFeedbackPrimitiveMode == PrimitiveMode::Points; |
| 660 | case PrimitiveMode::Lines: |
| 661 | case PrimitiveMode::LineStrip: |
| 662 | case PrimitiveMode::LineLoop: |
| 663 | return transformFeedbackPrimitiveMode == PrimitiveMode::Lines; |
| 664 | case PrimitiveMode::Triangles: |
| 665 | case PrimitiveMode::TriangleFan: |
| 666 | case PrimitiveMode::TriangleStrip: |
| 667 | return transformFeedbackPrimitiveMode == PrimitiveMode::Triangles; |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 668 | default: |
| 669 | UNREACHABLE(); |
| 670 | return false; |
| 671 | } |
| 672 | } |
| 673 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 674 | bool ValidateDrawElementsInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 675 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 676 | GLsizei count, |
| 677 | GLenum type, |
| 678 | const GLvoid *indices, |
| 679 | GLsizei primcount) |
| 680 | { |
| 681 | if (primcount < 0) |
| 682 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 683 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 684 | return false; |
| 685 | } |
| 686 | |
| 687 | if (!ValidateDrawElementsCommon(context, mode, count, type, indices, primcount)) |
| 688 | { |
| 689 | return false; |
| 690 | } |
| 691 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 692 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 693 | } |
| 694 | |
| 695 | bool ValidateDrawArraysInstancedBase(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 696 | PrimitiveMode mode, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 697 | GLint first, |
| 698 | GLsizei count, |
| 699 | GLsizei primcount) |
| 700 | { |
| 701 | if (primcount < 0) |
| 702 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 703 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativePrimcount); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 704 | return false; |
| 705 | } |
| 706 | |
| 707 | if (!ValidateDrawArraysCommon(context, mode, first, count, primcount)) |
| 708 | { |
| 709 | return false; |
| 710 | } |
| 711 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 712 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 713 | } |
| 714 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 715 | bool ValidateDrawInstancedANGLE(Context *context) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 716 | { |
| 717 | // Verify there is at least one active attribute with a divisor of zero |
| 718 | const State &state = context->getGLState(); |
| 719 | |
| 720 | Program *program = state.getProgram(); |
| 721 | |
| 722 | const auto &attribs = state.getVertexArray()->getVertexAttributes(); |
| 723 | const auto &bindings = state.getVertexArray()->getVertexBindings(); |
| 724 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
| 725 | { |
| 726 | const VertexAttribute &attrib = attribs[attributeIndex]; |
| 727 | const VertexBinding &binding = bindings[attrib.bindingIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 728 | if (program->isAttribLocationActive(attributeIndex) && binding.getDivisor() == 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 729 | { |
| 730 | return true; |
| 731 | } |
| 732 | } |
| 733 | |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 734 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoZeroDivisor); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 735 | return false; |
| 736 | } |
| 737 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 738 | bool ValidTexture3DDestinationTarget(const Context *context, TextureType target) |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 739 | { |
| 740 | switch (target) |
| 741 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 742 | case TextureType::_3D: |
| 743 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 744 | return true; |
| 745 | default: |
| 746 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 747 | } |
| 748 | } |
| 749 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 750 | bool ValidTexLevelDestinationTarget(const Context *context, TextureType type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 751 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 752 | switch (type) |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 753 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 754 | case TextureType::_2D: |
| 755 | case TextureType::_2DArray: |
| 756 | case TextureType::_2DMultisample: |
| 757 | case TextureType::CubeMap: |
| 758 | case TextureType::_3D: |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 759 | return true; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 760 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 761 | return context->getExtensions().textureRectangle; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame] | 762 | default: |
| 763 | return false; |
| 764 | } |
| 765 | } |
| 766 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 767 | bool ValidFramebufferTarget(const Context *context, GLenum target) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 768 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 769 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 770 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 771 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 772 | |
| 773 | switch (target) |
| 774 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 775 | case GL_FRAMEBUFFER: |
| 776 | return true; |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 777 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 778 | case GL_READ_FRAMEBUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 779 | case GL_DRAW_FRAMEBUFFER: |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 780 | return (context->getExtensions().framebufferBlit || |
| 781 | context->getClientMajorVersion() >= 3); |
| 782 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 783 | default: |
| 784 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 785 | } |
| 786 | } |
| 787 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 788 | bool ValidMipLevel(const Context *context, TextureType type, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 789 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 790 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 791 | size_t maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 792 | switch (type) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 793 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 794 | case TextureType::_2D: |
| 795 | case TextureType::_2DArray: |
| 796 | case TextureType::_2DMultisample: |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 797 | maxDimension = caps.max2DTextureSize; |
| 798 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 799 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 800 | maxDimension = caps.maxCubeMapTextureSize; |
| 801 | break; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 802 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 803 | return level == 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 804 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 805 | maxDimension = caps.max3DTextureSize; |
| 806 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 807 | default: |
| 808 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 809 | } |
| 810 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 811 | return level <= gl::log2(static_cast<int>(maxDimension)) && level >= 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 812 | } |
| 813 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 814 | bool ValidImageSizeParameters(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 815 | TextureType target, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 816 | GLint level, |
| 817 | GLsizei width, |
| 818 | GLsizei height, |
| 819 | GLsizei depth, |
| 820 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 821 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 822 | if (width < 0 || height < 0 || depth < 0) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 823 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 824 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 825 | return false; |
| 826 | } |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 827 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 828 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 829 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 830 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 831 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 832 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 833 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 834 | ANGLE_VALIDATION_ERR(context, InvalidValue(), TextureNotPow2); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 835 | return false; |
| 836 | } |
| 837 | |
| 838 | if (!ValidMipLevel(context, target, level)) |
| 839 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 840 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 841 | return false; |
| 842 | } |
| 843 | |
| 844 | return true; |
| 845 | } |
| 846 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 847 | bool ValidCompressedDimension(GLsizei size, GLuint blockSize, bool smallerThanBlockSizeAllowed) |
| 848 | { |
| 849 | return (smallerThanBlockSizeAllowed && (size > 0) && (blockSize % size == 0)) || |
| 850 | (size % blockSize == 0); |
| 851 | } |
| 852 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 853 | bool ValidCompressedImageSize(const Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 854 | GLenum internalFormat, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 855 | GLint level, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 856 | GLsizei width, |
| 857 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 858 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 859 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 860 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 861 | { |
| 862 | return false; |
| 863 | } |
| 864 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 865 | if (width < 0 || height < 0) |
| 866 | { |
| 867 | return false; |
| 868 | } |
| 869 | |
| 870 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 871 | { |
| 872 | // The ANGLE extensions allow specifying compressed textures with sizes smaller than the |
| 873 | // block size for level 0 but WebGL disallows this. |
| 874 | bool smallerThanBlockSizeAllowed = |
| 875 | level > 0 || !context->getExtensions().webglCompatibility; |
| 876 | |
| 877 | if (!ValidCompressedDimension(width, formatInfo.compressedBlockWidth, |
| 878 | smallerThanBlockSizeAllowed) || |
| 879 | !ValidCompressedDimension(height, formatInfo.compressedBlockHeight, |
| 880 | smallerThanBlockSizeAllowed)) |
| 881 | { |
| 882 | return false; |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return true; |
| 887 | } |
| 888 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 889 | bool ValidCompressedSubImageSize(const Context *context, |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 890 | GLenum internalFormat, |
| 891 | GLint xoffset, |
| 892 | GLint yoffset, |
| 893 | GLsizei width, |
| 894 | GLsizei height, |
| 895 | size_t textureWidth, |
| 896 | size_t textureHeight) |
| 897 | { |
| 898 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); |
| 899 | if (!formatInfo.compressed) |
| 900 | { |
| 901 | return false; |
| 902 | } |
| 903 | |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 904 | if (xoffset < 0 || yoffset < 0 || width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 905 | { |
| 906 | return false; |
| 907 | } |
| 908 | |
Luc Ferron | 9dbaeba | 2018-02-01 07:26:59 -0500 | [diff] [blame] | 909 | if (CompressedSubTextureFormatRequiresExactSize(internalFormat)) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 910 | { |
Geoff Lang | 44ff5a7 | 2017-02-03 15:15:43 -0500 | [diff] [blame] | 911 | if (xoffset % formatInfo.compressedBlockWidth != 0 || |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 912 | yoffset % formatInfo.compressedBlockHeight != 0) |
| 913 | { |
| 914 | return false; |
| 915 | } |
| 916 | |
| 917 | // Allowed to either have data that is a multiple of block size or is smaller than the block |
| 918 | // size but fills the entire mip |
| 919 | bool fillsEntireMip = xoffset == 0 && yoffset == 0 && |
| 920 | static_cast<size_t>(width) == textureWidth && |
| 921 | static_cast<size_t>(height) == textureHeight; |
| 922 | bool sizeMultipleOfBlockSize = (width % formatInfo.compressedBlockWidth) == 0 && |
| 923 | (height % formatInfo.compressedBlockHeight) == 0; |
| 924 | if (!sizeMultipleOfBlockSize && !fillsEntireMip) |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 925 | { |
| 926 | return false; |
| 927 | } |
| 928 | } |
| 929 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 930 | return true; |
| 931 | } |
| 932 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 933 | bool ValidImageDataSize(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 934 | TextureType texType, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 935 | GLsizei width, |
| 936 | GLsizei height, |
| 937 | GLsizei depth, |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 938 | GLenum format, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 939 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 940 | const void *pixels, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 941 | GLsizei imageSize) |
| 942 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 943 | gl::Buffer *pixelUnpackBuffer = |
| 944 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 945 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 946 | { |
| 947 | // Checks are not required |
| 948 | return true; |
| 949 | } |
| 950 | |
| 951 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 952 | // would exceed the data store size. |
Geoff Lang | dbcced8 | 2017-06-06 15:55:54 -0400 | [diff] [blame] | 953 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(format, type); |
| 954 | ASSERT(formatInfo.internalFormat != GL_NONE); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 955 | const gl::Extents size(width, height, depth); |
| 956 | const auto &unpack = context->getGLState().getUnpackState(); |
| 957 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 958 | bool targetIs3D = texType == TextureType::_3D || texType == TextureType::_2DArray; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 959 | auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D); |
| 960 | if (endByteOrErr.isError()) |
| 961 | { |
| 962 | context->handleError(endByteOrErr.getError()); |
| 963 | return false; |
| 964 | } |
| 965 | |
| 966 | GLuint endByte = endByteOrErr.getResult(); |
| 967 | |
| 968 | if (pixelUnpackBuffer) |
| 969 | { |
| 970 | CheckedNumeric<size_t> checkedEndByte(endByteOrErr.getResult()); |
| 971 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 972 | checkedEndByte += checkedOffset; |
| 973 | |
| 974 | if (!checkedEndByte.IsValid() || |
| 975 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 976 | { |
| 977 | // Overflow past the end of the buffer |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 978 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 979 | return false; |
| 980 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 981 | if (context->getExtensions().webglCompatibility && |
| 982 | pixelUnpackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 983 | { |
| 984 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 985 | PixelUnpackBufferBoundForTransformFeedback); |
| 986 | return false; |
| 987 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 988 | } |
| 989 | else |
| 990 | { |
| 991 | ASSERT(imageSize >= 0); |
| 992 | if (pixels == nullptr && imageSize != 0) |
| 993 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 994 | context->handleError(InvalidOperation() |
| 995 | << "imageSize must be 0 if no texture data is provided."); |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 996 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 997 | } |
| 998 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 999 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1000 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1001 | context->handleError(InvalidOperation() << "imageSize must be at least " << endByte); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1002 | return false; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | return true; |
| 1007 | } |
| 1008 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1009 | bool ValidQueryType(const Context *context, QueryType queryType) |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1010 | { |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1011 | switch (queryType) |
| 1012 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1013 | case QueryType::AnySamples: |
| 1014 | case QueryType::AnySamplesConservative: |
Geoff Lang | 8c5b31c | 2017-09-26 18:07:44 -0400 | [diff] [blame] | 1015 | return context->getClientMajorVersion() >= 3 || |
| 1016 | context->getExtensions().occlusionQueryBoolean; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1017 | case QueryType::TransformFeedbackPrimitivesWritten: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1018 | return (context->getClientMajorVersion() >= 3); |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1019 | case QueryType::TimeElapsed: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1020 | return context->getExtensions().disjointTimerQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1021 | case QueryType::CommandsCompleted: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1022 | return context->getExtensions().syncQuery; |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1023 | case QueryType::PrimitivesGenerated: |
Jiawei Shao | d2fa07e | 2018-03-15 09:20:25 +0800 | [diff] [blame] | 1024 | return context->getExtensions().geometryShader; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1025 | default: |
| 1026 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1027 | } |
| 1028 | } |
| 1029 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1030 | bool ValidateWebGLVertexAttribPointer(Context *context, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1031 | GLenum type, |
| 1032 | GLboolean normalized, |
| 1033 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1034 | const void *ptr, |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1035 | bool pureInteger) |
| 1036 | { |
| 1037 | ASSERT(context->getExtensions().webglCompatibility); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1038 | // WebGL 1.0 [Section 6.11] Vertex Attribute Data Stride |
| 1039 | // The WebGL API supports vertex attribute data strides up to 255 bytes. A call to |
| 1040 | // vertexAttribPointer will generate an INVALID_VALUE error if the value for the stride |
| 1041 | // parameter exceeds 255. |
| 1042 | constexpr GLsizei kMaxWebGLStride = 255; |
| 1043 | if (stride > kMaxWebGLStride) |
| 1044 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1045 | context->handleError(InvalidValue() |
| 1046 | << "Stride is over the maximum stride allowed by WebGL."); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1047 | return false; |
| 1048 | } |
| 1049 | |
| 1050 | // WebGL 1.0 [Section 6.4] Buffer Offset and Stride Requirements |
| 1051 | // The offset arguments to drawElements and vertexAttribPointer, and the stride argument to |
| 1052 | // vertexAttribPointer, must be a multiple of the size of the data type passed to the call, |
| 1053 | // or an INVALID_OPERATION error is generated. |
| 1054 | VertexFormatType internalType = GetVertexFormatType(type, normalized, 1, pureInteger); |
| 1055 | size_t typeSize = GetVertexFormatTypeSize(internalType); |
| 1056 | |
| 1057 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 1058 | size_t sizeMask = (typeSize - 1); |
| 1059 | if ((reinterpret_cast<intptr_t>(ptr) & sizeMask) != 0) |
| 1060 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1061 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1062 | return false; |
| 1063 | } |
| 1064 | |
| 1065 | if ((stride & sizeMask) != 0) |
| 1066 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1067 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StrideMustBeMultipleOfType); |
Geoff Lang | 2d62ab7 | 2017-03-23 16:54:40 -0400 | [diff] [blame] | 1068 | return false; |
| 1069 | } |
| 1070 | |
| 1071 | return true; |
| 1072 | } |
| 1073 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1074 | Program *GetValidProgram(Context *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1075 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1076 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1077 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1078 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1079 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1080 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1081 | Program *validProgram = context->getProgram(id); |
| 1082 | |
| 1083 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1084 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1085 | if (context->getShader(id)) |
| 1086 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1087 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1088 | } |
| 1089 | else |
| 1090 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1091 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidProgramName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1092 | } |
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 | |
| 1095 | return validProgram; |
| 1096 | } |
| 1097 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1098 | Shader *GetValidShader(Context *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1099 | { |
| 1100 | // See ValidProgram for spec details. |
| 1101 | |
| 1102 | Shader *validShader = context->getShader(id); |
| 1103 | |
| 1104 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1105 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1106 | if (context->getProgram(id)) |
| 1107 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1108 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExpectedShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1109 | } |
| 1110 | else |
| 1111 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1112 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidShaderName); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1113 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1114 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1115 | |
| 1116 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1117 | } |
| 1118 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1119 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1120 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1121 | if (attachment >= GL_COLOR_ATTACHMENT1_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1122 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1123 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().drawBuffers) |
| 1124 | { |
| 1125 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 1126 | return false; |
| 1127 | } |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1128 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1129 | // Color attachment 0 is validated below because it is always valid |
| 1130 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1131 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1132 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1133 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1134 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1135 | } |
| 1136 | } |
| 1137 | else |
| 1138 | { |
| 1139 | switch (attachment) |
| 1140 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1141 | case GL_COLOR_ATTACHMENT0: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1142 | case GL_DEPTH_ATTACHMENT: |
| 1143 | case GL_STENCIL_ATTACHMENT: |
| 1144 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1145 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1146 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1147 | if (!context->getExtensions().webglCompatibility && |
| 1148 | context->getClientMajorVersion() < 3) |
| 1149 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1150 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1151 | return false; |
| 1152 | } |
| 1153 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1154 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1155 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 1156 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1157 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1158 | } |
| 1159 | } |
| 1160 | |
| 1161 | return true; |
| 1162 | } |
| 1163 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 1164 | bool ValidateRenderbufferStorageParametersBase(Context *context, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1165 | GLenum target, |
| 1166 | GLsizei samples, |
| 1167 | GLenum internalformat, |
| 1168 | GLsizei width, |
| 1169 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1170 | { |
| 1171 | switch (target) |
| 1172 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1173 | case GL_RENDERBUFFER: |
| 1174 | break; |
| 1175 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1176 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1177 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | if (width < 0 || height < 0 || samples < 0) |
| 1181 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1182 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidRenderbufferWidthHeight); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1183 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1184 | } |
| 1185 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 1186 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 1187 | GLenum convertedInternalFormat = context->getConvertedRenderbufferFormat(internalformat); |
| 1188 | |
| 1189 | const TextureCaps &formatCaps = context->getTextureCaps().get(convertedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 1190 | if (!formatCaps.renderbuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1191 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1192 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1193 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1197 | // 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] | 1198 | // only sized internal formats. |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 1199 | const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(convertedInternalFormat); |
| 1200 | if (formatInfo.internalFormat == GL_NONE) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1201 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1202 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferInternalFormat); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1203 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1204 | } |
| 1205 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1206 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1207 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1208 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1209 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1210 | } |
| 1211 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1212 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1213 | if (handle == 0) |
| 1214 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1215 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
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 | |
| 1219 | return true; |
| 1220 | } |
| 1221 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1222 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, |
| 1223 | GLenum target, |
| 1224 | GLenum attachment, |
| 1225 | GLenum renderbuffertarget, |
| 1226 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1227 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 1228 | if (!ValidFramebufferTarget(context, target)) |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1229 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1230 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1231 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1232 | } |
| 1233 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1234 | gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1235 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1236 | ASSERT(framebuffer); |
| 1237 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1238 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1239 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1240 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1241 | } |
| 1242 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1243 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1244 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1245 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1246 | } |
| 1247 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1248 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1249 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1250 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1251 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1252 | if (renderbuffer != 0) |
| 1253 | { |
| 1254 | if (!context->getRenderbuffer(renderbuffer)) |
| 1255 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1256 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidRenderbufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1257 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1258 | } |
| 1259 | } |
| 1260 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1261 | return true; |
| 1262 | } |
| 1263 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1264 | bool ValidateBlitFramebufferParameters(Context *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1265 | GLint srcX0, |
| 1266 | GLint srcY0, |
| 1267 | GLint srcX1, |
| 1268 | GLint srcY1, |
| 1269 | GLint dstX0, |
| 1270 | GLint dstY0, |
| 1271 | GLint dstX1, |
| 1272 | GLint dstY1, |
| 1273 | GLbitfield mask, |
| 1274 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1275 | { |
| 1276 | switch (filter) |
| 1277 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1278 | case GL_NEAREST: |
| 1279 | break; |
| 1280 | case GL_LINEAR: |
| 1281 | break; |
| 1282 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1283 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1284 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1288 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1289 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1290 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1291 | } |
| 1292 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1293 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1294 | // color buffer, leaving only nearest being unfiltered from above |
| 1295 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1296 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1297 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1298 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1299 | } |
| 1300 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1301 | const auto &glState = context->getGLState(); |
| 1302 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1303 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1304 | |
| 1305 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1306 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1307 | context->handleError(InvalidFramebufferOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1308 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1309 | } |
| 1310 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1311 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1312 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1313 | return false; |
| 1314 | } |
| 1315 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 1316 | if (!ValidateFramebufferComplete(context, drawFramebuffer)) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1317 | { |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1318 | return false; |
| 1319 | } |
| 1320 | |
Qin Jiajia | aef9216 | 2018-02-27 13:51:44 +0800 | [diff] [blame] | 1321 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1322 | { |
| 1323 | context->handleError(InvalidOperation()); |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 1327 | if (!ValidateFramebufferNotMultisampled(context, drawFramebuffer)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1328 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1329 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1330 | } |
| 1331 | |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1332 | // This validation is specified in the WebGL 2.0 spec and not in the GLES 3.0.5 spec, but we |
| 1333 | // always run it in order to avoid triggering driver bugs. |
| 1334 | if (DifferenceCanOverflow(srcX0, srcX1) || DifferenceCanOverflow(srcY0, srcY1) || |
| 1335 | DifferenceCanOverflow(dstX0, dstX1) || DifferenceCanOverflow(dstY0, dstY1)) |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1336 | { |
Olli Etuaho | 9aef81c | 2018-04-30 14:56:15 +0300 | [diff] [blame] | 1337 | ANGLE_VALIDATION_ERR(context, InvalidValue(), BlitDimensionsOutOfRange); |
| 1338 | return false; |
Olli Etuaho | 8d5571a | 2018-04-23 12:29:31 +0300 | [diff] [blame] | 1339 | } |
| 1340 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1341 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 1342 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1343 | if (mask & GL_COLOR_BUFFER_BIT) |
| 1344 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1345 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1346 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1347 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1348 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1349 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1350 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1351 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1352 | for (size_t drawbufferIdx = 0; |
| 1353 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1354 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 1355 | const FramebufferAttachment *attachment = |
| 1356 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 1357 | if (attachment) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1358 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1359 | const Format &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1360 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 1361 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 1362 | // 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] | 1363 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 1364 | // as well |
| 1365 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 1366 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1367 | // Changes with EXT_color_buffer_float: |
| 1368 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1369 | GLenum readComponentType = readFormat.info->componentType; |
| 1370 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1371 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1372 | readComponentType == GL_SIGNED_NORMALIZED); |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1373 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1374 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 1375 | |
| 1376 | if (extensions.colorBufferFloat) |
| 1377 | { |
| 1378 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 1379 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 1380 | |
| 1381 | if (readFixedOrFloat != drawFixedOrFloat) |
| 1382 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1383 | context->handleError(InvalidOperation() |
| 1384 | << "If the read buffer contains fixed-point or " |
| 1385 | "floating-point values, the draw buffer must " |
| 1386 | "as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1387 | return false; |
| 1388 | } |
| 1389 | } |
| 1390 | else if (readFixedPoint != drawFixedPoint) |
| 1391 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1392 | context->handleError(InvalidOperation() |
| 1393 | << "If the read buffer contains fixed-point values, " |
| 1394 | "the draw buffer must as well."); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1395 | return false; |
| 1396 | } |
| 1397 | |
| 1398 | if (readComponentType == GL_UNSIGNED_INT && |
| 1399 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1400 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1401 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1402 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1403 | } |
| 1404 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 1405 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1406 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1407 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1408 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1409 | } |
| 1410 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1411 | if (readColorBuffer->getSamples() > 0 && |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1412 | (!Format::EquivalentForBlit(readFormat, drawFormat) || !sameBounds)) |
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 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1417 | |
| 1418 | if (context->getExtensions().webglCompatibility && |
| 1419 | *readColorBuffer == *attachment) |
| 1420 | { |
| 1421 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1422 | InvalidOperation() |
| 1423 | << "Read and write color attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1424 | return false; |
| 1425 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1426 | } |
| 1427 | } |
| 1428 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 1429 | if ((readFormat.info->componentType == GL_INT || |
| 1430 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 1431 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1432 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1433 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1434 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1435 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1436 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1437 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1438 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 1439 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 1440 | // situation is an application error that would lead to a crash in ANGLE. |
| 1441 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 1442 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1443 | context->handleError( |
| 1444 | InvalidOperation() |
| 1445 | << "Attempt to read from a missing color attachment of a complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1446 | return false; |
| 1447 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1448 | } |
| 1449 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1450 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1451 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 1452 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1453 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1454 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1455 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1456 | const gl::FramebufferAttachment *readBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1457 | readFramebuffer->getAttachment(context, attachments[i]); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1458 | const gl::FramebufferAttachment *drawBuffer = |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 1459 | drawFramebuffer->getAttachment(context, attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1460 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1461 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1462 | { |
Kenneth Russell | 6938285 | 2017-07-21 16:38:44 -0400 | [diff] [blame] | 1463 | if (!Format::EquivalentForBlit(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1464 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1465 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1466 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1467 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1468 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 1469 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1470 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1471 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1472 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1473 | } |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1474 | |
| 1475 | if (context->getExtensions().webglCompatibility && *readBuffer == *drawBuffer) |
| 1476 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1477 | context->handleError( |
| 1478 | InvalidOperation() |
| 1479 | << "Read and write depth stencil attachments cannot be the same image."); |
Geoff Lang | e491578 | 2017-04-12 15:19:07 -0400 | [diff] [blame] | 1480 | return false; |
| 1481 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1482 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1483 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 1484 | else if (drawBuffer) |
| 1485 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1486 | context->handleError(InvalidOperation() << "Attempt to read from a missing " |
| 1487 | "depth/stencil attachment of a " |
| 1488 | "complete framebuffer."); |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 1489 | return false; |
| 1490 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | |
Martin Radev | a3ed457 | 2017-07-27 18:29:37 +0300 | [diff] [blame] | 1494 | // ANGLE_multiview, Revision 1: |
| 1495 | // Calling BlitFramebuffer will result in an INVALID_FRAMEBUFFER_OPERATION error if the |
| 1496 | // multi-view layout of the current draw framebuffer or read framebuffer is not NONE. |
| 1497 | if (readFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1498 | { |
| 1499 | context->handleError(InvalidFramebufferOperation() |
| 1500 | << "Attempt to read from a multi-view framebuffer."); |
| 1501 | return false; |
| 1502 | } |
| 1503 | if (drawFramebuffer->getMultiviewLayout() != GL_NONE) |
| 1504 | { |
| 1505 | context->handleError(InvalidFramebufferOperation() |
| 1506 | << "Attempt to write to a multi-view framebuffer."); |
| 1507 | return false; |
| 1508 | } |
| 1509 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1510 | return true; |
| 1511 | } |
| 1512 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1513 | bool ValidateReadPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1514 | GLint x, |
| 1515 | GLint y, |
| 1516 | GLsizei width, |
| 1517 | GLsizei height, |
| 1518 | GLenum format, |
| 1519 | GLenum type, |
| 1520 | GLsizei bufSize, |
| 1521 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1522 | GLsizei *columns, |
| 1523 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1524 | void *pixels) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1525 | { |
| 1526 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1527 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1528 | return false; |
| 1529 | } |
| 1530 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1531 | GLsizei writeLength = 0; |
| 1532 | GLsizei writeColumns = 0; |
| 1533 | GLsizei writeRows = 0; |
| 1534 | |
| 1535 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1536 | &writeColumns, &writeRows, pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1537 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1538 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1539 | } |
| 1540 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1541 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1542 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1543 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1544 | } |
| 1545 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1546 | SetRobustLengthParam(length, writeLength); |
| 1547 | SetRobustLengthParam(columns, writeColumns); |
| 1548 | SetRobustLengthParam(rows, writeRows); |
| 1549 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1550 | return true; |
| 1551 | } |
| 1552 | |
| 1553 | bool ValidateReadnPixelsEXT(Context *context, |
| 1554 | GLint x, |
| 1555 | GLint y, |
| 1556 | GLsizei width, |
| 1557 | GLsizei height, |
| 1558 | GLenum format, |
| 1559 | GLenum type, |
| 1560 | GLsizei bufSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1561 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1562 | { |
| 1563 | if (bufSize < 0) |
| 1564 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1565 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1566 | return false; |
| 1567 | } |
| 1568 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1569 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1570 | nullptr, nullptr, pixels); |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1571 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1572 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1573 | bool ValidateReadnPixelsRobustANGLE(Context *context, |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1574 | GLint x, |
| 1575 | GLint y, |
| 1576 | GLsizei width, |
| 1577 | GLsizei height, |
| 1578 | GLenum format, |
| 1579 | GLenum type, |
| 1580 | GLsizei bufSize, |
| 1581 | GLsizei *length, |
Geoff Lang | e93daba | 2017-03-30 13:54:40 -0400 | [diff] [blame] | 1582 | GLsizei *columns, |
| 1583 | GLsizei *rows, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1584 | void *data) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1585 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1586 | GLsizei writeLength = 0; |
| 1587 | GLsizei writeColumns = 0; |
| 1588 | GLsizei writeRows = 0; |
| 1589 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1590 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1591 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1592 | return false; |
| 1593 | } |
| 1594 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1595 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, &writeLength, |
| 1596 | &writeColumns, &writeRows, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1597 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1598 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1599 | } |
| 1600 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1601 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1602 | { |
| 1603 | return false; |
| 1604 | } |
| 1605 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1606 | SetRobustLengthParam(length, writeLength); |
| 1607 | SetRobustLengthParam(columns, writeColumns); |
| 1608 | SetRobustLengthParam(rows, writeRows); |
| 1609 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 1610 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 1611 | } |
| 1612 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1613 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n, GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1614 | { |
| 1615 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1616 | !context->getExtensions().disjointTimerQuery) |
| 1617 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1618 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1619 | return false; |
| 1620 | } |
| 1621 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1622 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1623 | } |
| 1624 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1625 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n, const GLuint *ids) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1626 | { |
| 1627 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1628 | !context->getExtensions().disjointTimerQuery) |
| 1629 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1630 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1631 | return false; |
| 1632 | } |
| 1633 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 1634 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1635 | } |
| 1636 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1637 | bool ValidateIsQueryEXT(gl::Context *context, GLuint id) |
| 1638 | { |
| 1639 | if (!context->getExtensions().occlusionQueryBoolean && |
| 1640 | !context->getExtensions().disjointTimerQuery) |
| 1641 | { |
| 1642 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
| 1643 | return false; |
| 1644 | } |
| 1645 | |
| 1646 | return true; |
| 1647 | } |
| 1648 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1649 | bool ValidateBeginQueryBase(gl::Context *context, QueryType target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1650 | { |
| 1651 | if (!ValidQueryType(context, target)) |
| 1652 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1653 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1654 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | if (id == 0) |
| 1658 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1659 | context->handleError(InvalidOperation() << "Query id is 0"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1660 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1661 | } |
| 1662 | |
| 1663 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 1664 | // of zero, if the active query object name for <target> is non-zero (for the |
| 1665 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 1666 | // the active query for either target is non-zero), if <id> is the name of an |
| 1667 | // existing query object whose type does not match <target>, or if <id> is the |
| 1668 | // active query object name for any query type, the error INVALID_OPERATION is |
| 1669 | // generated. |
| 1670 | |
| 1671 | // Ensure no other queries are active |
| 1672 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 1673 | // separately that: |
| 1674 | // a) The query ID passed is not the current active query for any target/type |
| 1675 | // b) There are no active queries for the requested target (and in the case |
| 1676 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1677 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1678 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1679 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1680 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1681 | context->handleError(InvalidOperation() << "Other query is active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1682 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | Query *queryObject = context->getQuery(id, true, target); |
| 1686 | |
| 1687 | // check that name was obtained with glGenQueries |
| 1688 | if (!queryObject) |
| 1689 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1690 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1691 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | // check for type mismatch |
| 1695 | if (queryObject->getType() != target) |
| 1696 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1697 | context->handleError(InvalidOperation() << "Query type does not match target"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1698 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1699 | } |
| 1700 | |
| 1701 | return true; |
| 1702 | } |
| 1703 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1704 | bool ValidateBeginQueryEXT(gl::Context *context, QueryType target, GLuint id) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1705 | { |
| 1706 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1707 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1708 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1709 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1710 | return false; |
| 1711 | } |
| 1712 | |
| 1713 | return ValidateBeginQueryBase(context, target, id); |
| 1714 | } |
| 1715 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1716 | bool ValidateEndQueryBase(gl::Context *context, QueryType target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1717 | { |
| 1718 | if (!ValidQueryType(context, target)) |
| 1719 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1720 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1721 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1722 | } |
| 1723 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1724 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1725 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1726 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1727 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1728 | context->handleError(InvalidOperation() << "Query target not active"); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1729 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1730 | } |
| 1731 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1732 | return true; |
| 1733 | } |
| 1734 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1735 | bool ValidateEndQueryEXT(gl::Context *context, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1736 | { |
| 1737 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1738 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1739 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1740 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1741 | return false; |
| 1742 | } |
| 1743 | |
| 1744 | return ValidateEndQueryBase(context, target); |
| 1745 | } |
| 1746 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1747 | bool ValidateQueryCounterEXT(Context *context, GLuint id, QueryType target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1748 | { |
| 1749 | if (!context->getExtensions().disjointTimerQuery) |
| 1750 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1751 | context->handleError(InvalidOperation() << "Disjoint timer query not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1752 | return false; |
| 1753 | } |
| 1754 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1755 | if (target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1756 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1757 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryTarget); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1758 | return false; |
| 1759 | } |
| 1760 | |
| 1761 | Query *queryObject = context->getQuery(id, true, target); |
| 1762 | if (queryObject == nullptr) |
| 1763 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1764 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1765 | return false; |
| 1766 | } |
| 1767 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1768 | if (context->getGLState().isQueryActive(queryObject)) |
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, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1771 | return false; |
| 1772 | } |
| 1773 | |
| 1774 | return true; |
| 1775 | } |
| 1776 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1777 | bool ValidateGetQueryivBase(Context *context, QueryType target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1778 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1779 | if (numParams) |
| 1780 | { |
| 1781 | *numParams = 0; |
| 1782 | } |
| 1783 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1784 | if (!ValidQueryType(context, target) && target != QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1785 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1786 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidQueryType); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1787 | return false; |
| 1788 | } |
| 1789 | |
| 1790 | switch (pname) |
| 1791 | { |
| 1792 | case GL_CURRENT_QUERY_EXT: |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1793 | if (target == QueryType::Timestamp) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1794 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1795 | context->handleError(InvalidEnum() << "Cannot use current query for timestamp"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1796 | return false; |
| 1797 | } |
| 1798 | break; |
| 1799 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1800 | if (!context->getExtensions().disjointTimerQuery || |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1801 | (target != QueryType::Timestamp && target != QueryType::TimeElapsed)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1802 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1803 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1804 | return false; |
| 1805 | } |
| 1806 | break; |
| 1807 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1808 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidPname); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1809 | return false; |
| 1810 | } |
| 1811 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1812 | if (numParams) |
| 1813 | { |
| 1814 | // All queries return only one value |
| 1815 | *numParams = 1; |
| 1816 | } |
| 1817 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1818 | return true; |
| 1819 | } |
| 1820 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1821 | bool ValidateGetQueryivEXT(Context *context, QueryType target, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1822 | { |
| 1823 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1824 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1825 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1826 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1827 | return false; |
| 1828 | } |
| 1829 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1830 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1831 | } |
| 1832 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1833 | bool ValidateGetQueryivRobustANGLE(Context *context, |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1834 | QueryType target, |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1835 | GLenum pname, |
| 1836 | GLsizei bufSize, |
| 1837 | GLsizei *length, |
| 1838 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1839 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1840 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1841 | { |
| 1842 | return false; |
| 1843 | } |
| 1844 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1845 | GLsizei numParams = 0; |
| 1846 | |
| 1847 | if (!ValidateGetQueryivBase(context, target, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1848 | { |
| 1849 | return false; |
| 1850 | } |
| 1851 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1852 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1853 | { |
| 1854 | return false; |
| 1855 | } |
| 1856 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1857 | SetRobustLengthParam(length, numParams); |
| 1858 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1859 | return true; |
| 1860 | } |
| 1861 | |
| 1862 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 1863 | { |
| 1864 | if (numParams) |
| 1865 | { |
| 1866 | *numParams = 0; |
| 1867 | } |
| 1868 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1869 | Query *queryObject = context->getQuery(id, false, QueryType::InvalidEnum); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1870 | |
| 1871 | if (!queryObject) |
| 1872 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1873 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidQueryId); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1874 | return false; |
| 1875 | } |
| 1876 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1877 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1878 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 1879 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), QueryActive); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1880 | return false; |
| 1881 | } |
| 1882 | |
| 1883 | switch (pname) |
| 1884 | { |
| 1885 | case GL_QUERY_RESULT_EXT: |
| 1886 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 1887 | break; |
| 1888 | |
| 1889 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1890 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1891 | return false; |
| 1892 | } |
| 1893 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1894 | if (numParams) |
| 1895 | { |
| 1896 | *numParams = 1; |
| 1897 | } |
| 1898 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1899 | return true; |
| 1900 | } |
| 1901 | |
| 1902 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 1903 | { |
| 1904 | if (!context->getExtensions().disjointTimerQuery) |
| 1905 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1906 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1907 | return false; |
| 1908 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1909 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1910 | } |
| 1911 | |
| 1912 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 1913 | GLuint id, |
| 1914 | GLenum pname, |
| 1915 | GLsizei bufSize, |
| 1916 | GLsizei *length, |
| 1917 | GLint *params) |
| 1918 | { |
| 1919 | if (!context->getExtensions().disjointTimerQuery) |
| 1920 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 1921 | context->handleError(InvalidOperation() << "Timer query extension not enabled"); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1922 | return false; |
| 1923 | } |
| 1924 | |
| 1925 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1926 | { |
| 1927 | return false; |
| 1928 | } |
| 1929 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1930 | GLsizei numParams = 0; |
| 1931 | |
| 1932 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1933 | { |
| 1934 | return false; |
| 1935 | } |
| 1936 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1937 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1938 | { |
| 1939 | return false; |
| 1940 | } |
| 1941 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1942 | SetRobustLengthParam(length, numParams); |
| 1943 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1944 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 1948 | { |
| 1949 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 1950 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1951 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1952 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1953 | return false; |
| 1954 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1955 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 1956 | } |
| 1957 | |
| 1958 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 1959 | GLuint id, |
| 1960 | GLenum pname, |
| 1961 | GLsizei bufSize, |
| 1962 | GLsizei *length, |
| 1963 | GLuint *params) |
| 1964 | { |
| 1965 | if (!context->getExtensions().disjointTimerQuery && |
| 1966 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 1967 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1968 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1969 | return false; |
| 1970 | } |
| 1971 | |
| 1972 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 1973 | { |
| 1974 | return false; |
| 1975 | } |
| 1976 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1977 | GLsizei numParams = 0; |
| 1978 | |
| 1979 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1980 | { |
| 1981 | return false; |
| 1982 | } |
| 1983 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1984 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1985 | { |
| 1986 | return false; |
| 1987 | } |
| 1988 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 1989 | SetRobustLengthParam(length, numParams); |
| 1990 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1991 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 1995 | { |
| 1996 | if (!context->getExtensions().disjointTimerQuery) |
| 1997 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 1998 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1999 | return false; |
| 2000 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2001 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2002 | } |
| 2003 | |
| 2004 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 2005 | GLuint id, |
| 2006 | GLenum pname, |
| 2007 | GLsizei bufSize, |
| 2008 | GLsizei *length, |
| 2009 | GLint64 *params) |
| 2010 | { |
| 2011 | if (!context->getExtensions().disjointTimerQuery) |
| 2012 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2013 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2014 | return false; |
| 2015 | } |
| 2016 | |
| 2017 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2018 | { |
| 2019 | return false; |
| 2020 | } |
| 2021 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2022 | GLsizei numParams = 0; |
| 2023 | |
| 2024 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2025 | { |
| 2026 | return false; |
| 2027 | } |
| 2028 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2029 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2030 | { |
| 2031 | return false; |
| 2032 | } |
| 2033 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2034 | SetRobustLengthParam(length, numParams); |
| 2035 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2036 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2037 | } |
| 2038 | |
| 2039 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2040 | { |
| 2041 | if (!context->getExtensions().disjointTimerQuery) |
| 2042 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2043 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2044 | return false; |
| 2045 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2046 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2047 | } |
| 2048 | |
| 2049 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2050 | GLuint id, |
| 2051 | GLenum pname, |
| 2052 | GLsizei bufSize, |
| 2053 | GLsizei *length, |
| 2054 | GLuint64 *params) |
| 2055 | { |
| 2056 | if (!context->getExtensions().disjointTimerQuery) |
| 2057 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2058 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2059 | return false; |
| 2060 | } |
| 2061 | |
| 2062 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2063 | { |
| 2064 | return false; |
| 2065 | } |
| 2066 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2067 | GLsizei numParams = 0; |
| 2068 | |
| 2069 | if (!ValidateGetQueryObjectValueBase(context, id, pname, &numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2070 | { |
| 2071 | return false; |
| 2072 | } |
| 2073 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2074 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2075 | { |
| 2076 | return false; |
| 2077 | } |
| 2078 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2079 | SetRobustLengthParam(length, numParams); |
| 2080 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2081 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2082 | } |
| 2083 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2084 | bool ValidateUniformCommonBase(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2085 | gl::Program *program, |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2086 | GLint location, |
| 2087 | GLsizei count, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2088 | const LinkedUniform **uniformOut) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2089 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2090 | // TODO(Jiajia): Add image uniform check in future. |
| 2091 | if (count < 0) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2092 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2093 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2094 | return false; |
| 2095 | } |
| 2096 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2097 | if (!program) |
| 2098 | { |
| 2099 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidProgramName); |
| 2100 | return false; |
| 2101 | } |
| 2102 | |
| 2103 | if (!program->isLinked()) |
| 2104 | { |
| 2105 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | if (location == -1) |
| 2110 | { |
| 2111 | // Silently ignore the uniform command |
| 2112 | return false; |
| 2113 | } |
| 2114 | |
| 2115 | const auto &uniformLocations = program->getUniformLocations(); |
| 2116 | size_t castedLocation = static_cast<size_t>(location); |
| 2117 | if (castedLocation >= uniformLocations.size()) |
| 2118 | { |
| 2119 | context->handleError(InvalidOperation() << "Invalid uniform location"); |
| 2120 | return false; |
| 2121 | } |
| 2122 | |
| 2123 | const auto &uniformLocation = uniformLocations[castedLocation]; |
| 2124 | if (uniformLocation.ignored) |
| 2125 | { |
| 2126 | // Silently ignore the uniform command |
| 2127 | return false; |
| 2128 | } |
| 2129 | |
| 2130 | if (!uniformLocation.used()) |
| 2131 | { |
| 2132 | context->handleError(InvalidOperation()); |
| 2133 | return false; |
| 2134 | } |
| 2135 | |
| 2136 | const auto &uniform = program->getUniformByIndex(uniformLocation.index); |
| 2137 | |
| 2138 | // 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] | 2139 | if (count > 1 && !uniform.isArray()) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2140 | { |
| 2141 | context->handleError(InvalidOperation()); |
| 2142 | return false; |
| 2143 | } |
| 2144 | |
| 2145 | *uniformOut = &uniform; |
| 2146 | return true; |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2147 | } |
| 2148 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2149 | bool ValidateUniform1ivValue(Context *context, |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2150 | GLenum uniformType, |
| 2151 | GLsizei count, |
| 2152 | const GLint *value) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2153 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2154 | // Value type is GL_INT, because we only get here from glUniform1i{v}. |
| 2155 | // It is compatible with INT or BOOL. |
| 2156 | // Do these cheap tests first, for a little extra speed. |
| 2157 | if (GL_INT == uniformType || GL_BOOL == uniformType) |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2158 | { |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2159 | return true; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2160 | } |
| 2161 | |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2162 | if (IsSamplerType(uniformType)) |
| 2163 | { |
| 2164 | // Check that the values are in range. |
| 2165 | const GLint max = context->getCaps().maxCombinedTextureImageUnits; |
| 2166 | for (GLsizei i = 0; i < count; ++i) |
| 2167 | { |
| 2168 | if (value[i] < 0 || value[i] >= max) |
| 2169 | { |
| 2170 | context->handleError(InvalidValue() << "sampler uniform value out of range"); |
| 2171 | return false; |
| 2172 | } |
| 2173 | } |
| 2174 | return true; |
| 2175 | } |
| 2176 | |
| 2177 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2178 | return false; |
| 2179 | } |
| 2180 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2181 | bool ValidateUniformValue(Context *context, GLenum valueType, GLenum uniformType) |
Jiajia Qin | 5451d53 | 2017-11-16 17:16:34 +0800 | [diff] [blame] | 2182 | { |
| 2183 | // Check that the value type is compatible with uniform type. |
| 2184 | // Do the cheaper test first, for a little extra speed. |
| 2185 | if (valueType == uniformType || VariableBoolVectorType(valueType) == uniformType) |
| 2186 | { |
| 2187 | return true; |
| 2188 | } |
| 2189 | |
| 2190 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), UniformSizeMismatch); |
| 2191 | return false; |
| 2192 | } |
| 2193 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2194 | bool ValidateUniformMatrixValue(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 | if (valueType == uniformType) |
| 2198 | { |
| 2199 | return true; |
| 2200 | } |
| 2201 | |
| 2202 | context->handleError(InvalidOperation() << "wrong type of value for uniform"); |
| 2203 | return false; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2204 | } |
| 2205 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2206 | bool ValidateUniform(Context *context, GLenum valueType, GLint location, GLsizei count) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2207 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2208 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2209 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2210 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2211 | ValidateUniformValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2212 | } |
| 2213 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2214 | bool ValidateUniform1iv(Context *context, GLint location, GLsizei count, const GLint *value) |
Frank Henigman | a98a647 | 2017-02-02 21:38:32 -0500 | [diff] [blame] | 2215 | { |
| 2216 | const LinkedUniform *uniform = nullptr; |
| 2217 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2218 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2219 | ValidateUniform1ivValue(context, uniform->type, count, value); |
| 2220 | } |
| 2221 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2222 | bool ValidateUniformMatrix(Context *context, |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2223 | GLenum valueType, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2224 | GLint location, |
| 2225 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2226 | GLboolean transpose) |
| 2227 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 2228 | if (ConvertToBool(transpose) && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2229 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2230 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2231 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2232 | } |
| 2233 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2234 | const LinkedUniform *uniform = nullptr; |
Frank Henigman | f5f74ae | 2017-02-02 21:14:23 -0500 | [diff] [blame] | 2235 | gl::Program *programObject = context->getGLState().getProgram(); |
| 2236 | return ValidateUniformCommonBase(context, programObject, location, count, &uniform) && |
| 2237 | ValidateUniformMatrixValue(context, valueType, uniform->type); |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2238 | } |
| 2239 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2240 | bool ValidateStateQuery(Context *context, GLenum pname, GLenum *nativeType, unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2241 | { |
| 2242 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2243 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2244 | context->handleError(InvalidEnum()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2245 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2246 | } |
| 2247 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2248 | const Caps &caps = context->getCaps(); |
| 2249 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2250 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2251 | { |
| 2252 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2253 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2254 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2255 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2256 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2257 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | switch (pname) |
| 2262 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2263 | case GL_TEXTURE_BINDING_2D: |
| 2264 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2265 | case GL_TEXTURE_BINDING_3D: |
| 2266 | case GL_TEXTURE_BINDING_2D_ARRAY: |
JiangYizhou | 24fe74c | 2017-07-06 16:56:50 +0800 | [diff] [blame] | 2267 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2268 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2269 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2270 | if (!context->getExtensions().textureRectangle) |
| 2271 | { |
| 2272 | context->handleError(InvalidEnum() |
| 2273 | << "ANGLE_texture_rectangle extension not present"); |
| 2274 | return false; |
| 2275 | } |
| 2276 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2277 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2278 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2279 | !context->getExtensions().eglImageExternal) |
| 2280 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2281 | context->handleError(InvalidEnum() << "Neither NV_EGL_stream_consumer_external " |
| 2282 | "nor GL_OES_EGL_image_external " |
| 2283 | "extensions enabled"); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2284 | return false; |
| 2285 | } |
| 2286 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2287 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2288 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2289 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2290 | { |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2291 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
| 2292 | ASSERT(readFramebuffer); |
| 2293 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2294 | if (!ValidateFramebufferComplete<InvalidOperation>(context, readFramebuffer)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2295 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2296 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2297 | } |
| 2298 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2299 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2300 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2301 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2302 | return false; |
| 2303 | } |
| 2304 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2305 | const FramebufferAttachment *attachment = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2306 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2307 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2308 | context->handleError(InvalidOperation()); |
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 | } |
| 2312 | break; |
| 2313 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2314 | default: |
| 2315 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2316 | } |
| 2317 | |
| 2318 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2319 | if (*numParams == 0) |
| 2320 | { |
| 2321 | return false; |
| 2322 | } |
| 2323 | |
| 2324 | return true; |
| 2325 | } |
| 2326 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 2327 | bool ValidateGetBooleanvRobustANGLE(Context *context, |
| 2328 | GLenum pname, |
| 2329 | GLsizei bufSize, |
| 2330 | GLsizei *length, |
| 2331 | GLboolean *params) |
| 2332 | { |
| 2333 | GLenum nativeType; |
| 2334 | unsigned int numParams = 0; |
| 2335 | |
| 2336 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2337 | { |
| 2338 | return false; |
| 2339 | } |
| 2340 | |
| 2341 | SetRobustLengthParam(length, numParams); |
| 2342 | |
| 2343 | return true; |
| 2344 | } |
| 2345 | |
| 2346 | bool ValidateGetFloatvRobustANGLE(Context *context, |
| 2347 | GLenum pname, |
| 2348 | GLsizei bufSize, |
| 2349 | GLsizei *length, |
| 2350 | GLfloat *params) |
| 2351 | { |
| 2352 | GLenum nativeType; |
| 2353 | unsigned int numParams = 0; |
| 2354 | |
| 2355 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2356 | { |
| 2357 | return false; |
| 2358 | } |
| 2359 | |
| 2360 | SetRobustLengthParam(length, numParams); |
| 2361 | |
| 2362 | return true; |
| 2363 | } |
| 2364 | |
| 2365 | bool ValidateGetIntegervRobustANGLE(Context *context, |
| 2366 | GLenum pname, |
| 2367 | GLsizei bufSize, |
| 2368 | GLsizei *length, |
| 2369 | GLint *data) |
| 2370 | { |
| 2371 | GLenum nativeType; |
| 2372 | unsigned int numParams = 0; |
| 2373 | |
| 2374 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2375 | { |
| 2376 | return false; |
| 2377 | } |
| 2378 | |
| 2379 | SetRobustLengthParam(length, numParams); |
| 2380 | |
| 2381 | return true; |
| 2382 | } |
| 2383 | |
| 2384 | bool ValidateGetInteger64vRobustANGLE(Context *context, |
| 2385 | GLenum pname, |
| 2386 | GLsizei bufSize, |
| 2387 | GLsizei *length, |
| 2388 | GLint64 *data) |
| 2389 | { |
| 2390 | GLenum nativeType; |
| 2391 | unsigned int numParams = 0; |
| 2392 | |
| 2393 | if (!ValidateRobustStateQuery(context, pname, bufSize, &nativeType, &numParams)) |
| 2394 | { |
| 2395 | return false; |
| 2396 | } |
| 2397 | |
| 2398 | if (nativeType == GL_INT_64_ANGLEX) |
| 2399 | { |
| 2400 | CastStateValues(context, nativeType, pname, numParams, data); |
| 2401 | return false; |
| 2402 | } |
| 2403 | |
| 2404 | SetRobustLengthParam(length, numParams); |
| 2405 | return true; |
| 2406 | } |
| 2407 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2408 | bool ValidateRobustStateQuery(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2409 | GLenum pname, |
| 2410 | GLsizei bufSize, |
| 2411 | GLenum *nativeType, |
| 2412 | unsigned int *numParams) |
| 2413 | { |
| 2414 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2415 | { |
| 2416 | return false; |
| 2417 | } |
| 2418 | |
| 2419 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2420 | { |
| 2421 | return false; |
| 2422 | } |
| 2423 | |
| 2424 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2425 | { |
| 2426 | return false; |
| 2427 | } |
| 2428 | |
| 2429 | return true; |
| 2430 | } |
| 2431 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2432 | bool ValidateCopyTexImageParametersBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2433 | TextureTarget target, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2434 | GLint level, |
| 2435 | GLenum internalformat, |
| 2436 | bool isSubImage, |
| 2437 | GLint xoffset, |
| 2438 | GLint yoffset, |
| 2439 | GLint zoffset, |
| 2440 | GLint x, |
| 2441 | GLint y, |
| 2442 | GLsizei width, |
| 2443 | GLsizei height, |
| 2444 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2445 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2446 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2447 | TextureType texType = TextureTargetToType(target); |
| 2448 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2449 | if (xoffset < 0 || yoffset < 0 || zoffset < 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2450 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2451 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 2452 | return false; |
| 2453 | } |
| 2454 | |
| 2455 | if (width < 0 || height < 0) |
| 2456 | { |
| 2457 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2458 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2459 | } |
| 2460 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2461 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2462 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2463 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2464 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2465 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2466 | } |
| 2467 | |
| 2468 | if (border != 0) |
| 2469 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2470 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidBorder); |
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 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2474 | if (!ValidMipLevel(context, texType, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2475 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2476 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2477 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2478 | } |
| 2479 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2480 | const gl::State &state = context->getGLState(); |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 2481 | Framebuffer *readFramebuffer = state.getReadFramebuffer(); |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2482 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2483 | { |
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 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2487 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2488 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2489 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2492 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 2493 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2494 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2495 | return false; |
| 2496 | } |
| 2497 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2498 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 2499 | // 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] | 2500 | // 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] | 2501 | // 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] | 2502 | const FramebufferAttachment *source = readFramebuffer->getReadColorbuffer(); |
| 2503 | if (source == nullptr) |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2504 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2505 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 2506 | return false; |
| 2507 | } |
| 2508 | |
Martin Radev | 04e2c3b | 2017-07-27 16:54:35 +0300 | [diff] [blame] | 2509 | // ANGLE_multiview spec, Revision 1: |
| 2510 | // Calling CopyTexSubImage3D, CopyTexImage2D, or CopyTexSubImage2D will result in an |
| 2511 | // INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the current read framebuffer |
| 2512 | // is not NONE. |
| 2513 | if (source->getMultiviewLayout() != GL_NONE) |
| 2514 | { |
| 2515 | context->handleError(InvalidFramebufferOperation() |
| 2516 | << "The active read framebuffer object has multiview attachments."); |
| 2517 | return false; |
| 2518 | } |
| 2519 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2520 | const gl::Caps &caps = context->getCaps(); |
| 2521 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 2522 | GLuint maxDimension = 0; |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2523 | switch (texType) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2524 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2525 | case TextureType::_2D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2526 | maxDimension = caps.max2DTextureSize; |
| 2527 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2528 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2529 | case TextureType::CubeMap: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2530 | maxDimension = caps.maxCubeMapTextureSize; |
| 2531 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2532 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2533 | case TextureType::Rectangle: |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2534 | maxDimension = caps.maxRectangleTextureSize; |
| 2535 | break; |
| 2536 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2537 | case TextureType::_2DArray: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2538 | maxDimension = caps.max2DTextureSize; |
| 2539 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2540 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2541 | case TextureType::_3D: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2542 | maxDimension = caps.max3DTextureSize; |
| 2543 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2544 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2545 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2546 | context->handleError(InvalidEnum()); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2547 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2548 | } |
| 2549 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2550 | gl::Texture *texture = state.getTargetTexture(texType); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2551 | if (!texture) |
| 2552 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2553 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TextureNotBound); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2554 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2555 | } |
| 2556 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 2557 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2558 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2559 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2560 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2561 | } |
| 2562 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2563 | const gl::InternalFormat &formatInfo = |
Geoff Lang | 86f8116 | 2017-10-30 15:10:45 -0400 | [diff] [blame] | 2564 | isSubImage ? *texture->getFormat(target, level).info |
| 2565 | : gl::GetInternalFormatInfo(internalformat, GL_UNSIGNED_BYTE); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2566 | |
Geoff Lang | 966c940 | 2017-04-18 12:38:27 -0400 | [diff] [blame] | 2567 | if (formatInfo.depthBits > 0 || formatInfo.compressed) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2568 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2569 | context->handleError(InvalidOperation()); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2570 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2571 | } |
| 2572 | |
| 2573 | if (isSubImage) |
| 2574 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 2575 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 2576 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 2577 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2578 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 2579 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2580 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2581 | } |
| 2582 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2583 | else |
| 2584 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 2585 | if (texType == TextureType::CubeMap && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2586 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2587 | ANGLE_VALIDATION_ERR(context, InvalidValue(), CubemapIncomplete); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2588 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2589 | } |
| 2590 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2591 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2592 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2593 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2594 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2595 | } |
| 2596 | |
| 2597 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2598 | if (static_cast<int>(width) > maxLevelDimension || |
| 2599 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2600 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2601 | ANGLE_VALIDATION_ERR(context, InvalidValue(), ResourceMaxTextureSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2602 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 2603 | } |
| 2604 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2605 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2606 | if (textureFormatOut) |
| 2607 | { |
| 2608 | *textureFormatOut = texture->getFormat(target, level); |
| 2609 | } |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2610 | |
| 2611 | // Detect texture copying feedback loops for WebGL. |
| 2612 | if (context->getExtensions().webglCompatibility) |
| 2613 | { |
Jamie Madill | fd3dd43 | 2017-02-02 19:59:59 -0500 | [diff] [blame] | 2614 | if (readFramebuffer->formsCopyingFeedbackLoopWith(texture->id(), level, zoffset)) |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2615 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 2616 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
Jamie Madill | f695a3a | 2017-01-11 17:36:35 -0500 | [diff] [blame] | 2617 | return false; |
| 2618 | } |
| 2619 | } |
| 2620 | |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2621 | return true; |
| 2622 | } |
| 2623 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2624 | bool ValidateDrawBase(Context *context, PrimitiveMode mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2625 | { |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2626 | const Extensions &extensions = context->getExtensions(); |
| 2627 | |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2628 | switch (mode) |
| 2629 | { |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2630 | case PrimitiveMode::Points: |
| 2631 | case PrimitiveMode::Lines: |
| 2632 | case PrimitiveMode::LineLoop: |
| 2633 | case PrimitiveMode::LineStrip: |
| 2634 | case PrimitiveMode::Triangles: |
| 2635 | case PrimitiveMode::TriangleStrip: |
| 2636 | case PrimitiveMode::TriangleFan: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2637 | break; |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2638 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2639 | case PrimitiveMode::LinesAdjacency: |
| 2640 | case PrimitiveMode::LineStripAdjacency: |
| 2641 | case PrimitiveMode::TrianglesAdjacency: |
| 2642 | case PrimitiveMode::TriangleStripAdjacency: |
Jiawei Shao | fccebff | 2018-03-08 13:51:02 +0800 | [diff] [blame] | 2643 | if (!extensions.geometryShader) |
| 2644 | { |
| 2645 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 2646 | return false; |
| 2647 | } |
| 2648 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2649 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2650 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidDrawMode); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2651 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 2652 | } |
| 2653 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2654 | if (count < 0) |
| 2655 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2656 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2657 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2658 | } |
| 2659 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2660 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2661 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2662 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 2663 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 2664 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 2665 | if (!extensions.webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2666 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2667 | // Check for mapped buffers |
| 2668 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2669 | if (state.hasMappedBuffer(BufferBinding::Array)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 2670 | { |
| 2671 | context->handleError(InvalidOperation()); |
| 2672 | return false; |
| 2673 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2674 | } |
| 2675 | |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2676 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 2677 | // Section 6.10 of the WebGL 1.0 spec. |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2678 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2679 | if (context->getLimitations().noSeparateStencilRefsAndMasks || extensions.webglCompatibility) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2680 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2681 | ASSERT(framebuffer); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 2682 | const FramebufferAttachment *dsAttachment = |
| 2683 | framebuffer->getStencilOrDepthStencilAttachment(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2684 | const GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
| 2685 | ASSERT(stencilBits <= 8); |
| 2686 | |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 2687 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2688 | if (depthStencilState.stencilTest && stencilBits > 0) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2689 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2690 | GLuint maxStencilValue = (1 << stencilBits) - 1; |
| 2691 | |
| 2692 | bool differentRefs = |
| 2693 | clamp(state.getStencilRef(), 0, static_cast<GLint>(maxStencilValue)) != |
| 2694 | clamp(state.getStencilBackRef(), 0, static_cast<GLint>(maxStencilValue)); |
| 2695 | bool differentWritemasks = (depthStencilState.stencilWritemask & maxStencilValue) != |
| 2696 | (depthStencilState.stencilBackWritemask & maxStencilValue); |
| 2697 | bool differentMasks = (depthStencilState.stencilMask & maxStencilValue) != |
| 2698 | (depthStencilState.stencilBackMask & maxStencilValue); |
| 2699 | |
| 2700 | if (differentRefs || differentWritemasks || differentMasks) |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2701 | { |
Ken Russell | b9f9250 | 2018-01-27 19:00:26 -0800 | [diff] [blame] | 2702 | if (!extensions.webglCompatibility) |
| 2703 | { |
| 2704 | ERR() << "This ANGLE implementation does not support separate front/back " |
| 2705 | "stencil writemasks, reference values, or stencil mask values."; |
| 2706 | } |
| 2707 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), StencilReferenceMaskOrMismatch); |
| 2708 | return false; |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 2709 | } |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 2710 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 2711 | } |
| 2712 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2713 | if (!ValidateFramebufferComplete(context, framebuffer)) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2714 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2715 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 2716 | } |
| 2717 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2718 | // If we are running GLES1, there is no current program. |
| 2719 | if (context->getClientVersion() >= Version(2, 0)) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2720 | { |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 2721 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2722 | gl::Program *program = state.getProgram(); |
| 2723 | if (!program) |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2724 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2725 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotBound); |
Martin Radev | 7cf6166 | 2017-07-26 17:10:53 +0300 | [diff] [blame] | 2726 | return false; |
| 2727 | } |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2728 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2729 | // In OpenGL ES spec for UseProgram at section 7.3, trying to render without |
| 2730 | // vertex shader stage or fragment shader stage is a undefined behaviour. |
| 2731 | // But ANGLE should clearly generate an INVALID_OPERATION error instead of |
| 2732 | // produce undefined result. |
| 2733 | if (!program->hasLinkedShaderStage(ShaderType::Vertex) || |
| 2734 | !program->hasLinkedShaderStage(ShaderType::Fragment)) |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2735 | { |
| 2736 | context->handleError(InvalidOperation() |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2737 | << "It is a undefined behaviour to render without " |
| 2738 | "vertex shader stage or fragment shader stage."); |
Martin Radev | 7e69f76 | 2017-07-27 14:54:13 +0300 | [diff] [blame] | 2739 | return false; |
| 2740 | } |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2741 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2742 | if (!program->validateSamplers(nullptr, context->getCaps())) |
Martin Radev | ffe754b | 2017-07-31 10:38:07 +0300 | [diff] [blame] | 2743 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2744 | context->handleError(InvalidOperation()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2745 | return false; |
| 2746 | } |
| 2747 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2748 | if (extensions.multiview) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2749 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2750 | const int programNumViews = program->usesMultiview() ? program->getNumViews() : 1; |
| 2751 | const int framebufferNumViews = framebuffer->getNumViews(); |
| 2752 | if (framebufferNumViews != programNumViews) |
| 2753 | { |
| 2754 | context->handleError(InvalidOperation() |
| 2755 | << "The number of views in the active program " |
| 2756 | "and draw framebuffer does not match."); |
| 2757 | return false; |
| 2758 | } |
| 2759 | |
| 2760 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2761 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2762 | framebufferNumViews > 1) |
| 2763 | { |
| 2764 | context->handleError(InvalidOperation() |
| 2765 | << "There is an active transform feedback object " |
| 2766 | "when the number of views in the active draw " |
| 2767 | "framebuffer is greater than 1."); |
| 2768 | return false; |
| 2769 | } |
| 2770 | |
| 2771 | if (extensions.disjointTimerQuery && framebufferNumViews > 1 && |
| 2772 | state.isQueryActive(QueryType::TimeElapsed)) |
| 2773 | { |
| 2774 | context->handleError(InvalidOperation() |
| 2775 | << "There is an active query for target " |
| 2776 | "GL_TIME_ELAPSED_EXT when the number of " |
| 2777 | "views in the active draw framebuffer is " |
| 2778 | "greater than 1."); |
| 2779 | return false; |
| 2780 | } |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 2781 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2782 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2783 | // Do geometry shader specific validations |
| 2784 | if (program->hasLinkedShaderStage(ShaderType::Geometry)) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 2785 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2786 | if (!IsCompatibleDrawModeWithGeometryShader( |
| 2787 | mode, program->getGeometryShaderInputPrimitiveType())) |
| 2788 | { |
| 2789 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2790 | IncompatibleDrawModeAgainstGeometryShader); |
| 2791 | return false; |
| 2792 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2793 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2794 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2795 | // Uniform buffer validation |
| 2796 | for (unsigned int uniformBlockIndex = 0; |
| 2797 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2798 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2799 | const gl::InterfaceBlock &uniformBlock = |
| 2800 | program->getUniformBlockByIndex(uniformBlockIndex); |
| 2801 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
| 2802 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 2803 | state.getIndexedUniformBuffer(blockBinding); |
| 2804 | |
| 2805 | if (uniformBuffer.get() == nullptr) |
| 2806 | { |
| 2807 | // undefined behaviour |
| 2808 | context->handleError( |
| 2809 | InvalidOperation() |
| 2810 | << "It is undefined behaviour to have a used but unbound uniform buffer."); |
| 2811 | return false; |
| 2812 | } |
| 2813 | |
| 2814 | size_t uniformBufferSize = GetBoundBufferAvailableSize(uniformBuffer); |
| 2815 | if (uniformBufferSize < uniformBlock.dataSize) |
| 2816 | { |
| 2817 | // undefined behaviour |
| 2818 | context->handleError( |
| 2819 | InvalidOperation() |
| 2820 | << "It is undefined behaviour to use a uniform buffer that is too small."); |
| 2821 | return false; |
| 2822 | } |
| 2823 | |
| 2824 | if (extensions.webglCompatibility && |
| 2825 | uniformBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 2826 | { |
| 2827 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2828 | UniformBufferBoundForTransformFeedback); |
| 2829 | return false; |
| 2830 | } |
Geoff Lang | 9ab5b82 | 2017-05-30 16:19:23 -0400 | [diff] [blame] | 2831 | } |
| 2832 | |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2833 | // Do some additonal WebGL-specific validation |
| 2834 | if (extensions.webglCompatibility) |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2835 | { |
Lingfeng Yang | 461b09a | 2018-04-23 09:02:09 -0700 | [diff] [blame] | 2836 | const TransformFeedback *transformFeedbackObject = state.getCurrentTransformFeedback(); |
| 2837 | if (transformFeedbackObject != nullptr && transformFeedbackObject->isActive() && |
| 2838 | transformFeedbackObject->buffersBoundForOtherUse()) |
| 2839 | { |
| 2840 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2841 | TransformFeedbackBufferDoubleBound); |
| 2842 | return false; |
| 2843 | } |
| 2844 | // Detect rendering feedback loops for WebGL. |
| 2845 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 2846 | { |
| 2847 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), FeedbackLoop); |
| 2848 | return false; |
| 2849 | } |
| 2850 | |
| 2851 | // Detect that the vertex shader input types match the attribute types |
| 2852 | if (!ValidateVertexShaderAttributeTypeMatch(context)) |
| 2853 | { |
| 2854 | return false; |
| 2855 | } |
| 2856 | |
| 2857 | // Detect that the color buffer types match the fragment shader output types |
| 2858 | if (!ValidateFragmentShaderColorBufferTypeMatch(context)) |
| 2859 | { |
| 2860 | return false; |
| 2861 | } |
Geoff Lang | e0cff19 | 2017-05-30 13:04:56 -0400 | [diff] [blame] | 2862 | } |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 2863 | } |
| 2864 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2865 | return true; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2866 | } |
| 2867 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2868 | bool ValidateDrawArraysCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2869 | PrimitiveMode mode, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 2870 | GLint first, |
| 2871 | GLsizei count, |
| 2872 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2873 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2874 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2875 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2876 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeStart); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2877 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2878 | } |
| 2879 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2880 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2881 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2882 | if (curTransformFeedback && curTransformFeedback->isActive() && |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2883 | !curTransformFeedback->isPaused()) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2884 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2885 | if (!ValidateTransformFeedbackPrimitiveMode(context, |
| 2886 | curTransformFeedback->getPrimitiveMode(), mode)) |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2887 | { |
James Darpinian | 30b604d | 2018-03-12 17:26:57 -0700 | [diff] [blame] | 2888 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2889 | return false; |
| 2890 | } |
| 2891 | |
| 2892 | if (!curTransformFeedback->checkBufferSpaceForDraw(count, primcount)) |
| 2893 | { |
| 2894 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), TransformFeedbackBufferTooSmall); |
| 2895 | return false; |
| 2896 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2897 | } |
| 2898 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2899 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 2900 | { |
| 2901 | return false; |
| 2902 | } |
| 2903 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2904 | // Check the computation of maxVertex doesn't overflow. |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2905 | // - first < 0 has been checked as an error condition. |
| 2906 | // - if count < 0, skip validating no-op draw calls. |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 2907 | // 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] | 2908 | ASSERT(first >= 0); |
| 2909 | if (count > 0) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2910 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2911 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 2912 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
| 2913 | { |
| 2914 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 2915 | return false; |
| 2916 | } |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 2917 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 2918 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex), count)) |
| 2919 | { |
| 2920 | return false; |
| 2921 | } |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2922 | } |
| 2923 | |
| 2924 | return true; |
| 2925 | } |
| 2926 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2927 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2928 | PrimitiveMode mode, |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2929 | GLint first, |
| 2930 | GLsizei count, |
| 2931 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2932 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 2933 | if (!context->getExtensions().instancedArrays) |
| 2934 | { |
| 2935 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 2936 | return false; |
| 2937 | } |
| 2938 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 2939 | if (!ValidateDrawArraysInstancedBase(context, mode, first, count, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2940 | { |
| 2941 | return false; |
| 2942 | } |
| 2943 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 2944 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 2945 | } |
| 2946 | |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2947 | bool ValidateDrawElementsBase(Context *context, PrimitiveMode mode, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 2948 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2949 | switch (type) |
| 2950 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2951 | case GL_UNSIGNED_BYTE: |
| 2952 | case GL_UNSIGNED_SHORT: |
| 2953 | break; |
| 2954 | case GL_UNSIGNED_INT: |
| 2955 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 2956 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2957 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2958 | return false; |
| 2959 | } |
| 2960 | break; |
| 2961 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 2962 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TypeNotUnsignedShortByte); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2963 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2964 | } |
| 2965 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2966 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2967 | |
| 2968 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2969 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 2970 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2971 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 2972 | // EXT_geometry_shader allows transform feedback to work with all draw commands. |
| 2973 | // [EXT_geometry_shader] Section 12.1, "Transform Feedback" |
| 2974 | if (context->getExtensions().geometryShader) |
| 2975 | { |
| 2976 | if (!ValidateTransformFeedbackPrimitiveMode( |
| 2977 | context, curTransformFeedback->getPrimitiveMode(), mode)) |
| 2978 | { |
| 2979 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidDrawModeTransformFeedback); |
| 2980 | return false; |
| 2981 | } |
| 2982 | } |
| 2983 | else |
| 2984 | { |
| 2985 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 2986 | // DrawElementsInstanced while transform feedback is active, (3.0.2, section 2.14, pg |
| 2987 | // 86) |
| 2988 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 2989 | UnsupportedDrawModeForTransformFeedback); |
| 2990 | return false; |
| 2991 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 2992 | } |
| 2993 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 2994 | return true; |
| 2995 | } |
| 2996 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 2997 | bool ValidateDrawElementsCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 2998 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 2999 | GLsizei count, |
| 3000 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3001 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3002 | GLsizei primcount) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3003 | { |
Jiawei Shao | 80c32cc | 2018-04-25 09:48:36 +0800 | [diff] [blame] | 3004 | if (!ValidateDrawElementsBase(context, mode, type)) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3005 | return false; |
| 3006 | |
| 3007 | const State &state = context->getGLState(); |
| 3008 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3009 | if (!ValidateDrawBase(context, mode, count)) |
| 3010 | { |
| 3011 | return false; |
| 3012 | } |
| 3013 | |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3014 | // WebGL buffers cannot be mapped/unmapped because the MapBufferRange, FlushMappedBufferRange, |
| 3015 | // and UnmapBuffer entry points are removed from the WebGL 2.0 API. |
| 3016 | // https://www.khronos.org/registry/webgl/specs/latest/2.0/#5.14 |
| 3017 | if (!context->getExtensions().webglCompatibility) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3018 | { |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3019 | // Check for mapped buffers |
| 3020 | // TODO(jmadill): Optimize this check for non - WebGL contexts. |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3021 | if (state.hasMappedBuffer(gl::BufferBinding::ElementArray)) |
Jiawei Shao | 3ef06a9 | 2017-11-03 18:41:33 +0800 | [diff] [blame] | 3022 | { |
| 3023 | context->handleError(InvalidOperation() << "Index buffer is mapped."); |
| 3024 | return false; |
| 3025 | } |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3026 | } |
| 3027 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3028 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 3029 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3030 | |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3031 | GLuint typeBytes = gl::GetTypeInfo(type).bytes; |
| 3032 | |
| 3033 | if (context->getExtensions().webglCompatibility) |
| 3034 | { |
| 3035 | ASSERT(isPow2(typeBytes) && typeBytes > 0); |
| 3036 | if ((reinterpret_cast<uintptr_t>(indices) & static_cast<uintptr_t>(typeBytes - 1)) != 0) |
| 3037 | { |
| 3038 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3039 | // The offset arguments to drawElements and [...], must be a multiple of the size of the |
| 3040 | // 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] | 3041 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), OffsetMustBeMultipleOfType); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3042 | return false; |
| 3043 | } |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3044 | |
| 3045 | // [WebGL 1.0] Section 6.4 Buffer Offset and Stride Requirements |
| 3046 | // In addition the offset argument to drawElements must be non-negative or an INVALID_VALUE |
| 3047 | // error is generated. |
| 3048 | if (reinterpret_cast<intptr_t>(indices) < 0) |
| 3049 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3050 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
Corentin Wallez | fe9306a | 2017-02-01 17:41:05 -0500 | [diff] [blame] | 3051 | return false; |
| 3052 | } |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 3053 | } |
| 3054 | |
| 3055 | if (context->getExtensions().webglCompatibility || |
| 3056 | !context->getGLState().areClientArraysEnabled()) |
| 3057 | { |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3058 | if (!elementArrayBuffer) |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3059 | { |
| 3060 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
Brandon Jones | 2a01815 | 2018-06-08 15:59:26 -0700 | [diff] [blame] | 3061 | // If an indexed draw command (drawElements) is called and no WebGLBuffer is bound to |
| 3062 | // the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3063 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MustHaveElementArrayBinding); |
Corentin Wallez | 3f6d4df | 2017-01-30 18:04:36 -0500 | [diff] [blame] | 3064 | return false; |
| 3065 | } |
| 3066 | } |
| 3067 | |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3068 | if (count > 0 && !elementArrayBuffer && !indices) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3069 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3070 | // This is an application error that would normally result in a crash, but we catch it and |
| 3071 | // return an error |
| 3072 | context->handleError(InvalidOperation() << "No element array buffer and no pointer."); |
| 3073 | return false; |
| 3074 | } |
| 3075 | |
| 3076 | if (count > 0 && elementArrayBuffer) |
| 3077 | { |
| 3078 | // The max possible type size is 8 and count is on 32 bits so doing the multiplication |
| 3079 | // in a 64 bit integer is safe. Also we are guaranteed that here count > 0. |
| 3080 | static_assert(std::is_same<int, GLsizei>::value, "GLsizei isn't the expected type"); |
| 3081 | constexpr uint64_t kMaxTypeSize = 8; |
| 3082 | constexpr uint64_t kIntMax = std::numeric_limits<int>::max(); |
| 3083 | constexpr uint64_t kUint64Max = std::numeric_limits<uint64_t>::max(); |
| 3084 | static_assert(kIntMax < kUint64Max / kMaxTypeSize, ""); |
| 3085 | |
| 3086 | uint64_t typeSize = typeBytes; |
| 3087 | uint64_t elementCount = static_cast<uint64_t>(count); |
| 3088 | ASSERT(elementCount > 0 && typeSize <= kMaxTypeSize); |
| 3089 | |
| 3090 | // Doing the multiplication here is overflow-safe |
| 3091 | uint64_t elementDataSizeNoOffset = typeSize * elementCount; |
| 3092 | |
| 3093 | // The offset can be any value, check for overflows |
| 3094 | uint64_t offset = static_cast<uint64_t>(reinterpret_cast<uintptr_t>(indices)); |
| 3095 | if (elementDataSizeNoOffset > kUint64Max - offset) |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3096 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3097 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 3098 | return false; |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3099 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3100 | |
| 3101 | uint64_t elementDataSizeWithOffset = elementDataSizeNoOffset + offset; |
| 3102 | if (elementDataSizeWithOffset > static_cast<uint64_t>(elementArrayBuffer->getSize())) |
Corentin Wallez | 0844f2d | 2017-01-31 17:02:59 -0500 | [diff] [blame] | 3103 | { |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3104 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 3105 | return false; |
| 3106 | } |
| 3107 | |
| 3108 | ASSERT(isPow2(typeSize) && typeSize > 0); |
| 3109 | if ((elementArrayBuffer->getSize() & (typeSize - 1)) != 0) |
| 3110 | { |
| 3111 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedByteCountType); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3112 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3113 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 3114 | |
| 3115 | if (context->getExtensions().webglCompatibility && |
| 3116 | elementArrayBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 3117 | { |
| 3118 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
| 3119 | ElementArrayBufferBoundForTransformFeedback); |
| 3120 | return false; |
| 3121 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3122 | } |
| 3123 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3124 | if (context->getExtensions().robustBufferAccessBehavior) |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3125 | { |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3126 | // Here we use maxVertex = 0 and vertexCount = 1 to avoid retrieving IndexRange when robust |
| 3127 | // access is enabled. |
| 3128 | if (!ValidateDrawAttribs(context, primcount, 0, 1)) |
| 3129 | { |
| 3130 | return false; |
| 3131 | } |
| 3132 | } |
Jamie Madill | 9fdaa49 | 2018-02-16 10:52:11 -0500 | [diff] [blame] | 3133 | else if (count == 0) |
| 3134 | { |
| 3135 | // ValidateDrawAttribs also does some extra validation that is independent of the vertex |
| 3136 | // count. |
| 3137 | if (!ValidateDrawAttribs(context, 0, 0, 0)) |
| 3138 | { |
| 3139 | return false; |
| 3140 | } |
| 3141 | } |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3142 | else |
| 3143 | { |
| 3144 | // Use the parameter buffer to retrieve and cache the index range. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3145 | const DrawCallParams ¶ms = context->getParams<DrawCallParams>(); |
| 3146 | ANGLE_VALIDATION_TRY(params.ensureIndexRangeResolved(context)); |
| 3147 | const IndexRange &indexRange = params.getIndexRange(); |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3148 | |
| 3149 | // If we use an index greater than our maximum supported index range, return an error. |
| 3150 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3151 | // return an error if possible here. |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3152 | if (static_cast<GLuint64>(indexRange.end) >= context->getCaps().maxElementIndex) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3153 | { |
| 3154 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExceedsMaxElement); |
| 3155 | return false; |
| 3156 | } |
| 3157 | |
Jamie Madill | 6f5444d | 2018-03-14 10:08:11 -0400 | [diff] [blame] | 3158 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRange.end), |
| 3159 | static_cast<GLint>(indexRange.vertexCount()))) |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3160 | { |
| 3161 | return false; |
| 3162 | } |
| 3163 | |
| 3164 | // 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] | 3165 | return (indexRange.vertexIndexCount > 0); |
Corentin Wallez | c1346fb | 2017-08-24 16:11:26 +0000 | [diff] [blame] | 3166 | } |
| 3167 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 3168 | return true; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3169 | } |
| 3170 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3171 | bool ValidateDrawElementsInstancedCommon(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3172 | PrimitiveMode mode, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3173 | GLsizei count, |
| 3174 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3175 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3176 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3177 | { |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3178 | return ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3179 | } |
| 3180 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3181 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
Jamie Madill | 493f957 | 2018-05-24 19:52:15 -0400 | [diff] [blame] | 3182 | PrimitiveMode mode, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3183 | GLsizei count, |
| 3184 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3185 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 3186 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3187 | { |
Geoff Lang | 63c5a59 | 2017-09-27 14:08:16 -0400 | [diff] [blame] | 3188 | if (!context->getExtensions().instancedArrays) |
| 3189 | { |
| 3190 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3191 | return false; |
| 3192 | } |
| 3193 | |
Corentin Wallez | 170efbf | 2017-05-02 13:45:01 -0400 | [diff] [blame] | 3194 | if (!ValidateDrawElementsInstancedBase(context, mode, count, type, indices, primcount)) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3195 | { |
| 3196 | return false; |
| 3197 | } |
| 3198 | |
Corentin Wallez | 0dc9781 | 2017-06-22 14:38:44 -0400 | [diff] [blame] | 3199 | return ValidateDrawInstancedANGLE(context); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3200 | } |
| 3201 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3202 | bool ValidateFramebufferTextureBase(Context *context, |
| 3203 | GLenum target, |
| 3204 | GLenum attachment, |
| 3205 | GLuint texture, |
| 3206 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3207 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 3208 | if (!ValidFramebufferTarget(context, target)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3209 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3210 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3211 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3212 | } |
| 3213 | |
| 3214 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3215 | { |
| 3216 | return false; |
| 3217 | } |
| 3218 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3219 | if (texture != 0) |
| 3220 | { |
| 3221 | gl::Texture *tex = context->getTexture(texture); |
| 3222 | |
Luc Ferron | adcf0ae | 2018-01-24 08:27:37 -0500 | [diff] [blame] | 3223 | if (tex == nullptr) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3224 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3225 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3226 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3227 | } |
| 3228 | |
| 3229 | if (level < 0) |
| 3230 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3231 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3232 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3233 | } |
| 3234 | } |
| 3235 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3236 | const gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3237 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3238 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3239 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3240 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3241 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3242 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3243 | } |
| 3244 | |
| 3245 | return true; |
| 3246 | } |
| 3247 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3248 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3249 | { |
| 3250 | if (program == 0) |
| 3251 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3252 | context->handleError(InvalidValue()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3253 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3254 | } |
| 3255 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3256 | gl::Program *programObject = GetValidProgram(context, program); |
| 3257 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3258 | { |
| 3259 | return false; |
| 3260 | } |
| 3261 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3262 | if (!programObject || !programObject->isLinked()) |
| 3263 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3264 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3265 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3266 | } |
| 3267 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3268 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3269 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3270 | context->handleError(InvalidOperation()); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3271 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3272 | } |
| 3273 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3274 | return true; |
| 3275 | } |
| 3276 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3277 | static bool ValidateSizedGetUniform(Context *context, |
| 3278 | GLuint program, |
| 3279 | GLint location, |
| 3280 | GLsizei bufSize, |
| 3281 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3282 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3283 | if (length) |
| 3284 | { |
| 3285 | *length = 0; |
| 3286 | } |
| 3287 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3288 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3289 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3290 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3291 | } |
| 3292 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3293 | if (bufSize < 0) |
| 3294 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3295 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3296 | return false; |
| 3297 | } |
| 3298 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3299 | gl::Program *programObject = context->getProgram(program); |
| 3300 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3301 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3302 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3303 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3304 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3305 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3306 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3307 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3308 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3309 | } |
| 3310 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3311 | if (length) |
| 3312 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3313 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3314 | } |
| 3315 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3316 | return true; |
| 3317 | } |
| 3318 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3319 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3320 | GLuint program, |
| 3321 | GLint location, |
| 3322 | GLsizei bufSize, |
| 3323 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3324 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3325 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3326 | } |
| 3327 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3328 | bool ValidateGetnUniformfvRobustANGLE(Context *context, |
| 3329 | GLuint program, |
| 3330 | GLint location, |
| 3331 | GLsizei bufSize, |
| 3332 | GLsizei *length, |
| 3333 | GLfloat *params) |
| 3334 | { |
| 3335 | UNIMPLEMENTED(); |
| 3336 | return false; |
| 3337 | } |
| 3338 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3339 | bool ValidateGetnUniformivEXT(Context *context, |
| 3340 | GLuint program, |
| 3341 | GLint location, |
| 3342 | GLsizei bufSize, |
| 3343 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3344 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3345 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3346 | } |
| 3347 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 3348 | bool ValidateGetnUniformivRobustANGLE(Context *context, |
| 3349 | GLuint program, |
| 3350 | GLint location, |
| 3351 | GLsizei bufSize, |
| 3352 | GLsizei *length, |
| 3353 | GLint *params) |
| 3354 | { |
| 3355 | UNIMPLEMENTED(); |
| 3356 | return false; |
| 3357 | } |
| 3358 | |
| 3359 | bool ValidateGetnUniformuivRobustANGLE(Context *context, |
| 3360 | GLuint program, |
| 3361 | GLint location, |
| 3362 | GLsizei bufSize, |
| 3363 | GLsizei *length, |
| 3364 | GLuint *params) |
| 3365 | { |
| 3366 | UNIMPLEMENTED(); |
| 3367 | return false; |
| 3368 | } |
| 3369 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3370 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3371 | GLuint program, |
| 3372 | GLint location, |
| 3373 | GLsizei bufSize, |
| 3374 | GLsizei *length, |
| 3375 | GLfloat *params) |
| 3376 | { |
| 3377 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3378 | { |
| 3379 | return false; |
| 3380 | } |
| 3381 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3382 | GLsizei writeLength = 0; |
| 3383 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3384 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3385 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3386 | { |
| 3387 | return false; |
| 3388 | } |
| 3389 | |
| 3390 | SetRobustLengthParam(length, writeLength); |
| 3391 | |
| 3392 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3393 | } |
| 3394 | |
| 3395 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3396 | GLuint program, |
| 3397 | GLint location, |
| 3398 | GLsizei bufSize, |
| 3399 | GLsizei *length, |
| 3400 | GLint *params) |
| 3401 | { |
| 3402 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3403 | { |
| 3404 | return false; |
| 3405 | } |
| 3406 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3407 | GLsizei writeLength = 0; |
| 3408 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3409 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3410 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3411 | { |
| 3412 | return false; |
| 3413 | } |
| 3414 | |
| 3415 | SetRobustLengthParam(length, writeLength); |
| 3416 | |
| 3417 | return true; |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3421 | GLuint program, |
| 3422 | GLint location, |
| 3423 | GLsizei bufSize, |
| 3424 | GLsizei *length, |
| 3425 | GLuint *params) |
| 3426 | { |
| 3427 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3428 | { |
| 3429 | return false; |
| 3430 | } |
| 3431 | |
| 3432 | if (context->getClientMajorVersion() < 3) |
| 3433 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 3434 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3435 | return false; |
| 3436 | } |
| 3437 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3438 | GLsizei writeLength = 0; |
| 3439 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3440 | // bufSize is validated in ValidateSizedGetUniform |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 3441 | if (!ValidateSizedGetUniform(context, program, location, bufSize, &writeLength)) |
| 3442 | { |
| 3443 | return false; |
| 3444 | } |
| 3445 | |
| 3446 | SetRobustLengthParam(length, writeLength); |
| 3447 | |
| 3448 | return true; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3449 | } |
| 3450 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3451 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3452 | GLenum target, |
| 3453 | GLsizei numAttachments, |
| 3454 | const GLenum *attachments, |
| 3455 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3456 | { |
| 3457 | if (numAttachments < 0) |
| 3458 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3459 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeAttachments); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3460 | return false; |
| 3461 | } |
| 3462 | |
| 3463 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3464 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3465 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3466 | { |
| 3467 | if (defaultFramebuffer) |
| 3468 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3469 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), DefaultFramebufferInvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3470 | return false; |
| 3471 | } |
| 3472 | |
| 3473 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3474 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3475 | context->handleError(InvalidOperation() << "Requested color attachment is " |
| 3476 | "greater than the maximum supported " |
| 3477 | "color attachments"); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3478 | return false; |
| 3479 | } |
| 3480 | } |
| 3481 | else |
| 3482 | { |
| 3483 | switch (attachments[i]) |
| 3484 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3485 | case GL_DEPTH_ATTACHMENT: |
| 3486 | case GL_STENCIL_ATTACHMENT: |
| 3487 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3488 | if (defaultFramebuffer) |
| 3489 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3490 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3491 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3492 | return false; |
| 3493 | } |
| 3494 | break; |
| 3495 | case GL_COLOR: |
| 3496 | case GL_DEPTH: |
| 3497 | case GL_STENCIL: |
| 3498 | if (!defaultFramebuffer) |
| 3499 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3500 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
| 3501 | DefaultFramebufferInvalidAttachment); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3502 | return false; |
| 3503 | } |
| 3504 | break; |
| 3505 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3506 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3507 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3508 | } |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | return true; |
| 3513 | } |
| 3514 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3515 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3516 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3517 | if (!context->getExtensions().debugMarker) |
| 3518 | { |
| 3519 | // The debug marker calls should not set error state |
| 3520 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3521 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3522 | return false; |
| 3523 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3524 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3525 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3526 | if (length < 0) |
| 3527 | { |
| 3528 | return false; |
| 3529 | } |
| 3530 | |
| 3531 | if (marker == nullptr) |
| 3532 | { |
| 3533 | return false; |
| 3534 | } |
| 3535 | |
| 3536 | return true; |
| 3537 | } |
| 3538 | |
| 3539 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3540 | { |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3541 | if (!context->getExtensions().debugMarker) |
| 3542 | { |
| 3543 | // The debug marker calls should not set error state |
| 3544 | // However, it seems reasonable to set an error state if the extension is not enabled |
| 3545 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ExtensionNotEnabled); |
| 3546 | return false; |
| 3547 | } |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3548 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3549 | // Note that debug marker calls must not set error state |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3550 | if (length < 0) |
| 3551 | { |
| 3552 | return false; |
| 3553 | } |
| 3554 | |
| 3555 | if (length > 0 && marker == nullptr) |
| 3556 | { |
| 3557 | return false; |
| 3558 | } |
| 3559 | |
| 3560 | return true; |
| 3561 | } |
| 3562 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3563 | bool ValidateEGLImageTargetTexture2DOES(Context *context, TextureType type, GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3564 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3565 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3566 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3567 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3568 | return false; |
| 3569 | } |
| 3570 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3571 | switch (type) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3572 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3573 | case TextureType::_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3574 | if (!context->getExtensions().eglImage) |
| 3575 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3576 | context->handleError(InvalidEnum() |
| 3577 | << "GL_TEXTURE_2D texture target requires GL_OES_EGL_image."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3578 | } |
| 3579 | break; |
| 3580 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 3581 | case TextureType::External: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3582 | if (!context->getExtensions().eglImageExternal) |
| 3583 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3584 | context->handleError(InvalidEnum() << "GL_TEXTURE_EXTERNAL_OES texture target " |
| 3585 | "requires GL_OES_EGL_image_external."); |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3586 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3587 | break; |
| 3588 | |
| 3589 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3590 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3591 | return false; |
| 3592 | } |
| 3593 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3594 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3595 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3596 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3597 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3598 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3599 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3600 | return false; |
| 3601 | } |
| 3602 | |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3603 | if (imageObject->getSamples() > 0) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3604 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3605 | context->handleError(InvalidOperation() |
| 3606 | << "cannot create a 2D texture from a multisampled EGL image."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3607 | return false; |
| 3608 | } |
| 3609 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3610 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3611 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3612 | if (!textureCaps.texturable) |
| 3613 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3614 | context->handleError(InvalidOperation() |
| 3615 | << "EGL image internal format is not supported as a texture."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3616 | return false; |
| 3617 | } |
| 3618 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3619 | return true; |
| 3620 | } |
| 3621 | |
| 3622 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3623 | GLenum target, |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3624 | GLeglImageOES image) |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3625 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3626 | if (!context->getExtensions().eglImage) |
| 3627 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3628 | context->handleError(InvalidOperation()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3629 | return false; |
| 3630 | } |
| 3631 | |
| 3632 | switch (target) |
| 3633 | { |
| 3634 | case GL_RENDERBUFFER: |
| 3635 | break; |
| 3636 | |
| 3637 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3638 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3639 | return false; |
| 3640 | } |
| 3641 | |
Rafael Cintron | 05a449a | 2018-06-20 18:08:04 -0700 | [diff] [blame] | 3642 | egl::Image *imageObject = static_cast<egl::Image *>(image); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3643 | |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 3644 | ASSERT(context->getCurrentDisplay()); |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3645 | if (!context->getCurrentDisplay()->isValidImage(imageObject)) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3646 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3647 | context->handleError(InvalidValue() << "EGL image is not valid."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3648 | return false; |
| 3649 | } |
| 3650 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 3651 | const TextureCaps &textureCaps = |
Jamie Madill | 007530e | 2017-12-28 14:27:04 -0500 | [diff] [blame] | 3652 | context->getTextureCaps().get(imageObject->getFormat().info->sizedInternalFormat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 3653 | if (!textureCaps.renderbuffer) |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3654 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3655 | context->handleError(InvalidOperation() |
| 3656 | << "EGL image internal format is not supported as a renderbuffer."); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3657 | return false; |
| 3658 | } |
| 3659 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3660 | return true; |
| 3661 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3662 | |
| 3663 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 3664 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 3665 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3666 | { |
| 3667 | // The default VAO should always exist |
| 3668 | ASSERT(array != 0); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3669 | context->handleError(InvalidOperation()); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 3670 | return false; |
| 3671 | } |
| 3672 | |
| 3673 | return true; |
| 3674 | } |
| 3675 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3676 | bool ValidateProgramBinaryBase(Context *context, |
| 3677 | GLuint program, |
| 3678 | GLenum binaryFormat, |
| 3679 | const void *binary, |
| 3680 | GLint length) |
| 3681 | { |
| 3682 | Program *programObject = GetValidProgram(context, program); |
| 3683 | if (programObject == nullptr) |
| 3684 | { |
| 3685 | return false; |
| 3686 | } |
| 3687 | |
| 3688 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 3689 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 3690 | programBinaryFormats.end()) |
| 3691 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3692 | context->handleError(InvalidEnum() << "Program binary format is not valid."); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3693 | return false; |
| 3694 | } |
| 3695 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3696 | if (context->hasActiveTransformFeedback(program)) |
| 3697 | { |
| 3698 | // ES 3.0.4 section 2.15 page 91 |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3699 | context->handleError(InvalidOperation() << "Cannot change program binary while program " |
| 3700 | "is associated with an active transform " |
| 3701 | "feedback object."); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 3702 | return false; |
| 3703 | } |
| 3704 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3705 | return true; |
| 3706 | } |
| 3707 | |
| 3708 | bool ValidateGetProgramBinaryBase(Context *context, |
| 3709 | GLuint program, |
| 3710 | GLsizei bufSize, |
| 3711 | GLsizei *length, |
| 3712 | GLenum *binaryFormat, |
| 3713 | void *binary) |
| 3714 | { |
| 3715 | Program *programObject = GetValidProgram(context, program); |
| 3716 | if (programObject == nullptr) |
| 3717 | { |
| 3718 | return false; |
| 3719 | } |
| 3720 | |
| 3721 | if (!programObject->isLinked()) |
| 3722 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3723 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3724 | return false; |
| 3725 | } |
| 3726 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3727 | if (context->getCaps().programBinaryFormats.empty()) |
| 3728 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3729 | context->handleError(InvalidOperation() << "No program binary formats supported."); |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 3730 | return false; |
| 3731 | } |
| 3732 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 3733 | return true; |
| 3734 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3735 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 3736 | bool ValidateDrawBuffersBase(Context *context, GLsizei n, const GLenum *bufs) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3737 | { |
| 3738 | // 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] | 3739 | if (n < 0) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3740 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 3741 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
| 3742 | return false; |
| 3743 | } |
| 3744 | if (static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 3745 | { |
| 3746 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxDrawBuffer); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3747 | return false; |
| 3748 | } |
| 3749 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3750 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 3751 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3752 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 3753 | |
| 3754 | // This should come first before the check for the default frame buffer |
| 3755 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 3756 | // rather than INVALID_OPERATION |
| 3757 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 3758 | { |
| 3759 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 3760 | |
| 3761 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3762 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 3763 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3764 | { |
| 3765 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3766 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 3767 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 3768 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 3769 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3770 | context->handleError(InvalidEnum() << "Invalid buffer value"); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3771 | return false; |
| 3772 | } |
| 3773 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 3774 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3775 | context->handleError(InvalidOperation() |
| 3776 | << "Buffer value is greater than MAX_DRAW_BUFFERS"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3777 | return false; |
| 3778 | } |
| 3779 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 3780 | frameBufferId != 0) |
| 3781 | { |
| 3782 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 3783 | // is not COLOR_ATTACHMENTi or NONE |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3784 | context->handleError(InvalidOperation() |
| 3785 | << "Ith value does not match COLOR_ATTACHMENTi or NONE"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3786 | return false; |
| 3787 | } |
| 3788 | } |
| 3789 | |
| 3790 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 3791 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 3792 | if (frameBufferId == 0) |
| 3793 | { |
| 3794 | if (n != 1) |
| 3795 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3796 | context->handleError(InvalidOperation() |
| 3797 | << "n must be 1 when GL is bound to the default framebuffer"); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3798 | return false; |
| 3799 | } |
| 3800 | |
| 3801 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 3802 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3803 | context->handleError( |
| 3804 | InvalidOperation() |
| 3805 | << "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] | 3806 | return false; |
| 3807 | } |
| 3808 | } |
| 3809 | |
| 3810 | return true; |
| 3811 | } |
| 3812 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3813 | bool ValidateGetBufferPointervBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3814 | BufferBinding target, |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3815 | GLenum pname, |
| 3816 | GLsizei *length, |
| 3817 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3818 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3819 | if (length) |
| 3820 | { |
| 3821 | *length = 0; |
| 3822 | } |
| 3823 | |
| 3824 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 3825 | { |
| 3826 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3827 | InvalidOperation() |
| 3828 | << "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] | 3829 | return false; |
| 3830 | } |
| 3831 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3832 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3833 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3834 | context->handleError(InvalidEnum() << "Buffer target not valid"); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3835 | return false; |
| 3836 | } |
| 3837 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3838 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3839 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3840 | case GL_BUFFER_MAP_POINTER: |
| 3841 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3842 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3843 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3844 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3845 | return false; |
| 3846 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3847 | |
| 3848 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 3849 | // target bound to zero generate an INVALID_OPERATION error." |
| 3850 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3851 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3852 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3853 | context->handleError(InvalidOperation() |
| 3854 | << "Can not get pointer for reserved buffer name zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3855 | return false; |
| 3856 | } |
| 3857 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3858 | if (length) |
| 3859 | { |
| 3860 | *length = 1; |
| 3861 | } |
| 3862 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3863 | return true; |
| 3864 | } |
| 3865 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3866 | bool ValidateUnmapBufferBase(Context *context, BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3867 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3868 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3869 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3870 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3871 | return false; |
| 3872 | } |
| 3873 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3874 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3875 | |
| 3876 | if (buffer == nullptr || !buffer->isMapped()) |
| 3877 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3878 | context->handleError(InvalidOperation() << "Buffer not mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3879 | return false; |
| 3880 | } |
| 3881 | |
| 3882 | return true; |
| 3883 | } |
| 3884 | |
| 3885 | bool ValidateMapBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3886 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3887 | GLintptr offset, |
| 3888 | GLsizeiptr length, |
| 3889 | GLbitfield access) |
| 3890 | { |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3891 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3892 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3893 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3894 | return false; |
| 3895 | } |
| 3896 | |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3897 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3898 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3899 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3900 | return false; |
| 3901 | } |
| 3902 | |
| 3903 | if (length < 0) |
| 3904 | { |
| 3905 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3906 | return false; |
| 3907 | } |
| 3908 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3909 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3910 | |
| 3911 | if (!buffer) |
| 3912 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3913 | context->handleError(InvalidOperation() << "Attempted to map buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3914 | return false; |
| 3915 | } |
| 3916 | |
| 3917 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3918 | CheckedNumeric<size_t> checkedOffset(offset); |
| 3919 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3920 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 3921 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3922 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3923 | context->handleError(InvalidValue() << "Mapped range does not fit into buffer dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3924 | return false; |
| 3925 | } |
| 3926 | |
| 3927 | // Check for invalid bits in the mask |
| 3928 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 3929 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 3930 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3931 | |
| 3932 | if (access & ~(allAccessBits)) |
| 3933 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3934 | context->handleError(InvalidValue() |
| 3935 | << "Invalid access bits: 0x" << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3936 | return false; |
| 3937 | } |
| 3938 | |
| 3939 | if (length == 0) |
| 3940 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3941 | context->handleError(InvalidOperation() << "Buffer mapping length is zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3942 | return false; |
| 3943 | } |
| 3944 | |
| 3945 | if (buffer->isMapped()) |
| 3946 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3947 | context->handleError(InvalidOperation() << "Buffer is already mapped."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3948 | return false; |
| 3949 | } |
| 3950 | |
| 3951 | // Check for invalid bit combinations |
| 3952 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 3953 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3954 | context->handleError(InvalidOperation() |
| 3955 | << "Need to map buffer for either reading or writing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3956 | return false; |
| 3957 | } |
| 3958 | |
| 3959 | GLbitfield writeOnlyBits = |
| 3960 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 3961 | |
| 3962 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 3963 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3964 | context->handleError(InvalidOperation() |
| 3965 | << "Invalid access bits when mapping buffer for reading: 0x" |
| 3966 | << std::hex << std::uppercase << access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3967 | return false; |
| 3968 | } |
| 3969 | |
| 3970 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 3971 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 3972 | context->handleError( |
| 3973 | InvalidOperation() |
| 3974 | << "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] | 3975 | return false; |
| 3976 | } |
Geoff Lang | 79f7104 | 2017-08-14 16:43:43 -0400 | [diff] [blame] | 3977 | |
| 3978 | return ValidateMapBufferBase(context, target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3982 | BufferBinding target, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3983 | GLintptr offset, |
| 3984 | GLsizeiptr length) |
| 3985 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3986 | if (offset < 0) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3987 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 3988 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeOffset); |
| 3989 | return false; |
| 3990 | } |
| 3991 | |
| 3992 | if (length < 0) |
| 3993 | { |
| 3994 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeLength); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3995 | return false; |
| 3996 | } |
| 3997 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 3998 | if (!context->isValidBufferBinding(target)) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3999 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4000 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4001 | return false; |
| 4002 | } |
| 4003 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4004 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4005 | |
| 4006 | if (buffer == nullptr) |
| 4007 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4008 | context->handleError(InvalidOperation() << "Attempted to flush buffer object zero."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4009 | return false; |
| 4010 | } |
| 4011 | |
| 4012 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4013 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4014 | context->handleError(InvalidOperation() |
| 4015 | << "Attempted to flush a buffer not mapped for explicit flushing."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4016 | return false; |
| 4017 | } |
| 4018 | |
| 4019 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4020 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4021 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4022 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4023 | if (!checkedSize.IsValid() || |
| 4024 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4025 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4026 | context->handleError(InvalidValue() |
| 4027 | << "Flushed range does not fit into buffer mapping dimensions."); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4028 | return false; |
| 4029 | } |
| 4030 | |
| 4031 | return true; |
| 4032 | } |
| 4033 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4034 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4035 | { |
| 4036 | if (n < 0) |
| 4037 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4038 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeCount); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4039 | return false; |
| 4040 | } |
| 4041 | return true; |
| 4042 | } |
| 4043 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4044 | bool ValidateRobustEntryPoint(Context *context, GLsizei bufSize) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4045 | { |
| 4046 | if (!context->getExtensions().robustClientMemory) |
| 4047 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4048 | context->handleError(InvalidOperation() |
| 4049 | << "GL_ANGLE_robust_client_memory is not available."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4050 | return false; |
| 4051 | } |
| 4052 | |
| 4053 | if (bufSize < 0) |
| 4054 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4055 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeBufferSize); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4056 | return false; |
| 4057 | } |
| 4058 | |
| 4059 | return true; |
| 4060 | } |
| 4061 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4062 | bool ValidateRobustBufferSize(Context *context, GLsizei bufSize, GLsizei numParams) |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4063 | { |
| 4064 | if (bufSize < numParams) |
| 4065 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4066 | context->handleError(InvalidOperation() << numParams << " parameters are required but " |
| 4067 | << bufSize << " were provided."); |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4068 | return false; |
| 4069 | } |
| 4070 | |
| 4071 | return true; |
| 4072 | } |
| 4073 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4074 | bool ValidateGetFramebufferAttachmentParameterivBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4075 | GLenum target, |
| 4076 | GLenum attachment, |
| 4077 | GLenum pname, |
| 4078 | GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4079 | { |
Geoff Lang | e8afa90 | 2017-09-27 15:00:43 -0400 | [diff] [blame] | 4080 | if (!ValidFramebufferTarget(context, target)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4081 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4082 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4083 | return false; |
| 4084 | } |
| 4085 | |
| 4086 | int clientVersion = context->getClientMajorVersion(); |
| 4087 | |
| 4088 | switch (pname) |
| 4089 | { |
| 4090 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4091 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4092 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4093 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4094 | break; |
| 4095 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4096 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_NUM_VIEWS_ANGLE: |
| 4097 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_MULTIVIEW_LAYOUT_ANGLE: |
| 4098 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_BASE_VIEW_INDEX_ANGLE: |
| 4099 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE: |
| 4100 | if (clientVersion < 3 || !context->getExtensions().multiview) |
| 4101 | { |
| 4102 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 4103 | return false; |
| 4104 | } |
| 4105 | break; |
| 4106 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4107 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4108 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4109 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4110 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4111 | return false; |
| 4112 | } |
| 4113 | break; |
| 4114 | |
| 4115 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4116 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4117 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4118 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4119 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4120 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4121 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4122 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4123 | if (clientVersion < 3) |
| 4124 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4125 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4126 | return false; |
| 4127 | } |
| 4128 | break; |
| 4129 | |
Jiawei Shao | a880247 | 2018-05-28 11:17:47 +0800 | [diff] [blame] | 4130 | case GL_FRAMEBUFFER_ATTACHMENT_LAYERED_EXT: |
| 4131 | if (!context->getExtensions().geometryShader) |
| 4132 | { |
| 4133 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4134 | return false; |
| 4135 | } |
| 4136 | break; |
| 4137 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4138 | default: |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4139 | context->handleError(InvalidEnum()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4140 | return false; |
| 4141 | } |
| 4142 | |
| 4143 | // Determine if the attachment is a valid enum |
| 4144 | switch (attachment) |
| 4145 | { |
| 4146 | case GL_BACK: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4147 | case GL_DEPTH: |
| 4148 | case GL_STENCIL: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4149 | if (clientVersion < 3) |
| 4150 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4151 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4152 | return false; |
| 4153 | } |
| 4154 | break; |
| 4155 | |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4156 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4157 | if (clientVersion < 3 && !context->isWebGL1()) |
| 4158 | { |
| 4159 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
| 4160 | return false; |
| 4161 | } |
| 4162 | break; |
| 4163 | |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4164 | case GL_COLOR_ATTACHMENT0: |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4165 | case GL_DEPTH_ATTACHMENT: |
| 4166 | case GL_STENCIL_ATTACHMENT: |
| 4167 | break; |
| 4168 | |
| 4169 | default: |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4170 | if ((clientVersion < 3 && !context->getExtensions().drawBuffers) || |
| 4171 | attachment < GL_COLOR_ATTACHMENT0_EXT || |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4172 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4173 | { |
Geoff Lang | fa125c9 | 2017-10-24 13:01:46 -0400 | [diff] [blame] | 4174 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4175 | return false; |
| 4176 | } |
| 4177 | break; |
| 4178 | } |
| 4179 | |
| 4180 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4181 | ASSERT(framebuffer); |
| 4182 | |
| 4183 | if (framebuffer->id() == 0) |
| 4184 | { |
| 4185 | if (clientVersion < 3) |
| 4186 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4187 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), DefaultFramebufferTarget); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4188 | return false; |
| 4189 | } |
| 4190 | |
| 4191 | switch (attachment) |
| 4192 | { |
| 4193 | case GL_BACK: |
| 4194 | case GL_DEPTH: |
| 4195 | case GL_STENCIL: |
| 4196 | break; |
| 4197 | |
| 4198 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4199 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4200 | return false; |
| 4201 | } |
| 4202 | } |
| 4203 | else |
| 4204 | { |
| 4205 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4206 | { |
| 4207 | // Valid attachment query |
| 4208 | } |
| 4209 | else |
| 4210 | { |
| 4211 | switch (attachment) |
| 4212 | { |
| 4213 | case GL_DEPTH_ATTACHMENT: |
| 4214 | case GL_STENCIL_ATTACHMENT: |
| 4215 | break; |
| 4216 | |
| 4217 | case GL_DEPTH_STENCIL_ATTACHMENT: |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4218 | if (!framebuffer->hasValidDepthStencil() && !context->isWebGL1()) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4219 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4220 | context->handleError(InvalidOperation()); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4221 | return false; |
| 4222 | } |
| 4223 | break; |
| 4224 | |
| 4225 | default: |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4226 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4227 | return false; |
| 4228 | } |
| 4229 | } |
| 4230 | } |
| 4231 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4232 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(context, attachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4233 | if (attachmentObject) |
| 4234 | { |
| 4235 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4236 | attachmentObject->type() == GL_TEXTURE || |
| 4237 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4238 | |
| 4239 | switch (pname) |
| 4240 | { |
| 4241 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4242 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4243 | attachmentObject->type() != GL_TEXTURE) |
| 4244 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4245 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4246 | return false; |
| 4247 | } |
| 4248 | break; |
| 4249 | |
| 4250 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4251 | if (attachmentObject->type() != GL_TEXTURE) |
| 4252 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4253 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4254 | return false; |
| 4255 | } |
| 4256 | break; |
| 4257 | |
| 4258 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4259 | if (attachmentObject->type() != GL_TEXTURE) |
| 4260 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4261 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4262 | return false; |
| 4263 | } |
| 4264 | break; |
| 4265 | |
| 4266 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4267 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4268 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 4269 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4270 | return false; |
| 4271 | } |
| 4272 | break; |
| 4273 | |
| 4274 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4275 | if (attachmentObject->type() != GL_TEXTURE) |
| 4276 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4277 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), FramebufferIncompleteAttachment); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4278 | return false; |
| 4279 | } |
| 4280 | break; |
| 4281 | |
| 4282 | default: |
| 4283 | break; |
| 4284 | } |
| 4285 | } |
| 4286 | else |
| 4287 | { |
| 4288 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4289 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4290 | |
| 4291 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4292 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4293 | // INVALID_OPERATION for all other pnames |
| 4294 | |
| 4295 | switch (pname) |
| 4296 | { |
| 4297 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4298 | break; |
| 4299 | |
| 4300 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4301 | if (clientVersion < 3) |
| 4302 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4303 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4304 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4305 | return false; |
| 4306 | } |
| 4307 | break; |
| 4308 | |
| 4309 | default: |
| 4310 | if (clientVersion < 3) |
| 4311 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4312 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4313 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4314 | return false; |
| 4315 | } |
| 4316 | else |
| 4317 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4318 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), |
Bryan Bernhart (Intel Americas Inc) | 491b0d6 | 2017-11-10 12:48:22 -0800 | [diff] [blame] | 4319 | InvalidFramebufferAttachmentParameter); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4320 | return false; |
| 4321 | } |
| 4322 | } |
| 4323 | } |
| 4324 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 4325 | if (numParams) |
| 4326 | { |
| 4327 | if (pname == GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_VIEWPORT_OFFSETS_ANGLE) |
| 4328 | { |
| 4329 | // Only when the viewport offsets are queried we can have a varying number of output |
| 4330 | // parameters. |
| 4331 | const int numViews = attachmentObject ? attachmentObject->getNumViews() : 1; |
| 4332 | *numParams = numViews * 2; |
| 4333 | } |
| 4334 | else |
| 4335 | { |
| 4336 | // For all other queries we can have only one output parameter. |
| 4337 | *numParams = 1; |
| 4338 | } |
| 4339 | } |
| 4340 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4341 | return true; |
| 4342 | } |
| 4343 | |
Bryan Bernhart (Intel Americas Inc) | 2eeb1b3 | 2017-11-29 16:06:43 -0800 | [diff] [blame] | 4344 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(Context *context, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4345 | GLenum target, |
| 4346 | GLenum attachment, |
| 4347 | GLenum pname, |
| 4348 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4349 | GLsizei *length, |
| 4350 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4351 | { |
| 4352 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4353 | { |
| 4354 | return false; |
| 4355 | } |
| 4356 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4357 | GLsizei numParams = 0; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4358 | if (!ValidateGetFramebufferAttachmentParameterivBase(context, target, attachment, pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4359 | &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4360 | { |
| 4361 | return false; |
| 4362 | } |
| 4363 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4364 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4365 | { |
| 4366 | return false; |
| 4367 | } |
| 4368 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4369 | SetRobustLengthParam(length, numParams); |
| 4370 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4371 | return true; |
| 4372 | } |
| 4373 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4374 | bool ValidateGetBufferParameterivRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4375 | BufferBinding target, |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4376 | GLenum pname, |
| 4377 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4378 | GLsizei *length, |
| 4379 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4380 | { |
| 4381 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4382 | { |
| 4383 | return false; |
| 4384 | } |
| 4385 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4386 | GLsizei numParams = 0; |
| 4387 | |
| 4388 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4389 | { |
| 4390 | return false; |
| 4391 | } |
| 4392 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4393 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4394 | { |
| 4395 | return false; |
| 4396 | } |
| 4397 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4398 | SetRobustLengthParam(length, numParams); |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4399 | return true; |
| 4400 | } |
| 4401 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4402 | bool ValidateGetBufferParameteri64vRobustANGLE(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 4403 | BufferBinding target, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4404 | GLenum pname, |
| 4405 | GLsizei bufSize, |
| 4406 | GLsizei *length, |
| 4407 | GLint64 *params) |
| 4408 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4409 | GLsizei numParams = 0; |
| 4410 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4411 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4412 | { |
| 4413 | return false; |
| 4414 | } |
| 4415 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4416 | if (!ValidateGetBufferParameterBase(context, target, pname, false, &numParams)) |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4417 | { |
| 4418 | return false; |
| 4419 | } |
| 4420 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4421 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4422 | { |
| 4423 | return false; |
| 4424 | } |
| 4425 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4426 | SetRobustLengthParam(length, numParams); |
| 4427 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4428 | return true; |
| 4429 | } |
| 4430 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 4431 | bool ValidateGetProgramivBase(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4432 | { |
| 4433 | // Currently, all GetProgramiv queries return 1 parameter |
Yunchao He | 33151a5 | 2017-04-13 09:58:17 +0800 | [diff] [blame] | 4434 | if (numParams) |
| 4435 | { |
| 4436 | *numParams = 1; |
| 4437 | } |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4438 | |
| 4439 | Program *programObject = GetValidProgram(context, program); |
| 4440 | if (!programObject) |
| 4441 | { |
| 4442 | return false; |
| 4443 | } |
| 4444 | |
| 4445 | switch (pname) |
| 4446 | { |
| 4447 | case GL_DELETE_STATUS: |
| 4448 | case GL_LINK_STATUS: |
| 4449 | case GL_VALIDATE_STATUS: |
| 4450 | case GL_INFO_LOG_LENGTH: |
| 4451 | case GL_ATTACHED_SHADERS: |
| 4452 | case GL_ACTIVE_ATTRIBUTES: |
| 4453 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 4454 | case GL_ACTIVE_UNIFORMS: |
| 4455 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 4456 | break; |
| 4457 | |
| 4458 | case GL_PROGRAM_BINARY_LENGTH: |
| 4459 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 4460 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4461 | context->handleError(InvalidEnum() << "Querying GL_PROGRAM_BINARY_LENGTH " |
| 4462 | "requires GL_OES_get_program_binary or " |
| 4463 | "ES 3.0."); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4464 | return false; |
| 4465 | } |
| 4466 | break; |
| 4467 | |
| 4468 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 4469 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 4470 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 4471 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 4472 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 4473 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 4474 | if (context->getClientMajorVersion() < 3) |
| 4475 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4476 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4477 | return false; |
| 4478 | } |
| 4479 | break; |
| 4480 | |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4481 | case GL_PROGRAM_SEPARABLE: |
jchen10 | 58f67be | 2017-10-27 08:59:27 +0800 | [diff] [blame] | 4482 | case GL_ACTIVE_ATOMIC_COUNTER_BUFFERS: |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4483 | if (context->getClientVersion() < Version(3, 1)) |
| 4484 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 4485 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 4486 | return false; |
| 4487 | } |
| 4488 | break; |
| 4489 | |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4490 | case GL_COMPUTE_WORK_GROUP_SIZE: |
| 4491 | if (context->getClientVersion() < Version(3, 1)) |
| 4492 | { |
| 4493 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES31Required); |
| 4494 | return false; |
| 4495 | } |
| 4496 | |
| 4497 | // [OpenGL ES 3.1] Chapter 7.12 Page 122 |
| 4498 | // An INVALID_OPERATION error is generated if COMPUTE_WORK_GROUP_SIZE is queried for a |
| 4499 | // program which has not been linked successfully, or which does not contain objects to |
| 4500 | // form a compute shader. |
| 4501 | if (!programObject->isLinked()) |
| 4502 | { |
| 4503 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4504 | return false; |
| 4505 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4506 | if (!programObject->hasLinkedShaderStage(ShaderType::Compute)) |
Jiawei Shao | 6ae5161 | 2018-02-23 14:03:25 +0800 | [diff] [blame] | 4507 | { |
| 4508 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveComputeShaderStage); |
| 4509 | return false; |
| 4510 | } |
| 4511 | break; |
| 4512 | |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4513 | case GL_GEOMETRY_LINKED_INPUT_TYPE_EXT: |
| 4514 | case GL_GEOMETRY_LINKED_OUTPUT_TYPE_EXT: |
| 4515 | case GL_GEOMETRY_LINKED_VERTICES_OUT_EXT: |
| 4516 | case GL_GEOMETRY_SHADER_INVOCATIONS_EXT: |
| 4517 | if (!context->getExtensions().geometryShader) |
| 4518 | { |
| 4519 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), GeometryShaderExtensionNotEnabled); |
| 4520 | return false; |
| 4521 | } |
| 4522 | |
| 4523 | // [EXT_geometry_shader] Chapter 7.12 |
| 4524 | // An INVALID_OPERATION error is generated if GEOMETRY_LINKED_VERTICES_OUT_EXT, |
| 4525 | // GEOMETRY_LINKED_INPUT_TYPE_EXT, GEOMETRY_LINKED_OUTPUT_TYPE_EXT, or |
| 4526 | // GEOMETRY_SHADER_INVOCATIONS_EXT are queried for a program which has not been linked |
| 4527 | // successfully, or which does not contain objects to form a geometry shader. |
| 4528 | if (!programObject->isLinked()) |
| 4529 | { |
| 4530 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ProgramNotLinked); |
| 4531 | return false; |
| 4532 | } |
Jiawei Shao | 385b3e0 | 2018-03-21 09:43:28 +0800 | [diff] [blame] | 4533 | if (!programObject->hasLinkedShaderStage(ShaderType::Geometry)) |
Jiawei Shao | 447bfac | 2018-03-14 14:23:40 +0800 | [diff] [blame] | 4534 | { |
| 4535 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), NoActiveGeometryShaderStage); |
| 4536 | return false; |
| 4537 | } |
| 4538 | break; |
| 4539 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4540 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 4541 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4542 | return false; |
| 4543 | } |
| 4544 | |
| 4545 | return true; |
| 4546 | } |
| 4547 | |
| 4548 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 4549 | GLuint program, |
| 4550 | GLenum pname, |
| 4551 | GLsizei bufSize, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4552 | GLsizei *length, |
| 4553 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4554 | { |
| 4555 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4556 | { |
| 4557 | return false; |
| 4558 | } |
| 4559 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4560 | GLsizei numParams = 0; |
| 4561 | |
| 4562 | if (!ValidateGetProgramivBase(context, program, pname, &numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4563 | { |
| 4564 | return false; |
| 4565 | } |
| 4566 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4567 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4568 | { |
| 4569 | return false; |
| 4570 | } |
| 4571 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4572 | SetRobustLengthParam(length, numParams); |
| 4573 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4574 | return true; |
| 4575 | } |
| 4576 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4577 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 4578 | GLenum target, |
| 4579 | GLenum pname, |
| 4580 | GLsizei bufSize, |
| 4581 | GLsizei *length, |
| 4582 | GLint *params) |
| 4583 | { |
| 4584 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4585 | { |
| 4586 | return false; |
| 4587 | } |
| 4588 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4589 | GLsizei numParams = 0; |
| 4590 | |
| 4591 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, &numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4592 | { |
| 4593 | return false; |
| 4594 | } |
| 4595 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4596 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4597 | { |
| 4598 | return false; |
| 4599 | } |
| 4600 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4601 | SetRobustLengthParam(length, numParams); |
| 4602 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 4603 | return true; |
| 4604 | } |
| 4605 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4606 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 4607 | GLuint shader, |
| 4608 | GLenum pname, |
| 4609 | GLsizei bufSize, |
| 4610 | GLsizei *length, |
| 4611 | GLint *params) |
| 4612 | { |
| 4613 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4614 | { |
| 4615 | return false; |
| 4616 | } |
| 4617 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4618 | GLsizei numParams = 0; |
| 4619 | |
| 4620 | if (!ValidateGetShaderivBase(context, shader, pname, &numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4621 | { |
| 4622 | return false; |
| 4623 | } |
| 4624 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4625 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4626 | { |
| 4627 | return false; |
| 4628 | } |
| 4629 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4630 | SetRobustLengthParam(length, numParams); |
| 4631 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 4632 | return true; |
| 4633 | } |
| 4634 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4635 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4636 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4637 | GLenum pname, |
| 4638 | GLsizei bufSize, |
| 4639 | GLsizei *length, |
| 4640 | GLfloat *params) |
| 4641 | { |
| 4642 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4643 | { |
| 4644 | return false; |
| 4645 | } |
| 4646 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4647 | GLsizei numParams = 0; |
| 4648 | |
| 4649 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4650 | { |
| 4651 | return false; |
| 4652 | } |
| 4653 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4654 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4655 | { |
| 4656 | return false; |
| 4657 | } |
| 4658 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4659 | SetRobustLengthParam(length, numParams); |
| 4660 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4661 | return true; |
| 4662 | } |
| 4663 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4664 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4665 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4666 | GLenum pname, |
| 4667 | GLsizei bufSize, |
| 4668 | GLsizei *length, |
| 4669 | GLint *params) |
| 4670 | { |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4671 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4672 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4673 | { |
| 4674 | return false; |
| 4675 | } |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4676 | GLsizei numParams = 0; |
| 4677 | if (!ValidateGetTexParameterBase(context, target, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4678 | { |
| 4679 | return false; |
| 4680 | } |
| 4681 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4682 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4683 | { |
| 4684 | return false; |
| 4685 | } |
| 4686 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4687 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4688 | return true; |
| 4689 | } |
| 4690 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4691 | bool ValidateGetTexParameterIivRobustANGLE(Context *context, |
| 4692 | TextureType target, |
| 4693 | GLenum pname, |
| 4694 | GLsizei bufSize, |
| 4695 | GLsizei *length, |
| 4696 | GLint *params) |
| 4697 | { |
| 4698 | UNIMPLEMENTED(); |
| 4699 | return false; |
| 4700 | } |
| 4701 | |
| 4702 | bool ValidateGetTexParameterIuivRobustANGLE(Context *context, |
| 4703 | TextureType target, |
| 4704 | GLenum pname, |
| 4705 | GLsizei bufSize, |
| 4706 | GLsizei *length, |
| 4707 | GLuint *params) |
| 4708 | { |
| 4709 | UNIMPLEMENTED(); |
| 4710 | return false; |
| 4711 | } |
| 4712 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4713 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4714 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4715 | GLenum pname, |
| 4716 | GLsizei bufSize, |
| 4717 | const GLfloat *params) |
| 4718 | { |
| 4719 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4720 | { |
| 4721 | return false; |
| 4722 | } |
| 4723 | |
| 4724 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4725 | } |
| 4726 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4727 | bool ValidateTexParameterivRobustANGLE(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 4728 | TextureType target, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4729 | GLenum pname, |
| 4730 | GLsizei bufSize, |
| 4731 | const GLint *params) |
| 4732 | { |
| 4733 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4734 | { |
| 4735 | return false; |
| 4736 | } |
| 4737 | |
| 4738 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 4739 | } |
| 4740 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4741 | bool ValidateTexParameterIivRobustANGLE(Context *context, |
| 4742 | TextureType target, |
| 4743 | GLenum pname, |
| 4744 | GLsizei bufSize, |
| 4745 | const GLint *params) |
| 4746 | { |
| 4747 | UNIMPLEMENTED(); |
| 4748 | return false; |
| 4749 | } |
| 4750 | |
| 4751 | bool ValidateTexParameterIuivRobustANGLE(Context *context, |
| 4752 | TextureType target, |
| 4753 | GLenum pname, |
| 4754 | GLsizei bufSize, |
| 4755 | const GLuint *params) |
| 4756 | { |
| 4757 | UNIMPLEMENTED(); |
| 4758 | return false; |
| 4759 | } |
| 4760 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4761 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 4762 | GLuint sampler, |
| 4763 | GLenum pname, |
| 4764 | GLuint bufSize, |
| 4765 | GLsizei *length, |
| 4766 | GLfloat *params) |
| 4767 | { |
| 4768 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4769 | { |
| 4770 | return false; |
| 4771 | } |
| 4772 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4773 | GLsizei numParams = 0; |
| 4774 | |
| 4775 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4776 | { |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4780 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4781 | { |
| 4782 | return false; |
| 4783 | } |
| 4784 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4785 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4786 | return true; |
| 4787 | } |
| 4788 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4789 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 4790 | GLuint sampler, |
| 4791 | GLenum pname, |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4792 | GLsizei bufSize, |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4793 | GLsizei *length, |
| 4794 | GLint *params) |
| 4795 | { |
| 4796 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4797 | { |
| 4798 | return false; |
| 4799 | } |
| 4800 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4801 | GLsizei numParams = 0; |
| 4802 | |
| 4803 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, &numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4804 | { |
| 4805 | return false; |
| 4806 | } |
| 4807 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4808 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4809 | { |
| 4810 | return false; |
| 4811 | } |
| 4812 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4813 | SetRobustLengthParam(length, numParams); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4814 | return true; |
| 4815 | } |
| 4816 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4817 | bool ValidateGetSamplerParameterIivRobustANGLE(Context *context, |
| 4818 | GLuint sampler, |
| 4819 | GLenum pname, |
| 4820 | GLsizei bufSize, |
| 4821 | GLsizei *length, |
| 4822 | GLint *params) |
| 4823 | { |
| 4824 | UNIMPLEMENTED(); |
| 4825 | return false; |
| 4826 | } |
| 4827 | |
| 4828 | bool ValidateGetSamplerParameterIuivRobustANGLE(Context *context, |
| 4829 | GLuint sampler, |
| 4830 | GLenum pname, |
| 4831 | GLsizei bufSize, |
| 4832 | GLsizei *length, |
| 4833 | GLuint *params) |
| 4834 | { |
| 4835 | UNIMPLEMENTED(); |
| 4836 | return false; |
| 4837 | } |
| 4838 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4839 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 4840 | GLuint sampler, |
| 4841 | GLenum pname, |
| 4842 | GLsizei bufSize, |
| 4843 | const GLfloat *params) |
| 4844 | { |
| 4845 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4846 | { |
| 4847 | return false; |
| 4848 | } |
| 4849 | |
| 4850 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4851 | } |
| 4852 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 4853 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 4854 | GLuint sampler, |
| 4855 | GLenum pname, |
| 4856 | GLsizei bufSize, |
| 4857 | const GLint *params) |
| 4858 | { |
| 4859 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4860 | { |
| 4861 | return false; |
| 4862 | } |
| 4863 | |
| 4864 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 4865 | } |
| 4866 | |
Brandon Jones | fe4bbe6 | 2018-04-06 13:50:14 -0700 | [diff] [blame] | 4867 | bool ValidateSamplerParameterIivRobustANGLE(Context *context, |
| 4868 | GLuint sampler, |
| 4869 | GLenum pname, |
| 4870 | GLsizei bufSize, |
| 4871 | const GLint *param) |
| 4872 | { |
| 4873 | UNIMPLEMENTED(); |
| 4874 | return false; |
| 4875 | } |
| 4876 | |
| 4877 | bool ValidateSamplerParameterIuivRobustANGLE(Context *context, |
| 4878 | GLuint sampler, |
| 4879 | GLenum pname, |
| 4880 | GLsizei bufSize, |
| 4881 | const GLuint *param) |
| 4882 | { |
| 4883 | UNIMPLEMENTED(); |
| 4884 | return false; |
| 4885 | } |
| 4886 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4887 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 4888 | GLuint index, |
| 4889 | GLenum pname, |
| 4890 | GLsizei bufSize, |
| 4891 | GLsizei *length, |
| 4892 | GLfloat *params) |
| 4893 | { |
| 4894 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4895 | { |
| 4896 | return false; |
| 4897 | } |
| 4898 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4899 | GLsizei writeLength = 0; |
| 4900 | |
| 4901 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4902 | { |
| 4903 | return false; |
| 4904 | } |
| 4905 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4906 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4907 | { |
| 4908 | return false; |
| 4909 | } |
| 4910 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4911 | SetRobustLengthParam(length, writeLength); |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4912 | return true; |
| 4913 | } |
| 4914 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4915 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 4916 | GLuint index, |
| 4917 | GLenum pname, |
| 4918 | GLsizei bufSize, |
| 4919 | GLsizei *length, |
| 4920 | GLint *params) |
| 4921 | { |
| 4922 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4923 | { |
| 4924 | return false; |
| 4925 | } |
| 4926 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4927 | GLsizei writeLength = 0; |
| 4928 | |
| 4929 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4930 | { |
| 4931 | return false; |
| 4932 | } |
| 4933 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4934 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4935 | { |
| 4936 | return false; |
| 4937 | } |
| 4938 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4939 | SetRobustLengthParam(length, writeLength); |
| 4940 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4941 | return true; |
| 4942 | } |
| 4943 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4944 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 4945 | GLuint index, |
| 4946 | GLenum pname, |
| 4947 | GLsizei bufSize, |
| 4948 | GLsizei *length, |
| 4949 | void **pointer) |
| 4950 | { |
| 4951 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4952 | { |
| 4953 | return false; |
| 4954 | } |
| 4955 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4956 | GLsizei writeLength = 0; |
| 4957 | |
| 4958 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, true, false)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4959 | { |
| 4960 | return false; |
| 4961 | } |
| 4962 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4963 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4964 | { |
| 4965 | return false; |
| 4966 | } |
| 4967 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4968 | SetRobustLengthParam(length, writeLength); |
| 4969 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4970 | return true; |
| 4971 | } |
| 4972 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4973 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 4974 | GLuint index, |
| 4975 | GLenum pname, |
| 4976 | GLsizei bufSize, |
| 4977 | GLsizei *length, |
| 4978 | GLint *params) |
| 4979 | { |
| 4980 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4981 | { |
| 4982 | return false; |
| 4983 | } |
| 4984 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4985 | GLsizei writeLength = 0; |
| 4986 | |
| 4987 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4988 | { |
| 4989 | return false; |
| 4990 | } |
| 4991 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4992 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4993 | { |
| 4994 | return false; |
| 4995 | } |
| 4996 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 4997 | SetRobustLengthParam(length, writeLength); |
| 4998 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 4999 | return true; |
| 5000 | } |
| 5001 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5002 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5003 | GLuint index, |
| 5004 | GLenum pname, |
| 5005 | GLsizei bufSize, |
| 5006 | GLsizei *length, |
| 5007 | GLuint *params) |
| 5008 | { |
| 5009 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5010 | { |
| 5011 | return false; |
| 5012 | } |
| 5013 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5014 | GLsizei writeLength = 0; |
| 5015 | |
| 5016 | if (!ValidateGetVertexAttribBase(context, index, pname, &writeLength, false, true)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5017 | { |
| 5018 | return false; |
| 5019 | } |
| 5020 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5021 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5022 | { |
| 5023 | return false; |
| 5024 | } |
| 5025 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5026 | SetRobustLengthParam(length, writeLength); |
| 5027 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5028 | return true; |
| 5029 | } |
| 5030 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5031 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5032 | GLuint program, |
| 5033 | GLuint uniformBlockIndex, |
| 5034 | GLenum pname, |
| 5035 | GLsizei bufSize, |
| 5036 | GLsizei *length, |
| 5037 | GLint *params) |
| 5038 | { |
| 5039 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5040 | { |
| 5041 | return false; |
| 5042 | } |
| 5043 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5044 | GLsizei writeLength = 0; |
| 5045 | |
| 5046 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, |
| 5047 | &writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5048 | { |
| 5049 | return false; |
| 5050 | } |
| 5051 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5052 | if (!ValidateRobustBufferSize(context, bufSize, writeLength)) |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5053 | { |
| 5054 | return false; |
| 5055 | } |
| 5056 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5057 | SetRobustLengthParam(length, writeLength); |
| 5058 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5059 | return true; |
| 5060 | } |
| 5061 | |
Brandon Jones | 416aaf9 | 2018-04-10 08:10:16 -0700 | [diff] [blame] | 5062 | bool ValidateGetInternalformativRobustANGLE(Context *context, |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5063 | GLenum target, |
| 5064 | GLenum internalformat, |
| 5065 | GLenum pname, |
| 5066 | GLsizei bufSize, |
| 5067 | GLsizei *length, |
| 5068 | GLint *params) |
| 5069 | { |
| 5070 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5071 | { |
| 5072 | return false; |
| 5073 | } |
| 5074 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5075 | GLsizei numParams = 0; |
| 5076 | |
| 5077 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5078 | &numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5079 | { |
| 5080 | return false; |
| 5081 | } |
| 5082 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5083 | if (!ValidateRobustBufferSize(context, bufSize, numParams)) |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5084 | { |
| 5085 | return false; |
| 5086 | } |
| 5087 | |
Brandon Jones | d104918 | 2018-03-28 10:02:20 -0700 | [diff] [blame] | 5088 | SetRobustLengthParam(length, numParams); |
| 5089 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5090 | return true; |
| 5091 | } |
| 5092 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5093 | bool ValidateVertexFormatBase(Context *context, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5094 | GLuint attribIndex, |
| 5095 | GLint size, |
| 5096 | GLenum type, |
| 5097 | GLboolean pureInteger) |
| 5098 | { |
| 5099 | const Caps &caps = context->getCaps(); |
| 5100 | if (attribIndex >= caps.maxVertexAttributes) |
| 5101 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5102 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5103 | return false; |
| 5104 | } |
| 5105 | |
| 5106 | if (size < 1 || size > 4) |
| 5107 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5108 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidVertexAttrSize); |
Geoff Lang | 8700a98 | 2017-06-13 10:15:13 -0400 | [diff] [blame] | 5109 | return false; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5110 | } |
| 5111 | |
| 5112 | switch (type) |
| 5113 | { |
| 5114 | case GL_BYTE: |
| 5115 | case GL_UNSIGNED_BYTE: |
| 5116 | case GL_SHORT: |
| 5117 | case GL_UNSIGNED_SHORT: |
| 5118 | break; |
| 5119 | |
| 5120 | case GL_INT: |
| 5121 | case GL_UNSIGNED_INT: |
| 5122 | if (context->getClientMajorVersion() < 3) |
| 5123 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5124 | context->handleError(InvalidEnum() |
| 5125 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5126 | return false; |
| 5127 | } |
| 5128 | break; |
| 5129 | |
| 5130 | case GL_FIXED: |
| 5131 | case GL_FLOAT: |
| 5132 | if (pureInteger) |
| 5133 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5134 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5135 | return false; |
| 5136 | } |
| 5137 | break; |
| 5138 | |
| 5139 | case GL_HALF_FLOAT: |
| 5140 | if (context->getClientMajorVersion() < 3) |
| 5141 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5142 | context->handleError(InvalidEnum() |
| 5143 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5144 | return false; |
| 5145 | } |
| 5146 | if (pureInteger) |
| 5147 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5148 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5149 | return false; |
| 5150 | } |
| 5151 | break; |
| 5152 | |
| 5153 | case GL_INT_2_10_10_10_REV: |
| 5154 | case GL_UNSIGNED_INT_2_10_10_10_REV: |
| 5155 | if (context->getClientMajorVersion() < 3) |
| 5156 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5157 | context->handleError(InvalidEnum() |
| 5158 | << "Vertex type not supported before OpenGL ES 3.0."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5159 | return false; |
| 5160 | } |
| 5161 | if (pureInteger) |
| 5162 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5163 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTypePureInt); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5164 | return false; |
| 5165 | } |
| 5166 | if (size != 4) |
| 5167 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5168 | context->handleError(InvalidOperation() << "Type is INT_2_10_10_10_REV or " |
| 5169 | "UNSIGNED_INT_2_10_10_10_REV and " |
| 5170 | "size is not 4."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5171 | return false; |
| 5172 | } |
| 5173 | break; |
| 5174 | |
| 5175 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5176 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 5177 | return false; |
| 5178 | } |
| 5179 | |
| 5180 | return true; |
| 5181 | } |
| 5182 | |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5183 | // Perform validation from WebGL 2 section 5.10 "Invalid Clears": |
| 5184 | // In the WebGL 2 API, trying to perform a clear when there is a mismatch between the type of the |
| 5185 | // specified clear value and the type of a buffer that is being cleared generates an |
| 5186 | // INVALID_OPERATION error instead of producing undefined results |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5187 | bool ValidateWebGLFramebufferAttachmentClearType(Context *context, |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5188 | GLint drawbuffer, |
| 5189 | const GLenum *validComponentTypes, |
| 5190 | size_t validComponentTypeCount) |
| 5191 | { |
| 5192 | const FramebufferAttachment *attachment = |
| 5193 | context->getGLState().getDrawFramebuffer()->getDrawBuffer(drawbuffer); |
| 5194 | if (attachment) |
| 5195 | { |
| 5196 | GLenum componentType = attachment->getFormat().info->componentType; |
| 5197 | const GLenum *end = validComponentTypes + validComponentTypeCount; |
| 5198 | if (std::find(validComponentTypes, end, componentType) == end) |
| 5199 | { |
| 5200 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5201 | InvalidOperation() |
| 5202 | << "No defined conversion between clear value and attachment format."); |
Geoff Lang | 76e6565 | 2017-03-27 14:58:02 -0400 | [diff] [blame] | 5203 | return false; |
| 5204 | } |
| 5205 | } |
| 5206 | |
| 5207 | return true; |
| 5208 | } |
| 5209 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5210 | bool ValidateRobustCompressedTexImageBase(Context *context, GLsizei imageSize, GLsizei dataSize) |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5211 | { |
| 5212 | if (!ValidateRobustEntryPoint(context, dataSize)) |
| 5213 | { |
| 5214 | return false; |
| 5215 | } |
| 5216 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5217 | gl::Buffer *pixelUnpackBuffer = |
| 5218 | context->getGLState().getTargetBuffer(BufferBinding::PixelUnpack); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5219 | if (pixelUnpackBuffer == nullptr) |
| 5220 | { |
| 5221 | if (dataSize < imageSize) |
| 5222 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5223 | context->handleError(InvalidOperation() << "dataSize must be at least " << imageSize); |
Corentin Wallez | b293160 | 2017-04-11 15:58:57 -0400 | [diff] [blame] | 5224 | } |
| 5225 | } |
| 5226 | return true; |
| 5227 | } |
| 5228 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 5229 | bool ValidateGetBufferParameterBase(Context *context, |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5230 | BufferBinding target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5231 | GLenum pname, |
| 5232 | bool pointerVersion, |
| 5233 | GLsizei *numParams) |
| 5234 | { |
| 5235 | if (numParams) |
| 5236 | { |
| 5237 | *numParams = 0; |
| 5238 | } |
| 5239 | |
Corentin Wallez | e447700 | 2017-12-01 14:39:58 -0500 | [diff] [blame] | 5240 | if (!context->isValidBufferBinding(target)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5241 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5242 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidBufferTypes); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5243 | return false; |
| 5244 | } |
| 5245 | |
| 5246 | const Buffer *buffer = context->getGLState().getTargetBuffer(target); |
| 5247 | if (!buffer) |
| 5248 | { |
| 5249 | // 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] | 5250 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), BufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5251 | return false; |
| 5252 | } |
| 5253 | |
| 5254 | const Extensions &extensions = context->getExtensions(); |
| 5255 | |
| 5256 | switch (pname) |
| 5257 | { |
| 5258 | case GL_BUFFER_USAGE: |
| 5259 | case GL_BUFFER_SIZE: |
| 5260 | break; |
| 5261 | |
| 5262 | case GL_BUFFER_ACCESS_OES: |
| 5263 | if (!extensions.mapBuffer) |
| 5264 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5265 | context->handleError(InvalidEnum() |
| 5266 | << "pname requires OpenGL ES 3.0 or GL_OES_mapbuffer."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5267 | return false; |
| 5268 | } |
| 5269 | break; |
| 5270 | |
| 5271 | case GL_BUFFER_MAPPED: |
| 5272 | static_assert(GL_BUFFER_MAPPED == GL_BUFFER_MAPPED_OES, "GL enums should be equal."); |
| 5273 | if (context->getClientMajorVersion() < 3 && !extensions.mapBuffer && |
| 5274 | !extensions.mapBufferRange) |
| 5275 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5276 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0, " |
| 5277 | "GL_OES_mapbuffer or " |
| 5278 | "GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5279 | return false; |
| 5280 | } |
| 5281 | break; |
| 5282 | |
| 5283 | case GL_BUFFER_MAP_POINTER: |
| 5284 | if (!pointerVersion) |
| 5285 | { |
| 5286 | context->handleError( |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5287 | InvalidEnum() |
| 5288 | << "GL_BUFFER_MAP_POINTER can only be queried with GetBufferPointerv."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5289 | return false; |
| 5290 | } |
| 5291 | break; |
| 5292 | |
| 5293 | case GL_BUFFER_ACCESS_FLAGS: |
| 5294 | case GL_BUFFER_MAP_OFFSET: |
| 5295 | case GL_BUFFER_MAP_LENGTH: |
| 5296 | if (context->getClientMajorVersion() < 3 && !extensions.mapBufferRange) |
| 5297 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5298 | context->handleError(InvalidEnum() |
| 5299 | << "pname requires OpenGL ES 3.0 or GL_EXT_map_buffer_range."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5300 | return false; |
| 5301 | } |
| 5302 | break; |
| 5303 | |
| 5304 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5305 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5306 | return false; |
| 5307 | } |
| 5308 | |
| 5309 | // All buffer parameter queries return one value. |
| 5310 | if (numParams) |
| 5311 | { |
| 5312 | *numParams = 1; |
| 5313 | } |
| 5314 | |
| 5315 | return true; |
| 5316 | } |
| 5317 | |
| 5318 | bool ValidateGetRenderbufferParameterivBase(Context *context, |
| 5319 | GLenum target, |
| 5320 | GLenum pname, |
| 5321 | GLsizei *length) |
| 5322 | { |
| 5323 | if (length) |
| 5324 | { |
| 5325 | *length = 0; |
| 5326 | } |
| 5327 | |
| 5328 | if (target != GL_RENDERBUFFER) |
| 5329 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5330 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidRenderbufferTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5331 | return false; |
| 5332 | } |
| 5333 | |
| 5334 | Renderbuffer *renderbuffer = context->getGLState().getCurrentRenderbuffer(); |
| 5335 | if (renderbuffer == nullptr) |
| 5336 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5337 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), RenderbufferNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5338 | return false; |
| 5339 | } |
| 5340 | |
| 5341 | switch (pname) |
| 5342 | { |
| 5343 | case GL_RENDERBUFFER_WIDTH: |
| 5344 | case GL_RENDERBUFFER_HEIGHT: |
| 5345 | case GL_RENDERBUFFER_INTERNAL_FORMAT: |
| 5346 | case GL_RENDERBUFFER_RED_SIZE: |
| 5347 | case GL_RENDERBUFFER_GREEN_SIZE: |
| 5348 | case GL_RENDERBUFFER_BLUE_SIZE: |
| 5349 | case GL_RENDERBUFFER_ALPHA_SIZE: |
| 5350 | case GL_RENDERBUFFER_DEPTH_SIZE: |
| 5351 | case GL_RENDERBUFFER_STENCIL_SIZE: |
| 5352 | break; |
| 5353 | |
| 5354 | case GL_RENDERBUFFER_SAMPLES_ANGLE: |
| 5355 | if (!context->getExtensions().framebufferMultisample) |
| 5356 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5357 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5358 | return false; |
| 5359 | } |
| 5360 | break; |
| 5361 | |
| 5362 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5363 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5364 | return false; |
| 5365 | } |
| 5366 | |
| 5367 | if (length) |
| 5368 | { |
| 5369 | *length = 1; |
| 5370 | } |
| 5371 | return true; |
| 5372 | } |
| 5373 | |
| 5374 | bool ValidateGetShaderivBase(Context *context, GLuint shader, GLenum pname, GLsizei *length) |
| 5375 | { |
| 5376 | if (length) |
| 5377 | { |
| 5378 | *length = 0; |
| 5379 | } |
| 5380 | |
| 5381 | if (GetValidShader(context, shader) == nullptr) |
| 5382 | { |
| 5383 | return false; |
| 5384 | } |
| 5385 | |
| 5386 | switch (pname) |
| 5387 | { |
| 5388 | case GL_SHADER_TYPE: |
| 5389 | case GL_DELETE_STATUS: |
| 5390 | case GL_COMPILE_STATUS: |
| 5391 | case GL_INFO_LOG_LENGTH: |
| 5392 | case GL_SHADER_SOURCE_LENGTH: |
| 5393 | break; |
| 5394 | |
| 5395 | case GL_TRANSLATED_SHADER_SOURCE_LENGTH_ANGLE: |
| 5396 | if (!context->getExtensions().translatedShaderSource) |
| 5397 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5398 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5399 | return false; |
| 5400 | } |
| 5401 | break; |
| 5402 | |
| 5403 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5404 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5405 | return false; |
| 5406 | } |
| 5407 | |
| 5408 | if (length) |
| 5409 | { |
| 5410 | *length = 1; |
| 5411 | } |
| 5412 | return true; |
| 5413 | } |
| 5414 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5415 | bool ValidateGetTexParameterBase(Context *context, |
| 5416 | TextureType target, |
| 5417 | GLenum pname, |
| 5418 | GLsizei *length) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5419 | { |
| 5420 | if (length) |
| 5421 | { |
| 5422 | *length = 0; |
| 5423 | } |
| 5424 | |
| 5425 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5426 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5427 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5428 | return false; |
| 5429 | } |
| 5430 | |
| 5431 | if (context->getTargetTexture(target) == nullptr) |
| 5432 | { |
| 5433 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5434 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5435 | return false; |
| 5436 | } |
| 5437 | |
| 5438 | switch (pname) |
| 5439 | { |
| 5440 | case GL_TEXTURE_MAG_FILTER: |
| 5441 | case GL_TEXTURE_MIN_FILTER: |
| 5442 | case GL_TEXTURE_WRAP_S: |
| 5443 | case GL_TEXTURE_WRAP_T: |
| 5444 | break; |
| 5445 | |
| 5446 | case GL_TEXTURE_USAGE_ANGLE: |
| 5447 | if (!context->getExtensions().textureUsage) |
| 5448 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5449 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5450 | return false; |
| 5451 | } |
| 5452 | break; |
| 5453 | |
| 5454 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 5455 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5456 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5457 | return false; |
| 5458 | } |
| 5459 | break; |
| 5460 | |
| 5461 | case GL_TEXTURE_IMMUTABLE_FORMAT: |
| 5462 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().textureStorage) |
| 5463 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5464 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ExtensionNotEnabled); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5465 | return false; |
| 5466 | } |
| 5467 | break; |
| 5468 | |
| 5469 | case GL_TEXTURE_WRAP_R: |
| 5470 | case GL_TEXTURE_IMMUTABLE_LEVELS: |
| 5471 | case GL_TEXTURE_SWIZZLE_R: |
| 5472 | case GL_TEXTURE_SWIZZLE_G: |
| 5473 | case GL_TEXTURE_SWIZZLE_B: |
| 5474 | case GL_TEXTURE_SWIZZLE_A: |
| 5475 | case GL_TEXTURE_BASE_LEVEL: |
| 5476 | case GL_TEXTURE_MAX_LEVEL: |
| 5477 | case GL_TEXTURE_MIN_LOD: |
| 5478 | case GL_TEXTURE_MAX_LOD: |
| 5479 | case GL_TEXTURE_COMPARE_MODE: |
| 5480 | case GL_TEXTURE_COMPARE_FUNC: |
| 5481 | if (context->getClientMajorVersion() < 3) |
| 5482 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5483 | context->handleError(InvalidEnum() << "pname requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5484 | return false; |
| 5485 | } |
| 5486 | break; |
| 5487 | |
| 5488 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 5489 | if (!context->getExtensions().textureSRGBDecode) |
| 5490 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5491 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5492 | return false; |
| 5493 | } |
| 5494 | break; |
| 5495 | |
Yunchao He | bacaa71 | 2018-01-30 14:01:39 +0800 | [diff] [blame] | 5496 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 5497 | if (context->getClientVersion() < Version(3, 1)) |
| 5498 | { |
| 5499 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
| 5500 | return false; |
| 5501 | } |
| 5502 | break; |
| 5503 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5504 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5505 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5506 | return false; |
| 5507 | } |
| 5508 | |
| 5509 | if (length) |
| 5510 | { |
| 5511 | *length = 1; |
| 5512 | } |
| 5513 | return true; |
| 5514 | } |
| 5515 | |
| 5516 | bool ValidateGetVertexAttribBase(Context *context, |
| 5517 | GLuint index, |
| 5518 | GLenum pname, |
| 5519 | GLsizei *length, |
| 5520 | bool pointer, |
| 5521 | bool pureIntegerEntryPoint) |
| 5522 | { |
| 5523 | if (length) |
| 5524 | { |
| 5525 | *length = 0; |
| 5526 | } |
| 5527 | |
| 5528 | if (pureIntegerEntryPoint && context->getClientMajorVersion() < 3) |
| 5529 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5530 | context->handleError(InvalidOperation() << "Context does not support OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5531 | return false; |
| 5532 | } |
| 5533 | |
| 5534 | if (index >= context->getCaps().maxVertexAttributes) |
| 5535 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5536 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5537 | return false; |
| 5538 | } |
| 5539 | |
| 5540 | if (pointer) |
| 5541 | { |
| 5542 | if (pname != GL_VERTEX_ATTRIB_ARRAY_POINTER) |
| 5543 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5544 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5545 | return false; |
| 5546 | } |
| 5547 | } |
| 5548 | else |
| 5549 | { |
| 5550 | switch (pname) |
| 5551 | { |
| 5552 | case GL_VERTEX_ATTRIB_ARRAY_ENABLED: |
| 5553 | case GL_VERTEX_ATTRIB_ARRAY_SIZE: |
| 5554 | case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
| 5555 | case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
| 5556 | case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
| 5557 | case GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING: |
| 5558 | case GL_CURRENT_VERTEX_ATTRIB: |
| 5559 | break; |
| 5560 | |
| 5561 | case GL_VERTEX_ATTRIB_ARRAY_DIVISOR: |
| 5562 | static_assert( |
| 5563 | GL_VERTEX_ATTRIB_ARRAY_DIVISOR == GL_VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE, |
| 5564 | "ANGLE extension enums not equal to GL enums."); |
| 5565 | if (context->getClientMajorVersion() < 3 && |
| 5566 | !context->getExtensions().instancedArrays) |
| 5567 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5568 | context->handleError(InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_DIVISOR " |
| 5569 | "requires OpenGL ES 3.0 or " |
| 5570 | "GL_ANGLE_instanced_arrays."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5571 | return false; |
| 5572 | } |
| 5573 | break; |
| 5574 | |
| 5575 | case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
| 5576 | if (context->getClientMajorVersion() < 3) |
| 5577 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5578 | context->handleError( |
| 5579 | InvalidEnum() << "GL_VERTEX_ATTRIB_ARRAY_INTEGER requires OpenGL ES 3.0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5580 | return false; |
| 5581 | } |
| 5582 | break; |
| 5583 | |
| 5584 | case GL_VERTEX_ATTRIB_BINDING: |
| 5585 | case GL_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 5586 | if (context->getClientVersion() < ES_3_1) |
| 5587 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5588 | context->handleError(InvalidEnum() |
| 5589 | << "Vertex Attrib Bindings require OpenGL ES 3.1."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5590 | return false; |
| 5591 | } |
| 5592 | break; |
| 5593 | |
| 5594 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5595 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5596 | return false; |
| 5597 | } |
| 5598 | } |
| 5599 | |
| 5600 | if (length) |
| 5601 | { |
| 5602 | if (pname == GL_CURRENT_VERTEX_ATTRIB) |
| 5603 | { |
| 5604 | *length = 4; |
| 5605 | } |
| 5606 | else |
| 5607 | { |
| 5608 | *length = 1; |
| 5609 | } |
| 5610 | } |
| 5611 | |
| 5612 | return true; |
| 5613 | } |
| 5614 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 5615 | bool ValidateReadPixelsBase(Context *context, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5616 | GLint x, |
| 5617 | GLint y, |
| 5618 | GLsizei width, |
| 5619 | GLsizei height, |
| 5620 | GLenum format, |
| 5621 | GLenum type, |
| 5622 | GLsizei bufSize, |
| 5623 | GLsizei *length, |
| 5624 | GLsizei *columns, |
| 5625 | GLsizei *rows, |
| 5626 | void *pixels) |
| 5627 | { |
| 5628 | if (length != nullptr) |
| 5629 | { |
| 5630 | *length = 0; |
| 5631 | } |
| 5632 | if (rows != nullptr) |
| 5633 | { |
| 5634 | *rows = 0; |
| 5635 | } |
| 5636 | if (columns != nullptr) |
| 5637 | { |
| 5638 | *columns = 0; |
| 5639 | } |
| 5640 | |
| 5641 | if (width < 0 || height < 0) |
| 5642 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5643 | ANGLE_VALIDATION_ERR(context, InvalidValue(), NegativeSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5644 | return false; |
| 5645 | } |
| 5646 | |
Jamie Madill | acf2f3a | 2017-11-21 19:22:44 -0500 | [diff] [blame] | 5647 | Framebuffer *readFramebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5648 | |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 5649 | if (!ValidateFramebufferComplete(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5650 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5651 | return false; |
| 5652 | } |
| 5653 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 5654 | if (readFramebuffer->id() != 0 && !ValidateFramebufferNotMultisampled(context, readFramebuffer)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5655 | { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5656 | return false; |
| 5657 | } |
| 5658 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5659 | Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5660 | ASSERT(framebuffer); |
| 5661 | |
| 5662 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 5663 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5664 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ReadBufferNone); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5665 | return false; |
| 5666 | } |
| 5667 | |
| 5668 | const FramebufferAttachment *readBuffer = framebuffer->getReadColorbuffer(); |
| 5669 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 5670 | // In OpenGL ES it is undefined what happens when an operation tries to read from a missing |
| 5671 | // attachment and WebGL defines it to be an error. We do the check unconditionnaly as the |
| 5672 | // situation is an application error that would lead to a crash in ANGLE. |
| 5673 | if (readBuffer == nullptr) |
| 5674 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5675 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MissingReadAttachment); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5676 | return false; |
| 5677 | } |
| 5678 | |
Martin Radev | 2803168 | 2017-07-28 14:47:56 +0300 | [diff] [blame] | 5679 | // ANGLE_multiview, Revision 1: |
| 5680 | // ReadPixels generates an INVALID_FRAMEBUFFER_OPERATION error if the multi-view layout of the |
| 5681 | // current read framebuffer is not NONE. |
| 5682 | if (readBuffer->getMultiviewLayout() != GL_NONE) |
| 5683 | { |
| 5684 | context->handleError(InvalidFramebufferOperation() |
| 5685 | << "Attempting to read from a multi-view framebuffer."); |
| 5686 | return false; |
| 5687 | } |
| 5688 | |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5689 | if (context->getExtensions().webglCompatibility) |
| 5690 | { |
| 5691 | // The ES 2.0 spec states that the format must be "among those defined in table 3.4, |
| 5692 | // excluding formats LUMINANCE and LUMINANCE_ALPHA.". This requires validating the format |
| 5693 | // and type before validating the combination of format and type. However, the |
| 5694 | // dEQP-GLES3.functional.negative_api.buffer.read_pixels passes GL_LUMINANCE as a format and |
| 5695 | // verifies that GL_INVALID_OPERATION is generated. |
| 5696 | // TODO(geofflang): Update this check to be done in all/no cases once this is resolved in |
| 5697 | // dEQP/WebGL. |
| 5698 | if (!ValidReadPixelsFormatEnum(context, format)) |
| 5699 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5700 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidFormat); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5701 | return false; |
| 5702 | } |
| 5703 | |
| 5704 | if (!ValidReadPixelsTypeEnum(context, type)) |
| 5705 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5706 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidType); |
Geoff Lang | 280ba99 | 2017-04-18 16:30:58 -0400 | [diff] [blame] | 5707 | return false; |
| 5708 | } |
| 5709 | } |
| 5710 | |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 5711 | GLenum currentFormat = GL_NONE; |
| 5712 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadFormat(context, ¤tFormat)); |
| 5713 | |
| 5714 | GLenum currentType = GL_NONE; |
| 5715 | ANGLE_VALIDATION_TRY(framebuffer->getImplementationColorReadType(context, ¤tType)); |
| 5716 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5717 | GLenum currentComponentType = readBuffer->getFormat().info->componentType; |
| 5718 | |
| 5719 | bool validFormatTypeCombination = |
| 5720 | ValidReadPixelsFormatType(context, currentComponentType, format, type); |
| 5721 | |
| 5722 | if (!(currentFormat == format && currentType == type) && !validFormatTypeCombination) |
| 5723 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5724 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), MismatchedTypeAndFormat); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5725 | return false; |
| 5726 | } |
| 5727 | |
| 5728 | // Check for pixel pack buffer related API errors |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5729 | gl::Buffer *pixelPackBuffer = context->getGLState().getTargetBuffer(BufferBinding::PixelPack); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5730 | if (pixelPackBuffer != nullptr && pixelPackBuffer->isMapped()) |
| 5731 | { |
| 5732 | // ...the buffer object's data store is currently mapped. |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5733 | context->handleError(InvalidOperation() << "Pixel pack buffer is mapped."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5734 | return false; |
| 5735 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 5736 | if (context->getExtensions().webglCompatibility && pixelPackBuffer != nullptr && |
| 5737 | pixelPackBuffer->isBoundForTransformFeedbackAndOtherUse()) |
| 5738 | { |
| 5739 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), PixelPackBufferBoundForTransformFeedback); |
| 5740 | return false; |
| 5741 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5742 | |
| 5743 | // .. the data would be packed to the buffer object such that the memory writes required |
| 5744 | // would exceed the data store size. |
| 5745 | const InternalFormat &formatInfo = GetInternalFormatInfo(format, type); |
| 5746 | const gl::Extents size(width, height, 1); |
| 5747 | const auto &pack = context->getGLState().getPackState(); |
| 5748 | |
| 5749 | auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, pack, false); |
| 5750 | if (endByteOrErr.isError()) |
| 5751 | { |
| 5752 | context->handleError(endByteOrErr.getError()); |
| 5753 | return false; |
| 5754 | } |
| 5755 | |
| 5756 | size_t endByte = endByteOrErr.getResult(); |
| 5757 | if (bufSize >= 0) |
| 5758 | { |
| 5759 | if (pixelPackBuffer == nullptr && static_cast<size_t>(bufSize) < endByte) |
| 5760 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5761 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5762 | return false; |
| 5763 | } |
| 5764 | } |
| 5765 | |
| 5766 | if (pixelPackBuffer != nullptr) |
| 5767 | { |
| 5768 | CheckedNumeric<size_t> checkedEndByte(endByte); |
| 5769 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 5770 | checkedEndByte += checkedOffset; |
| 5771 | |
| 5772 | if (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelPackBuffer->getSize())) |
| 5773 | { |
| 5774 | // Overflow past the end of the buffer |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5775 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ParamOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5776 | return false; |
| 5777 | } |
| 5778 | } |
| 5779 | |
| 5780 | if (pixelPackBuffer == nullptr && length != nullptr) |
| 5781 | { |
| 5782 | if (endByte > static_cast<size_t>(std::numeric_limits<GLsizei>::max())) |
| 5783 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5784 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5785 | return false; |
| 5786 | } |
| 5787 | |
| 5788 | *length = static_cast<GLsizei>(endByte); |
| 5789 | } |
| 5790 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5791 | auto getClippedExtent = [](GLint start, GLsizei length, int bufferSize, GLsizei *outExtent) { |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5792 | angle::CheckedNumeric<int> clippedExtent(length); |
| 5793 | if (start < 0) |
| 5794 | { |
| 5795 | // "subtract" the area that is less than 0 |
| 5796 | clippedExtent += start; |
| 5797 | } |
| 5798 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5799 | angle::CheckedNumeric<int> readExtent = start; |
| 5800 | readExtent += length; |
| 5801 | if (!readExtent.IsValid()) |
| 5802 | { |
| 5803 | return false; |
| 5804 | } |
| 5805 | |
| 5806 | if (readExtent.ValueOrDie() > bufferSize) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5807 | { |
| 5808 | // Subtract the region to the right of the read buffer |
| 5809 | clippedExtent -= (readExtent - bufferSize); |
| 5810 | } |
| 5811 | |
| 5812 | if (!clippedExtent.IsValid()) |
| 5813 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5814 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5815 | } |
| 5816 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5817 | *outExtent = std::max(clippedExtent.ValueOrDie(), 0); |
| 5818 | return true; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5819 | }; |
| 5820 | |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5821 | GLsizei writtenColumns = 0; |
| 5822 | if (!getClippedExtent(x, width, readBuffer->getSize().width, &writtenColumns)) |
| 5823 | { |
| 5824 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5825 | return false; |
| 5826 | } |
| 5827 | |
| 5828 | GLsizei writtenRows = 0; |
| 5829 | if (!getClippedExtent(y, height, readBuffer->getSize().height, &writtenRows)) |
| 5830 | { |
| 5831 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), IntegerOverflow); |
| 5832 | return false; |
| 5833 | } |
| 5834 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5835 | if (columns != nullptr) |
| 5836 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5837 | *columns = writtenColumns; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5838 | } |
| 5839 | |
| 5840 | if (rows != nullptr) |
| 5841 | { |
Geoff Lang | a953b52 | 2018-02-21 16:56:23 -0500 | [diff] [blame] | 5842 | *rows = writtenRows; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5843 | } |
| 5844 | |
| 5845 | return true; |
| 5846 | } |
| 5847 | |
| 5848 | template <typename ParamType> |
| 5849 | bool ValidateTexParameterBase(Context *context, |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5850 | TextureType target, |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5851 | GLenum pname, |
| 5852 | GLsizei bufSize, |
| 5853 | const ParamType *params) |
| 5854 | { |
| 5855 | if (!ValidTextureTarget(context, target) && !ValidTextureExternalTarget(context, target)) |
| 5856 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5857 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTextureTarget); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5858 | return false; |
| 5859 | } |
| 5860 | |
| 5861 | if (context->getTargetTexture(target) == nullptr) |
| 5862 | { |
| 5863 | // Should only be possible for external textures |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5864 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), TextureNotBound); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5865 | return false; |
| 5866 | } |
| 5867 | |
| 5868 | const GLsizei minBufSize = 1; |
| 5869 | if (bufSize >= 0 && bufSize < minBufSize) |
| 5870 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5871 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5872 | return false; |
| 5873 | } |
| 5874 | |
| 5875 | switch (pname) |
| 5876 | { |
| 5877 | case GL_TEXTURE_WRAP_R: |
| 5878 | case GL_TEXTURE_SWIZZLE_R: |
| 5879 | case GL_TEXTURE_SWIZZLE_G: |
| 5880 | case GL_TEXTURE_SWIZZLE_B: |
| 5881 | case GL_TEXTURE_SWIZZLE_A: |
| 5882 | case GL_TEXTURE_BASE_LEVEL: |
| 5883 | case GL_TEXTURE_MAX_LEVEL: |
| 5884 | case GL_TEXTURE_COMPARE_MODE: |
| 5885 | case GL_TEXTURE_COMPARE_FUNC: |
| 5886 | case GL_TEXTURE_MIN_LOD: |
| 5887 | case GL_TEXTURE_MAX_LOD: |
| 5888 | if (context->getClientMajorVersion() < 3) |
| 5889 | { |
Brandon Jones | afa7515 | 2017-07-21 13:11:29 -0700 | [diff] [blame] | 5890 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), ES3Required); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5891 | return false; |
| 5892 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5893 | if (target == TextureType::External && !context->getExtensions().eglImageExternalEssl3) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5894 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 5895 | context->handleError(InvalidEnum() << "ES3 texture parameters are not " |
| 5896 | "available without " |
| 5897 | "GL_OES_EGL_image_external_essl3."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5898 | return false; |
| 5899 | } |
| 5900 | break; |
| 5901 | |
| 5902 | default: |
| 5903 | break; |
| 5904 | } |
| 5905 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 5906 | if (target == TextureType::_2DMultisample) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 5907 | { |
| 5908 | switch (pname) |
| 5909 | { |
| 5910 | case GL_TEXTURE_MIN_FILTER: |
| 5911 | case GL_TEXTURE_MAG_FILTER: |
| 5912 | case GL_TEXTURE_WRAP_S: |
| 5913 | case GL_TEXTURE_WRAP_T: |
| 5914 | case GL_TEXTURE_WRAP_R: |
| 5915 | case GL_TEXTURE_MIN_LOD: |
| 5916 | case GL_TEXTURE_MAX_LOD: |
| 5917 | case GL_TEXTURE_COMPARE_MODE: |
| 5918 | case GL_TEXTURE_COMPARE_FUNC: |
| 5919 | context->handleError(InvalidEnum() |
| 5920 | << "Invalid parameter for 2D multisampled textures."); |
| 5921 | return false; |
| 5922 | } |
| 5923 | } |
| 5924 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5925 | switch (pname) |
| 5926 | { |
| 5927 | case GL_TEXTURE_WRAP_S: |
| 5928 | case GL_TEXTURE_WRAP_T: |
| 5929 | case GL_TEXTURE_WRAP_R: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5930 | { |
| 5931 | bool restrictedWrapModes = |
| 5932 | target == TextureType::External || target == TextureType::Rectangle; |
| 5933 | if (!ValidateTextureWrapModeValue(context, params, restrictedWrapModes)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5934 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5935 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5936 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5937 | } |
| 5938 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5939 | |
| 5940 | case GL_TEXTURE_MIN_FILTER: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5941 | { |
| 5942 | bool restrictedMinFilter = |
| 5943 | target == TextureType::External || target == TextureType::Rectangle; |
| 5944 | if (!ValidateTextureMinFilterValue(context, params, restrictedMinFilter)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5945 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5946 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5947 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5948 | } |
| 5949 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5950 | |
| 5951 | case GL_TEXTURE_MAG_FILTER: |
| 5952 | if (!ValidateTextureMagFilterValue(context, params)) |
| 5953 | { |
| 5954 | return false; |
| 5955 | } |
| 5956 | break; |
| 5957 | |
| 5958 | case GL_TEXTURE_USAGE_ANGLE: |
Geoff Lang | 91ab54b | 2017-10-30 15:12:42 -0400 | [diff] [blame] | 5959 | if (!context->getExtensions().textureUsage) |
| 5960 | { |
| 5961 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 5962 | return false; |
| 5963 | } |
| 5964 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5965 | switch (ConvertToGLenum(params[0])) |
| 5966 | { |
| 5967 | case GL_NONE: |
| 5968 | case GL_FRAMEBUFFER_ATTACHMENT_ANGLE: |
| 5969 | break; |
| 5970 | |
| 5971 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 5972 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5973 | return false; |
| 5974 | } |
| 5975 | break; |
| 5976 | |
| 5977 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5978 | { |
| 5979 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 5980 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5981 | { |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5982 | return false; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5983 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 5984 | ASSERT(static_cast<ParamType>(paramValue) == params[0]); |
| 5985 | } |
| 5986 | break; |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 5987 | |
| 5988 | case GL_TEXTURE_MIN_LOD: |
| 5989 | case GL_TEXTURE_MAX_LOD: |
| 5990 | // any value is permissible |
| 5991 | break; |
| 5992 | |
| 5993 | case GL_TEXTURE_COMPARE_MODE: |
| 5994 | if (!ValidateTextureCompareModeValue(context, params)) |
| 5995 | { |
| 5996 | return false; |
| 5997 | } |
| 5998 | break; |
| 5999 | |
| 6000 | case GL_TEXTURE_COMPARE_FUNC: |
| 6001 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6002 | { |
| 6003 | return false; |
| 6004 | } |
| 6005 | break; |
| 6006 | |
| 6007 | case GL_TEXTURE_SWIZZLE_R: |
| 6008 | case GL_TEXTURE_SWIZZLE_G: |
| 6009 | case GL_TEXTURE_SWIZZLE_B: |
| 6010 | case GL_TEXTURE_SWIZZLE_A: |
| 6011 | switch (ConvertToGLenum(params[0])) |
| 6012 | { |
| 6013 | case GL_RED: |
| 6014 | case GL_GREEN: |
| 6015 | case GL_BLUE: |
| 6016 | case GL_ALPHA: |
| 6017 | case GL_ZERO: |
| 6018 | case GL_ONE: |
| 6019 | break; |
| 6020 | |
| 6021 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6022 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6023 | return false; |
| 6024 | } |
| 6025 | break; |
| 6026 | |
| 6027 | case GL_TEXTURE_BASE_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6028 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6029 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6030 | context->handleError(InvalidValue() << "Base level must be at least 0."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6031 | return false; |
| 6032 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6033 | if (target == TextureType::External && static_cast<GLuint>(params[0]) != 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6034 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 6035 | context->handleError(InvalidOperation() |
| 6036 | << "Base level must be 0 for external textures."); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6037 | return false; |
| 6038 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6039 | if (target == TextureType::_2DMultisample && static_cast<GLuint>(params[0]) != 0) |
JiangYizhou | 4cff8d6 | 2017-07-06 14:54:09 +0800 | [diff] [blame] | 6040 | { |
| 6041 | context->handleError(InvalidOperation() |
| 6042 | << "Base level must be 0 for multisampled textures."); |
| 6043 | return false; |
| 6044 | } |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6045 | if (target == TextureType::Rectangle && static_cast<GLuint>(params[0]) != 0) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 6046 | { |
| 6047 | context->handleError(InvalidOperation() |
| 6048 | << "Base level must be 0 for rectangle textures."); |
| 6049 | return false; |
| 6050 | } |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6051 | break; |
| 6052 | |
| 6053 | case GL_TEXTURE_MAX_LEVEL: |
Geoff Lang | fb7685f | 2017-11-13 11:44:11 -0500 | [diff] [blame] | 6054 | if (ConvertToGLint(params[0]) < 0) |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6055 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6056 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InvalidMipLevel); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6057 | return false; |
| 6058 | } |
| 6059 | break; |
| 6060 | |
| 6061 | case GL_DEPTH_STENCIL_TEXTURE_MODE: |
| 6062 | if (context->getClientVersion() < Version(3, 1)) |
| 6063 | { |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6064 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumRequiresGLES31); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6065 | return false; |
| 6066 | } |
| 6067 | switch (ConvertToGLenum(params[0])) |
| 6068 | { |
| 6069 | case GL_DEPTH_COMPONENT: |
| 6070 | case GL_STENCIL_INDEX: |
| 6071 | break; |
| 6072 | |
| 6073 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6074 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6075 | return false; |
| 6076 | } |
| 6077 | break; |
| 6078 | |
| 6079 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6080 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6081 | { |
| 6082 | return false; |
| 6083 | } |
| 6084 | break; |
| 6085 | |
| 6086 | default: |
Brandon Jones | 6cad566 | 2017-06-14 13:25:13 -0700 | [diff] [blame] | 6087 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6088 | return false; |
| 6089 | } |
| 6090 | |
| 6091 | return true; |
| 6092 | } |
| 6093 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 6094 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLfloat *); |
| 6095 | template bool ValidateTexParameterBase(Context *, TextureType, GLenum, GLsizei, const GLint *); |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 6096 | |
Jamie Madill | 5b77231 | 2018-03-08 20:28:32 -0500 | [diff] [blame] | 6097 | bool ValidateVertexAttribIndex(Context *context, GLuint index) |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6098 | { |
| 6099 | if (index >= MAX_VERTEX_ATTRIBS) |
| 6100 | { |
| 6101 | ANGLE_VALIDATION_ERR(context, InvalidValue(), IndexExceedsMaxVertexAttribute); |
| 6102 | return false; |
| 6103 | } |
| 6104 | |
| 6105 | return true; |
| 6106 | } |
| 6107 | |
| 6108 | bool ValidateGetActiveUniformBlockivBase(Context *context, |
| 6109 | GLuint program, |
| 6110 | GLuint uniformBlockIndex, |
| 6111 | GLenum pname, |
| 6112 | GLsizei *length) |
| 6113 | { |
| 6114 | if (length) |
| 6115 | { |
| 6116 | *length = 0; |
| 6117 | } |
| 6118 | |
| 6119 | if (context->getClientMajorVersion() < 3) |
| 6120 | { |
| 6121 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6122 | return false; |
| 6123 | } |
| 6124 | |
| 6125 | Program *programObject = GetValidProgram(context, program); |
| 6126 | if (!programObject) |
| 6127 | { |
| 6128 | return false; |
| 6129 | } |
| 6130 | |
| 6131 | if (uniformBlockIndex >= programObject->getActiveUniformBlockCount()) |
| 6132 | { |
| 6133 | context->handleError(InvalidValue() |
| 6134 | << "uniformBlockIndex exceeds active uniform block count."); |
| 6135 | return false; |
| 6136 | } |
| 6137 | |
| 6138 | switch (pname) |
| 6139 | { |
| 6140 | case GL_UNIFORM_BLOCK_BINDING: |
| 6141 | case GL_UNIFORM_BLOCK_DATA_SIZE: |
| 6142 | case GL_UNIFORM_BLOCK_NAME_LENGTH: |
| 6143 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORMS: |
| 6144 | case GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES: |
| 6145 | case GL_UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER: |
| 6146 | case GL_UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER: |
| 6147 | break; |
| 6148 | |
| 6149 | default: |
| 6150 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6151 | return false; |
| 6152 | } |
| 6153 | |
| 6154 | if (length) |
| 6155 | { |
| 6156 | if (pname == GL_UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES) |
| 6157 | { |
Jiajia Qin | 729b2c6 | 2017-08-14 09:36:11 +0800 | [diff] [blame] | 6158 | const InterfaceBlock &uniformBlock = |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 6159 | programObject->getUniformBlockByIndex(uniformBlockIndex); |
| 6160 | *length = static_cast<GLsizei>(uniformBlock.memberIndexes.size()); |
| 6161 | } |
| 6162 | else |
| 6163 | { |
| 6164 | *length = 1; |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | return true; |
| 6169 | } |
| 6170 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6171 | template <typename ParamType> |
| 6172 | bool ValidateSamplerParameterBase(Context *context, |
| 6173 | GLuint sampler, |
| 6174 | GLenum pname, |
| 6175 | GLsizei bufSize, |
| 6176 | ParamType *params) |
| 6177 | { |
| 6178 | if (context->getClientMajorVersion() < 3) |
| 6179 | { |
| 6180 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6181 | return false; |
| 6182 | } |
| 6183 | |
| 6184 | if (!context->isSampler(sampler)) |
| 6185 | { |
| 6186 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6187 | return false; |
| 6188 | } |
| 6189 | |
| 6190 | const GLsizei minBufSize = 1; |
| 6191 | if (bufSize >= 0 && bufSize < minBufSize) |
| 6192 | { |
| 6193 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InsufficientBufferSize); |
| 6194 | return false; |
| 6195 | } |
| 6196 | |
| 6197 | switch (pname) |
| 6198 | { |
| 6199 | case GL_TEXTURE_WRAP_S: |
| 6200 | case GL_TEXTURE_WRAP_T: |
| 6201 | case GL_TEXTURE_WRAP_R: |
| 6202 | if (!ValidateTextureWrapModeValue(context, params, false)) |
| 6203 | { |
| 6204 | return false; |
| 6205 | } |
| 6206 | break; |
| 6207 | |
| 6208 | case GL_TEXTURE_MIN_FILTER: |
| 6209 | if (!ValidateTextureMinFilterValue(context, params, false)) |
| 6210 | { |
| 6211 | return false; |
| 6212 | } |
| 6213 | break; |
| 6214 | |
| 6215 | case GL_TEXTURE_MAG_FILTER: |
| 6216 | if (!ValidateTextureMagFilterValue(context, params)) |
| 6217 | { |
| 6218 | return false; |
| 6219 | } |
| 6220 | break; |
| 6221 | |
| 6222 | case GL_TEXTURE_MIN_LOD: |
| 6223 | case GL_TEXTURE_MAX_LOD: |
| 6224 | // any value is permissible |
| 6225 | break; |
| 6226 | |
| 6227 | case GL_TEXTURE_COMPARE_MODE: |
| 6228 | if (!ValidateTextureCompareModeValue(context, params)) |
| 6229 | { |
| 6230 | return false; |
| 6231 | } |
| 6232 | break; |
| 6233 | |
| 6234 | case GL_TEXTURE_COMPARE_FUNC: |
| 6235 | if (!ValidateTextureCompareFuncValue(context, params)) |
| 6236 | { |
| 6237 | return false; |
| 6238 | } |
| 6239 | break; |
| 6240 | |
| 6241 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6242 | if (!ValidateTextureSRGBDecodeValue(context, params)) |
| 6243 | { |
| 6244 | return false; |
| 6245 | } |
| 6246 | break; |
| 6247 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6248 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6249 | { |
| 6250 | GLfloat paramValue = static_cast<GLfloat>(params[0]); |
| 6251 | if (!ValidateTextureMaxAnisotropyValue(context, paramValue)) |
| 6252 | { |
| 6253 | return false; |
| 6254 | } |
| 6255 | } |
| 6256 | break; |
| 6257 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6258 | default: |
| 6259 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6260 | return false; |
| 6261 | } |
| 6262 | |
| 6263 | return true; |
| 6264 | } |
| 6265 | |
| 6266 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLfloat *); |
| 6267 | template bool ValidateSamplerParameterBase(Context *, GLuint, GLenum, GLsizei, GLint *); |
| 6268 | |
| 6269 | bool ValidateGetSamplerParameterBase(Context *context, |
| 6270 | GLuint sampler, |
| 6271 | GLenum pname, |
| 6272 | GLsizei *length) |
| 6273 | { |
| 6274 | if (length) |
| 6275 | { |
| 6276 | *length = 0; |
| 6277 | } |
| 6278 | |
| 6279 | if (context->getClientMajorVersion() < 3) |
| 6280 | { |
| 6281 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
| 6282 | return false; |
| 6283 | } |
| 6284 | |
| 6285 | if (!context->isSampler(sampler)) |
| 6286 | { |
| 6287 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), InvalidSampler); |
| 6288 | return false; |
| 6289 | } |
| 6290 | |
| 6291 | switch (pname) |
| 6292 | { |
| 6293 | case GL_TEXTURE_WRAP_S: |
| 6294 | case GL_TEXTURE_WRAP_T: |
| 6295 | case GL_TEXTURE_WRAP_R: |
| 6296 | case GL_TEXTURE_MIN_FILTER: |
| 6297 | case GL_TEXTURE_MAG_FILTER: |
| 6298 | case GL_TEXTURE_MIN_LOD: |
| 6299 | case GL_TEXTURE_MAX_LOD: |
| 6300 | case GL_TEXTURE_COMPARE_MODE: |
| 6301 | case GL_TEXTURE_COMPARE_FUNC: |
| 6302 | break; |
| 6303 | |
Luc Ferron | 1b1a864 | 2018-01-23 15:12:01 -0500 | [diff] [blame] | 6304 | case GL_TEXTURE_MAX_ANISOTROPY_EXT: |
| 6305 | if (!ValidateTextureMaxAnisotropyExtensionEnabled(context)) |
| 6306 | { |
| 6307 | return false; |
| 6308 | } |
| 6309 | break; |
| 6310 | |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6311 | case GL_TEXTURE_SRGB_DECODE_EXT: |
| 6312 | if (!context->getExtensions().textureSRGBDecode) |
| 6313 | { |
| 6314 | context->handleError(InvalidEnum() << "GL_EXT_texture_sRGB_decode is not enabled."); |
| 6315 | return false; |
| 6316 | } |
| 6317 | break; |
| 6318 | |
| 6319 | default: |
| 6320 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6321 | return false; |
| 6322 | } |
| 6323 | |
| 6324 | if (length) |
| 6325 | { |
| 6326 | *length = 1; |
| 6327 | } |
| 6328 | return true; |
| 6329 | } |
| 6330 | |
| 6331 | bool ValidateGetInternalFormativBase(Context *context, |
| 6332 | GLenum target, |
| 6333 | GLenum internalformat, |
| 6334 | GLenum pname, |
| 6335 | GLsizei bufSize, |
| 6336 | GLsizei *numParams) |
| 6337 | { |
| 6338 | if (numParams) |
| 6339 | { |
| 6340 | *numParams = 0; |
| 6341 | } |
| 6342 | |
| 6343 | if (context->getClientMajorVersion() < 3) |
| 6344 | { |
Yunchao He | f0fd87d | 2017-09-12 04:55:05 +0800 | [diff] [blame] | 6345 | ANGLE_VALIDATION_ERR(context, InvalidOperation(), ES3Required); |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6346 | return false; |
| 6347 | } |
| 6348 | |
| 6349 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
Yuly Novikov | f15f886 | 2018-06-04 18:59:41 -0400 | [diff] [blame] | 6350 | if (!formatCaps.renderbuffer) |
Jamie Madill | 9696d07 | 2017-08-26 23:19:57 -0400 | [diff] [blame] | 6351 | { |
| 6352 | context->handleError(InvalidEnum() << "Internal format is not renderable."); |
| 6353 | return false; |
| 6354 | } |
| 6355 | |
| 6356 | switch (target) |
| 6357 | { |
| 6358 | case GL_RENDERBUFFER: |
| 6359 | break; |
| 6360 | |
| 6361 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 6362 | if (context->getClientVersion() < ES_3_1) |
| 6363 | { |
| 6364 | context->handleError(InvalidOperation() |
| 6365 | << "Texture target requires at least OpenGL ES 3.1."); |
| 6366 | return false; |
| 6367 | } |
| 6368 | break; |
| 6369 | |
| 6370 | default: |
| 6371 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidTarget); |
| 6372 | return false; |
| 6373 | } |
| 6374 | |
| 6375 | if (bufSize < 0) |
| 6376 | { |
| 6377 | ANGLE_VALIDATION_ERR(context, InvalidValue(), InsufficientBufferSize); |
| 6378 | return false; |
| 6379 | } |
| 6380 | |
| 6381 | GLsizei maxWriteParams = 0; |
| 6382 | switch (pname) |
| 6383 | { |
| 6384 | case GL_NUM_SAMPLE_COUNTS: |
| 6385 | maxWriteParams = 1; |
| 6386 | break; |
| 6387 | |
| 6388 | case GL_SAMPLES: |
| 6389 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 6390 | break; |
| 6391 | |
| 6392 | default: |
| 6393 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), EnumNotSupported); |
| 6394 | return false; |
| 6395 | } |
| 6396 | |
| 6397 | if (numParams) |
| 6398 | { |
| 6399 | // glGetInternalFormativ will not overflow bufSize |
| 6400 | *numParams = std::min(bufSize, maxWriteParams); |
| 6401 | } |
| 6402 | |
| 6403 | return true; |
| 6404 | } |
| 6405 | |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6406 | bool ValidateFramebufferNotMultisampled(Context *context, Framebuffer *framebuffer) |
| 6407 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 6408 | if (framebuffer->getSamples(context) != 0) |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 6409 | { |
| 6410 | context->handleError(InvalidOperation()); |
| 6411 | return false; |
| 6412 | } |
| 6413 | return true; |
| 6414 | } |
| 6415 | |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 6416 | bool ValidateMultitextureUnit(Context *context, GLenum texture) |
| 6417 | { |
| 6418 | if (texture < GL_TEXTURE0 || texture >= GL_TEXTURE0 + context->getCaps().maxMultitextureUnits) |
| 6419 | { |
| 6420 | ANGLE_VALIDATION_ERR(context, InvalidEnum(), InvalidMultitextureUnit); |
| 6421 | return false; |
| 6422 | } |
| 6423 | return true; |
| 6424 | } |
| 6425 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 6426 | } // namespace gl |