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 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 28 | const std::string vsSource = SHADER_SOURCE(attribute highp vec4 position; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 29 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 30 | void main(void) { gl_Position = position; }); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 31 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 32 | const std::string fsSource = |
| 33 | SHADER_SOURCE(uniform highp vec4 color; void main(void) { gl_FragColor = color; }); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 34 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 35 | mProgram = CompileProgram(vsSource, fsSource); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 36 | if (mProgram == 0) |
| 37 | { |
| 38 | FAIL() << "shader compilation failed."; |
| 39 | } |
| 40 | |
| 41 | mPositionLocation = glGetAttribLocation(mProgram, "position"); |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 42 | mColorLocation = glGetUniformLocation(mProgram, "color"); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 43 | |
| 44 | glBlendFunc(GL_ONE, GL_ONE); |
| 45 | glEnable(GL_BLEND); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 46 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 47 | |
| 48 | ASSERT_GL_NO_ERROR(); |
| 49 | } |
| 50 | |
| 51 | virtual void TearDown() |
| 52 | { |
| 53 | glDeleteProgram(mProgram); |
| 54 | |
| 55 | ANGLETest::TearDown(); |
| 56 | } |
| 57 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 58 | void runTest(GLenum indexType, GLuint indexBuffer, const void *indexPtr) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 59 | { |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 60 | glClear(GL_COLOR_BUFFER_BIT); |
| 61 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 62 | 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 Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 65 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 66 | 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 Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 69 | |
| 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 Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 83 | glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, |
| 84 | &pixels[0]); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 85 | |
Corentin Wallez | 91f828e | 2015-07-13 11:08:19 -0400 | [diff] [blame] | 86 | ASSERT_GL_NO_ERROR(); |
| 87 | |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 88 | for (int y = 0; y < getWindowHeight(); y++) |
| 89 | { |
| 90 | for (int x = 0; x < getWindowWidth(); x++) |
| 91 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 92 | const GLubyte *pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 93 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 106 | TEST_P(LineLoopTest, LineLoopUByteIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 107 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 108 | // 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 Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 113 | static const GLubyte indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 114 | runTest(GL_UNSIGNED_BYTE, 0, indices + 1); |
| 115 | } |
| 116 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 117 | TEST_P(LineLoopTest, LineLoopUShortIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 118 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 119 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 120 | ignoreD3D11SDKLayersWarnings(); |
| 121 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 122 | static const GLushort indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 123 | runTest(GL_UNSIGNED_SHORT, 0, indices + 1); |
| 124 | } |
| 125 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 126 | TEST_P(LineLoopTest, LineLoopUIntIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 127 | { |
| 128 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 129 | { |
| 130 | return; |
| 131 | } |
| 132 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 133 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 134 | ignoreD3D11SDKLayersWarnings(); |
| 135 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 136 | static const GLuint indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 137 | runTest(GL_UNSIGNED_INT, 0, indices + 1); |
| 138 | } |
| 139 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 140 | TEST_P(LineLoopTest, LineLoopUByteIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 141 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 142 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 143 | ignoreD3D11SDKLayersWarnings(); |
| 144 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 145 | static const GLubyte indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 146 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 157 | TEST_P(LineLoopTest, LineLoopUShortIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 158 | { |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 159 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 160 | ignoreD3D11SDKLayersWarnings(); |
| 161 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 162 | static const GLushort indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 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_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort))); |
| 170 | |
| 171 | glDeleteBuffers(1, &buf); |
| 172 | } |
| 173 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 174 | TEST_P(LineLoopTest, LineLoopUIntIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 175 | { |
| 176 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 177 | { |
| 178 | return; |
| 179 | } |
| 180 | |
Austin Kinross | d544cc9 | 2016-01-11 15:26:42 -0800 | [diff] [blame] | 181 | // Disable D3D11 SDK Layers warnings checks, see ANGLE issue 667 for details |
| 182 | ignoreD3D11SDKLayersWarnings(); |
| 183 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 184 | static const GLuint indices[] = {0, 7, 6, 9, 8, 0}; |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 185 | |
| 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 Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 195 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 196 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these |
| 197 | // tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 198 | ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11(), ES2_OPENGL(), ES2_OPENGLES()); |