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