blob: 631f6e81d214129f98585c919504fe37e39ef39f [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 Wallezac3ab882015-05-12 13:31:28 -04007#include "end2end_tests/ANGLETest.h"
Jamie Madillfa05f602015-05-07 13:47:11 -04008
Geoff Langf8c2f5c2013-12-05 13:52:33 -05009#include <array>
10
Jamie Madillfa05f602015-05-07 13:47:11 -040011using namespace angle;
12
13template <typename IndexType, GLenum IndexTypeName>
Geoff Langf8c2f5c2013-12-05 13:52:33 -050014class IndexedPointsTest : public ANGLETest
15{
Jamie Madillfa05f602015-05-07 13:47:11 -040016 protected:
17 IndexedPointsTest()
Geoff Langf8c2f5c2013-12-05 13:52:33 -050018 {
19 setWindowWidth(128);
20 setWindowHeight(128);
21 setConfigRedBits(8);
22 setConfigGreenBits(8);
23 setConfigBlueBits(8);
24 setConfigAlphaBits(8);
25 setConfigDepthBits(24);
26 }
27
28 float getIndexPositionX(size_t idx)
29 {
30 return (idx == 0 || idx == 3) ? -0.5f : 0.5f;
31 }
32
33 float getIndexPositionY(size_t idx)
34 {
35 return (idx == 2 || idx == 3) ? -0.5f : 0.5f;
36 }
37
38 virtual void SetUp()
39 {
40 ANGLETest::SetUp();
41
42 const std::string vertexShaderSource = SHADER_SOURCE
43 (
44 precision highp float;
45 attribute vec2 position;
46
47 void main()
48 {
49 gl_PointSize = 5.0;
50 gl_Position = vec4(position, 0.0, 1.0);
51 }
52 );
53
54 const std::string fragmentShaderSource = SHADER_SOURCE
55 (
56 precision highp float;
57
58 void main()
59 {
60 gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
61 }
62 );
63
Jamie Madill5599c8f2014-08-26 13:16:39 -040064 mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050065 if (mProgram == 0)
66 {
67 FAIL() << "shader compilation failed.";
68 }
69
70 std::array<GLfloat, mPointCount * 2> vertices =
71 {
72 getIndexPositionX(0), getIndexPositionY(0),
73 getIndexPositionX(1), getIndexPositionY(1),
74 getIndexPositionX(2), getIndexPositionY(2),
75 getIndexPositionX(3), getIndexPositionY(3),
76 };
77 glGenBuffers(1, &mVertexBuffer);
78 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
Jamie Madillb4fd0c92014-10-01 17:40:24 -040079 glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(GLfloat), &vertices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050080
81 std::array<IndexType, mPointCount> indices = { 0, 1, 2, 3 };
82 glGenBuffers(1, &mIndexBuffer);
83 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Jamie Madillb4fd0c92014-10-01 17:40:24 -040084 glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(IndexType), &indices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050085 }
86
87 virtual void TearDown()
88 {
89 glDeleteProgram(mProgram);
90
91 ANGLETest::TearDown();
92 }
93
94 void runTest(GLuint firstIndex)
95 {
96 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
97 glClear(GL_COLOR_BUFFER_BIT);
98
99 GLint viewportSize[4];
100 glGetIntegerv(GL_VIEWPORT, viewportSize);
101
102 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
103 GLint vertexLocation = glGetAttribLocation(mProgram, "position");
104 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
105 glEnableVertexAttribArray(vertexLocation);
106
107 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
108
109 glUseProgram(mProgram);
110
111 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
112
113 for (size_t i = 0; i < mPointCount; i++)
114 {
Minmin Gong794e0002015-04-07 18:31:54 -0700115 GLuint x = static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0]));
116 GLuint y = static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1]));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500117
118 if (i < firstIndex)
119 {
120 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
121 }
122 else
123 {
124 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
125 }
126 }
127 }
128
129 GLuint mProgram;
130 GLuint mVertexBuffer;
131 GLuint mIndexBuffer;
132 static const GLuint mPointCount = 4;
133};
134
Jamie Madillfa05f602015-05-07 13:47:11 -0400135typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500136
Jamie Madillfa05f602015-05-07 13:47:11 -0400137TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500138{
139 runTest(0);
140}
141
Jamie Madillfa05f602015-05-07 13:47:11 -0400142TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500143{
144 runTest(1);
145}
146
Jamie Madillfa05f602015-05-07 13:47:11 -0400147TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500148{
149 runTest(2);
150}
151
Jamie Madillfa05f602015-05-07 13:47:11 -0400152TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500153{
154 runTest(3);
155}
156
Jamie Madillfa05f602015-05-07 13:47:11 -0400157typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500158
Jamie Madillfa05f602015-05-07 13:47:11 -0400159TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500160{
161 runTest(0);
162}
163
Jamie Madillfa05f602015-05-07 13:47:11 -0400164TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500165{
166 runTest(1);
167}
168
Jamie Madillfa05f602015-05-07 13:47:11 -0400169TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500170{
171 runTest(2);
172}
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500175{
176 runTest(3);
177}
178
Jamie Madillfa05f602015-05-07 13:47:11 -0400179typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500180
Jamie Madillfa05f602015-05-07 13:47:11 -0400181TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500182{
183 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
184 {
185 return;
186 }
187
188 runTest(0);
189}
190
Jamie Madillfa05f602015-05-07 13:47:11 -0400191TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500192{
193 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
194 {
195 return;
196 }
197
198 runTest(1);
199}
200
Jamie Madillfa05f602015-05-07 13:47:11 -0400201TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500202{
203 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
204 {
205 return;
206 }
207
208 runTest(2);
209}
210
Jamie Madillfa05f602015-05-07 13:47:11 -0400211TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500212{
213 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
214 {
215 return;
216 }
217
218 runTest(3);
219}
Jamie Madillfa05f602015-05-07 13:47:11 -0400220
221ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte, ES2_D3D11());
222ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort, ES2_D3D11());
223ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt, ES2_D3D11());