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