blob: 919994795bc11e7b46040124dd29f58f3cfe441f [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 =
Olli Etuahoa20af6d2017-09-18 13:32:29 +030035 R"(precision highp float;
36 attribute vec2 position;
Geoff Langf8c2f5c2013-12-05 13:52:33 -050037
Olli Etuahoa20af6d2017-09-18 13:32:29 +030038 void main() {
39 gl_PointSize = 5.0;
40 gl_Position = vec4(position, 0.0, 1.0);
41 })";
Geoff Langf8c2f5c2013-12-05 13:52:33 -050042
Jamie Madill231c7f52017-04-26 13:45:37 -040043 const std::string fragmentShaderSource =
Olli Etuahoa20af6d2017-09-18 13:32:29 +030044 R"(precision highp float;
Geoff Langf8c2f5c2013-12-05 13:52:33 -050045
Olli Etuahoa20af6d2017-09-18 13:32:29 +030046 void main()
47 {
48 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
49 })";
Geoff Langf8c2f5c2013-12-05 13:52:33 -050050
Jamie Madill5599c8f2014-08-26 13:16:39 -040051 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Cooper Partin558f2b52015-06-02 09:34:11 -070052 ASSERT_NE(0u, mProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050053
Jamie Madill231c7f52017-04-26 13:45:37 -040054 const std::string vertexShaderSource2 =
Olli Etuahoa20af6d2017-09-18 13:32:29 +030055 R"(precision highp float;
56 attribute vec2 position;
57 attribute vec4 color;
58 varying vec4 vcolor;
Cooper Partin558f2b52015-06-02 09:34:11 -070059
Olli Etuahoa20af6d2017-09-18 13:32:29 +030060 void main() {
61 gl_PointSize = 5.0;
62 gl_Position = vec4(position, 0.0, 1.0);
63 vcolor = color;
64 })";
Cooper Partin558f2b52015-06-02 09:34:11 -070065
Jamie Madill231c7f52017-04-26 13:45:37 -040066 const std::string fragmentShaderSource2 =
Olli Etuahoa20af6d2017-09-18 13:32:29 +030067 R"(precision highp float;
68 varying vec4 vcolor;
69
70 void main()
71 {
72 gl_FragColor = vec4(vcolor.xyz, 1.0);
73 })";
Cooper Partin558f2b52015-06-02 09:34:11 -070074
75 mVertexWithColorBufferProgram = CompileProgram(vertexShaderSource2, fragmentShaderSource2);
76 ASSERT_NE(0u, mVertexWithColorBufferProgram);
77
78 // Construct a vertex buffer of position values and color values
79 // contained in a single structure
Jamie Madill231c7f52017-04-26 13:45:37 -040080 const float verticesWithColor[] = {
Cooper Partin558f2b52015-06-02 09:34:11 -070081 getIndexPositionX(0), getIndexPositionY(0), 0.0f, 1.0f, 0.0f,
82 getIndexPositionX(2), getIndexPositionY(2), 0.0f, 1.0f, 0.0f,
83 getIndexPositionX(1), getIndexPositionY(1), 0.0f, 1.0f, 0.0f,
84 getIndexPositionX(3), getIndexPositionY(3), 0.0f, 1.0f, 0.0f,
85 };
86
87 glGenBuffers(1, &mVertexWithColorBuffer);
88 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
Jamie Madill231c7f52017-04-26 13:45:37 -040089 glBufferData(GL_ARRAY_BUFFER, sizeof(verticesWithColor), &verticesWithColor[0],
90 GL_STATIC_DRAW);
Cooper Partin558f2b52015-06-02 09:34:11 -070091
92 // Construct a vertex buffer of position values only
Jamie Madill231c7f52017-04-26 13:45:37 -040093 const GLfloat vertices[] = {
94 getIndexPositionX(0), getIndexPositionY(0), getIndexPositionX(2), getIndexPositionY(2),
95 getIndexPositionX(1), getIndexPositionY(1), getIndexPositionX(3), getIndexPositionY(3),
Geoff Langf8c2f5c2013-12-05 13:52:33 -050096 };
97 glGenBuffers(1, &mVertexBuffer);
98 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -040099 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500100
Cooper Partin558f2b52015-06-02 09:34:11 -0700101 // The indices buffer is shared between both variations of tests
Jamie Madill231c7f52017-04-26 13:45:37 -0400102 const IndexType indices[] = {0, 2, 1, 3};
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500103 glGenBuffers(1, &mIndexBuffer);
104 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -0400105 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500106 }
107
108 virtual void TearDown()
109 {
Cooper Partin558f2b52015-06-02 09:34:11 -0700110 glDeleteBuffers(1, &mVertexBuffer);
111 glDeleteBuffers(1, &mIndexBuffer);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500112 glDeleteProgram(mProgram);
113
Cooper Partin558f2b52015-06-02 09:34:11 -0700114 glDeleteBuffers(1, &mVertexWithColorBuffer);
115 glDeleteProgram(mVertexWithColorBufferProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500116 ANGLETest::TearDown();
117 }
118
Cooper Partin558f2b52015-06-02 09:34:11 -0700119 void runTest(GLuint firstIndex, bool useVertexBufferWithColor = false)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500120 {
121 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
122 glClear(GL_COLOR_BUFFER_BIT);
123
124 GLint viewportSize[4];
125 glGetIntegerv(GL_VIEWPORT, viewportSize);
126
Cooper Partin558f2b52015-06-02 09:34:11 -0700127 // Choose appropriate program to apply for the test
128 GLuint program = useVertexBufferWithColor ? mVertexWithColorBufferProgram : mProgram;
129
130 if (useVertexBufferWithColor)
131 {
132 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
133 GLint vertexLocation = glGetAttribLocation(program, "position");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700134 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE,
135 static_cast<const GLsizei>(VertexWithColorSize), 0);
Cooper Partin558f2b52015-06-02 09:34:11 -0700136 glEnableVertexAttribArray(vertexLocation);
137
138 GLint vertexColorLocation = glGetAttribLocation(program, "color");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700139 glVertexAttribPointer(vertexColorLocation, 3, GL_FLOAT, GL_FALSE,
140 static_cast<const GLsizei>(VertexWithColorSize),
Jamie Madill876429b2017-04-20 15:46:24 -0400141 (void *)((sizeof(float) * 2)));
Cooper Partin558f2b52015-06-02 09:34:11 -0700142 glEnableVertexAttribArray(vertexColorLocation);
143 }
144 else
145 {
146 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
147 GLint vertexLocation = glGetAttribLocation(program, "position");
148 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
149 glEnableVertexAttribArray(vertexLocation);
150 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500151
152 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Cooper Partin558f2b52015-06-02 09:34:11 -0700153 glUseProgram(program);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500154
Jamie Madill231c7f52017-04-26 13:45:37 -0400155 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName,
156 reinterpret_cast<void *>(firstIndex * sizeof(IndexType)));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500157
158 for (size_t i = 0; i < mPointCount; i++)
159 {
Jamie Madill231c7f52017-04-26 13:45:37 -0400160 GLuint x =
161 static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) *
162 (viewportSize[2] - viewportSize[0]));
163 GLuint y =
164 static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) *
165 (viewportSize[3] - viewportSize[1]));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500166
167 if (i < firstIndex)
168 {
169 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
170 }
171 else
172 {
Cooper Partin558f2b52015-06-02 09:34:11 -0700173 if (useVertexBufferWithColor)
174 {
175 // Pixel data is assumed to be GREEN
176 EXPECT_PIXEL_EQ(x, y, 0, 255, 0, 255);
177 }
178 else
179 {
180 // Pixel data is assumed to be RED
181 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
182 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500183 }
184 }
Cooper Partin558f2b52015-06-02 09:34:11 -0700185 swapBuffers();
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500186 }
187
188 GLuint mProgram;
189 GLuint mVertexBuffer;
190 GLuint mIndexBuffer;
Cooper Partin558f2b52015-06-02 09:34:11 -0700191
192 GLuint mVertexWithColorBufferProgram;
193 GLuint mVertexWithColorBuffer;
194
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500195 static const GLuint mPointCount = 4;
Cooper Partin558f2b52015-06-02 09:34:11 -0700196
197 private:
198 const size_t VertexWithColorSize = sizeof(float) * 5;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500199};
200
Jamie Madillfa05f602015-05-07 13:47:11 -0400201typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500202
Jamie Madillfa05f602015-05-07 13:47:11 -0400203TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500204{
205 runTest(0);
206}
207
Jamie Madillfa05f602015-05-07 13:47:11 -0400208TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500209{
210 runTest(1);
211}
212
Jamie Madillfa05f602015-05-07 13:47:11 -0400213TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500214{
215 runTest(2);
216}
217
Jamie Madillfa05f602015-05-07 13:47:11 -0400218TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500219{
220 runTest(3);
221}
222
Cooper Partin558f2b52015-06-02 09:34:11 -0700223TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset0)
224{
225 runTest(0, true);
226}
227
228TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset1)
229{
230 runTest(1, true);
231}
232
233TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset2)
234{
235 runTest(2, true);
236}
237
238TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset3)
239{
240 runTest(3, true);
241}
242
Jamie Madillfa05f602015-05-07 13:47:11 -0400243typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500244
Jamie Madillfa05f602015-05-07 13:47:11 -0400245TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500246{
247 runTest(0);
248}
249
Jamie Madillfa05f602015-05-07 13:47:11 -0400250TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500251{
252 runTest(1);
253}
254
Jamie Madillfa05f602015-05-07 13:47:11 -0400255TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500256{
257 runTest(2);
258}
259
Jamie Madillfa05f602015-05-07 13:47:11 -0400260TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500261{
262 runTest(3);
263}
264
Cooper Partin558f2b52015-06-02 09:34:11 -0700265TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset0)
266{
267 runTest(0, true);
268}
269
270TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset1)
271{
272 runTest(1, true);
273}
274
275TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset2)
276{
277 runTest(2, true);
278}
279
280TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset3)
281{
282 runTest(3, true);
283}
284
285TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffsetChangingIndices)
286{
Frank Henigmandf55f252017-04-05 15:32:06 -0400287 // TODO(fjhenigman): Figure out why this fails on Ozone Intel.
288 if (IsOzone() && IsIntel() && IsOpenGLES())
289 {
290 std::cout << "Test skipped on Ozone Intel." << std::endl;
291 return;
292 }
293
Cooper Partin558f2b52015-06-02 09:34:11 -0700294 runTest(3, true);
295 runTest(1, true);
296 runTest(0, true);
297 runTest(2, true);
298}
299
Jamie Madillfa05f602015-05-07 13:47:11 -0400300typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500301
Jamie Madillfa05f602015-05-07 13:47:11 -0400302TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500303{
Martin Radev1be913c2016-07-11 17:59:16 +0300304 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500305 {
306 return;
307 }
308
309 runTest(0);
310}
311
Jamie Madillfa05f602015-05-07 13:47:11 -0400312TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500313{
Martin Radev1be913c2016-07-11 17:59:16 +0300314 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500315 {
316 return;
317 }
318
319 runTest(1);
320}
321
Jamie Madillfa05f602015-05-07 13:47:11 -0400322TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500323{
Martin Radev1be913c2016-07-11 17:59:16 +0300324 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500325 {
326 return;
327 }
328
329 runTest(2);
330}
331
Jamie Madillfa05f602015-05-07 13:47:11 -0400332TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500333{
Martin Radev1be913c2016-07-11 17:59:16 +0300334 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500335 {
336 return;
337 }
338
339 runTest(3);
340}
Jamie Madillfa05f602015-05-07 13:47:11 -0400341
Cooper Partin558f2b52015-06-02 09:34:11 -0700342TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset0)
343{
Martin Radev1be913c2016-07-11 17:59:16 +0300344 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700345 {
346 return;
347 }
348
349 runTest(0, false);
350}
351
352TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset1)
353{
Martin Radev1be913c2016-07-11 17:59:16 +0300354 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700355 {
356 return;
357 }
358
359 runTest(1, false);
360}
361
362TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset2)
363{
Martin Radev1be913c2016-07-11 17:59:16 +0300364 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700365 {
366 return;
367 }
368
369 runTest(2, false);
370}
371
372TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset3)
373{
Martin Radev1be913c2016-07-11 17:59:16 +0300374 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700375 {
376 return;
377 }
378
379 runTest(3, false);
380}
381
Geoff Langc4222072015-05-25 13:19:48 -0400382// TODO(geofflang): Figure out why this test fails on Intel OpenGL
Geoff Lange0cc2a42016-01-20 10:58:17 -0500383ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte,
384 ES2_D3D11(),
385 ES2_D3D11_FL9_3(),
386 ES2_OPENGL(),
387 ES2_OPENGLES());
388ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort,
389 ES2_D3D11(),
390 ES2_D3D11_FL9_3(),
391 ES2_OPENGL(),
392 ES2_OPENGLES());
393ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt,
394 ES2_D3D11(),
395 ES2_D3D11_FL9_3(),
396 ES2_OPENGL(),
397 ES2_OPENGLES());