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