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