Added emulated indexed pointsprite rendering support.
This emulation is for renderers that do not support Geometry Shaders.
BUG=angleproject:949
Change-Id: I7acf003e83ea6661f10a703486e6d07eb28786f8
Reviewed-on: https://chromium-review.googlesource.com/274851
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Cooper Partin <coopp@microsoft.com>
diff --git a/src/tests/gl_tests/IndexedPointsTest.cpp b/src/tests/gl_tests/IndexedPointsTest.cpp
index 190d965..af59eb5 100644
--- a/src/tests/gl_tests/IndexedPointsTest.cpp
+++ b/src/tests/gl_tests/IndexedPointsTest.cpp
@@ -60,23 +60,64 @@
);
mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
- if (mProgram == 0)
- {
- FAIL() << "shader compilation failed.";
- }
+ ASSERT_NE(0u, mProgram);
+ const std::string vertexShaderSource2 = SHADER_SOURCE
+ (
+ precision highp float;
+ attribute vec2 position;
+ attribute vec4 color;
+ varying vec4 vcolor;
+
+ void main()
+ {
+ gl_PointSize = 5.0;
+ gl_Position = vec4(position, 0.0, 1.0);
+ vcolor = color;
+ }
+ );
+
+ const std::string fragmentShaderSource2 = SHADER_SOURCE
+ (
+ precision highp float;
+ varying vec4 vcolor;
+ void main()
+ {
+ gl_FragColor = vec4(vcolor.xyz, 1.0);
+ }
+ );
+
+ mVertexWithColorBufferProgram = CompileProgram(vertexShaderSource2, fragmentShaderSource2);
+ ASSERT_NE(0u, mVertexWithColorBufferProgram);
+
+ // Construct a vertex buffer of position values and color values
+ // contained in a single structure
+ const float verticesWithColor[] =
+ {
+ getIndexPositionX(0), getIndexPositionY(0), 0.0f, 1.0f, 0.0f,
+ getIndexPositionX(2), getIndexPositionY(2), 0.0f, 1.0f, 0.0f,
+ getIndexPositionX(1), getIndexPositionY(1), 0.0f, 1.0f, 0.0f,
+ getIndexPositionX(3), getIndexPositionY(3), 0.0f, 1.0f, 0.0f,
+ };
+
+ glGenBuffers(1, &mVertexWithColorBuffer);
+ glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(verticesWithColor), &verticesWithColor[0], GL_STATIC_DRAW);
+
+ // Construct a vertex buffer of position values only
const GLfloat vertices[] =
{
getIndexPositionX(0), getIndexPositionY(0),
- getIndexPositionX(1), getIndexPositionY(1),
getIndexPositionX(2), getIndexPositionY(2),
+ getIndexPositionX(1), getIndexPositionY(1),
getIndexPositionX(3), getIndexPositionY(3),
};
glGenBuffers(1, &mVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
- const IndexType indices[] = { 0, 1, 2, 3 };
+ // The indices buffer is shared between both variations of tests
+ const IndexType indices[] = { 0, 2, 1, 3 };
glGenBuffers(1, &mIndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
@@ -84,12 +125,16 @@
virtual void TearDown()
{
+ glDeleteBuffers(1, &mVertexBuffer);
+ glDeleteBuffers(1, &mIndexBuffer);
glDeleteProgram(mProgram);
+ glDeleteBuffers(1, &mVertexWithColorBuffer);
+ glDeleteProgram(mVertexWithColorBufferProgram);
ANGLETest::TearDown();
}
- void runTest(GLuint firstIndex)
+ void runTest(GLuint firstIndex, bool useVertexBufferWithColor = false)
{
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
@@ -97,14 +142,30 @@
GLint viewportSize[4];
glGetIntegerv(GL_VIEWPORT, viewportSize);
- glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
- GLint vertexLocation = glGetAttribLocation(mProgram, "position");
- glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(vertexLocation);
+ // Choose appropriate program to apply for the test
+ GLuint program = useVertexBufferWithColor ? mVertexWithColorBufferProgram : mProgram;
+
+ if (useVertexBufferWithColor)
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
+ GLint vertexLocation = glGetAttribLocation(program, "position");
+ glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, VertexWithColorSize, 0);
+ glEnableVertexAttribArray(vertexLocation);
+
+ GLint vertexColorLocation = glGetAttribLocation(program, "color");
+ glVertexAttribPointer(vertexColorLocation, 3, GL_FLOAT, GL_FALSE, VertexWithColorSize, (GLvoid*)((sizeof(float) * 2)));
+ glEnableVertexAttribArray(vertexColorLocation);
+ }
+ else
+ {
+ glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
+ GLint vertexLocation = glGetAttribLocation(program, "position");
+ glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(vertexLocation);
+ }
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
-
- glUseProgram(mProgram);
+ glUseProgram(program);
glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
@@ -119,15 +180,32 @@
}
else
{
- EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
+ if (useVertexBufferWithColor)
+ {
+ // Pixel data is assumed to be GREEN
+ EXPECT_PIXEL_EQ(x, y, 0, 255, 0, 255);
+ }
+ else
+ {
+ // Pixel data is assumed to be RED
+ EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
+ }
}
}
+ swapBuffers();
}
GLuint mProgram;
GLuint mVertexBuffer;
GLuint mIndexBuffer;
+
+ GLuint mVertexWithColorBufferProgram;
+ GLuint mVertexWithColorBuffer;
+
static const GLuint mPointCount = 4;
+
+ private:
+ const size_t VertexWithColorSize = sizeof(float) * 5;
};
typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
@@ -152,6 +230,26 @@
runTest(3);
}
+TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset0)
+{
+ runTest(0, true);
+}
+
+TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset1)
+{
+ runTest(1, true);
+}
+
+TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset2)
+{
+ runTest(2, true);
+}
+
+TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset3)
+{
+ runTest(3, true);
+}
+
typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
@@ -174,6 +272,34 @@
runTest(3);
}
+TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset0)
+{
+ runTest(0, true);
+}
+
+TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset1)
+{
+ runTest(1, true);
+}
+
+TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset2)
+{
+ runTest(2, true);
+}
+
+TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset3)
+{
+ runTest(3, true);
+}
+
+TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffsetChangingIndices)
+{
+ runTest(3, true);
+ runTest(1, true);
+ runTest(0, true);
+ runTest(2, true);
+}
+
typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
@@ -216,7 +342,47 @@
runTest(3);
}
+TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset0)
+{
+ if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
+ {
+ return;
+ }
+
+ runTest(0, false);
+}
+
+TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset1)
+{
+ if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
+ {
+ return;
+ }
+
+ runTest(1, false);
+}
+
+TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset2)
+{
+ if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
+ {
+ return;
+ }
+
+ runTest(2, false);
+}
+
+TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset3)
+{
+ if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
+ {
+ return;
+ }
+
+ runTest(3, false);
+}
+
// TODO(geofflang): Figure out why this test fails on Intel OpenGL
-ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte, ES2_D3D11());
-ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort, ES2_D3D11());
-ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt, ES2_D3D11());
+ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte, ES2_D3D11(), ES2_D3D11_FL9_3());
+ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort, ES2_D3D11(), ES2_D3D11_FL9_3());
+ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt, ES2_D3D11(), ES2_D3D11_FL9_3());