Hash :
25390156
Author :
Date :
2025-08-21T00:13:19
Suppress unsafe buffers on a file-by-file basis in src/ [1 of N] In this CL, we suppress many files but stop short of actually enabling the warning by not removing the line from the unsafe_buffers_paths.txt file. That will happen in a follow-on CL, along with resolving any stragglers missed here. This is mostly a manual change so as to familiarize myself with the kinds of issues faced by the Angle codebase when applying buffer safety warnings. -- Re-generate affected hashes. -- Clang-format applied to all changed files. -- Add a few missing .reserve() calls to vectors as noticed. -- Fix some mismatches between file names and header comments. -- Be more consistent with header comment format (blank lines and trailing //-only lines when a filename comment adjoins license boilerplate). Bug: b/436880895 Change-Id: I3bde5cc2059acbe8345057289214f1a26f1c34aa Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6869022 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@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 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
//
// Copyright 2015 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.
//
// ProvkingVertexTest:
// Tests on the conformance of the provoking vertex, which applies to flat
// shading and compatibility with D3D. See the section on 'flatshading'
// in the ES 3 specs.
//
#ifdef UNSAFE_BUFFERS_BUILD
# pragma allow_unsafe_buffers
#endif
#include "GLES2/gl2.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/gl_raii.h"
#include "util/gles_loader_autogen.h"
using namespace angle;
namespace
{
template <typename T>
size_t sizeOfVectorContents(const T &vector)
{
return vector.size() * sizeof(typename T::value_type);
}
void checkFlatQuadColors(size_t width,
size_t height,
const GLColor &bottomLeftColor,
const GLColor &topRightColor)
{
for (size_t x = 0; x < width; x += 2)
{
EXPECT_PIXEL_COLOR_EQ(x, 0, bottomLeftColor);
EXPECT_PIXEL_COLOR_EQ(x + 1, height - 1, topRightColor);
}
}
class ProvokingVertexTest : public ANGLETest<>
{
protected:
ProvokingVertexTest()
: mProgram(0),
mFramebuffer(0),
mTexture(0),
mTransformFeedback(0),
mBuffer(0),
mIntAttribLocation(-1)
{
setWindowWidth(64);
setWindowHeight(64);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
void testSetUp() override
{
constexpr char kVS[] =
"#version 300 es\n"
"in int intAttrib;\n"
"in vec2 position;\n"
"flat out int attrib;\n"
"void main() {\n"
" gl_Position = vec4(position, 0, 1);\n"
" attrib = intAttrib;\n"
"}";
constexpr char kFS[] =
"#version 300 es\n"
"flat in int attrib;\n"
"out int fragColor;\n"
"void main() {\n"
" fragColor = attrib;\n"
"}";
std::vector<std::string> tfVaryings;
tfVaryings.push_back("attrib");
mProgram = CompileProgramWithTransformFeedback(kVS, kFS, tfVaryings, GL_SEPARATE_ATTRIBS);
ASSERT_NE(0u, mProgram);
glGenTextures(1, &mTexture);
glBindTexture(GL_TEXTURE_2D, mTexture);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_R32I, getWindowWidth(), getWindowHeight());
glGenFramebuffers(1, &mFramebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, mTexture, 0);
mIntAttribLocation = glGetAttribLocation(mProgram, "intAttrib");
ASSERT_NE(-1, mIntAttribLocation);
glEnableVertexAttribArray(mIntAttribLocation);
ASSERT_GL_NO_ERROR();
}
void testTearDown() override
{
if (mProgram != 0)
{
glDeleteProgram(mProgram);
mProgram = 0;
}
if (mFramebuffer != 0)
{
glDeleteFramebuffers(1, &mFramebuffer);
mFramebuffer = 0;
}
if (mTexture != 0)
{
glDeleteTextures(1, &mTexture);
mTexture = 0;
}
if (mTransformFeedback != 0)
{
glDeleteTransformFeedbacks(1, &mTransformFeedback);
mTransformFeedback = 0;
}
if (mBuffer != 0)
{
glDeleteBuffers(1, &mBuffer);
mBuffer = 0;
}
}
GLuint mProgram;
GLuint mFramebuffer;
GLuint mTexture;
GLuint mTransformFeedback;
GLuint mBuffer;
GLint mIntAttribLocation;
};
// Test drawing a simple triangle with flat shading, and different valued vertices.
TEST_P(ProvokingVertexTest, FlatTriangle)
{
GLint vertexData[] = {1, 2, 3, 1, 2, 3};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
drawQuad(mProgram, "position", 0.5f);
GLint pixelValue[4] = {0};
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_INT, &pixelValue);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(vertexData[2], pixelValue[0]);
}
// Ensure that any provoking vertex shenanigans still gives correct vertex streams.
TEST_P(ProvokingVertexTest, FlatTriWithTransformFeedback)
{
glGenTransformFeedbacks(1, &mTransformFeedback);
glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, mTransformFeedback);
glGenBuffers(1, &mBuffer);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, mBuffer);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, 128, nullptr, GL_STREAM_DRAW);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, mBuffer);
GLint vertexData[] = {1, 2, 3, 1, 2, 3};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
glUseProgram(mProgram);
glBeginTransformFeedback(GL_TRIANGLES);
drawQuad(mProgram, "position", 0.5f);
glEndTransformFeedback();
glUseProgram(0);
GLint pixelValue[4] = {0};
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_INT, &pixelValue);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(vertexData[2], pixelValue[0]);
void *mapPointer =
glMapBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(int) * 6, GL_MAP_READ_BIT);
ASSERT_NE(nullptr, mapPointer);
int *mappedInts = static_cast<int *>(mapPointer);
for (unsigned int cnt = 0; cnt < 6; ++cnt)
{
EXPECT_EQ(vertexData[cnt], mappedInts[cnt]);
}
}
// Test drawing a simple line with flat shading, and different valued vertices.
TEST_P(ProvokingVertexTest, FlatLine)
{
GLfloat halfPixel = 1.0f / static_cast<GLfloat>(getWindowWidth());
GLint vertexData[] = {1, 2};
GLfloat positionData[] = {-1.0f + halfPixel, -1.0f, -1.0f + halfPixel, 1.0f};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, positionData);
glUseProgram(mProgram);
glDrawArrays(GL_LINES, 0, 2);
GLint pixelValue[4] = {0};
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_INT, &pixelValue);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(vertexData[1], pixelValue[0]);
}
// Test drawing a simple line with flat shading, and different valued vertices.
TEST_P(ProvokingVertexTest, FlatLineWithFirstIndex)
{
GLfloat halfPixel = 1.0f / static_cast<GLfloat>(getWindowWidth());
GLint vertexData[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2};
GLfloat positionData[] = {0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
-1.0f + halfPixel,
-1.0f,
-1.0f + halfPixel,
1.0f};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, positionData);
glUseProgram(mProgram);
glDrawArrays(GL_LINES, 10, 2);
GLint pixelValue[4] = {0};
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_INT, &pixelValue);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(vertexData[11], pixelValue[0]);
}
// Test drawing a simple triangle strip with flat shading, and different valued vertices.
TEST_P(ProvokingVertexTest, FlatTriStrip)
{
GLint vertexData[] = {1, 2, 3, 4, 5, 6};
GLfloat positionData[] = {-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, -1.0f,
0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, positionData);
glUseProgram(mProgram);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 6);
std::vector<GLint> pixelBuffer(getWindowWidth() * getWindowHeight() * 4, 0);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA_INTEGER, GL_INT,
&pixelBuffer[0]);
ASSERT_GL_NO_ERROR();
for (unsigned int triIndex = 0; triIndex < 4; ++triIndex)
{
GLfloat sumX = positionData[triIndex * 2 + 0] + positionData[triIndex * 2 + 2] +
positionData[triIndex * 2 + 4];
GLfloat sumY = positionData[triIndex * 2 + 1] + positionData[triIndex * 2 + 3] +
positionData[triIndex * 2 + 5];
float centerX = sumX / 3.0f * 0.5f + 0.5f;
float centerY = sumY / 3.0f * 0.5f + 0.5f;
unsigned int pixelX =
static_cast<unsigned int>(centerX * static_cast<GLfloat>(getWindowWidth()));
unsigned int pixelY =
static_cast<unsigned int>(centerY * static_cast<GLfloat>(getWindowHeight()));
unsigned int pixelIndex = pixelY * getWindowWidth() + pixelX;
unsigned int provokingVertexIndex = triIndex + 2;
EXPECT_EQ(vertexData[provokingVertexIndex], pixelBuffer[pixelIndex * 4]);
}
}
// Test drawing an indexed triangle strip with flat shading and primitive restart.
TEST_P(ProvokingVertexTest, FlatTriStripPrimitiveRestart)
{
// TODO(jmadill): Implement on the D3D back-end.
ANGLE_SKIP_TEST_IF(IsD3D11());
GLint indexData[] = {0, 1, 2, -1, 1, 2, 3, 4, -1, 3, 4, 5};
GLint vertexData[] = {1, 2, 3, 4, 5, 6};
GLfloat positionData[] = {-1.0f, -1.0f, -1.0f, 1.0f, 0.0f, -1.0f,
0.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f};
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, positionData);
glDisable(GL_CULL_FACE);
glEnable(GL_PRIMITIVE_RESTART_FIXED_INDEX);
glUseProgram(mProgram);
glDrawElements(GL_TRIANGLE_STRIP, 12, GL_UNSIGNED_INT, indexData);
std::vector<GLint> pixelBuffer(getWindowWidth() * getWindowHeight() * 4, 0);
glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA_INTEGER, GL_INT,
&pixelBuffer[0]);
ASSERT_GL_NO_ERROR();
// Account for primitive restart when checking the tris.
GLint triOffsets[] = {0, 4, 5, 9};
for (unsigned int triIndex = 0; triIndex < 4; ++triIndex)
{
GLint vertexA = indexData[triOffsets[triIndex] + 0];
GLint vertexB = indexData[triOffsets[triIndex] + 1];
GLint vertexC = indexData[triOffsets[triIndex] + 2];
GLfloat sumX =
positionData[vertexA * 2] + positionData[vertexB * 2] + positionData[vertexC * 2];
GLfloat sumY = positionData[vertexA * 2 + 1] + positionData[vertexB * 2 + 1] +
positionData[vertexC * 2 + 1];
float centerX = sumX / 3.0f * 0.5f + 0.5f;
float centerY = sumY / 3.0f * 0.5f + 0.5f;
unsigned int pixelX =
static_cast<unsigned int>(centerX * static_cast<GLfloat>(getWindowWidth()));
unsigned int pixelY =
static_cast<unsigned int>(centerY * static_cast<GLfloat>(getWindowHeight()));
unsigned int pixelIndex = pixelY * getWindowWidth() + pixelX;
unsigned int provokingVertexIndex = triIndex + 2;
EXPECT_EQ(vertexData[provokingVertexIndex], pixelBuffer[pixelIndex * 4]);
}
}
// Test with FRONT_CONVENTION if we have ANGLE_provoking_vertex.
TEST_P(ProvokingVertexTest, ANGLEProvokingVertex)
{
int32_t vertexData[] = {1, 2, 3};
float positionData[] = {-1.0f, -1.0f, 3.0f, -1.0f, -1.0f, 3.0f};
glEnableVertexAttribArray(mIntAttribLocation);
glVertexAttribIPointer(mIntAttribLocation, 1, GL_INT, 0, vertexData);
GLint positionLocation = glGetAttribLocation(mProgram, "position");
glEnableVertexAttribArray(positionLocation);
glVertexAttribPointer(positionLocation, 2, GL_FLOAT, GL_FALSE, 0, positionData);
glUseProgram(mProgram);
ASSERT_GL_NO_ERROR();
const auto &fnExpectId = [&](int id) {
const int32_t zero[4] = {};
glClearBufferiv(GL_COLOR, 0, zero);
glDrawArrays(GL_TRIANGLES, 0, 3);
int32_t pixelValue[4] = {0};
glReadPixels(0, 0, 1, 1, GL_RGBA_INTEGER, GL_INT, &pixelValue);
ASSERT_GL_NO_ERROR();
EXPECT_EQ(vertexData[id], pixelValue[0]);
};
fnExpectId(2);
const bool hasExt = IsGLExtensionEnabled("GL_ANGLE_provoking_vertex");
if (IsD3D11())
{
EXPECT_TRUE(hasExt);
}
if (hasExt)
{
GLint mode;
glGetIntegerv(GL_PROVOKING_VERTEX_ANGLE, &mode);
EXPECT_EQ(mode, GL_LAST_VERTEX_CONVENTION_ANGLE);
glProvokingVertexANGLE(GL_FIRST_VERTEX_CONVENTION_ANGLE);
glGetIntegerv(GL_PROVOKING_VERTEX_ANGLE, &mode);
EXPECT_EQ(mode, GL_FIRST_VERTEX_CONVENTION_ANGLE);
fnExpectId(0);
}
}
// Tests that alternating between drawing with flat and interpolated varyings works.
TEST_P(ProvokingVertexTest, DrawWithBothFlatAndInterpolatedVarying)
{
constexpr char kFlatVS[] = R"(#version 300 es
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
flat out highp vec4 v_color;
void main() {
gl_Position = position;
v_color = color;
}
)";
constexpr char kFlatFS[] = R"(#version 300 es
precision highp float;
flat in highp vec4 v_color;
out vec4 fragColor;
void main() {
fragColor = v_color;
}
)";
constexpr char kVS[] = R"(#version 300 es
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
out vec4 v_color;
void main() {
gl_Position = position;
v_color = color;
}
)";
constexpr char kFS[] = R"(#version 300 es
precision highp float;
in vec4 v_color;
out vec4 fragColor;
void main() {
fragColor = v_color;
}
)";
GLProgram varyingProgram;
varyingProgram.makeRaster(kVS, kFS);
GLProgram mProgram;
mProgram.makeRaster(kFlatVS, kFlatFS);
constexpr GLuint posNdx = 0;
constexpr GLuint colorNdx = 1;
static float positions[] = {
-1, -1, 1, -1, -1, 1,
};
static GLColor colors[] = {
GLColor::red,
GLColor::green,
GLColor::blue,
};
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
GLBuffer mPositionBuffer;
glBindBuffer(GL_ARRAY_BUFFER, mPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(positions), positions, GL_STATIC_DRAW);
glEnableVertexAttribArray(posNdx);
glVertexAttribPointer(posNdx, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
GLBuffer mColorBuffer;
glBindBuffer(GL_ARRAY_BUFFER, mColorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
glEnableVertexAttribArray(colorNdx);
glVertexAttribPointer(colorNdx, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, nullptr);
glUseProgram(varyingProgram);
glDrawArrays(GL_TRIANGLES, 0, 3);
glUseProgram(mProgram);
glDrawArrays(GL_TRIANGLES, 0, 3);
glUseProgram(varyingProgram);
glDrawArrays(GL_TRIANGLES, 0, 3);
glUseProgram(mProgram);
glDrawArrays(GL_TRIANGLES, 0, 3);
EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::blue);
ASSERT_GL_NO_ERROR();
}
class ProvokingVertexBufferUpdateTest : public ANGLETest<>
{
protected:
static constexpr size_t kWidth = 64;
static constexpr size_t kHeight = 64;
ProvokingVertexBufferUpdateTest()
{
setWindowWidth(64);
setWindowHeight(64);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
setConfigDepthBits(24);
}
void testSetUp() override
{
constexpr char kFlatVS[] = R"(#version 300 es
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
flat out highp vec4 v_color;
void main() {
gl_Position = position;
v_color = color;
}
)";
constexpr char kFlatFS[] = R"(#version 300 es
precision highp float;
flat in highp vec4 v_color;
out vec4 fragColor;
void main() {
fragColor = v_color;
}
)";
mProgram.makeRaster(kFlatVS, kFlatFS);
glUseProgram(mProgram);
ASSERT(kWidth % 2 == 0);
ASSERT(kHeight > 1);
constexpr GLuint posNdx = 0;
constexpr GLuint colorNdx = 1;
const size_t numQuads = kWidth / 2;
const size_t numVertsPerQuad = 4;
std::vector<Vector2> positions;
std::vector<GLColor> colors;
const size_t mNumVertsToDrawPerQuad = 6;
mNumVertsToDraw = mNumVertsToDrawPerQuad * numQuads;
for (size_t i = 0; i < numQuads; ++i)
{
float x0 = float(i + 0) / float(numQuads) * 2.0f - 1.0f;
float x1 = float(i + 1) / float(numQuads) * 2.0f - 1.0f;
positions.push_back(Vector2(x0, -1)); // 2--3
positions.push_back(Vector2(x1, -1)); // | |
positions.push_back(Vector2(x0, 1)); // 0--1
positions.push_back(Vector2(x1, 1));
colors.push_back(GLColor::red);
colors.push_back(GLColor::green);
colors.push_back(GLColor::blue);
colors.push_back(GLColor::yellow);
size_t offset = i * numVertsPerQuad;
mIndicesBlueYellow.push_back(offset + 0);
mIndicesBlueYellow.push_back(offset + 1);
mIndicesBlueYellow.push_back(offset + 2); // blue
mIndicesBlueYellow.push_back(offset + 2);
mIndicesBlueYellow.push_back(offset + 1);
mIndicesBlueYellow.push_back(offset + 3); // yellow
mIndicesRedGreen.push_back(offset + 1);
mIndicesRedGreen.push_back(offset + 2);
mIndicesRedGreen.push_back(offset + 0); // red
mIndicesRedGreen.push_back(offset + 3);
mIndicesRedGreen.push_back(offset + 2);
mIndicesRedGreen.push_back(offset + 1); // green
mIndicesGreenBlue.push_back(offset + 2);
mIndicesGreenBlue.push_back(offset + 0);
mIndicesGreenBlue.push_back(offset + 1); // green
mIndicesGreenBlue.push_back(offset + 1);
mIndicesGreenBlue.push_back(offset + 3);
mIndicesGreenBlue.push_back(offset + 2); // blue
}
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glBindBuffer(GL_ARRAY_BUFFER, mPositionBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeOfVectorContents(positions), positions.data(),
GL_STATIC_DRAW);
glEnableVertexAttribArray(posNdx);
glVertexAttribPointer(posNdx, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
glBindBuffer(GL_ARRAY_BUFFER, mColorBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeOfVectorContents(colors), colors.data(), GL_STATIC_DRAW);
glEnableVertexAttribArray(colorNdx);
glVertexAttribPointer(colorNdx, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, nullptr);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
ASSERT_GL_NO_ERROR();
}
void testTearDown() override {}
size_t mNumVertsToDraw;
GLProgram mProgram;
GLBuffer mPositionBuffer;
GLBuffer mColorBuffer;
GLBuffer mIndexBuffer;
std::vector<GLushort> mIndicesBlueYellow;
std::vector<GLushort> mIndicesRedGreen;
std::vector<GLushort> mIndicesGreenBlue;
};
// Tests that updating the index buffer via BufferData more than once works with flat interpolation
// The backend may queue the updates so the test tests that we draw after the buffer has been
// updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWith2BufferUpdates)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
// Tests that updating the index buffer more than once with a draw in between updates works with
// flat interpolation The backend may queue the updates so the test tests that we draw after the
// buffer has been updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWithBufferUpdateBetweenDraws)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
// Tests that updating the index buffer with BufferSubData works with flat interpolation
// The backend may queue the updates so the test tests that we draw after the buffer has been
// updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWithBufferSubUpdate)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data());
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
// Tests that updating the index buffer with BufferSubData after drawing works with flat
// interpolation The backend may queue the updates so the test tests that we draw after the buffer
// has been updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWithBufferSubUpdateBetweenDraws)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data());
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
// Tests that updating the index buffer twice with BufferSubData works with flat interpolation
// The backend may queue the updates so the test tests that we draw after the buffer has been
// updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWith2BufferSubUpdates)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data());
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesGreenBlue),
mIndicesGreenBlue.data());
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::green, GLColor::blue);
}
// Tests that updating the index buffer with BufferSubData works after drawing with flat
// interpolation The backend may queue the updates so the test tests that we draw after the buffer
// has been updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWith2BufferSubUpdatesBetweenDraws)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen),
mIndicesRedGreen.data());
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesGreenBlue),
mIndicesGreenBlue.data());
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::green, GLColor::blue);
}
// Tests that updating the index buffer via multiple calls to BufferSubData works with flat
// interpolation The backend may queue the updates so the test tests that we draw after the buffer
// has been updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWithPartialBufferSubUpdates)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen) / 2,
mIndicesRedGreen.data());
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesRedGreen) / 2,
sizeOfVectorContents(mIndicesRedGreen) / 2,
&mIndicesRedGreen[mIndicesRedGreen.size() / 2]);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
// Tests that updating the index buffer via multiple calls to BufferSubData and drawing before the
// update works with flat interpolation The backend may queue the updates so the test tests that we
// draw after the buffer has been updated.
TEST_P(ProvokingVertexBufferUpdateTest, DrawFlatWithPartialBufferSubUpdatesBetweenDraws)
{
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesBlueYellow),
mIndicesBlueYellow.data(), GL_STREAM_DRAW);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, sizeOfVectorContents(mIndicesRedGreen) / 2,
mIndicesRedGreen.data());
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, sizeOfVectorContents(mIndicesRedGreen) / 2,
sizeOfVectorContents(mIndicesRedGreen) / 2,
&mIndicesRedGreen[mIndicesRedGreen.size() / 2]);
glDrawElements(GL_TRIANGLES, mNumVertsToDraw, GL_UNSIGNED_SHORT, nullptr);
checkFlatQuadColors(kWidth, kHeight, GLColor::red, GLColor::green);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ProvokingVertexTest);
ANGLE_INSTANTIATE_TEST(ProvokingVertexTest, ES3_D3D11(), ES3_OPENGL(), ES3_OPENGLES(), ES3_METAL());
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(ProvokingVertexBufferUpdateTest);
ANGLE_INSTANTIATE_TEST(ProvokingVertexBufferUpdateTest,
ES3_D3D11(),
ES3_OPENGL(),
ES3_OPENGLES(),
ES3_METAL());
} // anonymous namespace