Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 1 | #include "ANGLETest.h" |
| 2 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 3 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 4 | ANGLE_TYPED_TEST_CASE(LineLoopTest, ES2_D3D9, ES2_D3D11); |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 5 | |
| 6 | template<typename T> |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 7 | class LineLoopTest : public ANGLETest |
| 8 | { |
| 9 | protected: |
Geoff Lang | 0d3683c | 2014-10-23 11:08:16 -0400 | [diff] [blame] | 10 | LineLoopTest() : ANGLETest(T::GetGlesMajorVersion(), T::GetPlatform()) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 11 | { |
| 12 | setWindowWidth(256); |
| 13 | setWindowHeight(256); |
| 14 | setConfigRedBits(8); |
| 15 | setConfigGreenBits(8); |
| 16 | setConfigBlueBits(8); |
| 17 | setConfigAlphaBits(8); |
| 18 | } |
| 19 | |
| 20 | virtual void SetUp() |
| 21 | { |
| 22 | ANGLETest::SetUp(); |
| 23 | |
| 24 | const std::string vsSource = SHADER_SOURCE |
| 25 | ( |
| 26 | attribute highp vec4 position; |
| 27 | attribute highp vec4 in_color; |
| 28 | |
| 29 | varying highp vec4 color; |
| 30 | |
| 31 | void main(void) |
| 32 | { |
| 33 | gl_Position = position; |
| 34 | color = in_color; |
| 35 | } |
| 36 | ); |
| 37 | |
| 38 | const std::string fsSource = SHADER_SOURCE |
| 39 | ( |
| 40 | varying highp vec4 color; |
| 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"); |
| 54 | mColorLocation = glGetAttribLocation(mProgram, "in_color"); |
| 55 | |
| 56 | glBlendFunc(GL_ONE, GL_ONE); |
| 57 | glEnable(GL_BLEND); |
| 58 | |
| 59 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 60 | glClear(GL_COLOR_BUFFER_BIT); |
| 61 | |
| 62 | ASSERT_GL_NO_ERROR(); |
| 63 | } |
| 64 | |
| 65 | virtual void TearDown() |
| 66 | { |
| 67 | glDeleteProgram(mProgram); |
| 68 | |
| 69 | ANGLETest::TearDown(); |
| 70 | } |
| 71 | |
Jamie Madill | b3584fb | 2015-04-09 17:34:21 +0000 | [diff] [blame^] | 72 | void runTest(GLenum indexType, GLubyte indexBuffer, const GLvoid *indexPtr) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 73 | { |
| 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 | { |
| 97 | 2, 0, 3, 1, 2 |
| 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 | |
| 115 | for (int y = 0; y < getWindowHeight(); y++) |
| 116 | { |
| 117 | for (int x = 0; x < getWindowWidth(); x++) |
| 118 | { |
Jamie Madill | b4fd0c9 | 2014-10-01 17:40:24 -0400 | [diff] [blame] | 119 | const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 120 | |
| 121 | EXPECT_EQ(pixel[0], 0); |
| 122 | EXPECT_EQ(pixel[1], pixel[2]); |
| 123 | EXPECT_EQ(pixel[3], 255); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | GLuint mProgram; |
| 129 | GLint mPositionLocation; |
| 130 | GLint mColorLocation; |
| 131 | }; |
| 132 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 133 | TYPED_TEST(LineLoopTest, LineLoopUByteIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 134 | { |
| 135 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 136 | runTest(GL_UNSIGNED_BYTE, 0, indices + 1); |
| 137 | } |
| 138 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 139 | TYPED_TEST(LineLoopTest, LineLoopUShortIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 140 | { |
| 141 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 142 | runTest(GL_UNSIGNED_SHORT, 0, indices + 1); |
| 143 | } |
| 144 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 145 | TYPED_TEST(LineLoopTest, LineLoopUIntIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 146 | { |
| 147 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 148 | { |
| 149 | return; |
| 150 | } |
| 151 | |
| 152 | static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 153 | runTest(GL_UNSIGNED_INT, 0, indices + 1); |
| 154 | } |
| 155 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 156 | TYPED_TEST(LineLoopTest, LineLoopUByteIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 157 | { |
| 158 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 159 | |
| 160 | GLuint buf; |
| 161 | glGenBuffers(1, &buf); |
| 162 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 163 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 164 | |
| 165 | runTest(GL_UNSIGNED_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte))); |
| 166 | |
| 167 | glDeleteBuffers(1, &buf); |
| 168 | } |
| 169 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 170 | TYPED_TEST(LineLoopTest, LineLoopUShortIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 171 | { |
| 172 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 173 | |
| 174 | GLuint buf; |
| 175 | glGenBuffers(1, &buf); |
| 176 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 177 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 178 | |
| 179 | runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort))); |
| 180 | |
| 181 | glDeleteBuffers(1, &buf); |
| 182 | } |
| 183 | |
Austin Kinross | 18b931d | 2014-09-29 12:58:31 -0700 | [diff] [blame] | 184 | TYPED_TEST(LineLoopTest, LineLoopUIntIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 185 | { |
| 186 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 187 | { |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | static const GLuint 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_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint))); |
| 199 | |
| 200 | glDeleteBuffers(1, &buf); |
| 201 | } |