Add end2end test for GL_TRIANGLE_FAN in SimpleOperationTest
Bug: angleproject:2334
Change-Id: Idb4d651ade139372f40d690e523c43b20e859a5e
Reviewed-on: https://chromium-review.googlesource.com/899024
Commit-Queue: Luc Ferron <lucferron@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/tests/gl_tests/SimpleOperationTest.cpp b/src/tests/gl_tests/SimpleOperationTest.cpp
index c48d42b..30515a9 100644
--- a/src/tests/gl_tests/SimpleOperationTest.cpp
+++ b/src/tests/gl_tests/SimpleOperationTest.cpp
@@ -233,6 +233,11 @@
// Simple line test.
TEST_P(SimpleOperationTest, DrawLine)
{
+ // We assume in the test the width and height are equal and we are tracing
+ // the line from bottom left to top right. Verify that all pixels along that line
+ // have been traced with green.
+ ASSERT_EQ(getWindowWidth(), getWindowHeight());
+
ANGLE_GL_PROGRAM(program, kBasicVertexShader, kGreenFragmentShader);
glUseProgram(program);
@@ -255,11 +260,6 @@
ASSERT_GL_NO_ERROR();
- // We assume in the test the width and height are equal and we are tracing
- // the line from bottom left to top right. Verify that all pixels along that line
- // have been traced with green.
- ASSERT_EQ(getWindowWidth(), getWindowHeight());
-
for (auto x = 0; x < getWindowWidth(); x++)
{
EXPECT_PIXEL_COLOR_EQ(x, x, GLColor::green);
@@ -269,6 +269,11 @@
// Simple line strip test.
TEST_P(SimpleOperationTest, DrawLineStrip)
{
+ // We assume in the test the width and height are equal and we are tracing
+ // the line from bottom left to center, then from center to bottom right.
+ // Verify that all pixels along these lines have been traced with green.
+ ASSERT_EQ(getWindowWidth(), getWindowHeight());
+
ANGLE_GL_PROGRAM(program, kBasicVertexShader, kGreenFragmentShader);
glUseProgram(program);
@@ -291,11 +296,6 @@
ASSERT_GL_NO_ERROR();
- // We assume in the test the width and height are equal and we are tracing
- // the line from bottom left to center, then from center to bottom right.
- // Verify that all pixels along these lines have been traced with green.
- ASSERT_EQ(getWindowWidth(), getWindowHeight());
-
const auto centerX = getWindowWidth() / 2;
const auto centerY = getWindowHeight() / 2;
@@ -310,6 +310,59 @@
}
}
+// Simple triangle fans test.
+TEST_P(SimpleOperationTest, DrawTriangleFan)
+{
+ // We assume in the test the width and height are equal and we are tracing
+ // 2 triangles to cover half the surface like this:
+ ASSERT_EQ(getWindowWidth(), getWindowHeight());
+
+ ANGLE_GL_PROGRAM(program, kBasicVertexShader, kGreenFragmentShader);
+ glUseProgram(program);
+
+ auto vertices = std::vector<Vector3>{
+ {-1.0f, -1.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {1.0f, -1.0f, 0.0f}, {1.0f, 1.0f, 0.0f}};
+
+ const GLint positionLocation = glGetAttribLocation(program, "position");
+ ASSERT_NE(-1, positionLocation);
+
+ GLBuffer vertexBuffer;
+ glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer.get());
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices[0]) * vertices.size(), vertices.data(),
+ GL_STATIC_DRAW);
+ glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(positionLocation);
+
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDrawArrays(GL_TRIANGLE_FAN, 0, static_cast<GLsizei>(vertices.size()));
+
+ glDisableVertexAttribArray(positionLocation);
+
+ EXPECT_GL_NO_ERROR();
+
+ // Check 4 lines accross de triangles to make sure we filled it.
+ // Don't check every pixel as it would slow down our tests.
+ for (auto x = 0; x < getWindowWidth(); x++)
+ {
+ EXPECT_PIXEL_COLOR_EQ(x, x, GLColor::green);
+ }
+
+ for (auto x = getWindowWidth() / 3, y = 0; x < getWindowWidth(); x++, y++)
+ {
+ EXPECT_PIXEL_COLOR_EQ(x, y, GLColor::green);
+ }
+
+ for (auto x = getWindowWidth() / 2, y = 0; x < getWindowWidth(); x++, y++)
+ {
+ EXPECT_PIXEL_COLOR_EQ(x, y, GLColor::green);
+ }
+
+ for (auto x = (getWindowWidth() / 4) * 3, y = 0; x < getWindowWidth(); x++, y++)
+ {
+ EXPECT_PIXEL_COLOR_EQ(x, y, GLColor::green);
+ }
+}
+
// Simple repeated draw and swap test.
TEST_P(SimpleOperationTest, DrawQuadAndSwap)
{