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