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( |
| 1233 | Error(GL_INVALID_ENUM, "pname requires OpenGL ES 3.0 or GL_OES_map_buffer.")); |
| 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, |
| 1245 | "pname requires OpenGL ES 3.0, GL_OES_map_buffer or GL_EXT_map_buffer_range.")); |
| 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 | |
| 1316 | default: |
| 1317 | context->handleError(Error(GL_INVALID_ENUM, "Invalid target.")); |
| 1318 | return false; |
| 1319 | } |
| 1320 | |
| 1321 | if (bufSize < 0) |
| 1322 | { |
| 1323 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
| 1324 | return false; |
| 1325 | } |
| 1326 | |
| 1327 | GLsizei maxWriteParams = 0; |
| 1328 | switch (pname) |
| 1329 | { |
| 1330 | case GL_NUM_SAMPLE_COUNTS: |
| 1331 | maxWriteParams = 1; |
| 1332 | break; |
| 1333 | |
| 1334 | case GL_SAMPLES: |
| 1335 | maxWriteParams = static_cast<GLsizei>(formatCaps.sampleCounts.size()); |
| 1336 | break; |
| 1337 | |
| 1338 | default: |
| 1339 | context->handleError(Error(GL_INVALID_ENUM, "Unknown pname.")); |
| 1340 | return false; |
| 1341 | } |
| 1342 | |
| 1343 | if (numParams) |
| 1344 | { |
| 1345 | // glGetInternalFormativ will not overflow bufSize |
| 1346 | *numParams = std::min(bufSize, maxWriteParams); |
| 1347 | } |
| 1348 | |
| 1349 | return true; |
| 1350 | } |
| 1351 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 1352 | } // anonymous namespace |
| 1353 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1354 | bool ValidTextureTarget(const ValidationContext *context, GLenum target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 1355 | { |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1356 | switch (target) |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 1357 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1358 | case GL_TEXTURE_2D: |
| 1359 | case GL_TEXTURE_CUBE_MAP: |
| 1360 | return true; |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 1361 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1362 | case GL_TEXTURE_3D: |
| 1363 | case GL_TEXTURE_2D_ARRAY: |
| 1364 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1365 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1366 | case GL_TEXTURE_2D_MULTISAMPLE: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1367 | return (context->getClientVersion() >= Version(3, 1)); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 1368 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1369 | default: |
| 1370 | return false; |
Jamie Madill | d7460c7 | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1371 | } |
Jamie Madill | 35d1501 | 2013-10-07 10:46:37 -0400 | [diff] [blame] | 1372 | } |
| 1373 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1374 | bool ValidTexture2DTarget(const ValidationContext *context, GLenum target) |
| 1375 | { |
| 1376 | switch (target) |
| 1377 | { |
| 1378 | case GL_TEXTURE_2D: |
| 1379 | case GL_TEXTURE_CUBE_MAP: |
| 1380 | return true; |
| 1381 | |
| 1382 | default: |
| 1383 | return false; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | bool ValidTexture3DTarget(const ValidationContext *context, GLenum target) |
| 1388 | { |
| 1389 | switch (target) |
| 1390 | { |
| 1391 | case GL_TEXTURE_3D: |
| 1392 | case GL_TEXTURE_2D_ARRAY: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1393 | return (context->getClientMajorVersion() >= 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1394 | |
| 1395 | default: |
| 1396 | return false; |
| 1397 | } |
| 1398 | } |
| 1399 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 1400 | // Most texture GL calls are not compatible with external textures, so we have a separate validation |
| 1401 | // function for use in the GL calls that do |
| 1402 | bool ValidTextureExternalTarget(const ValidationContext *context, GLenum target) |
| 1403 | { |
| 1404 | return (target == GL_TEXTURE_EXTERNAL_OES) && |
| 1405 | (context->getExtensions().eglImageExternal || |
| 1406 | context->getExtensions().eglStreamConsumerExternal); |
| 1407 | } |
| 1408 | |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 1409 | // This function differs from ValidTextureTarget in that the target must be |
| 1410 | // usable as the destination of a 2D operation-- so a cube face is valid, but |
| 1411 | // GL_TEXTURE_CUBE_MAP is not. |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 1412 | // Note: duplicate of IsInternalTextureTarget |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1413 | bool ValidTexture2DDestinationTarget(const ValidationContext *context, GLenum target) |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 1414 | { |
| 1415 | switch (target) |
| 1416 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1417 | case GL_TEXTURE_2D: |
| 1418 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1419 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1420 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1421 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1422 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1423 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1424 | return true; |
| 1425 | default: |
| 1426 | return false; |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | bool ValidTexture3DDestinationTarget(const ValidationContext *context, GLenum target) |
| 1431 | { |
| 1432 | switch (target) |
| 1433 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1434 | case GL_TEXTURE_3D: |
| 1435 | case GL_TEXTURE_2D_ARRAY: |
| 1436 | return true; |
| 1437 | default: |
| 1438 | return false; |
Shannon Woods | 4dfed83 | 2014-03-17 20:03:39 -0400 | [diff] [blame] | 1439 | } |
| 1440 | } |
| 1441 | |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame^] | 1442 | bool ValidTexLevelDestinationTarget(const ValidationContext *context, GLenum target) |
| 1443 | { |
| 1444 | switch (target) |
| 1445 | { |
| 1446 | case GL_TEXTURE_2D: |
| 1447 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1448 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1449 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1450 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1451 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1452 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1453 | case GL_TEXTURE_3D: |
| 1454 | case GL_TEXTURE_2D_ARRAY: |
| 1455 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 1456 | return true; |
| 1457 | default: |
| 1458 | return false; |
| 1459 | } |
| 1460 | } |
| 1461 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1462 | bool ValidFramebufferTarget(GLenum target) |
| 1463 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1464 | static_assert(GL_DRAW_FRAMEBUFFER_ANGLE == GL_DRAW_FRAMEBUFFER && |
| 1465 | GL_READ_FRAMEBUFFER_ANGLE == GL_READ_FRAMEBUFFER, |
Geoff Lang | d447581 | 2015-03-18 10:53:05 -0400 | [diff] [blame] | 1466 | "ANGLE framebuffer enums must equal the ES3 framebuffer enums."); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1467 | |
| 1468 | switch (target) |
| 1469 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1470 | case GL_FRAMEBUFFER: |
| 1471 | return true; |
| 1472 | case GL_READ_FRAMEBUFFER: |
| 1473 | return true; |
| 1474 | case GL_DRAW_FRAMEBUFFER: |
| 1475 | return true; |
| 1476 | default: |
| 1477 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 1481 | bool ValidBufferTarget(const ValidationContext *context, GLenum target) |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 1482 | { |
| 1483 | switch (target) |
| 1484 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1485 | case GL_ARRAY_BUFFER: |
| 1486 | case GL_ELEMENT_ARRAY_BUFFER: |
| 1487 | return true; |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 1488 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1489 | case GL_PIXEL_PACK_BUFFER: |
| 1490 | case GL_PIXEL_UNPACK_BUFFER: |
| 1491 | return (context->getExtensions().pixelBufferObject || |
| 1492 | context->getClientMajorVersion() >= 3); |
Shannon Woods | 158c438 | 2014-05-06 13:00:07 -0400 | [diff] [blame] | 1493 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1494 | case GL_COPY_READ_BUFFER: |
| 1495 | case GL_COPY_WRITE_BUFFER: |
| 1496 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 1497 | case GL_UNIFORM_BUFFER: |
| 1498 | return (context->getClientMajorVersion() >= 3); |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 1499 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1500 | case GL_ATOMIC_COUNTER_BUFFER: |
| 1501 | case GL_SHADER_STORAGE_BUFFER: |
| 1502 | case GL_DRAW_INDIRECT_BUFFER: |
| 1503 | case GL_DISPATCH_INDIRECT_BUFFER: |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1504 | return context->getClientVersion() >= Version(3, 1); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 1505 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1506 | default: |
| 1507 | return false; |
Jamie Madill | 8c96d58 | 2014-03-05 15:01:23 -0500 | [diff] [blame] | 1508 | } |
| 1509 | } |
| 1510 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1511 | bool ValidMipLevel(const ValidationContext *context, GLenum target, GLint level) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1512 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1513 | const auto &caps = context->getCaps(); |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1514 | size_t maxDimension = 0; |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1515 | switch (target) |
| 1516 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1517 | case GL_TEXTURE_2D: |
| 1518 | maxDimension = caps.max2DTextureSize; |
| 1519 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1520 | case GL_TEXTURE_CUBE_MAP: |
| 1521 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 1522 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 1523 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 1524 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 1525 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 1526 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 1527 | maxDimension = caps.maxCubeMapTextureSize; |
| 1528 | break; |
| 1529 | case GL_TEXTURE_3D: |
| 1530 | maxDimension = caps.max3DTextureSize; |
| 1531 | break; |
| 1532 | case GL_TEXTURE_2D_ARRAY: |
| 1533 | maxDimension = caps.max2DTextureSize; |
| 1534 | break; |
He Yunchao | 11b038b | 2016-11-22 21:24:04 +0800 | [diff] [blame^] | 1535 | case GL_TEXTURE_2D_MULTISAMPLE: |
| 1536 | maxDimension = caps.max2DTextureSize; |
| 1537 | break; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1538 | default: |
| 1539 | UNREACHABLE(); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1540 | } |
| 1541 | |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1542 | return level <= gl::log2(static_cast<int>(maxDimension)); |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1543 | } |
| 1544 | |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 1545 | bool ValidImageSizeParameters(const ValidationContext *context, |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1546 | GLenum target, |
| 1547 | GLint level, |
| 1548 | GLsizei width, |
| 1549 | GLsizei height, |
| 1550 | GLsizei depth, |
| 1551 | bool isSubImage) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1552 | { |
| 1553 | if (level < 0 || width < 0 || height < 0 || depth < 0) |
| 1554 | { |
| 1555 | return false; |
| 1556 | } |
| 1557 | |
Austin Kinross | 08528e1 | 2015-10-07 16:24:40 -0700 | [diff] [blame] | 1558 | // TexSubImage parameters can be NPOT without textureNPOT extension, |
| 1559 | // as long as the destination texture is POT. |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 1560 | bool hasNPOTSupport = |
Geoff Lang | 5f319a4 | 2017-01-09 16:49:19 -0500 | [diff] [blame] | 1561 | context->getExtensions().textureNPOT || context->getClientVersion() >= Version(3, 0); |
Geoff Lang | cc507aa | 2016-12-12 10:09:52 -0500 | [diff] [blame] | 1562 | if (!isSubImage && !hasNPOTSupport && |
Jamie Madill | 4fd75c1 | 2014-06-23 10:53:54 -0400 | [diff] [blame] | 1563 | (level != 0 && (!gl::isPow2(width) || !gl::isPow2(height) || !gl::isPow2(depth)))) |
Geoff Lang | ce63569 | 2013-09-24 13:56:32 -0400 | [diff] [blame] | 1564 | { |
| 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | if (!ValidMipLevel(context, target, level)) |
| 1569 | { |
| 1570 | return false; |
| 1571 | } |
| 1572 | |
| 1573 | return true; |
| 1574 | } |
| 1575 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 1576 | bool CompressedTextureFormatRequiresExactSize(GLenum internalFormat) |
| 1577 | { |
| 1578 | // List of compressed format that require that the texture size is smaller than or a multiple of |
| 1579 | // the compressed block size. |
| 1580 | switch (internalFormat) |
| 1581 | { |
| 1582 | case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: |
| 1583 | case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: |
| 1584 | case GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE: |
| 1585 | case GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE: |
Minmin Gong | e3939b9 | 2015-12-01 15:36:51 -0800 | [diff] [blame] | 1586 | case GL_ETC1_RGB8_LOSSY_DECODE_ANGLE: |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 1587 | return true; |
| 1588 | |
| 1589 | default: |
| 1590 | return false; |
| 1591 | } |
| 1592 | } |
| 1593 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1594 | bool ValidCompressedImageSize(const ValidationContext *context, |
| 1595 | GLenum internalFormat, |
| 1596 | GLsizei width, |
| 1597 | GLsizei height) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 1598 | { |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1599 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat); |
| 1600 | if (!formatInfo.compressed) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 1601 | { |
| 1602 | return false; |
| 1603 | } |
| 1604 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 1605 | if (width < 0 || height < 0) |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 1606 | { |
| 1607 | return false; |
| 1608 | } |
| 1609 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 1610 | if (CompressedTextureFormatRequiresExactSize(internalFormat)) |
| 1611 | { |
| 1612 | if ((static_cast<GLuint>(width) > formatInfo.compressedBlockWidth && |
| 1613 | width % formatInfo.compressedBlockWidth != 0) || |
| 1614 | (static_cast<GLuint>(height) > formatInfo.compressedBlockHeight && |
| 1615 | height % formatInfo.compressedBlockHeight != 0)) |
| 1616 | { |
| 1617 | return false; |
| 1618 | } |
| 1619 | } |
| 1620 | |
Geoff Lang | d4f180b | 2013-09-24 13:57:44 -0400 | [diff] [blame] | 1621 | return true; |
| 1622 | } |
| 1623 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1624 | bool ValidImageDataSize(ValidationContext *context, |
| 1625 | GLenum textureTarget, |
| 1626 | GLsizei width, |
| 1627 | GLsizei height, |
| 1628 | GLsizei depth, |
| 1629 | GLenum internalFormat, |
| 1630 | GLenum type, |
| 1631 | const GLvoid *pixels, |
| 1632 | GLsizei imageSize) |
| 1633 | { |
| 1634 | gl::Buffer *pixelUnpackBuffer = context->getGLState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER); |
| 1635 | if (pixelUnpackBuffer == nullptr && imageSize < 0) |
| 1636 | { |
| 1637 | // Checks are not required |
| 1638 | return true; |
| 1639 | } |
| 1640 | |
| 1641 | // ...the data would be unpacked from the buffer object such that the memory reads required |
| 1642 | // would exceed the data store size. |
| 1643 | GLenum sizedFormat = GetSizedInternalFormat(internalFormat, type); |
| 1644 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(sizedFormat); |
| 1645 | const gl::Extents size(width, height, depth); |
| 1646 | const auto &unpack = context->getGLState().getUnpackState(); |
| 1647 | |
| 1648 | bool targetIs3D = textureTarget == GL_TEXTURE_3D || textureTarget == GL_TEXTURE_2D_ARRAY; |
| 1649 | auto endByteOrErr = formatInfo.computePackUnpackEndByte(type, size, unpack, targetIs3D); |
| 1650 | if (endByteOrErr.isError()) |
| 1651 | { |
| 1652 | context->handleError(endByteOrErr.getError()); |
| 1653 | return false; |
| 1654 | } |
| 1655 | |
| 1656 | GLuint endByte = endByteOrErr.getResult(); |
| 1657 | |
| 1658 | if (pixelUnpackBuffer) |
| 1659 | { |
| 1660 | CheckedNumeric<size_t> checkedEndByte(endByteOrErr.getResult()); |
| 1661 | CheckedNumeric<size_t> checkedOffset(reinterpret_cast<size_t>(pixels)); |
| 1662 | checkedEndByte += checkedOffset; |
| 1663 | |
| 1664 | if (!checkedEndByte.IsValid() || |
| 1665 | (checkedEndByte.ValueOrDie() > static_cast<size_t>(pixelUnpackBuffer->getSize()))) |
| 1666 | { |
| 1667 | // Overflow past the end of the buffer |
| 1668 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 1669 | return false; |
| 1670 | } |
| 1671 | } |
| 1672 | else |
| 1673 | { |
| 1674 | ASSERT(imageSize >= 0); |
| 1675 | if (pixels == nullptr && imageSize != 0) |
| 1676 | { |
| 1677 | context->handleError( |
| 1678 | 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] | 1679 | return false; |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Geoff Lang | 3feb3ff | 2016-10-26 10:57:45 -0400 | [diff] [blame] | 1682 | if (pixels != nullptr && endByte > static_cast<GLuint>(imageSize)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 1683 | { |
| 1684 | context->handleError( |
| 1685 | Error(GL_INVALID_OPERATION, "imageSize must be at least %u.", endByte)); |
| 1686 | return false; |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | return true; |
| 1691 | } |
| 1692 | |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1693 | bool ValidQueryType(const Context *context, GLenum queryType) |
| 1694 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1695 | static_assert(GL_ANY_SAMPLES_PASSED == GL_ANY_SAMPLES_PASSED_EXT, |
| 1696 | "GL extension enums not equal."); |
| 1697 | static_assert(GL_ANY_SAMPLES_PASSED_CONSERVATIVE == GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 1698 | "GL extension enums not equal."); |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1699 | |
| 1700 | switch (queryType) |
| 1701 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1702 | case GL_ANY_SAMPLES_PASSED: |
| 1703 | case GL_ANY_SAMPLES_PASSED_CONSERVATIVE: |
| 1704 | return true; |
| 1705 | case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: |
| 1706 | return (context->getClientMajorVersion() >= 3); |
| 1707 | case GL_TIME_ELAPSED_EXT: |
| 1708 | return context->getExtensions().disjointTimerQuery; |
| 1709 | case GL_COMMANDS_COMPLETED_CHROMIUM: |
| 1710 | return context->getExtensions().syncQuery; |
| 1711 | default: |
| 1712 | return false; |
Geoff Lang | 37dde69 | 2014-01-31 16:34:54 -0500 | [diff] [blame] | 1713 | } |
| 1714 | } |
| 1715 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 1716 | Program *GetValidProgram(ValidationContext *context, GLuint id) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1717 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1718 | // ES3 spec (section 2.11.1) -- "Commands that accept shader or program object names will |
| 1719 | // generate the error INVALID_VALUE if the provided name is not the name of either a shader |
| 1720 | // or program object and INVALID_OPERATION if the provided name identifies an object |
| 1721 | // that is not the expected type." |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1722 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1723 | Program *validProgram = context->getProgram(id); |
| 1724 | |
| 1725 | if (!validProgram) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1726 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1727 | if (context->getShader(id)) |
| 1728 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1729 | context->handleError( |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1730 | Error(GL_INVALID_OPERATION, "Expected a program name, but found a shader name")); |
| 1731 | } |
| 1732 | else |
| 1733 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1734 | context->handleError(Error(GL_INVALID_VALUE, "Program name is not valid")); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1735 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1736 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1737 | |
| 1738 | return validProgram; |
| 1739 | } |
| 1740 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 1741 | Shader *GetValidShader(ValidationContext *context, GLuint id) |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1742 | { |
| 1743 | // See ValidProgram for spec details. |
| 1744 | |
| 1745 | Shader *validShader = context->getShader(id); |
| 1746 | |
| 1747 | if (!validShader) |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1748 | { |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1749 | if (context->getProgram(id)) |
| 1750 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1751 | context->handleError( |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1752 | Error(GL_INVALID_OPERATION, "Expected a shader name, but found a program name")); |
| 1753 | } |
| 1754 | else |
| 1755 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1756 | context->handleError(Error(GL_INVALID_VALUE, "Shader name is invalid")); |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1757 | } |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1758 | } |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 1759 | |
| 1760 | return validShader; |
Geoff Lang | 48dcae7 | 2014-02-05 16:28:24 -0500 | [diff] [blame] | 1761 | } |
| 1762 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1763 | bool ValidateAttachmentTarget(gl::Context *context, GLenum attachment) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1764 | { |
| 1765 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 1766 | { |
| 1767 | const unsigned int colorAttachment = (attachment - GL_COLOR_ATTACHMENT0_EXT); |
| 1768 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1769 | if (colorAttachment >= context->getCaps().maxColorAttachments) |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1770 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1771 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1772 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1773 | } |
| 1774 | } |
| 1775 | else |
| 1776 | { |
| 1777 | switch (attachment) |
| 1778 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1779 | case GL_DEPTH_ATTACHMENT: |
| 1780 | case GL_STENCIL_ATTACHMENT: |
| 1781 | break; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1782 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1783 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 1784 | if (!context->getExtensions().webglCompatibility && |
| 1785 | context->getClientMajorVersion() < 3) |
| 1786 | { |
| 1787 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1788 | return false; |
| 1789 | } |
| 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 | default: |
| 1793 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1794 | return false; |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1795 | } |
| 1796 | } |
| 1797 | |
| 1798 | return true; |
| 1799 | } |
| 1800 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1801 | bool ValidateRenderbufferStorageParametersBase(gl::Context *context, |
| 1802 | GLenum target, |
| 1803 | GLsizei samples, |
| 1804 | GLenum internalformat, |
| 1805 | GLsizei width, |
| 1806 | GLsizei height) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1807 | { |
| 1808 | switch (target) |
| 1809 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1810 | case GL_RENDERBUFFER: |
| 1811 | break; |
| 1812 | default: |
| 1813 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1814 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1815 | } |
| 1816 | |
| 1817 | if (width < 0 || height < 0 || samples < 0) |
| 1818 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1819 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1820 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1821 | } |
| 1822 | |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 1823 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1824 | if (!formatCaps.renderable) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1825 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1826 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1827 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1828 | } |
| 1829 | |
| 1830 | // ANGLE_framebuffer_multisample does not explicitly state that the internal format must be |
| 1831 | // 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] | 1832 | // only sized internal formats. |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 1833 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 1834 | if (formatInfo.pixelBytes == 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1835 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1836 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1837 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1838 | } |
| 1839 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 1840 | if (static_cast<GLuint>(std::max(width, height)) > context->getCaps().maxRenderbufferSize) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1841 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1842 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1843 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1844 | } |
| 1845 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1846 | GLuint handle = context->getGLState().getRenderbufferId(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1847 | if (handle == 0) |
| 1848 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1849 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1850 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | return true; |
| 1854 | } |
| 1855 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1856 | bool ValidateRenderbufferStorageParametersANGLE(gl::Context *context, |
| 1857 | GLenum target, |
| 1858 | GLsizei samples, |
| 1859 | GLenum internalformat, |
| 1860 | GLsizei width, |
| 1861 | GLsizei height) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1862 | { |
Austin Kinross | d2cf3ad | 2015-01-07 14:00:30 -0800 | [diff] [blame] | 1863 | ASSERT(samples == 0 || context->getExtensions().framebufferMultisample); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1864 | |
| 1865 | // 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] | 1866 | // to MAX_SAMPLES_ANGLE (Context::getCaps().maxSamples) otherwise GL_INVALID_VALUE is |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1867 | // generated. |
Geoff Lang | def624b | 2015-04-13 10:46:56 -0400 | [diff] [blame] | 1868 | if (static_cast<GLuint>(samples) > context->getCaps().maxSamples) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1869 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1870 | context->handleError(Error(GL_INVALID_VALUE)); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1871 | return false; |
| 1872 | } |
| 1873 | |
| 1874 | // ANGLE_framebuffer_multisample states GL_OUT_OF_MEMORY is generated on a failure to create |
| 1875 | // the specified storage. This is different than ES 3.0 in which a sample number higher |
| 1876 | // 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] | 1877 | // 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] | 1878 | if (context->getClientMajorVersion() >= 3) |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1879 | { |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 1880 | const TextureCaps &formatCaps = context->getTextureCaps().get(internalformat); |
| 1881 | if (static_cast<GLuint>(samples) > formatCaps.getMaxSamples()) |
| 1882 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1883 | context->handleError(Error(GL_OUT_OF_MEMORY)); |
Geoff Lang | a4903b7 | 2015-03-02 16:02:48 -0800 | [diff] [blame] | 1884 | return false; |
| 1885 | } |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1886 | } |
| 1887 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1888 | return ValidateRenderbufferStorageParametersBase(context, target, samples, internalformat, |
| 1889 | width, height); |
Corentin Wallez | e090264 | 2014-11-04 12:32:15 -0800 | [diff] [blame] | 1890 | } |
| 1891 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1892 | bool ValidateFramebufferRenderbufferParameters(gl::Context *context, |
| 1893 | GLenum target, |
| 1894 | GLenum attachment, |
| 1895 | GLenum renderbuffertarget, |
| 1896 | GLuint renderbuffer) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1897 | { |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1898 | if (!ValidFramebufferTarget(target)) |
| 1899 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1900 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1901 | return false; |
Shannon Woods | 1da3cf6 | 2014-06-27 15:32:23 -0400 | [diff] [blame] | 1902 | } |
| 1903 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1904 | gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1905 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 1906 | ASSERT(framebuffer); |
| 1907 | if (framebuffer->id() == 0) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1908 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1909 | context->handleError( |
| 1910 | Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1911 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1912 | } |
| 1913 | |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1914 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1915 | { |
Jamie Madill | b447227 | 2014-07-03 10:38:55 -0400 | [diff] [blame] | 1916 | return false; |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1917 | } |
| 1918 | |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1919 | // [OpenGL ES 2.0.25] Section 4.4.3 page 112 |
| 1920 | // [OpenGL ES 3.0.2] Section 4.4.2 page 201 |
| 1921 | // 'renderbuffer' must be either zero or the name of an existing renderbuffer object of |
| 1922 | // type 'renderbuffertarget', otherwise an INVALID_OPERATION error is generated. |
| 1923 | if (renderbuffer != 0) |
| 1924 | { |
| 1925 | if (!context->getRenderbuffer(renderbuffer)) |
| 1926 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1927 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1928 | return false; |
Jamie Madill | ab9d82c | 2014-01-21 16:38:14 -0500 | [diff] [blame] | 1929 | } |
| 1930 | } |
| 1931 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1932 | return true; |
| 1933 | } |
| 1934 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1935 | bool ValidateBlitFramebufferParameters(ValidationContext *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1936 | GLint srcX0, |
| 1937 | GLint srcY0, |
| 1938 | GLint srcX1, |
| 1939 | GLint srcY1, |
| 1940 | GLint dstX0, |
| 1941 | GLint dstY0, |
| 1942 | GLint dstX1, |
| 1943 | GLint dstY1, |
| 1944 | GLbitfield mask, |
| 1945 | GLenum filter) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1946 | { |
| 1947 | switch (filter) |
| 1948 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 1949 | case GL_NEAREST: |
| 1950 | break; |
| 1951 | case GL_LINEAR: |
| 1952 | break; |
| 1953 | default: |
| 1954 | context->handleError(Error(GL_INVALID_ENUM)); |
| 1955 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | if ((mask & ~(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)) != 0) |
| 1959 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1960 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1961 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1962 | } |
| 1963 | |
| 1964 | if (mask == 0) |
| 1965 | { |
| 1966 | // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no |
| 1967 | // buffers are copied. |
| 1968 | return false; |
| 1969 | } |
| 1970 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1971 | // ES3.0 spec, section 4.3.2 states that linear filtering is only available for the |
| 1972 | // color buffer, leaving only nearest being unfiltered from above |
| 1973 | if ((mask & ~GL_COLOR_BUFFER_BIT) != 0 && filter != GL_NEAREST) |
| 1974 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1975 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1976 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1977 | } |
| 1978 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1979 | const auto &glState = context->getGLState(); |
| 1980 | gl::Framebuffer *readFramebuffer = glState.getReadFramebuffer(); |
| 1981 | gl::Framebuffer *drawFramebuffer = glState.getDrawFramebuffer(); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1982 | |
| 1983 | if (!readFramebuffer || !drawFramebuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1984 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1985 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 1986 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 1987 | } |
| 1988 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1989 | if (readFramebuffer->id() == drawFramebuffer->id()) |
| 1990 | { |
| 1991 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 1992 | return false; |
| 1993 | } |
| 1994 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 1995 | if (readFramebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1996 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1997 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1998 | return false; |
| 1999 | } |
| 2000 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2001 | if (drawFramebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 2002 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2003 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 2004 | return false; |
| 2005 | } |
| 2006 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2007 | if (drawFramebuffer->getSamples(context->getContextState()) != 0) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2008 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2009 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2010 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2011 | } |
| 2012 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2013 | bool sameBounds = srcX0 == dstX0 && srcY0 == dstY0 && srcX1 == dstX1 && srcY1 == dstY1; |
| 2014 | |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2015 | if (mask & GL_COLOR_BUFFER_BIT) |
| 2016 | { |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 2017 | const gl::FramebufferAttachment *readColorBuffer = readFramebuffer->getReadColorbuffer(); |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 2018 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2019 | |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2020 | if (readColorBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2021 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2022 | const Format &readFormat = readColorBuffer->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2023 | |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2024 | for (size_t drawbufferIdx = 0; |
| 2025 | drawbufferIdx < drawFramebuffer->getDrawbufferStateCount(); ++drawbufferIdx) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2026 | { |
Geoff Lang | a15472a | 2015-08-11 11:48:03 -0400 | [diff] [blame] | 2027 | const FramebufferAttachment *attachment = |
| 2028 | drawFramebuffer->getDrawBuffer(drawbufferIdx); |
| 2029 | if (attachment) |
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 &drawFormat = attachment->getFormat(); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2032 | |
Geoff Lang | b2f3d05 | 2013-08-13 12:49:27 -0400 | [diff] [blame] | 2033 | // The GL ES 3.0.2 spec (pg 193) states that: |
| 2034 | // 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] | 2035 | // 2) If the read buffer is an unsigned integer format, the draw buffer must be |
| 2036 | // as well |
| 2037 | // 3) If the read buffer is a signed integer format, the draw buffer must be as |
| 2038 | // well |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 2039 | // Changes with EXT_color_buffer_float: |
| 2040 | // Case 1) is changed to fixed point OR floating point |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2041 | GLenum readComponentType = readFormat.info->componentType; |
| 2042 | GLenum drawComponentType = drawFormat.info->componentType; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2043 | bool readFixedPoint = (readComponentType == GL_UNSIGNED_NORMALIZED || |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 2044 | readComponentType == GL_SIGNED_NORMALIZED); |
| 2045 | bool drawFixedPoint = (drawComponentType == GL_UNSIGNED_NORMALIZED || |
| 2046 | drawComponentType == GL_SIGNED_NORMALIZED); |
| 2047 | |
| 2048 | if (extensions.colorBufferFloat) |
| 2049 | { |
| 2050 | bool readFixedOrFloat = (readFixedPoint || readComponentType == GL_FLOAT); |
| 2051 | bool drawFixedOrFloat = (drawFixedPoint || drawComponentType == GL_FLOAT); |
| 2052 | |
| 2053 | if (readFixedOrFloat != drawFixedOrFloat) |
| 2054 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2055 | context->handleError(Error(GL_INVALID_OPERATION, |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 2056 | "If the read buffer contains fixed-point or " |
| 2057 | "floating-point values, the draw buffer " |
| 2058 | "must as well.")); |
| 2059 | return false; |
| 2060 | } |
| 2061 | } |
| 2062 | else if (readFixedPoint != drawFixedPoint) |
| 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 " |
| 2066 | "values, the draw buffer must as well.")); |
| 2067 | return false; |
| 2068 | } |
| 2069 | |
| 2070 | if (readComponentType == GL_UNSIGNED_INT && |
| 2071 | drawComponentType != GL_UNSIGNED_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2072 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2073 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2074 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2075 | } |
| 2076 | |
Jamie Madill | 6163c75 | 2015-12-07 16:32:59 -0500 | [diff] [blame] | 2077 | if (readComponentType == GL_INT && drawComponentType != GL_INT) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2078 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2079 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2080 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2081 | } |
| 2082 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2083 | if (readColorBuffer->getSamples() > 0 && |
| 2084 | (!Format::SameSized(readFormat, drawFormat) || !sameBounds)) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2085 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2086 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2087 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | } |
| 2091 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2092 | if ((readFormat.info->componentType == GL_INT || |
| 2093 | readFormat.info->componentType == GL_UNSIGNED_INT) && |
| 2094 | filter == GL_LINEAR) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2095 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2096 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2097 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2098 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2099 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2100 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 2101 | // In OpenGL ES it is undefined what happens when an operation tries to blit from a missing |
| 2102 | // attachment and WebGL defines it to be an error. We do the check unconditionally as the |
| 2103 | // situation is an application error that would lead to a crash in ANGLE. |
| 2104 | else if (drawFramebuffer->hasEnabledDrawBuffer()) |
| 2105 | { |
| 2106 | context->handleError(Error( |
| 2107 | GL_INVALID_OPERATION, |
| 2108 | "Attempt to read from a missing color attachment of a complete framebuffer.")); |
| 2109 | return false; |
| 2110 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2111 | } |
| 2112 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2113 | GLenum masks[] = {GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT}; |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 2114 | GLenum attachments[] = {GL_DEPTH_ATTACHMENT, GL_STENCIL_ATTACHMENT}; |
| 2115 | for (size_t i = 0; i < 2; i++) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2116 | { |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 2117 | if (mask & masks[i]) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2118 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2119 | const gl::FramebufferAttachment *readBuffer = |
| 2120 | readFramebuffer->getAttachment(attachments[i]); |
| 2121 | const gl::FramebufferAttachment *drawBuffer = |
| 2122 | drawFramebuffer->getAttachment(attachments[i]); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2123 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 2124 | if (readBuffer && drawBuffer) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2125 | { |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 2126 | if (!Format::SameSized(readBuffer->getFormat(), drawBuffer->getFormat())) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2127 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2128 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2129 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2130 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2131 | |
Dongseong Hwang | 44b422c | 2014-12-09 15:42:01 +0200 | [diff] [blame] | 2132 | if (readBuffer->getSamples() > 0 && !sameBounds) |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2133 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2134 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2135 | return false; |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2136 | } |
| 2137 | } |
He Yunchao | 66a41a2 | 2016-12-15 16:45:05 +0800 | [diff] [blame] | 2138 | // WebGL 2.0 BlitFramebuffer when blitting from a missing attachment |
| 2139 | else if (drawBuffer) |
| 2140 | { |
| 2141 | context->handleError(Error(GL_INVALID_OPERATION, |
| 2142 | "Attempt to read from a missing depth/stencil " |
| 2143 | "attachment of a complete framebuffer.")); |
| 2144 | return false; |
| 2145 | } |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 2146 | } |
| 2147 | } |
| 2148 | |
| 2149 | return true; |
| 2150 | } |
| 2151 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2152 | bool ValidateReadPixels(ValidationContext *context, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2153 | GLint x, |
| 2154 | GLint y, |
| 2155 | GLsizei width, |
| 2156 | GLsizei height, |
| 2157 | GLenum format, |
| 2158 | GLenum type, |
| 2159 | GLvoid *pixels) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2160 | { |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2161 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, -1, nullptr, pixels); |
| 2162 | } |
| 2163 | |
| 2164 | bool ValidateReadPixelsRobustANGLE(ValidationContext *context, |
| 2165 | GLint x, |
| 2166 | GLint y, |
| 2167 | GLsizei width, |
| 2168 | GLsizei height, |
| 2169 | GLenum format, |
| 2170 | GLenum type, |
| 2171 | GLsizei bufSize, |
| 2172 | GLsizei *length, |
| 2173 | GLvoid *pixels) |
| 2174 | { |
| 2175 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2176 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2177 | return false; |
| 2178 | } |
| 2179 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2180 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length, |
| 2181 | pixels)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2182 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2183 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2184 | } |
| 2185 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2186 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2187 | { |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2188 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2189 | } |
| 2190 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2191 | return true; |
| 2192 | } |
| 2193 | |
| 2194 | bool ValidateReadnPixelsEXT(Context *context, |
| 2195 | GLint x, |
| 2196 | GLint y, |
| 2197 | GLsizei width, |
| 2198 | GLsizei height, |
| 2199 | GLenum format, |
| 2200 | GLenum type, |
| 2201 | GLsizei bufSize, |
| 2202 | GLvoid *pixels) |
| 2203 | { |
| 2204 | if (bufSize < 0) |
| 2205 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2206 | context->handleError(Error(GL_INVALID_VALUE, "bufSize must be a positive number")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2207 | return false; |
| 2208 | } |
| 2209 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2210 | return ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, nullptr, |
| 2211 | pixels); |
| 2212 | } |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2213 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2214 | bool ValidateReadnPixelsRobustANGLE(ValidationContext *context, |
| 2215 | GLint x, |
| 2216 | GLint y, |
| 2217 | GLsizei width, |
| 2218 | GLsizei height, |
| 2219 | GLenum format, |
| 2220 | GLenum type, |
| 2221 | GLsizei bufSize, |
| 2222 | GLsizei *length, |
| 2223 | GLvoid *data) |
| 2224 | { |
| 2225 | if (!ValidateRobustEntryPoint(context, bufSize)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2226 | { |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2227 | return false; |
| 2228 | } |
| 2229 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2230 | if (!ValidateReadPixelsBase(context, x, y, width, height, format, type, bufSize, length, data)) |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 2231 | { |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2232 | return false; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2233 | } |
| 2234 | |
Geoff Lang | 62fce5b | 2016-09-30 10:46:35 -0400 | [diff] [blame] | 2235 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2236 | { |
| 2237 | return false; |
| 2238 | } |
| 2239 | |
| 2240 | return true; |
Jamie Madill | 26e9195 | 2014-03-05 15:01:27 -0500 | [diff] [blame] | 2241 | } |
| 2242 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2243 | bool ValidateGenQueriesEXT(gl::Context *context, GLsizei n) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2244 | { |
| 2245 | if (!context->getExtensions().occlusionQueryBoolean && |
| 2246 | !context->getExtensions().disjointTimerQuery) |
| 2247 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2248 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2249 | return false; |
| 2250 | } |
| 2251 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2252 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2253 | } |
| 2254 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2255 | bool ValidateDeleteQueriesEXT(gl::Context *context, GLsizei n) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2256 | { |
| 2257 | if (!context->getExtensions().occlusionQueryBoolean && |
| 2258 | !context->getExtensions().disjointTimerQuery) |
| 2259 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2260 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2261 | return false; |
| 2262 | } |
| 2263 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 2264 | return ValidateGenOrDelete(context, n); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2265 | } |
| 2266 | |
| 2267 | bool ValidateBeginQueryBase(gl::Context *context, GLenum target, GLuint id) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2268 | { |
| 2269 | if (!ValidQueryType(context, target)) |
| 2270 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2271 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2272 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | if (id == 0) |
| 2276 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2277 | context->handleError(Error(GL_INVALID_OPERATION, "Query id is 0")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2278 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | // From EXT_occlusion_query_boolean: If BeginQueryEXT is called with an <id> |
| 2282 | // of zero, if the active query object name for <target> is non-zero (for the |
| 2283 | // targets ANY_SAMPLES_PASSED_EXT and ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, if |
| 2284 | // the active query for either target is non-zero), if <id> is the name of an |
| 2285 | // existing query object whose type does not match <target>, or if <id> is the |
| 2286 | // active query object name for any query type, the error INVALID_OPERATION is |
| 2287 | // generated. |
| 2288 | |
| 2289 | // Ensure no other queries are active |
| 2290 | // NOTE: If other queries than occlusion are supported, we will need to check |
| 2291 | // separately that: |
| 2292 | // a) The query ID passed is not the current active query for any target/type |
| 2293 | // b) There are no active queries for the requested target (and in the case |
| 2294 | // of GL_ANY_SAMPLES_PASSED_EXT and GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, |
| 2295 | // no query may be active for either if glBeginQuery targets either. |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2296 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2297 | if (context->getGLState().isQueryActive(target)) |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2298 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2299 | context->handleError(Error(GL_INVALID_OPERATION, "Other query is active")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2300 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
| 2303 | Query *queryObject = context->getQuery(id, true, target); |
| 2304 | |
| 2305 | // check that name was obtained with glGenQueries |
| 2306 | if (!queryObject) |
| 2307 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2308 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id")); |
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 | // check for type mismatch |
| 2313 | if (queryObject->getType() != target) |
| 2314 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2315 | context->handleError(Error(GL_INVALID_OPERATION, "Query type does not match target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2316 | return false; |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | return true; |
| 2320 | } |
| 2321 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2322 | bool ValidateBeginQueryEXT(gl::Context *context, GLenum target, GLuint id) |
| 2323 | { |
| 2324 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 2325 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2326 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2327 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2328 | return false; |
| 2329 | } |
| 2330 | |
| 2331 | return ValidateBeginQueryBase(context, target, id); |
| 2332 | } |
| 2333 | |
| 2334 | bool ValidateEndQueryBase(gl::Context *context, GLenum target) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2335 | { |
| 2336 | if (!ValidQueryType(context, target)) |
| 2337 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2338 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2339 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2340 | } |
| 2341 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2342 | const Query *queryObject = context->getGLState().getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2343 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2344 | if (queryObject == nullptr) |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2345 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2346 | context->handleError(Error(GL_INVALID_OPERATION, "Query target not active")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2347 | return false; |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2348 | } |
| 2349 | |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 2350 | return true; |
| 2351 | } |
| 2352 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2353 | bool ValidateEndQueryEXT(gl::Context *context, GLenum target) |
| 2354 | { |
| 2355 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 2356 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2357 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2358 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2359 | return false; |
| 2360 | } |
| 2361 | |
| 2362 | return ValidateEndQueryBase(context, target); |
| 2363 | } |
| 2364 | |
| 2365 | bool ValidateQueryCounterEXT(Context *context, GLuint id, GLenum target) |
| 2366 | { |
| 2367 | if (!context->getExtensions().disjointTimerQuery) |
| 2368 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2369 | context->handleError(Error(GL_INVALID_OPERATION, "Disjoint timer query not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2370 | return false; |
| 2371 | } |
| 2372 | |
| 2373 | if (target != GL_TIMESTAMP_EXT) |
| 2374 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2375 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query target")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2376 | return false; |
| 2377 | } |
| 2378 | |
| 2379 | Query *queryObject = context->getQuery(id, true, target); |
| 2380 | if (queryObject == nullptr) |
| 2381 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2382 | context->handleError(Error(GL_INVALID_OPERATION, "Invalid query id")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2383 | return false; |
| 2384 | } |
| 2385 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2386 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2387 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2388 | context->handleError(Error(GL_INVALID_OPERATION, "Query is active")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2389 | return false; |
| 2390 | } |
| 2391 | |
| 2392 | return true; |
| 2393 | } |
| 2394 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2395 | bool ValidateGetQueryivBase(Context *context, GLenum target, GLenum pname, GLsizei *numParams) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2396 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2397 | if (numParams) |
| 2398 | { |
| 2399 | *numParams = 0; |
| 2400 | } |
| 2401 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2402 | if (!ValidQueryType(context, target) && target != GL_TIMESTAMP_EXT) |
| 2403 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2404 | context->handleError(Error(GL_INVALID_ENUM, "Invalid query type")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2405 | return false; |
| 2406 | } |
| 2407 | |
| 2408 | switch (pname) |
| 2409 | { |
| 2410 | case GL_CURRENT_QUERY_EXT: |
| 2411 | if (target == GL_TIMESTAMP_EXT) |
| 2412 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2413 | context->handleError( |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2414 | Error(GL_INVALID_ENUM, "Cannot use current query for timestamp")); |
| 2415 | return false; |
| 2416 | } |
| 2417 | break; |
| 2418 | case GL_QUERY_COUNTER_BITS_EXT: |
| 2419 | if (!context->getExtensions().disjointTimerQuery || |
| 2420 | (target != GL_TIMESTAMP_EXT && target != GL_TIME_ELAPSED_EXT)) |
| 2421 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2422 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2423 | return false; |
| 2424 | } |
| 2425 | break; |
| 2426 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2427 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2428 | return false; |
| 2429 | } |
| 2430 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2431 | if (numParams) |
| 2432 | { |
| 2433 | // All queries return only one value |
| 2434 | *numParams = 1; |
| 2435 | } |
| 2436 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2437 | return true; |
| 2438 | } |
| 2439 | |
| 2440 | bool ValidateGetQueryivEXT(Context *context, GLenum target, GLenum pname, GLint *params) |
| 2441 | { |
| 2442 | if (!context->getExtensions().occlusionQueryBoolean && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 2443 | !context->getExtensions().disjointTimerQuery && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2444 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2445 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2446 | return false; |
| 2447 | } |
| 2448 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2449 | return ValidateGetQueryivBase(context, target, pname, nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2450 | } |
| 2451 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2452 | bool ValidateGetQueryivRobustANGLE(Context *context, |
| 2453 | GLenum target, |
| 2454 | GLenum pname, |
| 2455 | GLsizei bufSize, |
| 2456 | GLsizei *length, |
| 2457 | GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2458 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2459 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2460 | { |
| 2461 | return false; |
| 2462 | } |
| 2463 | |
| 2464 | if (!ValidateGetQueryivBase(context, target, pname, length)) |
| 2465 | { |
| 2466 | return false; |
| 2467 | } |
| 2468 | |
| 2469 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2470 | { |
| 2471 | return false; |
| 2472 | } |
| 2473 | |
| 2474 | return true; |
| 2475 | } |
| 2476 | |
| 2477 | bool ValidateGetQueryObjectValueBase(Context *context, GLuint id, GLenum pname, GLsizei *numParams) |
| 2478 | { |
| 2479 | if (numParams) |
| 2480 | { |
| 2481 | *numParams = 0; |
| 2482 | } |
| 2483 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2484 | Query *queryObject = context->getQuery(id, false, GL_NONE); |
| 2485 | |
| 2486 | if (!queryObject) |
| 2487 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2488 | context->handleError(Error(GL_INVALID_OPERATION, "Query does not exist")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2489 | return false; |
| 2490 | } |
| 2491 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2492 | if (context->getGLState().isQueryActive(queryObject)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2493 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2494 | context->handleError(Error(GL_INVALID_OPERATION, "Query currently active")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2495 | return false; |
| 2496 | } |
| 2497 | |
| 2498 | switch (pname) |
| 2499 | { |
| 2500 | case GL_QUERY_RESULT_EXT: |
| 2501 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 2502 | break; |
| 2503 | |
| 2504 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2505 | context->handleError(Error(GL_INVALID_ENUM, "Invalid pname enum")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2506 | return false; |
| 2507 | } |
| 2508 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2509 | if (numParams) |
| 2510 | { |
| 2511 | *numParams = 1; |
| 2512 | } |
| 2513 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2514 | return true; |
| 2515 | } |
| 2516 | |
| 2517 | bool ValidateGetQueryObjectivEXT(Context *context, GLuint id, GLenum pname, GLint *params) |
| 2518 | { |
| 2519 | if (!context->getExtensions().disjointTimerQuery) |
| 2520 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2521 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2522 | return false; |
| 2523 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2524 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2525 | } |
| 2526 | |
| 2527 | bool ValidateGetQueryObjectivRobustANGLE(Context *context, |
| 2528 | GLuint id, |
| 2529 | GLenum pname, |
| 2530 | GLsizei bufSize, |
| 2531 | GLsizei *length, |
| 2532 | GLint *params) |
| 2533 | { |
| 2534 | if (!context->getExtensions().disjointTimerQuery) |
| 2535 | { |
| 2536 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
| 2537 | return false; |
| 2538 | } |
| 2539 | |
| 2540 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2541 | { |
| 2542 | return false; |
| 2543 | } |
| 2544 | |
| 2545 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 2546 | { |
| 2547 | return false; |
| 2548 | } |
| 2549 | |
| 2550 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2551 | { |
| 2552 | return false; |
| 2553 | } |
| 2554 | |
| 2555 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2556 | } |
| 2557 | |
| 2558 | bool ValidateGetQueryObjectuivEXT(Context *context, GLuint id, GLenum pname, GLuint *params) |
| 2559 | { |
| 2560 | if (!context->getExtensions().disjointTimerQuery && |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 2561 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2562 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2563 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2564 | return false; |
| 2565 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2566 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2567 | } |
| 2568 | |
| 2569 | bool ValidateGetQueryObjectuivRobustANGLE(Context *context, |
| 2570 | GLuint id, |
| 2571 | GLenum pname, |
| 2572 | GLsizei bufSize, |
| 2573 | GLsizei *length, |
| 2574 | GLuint *params) |
| 2575 | { |
| 2576 | if (!context->getExtensions().disjointTimerQuery && |
| 2577 | !context->getExtensions().occlusionQueryBoolean && !context->getExtensions().syncQuery) |
| 2578 | { |
| 2579 | context->handleError(Error(GL_INVALID_OPERATION, "Query extension not enabled")); |
| 2580 | return false; |
| 2581 | } |
| 2582 | |
| 2583 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2584 | { |
| 2585 | return false; |
| 2586 | } |
| 2587 | |
| 2588 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 2589 | { |
| 2590 | return false; |
| 2591 | } |
| 2592 | |
| 2593 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2594 | { |
| 2595 | return false; |
| 2596 | } |
| 2597 | |
| 2598 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | bool ValidateGetQueryObjecti64vEXT(Context *context, GLuint id, GLenum pname, GLint64 *params) |
| 2602 | { |
| 2603 | if (!context->getExtensions().disjointTimerQuery) |
| 2604 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2605 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2606 | return false; |
| 2607 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2608 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2609 | } |
| 2610 | |
| 2611 | bool ValidateGetQueryObjecti64vRobustANGLE(Context *context, |
| 2612 | GLuint id, |
| 2613 | GLenum pname, |
| 2614 | GLsizei bufSize, |
| 2615 | GLsizei *length, |
| 2616 | GLint64 *params) |
| 2617 | { |
| 2618 | if (!context->getExtensions().disjointTimerQuery) |
| 2619 | { |
| 2620 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
| 2621 | return false; |
| 2622 | } |
| 2623 | |
| 2624 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2625 | { |
| 2626 | return false; |
| 2627 | } |
| 2628 | |
| 2629 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 2630 | { |
| 2631 | return false; |
| 2632 | } |
| 2633 | |
| 2634 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2635 | { |
| 2636 | return false; |
| 2637 | } |
| 2638 | |
| 2639 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | bool ValidateGetQueryObjectui64vEXT(Context *context, GLuint id, GLenum pname, GLuint64 *params) |
| 2643 | { |
| 2644 | if (!context->getExtensions().disjointTimerQuery) |
| 2645 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2646 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2647 | return false; |
| 2648 | } |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 2649 | return ValidateGetQueryObjectValueBase(context, id, pname, nullptr); |
| 2650 | } |
| 2651 | |
| 2652 | bool ValidateGetQueryObjectui64vRobustANGLE(Context *context, |
| 2653 | GLuint id, |
| 2654 | GLenum pname, |
| 2655 | GLsizei bufSize, |
| 2656 | GLsizei *length, |
| 2657 | GLuint64 *params) |
| 2658 | { |
| 2659 | if (!context->getExtensions().disjointTimerQuery) |
| 2660 | { |
| 2661 | context->handleError(Error(GL_INVALID_OPERATION, "Timer query extension not enabled")); |
| 2662 | return false; |
| 2663 | } |
| 2664 | |
| 2665 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2666 | { |
| 2667 | return false; |
| 2668 | } |
| 2669 | |
| 2670 | if (!ValidateGetQueryObjectValueBase(context, id, pname, length)) |
| 2671 | { |
| 2672 | return false; |
| 2673 | } |
| 2674 | |
| 2675 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 2676 | { |
| 2677 | return false; |
| 2678 | } |
| 2679 | |
| 2680 | return true; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 2681 | } |
| 2682 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2683 | static bool ValidateUniformCommonBase(gl::Context *context, |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2684 | gl::Program *program, |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2685 | GLenum targetUniformType, |
| 2686 | GLint location, |
| 2687 | GLsizei count, |
| 2688 | const LinkedUniform **uniformOut) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2689 | { |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2690 | // TODO(Jiajia): Add image uniform check in future. |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2691 | if (count < 0) |
| 2692 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2693 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2694 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2695 | } |
| 2696 | |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2697 | if (!program || !program->isLinked()) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2698 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2699 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2700 | return false; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2701 | } |
| 2702 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 2703 | if (program->isIgnoredUniformLocation(location)) |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2704 | { |
| 2705 | // Silently ignore the uniform command |
| 2706 | return false; |
| 2707 | } |
| 2708 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 2709 | if (!program->isValidUniformLocation(location)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2710 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2711 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2712 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2713 | } |
| 2714 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2715 | const LinkedUniform &uniform = program->getUniformByLocation(location); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2716 | |
| 2717 | // 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] | 2718 | if (!uniform.isArray() && count > 1) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2719 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2720 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2721 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2722 | } |
| 2723 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2724 | *uniformOut = &uniform; |
Jamie Madill | d7c7bb2 | 2014-05-20 10:55:54 -0400 | [diff] [blame] | 2725 | return true; |
| 2726 | } |
| 2727 | |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2728 | bool ValidateProgramUniform(gl::Context *context, |
| 2729 | GLenum uniformType, |
| 2730 | GLuint program, |
| 2731 | GLint location, |
| 2732 | GLsizei count) |
| 2733 | { |
| 2734 | // Check for ES31 program uniform entry points |
| 2735 | if (context->getClientVersion() < Version(3, 1)) |
| 2736 | { |
| 2737 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2738 | return false; |
| 2739 | } |
| 2740 | |
| 2741 | const LinkedUniform *uniform = nullptr; |
| 2742 | gl::Program *programObject = GetValidProgram(context, program); |
| 2743 | if (!ValidateUniformCommonBase(context, programObject, uniformType, location, count, &uniform)) |
| 2744 | { |
| 2745 | return false; |
| 2746 | } |
| 2747 | |
| 2748 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
| 2749 | bool samplerUniformCheck = (IsSamplerType(uniform->type) && uniformType == GL_INT); |
| 2750 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 2751 | { |
| 2752 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2753 | return false; |
| 2754 | } |
| 2755 | |
| 2756 | return true; |
| 2757 | } |
| 2758 | |
| 2759 | bool ValidateProgramUniformMatrix(gl::Context *context, |
| 2760 | GLenum matrixType, |
| 2761 | GLuint program, |
| 2762 | GLint location, |
| 2763 | GLsizei count, |
| 2764 | GLboolean transpose) |
| 2765 | { |
| 2766 | // Check for ES31 program uniform entry points |
| 2767 | if (context->getClientVersion() < Version(3, 1)) |
| 2768 | { |
| 2769 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2770 | return false; |
| 2771 | } |
| 2772 | |
| 2773 | const LinkedUniform *uniform = nullptr; |
| 2774 | gl::Program *programObject = GetValidProgram(context, program); |
| 2775 | if (!ValidateUniformCommonBase(context, programObject, matrixType, location, count, &uniform)) |
| 2776 | { |
| 2777 | return false; |
| 2778 | } |
| 2779 | |
| 2780 | if (uniform->type != matrixType) |
| 2781 | { |
| 2782 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 2783 | return false; |
| 2784 | } |
| 2785 | |
| 2786 | return true; |
| 2787 | } |
| 2788 | |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2789 | bool ValidateUniform(gl::Context *context, GLenum uniformType, GLint location, GLsizei count) |
| 2790 | { |
| 2791 | // Check for ES3 uniform entry points |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2792 | if (VariableComponentType(uniformType) == GL_UNSIGNED_INT && |
| 2793 | context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2794 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2795 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2796 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2797 | } |
| 2798 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2799 | const LinkedUniform *uniform = nullptr; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2800 | gl::Program *program = context->getGLState().getProgram(); |
| 2801 | if (!ValidateUniformCommonBase(context, program, uniformType, location, count, &uniform)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2802 | { |
| 2803 | return false; |
| 2804 | } |
| 2805 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2806 | GLenum targetBoolType = VariableBoolVectorType(uniformType); |
Geoff Lang | 2ec386b | 2014-12-03 14:44:38 -0500 | [diff] [blame] | 2807 | bool samplerUniformCheck = (IsSamplerType(uniform->type) && uniformType == GL_INT); |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2808 | if (!samplerUniformCheck && uniformType != uniform->type && targetBoolType != uniform->type) |
| 2809 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2810 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2811 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2815 | } |
| 2816 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2817 | bool ValidateUniformMatrix(gl::Context *context, |
| 2818 | GLenum matrixType, |
| 2819 | GLint location, |
| 2820 | GLsizei count, |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2821 | GLboolean transpose) |
| 2822 | { |
| 2823 | // Check for ES3 uniform entry points |
| 2824 | int rows = VariableRowCount(matrixType); |
| 2825 | int cols = VariableColumnCount(matrixType); |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2826 | if (rows != cols && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2827 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2828 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2829 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2830 | } |
| 2831 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 2832 | if (transpose != GL_FALSE && context->getClientMajorVersion() < 3) |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2833 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2834 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2835 | return false; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2836 | } |
| 2837 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 2838 | const LinkedUniform *uniform = nullptr; |
Jiajia Qin | ee9f08c | 2016-11-16 10:06:10 +0800 | [diff] [blame] | 2839 | gl::Program *program = context->getGLState().getProgram(); |
| 2840 | if (!ValidateUniformCommonBase(context, program, matrixType, location, count, &uniform)) |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2841 | { |
| 2842 | return false; |
| 2843 | } |
| 2844 | |
| 2845 | if (uniform->type != matrixType) |
| 2846 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2847 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2848 | return false; |
Jamie Madill | 3639892 | 2014-05-20 14:51:53 -0400 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | return true; |
Jamie Madill | aa981bd | 2014-05-20 10:55:55 -0400 | [diff] [blame] | 2852 | } |
| 2853 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2854 | bool ValidateStateQuery(ValidationContext *context, |
| 2855 | GLenum pname, |
| 2856 | GLenum *nativeType, |
| 2857 | unsigned int *numParams) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2858 | { |
| 2859 | if (!context->getQueryParameterInfo(pname, nativeType, numParams)) |
| 2860 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2861 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2862 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2863 | } |
| 2864 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2865 | const Caps &caps = context->getCaps(); |
| 2866 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2867 | if (pname >= GL_DRAW_BUFFER0 && pname <= GL_DRAW_BUFFER15) |
| 2868 | { |
| 2869 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0); |
| 2870 | |
Jamie Madill | 0af26e1 | 2015-03-05 19:54:33 -0500 | [diff] [blame] | 2871 | if (colorAttachment >= caps.maxDrawBuffers) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2872 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2873 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2874 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | switch (pname) |
| 2879 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2880 | case GL_TEXTURE_BINDING_2D: |
| 2881 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2882 | case GL_TEXTURE_BINDING_3D: |
| 2883 | case GL_TEXTURE_BINDING_2D_ARRAY: |
| 2884 | break; |
| 2885 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2886 | if (!context->getExtensions().eglStreamConsumerExternal && |
| 2887 | !context->getExtensions().eglImageExternal) |
| 2888 | { |
| 2889 | context->handleError(Error(GL_INVALID_ENUM, |
| 2890 | "Neither NV_EGL_stream_consumer_external nor " |
| 2891 | "GL_OES_EGL_image_external extensions enabled")); |
| 2892 | return false; |
| 2893 | } |
| 2894 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2895 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2896 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
| 2897 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2898 | { |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2899 | if (context->getGLState().getReadFramebuffer()->checkStatus( |
| 2900 | context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2901 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2902 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2903 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2904 | } |
| 2905 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 2906 | const Framebuffer *framebuffer = context->getGLState().getReadFramebuffer(); |
| 2907 | ASSERT(framebuffer); |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 2908 | |
| 2909 | if (framebuffer->getReadBufferState() == GL_NONE) |
| 2910 | { |
| 2911 | context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE")); |
| 2912 | return false; |
| 2913 | } |
| 2914 | |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 2915 | const FramebufferAttachment *attachment = framebuffer->getReadColorbuffer(); |
Jamie Madill | 3c7fa22 | 2014-06-05 13:08:51 -0400 | [diff] [blame] | 2916 | if (!attachment) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2917 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2918 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2919 | return false; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2920 | } |
| 2921 | } |
| 2922 | break; |
| 2923 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2924 | default: |
| 2925 | break; |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | // pname is valid, but there are no parameters to return |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2929 | if (*numParams == 0) |
| 2930 | { |
| 2931 | return false; |
| 2932 | } |
| 2933 | |
| 2934 | return true; |
| 2935 | } |
| 2936 | |
| 2937 | bool ValidateRobustStateQuery(ValidationContext *context, |
| 2938 | GLenum pname, |
| 2939 | GLsizei bufSize, |
| 2940 | GLenum *nativeType, |
| 2941 | unsigned int *numParams) |
| 2942 | { |
| 2943 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 2944 | { |
| 2945 | return false; |
| 2946 | } |
| 2947 | |
| 2948 | if (!ValidateStateQuery(context, pname, nativeType, numParams)) |
| 2949 | { |
| 2950 | return false; |
| 2951 | } |
| 2952 | |
| 2953 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2954 | { |
| 2955 | return false; |
| 2956 | } |
| 2957 | |
| 2958 | return true; |
| 2959 | } |
| 2960 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2961 | bool ValidateCopyTexImageParametersBase(ValidationContext *context, |
| 2962 | GLenum target, |
| 2963 | GLint level, |
| 2964 | GLenum internalformat, |
| 2965 | bool isSubImage, |
| 2966 | GLint xoffset, |
| 2967 | GLint yoffset, |
| 2968 | GLint zoffset, |
| 2969 | GLint x, |
| 2970 | GLint y, |
| 2971 | GLsizei width, |
| 2972 | GLsizei height, |
| 2973 | GLint border, |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 2974 | Format *textureFormatOut) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2975 | { |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2976 | if (level < 0 || xoffset < 0 || yoffset < 0 || zoffset < 0 || width < 0 || height < 0) |
| 2977 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2978 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2979 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2980 | } |
| 2981 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 2982 | if (std::numeric_limits<GLsizei>::max() - xoffset < width || |
| 2983 | std::numeric_limits<GLsizei>::max() - yoffset < height) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2984 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2985 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2986 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | if (border != 0) |
| 2990 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2991 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2992 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | if (!ValidMipLevel(context, target, level)) |
| 2996 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2997 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 2998 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 2999 | } |
| 3000 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 3001 | const auto &state = context->getGLState(); |
| 3002 | auto readFramebuffer = state.getReadFramebuffer(); |
| 3003 | if (readFramebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3004 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3005 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3006 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 3009 | if (readFramebuffer->id() != 0 && readFramebuffer->getSamples(context->getContextState()) != 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3010 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3011 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3012 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3013 | } |
| 3014 | |
Martin Radev | 138064f | 2016-07-15 12:03:41 +0300 | [diff] [blame] | 3015 | if (readFramebuffer->getReadBufferState() == GL_NONE) |
| 3016 | { |
| 3017 | context->handleError(Error(GL_INVALID_OPERATION, "Read buffer is GL_NONE")); |
| 3018 | return false; |
| 3019 | } |
| 3020 | |
Corentin Wallez | 3c90ed6 | 2016-12-16 16:19:28 -0500 | [diff] [blame] | 3021 | // WebGL 1.0 [Section 6.26] Reading From a Missing Attachment |
| 3022 | // 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] | 3023 | // 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] | 3024 | // situation is an application error that would lead to a crash in ANGLE. |
| 3025 | if (readFramebuffer->getReadColorbuffer() == nullptr) |
| 3026 | { |
| 3027 | context->handleError(Error(GL_INVALID_OPERATION, "Missing read attachment")); |
| 3028 | return false; |
| 3029 | } |
| 3030 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 3031 | const gl::Caps &caps = context->getCaps(); |
| 3032 | |
Geoff Lang | aae65a4 | 2014-05-26 12:43:44 -0400 | [diff] [blame] | 3033 | GLuint maxDimension = 0; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3034 | switch (target) |
| 3035 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3036 | case GL_TEXTURE_2D: |
| 3037 | maxDimension = caps.max2DTextureSize; |
| 3038 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3039 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3040 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 3041 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 3042 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 3043 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 3044 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 3045 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
| 3046 | maxDimension = caps.maxCubeMapTextureSize; |
| 3047 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3048 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3049 | case GL_TEXTURE_2D_ARRAY: |
| 3050 | maxDimension = caps.max2DTextureSize; |
| 3051 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3052 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3053 | case GL_TEXTURE_3D: |
| 3054 | maxDimension = caps.max3DTextureSize; |
| 3055 | break; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3056 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3057 | default: |
| 3058 | context->handleError(Error(GL_INVALID_ENUM)); |
| 3059 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3060 | } |
| 3061 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3062 | gl::Texture *texture = |
| 3063 | state.getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3064 | if (!texture) |
| 3065 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3066 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3067 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3068 | } |
| 3069 | |
Geoff Lang | 69cce58 | 2015-09-17 13:20:36 -0400 | [diff] [blame] | 3070 | if (texture->getImmutableFormat() && !isSubImage) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3071 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3072 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3073 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3074 | } |
| 3075 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 3076 | const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalformat); |
| 3077 | |
| 3078 | if (formatInfo.depthBits > 0) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3079 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3080 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3081 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3082 | } |
| 3083 | |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3084 | if (formatInfo.compressed && !ValidCompressedImageSize(context, internalformat, width, height)) |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3085 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3086 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3087 | return false; |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | if (isSubImage) |
| 3091 | { |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3092 | if (static_cast<size_t>(xoffset + width) > texture->getWidth(target, level) || |
| 3093 | static_cast<size_t>(yoffset + height) > texture->getHeight(target, level) || |
| 3094 | static_cast<size_t>(zoffset) >= texture->getDepth(target, level)) |
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_VALUE)); |
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 | } |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3100 | else |
| 3101 | { |
Geoff Lang | 691e58c | 2014-12-19 17:03:25 -0500 | [diff] [blame] | 3102 | if (IsCubeMapTextureTarget(target) && width != height) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3103 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3104 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3105 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3106 | } |
| 3107 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 3108 | if (!formatInfo.textureSupport(context->getClientVersion(), context->getExtensions())) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3109 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3110 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3111 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3112 | } |
| 3113 | |
| 3114 | int maxLevelDimension = (maxDimension >> level); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3115 | if (static_cast<int>(width) > maxLevelDimension || |
| 3116 | static_cast<int>(height) > maxLevelDimension) |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3117 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3118 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3119 | return false; |
Jamie Madill | 6f38f82 | 2014-06-06 17:12:20 -0400 | [diff] [blame] | 3120 | } |
| 3121 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3122 | |
Jamie Madill | 0c8abca | 2016-07-22 20:21:26 -0400 | [diff] [blame] | 3123 | if (textureFormatOut) |
| 3124 | { |
| 3125 | *textureFormatOut = texture->getFormat(target, level); |
| 3126 | } |
Jamie Madill | 560a8d8 | 2014-05-21 13:06:20 -0400 | [diff] [blame] | 3127 | return true; |
| 3128 | } |
| 3129 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3130 | bool ValidateDrawBase(ValidationContext *context, GLenum mode, GLsizei count) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3131 | { |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 3132 | switch (mode) |
| 3133 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3134 | case GL_POINTS: |
| 3135 | case GL_LINES: |
| 3136 | case GL_LINE_LOOP: |
| 3137 | case GL_LINE_STRIP: |
| 3138 | case GL_TRIANGLES: |
| 3139 | case GL_TRIANGLE_STRIP: |
| 3140 | case GL_TRIANGLE_FAN: |
| 3141 | break; |
| 3142 | default: |
| 3143 | context->handleError(Error(GL_INVALID_ENUM)); |
| 3144 | return false; |
Jamie Madill | 1aeb131 | 2014-06-20 13:21:25 -0400 | [diff] [blame] | 3145 | } |
| 3146 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3147 | if (count < 0) |
| 3148 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3149 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3150 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3151 | } |
| 3152 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3153 | const State &state = context->getGLState(); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3154 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3155 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 3156 | if (state.hasMappedBuffer(GL_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3157 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3158 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3159 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3160 | } |
| 3161 | |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 3162 | // Note: these separate values are not supported in WebGL, due to D3D's limitations. See |
| 3163 | // Section 6.10 of the WebGL 1.0 spec. |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 3164 | Framebuffer *framebuffer = state.getDrawFramebuffer(); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 3165 | if (context->getLimitations().noSeparateStencilRefsAndMasks || |
| 3166 | context->getExtensions().webglCompatibility) |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 3167 | { |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 3168 | const FramebufferAttachment *dsAttachment = |
| 3169 | framebuffer->getStencilOrDepthStencilAttachment(); |
| 3170 | GLuint stencilBits = dsAttachment ? dsAttachment->getStencilSize() : 0; |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3171 | GLuint minimumRequiredStencilMask = (1 << stencilBits) - 1; |
Jinyoung Hur | 85769f0 | 2015-10-20 17:08:44 -0400 | [diff] [blame] | 3172 | const DepthStencilState &depthStencilState = state.getDepthStencilState(); |
Corentin Wallez | b1d0a255 | 2016-12-19 16:15:54 -0500 | [diff] [blame] | 3173 | |
| 3174 | bool differentRefs = state.getStencilRef() != state.getStencilBackRef(); |
| 3175 | bool differentWritemasks = |
| 3176 | (depthStencilState.stencilWritemask & minimumRequiredStencilMask) != |
| 3177 | (depthStencilState.stencilBackWritemask & minimumRequiredStencilMask); |
| 3178 | bool differentMasks = (depthStencilState.stencilMask & minimumRequiredStencilMask) != |
| 3179 | (depthStencilState.stencilBackMask & minimumRequiredStencilMask); |
| 3180 | |
| 3181 | if (differentRefs || differentWritemasks || differentMasks) |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 3182 | { |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 3183 | if (!context->getExtensions().webglCompatibility) |
| 3184 | { |
Jamie Madill | 6a6b09c | 2017-01-12 21:52:29 +0000 | [diff] [blame] | 3185 | ERR("This ANGLE implementation does not support separate front/back stencil " |
| 3186 | "writemasks, reference values, or stencil mask values."); |
Jamie Madill | cbcde72 | 2017-01-06 14:50:00 -0500 | [diff] [blame] | 3187 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3188 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | 3a86ad3 | 2015-09-01 11:47:05 -0400 | [diff] [blame] | 3189 | return false; |
| 3190 | } |
Jamie Madill | ac52801 | 2014-06-20 13:21:23 -0400 | [diff] [blame] | 3191 | } |
| 3192 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 3193 | if (framebuffer->checkStatus(context->getContextState()) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 3194 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3195 | context->handleError(Error(GL_INVALID_FRAMEBUFFER_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3196 | return false; |
Jamie Madill | 13f7d7d | 2014-06-20 13:21:27 -0400 | [diff] [blame] | 3197 | } |
| 3198 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3199 | gl::Program *program = state.getProgram(); |
| 3200 | if (!program) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3201 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3202 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3203 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3204 | } |
| 3205 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3206 | if (!program->validateSamplers(NULL, context->getCaps())) |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3207 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3208 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3209 | return false; |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3210 | } |
| 3211 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3212 | // Uniform buffer validation |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3213 | for (unsigned int uniformBlockIndex = 0; |
| 3214 | uniformBlockIndex < program->getActiveUniformBlockCount(); uniformBlockIndex++) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3215 | { |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3216 | const gl::UniformBlock &uniformBlock = program->getUniformBlockByIndex(uniformBlockIndex); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3217 | GLuint blockBinding = program->getUniformBlockBinding(uniformBlockIndex); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 3218 | const OffsetBindingPointer<Buffer> &uniformBuffer = |
| 3219 | state.getIndexedUniformBuffer(blockBinding); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3220 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 3221 | if (uniformBuffer.get() == nullptr) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3222 | { |
| 3223 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3224 | context->handleError( |
| 3225 | Error(GL_INVALID_OPERATION, |
| 3226 | "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] | 3227 | return false; |
| 3228 | } |
| 3229 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 3230 | size_t uniformBufferSize = uniformBuffer.getSize(); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3231 | if (uniformBufferSize == 0) |
| 3232 | { |
| 3233 | // Bind the whole buffer. |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 3234 | uniformBufferSize = static_cast<size_t>(uniformBuffer->getSize()); |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3235 | } |
| 3236 | |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3237 | if (uniformBufferSize < uniformBlock.dataSize) |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 3238 | { |
| 3239 | // undefined behaviour |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3240 | context->handleError( |
| 3241 | Error(GL_INVALID_OPERATION, |
| 3242 | "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] | 3243 | return false; |
| 3244 | } |
| 3245 | } |
| 3246 | |
Jamie Madill | a4595b8 | 2017-01-11 17:36:34 -0500 | [diff] [blame] | 3247 | // Detect rendering feedback loops for WebGL. |
| 3248 | if (context->getExtensions().webglCompatibility) |
| 3249 | { |
| 3250 | if (framebuffer->formsRenderingFeedbackLoopWith(state)) |
| 3251 | { |
| 3252 | context->handleError( |
| 3253 | Error(GL_INVALID_OPERATION, |
| 3254 | "Rendering feedback loop formed between Framebuffer and active Texture.")); |
| 3255 | return false; |
| 3256 | } |
| 3257 | } |
| 3258 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3259 | // No-op if zero count |
| 3260 | return (count > 0); |
| 3261 | } |
| 3262 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3263 | bool ValidateDrawArrays(ValidationContext *context, |
| 3264 | GLenum mode, |
| 3265 | GLint first, |
| 3266 | GLsizei count, |
| 3267 | GLsizei primcount) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3268 | { |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3269 | if (first < 0) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3270 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3271 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3272 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3273 | } |
| 3274 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3275 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 3276 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3277 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 3278 | !curTransformFeedback->isPaused() && curTransformFeedback->getPrimitiveMode() != mode) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3279 | { |
| 3280 | // 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] | 3281 | // that does not match the current transform feedback object's draw mode (if transform |
| 3282 | // feedback |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3283 | // is active), (3.0.2, section 2.14, pg 86) |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3284 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3285 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3286 | } |
| 3287 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3288 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 3289 | { |
| 3290 | return false; |
| 3291 | } |
| 3292 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 3293 | // Check the computation of maxVertex doesn't overflow. |
| 3294 | // - first < 0 or count < 0 have been checked as an error condition |
| 3295 | // - count > 0 has been checked in ValidateDrawBase as it makes the call a noop |
| 3296 | // From this we know maxVertex will be positive, and only need to check if it overflows GLint. |
| 3297 | ASSERT(count > 0 && first >= 0); |
| 3298 | int64_t maxVertex = static_cast<int64_t>(first) + static_cast<int64_t>(count) - 1; |
| 3299 | if (maxVertex > static_cast<int64_t>(std::numeric_limits<GLint>::max())) |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 3300 | { |
| 3301 | context->handleError(Error(GL_INVALID_OPERATION, "Integer overflow.")); |
| 3302 | return false; |
| 3303 | } |
| 3304 | |
Corentin Wallez | 71168a0 | 2016-12-19 15:11:18 -0800 | [diff] [blame] | 3305 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(maxVertex), count)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3306 | { |
| 3307 | return false; |
| 3308 | } |
| 3309 | |
| 3310 | return true; |
| 3311 | } |
| 3312 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3313 | bool ValidateDrawArraysInstanced(Context *context, |
| 3314 | GLenum mode, |
| 3315 | GLint first, |
| 3316 | GLsizei count, |
| 3317 | GLsizei primcount) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3318 | { |
| 3319 | if (primcount < 0) |
| 3320 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3321 | context->handleError(Error(GL_INVALID_VALUE)); |
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 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3325 | if (!ValidateDrawArrays(context, mode, first, count, primcount)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3326 | { |
| 3327 | return false; |
| 3328 | } |
| 3329 | |
| 3330 | // No-op if zero primitive count |
| 3331 | return (primcount > 0); |
| 3332 | } |
| 3333 | |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3334 | static bool ValidateDrawInstancedANGLE(Context *context) |
| 3335 | { |
| 3336 | // 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] | 3337 | const gl::State &state = context->getGLState(); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3338 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3339 | gl::Program *program = state.getProgram(); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3340 | |
| 3341 | const VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3342 | for (size_t attributeIndex = 0; attributeIndex < MAX_VERTEX_ATTRIBS; attributeIndex++) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3343 | { |
| 3344 | const VertexAttribute &attrib = vao->getVertexAttribute(attributeIndex); |
Jamie Madill | 63805b4 | 2015-08-25 13:17:39 -0400 | [diff] [blame] | 3345 | if (program->isAttribLocationActive(attributeIndex) && attrib.divisor == 0) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3346 | { |
| 3347 | return true; |
| 3348 | } |
| 3349 | } |
| 3350 | |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3351 | context->handleError(Error(GL_INVALID_OPERATION, |
| 3352 | "ANGLE_instanced_arrays requires that at least one active attribute" |
| 3353 | "has a divisor of zero.")); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3354 | return false; |
| 3355 | } |
| 3356 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3357 | bool ValidateDrawArraysInstancedANGLE(Context *context, |
| 3358 | GLenum mode, |
| 3359 | GLint first, |
| 3360 | GLsizei count, |
| 3361 | GLsizei primcount) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3362 | { |
| 3363 | if (!ValidateDrawInstancedANGLE(context)) |
| 3364 | { |
| 3365 | return false; |
| 3366 | } |
| 3367 | |
| 3368 | return ValidateDrawArraysInstanced(context, mode, first, count, primcount); |
| 3369 | } |
| 3370 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3371 | bool ValidateDrawElementsBase(ValidationContext *context, GLenum type) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3372 | { |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3373 | switch (type) |
| 3374 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3375 | case GL_UNSIGNED_BYTE: |
| 3376 | case GL_UNSIGNED_SHORT: |
| 3377 | break; |
| 3378 | case GL_UNSIGNED_INT: |
| 3379 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().elementIndexUint) |
| 3380 | { |
| 3381 | context->handleError(Error(GL_INVALID_ENUM)); |
| 3382 | return false; |
| 3383 | } |
| 3384 | break; |
| 3385 | default: |
| 3386 | context->handleError(Error(GL_INVALID_ENUM)); |
| 3387 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3388 | } |
| 3389 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3390 | const State &state = context->getGLState(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 3391 | |
| 3392 | gl::TransformFeedback *curTransformFeedback = state.getCurrentTransformFeedback(); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3393 | if (curTransformFeedback && curTransformFeedback->isActive() && |
| 3394 | !curTransformFeedback->isPaused()) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3395 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3396 | // It is an invalid operation to call DrawElements, DrawRangeElements or |
| 3397 | // DrawElementsInstanced |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3398 | // 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] | 3399 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3400 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3401 | } |
| 3402 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3403 | return true; |
| 3404 | } |
| 3405 | |
| 3406 | bool ValidateDrawElements(ValidationContext *context, |
| 3407 | GLenum mode, |
| 3408 | GLsizei count, |
| 3409 | GLenum type, |
| 3410 | const GLvoid *indices, |
| 3411 | GLsizei primcount, |
| 3412 | IndexRange *indexRangeOut) |
| 3413 | { |
| 3414 | if (!ValidateDrawElementsBase(context, type)) |
| 3415 | return false; |
| 3416 | |
| 3417 | const State &state = context->getGLState(); |
| 3418 | |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3419 | // Check for mapped buffers |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 3420 | if (state.hasMappedBuffer(GL_ELEMENT_ARRAY_BUFFER)) |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3421 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3422 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3423 | return false; |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3424 | } |
| 3425 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3426 | const gl::VertexArray *vao = state.getVertexArray(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 3427 | gl::Buffer *elementArrayBuffer = vao->getElementArrayBuffer().get(); |
Jamie Madill | d4cfa57 | 2014-07-08 10:00:32 -0400 | [diff] [blame] | 3428 | |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3429 | if (elementArrayBuffer) |
| 3430 | { |
| 3431 | const gl::Type &typeInfo = gl::GetTypeInfo(type); |
| 3432 | |
| 3433 | GLint64 offset = reinterpret_cast<GLint64>(indices); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3434 | GLint64 byteCount = |
| 3435 | static_cast<GLint64>(typeInfo.bytes) * static_cast<GLint64>(count) + offset; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3436 | |
| 3437 | // check for integer overflows |
| 3438 | if (static_cast<GLuint>(count) > (std::numeric_limits<GLuint>::max() / typeInfo.bytes) || |
| 3439 | byteCount > static_cast<GLint64>(std::numeric_limits<GLuint>::max())) |
| 3440 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3441 | context->handleError(Error(GL_OUT_OF_MEMORY)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3442 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3443 | } |
| 3444 | |
| 3445 | // Check for reading past the end of the bound buffer object |
| 3446 | if (byteCount > elementArrayBuffer->getSize()) |
| 3447 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3448 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3449 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3450 | } |
| 3451 | } |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 3452 | else if (context->getExtensions().webglCompatibility && count > 0) |
| 3453 | { |
| 3454 | // [WebGL 1.0] Section 6.2 No Client Side Arrays |
| 3455 | // If drawElements is called with a count greater than zero, and no WebGLBuffer is bound |
| 3456 | // to the ELEMENT_ARRAY_BUFFER binding point, an INVALID_OPERATION error is generated. |
| 3457 | context->handleError( |
| 3458 | Error(GL_INVALID_OPERATION, "There is no element array buffer bound and count > 0.")); |
| 3459 | return false; |
| 3460 | } |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3461 | else if (!indices) |
| 3462 | { |
Corentin Wallez | 327411e | 2016-12-09 11:09:17 -0500 | [diff] [blame] | 3463 | // This is an application error that would normally result in a crash, |
| 3464 | // but we catch it and return an error |
| 3465 | context->handleError( |
| 3466 | Error(GL_INVALID_OPERATION, "No element array buffer and no pointer.")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3467 | return false; |
Jamie Madill | ae3000b | 2014-08-25 15:47:51 -0400 | [diff] [blame] | 3468 | } |
| 3469 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3470 | if (!ValidateDrawBase(context, mode, count)) |
Corentin Wallez | 18a2fb3 | 2015-08-10 12:58:14 -0700 | [diff] [blame] | 3471 | { |
| 3472 | return false; |
| 3473 | } |
| 3474 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3475 | // Use max index to validate if our vertex buffers are large enough for the pull. |
| 3476 | // TODO: offer fast path, with disabled index validation. |
| 3477 | // TODO: also disable index checking on back-ends that are robust to out-of-range accesses. |
| 3478 | if (elementArrayBuffer) |
| 3479 | { |
Jacek Caban | a5521de | 2014-10-01 17:23:46 +0200 | [diff] [blame] | 3480 | uintptr_t offset = reinterpret_cast<uintptr_t>(indices); |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3481 | Error error = |
| 3482 | elementArrayBuffer->getIndexRange(type, static_cast<size_t>(offset), count, |
| 3483 | state.isPrimitiveRestartEnabled(), indexRangeOut); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 3484 | if (error.isError()) |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3485 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3486 | context->handleError(error); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 3487 | return false; |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3488 | } |
| 3489 | } |
| 3490 | else |
| 3491 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3492 | *indexRangeOut = ComputeIndexRange(type, indices, count, state.isPrimitiveRestartEnabled()); |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3493 | } |
| 3494 | |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 3495 | // If we use an index greater than our maximum supported index range, return an error. |
| 3496 | // The ES3 spec does not specify behaviour here, it is undefined, but ANGLE should always |
| 3497 | // return an error if possible here. |
| 3498 | if (static_cast<GLuint64>(indexRangeOut->end) >= context->getCaps().maxElementIndex) |
| 3499 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3500 | context->handleError(Error(GL_INVALID_OPERATION, g_ExceedsMaxElementErrorMessage)); |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 3501 | return false; |
| 3502 | } |
| 3503 | |
Corentin Wallez | 92db694 | 2016-12-09 13:10:36 -0500 | [diff] [blame] | 3504 | if (!ValidateDrawAttribs(context, primcount, static_cast<GLint>(indexRangeOut->end), |
| 3505 | static_cast<GLint>(indexRangeOut->vertexCount()))) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3506 | { |
| 3507 | return false; |
| 3508 | } |
| 3509 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3510 | // No op if there are no real indices in the index data (all are primitive restart). |
| 3511 | return (indexRangeOut->vertexIndexCount > 0); |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3512 | } |
| 3513 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3514 | bool ValidateDrawElementsInstanced(Context *context, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3515 | GLenum mode, |
| 3516 | GLsizei count, |
| 3517 | GLenum type, |
| 3518 | const GLvoid *indices, |
| 3519 | GLsizei primcount, |
| 3520 | IndexRange *indexRangeOut) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3521 | { |
| 3522 | if (primcount < 0) |
| 3523 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3524 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3525 | return false; |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3526 | } |
| 3527 | |
Jamie Madill | 2b97681 | 2014-08-25 15:47:49 -0400 | [diff] [blame] | 3528 | if (!ValidateDrawElements(context, mode, count, type, indices, primcount, indexRangeOut)) |
Jamie Madill | fd71658 | 2014-06-06 17:09:04 -0400 | [diff] [blame] | 3529 | { |
| 3530 | return false; |
| 3531 | } |
| 3532 | |
| 3533 | // No-op zero primitive count |
| 3534 | return (primcount > 0); |
Jamie Madill | 250d33f | 2014-06-06 17:09:03 -0400 | [diff] [blame] | 3535 | } |
| 3536 | |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 3537 | bool ValidateDrawElementsInstancedANGLE(Context *context, |
| 3538 | GLenum mode, |
| 3539 | GLsizei count, |
| 3540 | GLenum type, |
| 3541 | const GLvoid *indices, |
| 3542 | GLsizei primcount, |
| 3543 | IndexRange *indexRangeOut) |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3544 | { |
| 3545 | if (!ValidateDrawInstancedANGLE(context)) |
| 3546 | { |
| 3547 | return false; |
| 3548 | } |
| 3549 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3550 | return ValidateDrawElementsInstanced(context, mode, count, type, indices, primcount, |
| 3551 | indexRangeOut); |
Geoff Lang | 87a9330 | 2014-09-16 13:29:43 -0400 | [diff] [blame] | 3552 | } |
| 3553 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3554 | bool ValidateFramebufferTextureBase(Context *context, |
| 3555 | GLenum target, |
| 3556 | GLenum attachment, |
| 3557 | GLuint texture, |
| 3558 | GLint level) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3559 | { |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3560 | if (!ValidFramebufferTarget(target)) |
| 3561 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3562 | context->handleError(Error(GL_INVALID_ENUM)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3563 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3564 | } |
| 3565 | |
| 3566 | if (!ValidateAttachmentTarget(context, attachment)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3567 | { |
| 3568 | return false; |
| 3569 | } |
| 3570 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3571 | if (texture != 0) |
| 3572 | { |
| 3573 | gl::Texture *tex = context->getTexture(texture); |
| 3574 | |
| 3575 | if (tex == NULL) |
| 3576 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3577 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3578 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3579 | } |
| 3580 | |
| 3581 | if (level < 0) |
| 3582 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3583 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3584 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3585 | } |
| 3586 | } |
| 3587 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3588 | const gl::Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3589 | ASSERT(framebuffer); |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3590 | |
Jamie Madill | 84115c9 | 2015-04-23 15:00:07 -0400 | [diff] [blame] | 3591 | if (framebuffer->id() == 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3592 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3593 | context->handleError( |
| 3594 | Error(GL_INVALID_OPERATION, "Cannot change default FBO's attachments")); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3595 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | return true; |
| 3599 | } |
| 3600 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3601 | bool ValidateFramebufferTexture2D(Context *context, |
| 3602 | GLenum target, |
| 3603 | GLenum attachment, |
| 3604 | GLenum textarget, |
| 3605 | GLuint texture, |
| 3606 | GLint level) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3607 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3608 | // Attachments are required to be bound to level 0 without ES3 or the GL_OES_fbo_render_mipmap |
| 3609 | // extension |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3610 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().fboRenderMipmap && |
| 3611 | level != 0) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3612 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3613 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3614 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level)) |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3618 | { |
| 3619 | return false; |
| 3620 | } |
| 3621 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3622 | if (texture != 0) |
| 3623 | { |
| 3624 | gl::Texture *tex = context->getTexture(texture); |
| 3625 | ASSERT(tex); |
| 3626 | |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 3627 | const gl::Caps &caps = context->getCaps(); |
| 3628 | |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3629 | switch (textarget) |
| 3630 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3631 | case GL_TEXTURE_2D: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3632 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 3633 | if (level > gl::log2(caps.max2DTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3634 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3635 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3636 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3637 | } |
| 3638 | if (tex->getTarget() != GL_TEXTURE_2D) |
| 3639 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3640 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3641 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3642 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3643 | } |
| 3644 | break; |
| 3645 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3646 | case GL_TEXTURE_CUBE_MAP_POSITIVE_X: |
| 3647 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_X: |
| 3648 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Y: |
| 3649 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: |
| 3650 | case GL_TEXTURE_CUBE_MAP_POSITIVE_Z: |
| 3651 | case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3652 | { |
Jamie Madill | 2a6564e | 2014-07-11 09:53:19 -0400 | [diff] [blame] | 3653 | if (level > gl::log2(caps.maxCubeMapTextureSize)) |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3654 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3655 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3656 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3657 | } |
| 3658 | if (tex->getTarget() != GL_TEXTURE_CUBE_MAP) |
| 3659 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3660 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3661 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3662 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3663 | } |
| 3664 | break; |
| 3665 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3666 | default: |
| 3667 | context->handleError(Error(GL_INVALID_ENUM)); |
| 3668 | return false; |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3669 | } |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3670 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 3671 | const Format &format = tex->getFormat(textarget, level); |
| 3672 | if (format.info->compressed) |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3673 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3674 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a9be0dc | 2014-12-17 12:34:40 -0500 | [diff] [blame] | 3675 | return false; |
| 3676 | } |
Jamie Madill | 55ec3b1 | 2014-07-03 10:38:57 -0400 | [diff] [blame] | 3677 | } |
| 3678 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 3679 | return true; |
| 3680 | } |
| 3681 | |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3682 | bool ValidateGetUniformBase(Context *context, GLuint program, GLint location) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3683 | { |
| 3684 | if (program == 0) |
| 3685 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3686 | context->handleError(Error(GL_INVALID_VALUE)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3687 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3688 | } |
| 3689 | |
Dian Xiang | 769769a | 2015-09-09 15:20:08 -0700 | [diff] [blame] | 3690 | gl::Program *programObject = GetValidProgram(context, program); |
| 3691 | if (!programObject) |
Shannon Woods | 4de4fd6 | 2014-11-07 16:22:02 -0500 | [diff] [blame] | 3692 | { |
| 3693 | return false; |
| 3694 | } |
| 3695 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3696 | if (!programObject || !programObject->isLinked()) |
| 3697 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3698 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3699 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3700 | } |
| 3701 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 3702 | if (!programObject->isValidUniformLocation(location)) |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3703 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3704 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3705 | return false; |
Jamie Madill | 549c7fd | 2014-08-25 15:47:56 -0400 | [diff] [blame] | 3706 | } |
| 3707 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3708 | return true; |
| 3709 | } |
| 3710 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3711 | bool ValidateGetUniformfv(Context *context, GLuint program, GLint location, GLfloat *params) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3712 | { |
| 3713 | return ValidateGetUniformBase(context, program, location); |
| 3714 | } |
| 3715 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3716 | bool ValidateGetUniformiv(Context *context, GLuint program, GLint location, GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3717 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3718 | return ValidateGetUniformBase(context, program, location); |
| 3719 | } |
| 3720 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3721 | static bool ValidateSizedGetUniform(Context *context, |
| 3722 | GLuint program, |
| 3723 | GLint location, |
| 3724 | GLsizei bufSize, |
| 3725 | GLsizei *length) |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3726 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3727 | if (length) |
| 3728 | { |
| 3729 | *length = 0; |
| 3730 | } |
| 3731 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3732 | if (!ValidateGetUniformBase(context, program, location)) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3733 | { |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3734 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3735 | } |
| 3736 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3737 | if (bufSize < 0) |
| 3738 | { |
| 3739 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
| 3740 | return false; |
| 3741 | } |
| 3742 | |
Jamie Madill | a502c74 | 2014-08-28 17:19:13 -0400 | [diff] [blame] | 3743 | gl::Program *programObject = context->getProgram(program); |
| 3744 | ASSERT(programObject); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3745 | |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3746 | // sized queries -- ensure the provided buffer is large enough |
Jamie Madill | 62d31cb | 2015-09-11 13:25:51 -0400 | [diff] [blame] | 3747 | const LinkedUniform &uniform = programObject->getUniformByLocation(location); |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3748 | size_t requiredBytes = VariableExternalSize(uniform.type); |
Jamie Madill | 78f4180 | 2014-08-25 15:47:55 -0400 | [diff] [blame] | 3749 | if (static_cast<size_t>(bufSize) < requiredBytes) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3750 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3751 | context->handleError( |
| 3752 | Error(GL_INVALID_OPERATION, "bufSize of at least %u is required.", requiredBytes)); |
Geoff Lang | b119668 | 2014-07-23 13:47:29 -0400 | [diff] [blame] | 3753 | return false; |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3754 | } |
| 3755 | |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3756 | if (length) |
| 3757 | { |
Geoff Lang | 94177fb | 2016-11-14 16:12:26 -0500 | [diff] [blame] | 3758 | *length = VariableComponentCount(uniform.type); |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3759 | } |
| 3760 | |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3761 | return true; |
| 3762 | } |
| 3763 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3764 | bool ValidateGetnUniformfvEXT(Context *context, |
| 3765 | GLuint program, |
| 3766 | GLint location, |
| 3767 | GLsizei bufSize, |
| 3768 | GLfloat *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3769 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3770 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3771 | } |
| 3772 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3773 | bool ValidateGetnUniformivEXT(Context *context, |
| 3774 | GLuint program, |
| 3775 | GLint location, |
| 3776 | GLsizei bufSize, |
| 3777 | GLint *params) |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3778 | { |
Geoff Lang | f41d0ee | 2016-10-07 13:04:23 -0400 | [diff] [blame] | 3779 | return ValidateSizedGetUniform(context, program, location, bufSize, nullptr); |
| 3780 | } |
| 3781 | |
| 3782 | bool ValidateGetUniformfvRobustANGLE(Context *context, |
| 3783 | GLuint program, |
| 3784 | GLint location, |
| 3785 | GLsizei bufSize, |
| 3786 | GLsizei *length, |
| 3787 | GLfloat *params) |
| 3788 | { |
| 3789 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3790 | { |
| 3791 | return false; |
| 3792 | } |
| 3793 | |
| 3794 | // bufSize is validated in ValidateSizedGetUniform |
| 3795 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
| 3796 | } |
| 3797 | |
| 3798 | bool ValidateGetUniformivRobustANGLE(Context *context, |
| 3799 | GLuint program, |
| 3800 | GLint location, |
| 3801 | GLsizei bufSize, |
| 3802 | GLsizei *length, |
| 3803 | GLint *params) |
| 3804 | { |
| 3805 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3806 | { |
| 3807 | return false; |
| 3808 | } |
| 3809 | |
| 3810 | // bufSize is validated in ValidateSizedGetUniform |
| 3811 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
| 3812 | } |
| 3813 | |
| 3814 | bool ValidateGetUniformuivRobustANGLE(Context *context, |
| 3815 | GLuint program, |
| 3816 | GLint location, |
| 3817 | GLsizei bufSize, |
| 3818 | GLsizei *length, |
| 3819 | GLuint *params) |
| 3820 | { |
| 3821 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 3822 | { |
| 3823 | return false; |
| 3824 | } |
| 3825 | |
| 3826 | if (context->getClientMajorVersion() < 3) |
| 3827 | { |
| 3828 | context->handleError( |
| 3829 | Error(GL_INVALID_OPERATION, "Entry point requires at least OpenGL ES 3.0.")); |
| 3830 | return false; |
| 3831 | } |
| 3832 | |
| 3833 | // bufSize is validated in ValidateSizedGetUniform |
| 3834 | return ValidateSizedGetUniform(context, program, location, bufSize, length); |
Jamie Madill | 0063c51 | 2014-08-25 15:47:53 -0400 | [diff] [blame] | 3835 | } |
| 3836 | |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3837 | bool ValidateDiscardFramebufferBase(Context *context, |
| 3838 | GLenum target, |
| 3839 | GLsizei numAttachments, |
| 3840 | const GLenum *attachments, |
| 3841 | bool defaultFramebuffer) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3842 | { |
| 3843 | if (numAttachments < 0) |
| 3844 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3845 | 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] | 3846 | return false; |
| 3847 | } |
| 3848 | |
| 3849 | for (GLsizei i = 0; i < numAttachments; ++i) |
| 3850 | { |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 3851 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT31) |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3852 | { |
| 3853 | if (defaultFramebuffer) |
| 3854 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3855 | context->handleError(Error( |
| 3856 | GL_INVALID_ENUM, "Invalid attachment when the default framebuffer is bound")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3857 | return false; |
| 3858 | } |
| 3859 | |
| 3860 | if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments) |
| 3861 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3862 | context->handleError(Error(GL_INVALID_OPERATION, |
| 3863 | "Requested color attachment is greater than the maximum " |
| 3864 | "supported color attachments")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3865 | return false; |
| 3866 | } |
| 3867 | } |
| 3868 | else |
| 3869 | { |
| 3870 | switch (attachments[i]) |
| 3871 | { |
He Yunchao | ced53ae | 2016-11-29 15:00:51 +0800 | [diff] [blame] | 3872 | case GL_DEPTH_ATTACHMENT: |
| 3873 | case GL_STENCIL_ATTACHMENT: |
| 3874 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 3875 | if (defaultFramebuffer) |
| 3876 | { |
| 3877 | context->handleError( |
| 3878 | Error(GL_INVALID_ENUM, |
| 3879 | "Invalid attachment when the default framebuffer is bound")); |
| 3880 | return false; |
| 3881 | } |
| 3882 | break; |
| 3883 | case GL_COLOR: |
| 3884 | case GL_DEPTH: |
| 3885 | case GL_STENCIL: |
| 3886 | if (!defaultFramebuffer) |
| 3887 | { |
| 3888 | context->handleError( |
| 3889 | Error(GL_INVALID_ENUM, |
| 3890 | "Invalid attachment when the default framebuffer is not bound")); |
| 3891 | return false; |
| 3892 | } |
| 3893 | break; |
| 3894 | default: |
| 3895 | context->handleError(Error(GL_INVALID_ENUM, "Invalid attachment")); |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3896 | return false; |
Austin Kinross | 0833263 | 2015-05-05 13:35:47 -0700 | [diff] [blame] | 3897 | } |
| 3898 | } |
| 3899 | } |
| 3900 | |
| 3901 | return true; |
| 3902 | } |
| 3903 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 3904 | bool ValidateInsertEventMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3905 | { |
| 3906 | // Note that debug marker calls must not set error state |
| 3907 | |
| 3908 | if (length < 0) |
| 3909 | { |
| 3910 | return false; |
| 3911 | } |
| 3912 | |
| 3913 | if (marker == nullptr) |
| 3914 | { |
| 3915 | return false; |
| 3916 | } |
| 3917 | |
| 3918 | return true; |
| 3919 | } |
| 3920 | |
| 3921 | bool ValidatePushGroupMarkerEXT(Context *context, GLsizei length, const char *marker) |
| 3922 | { |
| 3923 | // Note that debug marker calls must not set error state |
| 3924 | |
| 3925 | if (length < 0) |
| 3926 | { |
| 3927 | return false; |
| 3928 | } |
| 3929 | |
| 3930 | if (length > 0 && marker == nullptr) |
| 3931 | { |
| 3932 | return false; |
| 3933 | } |
| 3934 | |
| 3935 | return true; |
| 3936 | } |
| 3937 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3938 | bool ValidateEGLImageTargetTexture2DOES(Context *context, |
| 3939 | egl::Display *display, |
| 3940 | GLenum target, |
| 3941 | egl::Image *image) |
| 3942 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3943 | if (!context->getExtensions().eglImage && !context->getExtensions().eglImageExternal) |
| 3944 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3945 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3946 | return false; |
| 3947 | } |
| 3948 | |
| 3949 | switch (target) |
| 3950 | { |
| 3951 | case GL_TEXTURE_2D: |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 3952 | if (!context->getExtensions().eglImage) |
| 3953 | { |
| 3954 | context->handleError(Error( |
| 3955 | GL_INVALID_ENUM, "GL_TEXTURE_2D texture target requires GL_OES_EGL_image.")); |
| 3956 | } |
| 3957 | break; |
| 3958 | |
| 3959 | case GL_TEXTURE_EXTERNAL_OES: |
| 3960 | if (!context->getExtensions().eglImageExternal) |
| 3961 | { |
| 3962 | context->handleError(Error( |
| 3963 | GL_INVALID_ENUM, |
| 3964 | "GL_TEXTURE_EXTERNAL_OES texture target requires GL_OES_EGL_image_external.")); |
| 3965 | } |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3966 | break; |
| 3967 | |
| 3968 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3969 | context->handleError(Error(GL_INVALID_ENUM, "invalid texture target.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3970 | return false; |
| 3971 | } |
| 3972 | |
| 3973 | if (!display->isValidImage(image)) |
| 3974 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3975 | context->handleError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3976 | return false; |
| 3977 | } |
| 3978 | |
| 3979 | if (image->getSamples() > 0) |
| 3980 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3981 | context->handleError(Error(GL_INVALID_OPERATION, |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3982 | "cannot create a 2D texture from a multisampled EGL image.")); |
| 3983 | return false; |
| 3984 | } |
| 3985 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 3986 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getFormat().asSized()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3987 | if (!textureCaps.texturable) |
| 3988 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3989 | context->handleError(Error(GL_INVALID_OPERATION, |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 3990 | "EGL image internal format is not supported as a texture.")); |
| 3991 | return false; |
| 3992 | } |
| 3993 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 3994 | return true; |
| 3995 | } |
| 3996 | |
| 3997 | bool ValidateEGLImageTargetRenderbufferStorageOES(Context *context, |
| 3998 | egl::Display *display, |
| 3999 | GLenum target, |
| 4000 | egl::Image *image) |
| 4001 | { |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4002 | if (!context->getExtensions().eglImage) |
| 4003 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4004 | context->handleError(Error(GL_INVALID_OPERATION)); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4005 | return false; |
| 4006 | } |
| 4007 | |
| 4008 | switch (target) |
| 4009 | { |
| 4010 | case GL_RENDERBUFFER: |
| 4011 | break; |
| 4012 | |
| 4013 | default: |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4014 | context->handleError(Error(GL_INVALID_ENUM, "invalid renderbuffer target.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4015 | return false; |
| 4016 | } |
| 4017 | |
| 4018 | if (!display->isValidImage(image)) |
| 4019 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4020 | context->handleError(Error(GL_INVALID_VALUE, "EGL image is not valid.")); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4021 | return false; |
| 4022 | } |
| 4023 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 4024 | const TextureCaps &textureCaps = context->getTextureCaps().get(image->getFormat().asSized()); |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4025 | if (!textureCaps.renderable) |
| 4026 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4027 | context->handleError(Error( |
Geoff Lang | a840617 | 2015-07-21 16:53:39 -0400 | [diff] [blame] | 4028 | GL_INVALID_OPERATION, "EGL image internal format is not supported as a renderbuffer.")); |
| 4029 | return false; |
| 4030 | } |
| 4031 | |
Geoff Lang | dcab33b | 2015-07-21 13:03:16 -0400 | [diff] [blame] | 4032 | return true; |
| 4033 | } |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 4034 | |
| 4035 | bool ValidateBindVertexArrayBase(Context *context, GLuint array) |
| 4036 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 4037 | if (!context->isVertexArrayGenerated(array)) |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 4038 | { |
| 4039 | // The default VAO should always exist |
| 4040 | ASSERT(array != 0); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4041 | context->handleError(Error(GL_INVALID_OPERATION)); |
Austin Kinross | bc781f3 | 2015-10-26 09:27:38 -0700 | [diff] [blame] | 4042 | return false; |
| 4043 | } |
| 4044 | |
| 4045 | return true; |
| 4046 | } |
| 4047 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4048 | bool ValidateLinkProgram(Context *context, GLuint program) |
| 4049 | { |
| 4050 | if (context->hasActiveTransformFeedback(program)) |
| 4051 | { |
| 4052 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4053 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4054 | "Cannot link program while program is associated with an active " |
| 4055 | "transform feedback object.")); |
| 4056 | return false; |
| 4057 | } |
| 4058 | return true; |
| 4059 | } |
| 4060 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 4061 | bool ValidateProgramBinaryBase(Context *context, |
| 4062 | GLuint program, |
| 4063 | GLenum binaryFormat, |
| 4064 | const void *binary, |
| 4065 | GLint length) |
| 4066 | { |
| 4067 | Program *programObject = GetValidProgram(context, program); |
| 4068 | if (programObject == nullptr) |
| 4069 | { |
| 4070 | return false; |
| 4071 | } |
| 4072 | |
| 4073 | const std::vector<GLenum> &programBinaryFormats = context->getCaps().programBinaryFormats; |
| 4074 | if (std::find(programBinaryFormats.begin(), programBinaryFormats.end(), binaryFormat) == |
| 4075 | programBinaryFormats.end()) |
| 4076 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4077 | context->handleError(Error(GL_INVALID_ENUM, "Program binary format is not valid.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 4078 | return false; |
| 4079 | } |
| 4080 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4081 | if (context->hasActiveTransformFeedback(program)) |
| 4082 | { |
| 4083 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4084 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4085 | "Cannot change program binary while program is associated with " |
| 4086 | "an active transform feedback object.")); |
| 4087 | return false; |
| 4088 | } |
| 4089 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 4090 | return true; |
| 4091 | } |
| 4092 | |
| 4093 | bool ValidateGetProgramBinaryBase(Context *context, |
| 4094 | GLuint program, |
| 4095 | GLsizei bufSize, |
| 4096 | GLsizei *length, |
| 4097 | GLenum *binaryFormat, |
| 4098 | void *binary) |
| 4099 | { |
| 4100 | Program *programObject = GetValidProgram(context, program); |
| 4101 | if (programObject == nullptr) |
| 4102 | { |
| 4103 | return false; |
| 4104 | } |
| 4105 | |
| 4106 | if (!programObject->isLinked()) |
| 4107 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4108 | context->handleError(Error(GL_INVALID_OPERATION, "Program is not linked.")); |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 4109 | return false; |
| 4110 | } |
| 4111 | |
Jamie Madill | a7d12dc | 2016-12-13 15:08:19 -0500 | [diff] [blame] | 4112 | if (context->getCaps().programBinaryFormats.empty()) |
| 4113 | { |
| 4114 | context->handleError(Error(GL_INVALID_OPERATION, "No program binary formats supported.")); |
| 4115 | return false; |
| 4116 | } |
| 4117 | |
Geoff Lang | c562975 | 2015-12-07 16:29:04 -0500 | [diff] [blame] | 4118 | return true; |
| 4119 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4120 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4121 | bool ValidateUseProgram(Context *context, GLuint program) |
| 4122 | { |
| 4123 | if (program != 0) |
| 4124 | { |
| 4125 | Program *programObject = context->getProgram(program); |
| 4126 | if (!programObject) |
| 4127 | { |
| 4128 | // ES 3.1.0 section 7.3 page 72 |
| 4129 | if (context->getShader(program)) |
| 4130 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4131 | context->handleError( |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4132 | Error(GL_INVALID_OPERATION, |
| 4133 | "Attempted to use a single shader instead of a shader program.")); |
| 4134 | return false; |
| 4135 | } |
| 4136 | else |
| 4137 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4138 | context->handleError(Error(GL_INVALID_VALUE, "Program invalid.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4139 | return false; |
| 4140 | } |
| 4141 | } |
| 4142 | if (!programObject->isLinked()) |
| 4143 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4144 | context->handleError(Error(GL_INVALID_OPERATION, "Program not linked.")); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4145 | return false; |
| 4146 | } |
| 4147 | } |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4148 | if (context->getGLState().isTransformFeedbackActiveUnpaused()) |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4149 | { |
| 4150 | // ES 3.0.4 section 2.15 page 91 |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4151 | context->handleError( |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 4152 | Error(GL_INVALID_OPERATION, |
| 4153 | "Cannot change active program while transform feedback is unpaused.")); |
| 4154 | return false; |
| 4155 | } |
| 4156 | |
| 4157 | return true; |
| 4158 | } |
| 4159 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4160 | bool ValidateCopyTexImage2D(ValidationContext *context, |
| 4161 | GLenum target, |
| 4162 | GLint level, |
| 4163 | GLenum internalformat, |
| 4164 | GLint x, |
| 4165 | GLint y, |
| 4166 | GLsizei width, |
| 4167 | GLsizei height, |
| 4168 | GLint border) |
| 4169 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 4170 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4171 | { |
| 4172 | return ValidateES2CopyTexImageParameters(context, target, level, internalformat, false, 0, |
| 4173 | 0, x, y, width, height, border); |
| 4174 | } |
| 4175 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 4176 | ASSERT(context->getClientMajorVersion() == 3); |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 4177 | return ValidateES3CopyTexImage2DParameters(context, target, level, internalformat, false, 0, 0, |
| 4178 | 0, x, y, width, height, border); |
Geoff Lang | e8ebe7f | 2013-08-05 15:03:13 -0400 | [diff] [blame] | 4179 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4180 | |
| 4181 | bool ValidateFramebufferRenderbuffer(Context *context, |
| 4182 | GLenum target, |
| 4183 | GLenum attachment, |
| 4184 | GLenum renderbuffertarget, |
| 4185 | GLuint renderbuffer) |
| 4186 | { |
| 4187 | if (!ValidFramebufferTarget(target) || |
| 4188 | (renderbuffertarget != GL_RENDERBUFFER && renderbuffer != 0)) |
| 4189 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4190 | context->handleError(Error(GL_INVALID_ENUM)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4191 | return false; |
| 4192 | } |
| 4193 | |
| 4194 | return ValidateFramebufferRenderbufferParameters(context, target, attachment, |
| 4195 | renderbuffertarget, renderbuffer); |
| 4196 | } |
| 4197 | |
| 4198 | bool ValidateDrawBuffersBase(ValidationContext *context, GLsizei n, const GLenum *bufs) |
| 4199 | { |
| 4200 | // INVALID_VALUE is generated if n is negative or greater than value of MAX_DRAW_BUFFERS |
| 4201 | if (n < 0 || static_cast<GLuint>(n) > context->getCaps().maxDrawBuffers) |
| 4202 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4203 | context->handleError( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4204 | Error(GL_INVALID_VALUE, "n must be non-negative and no greater than MAX_DRAW_BUFFERS")); |
| 4205 | return false; |
| 4206 | } |
| 4207 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4208 | ASSERT(context->getGLState().getDrawFramebuffer()); |
| 4209 | GLuint frameBufferId = context->getGLState().getDrawFramebuffer()->id(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4210 | GLuint maxColorAttachment = GL_COLOR_ATTACHMENT0_EXT + context->getCaps().maxColorAttachments; |
| 4211 | |
| 4212 | // This should come first before the check for the default frame buffer |
| 4213 | // because when we switch to ES3.1+, invalid enums will return INVALID_ENUM |
| 4214 | // rather than INVALID_OPERATION |
| 4215 | for (int colorAttachment = 0; colorAttachment < n; colorAttachment++) |
| 4216 | { |
| 4217 | const GLenum attachment = GL_COLOR_ATTACHMENT0_EXT + colorAttachment; |
| 4218 | |
| 4219 | if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != GL_BACK && |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 4220 | (bufs[colorAttachment] < GL_COLOR_ATTACHMENT0 || |
| 4221 | bufs[colorAttachment] > GL_COLOR_ATTACHMENT31)) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4222 | { |
| 4223 | // Value in bufs is not NONE, BACK, or GL_COLOR_ATTACHMENTi |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 4224 | // The 3.0.4 spec says to generate GL_INVALID_OPERATION here, but this |
| 4225 | // was changed to GL_INVALID_ENUM in 3.1, which dEQP also expects. |
| 4226 | // 3.1 is still a bit ambiguous about the error, but future specs are |
| 4227 | // expected to clarify that GL_INVALID_ENUM is the correct error. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4228 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer value")); |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 4229 | return false; |
| 4230 | } |
| 4231 | else if (bufs[colorAttachment] >= maxColorAttachment) |
| 4232 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4233 | context->handleError( |
Olli Etuaho | 84c9f59 | 2016-03-09 14:37:25 +0200 | [diff] [blame] | 4234 | Error(GL_INVALID_OPERATION, "Buffer value is greater than MAX_DRAW_BUFFERS")); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4235 | return false; |
| 4236 | } |
| 4237 | else if (bufs[colorAttachment] != GL_NONE && bufs[colorAttachment] != attachment && |
| 4238 | frameBufferId != 0) |
| 4239 | { |
| 4240 | // INVALID_OPERATION-GL is bound to buffer and ith argument |
| 4241 | // is not COLOR_ATTACHMENTi or NONE |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4242 | context->handleError( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4243 | Error(GL_INVALID_OPERATION, "Ith value does not match COLOR_ATTACHMENTi or NONE")); |
| 4244 | return false; |
| 4245 | } |
| 4246 | } |
| 4247 | |
| 4248 | // INVALID_OPERATION is generated if GL is bound to the default framebuffer |
| 4249 | // and n is not 1 or bufs is bound to value other than BACK and NONE |
| 4250 | if (frameBufferId == 0) |
| 4251 | { |
| 4252 | if (n != 1) |
| 4253 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4254 | context->handleError(Error(GL_INVALID_OPERATION, |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4255 | "n must be 1 when GL is bound to the default framebuffer")); |
| 4256 | return false; |
| 4257 | } |
| 4258 | |
| 4259 | if (bufs[0] != GL_NONE && bufs[0] != GL_BACK) |
| 4260 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4261 | context->handleError(Error( |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4262 | GL_INVALID_OPERATION, |
| 4263 | "Only NONE or BACK are valid values when drawing to the default framebuffer")); |
| 4264 | return false; |
| 4265 | } |
| 4266 | } |
| 4267 | |
| 4268 | return true; |
| 4269 | } |
| 4270 | |
| 4271 | bool ValidateCopyTexSubImage2D(Context *context, |
| 4272 | GLenum target, |
| 4273 | GLint level, |
| 4274 | GLint xoffset, |
| 4275 | GLint yoffset, |
| 4276 | GLint x, |
| 4277 | GLint y, |
| 4278 | GLsizei width, |
| 4279 | GLsizei height) |
| 4280 | { |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 4281 | if (context->getClientMajorVersion() < 3) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4282 | { |
| 4283 | return ValidateES2CopyTexImageParameters(context, target, level, GL_NONE, true, xoffset, |
| 4284 | yoffset, x, y, width, height, 0); |
| 4285 | } |
| 4286 | |
Ian Ewell | fc7cf8e | 2016-01-20 15:57:46 -0500 | [diff] [blame] | 4287 | return ValidateES3CopyTexImage2DParameters(context, target, level, GL_NONE, true, xoffset, |
| 4288 | yoffset, 0, x, y, width, height, 0); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 4289 | } |
| 4290 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4291 | bool ValidateGetBufferPointervBase(Context *context, |
| 4292 | GLenum target, |
| 4293 | GLenum pname, |
| 4294 | GLsizei *length, |
| 4295 | void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4296 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4297 | if (length) |
| 4298 | { |
| 4299 | *length = 0; |
| 4300 | } |
| 4301 | |
| 4302 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().mapBuffer) |
| 4303 | { |
| 4304 | context->handleError( |
| 4305 | Error(GL_INVALID_OPERATION, |
| 4306 | "Context does not support OpenGL ES 3.0 or GL_OES_map_buffer is not enabled.")); |
| 4307 | return false; |
| 4308 | } |
| 4309 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4310 | if (!ValidBufferTarget(context, target)) |
| 4311 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4312 | 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] | 4313 | return false; |
| 4314 | } |
| 4315 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4316 | switch (pname) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4317 | { |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4318 | case GL_BUFFER_MAP_POINTER: |
| 4319 | break; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4320 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4321 | default: |
| 4322 | context->handleError(Error(GL_INVALID_ENUM, "Unknown pname.")); |
| 4323 | return false; |
| 4324 | } |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4325 | |
| 4326 | // GLES 3.0 section 2.10.1: "Attempts to attempts to modify or query buffer object state for a |
| 4327 | // target bound to zero generate an INVALID_OPERATION error." |
| 4328 | // GLES 3.1 section 6.6 explicitly specifies this error. |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4329 | if (context->getGLState().getTargetBuffer(target) == nullptr) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4330 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4331 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4332 | Error(GL_INVALID_OPERATION, "Can not get pointer for reserved buffer name zero.")); |
| 4333 | return false; |
| 4334 | } |
| 4335 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 4336 | if (length) |
| 4337 | { |
| 4338 | *length = 1; |
| 4339 | } |
| 4340 | |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4341 | return true; |
| 4342 | } |
| 4343 | |
| 4344 | bool ValidateUnmapBufferBase(Context *context, GLenum target) |
| 4345 | { |
| 4346 | if (!ValidBufferTarget(context, target)) |
| 4347 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4348 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4349 | return false; |
| 4350 | } |
| 4351 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4352 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4353 | |
| 4354 | if (buffer == nullptr || !buffer->isMapped()) |
| 4355 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4356 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer not mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4357 | return false; |
| 4358 | } |
| 4359 | |
| 4360 | return true; |
| 4361 | } |
| 4362 | |
| 4363 | bool ValidateMapBufferRangeBase(Context *context, |
| 4364 | GLenum target, |
| 4365 | GLintptr offset, |
| 4366 | GLsizeiptr length, |
| 4367 | GLbitfield access) |
| 4368 | { |
| 4369 | if (!ValidBufferTarget(context, target)) |
| 4370 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4371 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4372 | return false; |
| 4373 | } |
| 4374 | |
| 4375 | if (offset < 0 || length < 0) |
| 4376 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4377 | context->handleError(Error(GL_INVALID_VALUE, "Invalid offset or length.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4378 | return false; |
| 4379 | } |
| 4380 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4381 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4382 | |
| 4383 | if (!buffer) |
| 4384 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4385 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to map buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4386 | return false; |
| 4387 | } |
| 4388 | |
| 4389 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4390 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4391 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4392 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4393 | if (!checkedSize.IsValid() || checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getSize())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4394 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4395 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4396 | Error(GL_INVALID_VALUE, "Mapped range does not fit into buffer dimensions.")); |
| 4397 | return false; |
| 4398 | } |
| 4399 | |
| 4400 | // Check for invalid bits in the mask |
| 4401 | GLbitfield allAccessBits = GL_MAP_READ_BIT | GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | |
| 4402 | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_FLUSH_EXPLICIT_BIT | |
| 4403 | GL_MAP_UNSYNCHRONIZED_BIT; |
| 4404 | |
| 4405 | if (access & ~(allAccessBits)) |
| 4406 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4407 | context->handleError(Error(GL_INVALID_VALUE, "Invalid access bits: 0x%X.", access)); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4408 | return false; |
| 4409 | } |
| 4410 | |
| 4411 | if (length == 0) |
| 4412 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4413 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer mapping length is zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4414 | return false; |
| 4415 | } |
| 4416 | |
| 4417 | if (buffer->isMapped()) |
| 4418 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4419 | context->handleError(Error(GL_INVALID_OPERATION, "Buffer is already mapped.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4420 | return false; |
| 4421 | } |
| 4422 | |
| 4423 | // Check for invalid bit combinations |
| 4424 | if ((access & (GL_MAP_READ_BIT | GL_MAP_WRITE_BIT)) == 0) |
| 4425 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4426 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4427 | Error(GL_INVALID_OPERATION, "Need to map buffer for either reading or writing.")); |
| 4428 | return false; |
| 4429 | } |
| 4430 | |
| 4431 | GLbitfield writeOnlyBits = |
| 4432 | GL_MAP_INVALIDATE_RANGE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT | GL_MAP_UNSYNCHRONIZED_BIT; |
| 4433 | |
| 4434 | if ((access & GL_MAP_READ_BIT) != 0 && (access & writeOnlyBits) != 0) |
| 4435 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4436 | context->handleError(Error(GL_INVALID_OPERATION, |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4437 | "Invalid access bits when mapping buffer for reading: 0x%X.", |
| 4438 | access)); |
| 4439 | return false; |
| 4440 | } |
| 4441 | |
| 4442 | if ((access & GL_MAP_WRITE_BIT) == 0 && (access & GL_MAP_FLUSH_EXPLICIT_BIT) != 0) |
| 4443 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4444 | context->handleError(Error( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4445 | GL_INVALID_OPERATION, |
| 4446 | "The explicit flushing bit may only be set if the buffer is mapped for writing.")); |
| 4447 | return false; |
| 4448 | } |
| 4449 | return true; |
| 4450 | } |
| 4451 | |
| 4452 | bool ValidateFlushMappedBufferRangeBase(Context *context, |
| 4453 | GLenum target, |
| 4454 | GLintptr offset, |
| 4455 | GLsizeiptr length) |
| 4456 | { |
| 4457 | if (offset < 0 || length < 0) |
| 4458 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4459 | context->handleError(Error(GL_INVALID_VALUE, "Invalid offset/length parameters.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4460 | return false; |
| 4461 | } |
| 4462 | |
| 4463 | if (!ValidBufferTarget(context, target)) |
| 4464 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4465 | context->handleError(Error(GL_INVALID_ENUM, "Invalid buffer target.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4466 | return false; |
| 4467 | } |
| 4468 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 4469 | Buffer *buffer = context->getGLState().getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4470 | |
| 4471 | if (buffer == nullptr) |
| 4472 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4473 | context->handleError(Error(GL_INVALID_OPERATION, "Attempted to flush buffer object zero.")); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4474 | return false; |
| 4475 | } |
| 4476 | |
| 4477 | if (!buffer->isMapped() || (buffer->getAccessFlags() & GL_MAP_FLUSH_EXPLICIT_BIT) == 0) |
| 4478 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4479 | context->handleError(Error( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4480 | GL_INVALID_OPERATION, "Attempted to flush a buffer not mapped for explicit flushing.")); |
| 4481 | return false; |
| 4482 | } |
| 4483 | |
| 4484 | // Check for buffer overflow |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4485 | CheckedNumeric<size_t> checkedOffset(offset); |
| 4486 | auto checkedSize = checkedOffset + length; |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4487 | |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 4488 | if (!checkedSize.IsValid() || |
| 4489 | checkedSize.ValueOrDie() > static_cast<size_t>(buffer->getMapLength())) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4490 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4491 | context->handleError( |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 4492 | Error(GL_INVALID_VALUE, "Flushed range does not fit into buffer mapping dimensions.")); |
| 4493 | return false; |
| 4494 | } |
| 4495 | |
| 4496 | return true; |
| 4497 | } |
| 4498 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4499 | bool ValidateGenerateMipmap(Context *context, GLenum target) |
| 4500 | { |
| 4501 | if (!ValidTextureTarget(context, target)) |
| 4502 | { |
| 4503 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4504 | return false; |
| 4505 | } |
| 4506 | |
| 4507 | Texture *texture = context->getTargetTexture(target); |
| 4508 | |
| 4509 | if (texture == nullptr) |
| 4510 | { |
| 4511 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4512 | return false; |
| 4513 | } |
| 4514 | |
| 4515 | const GLuint effectiveBaseLevel = texture->getTextureState().getEffectiveBaseLevel(); |
| 4516 | |
| 4517 | // This error isn't spelled out in the spec in a very explicit way, but we interpret the spec so |
| 4518 | // that out-of-range base level has a non-color-renderable / non-texture-filterable format. |
| 4519 | if (effectiveBaseLevel >= gl::IMPLEMENTATION_MAX_TEXTURE_LEVELS) |
| 4520 | { |
| 4521 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4522 | return false; |
| 4523 | } |
| 4524 | |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 4525 | GLenum baseTarget = (target == GL_TEXTURE_CUBE_MAP) ? GL_TEXTURE_CUBE_MAP_POSITIVE_X : target; |
| 4526 | const auto &format = texture->getFormat(baseTarget, effectiveBaseLevel); |
| 4527 | const TextureCaps &formatCaps = context->getTextureCaps().get(format.asSized()); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4528 | |
| 4529 | // GenerateMipmap should not generate an INVALID_OPERATION for textures created with |
| 4530 | // unsized formats or that are color renderable and filterable. Since we do not track if |
| 4531 | // the texture was created with sized or unsized format (only sized formats are stored), |
| 4532 | // it is not possible to make sure the the LUMA formats can generate mipmaps (they should |
| 4533 | // be able to) because they aren't color renderable. Simply do a special case for LUMA |
| 4534 | // textures since they're the only texture format that can be created with unsized formats |
| 4535 | // that is not color renderable. New unsized formats are unlikely to be added, since ES2 |
| 4536 | // was the last version to use add them. |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 4537 | if (format.info->depthBits > 0 || format.info->stencilBits > 0 || !formatCaps.filterable || |
| 4538 | (!formatCaps.renderable && !format.info->isLUMA()) || format.info->compressed) |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4539 | { |
| 4540 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4541 | return false; |
| 4542 | } |
| 4543 | |
| 4544 | // GL_EXT_sRGB does not support mipmap generation on sRGB textures |
Jamie Madill | a3944d4 | 2016-07-22 22:13:26 -0400 | [diff] [blame] | 4545 | if (context->getClientMajorVersion() == 2 && format.info->colorEncoding == GL_SRGB) |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4546 | { |
| 4547 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4548 | return false; |
| 4549 | } |
| 4550 | |
| 4551 | // Non-power of 2 ES2 check |
Geoff Lang | 55482a1 | 2016-11-21 16:54:01 -0500 | [diff] [blame] | 4552 | if (context->getClientVersion() < Version(3, 0) && !context->getExtensions().textureNPOT && |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4553 | (!isPow2(static_cast<int>(texture->getWidth(baseTarget, 0))) || |
| 4554 | !isPow2(static_cast<int>(texture->getHeight(baseTarget, 0))))) |
| 4555 | { |
Geoff Lang | 55482a1 | 2016-11-21 16:54:01 -0500 | [diff] [blame] | 4556 | ASSERT(target == GL_TEXTURE_2D || target == GL_TEXTURE_CUBE_MAP); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 4557 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4558 | return false; |
| 4559 | } |
| 4560 | |
| 4561 | // Cube completeness check |
| 4562 | if (target == GL_TEXTURE_CUBE_MAP && !texture->getTextureState().isCubeComplete()) |
| 4563 | { |
| 4564 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4565 | return false; |
| 4566 | } |
| 4567 | |
| 4568 | return true; |
| 4569 | } |
| 4570 | |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4571 | bool ValidateGenBuffers(Context *context, GLint n, GLuint *) |
| 4572 | { |
| 4573 | return ValidateGenOrDelete(context, n); |
| 4574 | } |
| 4575 | |
| 4576 | bool ValidateDeleteBuffers(Context *context, GLint n, const GLuint *) |
| 4577 | { |
| 4578 | return ValidateGenOrDelete(context, n); |
| 4579 | } |
| 4580 | |
| 4581 | bool ValidateGenFramebuffers(Context *context, GLint n, GLuint *) |
| 4582 | { |
| 4583 | return ValidateGenOrDelete(context, n); |
| 4584 | } |
| 4585 | |
| 4586 | bool ValidateDeleteFramebuffers(Context *context, GLint n, const GLuint *) |
| 4587 | { |
| 4588 | return ValidateGenOrDelete(context, n); |
| 4589 | } |
| 4590 | |
| 4591 | bool ValidateGenRenderbuffers(Context *context, GLint n, GLuint *) |
| 4592 | { |
| 4593 | return ValidateGenOrDelete(context, n); |
| 4594 | } |
| 4595 | |
| 4596 | bool ValidateDeleteRenderbuffers(Context *context, GLint n, const GLuint *) |
| 4597 | { |
| 4598 | return ValidateGenOrDelete(context, n); |
| 4599 | } |
| 4600 | |
| 4601 | bool ValidateGenTextures(Context *context, GLint n, GLuint *) |
| 4602 | { |
| 4603 | return ValidateGenOrDelete(context, n); |
| 4604 | } |
| 4605 | |
| 4606 | bool ValidateDeleteTextures(Context *context, GLint n, const GLuint *) |
| 4607 | { |
| 4608 | return ValidateGenOrDelete(context, n); |
| 4609 | } |
| 4610 | |
| 4611 | bool ValidateGenOrDelete(Context *context, GLint n) |
| 4612 | { |
| 4613 | if (n < 0) |
| 4614 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 4615 | context->handleError(Error(GL_INVALID_VALUE, "n < 0")); |
Olli Etuaho | 41997e7 | 2016-03-10 13:38:39 +0200 | [diff] [blame] | 4616 | return false; |
| 4617 | } |
| 4618 | return true; |
| 4619 | } |
| 4620 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 4621 | bool ValidateEnable(Context *context, GLenum cap) |
| 4622 | { |
| 4623 | if (!ValidCap(context, cap, false)) |
| 4624 | { |
| 4625 | context->handleError(Error(GL_INVALID_ENUM, "Invalid cap.")); |
| 4626 | return false; |
| 4627 | } |
| 4628 | |
| 4629 | if (context->getLimitations().noSampleAlphaToCoverageSupport && |
| 4630 | cap == GL_SAMPLE_ALPHA_TO_COVERAGE) |
| 4631 | { |
| 4632 | const char *errorMessage = "Current renderer doesn't support alpha-to-coverage"; |
| 4633 | context->handleError(Error(GL_INVALID_OPERATION, errorMessage)); |
| 4634 | |
| 4635 | // We also output an error message to the debugger window if tracing is active, so that |
| 4636 | // developers can see the error message. |
Jamie Madill | 6a6b09c | 2017-01-12 21:52:29 +0000 | [diff] [blame] | 4637 | ERR("%s", errorMessage); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 4638 | return false; |
| 4639 | } |
| 4640 | |
| 4641 | return true; |
| 4642 | } |
| 4643 | |
| 4644 | bool ValidateDisable(Context *context, GLenum cap) |
| 4645 | { |
| 4646 | if (!ValidCap(context, cap, false)) |
| 4647 | { |
| 4648 | context->handleError(Error(GL_INVALID_ENUM, "Invalid cap.")); |
| 4649 | return false; |
| 4650 | } |
| 4651 | |
| 4652 | return true; |
| 4653 | } |
| 4654 | |
| 4655 | bool ValidateIsEnabled(Context *context, GLenum cap) |
| 4656 | { |
| 4657 | if (!ValidCap(context, cap, true)) |
| 4658 | { |
| 4659 | context->handleError(Error(GL_INVALID_ENUM, "Invalid cap.")); |
| 4660 | return false; |
| 4661 | } |
| 4662 | |
| 4663 | return true; |
| 4664 | } |
| 4665 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4666 | bool ValidateRobustEntryPoint(ValidationContext *context, GLsizei bufSize) |
| 4667 | { |
| 4668 | if (!context->getExtensions().robustClientMemory) |
| 4669 | { |
| 4670 | context->handleError( |
| 4671 | Error(GL_INVALID_OPERATION, "GL_ANGLE_robust_client_memory is not available.")); |
| 4672 | return false; |
| 4673 | } |
| 4674 | |
| 4675 | if (bufSize < 0) |
| 4676 | { |
| 4677 | context->handleError(Error(GL_INVALID_VALUE, "bufSize cannot be negative.")); |
| 4678 | return false; |
| 4679 | } |
| 4680 | |
| 4681 | return true; |
| 4682 | } |
| 4683 | |
Geoff Lang | 2e43dbb | 2016-10-14 12:27:35 -0400 | [diff] [blame] | 4684 | bool ValidateRobustBufferSize(ValidationContext *context, GLsizei bufSize, GLsizei numParams) |
| 4685 | { |
| 4686 | if (bufSize < numParams) |
| 4687 | { |
| 4688 | context->handleError(Error(GL_INVALID_OPERATION, |
| 4689 | "%u parameters are required but %i were provided.", numParams, |
| 4690 | bufSize)); |
| 4691 | return false; |
| 4692 | } |
| 4693 | |
| 4694 | return true; |
| 4695 | } |
| 4696 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4697 | bool ValidateGetFramebufferAttachmentParameteriv(ValidationContext *context, |
| 4698 | GLenum target, |
| 4699 | GLenum attachment, |
| 4700 | GLenum pname, |
| 4701 | GLsizei *numParams) |
| 4702 | { |
| 4703 | // Only one parameter is returned from glGetFramebufferAttachmentParameteriv |
| 4704 | *numParams = 1; |
| 4705 | |
| 4706 | if (!ValidFramebufferTarget(target)) |
| 4707 | { |
| 4708 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4709 | return false; |
| 4710 | } |
| 4711 | |
| 4712 | int clientVersion = context->getClientMajorVersion(); |
| 4713 | |
| 4714 | switch (pname) |
| 4715 | { |
| 4716 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4717 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4718 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4719 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4720 | break; |
| 4721 | |
| 4722 | case GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING: |
| 4723 | if (clientVersion < 3 && !context->getExtensions().sRGB) |
| 4724 | { |
| 4725 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4726 | return false; |
| 4727 | } |
| 4728 | break; |
| 4729 | |
| 4730 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
| 4731 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
| 4732 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
| 4733 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
| 4734 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
| 4735 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
| 4736 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4737 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4738 | if (clientVersion < 3) |
| 4739 | { |
| 4740 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4741 | return false; |
| 4742 | } |
| 4743 | break; |
| 4744 | |
| 4745 | default: |
| 4746 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4747 | return false; |
| 4748 | } |
| 4749 | |
| 4750 | // Determine if the attachment is a valid enum |
| 4751 | switch (attachment) |
| 4752 | { |
| 4753 | case GL_BACK: |
| 4754 | case GL_FRONT: |
| 4755 | case GL_DEPTH: |
| 4756 | case GL_STENCIL: |
| 4757 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4758 | if (clientVersion < 3) |
| 4759 | { |
| 4760 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4761 | return false; |
| 4762 | } |
| 4763 | break; |
| 4764 | |
| 4765 | case GL_DEPTH_ATTACHMENT: |
| 4766 | case GL_STENCIL_ATTACHMENT: |
| 4767 | break; |
| 4768 | |
| 4769 | default: |
| 4770 | if (attachment < GL_COLOR_ATTACHMENT0_EXT || |
| 4771 | (attachment - GL_COLOR_ATTACHMENT0_EXT) >= context->getCaps().maxColorAttachments) |
| 4772 | { |
| 4773 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4774 | return false; |
| 4775 | } |
| 4776 | break; |
| 4777 | } |
| 4778 | |
| 4779 | const Framebuffer *framebuffer = context->getGLState().getTargetFramebuffer(target); |
| 4780 | ASSERT(framebuffer); |
| 4781 | |
| 4782 | if (framebuffer->id() == 0) |
| 4783 | { |
| 4784 | if (clientVersion < 3) |
| 4785 | { |
| 4786 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4787 | return false; |
| 4788 | } |
| 4789 | |
| 4790 | switch (attachment) |
| 4791 | { |
| 4792 | case GL_BACK: |
| 4793 | case GL_DEPTH: |
| 4794 | case GL_STENCIL: |
| 4795 | break; |
| 4796 | |
| 4797 | default: |
| 4798 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4799 | return false; |
| 4800 | } |
| 4801 | } |
| 4802 | else |
| 4803 | { |
| 4804 | if (attachment >= GL_COLOR_ATTACHMENT0_EXT && attachment <= GL_COLOR_ATTACHMENT15_EXT) |
| 4805 | { |
| 4806 | // Valid attachment query |
| 4807 | } |
| 4808 | else |
| 4809 | { |
| 4810 | switch (attachment) |
| 4811 | { |
| 4812 | case GL_DEPTH_ATTACHMENT: |
| 4813 | case GL_STENCIL_ATTACHMENT: |
| 4814 | break; |
| 4815 | |
| 4816 | case GL_DEPTH_STENCIL_ATTACHMENT: |
| 4817 | if (!framebuffer->hasValidDepthStencil()) |
| 4818 | { |
| 4819 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4820 | return false; |
| 4821 | } |
| 4822 | break; |
| 4823 | |
| 4824 | default: |
| 4825 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4826 | return false; |
| 4827 | } |
| 4828 | } |
| 4829 | } |
| 4830 | |
| 4831 | const FramebufferAttachment *attachmentObject = framebuffer->getAttachment(attachment); |
| 4832 | if (attachmentObject) |
| 4833 | { |
| 4834 | ASSERT(attachmentObject->type() == GL_RENDERBUFFER || |
| 4835 | attachmentObject->type() == GL_TEXTURE || |
| 4836 | attachmentObject->type() == GL_FRAMEBUFFER_DEFAULT); |
| 4837 | |
| 4838 | switch (pname) |
| 4839 | { |
| 4840 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4841 | if (attachmentObject->type() != GL_RENDERBUFFER && |
| 4842 | attachmentObject->type() != GL_TEXTURE) |
| 4843 | { |
| 4844 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4845 | return false; |
| 4846 | } |
| 4847 | break; |
| 4848 | |
| 4849 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL: |
| 4850 | if (attachmentObject->type() != GL_TEXTURE) |
| 4851 | { |
| 4852 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4853 | return false; |
| 4854 | } |
| 4855 | break; |
| 4856 | |
| 4857 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE: |
| 4858 | if (attachmentObject->type() != GL_TEXTURE) |
| 4859 | { |
| 4860 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4861 | return false; |
| 4862 | } |
| 4863 | break; |
| 4864 | |
| 4865 | case GL_FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE: |
| 4866 | if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) |
| 4867 | { |
| 4868 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4869 | return false; |
| 4870 | } |
| 4871 | break; |
| 4872 | |
| 4873 | case GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER: |
| 4874 | if (attachmentObject->type() != GL_TEXTURE) |
| 4875 | { |
| 4876 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4877 | return false; |
| 4878 | } |
| 4879 | break; |
| 4880 | |
| 4881 | default: |
| 4882 | break; |
| 4883 | } |
| 4884 | } |
| 4885 | else |
| 4886 | { |
| 4887 | // ES 2.0.25 spec pg 127 states that if the value of FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE |
| 4888 | // is NONE, then querying any other pname will generate INVALID_ENUM. |
| 4889 | |
| 4890 | // ES 3.0.2 spec pg 235 states that if the attachment type is none, |
| 4891 | // GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME will return zero and be an |
| 4892 | // INVALID_OPERATION for all other pnames |
| 4893 | |
| 4894 | switch (pname) |
| 4895 | { |
| 4896 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE: |
| 4897 | break; |
| 4898 | |
| 4899 | case GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME: |
| 4900 | if (clientVersion < 3) |
| 4901 | { |
| 4902 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4903 | return false; |
| 4904 | } |
| 4905 | break; |
| 4906 | |
| 4907 | default: |
| 4908 | if (clientVersion < 3) |
| 4909 | { |
| 4910 | context->handleError(Error(GL_INVALID_ENUM)); |
| 4911 | return false; |
| 4912 | } |
| 4913 | else |
| 4914 | { |
| 4915 | context->handleError(Error(GL_INVALID_OPERATION)); |
| 4916 | return false; |
| 4917 | } |
| 4918 | } |
| 4919 | } |
| 4920 | |
| 4921 | return true; |
| 4922 | } |
| 4923 | |
| 4924 | bool ValidateGetFramebufferAttachmentParameterivRobustANGLE(ValidationContext *context, |
| 4925 | GLenum target, |
| 4926 | GLenum attachment, |
| 4927 | GLenum pname, |
| 4928 | GLsizei bufSize, |
| 4929 | GLsizei *numParams) |
| 4930 | { |
| 4931 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4932 | { |
| 4933 | return false; |
| 4934 | } |
| 4935 | |
| 4936 | if (!ValidateGetFramebufferAttachmentParameteriv(context, target, attachment, pname, numParams)) |
| 4937 | { |
| 4938 | return false; |
| 4939 | } |
| 4940 | |
| 4941 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
| 4942 | { |
| 4943 | return false; |
| 4944 | } |
| 4945 | |
| 4946 | return true; |
| 4947 | } |
| 4948 | |
| 4949 | bool ValidateGetBufferParameteriv(ValidationContext *context, |
| 4950 | GLenum target, |
| 4951 | GLenum pname, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4952 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4953 | { |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4954 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4955 | } |
| 4956 | |
| 4957 | bool ValidateGetBufferParameterivRobustANGLE(ValidationContext *context, |
| 4958 | GLenum target, |
| 4959 | GLenum pname, |
| 4960 | GLsizei bufSize, |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4961 | GLsizei *length, |
| 4962 | GLint *params) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4963 | { |
| 4964 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4965 | { |
| 4966 | return false; |
| 4967 | } |
| 4968 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4969 | if (!ValidateGetBufferParameterBase(context, target, pname, false, length)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 4970 | { |
| 4971 | return false; |
| 4972 | } |
| 4973 | |
Geoff Lang | ebebe1c | 2016-10-14 12:01:31 -0400 | [diff] [blame] | 4974 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 4975 | { |
| 4976 | return false; |
| 4977 | } |
| 4978 | |
| 4979 | return true; |
| 4980 | } |
| 4981 | |
| 4982 | bool ValidateGetBufferParameteri64v(ValidationContext *context, |
| 4983 | GLenum target, |
| 4984 | GLenum pname, |
| 4985 | GLint64 *params) |
| 4986 | { |
| 4987 | return ValidateGetBufferParameterBase(context, target, pname, false, nullptr); |
| 4988 | } |
| 4989 | |
| 4990 | bool ValidateGetBufferParameteri64vRobustANGLE(ValidationContext *context, |
| 4991 | GLenum target, |
| 4992 | GLenum pname, |
| 4993 | GLsizei bufSize, |
| 4994 | GLsizei *length, |
| 4995 | GLint64 *params) |
| 4996 | { |
| 4997 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 4998 | { |
| 4999 | return false; |
| 5000 | } |
| 5001 | |
| 5002 | if (!ValidateGetBufferParameterBase(context, target, pname, false, length)) |
| 5003 | { |
| 5004 | return false; |
| 5005 | } |
| 5006 | |
| 5007 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 5008 | { |
| 5009 | return false; |
| 5010 | } |
| 5011 | |
| 5012 | return true; |
| 5013 | } |
| 5014 | |
| 5015 | bool ValidateGetProgramiv(Context *context, GLuint program, GLenum pname, GLsizei *numParams) |
| 5016 | { |
| 5017 | // Currently, all GetProgramiv queries return 1 parameter |
| 5018 | *numParams = 1; |
| 5019 | |
| 5020 | Program *programObject = GetValidProgram(context, program); |
| 5021 | if (!programObject) |
| 5022 | { |
| 5023 | return false; |
| 5024 | } |
| 5025 | |
| 5026 | switch (pname) |
| 5027 | { |
| 5028 | case GL_DELETE_STATUS: |
| 5029 | case GL_LINK_STATUS: |
| 5030 | case GL_VALIDATE_STATUS: |
| 5031 | case GL_INFO_LOG_LENGTH: |
| 5032 | case GL_ATTACHED_SHADERS: |
| 5033 | case GL_ACTIVE_ATTRIBUTES: |
| 5034 | case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH: |
| 5035 | case GL_ACTIVE_UNIFORMS: |
| 5036 | case GL_ACTIVE_UNIFORM_MAX_LENGTH: |
| 5037 | break; |
| 5038 | |
| 5039 | case GL_PROGRAM_BINARY_LENGTH: |
| 5040 | if (context->getClientMajorVersion() < 3 && !context->getExtensions().getProgramBinary) |
| 5041 | { |
| 5042 | context->handleError(Error(GL_INVALID_ENUM, |
| 5043 | "Querying GL_PROGRAM_BINARY_LENGTH requires " |
| 5044 | "GL_OES_get_program_binary or ES 3.0.")); |
| 5045 | return false; |
| 5046 | } |
| 5047 | break; |
| 5048 | |
| 5049 | case GL_ACTIVE_UNIFORM_BLOCKS: |
| 5050 | case GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH: |
| 5051 | case GL_TRANSFORM_FEEDBACK_BUFFER_MODE: |
| 5052 | case GL_TRANSFORM_FEEDBACK_VARYINGS: |
| 5053 | case GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH: |
| 5054 | case GL_PROGRAM_BINARY_RETRIEVABLE_HINT: |
| 5055 | if (context->getClientMajorVersion() < 3) |
| 5056 | { |
| 5057 | context->handleError(Error(GL_INVALID_ENUM, "Querying requires at least ES 3.0.")); |
| 5058 | return false; |
| 5059 | } |
| 5060 | break; |
| 5061 | |
| 5062 | default: |
| 5063 | context->handleError(Error(GL_INVALID_ENUM, "Unknown parameter name.")); |
| 5064 | return false; |
| 5065 | } |
| 5066 | |
| 5067 | return true; |
| 5068 | } |
| 5069 | |
| 5070 | bool ValidateGetProgramivRobustANGLE(Context *context, |
| 5071 | GLuint program, |
| 5072 | GLenum pname, |
| 5073 | GLsizei bufSize, |
| 5074 | GLsizei *numParams) |
| 5075 | { |
| 5076 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5077 | { |
| 5078 | return false; |
| 5079 | } |
| 5080 | |
| 5081 | if (!ValidateGetProgramiv(context, program, pname, numParams)) |
| 5082 | { |
| 5083 | return false; |
| 5084 | } |
| 5085 | |
| 5086 | if (!ValidateRobustBufferSize(context, bufSize, *numParams)) |
| 5087 | { |
| 5088 | return false; |
| 5089 | } |
| 5090 | |
| 5091 | return true; |
| 5092 | } |
| 5093 | |
Geoff Lang | 740d902 | 2016-10-07 11:20:52 -0400 | [diff] [blame] | 5094 | bool ValidateGetRenderbufferParameteriv(Context *context, |
| 5095 | GLenum target, |
| 5096 | GLenum pname, |
| 5097 | GLint *params) |
| 5098 | { |
| 5099 | return ValidateGetRenderbufferParameterivBase(context, target, pname, nullptr); |
| 5100 | } |
| 5101 | |
| 5102 | bool ValidateGetRenderbufferParameterivRobustANGLE(Context *context, |
| 5103 | GLenum target, |
| 5104 | GLenum pname, |
| 5105 | GLsizei bufSize, |
| 5106 | GLsizei *length, |
| 5107 | GLint *params) |
| 5108 | { |
| 5109 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5110 | { |
| 5111 | return false; |
| 5112 | } |
| 5113 | |
| 5114 | if (!ValidateGetRenderbufferParameterivBase(context, target, pname, length)) |
| 5115 | { |
| 5116 | return false; |
| 5117 | } |
| 5118 | |
| 5119 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5120 | { |
| 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | return true; |
| 5125 | } |
| 5126 | |
Geoff Lang | d7d0ed3 | 2016-10-07 11:33:51 -0400 | [diff] [blame] | 5127 | bool ValidateGetShaderiv(Context *context, GLuint shader, GLenum pname, GLint *params) |
| 5128 | { |
| 5129 | return ValidateGetShaderivBase(context, shader, pname, nullptr); |
| 5130 | } |
| 5131 | |
| 5132 | bool ValidateGetShaderivRobustANGLE(Context *context, |
| 5133 | GLuint shader, |
| 5134 | GLenum pname, |
| 5135 | GLsizei bufSize, |
| 5136 | GLsizei *length, |
| 5137 | GLint *params) |
| 5138 | { |
| 5139 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5140 | { |
| 5141 | return false; |
| 5142 | } |
| 5143 | |
| 5144 | if (!ValidateGetShaderivBase(context, shader, pname, length)) |
| 5145 | { |
| 5146 | return false; |
| 5147 | } |
| 5148 | |
| 5149 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5150 | { |
| 5151 | return false; |
| 5152 | } |
| 5153 | |
| 5154 | return true; |
| 5155 | } |
| 5156 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 5157 | bool ValidateGetTexParameterfv(Context *context, GLenum target, GLenum pname, GLfloat *params) |
| 5158 | { |
| 5159 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 5160 | } |
| 5161 | |
| 5162 | bool ValidateGetTexParameterfvRobustANGLE(Context *context, |
| 5163 | GLenum target, |
| 5164 | GLenum pname, |
| 5165 | GLsizei bufSize, |
| 5166 | GLsizei *length, |
| 5167 | GLfloat *params) |
| 5168 | { |
| 5169 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5170 | { |
| 5171 | return false; |
| 5172 | } |
| 5173 | |
| 5174 | if (!ValidateGetTexParameterBase(context, target, pname, length)) |
| 5175 | { |
| 5176 | return false; |
| 5177 | } |
| 5178 | |
| 5179 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5180 | { |
| 5181 | return false; |
| 5182 | } |
| 5183 | |
| 5184 | return true; |
| 5185 | } |
| 5186 | |
| 5187 | bool ValidateGetTexParameteriv(Context *context, GLenum target, GLenum pname, GLint *params) |
| 5188 | { |
| 5189 | return ValidateGetTexParameterBase(context, target, pname, nullptr); |
| 5190 | } |
| 5191 | |
| 5192 | bool ValidateGetTexParameterivRobustANGLE(Context *context, |
| 5193 | GLenum target, |
| 5194 | GLenum pname, |
| 5195 | GLsizei bufSize, |
| 5196 | GLsizei *length, |
| 5197 | GLint *params) |
| 5198 | { |
| 5199 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5200 | { |
| 5201 | return false; |
| 5202 | } |
| 5203 | |
| 5204 | if (!ValidateGetTexParameterBase(context, target, pname, length)) |
| 5205 | { |
| 5206 | return false; |
| 5207 | } |
| 5208 | |
| 5209 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5210 | { |
| 5211 | return false; |
| 5212 | } |
| 5213 | |
| 5214 | return true; |
| 5215 | } |
| 5216 | |
| 5217 | bool ValidateTexParameterf(Context *context, GLenum target, GLenum pname, GLfloat param) |
| 5218 | { |
| 5219 | return ValidateTexParameterBase(context, target, pname, -1, ¶m); |
| 5220 | } |
| 5221 | |
| 5222 | bool ValidateTexParameterfv(Context *context, GLenum target, GLenum pname, const GLfloat *params) |
| 5223 | { |
| 5224 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 5225 | } |
| 5226 | |
| 5227 | bool ValidateTexParameterfvRobustANGLE(Context *context, |
| 5228 | GLenum target, |
| 5229 | GLenum pname, |
| 5230 | GLsizei bufSize, |
| 5231 | const GLfloat *params) |
| 5232 | { |
| 5233 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5234 | { |
| 5235 | return false; |
| 5236 | } |
| 5237 | |
| 5238 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 5239 | } |
| 5240 | |
| 5241 | bool ValidateTexParameteri(Context *context, GLenum target, GLenum pname, GLint param) |
| 5242 | { |
| 5243 | return ValidateTexParameterBase(context, target, pname, -1, ¶m); |
| 5244 | } |
| 5245 | |
| 5246 | bool ValidateTexParameteriv(Context *context, GLenum target, GLenum pname, const GLint *params) |
| 5247 | { |
| 5248 | return ValidateTexParameterBase(context, target, pname, -1, params); |
| 5249 | } |
| 5250 | |
| 5251 | bool ValidateTexParameterivRobustANGLE(Context *context, |
| 5252 | GLenum target, |
| 5253 | GLenum pname, |
| 5254 | GLsizei bufSize, |
| 5255 | const GLint *params) |
| 5256 | { |
| 5257 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5258 | { |
| 5259 | return false; |
| 5260 | } |
| 5261 | |
| 5262 | return ValidateTexParameterBase(context, target, pname, bufSize, params); |
| 5263 | } |
| 5264 | |
| 5265 | bool ValidateGetSamplerParameterfv(Context *context, GLuint sampler, GLenum pname, GLfloat *params) |
| 5266 | { |
| 5267 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 5268 | } |
| 5269 | |
| 5270 | bool ValidateGetSamplerParameterfvRobustANGLE(Context *context, |
| 5271 | GLuint sampler, |
| 5272 | GLenum pname, |
| 5273 | GLuint bufSize, |
| 5274 | GLsizei *length, |
| 5275 | GLfloat *params) |
| 5276 | { |
| 5277 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5278 | { |
| 5279 | return false; |
| 5280 | } |
| 5281 | |
| 5282 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, length)) |
| 5283 | { |
| 5284 | return false; |
| 5285 | } |
| 5286 | |
| 5287 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5288 | { |
| 5289 | return false; |
| 5290 | } |
| 5291 | |
| 5292 | return true; |
| 5293 | } |
| 5294 | |
| 5295 | bool ValidateGetSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, GLint *params) |
| 5296 | { |
| 5297 | return ValidateGetSamplerParameterBase(context, sampler, pname, nullptr); |
| 5298 | } |
| 5299 | |
| 5300 | bool ValidateGetSamplerParameterivRobustANGLE(Context *context, |
| 5301 | GLuint sampler, |
| 5302 | GLenum pname, |
| 5303 | GLuint bufSize, |
| 5304 | GLsizei *length, |
| 5305 | GLint *params) |
| 5306 | { |
| 5307 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5308 | { |
| 5309 | return false; |
| 5310 | } |
| 5311 | |
| 5312 | if (!ValidateGetSamplerParameterBase(context, sampler, pname, length)) |
| 5313 | { |
| 5314 | return false; |
| 5315 | } |
| 5316 | |
| 5317 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5318 | { |
| 5319 | return false; |
| 5320 | } |
| 5321 | |
| 5322 | return true; |
| 5323 | } |
| 5324 | |
| 5325 | bool ValidateSamplerParameterf(Context *context, GLuint sampler, GLenum pname, GLfloat param) |
| 5326 | { |
| 5327 | return ValidateSamplerParameterBase(context, sampler, pname, -1, ¶m); |
| 5328 | } |
| 5329 | |
| 5330 | bool ValidateSamplerParameterfv(Context *context, |
| 5331 | GLuint sampler, |
| 5332 | GLenum pname, |
| 5333 | const GLfloat *params) |
| 5334 | { |
| 5335 | return ValidateSamplerParameterBase(context, sampler, pname, -1, params); |
| 5336 | } |
| 5337 | |
| 5338 | bool ValidateSamplerParameterfvRobustANGLE(Context *context, |
| 5339 | GLuint sampler, |
| 5340 | GLenum pname, |
| 5341 | GLsizei bufSize, |
| 5342 | const GLfloat *params) |
| 5343 | { |
| 5344 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5345 | { |
| 5346 | return false; |
| 5347 | } |
| 5348 | |
| 5349 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 5350 | } |
| 5351 | |
| 5352 | bool ValidateSamplerParameteri(Context *context, GLuint sampler, GLenum pname, GLint param) |
| 5353 | { |
| 5354 | return ValidateSamplerParameterBase(context, sampler, pname, -1, ¶m); |
| 5355 | } |
| 5356 | |
| 5357 | bool ValidateSamplerParameteriv(Context *context, GLuint sampler, GLenum pname, const GLint *params) |
| 5358 | { |
| 5359 | return ValidateSamplerParameterBase(context, sampler, pname, -1, params); |
| 5360 | } |
| 5361 | |
| 5362 | bool ValidateSamplerParameterivRobustANGLE(Context *context, |
| 5363 | GLuint sampler, |
| 5364 | GLenum pname, |
| 5365 | GLsizei bufSize, |
| 5366 | const GLint *params) |
| 5367 | { |
| 5368 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5369 | { |
| 5370 | return false; |
| 5371 | } |
| 5372 | |
| 5373 | return ValidateSamplerParameterBase(context, sampler, pname, bufSize, params); |
| 5374 | } |
| 5375 | |
Geoff Lang | 0b03106 | 2016-10-13 14:30:04 -0400 | [diff] [blame] | 5376 | bool ValidateGetVertexAttribfv(Context *context, GLuint index, GLenum pname, GLfloat *params) |
| 5377 | { |
| 5378 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 5379 | } |
| 5380 | |
| 5381 | bool ValidateGetVertexAttribfvRobustANGLE(Context *context, |
| 5382 | GLuint index, |
| 5383 | GLenum pname, |
| 5384 | GLsizei bufSize, |
| 5385 | GLsizei *length, |
| 5386 | GLfloat *params) |
| 5387 | { |
| 5388 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5389 | { |
| 5390 | return false; |
| 5391 | } |
| 5392 | |
| 5393 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, false)) |
| 5394 | { |
| 5395 | return false; |
| 5396 | } |
| 5397 | |
| 5398 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5399 | { |
| 5400 | return false; |
| 5401 | } |
| 5402 | |
| 5403 | return true; |
| 5404 | } |
| 5405 | |
| 5406 | bool ValidateGetVertexAttribiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 5407 | { |
| 5408 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, false); |
| 5409 | } |
| 5410 | |
| 5411 | bool ValidateGetVertexAttribivRobustANGLE(Context *context, |
| 5412 | GLuint index, |
| 5413 | GLenum pname, |
| 5414 | GLsizei bufSize, |
| 5415 | GLsizei *length, |
| 5416 | GLint *params) |
| 5417 | { |
| 5418 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5419 | { |
| 5420 | return false; |
| 5421 | } |
| 5422 | |
| 5423 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, false)) |
| 5424 | { |
| 5425 | return false; |
| 5426 | } |
| 5427 | |
| 5428 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5429 | { |
| 5430 | return false; |
| 5431 | } |
| 5432 | |
| 5433 | return true; |
| 5434 | } |
| 5435 | |
| 5436 | bool ValidateGetVertexAttribPointerv(Context *context, GLuint index, GLenum pname, void **pointer) |
| 5437 | { |
| 5438 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, true, false); |
| 5439 | } |
| 5440 | |
| 5441 | bool ValidateGetVertexAttribPointervRobustANGLE(Context *context, |
| 5442 | GLuint index, |
| 5443 | GLenum pname, |
| 5444 | GLsizei bufSize, |
| 5445 | GLsizei *length, |
| 5446 | void **pointer) |
| 5447 | { |
| 5448 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5449 | { |
| 5450 | return false; |
| 5451 | } |
| 5452 | |
| 5453 | if (!ValidateGetVertexAttribBase(context, index, pname, length, true, false)) |
| 5454 | { |
| 5455 | return false; |
| 5456 | } |
| 5457 | |
| 5458 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5459 | { |
| 5460 | return false; |
| 5461 | } |
| 5462 | |
| 5463 | return true; |
| 5464 | } |
| 5465 | |
| 5466 | bool ValidateGetVertexAttribIiv(Context *context, GLuint index, GLenum pname, GLint *params) |
| 5467 | { |
| 5468 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true); |
| 5469 | } |
| 5470 | |
| 5471 | bool ValidateGetVertexAttribIivRobustANGLE(Context *context, |
| 5472 | GLuint index, |
| 5473 | GLenum pname, |
| 5474 | GLsizei bufSize, |
| 5475 | GLsizei *length, |
| 5476 | GLint *params) |
| 5477 | { |
| 5478 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5479 | { |
| 5480 | return false; |
| 5481 | } |
| 5482 | |
| 5483 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, true)) |
| 5484 | { |
| 5485 | return false; |
| 5486 | } |
| 5487 | |
| 5488 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5489 | { |
| 5490 | return false; |
| 5491 | } |
| 5492 | |
| 5493 | return true; |
| 5494 | } |
| 5495 | |
| 5496 | bool ValidateGetVertexAttribIuiv(Context *context, GLuint index, GLenum pname, GLuint *params) |
| 5497 | { |
| 5498 | return ValidateGetVertexAttribBase(context, index, pname, nullptr, false, true); |
| 5499 | } |
| 5500 | |
| 5501 | bool ValidateGetVertexAttribIuivRobustANGLE(Context *context, |
| 5502 | GLuint index, |
| 5503 | GLenum pname, |
| 5504 | GLsizei bufSize, |
| 5505 | GLsizei *length, |
| 5506 | GLuint *params) |
| 5507 | { |
| 5508 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5509 | { |
| 5510 | return false; |
| 5511 | } |
| 5512 | |
| 5513 | if (!ValidateGetVertexAttribBase(context, index, pname, length, false, true)) |
| 5514 | { |
| 5515 | return false; |
| 5516 | } |
| 5517 | |
| 5518 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5519 | { |
| 5520 | return false; |
| 5521 | } |
| 5522 | |
| 5523 | return true; |
| 5524 | } |
| 5525 | |
Geoff Lang | 6899b87 | 2016-10-14 11:30:13 -0400 | [diff] [blame] | 5526 | bool ValidateGetActiveUniformBlockiv(Context *context, |
| 5527 | GLuint program, |
| 5528 | GLuint uniformBlockIndex, |
| 5529 | GLenum pname, |
| 5530 | GLint *params) |
| 5531 | { |
| 5532 | return ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, nullptr); |
| 5533 | } |
| 5534 | |
| 5535 | bool ValidateGetActiveUniformBlockivRobustANGLE(Context *context, |
| 5536 | GLuint program, |
| 5537 | GLuint uniformBlockIndex, |
| 5538 | GLenum pname, |
| 5539 | GLsizei bufSize, |
| 5540 | GLsizei *length, |
| 5541 | GLint *params) |
| 5542 | { |
| 5543 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5544 | { |
| 5545 | return false; |
| 5546 | } |
| 5547 | |
| 5548 | if (!ValidateGetActiveUniformBlockivBase(context, program, uniformBlockIndex, pname, length)) |
| 5549 | { |
| 5550 | return false; |
| 5551 | } |
| 5552 | |
| 5553 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5554 | { |
| 5555 | return false; |
| 5556 | } |
| 5557 | |
| 5558 | return true; |
| 5559 | } |
| 5560 | |
Geoff Lang | 0a9661f | 2016-10-20 10:59:20 -0700 | [diff] [blame] | 5561 | bool ValidateGetInternalFormativ(Context *context, |
| 5562 | GLenum target, |
| 5563 | GLenum internalformat, |
| 5564 | GLenum pname, |
| 5565 | GLsizei bufSize, |
| 5566 | GLint *params) |
| 5567 | { |
| 5568 | return ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, |
| 5569 | nullptr); |
| 5570 | } |
| 5571 | |
| 5572 | bool ValidateGetInternalFormativRobustANGLE(Context *context, |
| 5573 | GLenum target, |
| 5574 | GLenum internalformat, |
| 5575 | GLenum pname, |
| 5576 | GLsizei bufSize, |
| 5577 | GLsizei *length, |
| 5578 | GLint *params) |
| 5579 | { |
| 5580 | if (!ValidateRobustEntryPoint(context, bufSize)) |
| 5581 | { |
| 5582 | return false; |
| 5583 | } |
| 5584 | |
| 5585 | if (!ValidateGetInternalFormativBase(context, target, internalformat, pname, bufSize, length)) |
| 5586 | { |
| 5587 | return false; |
| 5588 | } |
| 5589 | |
| 5590 | if (!ValidateRobustBufferSize(context, bufSize, *length)) |
| 5591 | { |
| 5592 | return false; |
| 5593 | } |
| 5594 | |
| 5595 | return true; |
| 5596 | } |
| 5597 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 5598 | } // namespace gl |