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