Hash :
10a98f44
Author :
Date :
2024-06-18T00:00:00
Add ClipControlTest.DepthFragCoord test Bug: angleproject:347737886 Change-Id: Id10b0f99b0a87a746f99ddf77c095861b1c72f74 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/5638710 Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Alexey Knyazev <lexa.knyazev@gmail.com>
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 683 684 685 686 687 688 689
//
// Copyright 2023 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.
//
// Test cases for GL_EXT_clip_control
// These tests complement dEQP-GLES2.functional.clip_control.*
//
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/EGLWindow.h"
#include "util/test_utils.h"
using namespace angle;
class ClipControlTest : public ANGLETest<>
{
protected:
static const int w = 64;
static const int h = 64;
ClipControlTest()
{
setWindowWidth(w);
setWindowHeight(h);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
setExtensionsEnabled(false);
}
};
// Test state queries and updates
TEST_P(ClipControlTest, StateQuery)
{
// Queries with the extension disabled
GLint clipOrigin = -1;
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
EXPECT_EQ(clipOrigin, -1);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
GLint clipDepthMode = -1;
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_EQ(clipDepthMode, -1);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Command with the extension disabled
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
EXPECT_GL_ERROR(GL_INVALID_OPERATION);
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
ASSERT_GL_NO_ERROR();
// Default state with the extension enabled
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
// Check valid state updates
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_LOWER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_NEGATIVE_ONE_TO_ONE_EXT, clipDepthMode);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
// Check invalid state updates
glClipControlEXT(GL_LOWER_LEFT_EXT, 0);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
glClipControlEXT(0, GL_NEGATIVE_ONE_TO_ONE_EXT);
EXPECT_GL_ERROR(GL_INVALID_ENUM);
// Invalid command does not change the state
glGetIntegerv(GL_CLIP_ORIGIN_EXT, &clipOrigin);
glGetIntegerv(GL_CLIP_DEPTH_MODE_EXT, &clipDepthMode);
EXPECT_GLENUM_EQ(GL_UPPER_LEFT_EXT, clipOrigin);
EXPECT_GLENUM_EQ(GL_ZERO_TO_ONE_EXT, clipDepthMode);
ASSERT_GL_NO_ERROR();
}
// Test that clip origin does not affect scissored clears
TEST_P(ClipControlTest, OriginScissorClear)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::Blue());
auto test = [&](std::string name, bool useES3) {
// Start with lower-left
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Make a draw call without color writes to sync the state
glColorMask(false, false, false, false);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
glColorMask(true, true, true, true);
// Clear to red
glDisable(GL_SCISSOR_TEST);
if (useES3)
{
float color[4] = {1.0, 0.0, 0.0, 1.0};
glClearBufferfv(GL_COLOR, 0, color);
}
else
{
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
// Flip the clip origin
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Make a draw call without color writes to sync the state
glColorMask(false, false, false, false);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
glColorMask(true, true, true, true);
// Clear lower half to green
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w, h / 2);
if (useES3)
{
float color[4] = {0.0, 1.0, 0.0, 1.0};
glClearBufferfv(GL_COLOR, 0, color);
}
else
{
glClearColor(0.0, 1.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
}
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(0.5 * w, 0.25 * h, GLColor::green) << name;
EXPECT_PIXEL_COLOR_EQ(0.5 * w, 0.75 * h, GLColor::red) << name;
};
test("Default framebuffer", getClientMajorVersion() > 2);
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_OES_rgb8_rgba8"));
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
test("User framebuffer", getClientMajorVersion() > 2);
}
// Test that changing clip origin state does not affect location of scissor area
TEST_P(ClipControlTest, OriginScissorDraw)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
constexpr char kVS[] = R"(
attribute vec2 a_position;
void main()
{
// Square at (0.25, 0.25) -> (0.75, 0.75)
gl_Position = vec4(a_position * 0.25 + 0.5, 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, kVS, essl1_shaders::fs::Blue());
glUseProgram(program);
ASSERT_GL_NO_ERROR();
auto test = [&](std::string name) {
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glDisable(GL_SCISSOR_TEST);
glClear(GL_COLOR_BUFFER_BIT);
// Draw only to the lower half
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w, h / 2);
// Draw blue quad in the upper-right part of the framebuffer; scissor test must fail
drawQuad(program, "a_position", 0);
ASSERT_GL_NO_ERROR();
// Switch the clip origin and draw again; scissor test must pass
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
drawQuad(program, "a_position", 0);
ASSERT_GL_NO_ERROR();
// Reads are unaffected by clip origin
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.25 * h, GLColor::blue) << name;
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.75 * h, GLColor::transparentBlack) << name;
};
test("Default framebuffer");
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
test("User framebuffer");
}
// Test that changing clip origin state does not affect copyTexImage
TEST_P(ClipControlTest, OriginCopyTexImage)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
auto test = [&](std::string name) {
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Clear to red
glDisable(GL_SCISSOR_TEST);
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// Clear lower half-space to green
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w, h / 2);
glClearColor(0.0, 1.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
// Switch clip origin state, it must have no effect on the next commands
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w / 4, h / 4, 0);
ASSERT_GL_NO_ERROR();
GLFramebuffer readFb;
glBindFramebuffer(GL_FRAMEBUFFER, readFb);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
// Copied texture must contain values from the lower half-space
EXPECT_PIXEL_COLOR_EQ(w / 8, h / 8, GLColor::green) << name;
};
test("Default framebuffer");
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
test("User framebuffer");
}
// Test that changing clip origin state does not affect copyTexImage
// with Luma format that may use draw calls internally
TEST_P(ClipControlTest, OriginCopyTexImageLuma)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
// Clear to zero
glClear(GL_COLOR_BUFFER_BIT);
// Clear lower half-space to one
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, w, h / 2);
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
// Switch clip origin state, it must have no effect on the next commands
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
GLTexture tex;
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 0, 0, w, h, 0);
ASSERT_GL_NO_ERROR();
glClearColor(1.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::magenta);
// Draw the luma texture
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
ANGLE_GL_PROGRAM(drawTexture, essl1_shaders::vs::Texture2D(), essl1_shaders::fs::Texture2D());
drawQuad(drawTexture, essl1_shaders::PositionAttrib(), 0.0f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(w / 2, h * 1 / 4, GLColor::white);
EXPECT_PIXEL_COLOR_EQ(w / 2, h * 3 / 4, GLColor::black);
}
// Test that clip origin does not affect gl_FragCoord
TEST_P(ClipControlTest, OriginFragCoord)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
const char kFS[] = R"(precision mediump float;
void main()
{
gl_FragColor = vec4(sign(gl_FragCoord.xy / 64.0 - 0.5), 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS);
glClearColor(1.0, 0.0, 1.0, 1.0);
for (GLenum origin : {GL_LOWER_LEFT_EXT, GL_UPPER_LEFT_EXT})
{
glClipControlEXT(origin, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(w - 1, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(0, h - 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(w - 1, h - 1, GLColor::yellow);
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glClear(GL_COLOR_BUFFER_BIT);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(w - 1, 0, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(0, h - 1, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(w - 1, h - 1, GLColor::yellow);
}
}
// Test that clip origin does not affect gl_PointCoord
TEST_P(ClipControlTest, OriginPointCoord)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
float pointSizeRange[2] = {};
glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange);
ANGLE_SKIP_TEST_IF(pointSizeRange[1] < 32);
const char kVS[] = R"(precision mediump float;
void main()
{
gl_Position = vec4(0.0, 0.0, 0.0, 1.0);
gl_PointSize = 32.0;
})";
const char kFS[] = R"(precision mediump float;
void main()
{
gl_FragColor = vec4(sign(gl_PointCoord.xy - 0.5), 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, kVS, kFS);
glUseProgram(program);
ASSERT_GL_NO_ERROR();
glClearColor(1.0, 0.0, 1.0, 1.0);
for (GLenum origin : {GL_LOWER_LEFT_EXT, GL_UPPER_LEFT_EXT})
{
glClipControlEXT(origin, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(w / 2 - 15, h / 2 + 15, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(w / 2 + 15, h / 2 + 15, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(w / 2 - 15, h / 2 - 15, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(w / 2 + 15, h / 2 - 15, GLColor::yellow);
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glClear(GL_COLOR_BUFFER_BIT);
glDrawArrays(GL_POINTS, 0, 1);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_COLOR_EQ(w / 2 - 15, h / 2 + 15, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(w / 2 + 15, h / 2 + 15, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(w / 2 - 15, h / 2 - 15, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(w / 2 + 15, h / 2 - 15, GLColor::yellow);
}
}
// Test that clip origin does not affect gl_FrontFacing
TEST_P(ClipControlTest, OriginFrontFacing)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
const char kFS[] = R"(precision mediump float;
void main()
{
gl_FragColor = vec4(gl_FrontFacing ? vec2(1.0, 0.0) : vec2(0.0, 1.0), 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS);
for (GLenum origin : {GL_LOWER_LEFT_EXT, GL_UPPER_LEFT_EXT})
{
glClipControlEXT(origin, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glFrontFace(GL_CCW);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
glFrontFace(GL_CW);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
GLFramebuffer fb;
glBindFramebuffer(GL_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, w, h);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_FRAMEBUFFER);
glFrontFace(GL_CCW);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
glFrontFace(GL_CW);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
}
// Test that clip origin does not affect readPixels
TEST_P(ClipControlTest, OriginReadPixels)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
const char kFS[] = R"(precision mediump float;
uniform float blue;
varying vec4 v_position;
void main()
{
gl_FragColor = (v_position.y > 0.0) ? vec4(1.0, 0.0, blue, 1.0) : vec4(0.0, 1.0, blue, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Passthrough(), kFS);
const GLint blueUniformLocation = glGetUniformLocation(program, "blue");
glUseProgram(program);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glUniform1f(blueUniformLocation, 0.0f);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_RECT_EQ(0, h / 2 + 2, w, h / 2 - 2, GLColor::red);
EXPECT_PIXEL_RECT_EQ(0, 0, w, h / 2 - 2, GLColor::green);
// Update clip origin and make a draw call that fails the depth test to
// ensure that the backend is synced while the framebuffer is unchanged.
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glUniform1f(blueUniformLocation, 1.0f);
drawQuad(program, essl1_shaders::PositionAttrib(), 1.0);
// Check that the second draw call has failed the depth test and
// reading from the framebuffer returns the same values as before.
EXPECT_PIXEL_RECT_EQ(0, h / 2 + 2, w, h / 2 - 2, GLColor::red);
EXPECT_PIXEL_RECT_EQ(0, 0, w, h / 2 - 2, GLColor::green);
}
// Test that changing only the clip depth mode syncs the state correctly
TEST_P(ClipControlTest, DepthModeSimple)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), essl1_shaders::fs::UniformColor());
const GLint colorUniformLocation = glGetUniformLocation(program, essl1_shaders::ColorUniform());
glUseProgram(program);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glUniform4fv(colorUniformLocation, 1, GLColor::red.toNormalizedVector().data());
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
glUniform4fv(colorUniformLocation, 1, GLColor::green.toNormalizedVector().data());
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
}
// Test that gl_FragCoord.z has expected values for ZERO_TO_ONE clip depth mode
TEST_P(ClipControlTest, DepthFragCoord)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
const char kFS[] = R"(precision mediump float;
void main()
{
gl_FragColor = vec4(gl_FragCoord.z, 0, 0, 1);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Simple(), kFS);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_ZERO_TO_ONE_EXT);
ASSERT_GL_NO_ERROR();
drawQuad(program, essl1_shaders::PositionAttrib(), 1.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.5);
EXPECT_PIXEL_COLOR_NEAR(0, 0, GLColor(127, 0, 0, 255), 1);
drawQuad(program, essl1_shaders::PositionAttrib(), 0.0);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::black);
}
class ClipControlTestES3 : public ClipControlTest
{};
// Test that clip origin state does not affect framebuffer blits
TEST_P(ClipControlTestES3, OriginBlit)
{
ANGLE_SKIP_TEST_IF(!EnsureGLExtensionEnabled("GL_EXT_clip_control"));
constexpr char kFS[] = R"(
precision mediump float;
varying vec4 v_position;
void main()
{
gl_FragColor = vec4(sign(v_position.xy), 0.0, 1.0);
})";
ANGLE_GL_PROGRAM(program, essl1_shaders::vs::Passthrough(), kFS);
glUseProgram(program);
ASSERT_GL_NO_ERROR();
// Blit default to custom
{
GLFramebuffer fb;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
drawQuad(program, "a_position", 0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.25 * h, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.25 * h, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.75 * h, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.75 * h, GLColor::yellow);
}
// Blit custom to default
{
GLFramebuffer fb;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
GLRenderbuffer rb;
glBindRenderbuffer(GL_RENDERBUFFER, rb);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
drawQuad(program, "a_position", 0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.25 * h, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.25 * h, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.75 * h, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.75 * h, GLColor::yellow);
}
// Blit custom to custom
{
GLFramebuffer fb1;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb1);
GLRenderbuffer rb1;
glBindRenderbuffer(GL_RENDERBUFFER, rb1);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb1);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
GLFramebuffer fb2;
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb2);
GLRenderbuffer rb2;
glBindRenderbuffer(GL_RENDERBUFFER, rb2);
glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8, w, h);
glFramebufferRenderbuffer(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rb2);
ASSERT_GL_FRAMEBUFFER_COMPLETE(GL_DRAW_FRAMEBUFFER);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb1);
glClipControlEXT(GL_LOWER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
drawQuad(program, "a_position", 0);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb1);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb2);
glClipControlEXT(GL_UPPER_LEFT_EXT, GL_NEGATIVE_ONE_TO_ONE_EXT);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_READ_FRAMEBUFFER, fb2);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.25 * h, GLColor::black);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.25 * h, GLColor::red);
EXPECT_PIXEL_COLOR_EQ(0.25 * w, 0.75 * h, GLColor::green);
EXPECT_PIXEL_COLOR_EQ(0.75 * w, 0.75 * h, GLColor::yellow);
}
}
ANGLE_INSTANTIATE_TEST_ES2_AND_ES3_AND(ClipControlTest,
ES2_OPENGLES().enable(Feature::EmulateClipOrigin),
ES3_OPENGLES().enable(Feature::EmulateClipOrigin));
ANGLE_INSTANTIATE_TEST_ES3_AND(ClipControlTestES3,
ES3_OPENGLES().enable(Feature::EmulateClipOrigin));