blob: c3779efea0e7f92ec06145daad6dcf9d576bd09e [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
26 float getIndexPositionX(size_t idx)
27 {
28 return (idx == 0 || idx == 3) ? -0.5f : 0.5f;
29 }
30
31 float getIndexPositionY(size_t idx)
32 {
33 return (idx == 2 || idx == 3) ? -0.5f : 0.5f;
34 }
35
36 virtual void SetUp()
37 {
38 ANGLETest::SetUp();
39
40 const std::string vertexShaderSource = SHADER_SOURCE
41 (
42 precision highp float;
43 attribute vec2 position;
44
45 void main()
46 {
47 gl_PointSize = 5.0;
48 gl_Position = vec4(position, 0.0, 1.0);
49 }
50 );
51
52 const std::string fragmentShaderSource = SHADER_SOURCE
53 (
54 precision highp float;
55
56 void main()
57 {
58 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
59 }
60 );
61
Jamie Madill5599c8f2014-08-26 13:16:39 -040062 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Cooper Partin558f2b52015-06-02 09:34:11 -070063 ASSERT_NE(0u, mProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050064
Cooper Partin558f2b52015-06-02 09:34:11 -070065 const std::string vertexShaderSource2 = SHADER_SOURCE
66 (
67 precision highp float;
68 attribute vec2 position;
69 attribute vec4 color;
70 varying vec4 vcolor;
71
72 void main()
73 {
74 gl_PointSize = 5.0;
75 gl_Position = vec4(position, 0.0, 1.0);
76 vcolor = color;
77 }
78 );
79
80 const std::string fragmentShaderSource2 = SHADER_SOURCE
81 (
82 precision highp float;
83 varying vec4 vcolor;
84 void main()
85 {
86 gl_FragColor = vec4(vcolor.xyz, 1.0);
87 }
88 );
89
90 mVertexWithColorBufferProgram = CompileProgram(vertexShaderSource2, fragmentShaderSource2);
91 ASSERT_NE(0u, mVertexWithColorBufferProgram);
92
93 // Construct a vertex buffer of position values and color values
94 // contained in a single structure
95 const float verticesWithColor[] =
96 {
97 getIndexPositionX(0), getIndexPositionY(0), 0.0f, 1.0f, 0.0f,
98 getIndexPositionX(2), getIndexPositionY(2), 0.0f, 1.0f, 0.0f,
99 getIndexPositionX(1), getIndexPositionY(1), 0.0f, 1.0f, 0.0f,
100 getIndexPositionX(3), getIndexPositionY(3), 0.0f, 1.0f, 0.0f,
101 };
102
103 glGenBuffers(1, &mVertexWithColorBuffer);
104 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
105 glBufferData(GL_ARRAY_BUFFER, sizeof(verticesWithColor), &verticesWithColor[0], GL_STATIC_DRAW);
106
107 // Construct a vertex buffer of position values only
Corentin Wallez91c2fad2015-05-15 10:34:14 -0400108 const GLfloat vertices[] =
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500109 {
110 getIndexPositionX(0), getIndexPositionY(0),
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500111 getIndexPositionX(2), getIndexPositionY(2),
Cooper Partin558f2b52015-06-02 09:34:11 -0700112 getIndexPositionX(1), getIndexPositionY(1),
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500113 getIndexPositionX(3), getIndexPositionY(3),
114 };
115 glGenBuffers(1, &mVertexBuffer);
116 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -0400117 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500118
Cooper Partin558f2b52015-06-02 09:34:11 -0700119 // The indices buffer is shared between both variations of tests
120 const IndexType indices[] = { 0, 2, 1, 3 };
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500121 glGenBuffers(1, &mIndexBuffer);
122 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -0400123 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500124 }
125
126 virtual void TearDown()
127 {
Cooper Partin558f2b52015-06-02 09:34:11 -0700128 glDeleteBuffers(1, &mVertexBuffer);
129 glDeleteBuffers(1, &mIndexBuffer);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500130 glDeleteProgram(mProgram);
131
Cooper Partin558f2b52015-06-02 09:34:11 -0700132 glDeleteBuffers(1, &mVertexWithColorBuffer);
133 glDeleteProgram(mVertexWithColorBufferProgram);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500134 ANGLETest::TearDown();
135 }
136
Cooper Partin558f2b52015-06-02 09:34:11 -0700137 void runTest(GLuint firstIndex, bool useVertexBufferWithColor = false)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500138 {
139 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
140 glClear(GL_COLOR_BUFFER_BIT);
141
142 GLint viewportSize[4];
143 glGetIntegerv(GL_VIEWPORT, viewportSize);
144
Cooper Partin558f2b52015-06-02 09:34:11 -0700145 // Choose appropriate program to apply for the test
146 GLuint program = useVertexBufferWithColor ? mVertexWithColorBufferProgram : mProgram;
147
148 if (useVertexBufferWithColor)
149 {
150 glBindBuffer(GL_ARRAY_BUFFER, mVertexWithColorBuffer);
151 GLint vertexLocation = glGetAttribLocation(program, "position");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700152 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE,
153 static_cast<const GLsizei>(VertexWithColorSize), 0);
Cooper Partin558f2b52015-06-02 09:34:11 -0700154 glEnableVertexAttribArray(vertexLocation);
155
156 GLint vertexColorLocation = glGetAttribLocation(program, "color");
Cooper Partin4d61f7e2015-08-12 10:56:50 -0700157 glVertexAttribPointer(vertexColorLocation, 3, GL_FLOAT, GL_FALSE,
158 static_cast<const GLsizei>(VertexWithColorSize),
159 (GLvoid *)((sizeof(float) * 2)));
Cooper Partin558f2b52015-06-02 09:34:11 -0700160 glEnableVertexAttribArray(vertexColorLocation);
161 }
162 else
163 {
164 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
165 GLint vertexLocation = glGetAttribLocation(program, "position");
166 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
167 glEnableVertexAttribArray(vertexLocation);
168 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500169
170 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Cooper Partin558f2b52015-06-02 09:34:11 -0700171 glUseProgram(program);
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500172
173 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
174
175 for (size_t i = 0; i < mPointCount; i++)
176 {
Minmin Gong794e0002015-04-07 18:31:54 -0700177 GLuint x = static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0]));
178 GLuint y = static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1]));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500179
180 if (i < firstIndex)
181 {
182 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
183 }
184 else
185 {
Cooper Partin558f2b52015-06-02 09:34:11 -0700186 if (useVertexBufferWithColor)
187 {
188 // Pixel data is assumed to be GREEN
189 EXPECT_PIXEL_EQ(x, y, 0, 255, 0, 255);
190 }
191 else
192 {
193 // Pixel data is assumed to be RED
194 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
195 }
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500196 }
197 }
Cooper Partin558f2b52015-06-02 09:34:11 -0700198 swapBuffers();
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500199 }
200
201 GLuint mProgram;
202 GLuint mVertexBuffer;
203 GLuint mIndexBuffer;
Cooper Partin558f2b52015-06-02 09:34:11 -0700204
205 GLuint mVertexWithColorBufferProgram;
206 GLuint mVertexWithColorBuffer;
207
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500208 static const GLuint mPointCount = 4;
Cooper Partin558f2b52015-06-02 09:34:11 -0700209
210 private:
211 const size_t VertexWithColorSize = sizeof(float) * 5;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500212};
213
Jamie Madillfa05f602015-05-07 13:47:11 -0400214typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500215
Jamie Madillfa05f602015-05-07 13:47:11 -0400216TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500217{
218 runTest(0);
219}
220
Jamie Madillfa05f602015-05-07 13:47:11 -0400221TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500222{
223 runTest(1);
224}
225
Jamie Madillfa05f602015-05-07 13:47:11 -0400226TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500227{
228 runTest(2);
229}
230
Jamie Madillfa05f602015-05-07 13:47:11 -0400231TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500232{
233 runTest(3);
234}
235
Cooper Partin558f2b52015-06-02 09:34:11 -0700236TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset0)
237{
238 runTest(0, true);
239}
240
241TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset1)
242{
243 runTest(1, true);
244}
245
246TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset2)
247{
248 runTest(2, true);
249}
250
251TEST_P(IndexedPointsTestUByte, VertexWithColorUnsignedByteOffset3)
252{
253 runTest(3, true);
254}
255
Jamie Madillfa05f602015-05-07 13:47:11 -0400256typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500257
Jamie Madillfa05f602015-05-07 13:47:11 -0400258TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500259{
260 runTest(0);
261}
262
Jamie Madillfa05f602015-05-07 13:47:11 -0400263TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500264{
265 runTest(1);
266}
267
Jamie Madillfa05f602015-05-07 13:47:11 -0400268TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500269{
270 runTest(2);
271}
272
Jamie Madillfa05f602015-05-07 13:47:11 -0400273TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500274{
275 runTest(3);
276}
277
Cooper Partin558f2b52015-06-02 09:34:11 -0700278TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset0)
279{
280 runTest(0, true);
281}
282
283TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset1)
284{
285 runTest(1, true);
286}
287
288TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset2)
289{
290 runTest(2, true);
291}
292
293TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffset3)
294{
295 runTest(3, true);
296}
297
298TEST_P(IndexedPointsTestUShort, VertexWithColorUnsignedShortOffsetChangingIndices)
299{
Frank Henigmandf55f252017-04-05 15:32:06 -0400300 // TODO(fjhenigman): Figure out why this fails on Ozone Intel.
301 if (IsOzone() && IsIntel() && IsOpenGLES())
302 {
303 std::cout << "Test skipped on Ozone Intel." << std::endl;
304 return;
305 }
306
Cooper Partin558f2b52015-06-02 09:34:11 -0700307 runTest(3, true);
308 runTest(1, true);
309 runTest(0, true);
310 runTest(2, true);
311}
312
Jamie Madillfa05f602015-05-07 13:47:11 -0400313typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500314
Jamie Madillfa05f602015-05-07 13:47:11 -0400315TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500316{
Martin Radev1be913c2016-07-11 17:59:16 +0300317 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500318 {
319 return;
320 }
321
322 runTest(0);
323}
324
Jamie Madillfa05f602015-05-07 13:47:11 -0400325TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500326{
Martin Radev1be913c2016-07-11 17:59:16 +0300327 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500328 {
329 return;
330 }
331
332 runTest(1);
333}
334
Jamie Madillfa05f602015-05-07 13:47:11 -0400335TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500336{
Martin Radev1be913c2016-07-11 17:59:16 +0300337 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500338 {
339 return;
340 }
341
342 runTest(2);
343}
344
Jamie Madillfa05f602015-05-07 13:47:11 -0400345TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500346{
Martin Radev1be913c2016-07-11 17:59:16 +0300347 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500348 {
349 return;
350 }
351
352 runTest(3);
353}
Jamie Madillfa05f602015-05-07 13:47:11 -0400354
Cooper Partin558f2b52015-06-02 09:34:11 -0700355TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset0)
356{
Martin Radev1be913c2016-07-11 17:59:16 +0300357 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700358 {
359 return;
360 }
361
362 runTest(0, false);
363}
364
365TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset1)
366{
Martin Radev1be913c2016-07-11 17:59:16 +0300367 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700368 {
369 return;
370 }
371
372 runTest(1, false);
373}
374
375TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset2)
376{
Martin Radev1be913c2016-07-11 17:59:16 +0300377 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700378 {
379 return;
380 }
381
382 runTest(2, false);
383}
384
385TEST_P(IndexedPointsTestUInt, VertexWithColorUnsignedIntOffset3)
386{
Martin Radev1be913c2016-07-11 17:59:16 +0300387 if (getClientMajorVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
Cooper Partin558f2b52015-06-02 09:34:11 -0700388 {
389 return;
390 }
391
392 runTest(3, false);
393}
394
Geoff Langc4222072015-05-25 13:19:48 -0400395// TODO(geofflang): Figure out why this test fails on Intel OpenGL
Geoff Lange0cc2a42016-01-20 10:58:17 -0500396ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte,
397 ES2_D3D11(),
398 ES2_D3D11_FL9_3(),
399 ES2_OPENGL(),
400 ES2_OPENGLES());
401ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort,
402 ES2_D3D11(),
403 ES2_D3D11_FL9_3(),
404 ES2_OPENGL(),
405 ES2_OPENGLES());
406ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt,
407 ES2_D3D11(),
408 ES2_D3D11_FL9_3(),
409 ES2_OPENGL(),
410 ES2_OPENGLES());