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 | |
| 28 | const std::string vsSource = SHADER_SOURCE |
| 29 | ( |
| 30 | attribute highp vec4 position; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 31 | |
| 32 | void main(void) |
| 33 | { |
| 34 | gl_Position = position; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 35 | } |
| 36 | ); |
| 37 | |
| 38 | const std::string fsSource = SHADER_SOURCE |
| 39 | ( |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 40 | uniform highp vec4 color; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 41 | void main(void) |
| 42 | { |
| 43 | gl_FragColor = color; |
| 44 | } |
| 45 | ); |
| 46 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 47 | mProgram = CompileProgram(vsSource, fsSource); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 48 | if (mProgram == 0) |
| 49 | { |
| 50 | FAIL() << "shader compilation failed."; |
| 51 | } |
| 52 | |
| 53 | mPositionLocation = glGetAttribLocation(mProgram, "position"); |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 54 | mColorLocation = glGetUniformLocation(mProgram, "color"); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 55 | |
| 56 | glBlendFunc(GL_ONE, GL_ONE); |
| 57 | glEnable(GL_BLEND); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 58 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 59 | |
| 60 | ASSERT_GL_NO_ERROR(); |
| 61 | } |
| 62 | |
| 63 | virtual void TearDown() |
| 64 | { |
| 65 | glDeleteProgram(mProgram); |
| 66 | |
| 67 | ANGLETest::TearDown(); |
| 68 | } |
| 69 | |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 70 | void runTest(GLenum indexType, GLuint indexBuffer, const GLvoid *indexPtr) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 71 | { |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 72 | glClear(GL_COLOR_BUFFER_BIT); |
| 73 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 74 | static const GLfloat loopPositions[] = |
| 75 | { |
| 76 | 0.0f, 0.0f, |
| 77 | 0.0f, 0.0f, |
| 78 | 0.0f, 0.0f, |
| 79 | 0.0f, 0.0f, |
| 80 | 0.0f, 0.0f, |
| 81 | 0.0f, 0.0f, |
| 82 | -0.5f, -0.5f, |
| 83 | -0.5f, 0.5f, |
| 84 | 0.5f, 0.5f, |
| 85 | 0.5f, -0.5f |
| 86 | }; |
| 87 | |
| 88 | static const GLfloat stripPositions[] = |
| 89 | { |
| 90 | -0.5f, -0.5f, |
| 91 | -0.5f, 0.5f, |
| 92 | 0.5f, 0.5f, |
| 93 | 0.5f, -0.5f |
| 94 | }; |
| 95 | static const GLubyte stripIndices[] = |
| 96 | { |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 97 | 1, 0, 3, 2, 1 |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | glUseProgram(mProgram); |
| 101 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); |
| 102 | glEnableVertexAttribArray(mPositionLocation); |
| 103 | glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions); |
| 104 | glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f); |
| 105 | glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr); |
| 106 | |
| 107 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 108 | glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions); |
| 109 | glUniform4f(mColorLocation, 0, 1, 0, 1); |
| 110 | glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices); |
| 111 | |
| 112 | std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4); |
Jamie Madill | b4fd0c9 | 2014-10-01 17:40:24 -0400 | [diff] [blame] | 113 | glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 114 | |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 115 | ASSERT_GL_NO_ERROR(); |
| 116 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 117 | for (int y = 0; y < getWindowHeight(); y++) |
| 118 | { |
| 119 | for (int x = 0; x < getWindowWidth(); x++) |
| 120 | { |
Jamie Madill | b4fd0c9 | 2014-10-01 17:40:24 -0400 | [diff] [blame] | 121 | const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 122 | |
| 123 | EXPECT_EQ(pixel[0], 0); |
| 124 | EXPECT_EQ(pixel[1], pixel[2]); |
| 125 | EXPECT_EQ(pixel[3], 255); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | GLuint mProgram; |
| 131 | GLint mPositionLocation; |
| 132 | GLint mColorLocation; |
| 133 | }; |
| 134 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 135 | TEST_P(LineLoopTest, LineLoopUByteIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 136 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 137 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 138 | // On Win7, the D3D SDK Layers emits a false warning for these tests. |
| 139 | // This doesn't occur on Windows 10 (Version 1511) though. |
| 140 | ignoreD3D11SDKLayersWarnings(); |
| 141 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 142 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 143 | runTest(GL_UNSIGNED_BYTE, 0, indices + 1); |
| 144 | } |
| 145 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 146 | TEST_P(LineLoopTest, LineLoopUShortIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 147 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 148 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 149 | ignoreD3D11SDKLayersWarnings(); |
| 150 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 151 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 152 | runTest(GL_UNSIGNED_SHORT, 0, indices + 1); |
| 153 | } |
| 154 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 155 | TEST_P(LineLoopTest, LineLoopUIntIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 156 | { |
| 157 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 158 | { |
| 159 | return; |
| 160 | } |
| 161 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 162 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 163 | ignoreD3D11SDKLayersWarnings(); |
| 164 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 165 | static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 166 | runTest(GL_UNSIGNED_INT, 0, indices + 1); |
| 167 | } |
| 168 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 169 | TEST_P(LineLoopTest, LineLoopUByteIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 170 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 171 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 172 | ignoreD3D11SDKLayersWarnings(); |
| 173 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 174 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 175 | |
| 176 | GLuint buf; |
| 177 | glGenBuffers(1, &buf); |
| 178 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 179 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 180 | |
| 181 | runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte))); |
| 182 | |
| 183 | glDeleteBuffers(1, &buf); |
| 184 | } |
| 185 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 186 | TEST_P(LineLoopTest, LineLoopUShortIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 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 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 191 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 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_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort))); |
| 199 | |
| 200 | glDeleteBuffers(1, &buf); |
| 201 | } |
| 202 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 203 | TEST_P(LineLoopTest, LineLoopUIntIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 204 | { |
| 205 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 206 | { |
| 207 | return; |
| 208 | } |
| 209 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame^] | 210 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 211 | ignoreD3D11SDKLayersWarnings(); |
| 212 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 213 | static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 214 | |
| 215 | GLuint buf; |
| 216 | glGenBuffers(1, &buf); |
| 217 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 218 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 219 | |
| 220 | runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint))); |
| 221 | |
| 222 | glDeleteBuffers(1, &buf); |
| 223 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 224 | |
| 225 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | f34d1db | 2015-05-20 14:10:46 -0400 | [diff] [blame] | 226 | ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL()); |