3 class LineLoopTest : public ANGLETest
11 setConfigGreenBits(8);
13 setConfigAlphaBits(8);
20 const std::string vsSource = SHADER_SOURCE
22 attribute highp vec4 position;
23 attribute highp vec4 in_color;
25 varying highp vec4 color;
29 gl_Position = position;
34 const std::string fsSource = SHADER_SOURCE
36 varying highp vec4 color;
43 mProgram = CompileProgram(vsSource, fsSource);
46 FAIL() << "shader compilation failed.";
49 mPositionLocation = glGetAttribLocation(mProgram, "position");
50 mColorLocation = glGetAttribLocation(mProgram, "in_color");
52 glBlendFunc(GL_ONE, GL_ONE);
55 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
56 glClear(GL_COLOR_BUFFER_BIT);
61 virtual void TearDown()
63 glDeleteProgram(mProgram);
65 ANGLETest::TearDown();
68 void runTest(GLenum indexType, GLubyte indexBuffer, const GLvoid *indexPtr)
70 static const GLfloat loopPositions[] =
84 static const GLfloat stripPositions[] =
91 static const GLubyte stripIndices[] =
96 glUseProgram(mProgram);
97 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
98 glEnableVertexAttribArray(mPositionLocation);
99 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions);
100 glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f);
101 glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr);
103 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
104 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions);
105 glUniform4f(mColorLocation, 0, 1, 0, 1);
106 glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
108 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
109 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, pixels.data());
111 for (int y = 0; y < getWindowHeight(); y++)
113 for (int x = 0; x < getWindowWidth(); x++)
115 const GLubyte* pixel = pixels.data() + ((y * getWindowWidth() + x) * 4);
117 EXPECT_EQ(pixel[0], 0);
118 EXPECT_EQ(pixel[1], pixel[2]);
119 EXPECT_EQ(pixel[3], 255);
125 GLint mPositionLocation;
126 GLint mColorLocation;
129 TEST_F(LineLoopTest, LineLoopUByteIndices)
131 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
132 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
135 TEST_F(LineLoopTest, LineLoopUShortIndices)
137 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
138 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
141 TEST_F(LineLoopTest, LineLoopUIntIndices)
143 if (!extensionEnabled("GL_OES_element_index_uint"))
148 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
149 runTest(GL_UNSIGNED_INT, 0, indices + 1);
152 TEST_F(LineLoopTest, LineLoopUByteIndexBuffer)
154 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
157 glGenBuffers(1, &buf);
158 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
159 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
161 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
163 glDeleteBuffers(1, &buf);
166 TEST_F(LineLoopTest, LineLoopUShortIndexBuffer)
168 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
171 glGenBuffers(1, &buf);
172 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
173 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
175 runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
177 glDeleteBuffers(1, &buf);
180 TEST_F(LineLoopTest, LineLoopUIntIndexBuffer)
182 if (!extensionEnabled("GL_OES_element_index_uint"))
187 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
190 glGenBuffers(1, &buf);
191 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
192 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
194 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
196 glDeleteBuffers(1, &buf);