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