blob: 91fe88bd2334ec9be3e1a097f6ec8b3a0295c554 [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"
Geoff Lang1f12fa02013-10-23 13:24:53 -04008
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
Jamie Madill231c7f52017-04-26 13:45:37 -040028 const std::string vsSource = SHADER_SOURCE(attribute highp vec4 position;
Geoff Lang1f12fa02013-10-23 13:24:53 -040029
Jamie Madill231c7f52017-04-26 13:45:37 -040030 void main(void) { gl_Position = position; });
Geoff Lang1f12fa02013-10-23 13:24:53 -040031
Jamie Madill231c7f52017-04-26 13:45:37 -040032 const std::string fsSource =
33 SHADER_SOURCE(uniform highp vec4 color; void main(void) { gl_FragColor = color; });
Geoff Lang1f12fa02013-10-23 13:24:53 -040034
Jamie Madill5599c8f2014-08-26 13:16:39 -040035 mProgram = CompileProgram(vsSource, fsSource);
Geoff Lang1f12fa02013-10-23 13:24:53 -040036 if (mProgram == 0)
37 {
38 FAIL() << "shader compilation failed.";
39 }
40
41 mPositionLocation = glGetAttribLocation(mProgram, "position");
Jamie Madill231c7f52017-04-26 13:45:37 -040042 mColorLocation = glGetUniformLocation(mProgram, "color");
Geoff Lang1f12fa02013-10-23 13:24:53 -040043
44 glBlendFunc(GL_ONE, GL_ONE);
45 glEnable(GL_BLEND);
Geoff Lang1f12fa02013-10-23 13:24:53 -040046 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Geoff Lang1f12fa02013-10-23 13:24:53 -040047
48 ASSERT_GL_NO_ERROR();
49 }
50
51 virtual void TearDown()
52 {
53 glDeleteProgram(mProgram);
54
55 ANGLETest::TearDown();
56 }
57
Jamie Madill876429b2017-04-20 15:46:24 -040058 void runTest(GLenum indexType, GLuint indexBuffer, const void *indexPtr)
Geoff Lang1f12fa02013-10-23 13:24:53 -040059 {
Corentin Wallez91f828e2015-07-13 11:08:19 -040060 glClear(GL_COLOR_BUFFER_BIT);
61
Jamie Madill231c7f52017-04-26 13:45:37 -040062 static const GLfloat loopPositions[] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
63 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, -0.5f,
64 -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f};
Geoff Lang1f12fa02013-10-23 13:24:53 -040065
Jamie Madill231c7f52017-04-26 13:45:37 -040066 static const GLfloat stripPositions[] = {-0.5f, -0.5f, -0.5f, 0.5f,
67 0.5f, 0.5f, 0.5f, -0.5f};
68 static const GLubyte stripIndices[] = {1, 0, 3, 2, 1};
Geoff Lang1f12fa02013-10-23 13:24:53 -040069
70 glUseProgram(mProgram);
71 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
72 glEnableVertexAttribArray(mPositionLocation);
73 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions);
74 glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f);
75 glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr);
76
77 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
78 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions);
79 glUniform4f(mColorLocation, 0, 1, 0, 1);
80 glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
81
82 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
Jamie Madill231c7f52017-04-26 13:45:37 -040083 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
84 &pixels[0]);
Geoff Lang1f12fa02013-10-23 13:24:53 -040085
Corentin Wallez91f828e2015-07-13 11:08:19 -040086 ASSERT_GL_NO_ERROR();
87
Geoff Lang1f12fa02013-10-23 13:24:53 -040088 for (int y = 0; y < getWindowHeight(); y++)
89 {
90 for (int x = 0; x < getWindowWidth(); x++)
91 {
Jamie Madill231c7f52017-04-26 13:45:37 -040092 const GLubyte *pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
Geoff Lang1f12fa02013-10-23 13:24:53 -040093
94 EXPECT_EQ(pixel[0], 0);
95 EXPECT_EQ(pixel[1], pixel[2]);
96 EXPECT_EQ(pixel[3], 255);
97 }
98 }
99 }
100
101 GLuint mProgram;
102 GLint mPositionLocation;
103 GLint mColorLocation;
104};
105
Jamie Madillfa05f602015-05-07 13:47:11 -0400106TEST_P(LineLoopTest, LineLoopUByteIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400107{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800108 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
109 // On Win7, the D3D SDK Layers emits a false warning for these tests.
110 // This doesn't occur on Windows 10 (Version 1511) though.
111 ignoreD3D11SDKLayersWarnings();
112
Jamie Madill231c7f52017-04-26 13:45:37 -0400113 static const GLubyte indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400114 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
115}
116
Jamie Madillfa05f602015-05-07 13:47:11 -0400117TEST_P(LineLoopTest, LineLoopUShortIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400118{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800119 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
120 ignoreD3D11SDKLayersWarnings();
121
Jamie Madill231c7f52017-04-26 13:45:37 -0400122 static const GLushort indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400123 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
124}
125
Jamie Madillfa05f602015-05-07 13:47:11 -0400126TEST_P(LineLoopTest, LineLoopUIntIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400127{
128 if (!extensionEnabled("GL_OES_element_index_uint"))
129 {
130 return;
131 }
132
Austin Kinrossd544cc92016-01-11 15:26:42 -0800133 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
134 ignoreD3D11SDKLayersWarnings();
135
Jamie Madill231c7f52017-04-26 13:45:37 -0400136 static const GLuint indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400137 runTest(GL_UNSIGNED_INT, 0, indices + 1);
138}
139
Jamie Madillfa05f602015-05-07 13:47:11 -0400140TEST_P(LineLoopTest, LineLoopUByteIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400141{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800142 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
143 ignoreD3D11SDKLayersWarnings();
144
Jamie Madill231c7f52017-04-26 13:45:37 -0400145 static const GLubyte indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400146
147 GLuint buf;
148 glGenBuffers(1, &buf);
149 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
150 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
151
152 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
153
154 glDeleteBuffers(1, &buf);
155}
156
Jamie Madillfa05f602015-05-07 13:47:11 -0400157TEST_P(LineLoopTest, LineLoopUShortIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400158{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800159 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
160 ignoreD3D11SDKLayersWarnings();
161
Jamie Madill231c7f52017-04-26 13:45:37 -0400162 static const GLushort indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400163
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_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
170
171 glDeleteBuffers(1, &buf);
172}
173
Jamie Madillfa05f602015-05-07 13:47:11 -0400174TEST_P(LineLoopTest, LineLoopUIntIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400175{
176 if (!extensionEnabled("GL_OES_element_index_uint"))
177 {
178 return;
179 }
180
Austin Kinrossd544cc92016-01-11 15:26:42 -0800181 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
182 ignoreD3D11SDKLayersWarnings();
183
Jamie Madill231c7f52017-04-26 13:45:37 -0400184 static const GLuint indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400185
186 GLuint buf;
187 glGenBuffers(1, &buf);
188 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
189 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
190
191 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
192
193 glDeleteBuffers(1, &buf);
194}
Jamie Madillfa05f602015-05-07 13:47:11 -0400195
Jamie Madill231c7f52017-04-26 13:45:37 -0400196// Use this to select which configurations (e.g. which renderer, which GLES major version) these
197// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500198ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());