Hash :
96c9f065
Author :
Date :
2025-05-15T19:22:29
WGPU: Flip y for the default framebuffer Bug: angleproject:389145696 Change-Id: I0d527ad3dc24dbca7e9d914b03edacdc257a568f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6477137 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Matthew Denton <mpdenton@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
//
// Copyright 2017 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.
//
// SamplerTest.cpp : Tests for samplers.
#include "gtest/gtest.h"
#include "test_utils/ANGLETest.h"
#include "test_utils/angle_test_configs.h"
#include "test_utils/gl_raii.h"
#include "util/gles_loader_autogen.h"
#include "util/shader_utils.h"
namespace angle
{
using BasicSamplersTest = ANGLETest<>;
// Basic sampler test.
TEST_P(BasicSamplersTest, SampleATexture)
{
constexpr int kWidth = 2;
constexpr int kHeight = 2;
const GLchar *vertString = R"(precision highp float;
attribute vec2 a_position;
varying vec2 texCoord;
void main()
{
gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
texCoord = a_position * 0.5 + vec2(0.5);
})";
const GLchar *fragString = R"(precision highp float;
varying vec2 texCoord;
uniform sampler2D tex;
void main()
{
gl_FragColor = texture2D(tex, texCoord);
})";
std::array<GLColor, kWidth * kHeight> redColor = {
{GLColor::red, GLColor::red, GLColor::red, GLColor::red}};
std::array<GLColor, kWidth * kHeight> greenColor = {
{GLColor::green, GLColor::green, GLColor::green, GLColor::green}};
// Create a red texture and bind to texture unit 0
GLTexture redTex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, redTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
redColor.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Create a green texture and bind to texture unit 1
GLTexture greenTex;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, greenTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
greenColor.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glActiveTexture(GL_TEXTURE0);
ASSERT_GL_NO_ERROR();
GLProgram program;
program.makeRaster(vertString, fragString);
ASSERT_NE(0u, program);
glUseProgram(program);
GLint location = glGetUniformLocation(program, "tex");
ASSERT_NE(location, -1);
ASSERT_GL_NO_ERROR();
// Draw red
glUniform1i(location, 0);
ASSERT_GL_NO_ERROR();
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, GLColor::red);
// Draw green
glUniform1i(location, 1);
ASSERT_GL_NO_ERROR();
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, GLColor::green);
}
class SampleFromRenderedTextureTest : public ANGLETest<>
{
protected:
const GLchar *vertString = R"(precision highp float;
attribute vec2 a_position;
varying vec2 texCoord;
void main()
{
gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
texCoord = a_position * 0.5 + vec2(0.5);
})";
const GLchar *vertString2 = R"(precision highp float;
attribute vec2 a_position;
varying vec2 texCoord;
void main()
{
gl_Position = vec4(a_position.x, a_position.y, 0.0, 1.0);
texCoord = a_position * 0.25 + vec2(0.5);
})";
const GLchar *fragString = R"(precision highp float;
varying vec2 texCoord;
uniform sampler2D tex;
void main()
{
gl_FragColor = texture2D(tex, texCoord);
})";
virtual GLsizei getTextureWidth() = 0;
virtual GLsizei getTextureHeight() = 0;
virtual GLsizei getViewportOriginX() = 0;
virtual GLsizei getViewportOriginY() = 0;
void testSetUp() override
{
glViewport(getViewportOriginX(), getViewportOriginY(), getTextureWidth(),
getTextureHeight());
ANGLETest<>::testSetUp();
}
GLuint createGradientTexture()
{
GLuint gradientTex;
glGenTextures(1, &gradientTex);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, gradientTex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
std::vector<GLubyte> gradientPixels(getTextureWidth() * getTextureHeight() * 4);
for (GLubyte y = 0; y < getTextureHeight(); y++)
{
for (GLubyte x = 0; x < getTextureWidth(); x++)
{
GLubyte *pixel = &gradientPixels[0] + ((y * getTextureWidth() + x) * 4);
// Draw a gradient, red in x direction, green in y direction
pixel[0] = x;
pixel[1] = y;
pixel[2] = 0u;
pixel[3] = 255u;
}
}
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getTextureWidth(), getTextureHeight(), 0, GL_RGBA,
GL_UNSIGNED_BYTE, gradientPixels.data());
EXPECT_GL_NO_ERROR();
glBindTexture(GL_TEXTURE_2D, 0);
return gradientTex;
}
void installProgram(bool halfScreen)
{
if (halfScreen)
{
mProgram.makeRaster(vertString2, fragString);
ASSERT_NE(0u, mProgram);
glUseProgram(mProgram);
}
else
{
mProgram.makeRaster(vertString, fragString);
ASSERT_NE(0u, mProgram);
glUseProgram(mProgram);
}
}
void createBoundFramebufferWithColorAttachment(GLuint *fboId, GLuint *colorAttachment)
{
// Create a texture to use as the non-default FBO's color attachment.
glGenTextures(1, colorAttachment);
glBindTexture(GL_TEXTURE_2D, *colorAttachment);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, getWindowWidth(), getWindowHeight(), 0, GL_RGBA,
GL_UNSIGNED_BYTE, NULL);
EXPECT_GL_NO_ERROR();
// Create the non-default fbo
if (fboId)
{
glGenFramebuffers(1, fboId);
glBindFramebuffer(GL_FRAMEBUFFER, *fboId);
EXPECT_GL_NO_ERROR();
}
// Attach the texture to the fbo
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
*colorAttachment, 0);
ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
ASSERT_GL_NO_ERROR();
glBindTexture(GL_TEXTURE_2D, 0);
}
void bindActiveTextureToProgram(GLuint activeTextureUnit, GLuint tex)
{
GLint texLocation = glGetUniformLocation(mProgram, "tex");
ASSERT_NE(texLocation, -1);
ASSERT_GL_NO_ERROR();
glActiveTexture(GL_TEXTURE0 + activeTextureUnit);
glBindTexture(GL_TEXTURE_2D, tex);
ASSERT_GL_NO_ERROR();
glUniform1i(texLocation, activeTextureUnit);
ASSERT_GL_NO_ERROR();
}
void drawAndCheckGradient(bool strict)
{
drawQuad(mProgram, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
std::vector<GLubyte> pixels(getTextureWidth() * getTextureHeight() * 4);
glReadPixels(getViewportOriginX(), getViewportOriginY(), getTextureWidth(),
getTextureHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
ASSERT_GL_NO_ERROR();
// Check the pixels match the gradient.
size_t checkWidth = getTextureWidth();
size_t checkHeight = getTextureHeight();
if (!strict)
{
// Don't check the last row or column if not strict.
checkWidth--;
checkHeight--;
}
for (size_t y = 1; y < checkHeight; y++)
{
for (size_t x = 1; x < checkWidth; x++)
{
const GLubyte *prevPixel =
pixels.data() + (((y - 1) * getTextureWidth() + (x - 1)) * 4);
const GLubyte *curPixel = pixels.data() + ((y * getTextureWidth() + x) * 4);
if (strict)
{
EXPECT_EQ(curPixel[0], prevPixel[0] + 1)
<< " failed at (" << x << ", " << y << ")";
EXPECT_EQ(curPixel[1], prevPixel[1] + 1)
<< " failed at (" << x << ", " << y << ")";
}
else
{
EXPECT_GE(curPixel[0], prevPixel[0]) << " failed at (" << x << ", " << y << ")";
EXPECT_GE(curPixel[1], prevPixel[1]) << " failed at (" << x << ", " << y << ")";
}
EXPECT_EQ(curPixel[2], prevPixel[2]);
EXPECT_EQ(curPixel[3], prevPixel[3]);
}
}
}
GLProgram mProgram;
};
class SampleFromRenderedTextureTestHalfWindow : public SampleFromRenderedTextureTest
{
protected:
static constexpr GLsizei kTextureWidth = 255;
static constexpr GLsizei kTextureHeight = 255;
static constexpr GLsizei kViewportOriginX = kTextureWidth / 2;
static constexpr GLsizei kViewportOriginY = kTextureHeight / 2;
static constexpr GLsizei kWindowWidth = kTextureWidth * 2;
static constexpr GLsizei kWindowHeight = kTextureHeight * 2;
GLsizei getTextureWidth() override { return kTextureWidth; }
GLsizei getTextureHeight() override { return kTextureHeight; }
GLsizei getViewportOriginX() override { return kViewportOriginX; }
GLsizei getViewportOriginY() override { return kViewportOriginY; }
SampleFromRenderedTextureTestHalfWindow()
{
setWindowWidth(kWindowWidth);
setWindowHeight(kWindowHeight);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Renders a gradient to a texture (twice the size) attached to an FBO, then samples from that
// texture in a second pass, effectively copying the gradient to the middle of the default
// framebuffer. Tests that the gradient remains intact.
TEST_P(SampleFromRenderedTextureTestHalfWindow, RenderToTextureAndSampleFromIt)
{
// Create a gradient texture to use as the original source texture.
GLuint gradientTex = createGradientTexture();
installProgram(/*halfScreen=*/false);
GLuint fboId;
GLuint fboTextureAttachment;
createBoundFramebufferWithColorAttachment(&fboId, &fboTextureAttachment);
// The source texture used by the fragment shader should be the gradient texture.
bindActiveTextureToProgram(0, gradientTex);
drawAndCheckGradient(/*strict=*/true);
// Sample from the texture only in the current viewport (half the screen).
installProgram(/*halfScreen=*/true);
// Now bind the default framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ASSERT_GL_NO_ERROR();
// Use the texture attached to the first framebuffer as the source texture for this draw call.
bindActiveTextureToProgram(0, fboTextureAttachment);
// Draw and check the pixels, but in the default framebuffer
drawAndCheckGradient(/*strict=*/false);
}
class SampleFromRenderedTextureTestFullWindow : public SampleFromRenderedTextureTest
{
protected:
static constexpr GLsizei kTextureWidth = 255;
static constexpr GLsizei kTextureHeight = 255;
static constexpr GLsizei kViewportOriginX = 0;
static constexpr GLsizei kViewportOriginY = 0;
static constexpr GLsizei kWindowWidth = kTextureWidth;
static constexpr GLsizei kWindowHeight = kTextureHeight;
GLsizei getTextureWidth() override { return kTextureWidth; }
GLsizei getTextureHeight() override { return kTextureHeight; }
GLsizei getViewportOriginX() override { return kViewportOriginX; }
GLsizei getViewportOriginY() override { return kViewportOriginY; }
SampleFromRenderedTextureTestFullWindow()
{
setWindowWidth(kWindowWidth);
setWindowHeight(kWindowHeight);
setConfigRedBits(8);
setConfigGreenBits(8);
setConfigBlueBits(8);
setConfigAlphaBits(8);
}
};
// Renders a gradient to a texture attached to an FBO, then samples from that texture in a second
// pass, effectively copying the gradient to the default framebuffer. Tests that the gradient
// remains intact.
TEST_P(SampleFromRenderedTextureTestFullWindow, RenderToTextureAndSampleFromIt)
{
// Setup the program.
installProgram(/*halfScreen=*/false);
// Create a gradient texture to use as the original source texture.
GLuint gradientTex = createGradientTexture();
// Create a texture to use as the non-default FBO's color attachment.
GLuint fboId;
GLuint fboTextureAttachment;
createBoundFramebufferWithColorAttachment(&fboId, &fboTextureAttachment);
bindActiveTextureToProgram(0, gradientTex);
drawAndCheckGradient(/*strict=*/true);
// Now bind the default framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ASSERT_GL_NO_ERROR();
// Use the texture attached to the first framebuffer as the source texture for this draw call.
bindActiveTextureToProgram(0, fboTextureAttachment);
drawAndCheckGradient(/*strict=*/true);
}
// Renders a gradient to a texture attached to an FBO, then samples from that texture in a second
// pass rendering to another texture attached to the FBO. Finally that texture is rendered to the
// default framebuffer. Tests that the gradient remains intact.
TEST_P(SampleFromRenderedTextureTestFullWindow, RenderToTextureTwiceAndSampleFromIt)
{
// Setup the program.
installProgram(/*halfScreen=*/false);
// Create a gradient texture to use as the original source texture.
GLuint gradientTex = createGradientTexture();
// Create a texture to use as the non-default FBO's color attachment.
GLuint fboId;
GLuint fboTextureAttachment;
createBoundFramebufferWithColorAttachment(&fboId, &fboTextureAttachment);
bindActiveTextureToProgram(0, gradientTex);
drawAndCheckGradient(/*strict=*/true);
// Create another texture to use as the non-default FBO's color attachment.
GLuint fboTextureAttachment2;
createBoundFramebufferWithColorAttachment(nullptr, &fboTextureAttachment2);
// Use the texture attached to the first framebuffer as the source texture for this draw call.
bindActiveTextureToProgram(0, fboTextureAttachment);
drawAndCheckGradient(/*strict=*/true);
// Now bind the default framebuffer.
glBindFramebuffer(GL_FRAMEBUFFER, 0);
ASSERT_GL_NO_ERROR();
// Use the second texture attached to the first framebuffer as the source texture for this draw
// call.
bindActiveTextureToProgram(0, fboTextureAttachment2);
drawAndCheckGradient(/*strict=*/true);
}
class SamplersTest : public ANGLETest<>
{
protected:
SamplersTest() {}
// Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to fail.
void validateInvalidAnisotropy(GLSampler &sampler, float invalidValue)
{
glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, invalidValue);
EXPECT_GL_ERROR(GL_INVALID_VALUE);
}
// Sets a value for GL_TEXTURE_MAX_ANISOTROPY_EXT and expects it to work.
void validateValidAnisotropy(GLSampler &sampler, float validValue)
{
glSamplerParameterf(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, validValue);
EXPECT_GL_NO_ERROR();
GLfloat valueToVerify = 0.0f;
glGetSamplerParameterfv(sampler, GL_TEXTURE_MAX_ANISOTROPY_EXT, &valueToVerify);
ASSERT_EQ(valueToVerify, validValue);
}
};
class SamplersTest31 : public SamplersTest
{};
// Verify that samplerParameterf supports TEXTURE_MAX_ANISOTROPY_EXT valid values.
TEST_P(SamplersTest, ValidTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
// Exact min
validateValidAnisotropy(sampler, 1.0f);
GLfloat maxValue = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
// Max value
validateValidAnisotropy(sampler, maxValue - 1);
// In-between
GLfloat between = (1.0f + maxValue) / 2;
validateValidAnisotropy(sampler, between);
}
// Verify an error is thrown if we try to go under the minimum value for
// GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest, InvalidUnderTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
// Under min
validateInvalidAnisotropy(sampler, 0.0f);
}
// Verify an error is thrown if we try to go over the max value for
// GL_TEXTURE_MAX_ANISOTROPY_EXT
TEST_P(SamplersTest, InvalidOverTextureSamplerMaxAnisotropyExt)
{
GLSampler sampler;
GLfloat maxValue = 0.0f;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxValue);
maxValue += 1;
validateInvalidAnisotropy(sampler, maxValue);
}
// Test that updating a sampler uniform in a program behaves correctly.
TEST_P(SamplersTest31, SampleTextureAThenTextureB)
{
ANGLE_SKIP_TEST_IF(!IsVulkan());
constexpr int kWidth = 2;
constexpr int kHeight = 2;
const GLchar *vertString = R"(#version 310 es
precision highp float;
in vec2 a_position;
out vec2 texCoord;
void main()
{
gl_Position = vec4(a_position, 0, 1);
texCoord = a_position * 0.5 + vec2(0.5);
})";
const GLchar *fragString = R"(#version 310 es
precision highp float;
in vec2 texCoord;
uniform sampler2D tex;
out vec4 my_FragColor;
void main()
{
my_FragColor = texture(tex, texCoord);
})";
std::array<GLColor, kWidth * kHeight> redColor = {
{GLColor::red, GLColor::red, GLColor::red, GLColor::red}};
std::array<GLColor, kWidth * kHeight> greenColor = {
{GLColor::green, GLColor::green, GLColor::green, GLColor::green}};
// Create a red texture and bind to texture unit 0
GLTexture redTex;
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, redTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
redColor.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
ASSERT_GL_NO_ERROR();
// Create a green texture and bind to texture unit 1
GLTexture greenTex;
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, greenTex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
greenColor.data());
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glActiveTexture(GL_TEXTURE0);
ASSERT_GL_NO_ERROR();
GLProgram program;
program.makeRaster(vertString, fragString);
ASSERT_NE(0u, program);
glUseProgram(program);
GLint location = glGetUniformLocation(program, "tex");
ASSERT_NE(location, -1);
ASSERT_GL_NO_ERROR();
// Draw red
glUniform1i(location, 0);
ASSERT_GL_NO_ERROR();
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE);
// Draw green
glUniform1i(location, 1);
ASSERT_GL_NO_ERROR();
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
// Draw red
glUniform1i(location, 0);
ASSERT_GL_NO_ERROR();
drawQuad(program, "a_position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_RECT_EQ(0, 0, kWidth, kHeight, GLColor::yellow);
}
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(BasicSamplersTest);
ANGLE_INSTANTIATE_TEST_ES2_AND(BasicSamplersTest, ES2_WEBGPU());
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SampleFromRenderedTextureTestHalfWindow);
ANGLE_INSTANTIATE_TEST_ES2_AND(SampleFromRenderedTextureTestHalfWindow, ES2_WEBGPU());
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SampleFromRenderedTextureTestFullWindow);
ANGLE_INSTANTIATE_TEST_ES2_AND(SampleFromRenderedTextureTestFullWindow, ES2_WEBGPU());
// Samplers are only supported on ES3.
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SamplersTest);
ANGLE_INSTANTIATE_TEST_ES3(SamplersTest);
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(SamplersTest31);
ANGLE_INSTANTIATE_TEST_ES31(SamplersTest31);
} // namespace angle