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