Hash :
53a94a82
Author :
Date :
2014-06-24T15:20:36
Refactors State to be a fully-qualified class BUG=angle:685 Change-Id: I36cff2da985a12c7180fe2850ccd471f4cebbaad Reviewed-on: https://chromium-review.googlesource.com/206634 Tested-by: Shannon Woods <shannonwoods@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682
#include "precompiled.h"
//
// Copyright (c) 2013-2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// validationES3.cpp: Validation functions for OpenGL ES 3.0 entry point parameters
#include "libGLESv2/validationES3.h"
#include "libGLESv2/validationES.h"
#include "libGLESv2/Context.h"
#include "libGLESv2/Texture.h"
#include "libGLESv2/Framebuffer.h"
#include "libGLESv2/Renderbuffer.h"
#include "libGLESv2/formatutils.h"
#include "libGLESv2/main.h"
#include "libGLESv2/FramebufferAttachment.h"
#include "common/mathutil.h"
namespace gl
{
bool ValidateES3TexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat, bool isCompressed, bool isSubImage,
GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
GLint border, GLenum format, GLenum type, const GLvoid *pixels)
{
if (!ValidTexture2DDestinationTarget(context, target))
{
return gl::error(GL_INVALID_ENUM, false);
}
// Validate image size
if (!ValidImageSize(context, target, level, width, height, depth))
{
return gl::error(GL_INVALID_VALUE, false);
}
// Verify zero border
if (border != 0)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (xoffset < 0 || yoffset < 0 || zoffset < 0 ||
std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height ||
std::numeric_limits<GLsizei>::max() - zoffset < depth)
{
return gl::error(GL_INVALID_VALUE, false);
}
const gl::Caps &caps = context->getCaps();
gl::Texture *texture = NULL;
bool textureCompressed = false;
GLenum textureInternalFormat = GL_NONE;
GLint textureLevelWidth = 0;
GLint textureLevelHeight = 0;
GLint textureLevelDepth = 0;
switch (target)
{
case GL_TEXTURE_2D:
{
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level))
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::Texture2D *texture2d = context->getTexture2D();
if (texture2d)
{
textureCompressed = texture2d->isCompressed(level);
textureInternalFormat = texture2d->getInternalFormat(level);
textureLevelWidth = texture2d->getWidth(level);
textureLevelHeight = texture2d->getHeight(level);
textureLevelDepth = 1;
texture = texture2d;
}
}
break;
case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
{
if (!isSubImage && width != height)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (static_cast<GLuint>(width) > (caps.maxCubeMapTextureSize >> level))
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::TextureCubeMap *textureCube = context->getTextureCubeMap();
if (textureCube)
{
textureCompressed = textureCube->isCompressed(target, level);
textureInternalFormat = textureCube->getInternalFormat(target, level);
textureLevelWidth = textureCube->getWidth(target, level);
textureLevelHeight = textureCube->getHeight(target, level);
textureLevelDepth = 1;
texture = textureCube;
}
}
break;
case GL_TEXTURE_3D:
{
if (static_cast<GLuint>(width) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max3DTextureSize >> level) ||
static_cast<GLuint>(depth) > (caps.max3DTextureSize >> level))
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::Texture3D *texture3d = context->getTexture3D();
if (texture3d)
{
textureCompressed = texture3d->isCompressed(level);
textureInternalFormat = texture3d->getInternalFormat(level);
textureLevelWidth = texture3d->getWidth(level);
textureLevelHeight = texture3d->getHeight(level);
textureLevelDepth = texture3d->getDepth(level);
texture = texture3d;
}
}
break;
case GL_TEXTURE_2D_ARRAY:
{
if (static_cast<GLuint>(width) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(height) > (caps.max2DTextureSize >> level) ||
static_cast<GLuint>(depth) > (caps.maxArrayTextureLayers >> level))
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::Texture2DArray *texture2darray = context->getTexture2DArray();
if (texture2darray)
{
textureCompressed = texture2darray->isCompressed(level);
textureInternalFormat = texture2darray->getInternalFormat(level);
textureLevelWidth = texture2darray->getWidth(level);
textureLevelHeight = texture2darray->getHeight(level);
textureLevelDepth = texture2darray->getLayers(level);
texture = texture2darray;
}
}
break;
default:
return gl::error(GL_INVALID_ENUM, false);
}
if (!texture)
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (texture->isImmutable() && !isSubImage)
{
return gl::error(GL_INVALID_OPERATION, false);
}
// Validate texture formats
GLenum actualInternalFormat = isSubImage ? textureInternalFormat : internalformat;
if (isCompressed)
{
if (!ValidCompressedImageSize(context, actualInternalFormat, width, height))
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (!gl::IsFormatCompressed(actualInternalFormat))
{
return gl::error(GL_INVALID_ENUM, false);
}
if (target == GL_TEXTURE_3D)
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
else
{
// Note: dEQP 2013.4 expects an INVALID_VALUE error for TexImage3D with an invalid
// internal format. (dEQP-GLES3.functional.negative_api.texture.teximage3d)
if (!gl::IsValidInternalFormat(actualInternalFormat, context->getExtensions(), context->getClientVersion()) ||
!gl::IsValidFormat(format, context->getExtensions(), context->getClientVersion()) ||
!gl::IsValidType(type, context->getExtensions(), context->getClientVersion()))
{
return gl::error(GL_INVALID_ENUM, false);
}
if (!gl::IsValidFormatCombination(actualInternalFormat, format, type, context->getExtensions(), context->getClientVersion()))
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (target == GL_TEXTURE_3D && (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
// Validate sub image parameters
if (isSubImage)
{
if (isCompressed != textureCompressed)
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (isCompressed)
{
if ((width % 4 != 0 && width != textureLevelWidth) ||
(height % 4 != 0 && height != textureLevelHeight))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
if (width == 0 || height == 0 || depth == 0)
{
return false;
}
if (xoffset < 0 || yoffset < 0 || zoffset < 0)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (std::numeric_limits<GLsizei>::max() - xoffset < width ||
std::numeric_limits<GLsizei>::max() - yoffset < height ||
std::numeric_limits<GLsizei>::max() - zoffset < depth)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (xoffset + width > textureLevelWidth ||
yoffset + height > textureLevelHeight ||
zoffset + depth > textureLevelDepth)
{
return gl::error(GL_INVALID_VALUE, false);
}
}
// Check for pixel unpack buffer related API errors
gl::Buffer *pixelUnpackBuffer = context->getState().getTargetBuffer(GL_PIXEL_UNPACK_BUFFER);
if (pixelUnpackBuffer != NULL)
{
// ...the data would be unpacked from the buffer object such that the memory reads required
// would exceed the data store size.
size_t widthSize = static_cast<size_t>(width);
size_t heightSize = static_cast<size_t>(height);
size_t depthSize = static_cast<size_t>(depth);
GLenum sizedFormat = gl::IsSizedInternalFormat(actualInternalFormat) ? actualInternalFormat
: gl::GetSizedInternalFormat(actualInternalFormat, type);
size_t pixelBytes = static_cast<size_t>(gl::GetPixelBytes(sizedFormat));
if (!rx::IsUnsignedMultiplicationSafe(widthSize, heightSize) ||
!rx::IsUnsignedMultiplicationSafe(widthSize * heightSize, depthSize) ||
!rx::IsUnsignedMultiplicationSafe(widthSize * heightSize * depthSize, pixelBytes))
{
// Overflow past the end of the buffer
return gl::error(GL_INVALID_OPERATION, false);
}
size_t copyBytes = widthSize * heightSize * depthSize * pixelBytes;
size_t offset = reinterpret_cast<size_t>(pixels);
if (!rx::IsUnsignedAdditionSafe(offset, copyBytes) ||
((offset + copyBytes) > static_cast<size_t>(pixelUnpackBuffer->getSize())))
{
// Overflow past the end of the buffer
return gl::error(GL_INVALID_OPERATION, false);
}
// ...data is not evenly divisible into the number of bytes needed to store in memory a datum
// indicated by type.
size_t dataBytesPerPixel = static_cast<size_t>(gl::GetTypeBytes(type));
if ((offset % dataBytesPerPixel) != 0)
{
return gl::error(GL_INVALID_OPERATION, false);
}
// ...the buffer object's data store is currently mapped.
if (pixelUnpackBuffer->isMapped())
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
return true;
}
bool ValidateES3CopyTexImageParameters(gl::Context *context, GLenum target, GLint level, GLenum internalformat,
bool isSubImage, GLint xoffset, GLint yoffset, GLint zoffset,
GLint x, GLint y, GLsizei width, GLsizei height, GLint border)
{
GLenum textureInternalFormat;
if (!ValidateCopyTexImageParametersBase(context, target, level, internalformat, isSubImage,
xoffset, yoffset, zoffset, x, y, width, height,
border, &textureInternalFormat))
{
return false;
}
gl::Framebuffer *framebuffer = context->getState().getReadFramebuffer();
if (framebuffer->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
}
if (context->getState().getReadFramebuffer()->id() != 0 && framebuffer->getSamples() != 0)
{
return gl::error(GL_INVALID_OPERATION, false);
}
gl::FramebufferAttachment *source = framebuffer->getReadColorbuffer();
GLenum colorbufferInternalFormat = source->getInternalFormat();
if (isSubImage)
{
if (!gl::IsValidCopyTexImageCombination(textureInternalFormat, colorbufferInternalFormat,
context->getState().getReadFramebuffer()->id(),
context->getClientVersion()))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
else
{
if (!gl::IsValidCopyTexImageCombination(internalformat, colorbufferInternalFormat,
context->getState().getReadFramebuffer()->id(),
context->getClientVersion()))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
// If width or height is zero, it is a no-op. Return false without setting an error.
return (width > 0 && height > 0);
}
bool ValidateES3TexStorageParameters(gl::Context *context, GLenum target, GLsizei levels, GLenum internalformat,
GLsizei width, GLsizei height, GLsizei depth)
{
if (width < 1 || height < 1 || depth < 1 || levels < 1)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (levels > gl::log2(std::max(std::max(width, height), depth)) + 1)
{
return gl::error(GL_INVALID_OPERATION, false);
}
const gl::Caps &caps = context->getCaps();
gl::Texture *texture = NULL;
switch (target)
{
case GL_TEXTURE_2D:
{
texture = context->getTexture2D();
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize)
{
return gl::error(GL_INVALID_VALUE, false);
}
}
break;
case GL_TEXTURE_CUBE_MAP:
{
texture = context->getTextureCubeMap();
if (width != height)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (static_cast<GLuint>(width) > caps.maxCubeMapTextureSize)
{
return gl::error(GL_INVALID_VALUE, false);
}
}
break;
case GL_TEXTURE_3D:
{
texture = context->getTexture3D();
if (static_cast<GLuint>(width) > caps.max3DTextureSize ||
static_cast<GLuint>(height) > caps.max3DTextureSize ||
static_cast<GLuint>(depth) > caps.max3DTextureSize)
{
return gl::error(GL_INVALID_VALUE, false);
}
}
break;
case GL_TEXTURE_2D_ARRAY:
{
texture = context->getTexture2DArray();
if (static_cast<GLuint>(width) > caps.max2DTextureSize ||
static_cast<GLuint>(height) > caps.max2DTextureSize ||
static_cast<GLuint>(depth) > caps.maxArrayTextureLayers)
{
return gl::error(GL_INVALID_VALUE, false);
}
}
break;
default:
return gl::error(GL_INVALID_ENUM, false);
}
if (!texture || texture->id() == 0)
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (texture->isImmutable())
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (!gl::IsValidInternalFormat(internalformat, context->getExtensions(), context->getClientVersion()))
{
return gl::error(GL_INVALID_ENUM, false);
}
if (!gl::IsSizedInternalFormat(internalformat))
{
return gl::error(GL_INVALID_ENUM, false);
}
return true;
}
bool ValidateFramebufferTextureLayer(const gl::Context *context, GLenum target, GLenum attachment,
GLuint texture, GLint level, GLint layer)
{
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_OPERATION, false);
}
if (layer < 0)
{
return gl::error(GL_INVALID_VALUE, false);
}
if (!ValidateFramebufferTextureBase(context, target, attachment, texture, level))
{
return false;
}
const gl::Caps &caps = context->getCaps();
if (texture != 0)
{
gl::Texture *tex = context->getTexture(texture);
ASSERT(tex);
switch (tex->getTarget())
{
case GL_TEXTURE_2D_ARRAY:
{
if (level > gl::log2(caps.max2DTextureSize))
{
return gl::error(GL_INVALID_VALUE, false);
}
if (static_cast<GLuint>(layer) >= caps.maxArrayTextureLayers)
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::Texture2DArray *texArray = static_cast<gl::Texture2DArray *>(tex);
if (texArray->isCompressed(level))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
break;
case GL_TEXTURE_3D:
{
if (level > gl::log2(caps.max3DTextureSize))
{
return gl::error(GL_INVALID_VALUE, false);
}
if (static_cast<GLuint>(layer) >= caps.max3DTextureSize)
{
return gl::error(GL_INVALID_VALUE, false);
}
gl::Texture3D *tex3d = static_cast<gl::Texture3D *>(tex);
if (tex3d->isCompressed(level))
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
break;
default:
return gl::error(GL_INVALID_OPERATION, false);
}
}
return true;
}
bool ValidES3ReadFormatType(gl::Context *context, GLenum internalFormat, GLenum format, GLenum type)
{
switch (format)
{
case GL_RGBA:
switch (type)
{
case GL_UNSIGNED_BYTE:
break;
case GL_UNSIGNED_INT_2_10_10_10_REV:
if (internalFormat != GL_RGB10_A2)
{
return false;
}
break;
case GL_FLOAT:
if (gl::GetComponentType(internalFormat) != GL_FLOAT)
{
return false;
}
break;
default:
return false;
}
break;
case GL_RGBA_INTEGER:
switch (type)
{
case GL_INT:
if (gl::GetComponentType(internalFormat) != GL_INT)
{
return false;
}
break;
case GL_UNSIGNED_INT:
if (gl::GetComponentType(internalFormat) != GL_UNSIGNED_INT)
{
return false;
}
break;
default:
return false;
}
break;
case GL_BGRA_EXT:
switch (type)
{
case GL_UNSIGNED_BYTE:
case GL_UNSIGNED_SHORT_4_4_4_4_REV_EXT:
case GL_UNSIGNED_SHORT_1_5_5_5_REV_EXT:
break;
default:
return false;
}
break;
case GL_RG_EXT:
case GL_RED_EXT:
if (!context->getExtensions().textureRG)
{
return false;
}
switch (type)
{
case GL_UNSIGNED_BYTE:
break;
default:
return false;
}
break;
default:
return false;
}
return true;
}
bool ValidateInvalidateFramebufferParameters(gl::Context *context, GLenum target, GLsizei numAttachments,
const GLenum* attachments)
{
bool defaultFramebuffer = false;
switch (target)
{
case GL_DRAW_FRAMEBUFFER:
case GL_FRAMEBUFFER:
defaultFramebuffer = context->getState().getDrawFramebuffer()->id() == 0;
break;
case GL_READ_FRAMEBUFFER:
defaultFramebuffer = context->getState().getReadFramebuffer()->id() == 0;
break;
default:
return gl::error(GL_INVALID_ENUM, false);
}
for (int i = 0; i < numAttachments; ++i)
{
if (attachments[i] >= GL_COLOR_ATTACHMENT0 && attachments[i] <= GL_COLOR_ATTACHMENT15)
{
if (defaultFramebuffer)
{
return gl::error(GL_INVALID_ENUM, false);
}
if (attachments[i] >= GL_COLOR_ATTACHMENT0 + context->getCaps().maxColorAttachments)
{
return gl::error(GL_INVALID_OPERATION, false);
}
}
else
{
switch (attachments[i])
{
case GL_DEPTH_ATTACHMENT:
case GL_STENCIL_ATTACHMENT:
case GL_DEPTH_STENCIL_ATTACHMENT:
if (defaultFramebuffer)
{
return gl::error(GL_INVALID_ENUM, false);
}
break;
case GL_COLOR:
case GL_DEPTH:
case GL_STENCIL:
if (!defaultFramebuffer)
{
return gl::error(GL_INVALID_ENUM, false);
}
break;
default:
return gl::error(GL_INVALID_ENUM, false);
}
}
}
return true;
}
bool ValidateClearBuffer(const gl::Context *context)
{
if (context->getClientVersion() < 3)
{
return gl::error(GL_INVALID_OPERATION, false);
}
const gl::Framebuffer *fbo = context->getState().getDrawFramebuffer();
if (!fbo || fbo->completeness() != GL_FRAMEBUFFER_COMPLETE)
{
return gl::error(GL_INVALID_FRAMEBUFFER_OPERATION, false);
}
return true;
}
}