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