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