Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 1 | // |
| 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 Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 7 | #include "test_utils/ANGLETest.h" |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 8 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 10 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 11 | class LineLoopTest : public ANGLETest |
| 12 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | protected: |
| 14 | LineLoopTest() |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 15 | { |
| 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 Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 28 | const std::string vsSource = |
| 29 | R"(attribute highp vec4 position; |
| 30 | void main(void) |
| 31 | { |
| 32 | gl_Position = position; |
| 33 | })"; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 34 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 35 | const std::string fsSource = |
Olli Etuaho | a20af6d | 2017-09-18 13:32:29 +0300 | [diff] [blame^] | 36 | R"(uniform highp vec4 color; |
| 37 | void main(void) |
| 38 | { |
| 39 | gl_FragColor = color; |
| 40 | })"; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 41 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 42 | mProgram = CompileProgram(vsSource, fsSource); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 43 | if (mProgram == 0) |
| 44 | { |
| 45 | FAIL() << "shader compilation failed."; |
| 46 | } |
| 47 | |
| 48 | mPositionLocation = glGetAttribLocation(mProgram, "position"); |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 49 | mColorLocation = glGetUniformLocation(mProgram, "color"); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 50 | |
| 51 | glBlendFunc(GL_ONE, GL_ONE); |
| 52 | glEnable(GL_BLEND); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 53 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 54 | |
| 55 | ASSERT_GL_NO_ERROR(); |
| 56 | } |
| 57 | |
| 58 | virtual void TearDown() |
| 59 | { |
| 60 | glDeleteProgram(mProgram); |
| 61 | |
| 62 | ANGLETest::TearDown(); |
| 63 | } |
| 64 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 65 | void runTest(GLenum indexType, GLuint indexBuffer, const void *indexPtr) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 66 | { |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 67 | glClear(GL_COLOR_BUFFER_BIT); |
| 68 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 69 | 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 Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 72 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 73 | 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 Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 76 | |
| 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 Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 90 | glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, |
| 91 | &pixels[0]); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 92 | |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 93 | ASSERT_GL_NO_ERROR(); |
| 94 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 95 | for (int y = 0; y < getWindowHeight(); y++) |
| 96 | { |
| 97 | for (int x = 0; x < getWindowWidth(); x++) |
| 98 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 99 | const GLubyte *pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 100 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 113 | TEST_P(LineLoopTest, LineLoopUByteIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 114 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 115 | // 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 Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 120 | static const GLubyte indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 121 | runTest(GL_UNSIGNED_BYTE, 0, indices + 1); |
| 122 | } |
| 123 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 124 | TEST_P(LineLoopTest, LineLoopUShortIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 125 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 126 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 127 | ignoreD3D11SDKLayersWarnings(); |
| 128 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 129 | static const GLushort indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 130 | runTest(GL_UNSIGNED_SHORT, 0, indices + 1); |
| 131 | } |
| 132 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 133 | TEST_P(LineLoopTest, LineLoopUIntIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 134 | { |
| 135 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 136 | { |
| 137 | return; |
| 138 | } |
| 139 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 140 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 141 | ignoreD3D11SDKLayersWarnings(); |
| 142 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 143 | static const GLuint indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 144 | runTest(GL_UNSIGNED_INT, 0, indices + 1); |
| 145 | } |
| 146 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 147 | TEST_P(LineLoopTest, LineLoopUByteIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 148 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 149 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 150 | ignoreD3D11SDKLayersWarnings(); |
| 151 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 152 | static const GLubyte indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 153 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 164 | TEST_P(LineLoopTest, LineLoopUShortIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 165 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 166 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 167 | ignoreD3D11SDKLayersWarnings(); |
| 168 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 169 | static const GLushort indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 170 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 181 | TEST_P(LineLoopTest, LineLoopUIntIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 182 | { |
| 183 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 184 | { |
| 185 | return; |
| 186 | } |
| 187 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 188 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 189 | ignoreD3D11SDKLayersWarnings(); |
| 190 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 191 | static const GLuint indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 192 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 202 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 203 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 204 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 205 | ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |