3 // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
4 typedef ::testing::Types<TFT<Gles::Two, Rend::D3D11>, TFT<Gles::Two, Rend::D3D9>> TestFixtureTypes;
5 TYPED_TEST_CASE(LineLoopTest, TestFixtureTypes);
8 class LineLoopTest : public ANGLETest
11 LineLoopTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetRequestedRenderer())
16 setConfigGreenBits(8);
18 setConfigAlphaBits(8);
25 const std::string vsSource = SHADER_SOURCE
27 attribute highp vec4 position;
28 attribute highp vec4 in_color;
30 varying highp vec4 color;
34 gl_Position = position;
39 const std::string fsSource = SHADER_SOURCE
41 varying highp vec4 color;
48 mProgram = CompileProgram(vsSource, fsSource);
51 FAIL() << "shader compilation failed.";
54 mPositionLocation = glGetAttribLocation(mProgram, "position");
55 mColorLocation = glGetAttribLocation(mProgram, "in_color");
57 glBlendFunc(GL_ONE, GL_ONE);
60 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
61 glClear(GL_COLOR_BUFFER_BIT);
66 virtual void TearDown()
68 glDeleteProgram(mProgram);
70 ANGLETest::TearDown();
73 void runTest(GLenum indexType, GLubyte indexBuffer, const GLvoid *indexPtr)
75 static const GLfloat loopPositions[] =
89 static const GLfloat stripPositions[] =
96 static const GLubyte stripIndices[] =
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);
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);
113 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
114 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
116 for (int y = 0; y < getWindowHeight(); y++)
118 for (int x = 0; x < getWindowWidth(); x++)
120 const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
122 EXPECT_EQ(pixel[0], 0);
123 EXPECT_EQ(pixel[1], pixel[2]);
124 EXPECT_EQ(pixel[3], 255);
130 GLint mPositionLocation;
131 GLint mColorLocation;
134 TYPED_TEST(LineLoopTest, LineLoopUByteIndices)
136 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
137 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
140 TYPED_TEST(LineLoopTest, LineLoopUShortIndices)
142 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
143 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
146 TYPED_TEST(LineLoopTest, LineLoopUIntIndices)
148 if (!extensionEnabled("GL_OES_element_index_uint"))
153 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
154 runTest(GL_UNSIGNED_INT, 0, indices + 1);
157 TYPED_TEST(LineLoopTest, LineLoopUByteIndexBuffer)
159 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
162 glGenBuffers(1, &buf);
163 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
164 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
166 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
168 glDeleteBuffers(1, &buf);
171 TYPED_TEST(LineLoopTest, LineLoopUShortIndexBuffer)
173 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
176 glGenBuffers(1, &buf);
177 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
178 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
180 runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
182 glDeleteBuffers(1, &buf);
185 TYPED_TEST(LineLoopTest, LineLoopUIntIndexBuffer)
187 if (!extensionEnabled("GL_OES_element_index_uint"))
192 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
195 glGenBuffers(1, &buf);
196 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
197 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
199 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
201 glDeleteBuffers(1, &buf);