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; |
| 31 | attribute highp vec4 in_color; |
| 32 | |
| 33 | varying highp vec4 color; |
| 34 | |
| 35 | void main(void) |
| 36 | { |
| 37 | gl_Position = position; |
| 38 | color = in_color; |
| 39 | } |
| 40 | ); |
| 41 | |
| 42 | const std::string fsSource = SHADER_SOURCE |
| 43 | ( |
| 44 | varying highp vec4 color; |
| 45 | void main(void) |
| 46 | { |
| 47 | gl_FragColor = color; |
| 48 | } |
| 49 | ); |
| 50 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 51 | mProgram = CompileProgram(vsSource, fsSource); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 52 | if (mProgram == 0) |
| 53 | { |
| 54 | FAIL() << "shader compilation failed."; |
| 55 | } |
| 56 | |
| 57 | mPositionLocation = glGetAttribLocation(mProgram, "position"); |
| 58 | mColorLocation = glGetAttribLocation(mProgram, "in_color"); |
| 59 | |
| 60 | glBlendFunc(GL_ONE, GL_ONE); |
| 61 | glEnable(GL_BLEND); |
| 62 | |
| 63 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 64 | glClear(GL_COLOR_BUFFER_BIT); |
| 65 | |
| 66 | ASSERT_GL_NO_ERROR(); |
| 67 | } |
| 68 | |
| 69 | virtual void TearDown() |
| 70 | { |
| 71 | glDeleteProgram(mProgram); |
| 72 | |
| 73 | ANGLETest::TearDown(); |
| 74 | } |
| 75 | |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 76 | void runTest(GLenum indexType, GLuint indexBuffer, const GLvoid *indexPtr) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 77 | { |
| 78 | static const GLfloat loopPositions[] = |
| 79 | { |
| 80 | 0.0f, 0.0f, |
| 81 | 0.0f, 0.0f, |
| 82 | 0.0f, 0.0f, |
| 83 | 0.0f, 0.0f, |
| 84 | 0.0f, 0.0f, |
| 85 | 0.0f, 0.0f, |
| 86 | -0.5f, -0.5f, |
| 87 | -0.5f, 0.5f, |
| 88 | 0.5f, 0.5f, |
| 89 | 0.5f, -0.5f |
| 90 | }; |
| 91 | |
| 92 | static const GLfloat stripPositions[] = |
| 93 | { |
| 94 | -0.5f, -0.5f, |
| 95 | -0.5f, 0.5f, |
| 96 | 0.5f, 0.5f, |
| 97 | 0.5f, -0.5f |
| 98 | }; |
| 99 | static const GLubyte stripIndices[] = |
| 100 | { |
| 101 | 2, 0, 3, 1, 2 |
| 102 | }; |
| 103 | |
| 104 | glUseProgram(mProgram); |
| 105 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); |
| 106 | glEnableVertexAttribArray(mPositionLocation); |
| 107 | glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, loopPositions); |
| 108 | glUniform4f(mColorLocation, 0.0f, 0.0f, 1.0f, 1.0f); |
| 109 | glDrawElements(GL_LINE_LOOP, 4, indexType, indexPtr); |
| 110 | |
| 111 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); |
| 112 | glVertexAttribPointer(mPositionLocation, 2, GL_FLOAT, GL_FALSE, 0, stripPositions); |
| 113 | glUniform4f(mColorLocation, 0, 1, 0, 1); |
| 114 | glDrawElements(GL_LINE_STRIP, 5, GL_UNSIGNED_BYTE, stripIndices); |
| 115 | |
| 116 | std::vector<GLubyte> pixels(getWindowWidth() * getWindowHeight() * 4); |
Jamie Madill | b4fd0c9 | 2014-10-01 17:40:24 -0400 | [diff] [blame] | 117 | glReadPixels(0, 0, getWindowWidth(), getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, &pixels[0]); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 118 | |
| 119 | for (int y = 0; y < getWindowHeight(); y++) |
| 120 | { |
| 121 | for (int x = 0; x < getWindowWidth(); x++) |
| 122 | { |
Jamie Madill | b4fd0c9 | 2014-10-01 17:40:24 -0400 | [diff] [blame] | 123 | const GLubyte* pixel = &pixels[0] + ((y * getWindowWidth() + x) * 4); |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 124 | |
| 125 | EXPECT_EQ(pixel[0], 0); |
| 126 | EXPECT_EQ(pixel[1], pixel[2]); |
| 127 | EXPECT_EQ(pixel[3], 255); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | GLuint mProgram; |
| 133 | GLint mPositionLocation; |
| 134 | GLint mColorLocation; |
| 135 | }; |
| 136 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 137 | TEST_P(LineLoopTest, LineLoopUByteIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 138 | { |
| 139 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 140 | runTest(GL_UNSIGNED_BYTE, 0, indices + 1); |
| 141 | } |
| 142 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 143 | TEST_P(LineLoopTest, LineLoopUShortIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 144 | { |
| 145 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 146 | runTest(GL_UNSIGNED_SHORT, 0, indices + 1); |
| 147 | } |
| 148 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 149 | TEST_P(LineLoopTest, LineLoopUIntIndices) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 150 | { |
| 151 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 152 | { |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 157 | runTest(GL_UNSIGNED_INT, 0, indices + 1); |
| 158 | } |
| 159 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 160 | TEST_P(LineLoopTest, LineLoopUByteIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 161 | { |
| 162 | static const GLubyte indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 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_BYTE, buf, reinterpret_cast<const void *>(sizeof(GLubyte))); |
| 170 | |
| 171 | glDeleteBuffers(1, &buf); |
| 172 | } |
| 173 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 174 | TEST_P(LineLoopTest, LineLoopUShortIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 175 | { |
| 176 | static const GLushort indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 177 | |
| 178 | GLuint buf; |
| 179 | glGenBuffers(1, &buf); |
| 180 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 181 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 182 | |
| 183 | runTest(GL_UNSIGNED_SHORT, buf, reinterpret_cast<const void *>(sizeof(GLushort))); |
| 184 | |
| 185 | glDeleteBuffers(1, &buf); |
| 186 | } |
| 187 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 188 | TEST_P(LineLoopTest, LineLoopUIntIndexBuffer) |
Geoff Lang | 1f12fa0 | 2013-10-23 13:24:53 -0400 | [diff] [blame] | 189 | { |
| 190 | if (!extensionEnabled("GL_OES_element_index_uint")) |
| 191 | { |
| 192 | return; |
| 193 | } |
| 194 | |
| 195 | static const GLuint indices[] = { 0, 7, 6, 9, 8, 0 }; |
| 196 | |
| 197 | GLuint buf; |
| 198 | glGenBuffers(1, &buf); |
| 199 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf); |
| 200 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); |
| 201 | |
| 202 | runTest(GL_UNSIGNED_INT, buf, reinterpret_cast<const void *>(sizeof(GLuint))); |
| 203 | |
| 204 | glDeleteBuffers(1, &buf); |
| 205 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 206 | |
| 207 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 208 | ANGLE_INSTANTIATE_TEST(LineLoopTest, ES2_D3D9(), ES2_D3D11()); |