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