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