blob: f827e3a1787f3d41e34060d584385e30b7587538 [file] [log] [blame]
Geoff Lang1f12fa02013-10-23 13:24:53 -04001#include "ANGLETest.h"
2
Austin Kinross18b931d2014-09-29 12:58:31 -07003// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5TYPED_TEST_CASE(LineLoopTest, TestFixtureTypes);
6
7template<typename T>
Geoff Lang1f12fa02013-10-23 13:24:53 -04008class LineLoopTest : public ANGLETest
9{
10protected:
Austin Kinross18b931d2014-09-29 12:58:31 -070011 LineLoopTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
Geoff Lang1f12fa02013-10-23 13:24:53 -040012 {
13 setWindowWidth(256);
14 setWindowHeight(256);
15 setConfigRedBits(8);
16 setConfigGreenBits(8);
17 setConfigBlueBits(8);
18 setConfigAlphaBits(8);
19 }
20
21 virtual void SetUp()
22 {
23 ANGLETest::SetUp();
24
25 const std::string vsSource = SHADER_SOURCE
26 (
27 attribute highp vec4 position;
28 attribute highp vec4 in_color;
29
30 varying highp vec4 color;
31
32 void main(void)
33 {
34 gl_Position = position;
35 color = in_color;
36 }
37 );
38
39 const std::string fsSource = SHADER_SOURCE
40 (
41 varying highp vec4 color;
42 void main(void)
43 {
44 gl_FragColor = color;
45 }
46 );
47
Jamie Madill5599c8f2014-08-26 13:16:39 -040048 mProgram = CompileProgram(vsSource, fsSource);
Geoff Lang1f12fa02013-10-23 13:24:53 -040049 if (mProgram == 0)
50 {
51 FAIL() << "shader compilation failed.";
52 }
53
54 mPositionLocation = glGetAttribLocation(mProgram, "position");
55 mColorLocation = glGetAttribLocation(mProgram, "in_color");
56
57 glBlendFunc(GL_ONE, GL_ONE);
58 glEnable(GL_BLEND);
59
60 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
61 glClear(GL_COLOR_BUFFER_BIT);
62
63 ASSERT_GL_NO_ERROR();
64 }
65
66 virtual void TearDown()
67 {
68 glDeleteProgram(mProgram);
69
70 ANGLETest::TearDown();
71 }
72
73 void runTest(GLenum indexType, GLubyte indexBuffer, const GLvoid *indexPtr)
74 {
75 static const GLfloat loopPositions[] =
76 {
77 0.0f, 0.0f,
78 0.0f, 0.0f,
79 0.0f, 0.0f,
80 0.0f, 0.0f,
81 0.0f, 0.0f,
82 0.0f, 0.0f,
83 -0.5f, -0.5f,
84 -0.5f, 0.5f,
85 0.5f, 0.5f,
86 0.5f, -0.5f
87 };
88
89 static const GLfloat stripPositions[] =
90 {
91 -0.5f, -0.5f,
92 -0.5f, 0.5f,
93 0.5f, 0.5f,
94 0.5f, -0.5f
95 };
96 static const GLubyte stripIndices[] =
97 {
98 2, 0, 3, 1, 2
99 };
100
101 glUseProgram(mProgram);
102 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
103 glEnableVertexAttribArray(mPositionLocation);
104 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions);
105 glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f);
106 glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr);
107
108 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
109 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions);
110 glUniform4f(mColorLocation, 0, 1, 0, 1);
111 glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
112
113 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400114 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
Geoff Lang1f12fa02013-10-23 13:24:53 -0400115
116 for (int y = 0; y < getWindowHeight(); y++)
117 {
118 for (int x = 0; x < getWindowWidth(); x++)
119 {
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400120 const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
Geoff Lang1f12fa02013-10-23 13:24:53 -0400121
122 EXPECT_EQ(pixel[0], 0);
123 EXPECT_EQ(pixel[1], pixel[2]);
124 EXPECT_EQ(pixel[3], 255);
125 }
126 }
127 }
128
129 GLuint mProgram;
130 GLint mPositionLocation;
131 GLint mColorLocation;
132};
133
Austin Kinross18b931d2014-09-29 12:58:31 -0700134TYPED_TEST(LineLoopTest, LineLoopUByteIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400135{
136 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
137 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
138}
139
Austin Kinross18b931d2014-09-29 12:58:31 -0700140TYPED_TEST(LineLoopTest, LineLoopUShortIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400141{
142 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
143 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
144}
145
Austin Kinross18b931d2014-09-29 12:58:31 -0700146TYPED_TEST(LineLoopTest, LineLoopUIntIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400147{
148 if (!extensionEnabled("GL_OES_element_index_uint"))
149 {
150 return;
151 }
152
153 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
154 runTest(GL_UNSIGNED_INT, 0, indices + 1);
155}
156
Austin Kinross18b931d2014-09-29 12:58:31 -0700157TYPED_TEST(LineLoopTest, LineLoopUByteIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400158{
159 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
160
161 GLuint buf;
162 glGenBuffers(1, &buf);
163 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
164 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
165
166 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
167
168 glDeleteBuffers(1, &buf);
169}
170
Austin Kinross18b931d2014-09-29 12:58:31 -0700171TYPED_TEST(LineLoopTest, LineLoopUShortIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400172{
173 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
174
175 GLuint buf;
176 glGenBuffers(1, &buf);
177 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
178 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
179
180 runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
181
182 glDeleteBuffers(1, &buf);
183}
184
Austin Kinross18b931d2014-09-29 12:58:31 -0700185TYPED_TEST(LineLoopTest, LineLoopUIntIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400186{
187 if (!extensionEnabled("GL_OES_element_index_uint"))
188 {
189 return;
190 }
191
192 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
193
194 GLuint buf;
195 glGenBuffers(1, &buf);
196 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
197 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
198
199 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
200
201 glDeleteBuffers(1, &buf);
202}