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