4 template <typename IndexType, GLenum IndexTypeName>
5 class IndexedPointsTest : public ANGLETest
13 setConfigGreenBits(8);
15 setConfigAlphaBits(8);
16 setConfigDepthBits(24);
19 float getIndexPositionX(size_t idx)
21 return (idx == 0 || idx == 3) ? -0.5f : 0.5f;
24 float getIndexPositionY(size_t idx)
26 return (idx == 2 || idx == 3) ? -0.5f : 0.5f;
33 const std::string vertexShaderSource = SHADER_SOURCE
35 precision highp float;
36 attribute vec2 position;
41 gl_Position = vec4(position, 0.0, 1.0);
45 const std::string fragmentShaderSource = SHADER_SOURCE
47 precision highp float;
51 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
55 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
58 FAIL() << "shader compilation failed.";
61 std::array<GLfloat, mPointCount * 2> vertices =
63 getIndexPositionX(0), getIndexPositionY(0),
64 getIndexPositionX(1), getIndexPositionY(1),
65 getIndexPositionX(2), getIndexPositionY(2),
66 getIndexPositionX(3), getIndexPositionY(3),
68 glGenBuffers(1, &mVertexBuffer);
69 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
70 glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
72 std::array<IndexType, mPointCount> indices = { 0, 1, 2, 3 };
73 glGenBuffers(1, &mIndexBuffer);
74 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
75 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IndexType), indices.data(), GL_STATIC_DRAW);
78 virtual void TearDown()
80 glDeleteProgram(mProgram);
82 ANGLETest::TearDown();
85 void runTest(GLuint firstIndex)
87 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
88 glClear(GL_COLOR_BUFFER_BIT);
90 GLint viewportSize[4];
91 glGetIntegerv(GL_VIEWPORT, viewportSize);
93 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
94 GLint vertexLocation = glGetAttribLocation(mProgram, "position");
95 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
96 glEnableVertexAttribArray(vertexLocation);
98 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
100 glUseProgram(mProgram);
102 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
104 for (size_t i = 0; i < mPointCount; i++)
106 GLuint x = viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0]);
107 GLuint y = viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1]);
111 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
115 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
121 GLuint mVertexBuffer;
123 static const GLuint mPointCount = 4;
126 typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
128 TEST_F(IndexedPointsTestUByte, UnsignedByteOffset0)
133 TEST_F(IndexedPointsTestUByte, UnsignedByteOffset1)
138 TEST_F(IndexedPointsTestUByte, UnsignedByteOffset2)
143 TEST_F(IndexedPointsTestUByte, UnsignedByteOffset3)
148 typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
150 TEST_F(IndexedPointsTestUShort, UnsignedShortOffset0)
155 TEST_F(IndexedPointsTestUShort, UnsignedShortOffset1)
160 TEST_F(IndexedPointsTestUShort, UnsignedShortOffset2)
165 TEST_F(IndexedPointsTestUShort, UnsignedShortOffset3)
170 typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
172 TEST_F(IndexedPointsTestUInt, UnsignedIntOffset0)
174 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
182 TEST_F(IndexedPointsTestUInt, UnsignedIntOffset1)
184 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
192 TEST_F(IndexedPointsTestUInt, UnsignedIntOffset2)
194 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
202 TEST_F(IndexedPointsTestUInt, UnsignedIntOffset3)
204 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))