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