blob: 4566a37d2049701f38bd102c7d53896b73bb5e3d [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
Olli Etuahoa20af6d2017-09-18 13:32:29 +030028 const std::string vsSource =
29 R"(attribute highp vec4 position;
30 void main(void)
31 {
32 gl_Position = position;
33 })";
Geoff Lang1f12fa02013-10-23 13:24:53 -040034
Jamie Madill231c7f52017-04-26 13:45:37 -040035 const std::string fsSource =
Olli Etuahoa20af6d2017-09-18 13:32:29 +030036 R"(uniform highp vec4 color;
37 void main(void)
38 {
39 gl_FragColor = color;
40 })";
Geoff Lang1f12fa02013-10-23 13:24:53 -040041
Jamie Madill5599c8f2014-08-26 13:16:39 -040042 mProgram = CompileProgram(vsSource, fsSource);
Geoff Lang1f12fa02013-10-23 13:24:53 -040043 if (mProgram == 0)
44 {
45 FAIL() << "shader compilation failed.";
46 }
47
48 mPositionLocation = glGetAttribLocation(mProgram, "position");
Jamie Madill231c7f52017-04-26 13:45:37 -040049 mColorLocation = glGetUniformLocation(mProgram, "color");
Geoff Lang1f12fa02013-10-23 13:24:53 -040050
51 glBlendFunc(GL_ONE, GL_ONE);
52 glEnable(GL_BLEND);
Geoff Lang1f12fa02013-10-23 13:24:53 -040053 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Geoff Lang1f12fa02013-10-23 13:24:53 -040054
55 ASSERT_GL_NO_ERROR();
56 }
57
58 virtual void TearDown()
59 {
60 glDeleteProgram(mProgram);
61
62 ANGLETest::TearDown();
63 }
64
Jamie Madill876429b2017-04-20 15:46:24 -040065 void runTest(GLenum indexType, GLuint indexBuffer, const void *indexPtr)
Geoff Lang1f12fa02013-10-23 13:24:53 -040066 {
Corentin Wallez91f828e2015-07-13 11:08:19 -040067 glClear(GL_COLOR_BUFFER_BIT);
68
Jamie Madill231c7f52017-04-26 13:45:37 -040069 static const GLfloat loopPositions[] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,
70 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -0.5f, -0.5f,
71 -0.5f, 0.5f, 0.5f, 0.5f, 0.5f, -0.5f};
Geoff Lang1f12fa02013-10-23 13:24:53 -040072
Jamie Madill231c7f52017-04-26 13:45:37 -040073 static const GLfloat stripPositions[] = {-0.5f, -0.5f, -0.5f, 0.5f,
74 0.5f, 0.5f, 0.5f, -0.5f};
75 static const GLubyte stripIndices[] = {1, 0, 3, 2, 1};
Geoff Lang1f12fa02013-10-23 13:24:53 -040076
77 glUseProgram(mProgram);
78 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer);
79 glEnableVertexAttribArray(mPositionLocation);
80 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions);
81 glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f);
82 glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr);
83
84 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
85 glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions);
86 glUniform4f(mColorLocation, 0, 1, 0, 1);
87 glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices);
88
89 std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4);
Jamie Madill231c7f52017-04-26 13:45:37 -040090 glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE,
91 &pixels[0]);
Geoff Lang1f12fa02013-10-23 13:24:53 -040092
Corentin Wallez91f828e2015-07-13 11:08:19 -040093 ASSERT_GL_NO_ERROR();
94
Geoff Lang1f12fa02013-10-23 13:24:53 -040095 for (int y = 0; y < getWindowHeight(); y++)
96 {
97 for (int x = 0; x < getWindowWidth(); x++)
98 {
Jamie Madill231c7f52017-04-26 13:45:37 -040099 const GLubyte *pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4);
Geoff Lang1f12fa02013-10-23 13:24:53 -0400100
101 EXPECT_EQ(pixel[0], 0);
102 EXPECT_EQ(pixel[1], pixel[2]);
103 EXPECT_EQ(pixel[3], 255);
104 }
105 }
106 }
107
108 GLuint mProgram;
109 GLint mPositionLocation;
110 GLint mColorLocation;
111};
112
Jamie Madillfa05f602015-05-07 13:47:11 -0400113TEST_P(LineLoopTest, LineLoopUByteIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400114{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800115 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
116 // On Win7, the D3D SDK Layers emits a false warning for these tests.
117 // This doesn't occur on Windows 10 (Version 1511) though.
118 ignoreD3D11SDKLayersWarnings();
119
Jamie Madill231c7f52017-04-26 13:45:37 -0400120 static const GLubyte indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400121 runTest(GL_UNSIGNED_BYTE, 0, indices + 1);
122}
123
Jamie Madillfa05f602015-05-07 13:47:11 -0400124TEST_P(LineLoopTest, LineLoopUShortIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400125{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800126 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
127 ignoreD3D11SDKLayersWarnings();
128
Jamie Madill231c7f52017-04-26 13:45:37 -0400129 static const GLushort indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400130 runTest(GL_UNSIGNED_SHORT, 0, indices + 1);
131}
132
Jamie Madillfa05f602015-05-07 13:47:11 -0400133TEST_P(LineLoopTest, LineLoopUIntIndices)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400134{
135 if (!extensionEnabled("GL_OES_element_index_uint"))
136 {
137 return;
138 }
139
Austin Kinrossd544cc92016-01-11 15:26:42 -0800140 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
141 ignoreD3D11SDKLayersWarnings();
142
Jamie Madill231c7f52017-04-26 13:45:37 -0400143 static const GLuint indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400144 runTest(GL_UNSIGNED_INT, 0, indices + 1);
145}
146
Jamie Madillfa05f602015-05-07 13:47:11 -0400147TEST_P(LineLoopTest, LineLoopUByteIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400148{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800149 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
150 ignoreD3D11SDKLayersWarnings();
151
Jamie Madill231c7f52017-04-26 13:45:37 -0400152 static const GLubyte indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400153
154 GLuint buf;
155 glGenBuffers(1, &buf);
156 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
157 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
158
159 runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte)));
160
161 glDeleteBuffers(1, &buf);
162}
163
Jamie Madillfa05f602015-05-07 13:47:11 -0400164TEST_P(LineLoopTest, LineLoopUShortIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400165{
Austin Kinrossd544cc92016-01-11 15:26:42 -0800166 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
167 ignoreD3D11SDKLayersWarnings();
168
Jamie Madill231c7f52017-04-26 13:45:37 -0400169 static const GLushort indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400170
171 GLuint buf;
172 glGenBuffers(1, &buf);
173 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
174 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
175
176 runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort)));
177
178 glDeleteBuffers(1, &buf);
179}
180
Jamie Madillfa05f602015-05-07 13:47:11 -0400181TEST_P(LineLoopTest, LineLoopUIntIndexBuffer)
Geoff Lang1f12fa02013-10-23 13:24:53 -0400182{
183 if (!extensionEnabled("GL_OES_element_index_uint"))
184 {
185 return;
186 }
187
Austin Kinrossd544cc92016-01-11 15:26:42 -0800188 // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details
189 ignoreD3D11SDKLayersWarnings();
190
Jamie Madill231c7f52017-04-26 13:45:37 -0400191 static const GLuint indices[] = {0, 7, 6, 9, 8, 0};
Geoff Lang1f12fa02013-10-23 13:24:53 -0400192
193 GLuint buf;
194 glGenBuffers(1, &buf);
195 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf);
196 glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
197
198 runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint)));
199
200 glDeleteBuffers(1, &buf);
201}
Jamie Madillfa05f602015-05-07 13:47:11 -0400202
Jamie Madill231c7f52017-04-26 13:45:37 -0400203// Use this to select which configurations (e.g. which renderer, which GLES major version) these
204// tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500205ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES());