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" |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 8 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 9 | using namespace angle; |
| 10 | |
| 11 | template <typename IndexType, GLenum IndexTypeName> |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 12 | class IndexedPointsTest : public ANGLETest |
| 13 | { |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 14 | protected: |
| 15 | IndexedPointsTest() |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 16 | { |
| 17 | setWindowWidth(128); |
| 18 | setWindowHeight(128); |
| 19 | setConfigRedBits(8); |
| 20 | setConfigGreenBits(8); |
| 21 | setConfigBlueBits(8); |
| 22 | setConfigAlphaBits(8); |
| 23 | setConfigDepthBits(24); |
| 24 | } |
| 25 | |
| 26 | float getIndexPositionX(size_t idx) |
| 27 | { |
| 28 | return (idx == 0 || idx == 3) ? -0.5f : 0.5f; |
| 29 | } |
| 30 | |
| 31 | float getIndexPositionY(size_t idx) |
| 32 | { |
| 33 | return (idx == 2 || idx == 3) ? -0.5f : 0.5f; |
| 34 | } |
| 35 | |
| 36 | virtual void SetUp() |
| 37 | { |
| 38 | ANGLETest::SetUp(); |
| 39 | |
| 40 | const std::string vertexShaderSource = SHADER_SOURCE |
| 41 | ( |
| 42 | precision highp float; |
| 43 | attribute vec2 position; |
| 44 | |
| 45 | void main() |
| 46 | { |
| 47 | gl_PointSize = 5.0; |
| 48 | gl_Position = vec4(position, 0.0, 1.0); |
| 49 | } |
| 50 | ); |
| 51 | |
| 52 | const std::string fragmentShaderSource = SHADER_SOURCE |
| 53 | ( |
| 54 | precision highp float; |
| 55 | |
| 56 | void main() |
| 57 | { |
| 58 | gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); |
| 59 | } |
| 60 | ); |
| 61 | |
Jamie Madill | 5599c8f | 2014-08-26 13:16:39 -0400 | [diff] [blame] | 62 | mProgram = CompileProgram(vertexShaderSource, fragmentShaderSource); |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 63 | if (mProgram == 0) |
| 64 | { |
| 65 | FAIL() << "shader compilation failed."; |
| 66 | } |
| 67 | |
Corentin Wallez | 91c2fad | 2015-05-15 10:34:14 -0400 | [diff] [blame^] | 68 | const GLfloat vertices[] = |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 69 | { |
| 70 | getIndexPositionX(0), getIndexPositionY(0), |
| 71 | getIndexPositionX(1), getIndexPositionY(1), |
| 72 | getIndexPositionX(2), getIndexPositionY(2), |
| 73 | getIndexPositionX(3), getIndexPositionY(3), |
| 74 | }; |
| 75 | glGenBuffers(1, &mVertexBuffer); |
| 76 | glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); |
Corentin Wallez | 91c2fad | 2015-05-15 10:34:14 -0400 | [diff] [blame^] | 77 | glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), &vertices[0], GL_STATIC_DRAW); |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 78 | |
Corentin Wallez | 91c2fad | 2015-05-15 10:34:14 -0400 | [diff] [blame^] | 79 | const IndexType indices[] = { 0, 1, 2, 3 }; |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 80 | glGenBuffers(1, &mIndexBuffer); |
| 81 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer); |
Corentin Wallez | 91c2fad | 2015-05-15 10:34:14 -0400 | [diff] [blame^] | 82 | glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), &indices[0], GL_STATIC_DRAW); |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | virtual void TearDown() |
| 86 | { |
| 87 | glDeleteProgram(mProgram); |
| 88 | |
| 89 | ANGLETest::TearDown(); |
| 90 | } |
| 91 | |
| 92 | void runTest(GLuint firstIndex) |
| 93 | { |
| 94 | glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
| 95 | glClear(GL_COLOR_BUFFER_BIT); |
| 96 | |
| 97 | GLint viewportSize[4]; |
| 98 | glGetIntegerv(GL_VIEWPORT, viewportSize); |
| 99 | |
| 100 | glBindBuffer(GL_ARRAY_BUFFER, mVertexBuffer); |
| 101 | GLint vertexLocation = glGetAttribLocation(mProgram, "position"); |
| 102 | glVertexAttribPointer(vertexLocation, 2, GL_FLOAT, GL_FALSE, 0, 0); |
| 103 | glEnableVertexAttribArray(vertexLocation); |
| 104 | |
| 105 | glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mIndexBuffer); |
| 106 | |
| 107 | glUseProgram(mProgram); |
| 108 | |
| 109 | glDrawElements(GL_POINTS, mPointCount - firstIndex, IndexTypeName, reinterpret_cast<void*>(firstIndex * sizeof(IndexType))); |
| 110 | |
| 111 | for (size_t i = 0; i < mPointCount; i++) |
| 112 | { |
Minmin Gong | 794e000 | 2015-04-07 18:31:54 -0700 | [diff] [blame] | 113 | GLuint x = static_cast<GLuint>(viewportSize[0] + (getIndexPositionX(i) * 0.5f + 0.5f) * (viewportSize[2] - viewportSize[0])); |
| 114 | GLuint y = static_cast<GLuint>(viewportSize[1] + (getIndexPositionY(i) * 0.5f + 0.5f) * (viewportSize[3] - viewportSize[1])); |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 115 | |
| 116 | if (i < firstIndex) |
| 117 | { |
| 118 | EXPECT_PIXEL_EQ(x, y, 0, 0, 0, 255); |
| 119 | } |
| 120 | else |
| 121 | { |
| 122 | EXPECT_PIXEL_EQ(x, y, 255, 0, 0, 255); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | GLuint mProgram; |
| 128 | GLuint mVertexBuffer; |
| 129 | GLuint mIndexBuffer; |
| 130 | static const GLuint mPointCount = 4; |
| 131 | }; |
| 132 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 133 | typedef IndexedPointsTest<GLubyte, GL_UNSIGNED_BYTE> IndexedPointsTestUByte; |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 134 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 135 | TEST_P(IndexedPointsTestUByte, UnsignedByteOffset0) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 136 | { |
| 137 | runTest(0); |
| 138 | } |
| 139 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 140 | TEST_P(IndexedPointsTestUByte, UnsignedByteOffset1) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 141 | { |
| 142 | runTest(1); |
| 143 | } |
| 144 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 145 | TEST_P(IndexedPointsTestUByte, UnsignedByteOffset2) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 146 | { |
| 147 | runTest(2); |
| 148 | } |
| 149 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 150 | TEST_P(IndexedPointsTestUByte, UnsignedByteOffset3) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 151 | { |
| 152 | runTest(3); |
| 153 | } |
| 154 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 155 | typedef IndexedPointsTest<GLushort, GL_UNSIGNED_SHORT> IndexedPointsTestUShort; |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 156 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 157 | TEST_P(IndexedPointsTestUShort, UnsignedShortOffset0) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 158 | { |
| 159 | runTest(0); |
| 160 | } |
| 161 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 162 | TEST_P(IndexedPointsTestUShort, UnsignedShortOffset1) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 163 | { |
| 164 | runTest(1); |
| 165 | } |
| 166 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 167 | TEST_P(IndexedPointsTestUShort, UnsignedShortOffset2) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 168 | { |
| 169 | runTest(2); |
| 170 | } |
| 171 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 172 | TEST_P(IndexedPointsTestUShort, UnsignedShortOffset3) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 173 | { |
| 174 | runTest(3); |
| 175 | } |
| 176 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 177 | typedef IndexedPointsTest<GLuint, GL_UNSIGNED_INT> IndexedPointsTestUInt; |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 178 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 179 | TEST_P(IndexedPointsTestUInt, UnsignedIntOffset0) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 180 | { |
| 181 | if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint")) |
| 182 | { |
| 183 | return; |
| 184 | } |
| 185 | |
| 186 | runTest(0); |
| 187 | } |
| 188 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 189 | TEST_P(IndexedPointsTestUInt, UnsignedIntOffset1) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 190 | { |
| 191 | if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint")) |
| 192 | { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | runTest(1); |
| 197 | } |
| 198 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 199 | TEST_P(IndexedPointsTestUInt, UnsignedIntOffset2) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 200 | { |
| 201 | if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint")) |
| 202 | { |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | runTest(2); |
| 207 | } |
| 208 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 209 | TEST_P(IndexedPointsTestUInt, UnsignedIntOffset3) |
Geoff Lang | f8c2f5c | 2013-12-05 13:52:33 -0500 | [diff] [blame] | 210 | { |
| 211 | if (getClientVersion() < 3 && !extensionEnabled("GL_OES_element_index_uint")) |
| 212 | { |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | runTest(3); |
| 217 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 218 | |
| 219 | ANGLE_INSTANTIATE_TEST(IndexedPointsTestUByte, ES2_D3D11()); |
| 220 | ANGLE_INSTANTIATE_TEST(IndexedPointsTestUShort, ES2_D3D11()); |
| 221 | ANGLE_INSTANTIATE_TEST(IndexedPointsTestUInt, ES2_D3D11()); |