blob: 190d965f555a6bcc7eca9d0366ff6c91df333f89 [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);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050063 if (mProgram == 0)
64 {
65 FAIL() << "shader compilation failed.";
66 }
67
Corentin Wallez91c2fad2015-05-15 10:34:14 -040068 const GLfloat vertices[] =
Geoff Langf8c2f5c2013-12-05 13:52:33 -050069 {
70 getIndexPositionX(0), getIndexPositionY(0),
71 getIndexPositionX(1), getIndexPositionY(1),
72 getIndexPositionX(2), getIndexPositionY(2),
73 getIndexPositionX(3), getIndexPositionY(3),
74 };
75 glGenBuffers(1, &mVertexBuffer);
76 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -040077 glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050078
Corentin Wallez91c2fad2015-05-15 10:34:14 -040079 const IndexType indices[] = { 0, 1, 2, 3 };
Geoff Langf8c2f5c2013-12-05 13:52:33 -050080 glGenBuffers(1, &mIndexBuffer);
81 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
Corentin Wallez91c2fad2015-05-15 10:34:14 -040082 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW);
Geoff Langf8c2f5c2013-12-05 13:52:33 -050083 }
84
85 virtual void TearDown()
86 {
87 glDeleteProgram(mProgram);
88
89 ANGLETest::TearDown();
90 }
91
92 void runTest(GLuint firstIndex)
93 {
94 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
95 glClear(GL_COLOR_BUFFER_BIT);
96
97 GLint viewportSize[4];
98 glGetIntegerv(GL_VIEWPORT, viewportSize);
99
100 glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer);
101 GLint vertexLocation = glGetAttribLocation(mProgram, "position");
102 glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0);
103 glEnableVertexAttribArray(vertexLocation);
104
105 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer);
106
107 glUseProgram(mProgram);
108
109 glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType)));
110
111 for (size_t i = 0; i < mPointCount; i++)
112 {
Minmin Gong794e0002015-04-07 18:31:54 -0700113 GLuint x = static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0]));
114 GLuint y = static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1]));
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500115
116 if (i < firstIndex)
117 {
118 EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255);
119 }
120 else
121 {
122 EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255);
123 }
124 }
125 }
126
127 GLuint mProgram;
128 GLuint mVertexBuffer;
129 GLuint mIndexBuffer;
130 static const GLuint mPointCount = 4;
131};
132
Jamie Madillfa05f602015-05-07 13:47:11 -0400133typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500134
Jamie Madillfa05f602015-05-07 13:47:11 -0400135TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500136{
137 runTest(0);
138}
139
Jamie Madillfa05f602015-05-07 13:47:11 -0400140TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500141{
142 runTest(1);
143}
144
Jamie Madillfa05f602015-05-07 13:47:11 -0400145TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500146{
147 runTest(2);
148}
149
Jamie Madillfa05f602015-05-07 13:47:11 -0400150TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500151{
152 runTest(3);
153}
154
Jamie Madillfa05f602015-05-07 13:47:11 -0400155typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500156
Jamie Madillfa05f602015-05-07 13:47:11 -0400157TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500158{
159 runTest(0);
160}
161
Jamie Madillfa05f602015-05-07 13:47:11 -0400162TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500163{
164 runTest(1);
165}
166
Jamie Madillfa05f602015-05-07 13:47:11 -0400167TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500168{
169 runTest(2);
170}
171
Jamie Madillfa05f602015-05-07 13:47:11 -0400172TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500173{
174 runTest(3);
175}
176
Jamie Madillfa05f602015-05-07 13:47:11 -0400177typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt;
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500178
Jamie Madillfa05f602015-05-07 13:47:11 -0400179TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500180{
181 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
182 {
183 return;
184 }
185
186 runTest(0);
187}
188
Jamie Madillfa05f602015-05-07 13:47:11 -0400189TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500190{
191 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
192 {
193 return;
194 }
195
196 runTest(1);
197}
198
Jamie Madillfa05f602015-05-07 13:47:11 -0400199TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500200{
201 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
202 {
203 return;
204 }
205
206 runTest(2);
207}
208
Jamie Madillfa05f602015-05-07 13:47:11 -0400209TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3)
Geoff Langf8c2f5c2013-12-05 13:52:33 -0500210{
211 if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint"))
212 {
213 return;
214 }
215
216 runTest(3);
217}
Jamie Madillfa05f602015-05-07 13:47:11 -0400218
Geoff Langc4222072015-05-25 13:19:48 -0400219// TODO(geofflang): Figure out why this test fails on Intel OpenGL
220ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte, ES2_D3D11());
221ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort, ES2_D3D11());
222ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt, ES2_D3D11());