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