blob: 4858f205243f293d23e651dac39a34c63c53e08b [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
2// Copyright 2015 The ANGLE Project Authors. All rights reserved.
3// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Corentin Wallezd3970de2015-05-14 11:07:48 -04007#include "test_utils/ANGLETest.h"
Jamie Madillfa05f602015-05-07 13:47:11 -04008
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
10
11template <typename IndexType, GLenum IndexTypeName>
Geoff Langf8c2f5c2013-12-05 13:52:33 -050012class IndexedPointsTest : public ANGLETest
13{
Jamie Madillfa05f602015-05-07 13:47:11 -040014 protected:
15 IndexedPointsTest()
Geoff Langf8c2f5c2013-12-05 13:52:33 -050016 {
17 setWindowWidth(128);
18 setWindowHeight(128);
19 setConfigRedBits(8);
20 setConfigGreenBits(8);
21 setConfigBlueBits(8);
22 setConfigAlphaBits(8);
23 setConfigDepthBits(24);
24 }
25
Jamie Madill231c7f52017-04-26 13:45:37 -040026 float getIndexPositionX(size_t idx) { return (idx == 0 || idx == 3) ? -0.5f : 0.5f; }
Geoff Langf8c2f5c2013-12-05 13:52:33 -050027
Jamie Madill231c7f52017-04-26 13:45:37 -040028 float getIndexPositionY(size_t idx) { return (idx == 2 || idx == 3) ? -0.5f : 0.5f; }
Geoff Langf8c2f5c2013-12-05 13:52:33 -050029
30 virtual void SetUp()
31 {
32 ANGLETest::SetUp();
33
Jamie Madill231c7f52017-04-26 13:45:37 -040034 const std::string vertexShaderSource =
35 SHADER_SOURCE(precision highp float; attribute vec2 position;
Geoff Langf8c2f5c2013-12-05 13:52:33 -050036
Jamie Madill231c7f52017-04-26 13:45:37 -040037 void main() {
38 gl_PointSize = 5.0;
39 gl_Position = vec4(position, 0.0, 1.0);
40 });
Geoff Langf8c2f5c2013-12-05 13:52:33 -050041
Jamie Madill231c7f52017-04-26 13:45:37 -040042 const std::string fragmentShaderSource =
43 SHADER_SOURCE(precision highp float;
Geoff Langf8c2f5c2013-12-05 13:52:33 -050044
Jamie Madill231c7f52017-04-26 13:45:37 -040045 void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); });
Geoff Langf8c2f5c2013-12-05 13:52:33 -050046
Jamie Madill5599c8f2014-08-26 13:16:39 -040047 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Cooper Partin558f2b52015-06-02 09:34:11 -070048 ASSERT_NE(0u, mProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050049
Jamie Madill231c7f52017-04-26 13:45:37 -040050 const std::string vertexShaderSource2 =
51 SHADER_SOURCE(precision highp float; attribute vec2 position; attribute vec4 color;
52 varying vec4 vcolor;
Cooper Partin558f2b52015-06-02 09:34:11 -070053
Jamie Madill231c7f52017-04-26 13:45:37 -040054 void main() {
55 gl_PointSize = 5.0;
56 gl_Position = vec4(position, 0.0, 1.0);
57 vcolor = color;
58 });
Cooper Partin558f2b52015-06-02 09:34:11 -070059
Jamie Madill231c7f52017-04-26 13:45:37 -040060 const std::string fragmentShaderSource2 =
61 SHADER_SOURCE(precision highp float; varying vec4 vcolor;
62 void main() { gl_FragColor = vec4(vcolor.xyz, 1.0); });
Cooper Partin558f2b52015-06-02 09:34:11 -070063
64 mVertexWithColorBufferProgram = CompileProgram(vertexShaderSource2, fragmentShaderSource2);
65 ASSERT_NE(0u, mVertexWithColorBufferProgram);
66
67 // Construct a vertex buffer of position values and color values
68 // contained in a single structure
Jamie Madill231c7f52017-04-26 13:45:37 -040069 const float verticesWithColor[] = {
Cooper Partin558f2b52015-06-02 09:34:11 -070070 getIndexPositionX(0), getIndexPositionY(0), 0.0f, 1.0f, 0.0f,
71 getIndexPositionX(2), getIndexPositionY(2), 0.0f, 1.0f, 0.0f,
72 getIndexPositionX(1), getIndexPositionY(1), 0.0f, 1.0f, 0.0f,
73 getIndexPositionX(3), getIndexPositionY(3), 0.0f, 1.0f, 0.0f,
74 };
75
76 glGenBuffers(1, &mVertexWithColorBuffer);
77 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
Jamie Madill231c7f52017-04-26 13:45:37 -040078 glBufferData(GL_ARRAY_BUFFER, sizeof(verticesWithColor), &verticesWithColor[0],
79 GL_STATIC_DRAW);
Cooper Partin558f2b52015-06-02 09:34:11 -070080
81 // Construct a vertex buffer of position values only
Jamie Madill231c7f52017-04-26 13:45:37 -040082 const GLfloat vertices[] = {
83 getIndexPositionX(0), getIndexPositionY(0), getIndexPositionX(2), getIndexPositionY(2),
84 getIndexPositionX(1), getIndexPositionY(1), getIndexPositionX(3), getIndexPositionY(3),
Geoff Langf8c2f5c2013-12-05 13:52:33 -050085 };
86 glGenBuffers(1, &mVertexBuffer);
87 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -040088 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050089
Cooper Partin558f2b52015-06-02 09:34:11 -070090 // The indices buffer is shared between both variations of tests
Jamie Madill231c7f52017-04-26 13:45:37 -040091 const IndexType indices[] = {0, 2, 1, 3};
Geoff Langf8c2f5c2013-12-05 13:52:33 -050092 glGenBuffers(1, &mIndexBuffer);
93 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -040094 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050095 }
96
97 virtual void TearDown()
98 {
Cooper Partin558f2b52015-06-02 09:34:11 -070099 glDeleteBuffers(1, &mVertexBuffer);
100 glDeleteBuffers(1, &mIndexBuffer);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500101 glDeleteProgram(mProgram);
102
Cooper Partin558f2b52015-06-02 09:34:11 -0700103 glDeleteBuffers(1, &mVertexWithColorBuffer);
104 glDeleteProgram(mVertexWithColorBufferProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500105 ANGLETest::TearDown();
106 }
107
Cooper Partin558f2b52015-06-02 09:34:11 -0700108 void runTest(GLuint firstIndex, bool useVertexBufferWithColor = false)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500109 {
110 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
111 glClear(GL_COLOR_BUFFER_BIT);
112
113 GLint viewportSize[4];
114 glGetIntegerv(GL_VIEWPORT, viewportSize);
115
Cooper Partin558f2b52015-06-02 09:34:11 -0700116 // Choose appropriate program to apply for the test
117 GLuint program = useVertexBufferWithColor ? mVertexWithColorBufferProgram : mProgram;
118
119 if (useVertexBufferWithColor)
120 {
121 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
122 GLint vertexLocation = glGetAttribLocation(program, "position");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700123 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE,
124 static_cast<const GLsizei>(VertexWithColorSize), 0);
Cooper Partin558f2b52015-06-02 09:34:11 -0700125 glEnableVertexAttribArray(vertexLocation);
126
127 GLint vertexColorLocation = glGetAttribLocation(program, "color");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700128 glVertexAttribPointer(vertexColorLocation, 3, GL_FLOAT, GL_FALSE,
129 static_cast<const GLsizei>(VertexWithColorSize),
Jamie Madill876429b2017-04-20 15:46:24 -0400130 (void *)((sizeof(float) * 2)));
Cooper Partin558f2b52015-06-02 09:34:11 -0700131 glEnableVertexAttribArray(vertexColorLocation);
132 }
133 else
134 {
135 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
136 GLint vertexLocation = glGetAttribLocation(program, "position");
137 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
138 glEnableVertexAttribArray(vertexLocation);
139 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500140
141 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Cooper Partin558f2b52015-06-02 09:34:11 -0700142 glUseProgram(program);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500143
Jamie Madill231c7f52017-04-26 13:45:37 -0400144 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName,
145 reinterpret_cast<void *>(firstIndex * sizeof(IndexType)));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500146
147 for (size_t i = 0; i < mPointCount; i++)
148 {
Jamie Madill231c7f52017-04-26 13:45:37 -0400149 GLuint x =
150 static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) *
151 (viewportSize[2] - viewportSize[0]));
152 GLuint y =
153 static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) *
154 (viewportSize[3] - viewportSize[1]));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500155
156 if (i < firstIndex)
157 {
158 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
159 }
160 else
161 {
Cooper Partin558f2b52015-06-02 09:34:11 -0700162 if (useVertexBufferWithColor)
163 {
164 // Pixel data is assumed to be GREEN
165 EXPECT_PIXEL_EQ(x, y, 0, 255, 0, 255);
166 }
167 else
168 {
169 // Pixel data is assumed to be RED
170 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
171 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500172 }
173 }
Cooper Partin558f2b52015-06-02 09:34:11 -0700174 swapBuffers();
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500175 }
176
177 GLuint mProgram;
178 GLuint mVertexBuffer;
179 GLuint mIndexBuffer;
Cooper Partin558f2b52015-06-02 09:34:11 -0700180
181 GLuint mVertexWithColorBufferProgram;
182 GLuint mVertexWithColorBuffer;
183
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500184 static const GLuint mPointCount = 4;
Cooper Partin558f2b52015-06-02 09:34:11 -0700185
186 private:
187 const size_t VertexWithColorSize = sizeof(float) * 5;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500188};
189
Jamie Madillfa05f602015-05-07 13:47:11 -0400190typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500191
Jamie Madillfa05f602015-05-07 13:47:11 -0400192TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500193{
194 runTest(0);
195}
196
Jamie Madillfa05f602015-05-07 13:47:11 -0400197TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500198{
199 runTest(1);
200}
201
Jamie Madillfa05f602015-05-07 13:47:11 -0400202TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500203{
204 runTest(2);
205}
206
Jamie Madillfa05f602015-05-07 13:47:11 -0400207TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500208{
209 runTest(3);
210}
211
Cooper Partin558f2b52015-06-02 09:34:11 -0700212TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset0)
213{
214 runTest(0, true);
215}
216
217TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset1)
218{
219 runTest(1, true);
220}
221
222TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset2)
223{
224 runTest(2, true);
225}
226
227TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset3)
228{
229 runTest(3, true);
230}
231
Jamie Madillfa05f602015-05-07 13:47:11 -0400232typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500233
Jamie Madillfa05f602015-05-07 13:47:11 -0400234TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500235{
236 runTest(0);
237}
238
Jamie Madillfa05f602015-05-07 13:47:11 -0400239TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500240{
241 runTest(1);
242}
243
Jamie Madillfa05f602015-05-07 13:47:11 -0400244TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500245{
246 runTest(2);
247}
248
Jamie Madillfa05f602015-05-07 13:47:11 -0400249TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500250{
251 runTest(3);
252}
253
Cooper Partin558f2b52015-06-02 09:34:11 -0700254TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset0)
255{
256 runTest(0, true);
257}
258
259TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset1)
260{
261 runTest(1, true);
262}
263
264TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset2)
265{
266 runTest(2, true);
267}
268
269TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset3)
270{
271 runTest(3, true);
272}
273
274TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffsetChangingIndices)
275{
Frank Henigmandf55f252017-04-05 15:32:06 -0400276 // TODO(fjhenigman): Figure out why this fails on Ozone Intel.
277 if (IsOzone() && IsIntel() && IsOpenGLES())
278 {
279 std::cout << "Test skipped on Ozone Intel." << std::endl;
280 return;
281 }
282
Cooper Partin558f2b52015-06-02 09:34:11 -0700283 runTest(3, true);
284 runTest(1, true);
285 runTest(0, true);
286 runTest(2, true);
287}
288
Jamie Madillfa05f602015-05-07 13:47:11 -0400289typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500290
Jamie Madillfa05f602015-05-07 13:47:11 -0400291TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500292{
Martin Radev1be913c2016-07-11 17:59:16 +0300293 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500294 {
295 return;
296 }
297
298 runTest(0);
299}
300
Jamie Madillfa05f602015-05-07 13:47:11 -0400301TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500302{
Martin Radev1be913c2016-07-11 17:59:16 +0300303 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500304 {
305 return;
306 }
307
308 runTest(1);
309}
310
Jamie Madillfa05f602015-05-07 13:47:11 -0400311TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500312{
Martin Radev1be913c2016-07-11 17:59:16 +0300313 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500314 {
315 return;
316 }
317
318 runTest(2);
319}
320
Jamie Madillfa05f602015-05-07 13:47:11 -0400321TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500322{
Martin Radev1be913c2016-07-11 17:59:16 +0300323 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500324 {
325 return;
326 }
327
328 runTest(3);
329}
Jamie Madillfa05f602015-05-07 13:47:11 -0400330
Cooper Partin558f2b52015-06-02 09:34:11 -0700331TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset0)
332{
Martin Radev1be913c2016-07-11 17:59:16 +0300333 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700334 {
335 return;
336 }
337
338 runTest(0, false);
339}
340
341TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset1)
342{
Martin Radev1be913c2016-07-11 17:59:16 +0300343 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700344 {
345 return;
346 }
347
348 runTest(1, false);
349}
350
351TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset2)
352{
Martin Radev1be913c2016-07-11 17:59:16 +0300353 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700354 {
355 return;
356 }
357
358 runTest(2, false);
359}
360
361TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset3)
362{
Martin Radev1be913c2016-07-11 17:59:16 +0300363 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700364 {
365 return;
366 }
367
368 runTest(3, false);
369}
370
Geoff Langc4222072015-05-25 13:19:48 -0400371// TODO(geofflang): Figure out why this test fails on Intel OpenGL
Geoff Lange0cc2a42016-01-20 10:58:17 -0500372ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte,
373 ES2_D3D11(),
374 ES2_D3D11_FL9_3(),
375 ES2_OPENGL(),
376 ES2_OPENGLES());
377ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort,
378 ES2_D3D11(),
379 ES2_D3D11_FL9_3(),
380 ES2_OPENGL(),
381 ES2_OPENGLES());
382ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt,
383 ES2_D3D11(),
384 ES2_D3D11_FL9_3(),
385 ES2_OPENGL(),
386 ES2_OPENGLES());