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