blob: 059169d5185acc3f6b3b12f01ae5fd7002528910 [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
Geoff Lang1f12fa02013-10-23 13:24:53 -04007#include "ANGLETest.h"
8
Jamie Madillfa05f602015-05-07 13:47:11 -04009using namespace angle;
Austin Kinross18b931d2014-09-29 12:58:31 -070010
Geoff Lang1f12fa02013-10-23 13:24:53 -040011class LineLoopTest : public ANGLETest
12{
Jamie Madillfa05f602015-05-07 13:47:11 -040013 protected:
14 LineLoopTest()
Geoff Lang1f12fa02013-10-23 13:24:53 -040015 {
16 setWindowWidth(256);
17 setWindowHeight(256);
18 setConfigRedBits(8);
19 setConfigGreenBits(8);
20 setConfigBlueBits(8);
21 setConfigAlphaBits(8);
22 }
23
24 virtual void SetUp()
25 {
26 ANGLETest::SetUp();
27
28 const std::string vsSource = SHADER_SOURCE
29 (
30 attribute highp vec4 position;
31 attribute highp vec4 in_color;
32
33 varying highp vec4 color;
34
35 void main(void)
36 {
37 gl_Position = position;
38 color = in_color;
39 }
40 );
41
42 const std::string fsSource = SHADER_SOURCE
43 (
44 varying highp vec4 color;
45 void main(void)
46 {
47 gl_FragColor = color;
48 }
49 );
50
Jamie Madill5599c8f2014-08-26 13:16:39 -040051 mProgram = CompileProgram(vsSource, fsSource);
Geoff Lang1f12fa02013-10-23 13:24:53 -040052 if (mProgram == 0)
53 {
54 FAIL() << "shader compilation failed.";
55 }
56
57 mPositionLocation = glGetAttribLocation(mProgram, "position");
58 mColorLocation = glGetAttribLocation(mProgram, "in_color");
59
60 glBlendFunc(GL_ONE, GL_ONE);
61 glEnable(GL_BLEND);
62
63 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
64 glClear(GL_COLOR_BUFFER_BIT);
65
66 ASSERT_GL_NO_ERROR();
67 }
68
69 virtual void TearDown()
70 {
71 glDeleteProgram(mProgram);
72
73 ANGLETest::TearDown();
74 }
75
Minmin Gong794e0002015-04-07 18:31:54 -070076 void runTest(GLenum indexType, GLuint indexBuffer, const GLvoid *indexPtr)
Geoff Lang1f12fa02013-10-23 13:24:53 -040077 {
78 static const GLfloat loopPositions[] =
79 {
80 0.0f, 0.0f,
81 0.0f, 0.0f,
82 0.0f, 0.0f,
83 0.0f, 0.0f,
84 0.0f, 0.0f,
85 0.0f, 0.0f,
86 -0.5f, -0.5f,
87 -0.5f, 0.5f,
88 0.5f, 0.5f,
89 0.5f, -0.5f
90 };
91
92 static const GLfloat stripPositions[] =
93 {
94 -0.5f, -0.5f,
95 -0.5f, 0.5f,
96 0.5f, 0.5f,
97 0.5f, -0.5f
98 };
99 static const GLubyte stripIndices[] =
100 {
101 2, 0, 3, 1, 2
102 };
103
104 glUseProgram(mProgram);
105 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
106 glEnableVertexAttribArray(mPositionLocation);
107 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions);
108 glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f);
109 glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr);
110
111 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
112 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions);
113 glUniform4f(mColorLocation, 0, 1, 0, 1);
114 glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
115
116 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400117 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]);
Geoff Lang1f12fa02013-10-23 13:24:53 -0400118
119 for (int y = 0; y < getWindowHeight(); y++)
120 {
121 for (int x = 0; x < getWindowWidth(); x++)
122 {
Jamie Madillb4fd0c92014-10-01 17:40:24 -0400123 const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
Geoff Lang1f12fa02013-10-23 13:24:53 -0400124
125 EXPECT_EQ(pixel[0], 0);
126 EXPECT_EQ(pixel[1], pixel[2]);
127 EXPECT_EQ(pixel[3], 255);
128 }
129 }
130 }
131
132 GLuint mProgram;
133 GLint mPositionLocation;
134 GLint mColorLocation;
135};
136
Jamie Madillfa05f602015-05-07 13:47:11 -0400137TEST_P(LineLoopTest, LineLoopUByteIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400138{
139 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
140 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
141}
142
Jamie Madillfa05f602015-05-07 13:47:11 -0400143TEST_P(LineLoopTest, LineLoopUShortIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400144{
145 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
146 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
147}
148
Jamie Madillfa05f602015-05-07 13:47:11 -0400149TEST_P(LineLoopTest, LineLoopUIntIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400150{
151 if (!extensionEnabled("GL_OES_element_index_uint"))
152 {
153 return;
154 }
155
156 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
157 runTest(GL_UNSIGNED_INT, 0, indices + 1);
158}
159
Jamie Madillfa05f602015-05-07 13:47:11 -0400160TEST_P(LineLoopTest, LineLoopUByteIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400161{
162 static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 };
163
164 GLuint buf;
165 glGenBuffers(1, &buf);
166 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
167 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
168
169 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
170
171 glDeleteBuffers(1, &buf);
172}
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174TEST_P(LineLoopTest, LineLoopUShortIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400175{
176 static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 };
177
178 GLuint buf;
179 glGenBuffers(1, &buf);
180 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
181 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
182
183 runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
184
185 glDeleteBuffers(1, &buf);
186}
187
Jamie Madillfa05f602015-05-07 13:47:11 -0400188TEST_P(LineLoopTest, LineLoopUIntIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400189{
190 if (!extensionEnabled("GL_OES_element_index_uint"))
191 {
192 return;
193 }
194
195 static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 };
196
197 GLuint buf;
198 glGenBuffers(1, &buf);
199 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
200 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
201
202 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
203
204 glDeleteBuffers(1, &buf);
205}
Jamie Madillfa05f602015-05-07 13:47:11 -0400206
207// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
208ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11());