blob: e5c7c789ef87f0f241523a4671fc60841ef18012 [file] [log] [blame]
Geoff Langf8c2f5c2013-12-05 13:52:33 -05001#include "ANGLETest.h"
2#include <array>
3
4template <typename IndexType, GLenum IndexTypeName>
5class IndexedPointsTest : public ANGLETest
6{
7protected:
8 IndexedPointsTest()
9 {
10 setWindowWidth(128);
11 setWindowHeight(128);
12 setConfigRedBits(8);
13 setConfigGreenBits(8);
14 setConfigBlueBits(8);
15 setConfigAlphaBits(8);
16 setConfigDepthBits(24);
17 }
18
19 float getIndexPositionX(size_t idx)
20 {
21 return (idx == 0 || idx == 3) ? -0.5f : 0.5f;
22 }
23
24 float getIndexPositionY(size_t idx)
25 {
26 return (idx == 2 || idx == 3) ? -0.5f : 0.5f;
27 }
28
29 virtual void SetUp()
30 {
31 ANGLETest::SetUp();
32
33 const std::string vertexShaderSource = SHADER_SOURCE
34 (
35 precision highp float;
36 attribute vec2 position;
37
38 void main()
39 {
40 gl_PointSize = 5.0;
41 gl_Position = vec4(position, 0.0, 1.0);
42 }
43 );
44
45 const std::string fragmentShaderSource = SHADER_SOURCE
46 (
47 precision highp float;
48
49 void main()
50 {
51 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
52 }
53 );
54
Jamie Madill5599c8f2014-08-26 13:16:39 -040055 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050056 if (mProgram == 0)
57 {
58 FAIL() << "shader compilation failed.";
59 }
60
61 std::array<GLfloat, mPointCount * 2> vertices =
62 {
63 getIndexPositionX(0), getIndexPositionY(0),
64 getIndexPositionX(1), getIndexPositionY(1),
65 getIndexPositionX(2), getIndexPositionY(2),
66 getIndexPositionX(3), getIndexPositionY(3),
67 };
68 glGenBuffers(1, &mVertexBuffer);
69 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
70 glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), vertices.data(), GL_STATIC_DRAW);
71
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);
76 }
77
78 virtual void TearDown()
79 {
80 glDeleteProgram(mProgram);
81
82 ANGLETest::TearDown();
83 }
84
85 void runTest(GLuint firstIndex)
86 {
87 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
88 glClear(GL_COLOR_BUFFER_BIT);
89
90 GLint viewportSize[4];
91 glGetIntegerv(GL_VIEWPORT, viewportSize);
92
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);
97
98 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
99
100 glUseProgram(mProgram);
101
102 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
103
104 for (size_t i = 0; i < mPointCount; i++)
105 {
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]);
108
109 if (i < firstIndex)
110 {
111 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
112 }
113 else
114 {
115 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
116 }
117 }
118 }
119
120 GLuint mProgram;
121 GLuint mVertexBuffer;
122 GLuint mIndexBuffer;
123 static const GLuint mPointCount = 4;
124};
125
126typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
127
Jamie Madillb759a742014-07-17 10:40:49 -0400128TEST_F(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500129{
130 runTest(0);
131}
132
Jamie Madillb759a742014-07-17 10:40:49 -0400133TEST_F(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500134{
135 runTest(1);
136}
137
Jamie Madillb759a742014-07-17 10:40:49 -0400138TEST_F(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500139{
140 runTest(2);
141}
142
Jamie Madillb759a742014-07-17 10:40:49 -0400143TEST_F(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500144{
145 runTest(3);
146}
147
148typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
149
Jamie Madillb759a742014-07-17 10:40:49 -0400150TEST_F(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500151{
152 runTest(0);
153}
154
Jamie Madillb759a742014-07-17 10:40:49 -0400155TEST_F(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500156{
157 runTest(1);
158}
159
Jamie Madillb759a742014-07-17 10:40:49 -0400160TEST_F(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500161{
162 runTest(2);
163}
164
Jamie Madillb759a742014-07-17 10:40:49 -0400165TEST_F(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500166{
167 runTest(3);
168}
169
170typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
171
Jamie Madillb759a742014-07-17 10:40:49 -0400172TEST_F(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500173{
174 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
175 {
176 return;
177 }
178
179 runTest(0);
180}
181
Jamie Madillb759a742014-07-17 10:40:49 -0400182TEST_F(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500183{
184 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
185 {
186 return;
187 }
188
189 runTest(1);
190}
191
Jamie Madillb759a742014-07-17 10:40:49 -0400192TEST_F(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500193{
194 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
195 {
196 return;
197 }
198
199 runTest(2);
200}
201
Jamie Madillb759a742014-07-17 10:40:49 -0400202TEST_F(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500203{
204 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
205 {
206 return;
207 }
208
209 runTest(3);
210}