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 | // SimpleOperationTest: |
| 7 | // Basic GL commands such as linking a program, initializing a buffer, etc. |
| 8 | |
Corentin Wallez | d3970de | 2015-05-14 11:07:48 -0400 | [diff] [blame] | 9 | #include "test_utils/ANGLETest.h" |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 10 | |
| 11 | #include <vector> |
| 12 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 13 | #include "random_utils.h" |
| 14 | #include "test_utils/gl_raii.h" |
| 15 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 16 | using namespace angle; |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 17 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 18 | namespace |
| 19 | { |
| 20 | |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 21 | class SimpleOperationTest : public ANGLETest |
| 22 | { |
| 23 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 24 | SimpleOperationTest() |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 25 | { |
| 26 | setWindowWidth(128); |
| 27 | setWindowHeight(128); |
| 28 | setConfigRedBits(8); |
| 29 | setConfigGreenBits(8); |
| 30 | setConfigBlueBits(8); |
| 31 | setConfigAlphaBits(8); |
| 32 | } |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 33 | |
| 34 | void verifyBuffer(const std::vector<uint8_t> &data, GLenum binding); |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 37 | void SimpleOperationTest::verifyBuffer(const std::vector<uint8_t> &data, GLenum binding) |
| 38 | { |
| 39 | if (!extensionEnabled("GL_EXT_map_buffer_range")) |
| 40 | { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | uint8_t *mapPointer = |
| 45 | static_cast<uint8_t *>(glMapBufferRangeEXT(GL_ARRAY_BUFFER, 0, 1024, GL_MAP_READ_BIT)); |
| 46 | ASSERT_GL_NO_ERROR(); |
| 47 | |
| 48 | std::vector<uint8_t> readbackData(data.size()); |
| 49 | memcpy(readbackData.data(), mapPointer, data.size()); |
| 50 | glUnmapBufferOES(GL_ARRAY_BUFFER); |
| 51 | |
| 52 | EXPECT_EQ(data, readbackData); |
| 53 | } |
| 54 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 55 | TEST_P(SimpleOperationTest, CompileVertexShader) |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 56 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 57 | if (IsVulkan()) |
| 58 | { |
| 59 | // TODO(jmadill): Complete Vulkan implementation. |
| 60 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 61 | return; |
| 62 | } |
| 63 | |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 64 | const std::string source = SHADER_SOURCE |
| 65 | ( |
| 66 | attribute vec4 a_input; |
| 67 | void main() |
| 68 | { |
| 69 | gl_Position = a_input; |
| 70 | } |
| 71 | ); |
| 72 | |
| 73 | GLuint shader = CompileShader(GL_VERTEX_SHADER, source); |
| 74 | EXPECT_NE(shader, 0u); |
| 75 | glDeleteShader(shader); |
| 76 | |
| 77 | EXPECT_GL_NO_ERROR(); |
| 78 | } |
| 79 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 80 | TEST_P(SimpleOperationTest, CompileFragmentShader) |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 81 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 82 | if (IsVulkan()) |
| 83 | { |
| 84 | // TODO(jmadill): Complete Vulkan implementation. |
| 85 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 86 | return; |
| 87 | } |
| 88 | |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 89 | const std::string source = SHADER_SOURCE |
| 90 | ( |
| 91 | precision mediump float; |
| 92 | varying vec4 v_input; |
| 93 | void main() |
| 94 | { |
| 95 | gl_FragColor = v_input; |
| 96 | } |
| 97 | ); |
| 98 | |
| 99 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 100 | EXPECT_NE(shader, 0u); |
| 101 | glDeleteShader(shader); |
| 102 | |
| 103 | EXPECT_GL_NO_ERROR(); |
| 104 | } |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 105 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 106 | TEST_P(SimpleOperationTest, LinkProgram) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 107 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 108 | if (IsVulkan()) |
| 109 | { |
| 110 | // TODO(jmadill): Complete Vulkan implementation. |
| 111 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 112 | return; |
| 113 | } |
| 114 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 115 | const std::string vsSource = SHADER_SOURCE |
| 116 | ( |
| 117 | void main() |
| 118 | { |
| 119 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 120 | } |
| 121 | ); |
| 122 | |
| 123 | const std::string fsSource = SHADER_SOURCE |
| 124 | ( |
| 125 | void main() |
| 126 | { |
| 127 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 128 | } |
| 129 | ); |
| 130 | |
| 131 | GLuint program = CompileProgram(vsSource, fsSource); |
| 132 | EXPECT_NE(program, 0u); |
| 133 | glDeleteProgram(program); |
| 134 | |
| 135 | EXPECT_GL_NO_ERROR(); |
| 136 | } |
| 137 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 138 | TEST_P(SimpleOperationTest, LinkProgramWithUniforms) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 139 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 140 | if (IsVulkan()) |
| 141 | { |
| 142 | // TODO(jmadill): Complete Vulkan implementation. |
| 143 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 144 | return; |
| 145 | } |
| 146 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 147 | const std::string vsSource = SHADER_SOURCE |
| 148 | ( |
| 149 | void main() |
| 150 | { |
| 151 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 152 | } |
| 153 | ); |
| 154 | |
| 155 | const std::string fsSource = SHADER_SOURCE |
| 156 | ( |
| 157 | precision mediump float; |
| 158 | uniform vec4 u_input; |
| 159 | void main() |
| 160 | { |
| 161 | gl_FragColor = u_input; |
| 162 | } |
| 163 | ); |
| 164 | |
| 165 | GLuint program = CompileProgram(vsSource, fsSource); |
| 166 | EXPECT_NE(program, 0u); |
| 167 | |
| 168 | GLint uniformLoc = glGetUniformLocation(program, "u_input"); |
| 169 | EXPECT_NE(-1, uniformLoc); |
| 170 | |
| 171 | glDeleteProgram(program); |
| 172 | |
| 173 | EXPECT_GL_NO_ERROR(); |
| 174 | } |
| 175 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 176 | TEST_P(SimpleOperationTest, LinkProgramWithAttributes) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 177 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 178 | if (IsVulkan()) |
| 179 | { |
| 180 | // TODO(jmadill): Complete Vulkan implementation. |
| 181 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 182 | return; |
| 183 | } |
| 184 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 185 | const std::string vsSource = SHADER_SOURCE |
| 186 | ( |
| 187 | attribute vec4 a_input; |
| 188 | void main() |
| 189 | { |
| 190 | gl_Position = a_input; |
| 191 | } |
| 192 | ); |
| 193 | |
| 194 | const std::string fsSource = SHADER_SOURCE |
| 195 | ( |
| 196 | void main() |
| 197 | { |
| 198 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 199 | } |
| 200 | ); |
| 201 | |
| 202 | GLuint program = CompileProgram(vsSource, fsSource); |
| 203 | EXPECT_NE(program, 0u); |
| 204 | |
| 205 | GLint attribLoc = glGetAttribLocation(program, "a_input"); |
| 206 | EXPECT_NE(-1, attribLoc); |
| 207 | |
| 208 | glDeleteProgram(program); |
| 209 | |
| 210 | EXPECT_GL_NO_ERROR(); |
| 211 | } |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 212 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 213 | TEST_P(SimpleOperationTest, BufferDataWithData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 214 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 215 | GLBuffer buffer; |
| 216 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 217 | |
| 218 | std::vector<uint8_t> data(1024); |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 219 | FillVectorWithRandomUBytes(&data); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 220 | glBufferData(GL_ARRAY_BUFFER, data.size(), &data[0], GL_STATIC_DRAW); |
| 221 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 222 | verifyBuffer(data, GL_ARRAY_BUFFER); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 223 | |
| 224 | EXPECT_GL_NO_ERROR(); |
| 225 | } |
| 226 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 227 | TEST_P(SimpleOperationTest, BufferDataWithNoData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 228 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 229 | GLBuffer buffer; |
| 230 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 231 | glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 232 | |
| 233 | EXPECT_GL_NO_ERROR(); |
| 234 | } |
| 235 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 236 | TEST_P(SimpleOperationTest, BufferSubData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 237 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 238 | GLBuffer buffer; |
| 239 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 240 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 241 | constexpr size_t bufferSize = 1024; |
| 242 | std::vector<uint8_t> data(bufferSize); |
| 243 | FillVectorWithRandomUBytes(&data); |
| 244 | |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 245 | glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW); |
| 246 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 247 | constexpr size_t subDataCount = 16; |
| 248 | constexpr size_t sliceSize = bufferSize / subDataCount; |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 249 | for (size_t i = 0; i < subDataCount; i++) |
| 250 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 251 | size_t offset = i * sliceSize; |
| 252 | glBufferSubData(GL_ARRAY_BUFFER, offset, sliceSize, &data[offset]); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 253 | } |
| 254 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 255 | verifyBuffer(data, GL_ARRAY_BUFFER); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 256 | |
| 257 | EXPECT_GL_NO_ERROR(); |
| 258 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 259 | |
| 260 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 261 | ANGLE_INSTANTIATE_TEST(SimpleOperationTest, |
| 262 | ES2_D3D9(), |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 263 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 264 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 265 | ES3_D3D11(), |
| 266 | ES2_OPENGL(), |
| 267 | ES3_OPENGL(), |
| 268 | ES2_OPENGLES(), |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame^] | 269 | ES3_OPENGLES(), |
| 270 | ES2_VULKAN()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 271 | |
| 272 | } // namespace |