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 | { |
| 57 | const std::string source = SHADER_SOURCE |
| 58 | ( |
| 59 | attribute vec4 a_input; |
| 60 | void main() |
| 61 | { |
| 62 | gl_Position = a_input; |
| 63 | } |
| 64 | ); |
| 65 | |
| 66 | GLuint shader = CompileShader(GL_VERTEX_SHADER, source); |
| 67 | EXPECT_NE(shader, 0u); |
| 68 | glDeleteShader(shader); |
| 69 | |
| 70 | EXPECT_GL_NO_ERROR(); |
| 71 | } |
| 72 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 73 | TEST_P(SimpleOperationTest, CompileFragmentShader) |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 74 | { |
| 75 | const std::string source = SHADER_SOURCE |
| 76 | ( |
| 77 | precision mediump float; |
| 78 | varying vec4 v_input; |
| 79 | void main() |
| 80 | { |
| 81 | gl_FragColor = v_input; |
| 82 | } |
| 83 | ); |
| 84 | |
| 85 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 86 | EXPECT_NE(shader, 0u); |
| 87 | glDeleteShader(shader); |
| 88 | |
| 89 | EXPECT_GL_NO_ERROR(); |
| 90 | } |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 91 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 92 | TEST_P(SimpleOperationTest, LinkProgram) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 93 | { |
| 94 | const std::string vsSource = SHADER_SOURCE |
| 95 | ( |
| 96 | void main() |
| 97 | { |
| 98 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 99 | } |
| 100 | ); |
| 101 | |
| 102 | const std::string fsSource = SHADER_SOURCE |
| 103 | ( |
| 104 | void main() |
| 105 | { |
| 106 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 107 | } |
| 108 | ); |
| 109 | |
| 110 | GLuint program = CompileProgram(vsSource, fsSource); |
| 111 | EXPECT_NE(program, 0u); |
| 112 | glDeleteProgram(program); |
| 113 | |
| 114 | EXPECT_GL_NO_ERROR(); |
| 115 | } |
| 116 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 117 | TEST_P(SimpleOperationTest, LinkProgramWithUniforms) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 118 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 119 | if (IsVulkan()) |
| 120 | { |
| 121 | // TODO(jmadill): Complete Vulkan implementation. |
| 122 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 123 | return; |
| 124 | } |
| 125 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 126 | const std::string vsSource = SHADER_SOURCE |
| 127 | ( |
| 128 | void main() |
| 129 | { |
| 130 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 131 | } |
| 132 | ); |
| 133 | |
| 134 | const std::string fsSource = SHADER_SOURCE |
| 135 | ( |
| 136 | precision mediump float; |
| 137 | uniform vec4 u_input; |
| 138 | void main() |
| 139 | { |
| 140 | gl_FragColor = u_input; |
| 141 | } |
| 142 | ); |
| 143 | |
| 144 | GLuint program = CompileProgram(vsSource, fsSource); |
| 145 | EXPECT_NE(program, 0u); |
| 146 | |
| 147 | GLint uniformLoc = glGetUniformLocation(program, "u_input"); |
| 148 | EXPECT_NE(-1, uniformLoc); |
| 149 | |
| 150 | glDeleteProgram(program); |
| 151 | |
| 152 | EXPECT_GL_NO_ERROR(); |
| 153 | } |
| 154 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 155 | TEST_P(SimpleOperationTest, LinkProgramWithAttributes) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 156 | { |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 157 | if (IsVulkan()) |
| 158 | { |
| 159 | // TODO(jmadill): Complete Vulkan implementation. |
| 160 | std::cout << "Test skipped on Vulkan." << std::endl; |
| 161 | return; |
| 162 | } |
| 163 | |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 164 | const std::string vsSource = SHADER_SOURCE |
| 165 | ( |
| 166 | attribute vec4 a_input; |
| 167 | void main() |
| 168 | { |
| 169 | gl_Position = a_input; |
| 170 | } |
| 171 | ); |
| 172 | |
| 173 | const std::string fsSource = SHADER_SOURCE |
| 174 | ( |
| 175 | void main() |
| 176 | { |
| 177 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 178 | } |
| 179 | ); |
| 180 | |
| 181 | GLuint program = CompileProgram(vsSource, fsSource); |
| 182 | EXPECT_NE(program, 0u); |
| 183 | |
| 184 | GLint attribLoc = glGetAttribLocation(program, "a_input"); |
| 185 | EXPECT_NE(-1, attribLoc); |
| 186 | |
| 187 | glDeleteProgram(program); |
| 188 | |
| 189 | EXPECT_GL_NO_ERROR(); |
| 190 | } |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 191 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 192 | TEST_P(SimpleOperationTest, BufferDataWithData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 193 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 194 | GLBuffer buffer; |
| 195 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 196 | |
| 197 | std::vector<uint8_t> data(1024); |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 198 | FillVectorWithRandomUBytes(&data); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 199 | glBufferData(GL_ARRAY_BUFFER, data.size(), &data[0], GL_STATIC_DRAW); |
| 200 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 201 | verifyBuffer(data, GL_ARRAY_BUFFER); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 202 | |
| 203 | EXPECT_GL_NO_ERROR(); |
| 204 | } |
| 205 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 206 | TEST_P(SimpleOperationTest, BufferDataWithNoData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 207 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 208 | GLBuffer buffer; |
| 209 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 210 | glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 211 | |
| 212 | EXPECT_GL_NO_ERROR(); |
| 213 | } |
| 214 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 215 | TEST_P(SimpleOperationTest, BufferSubData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 216 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 217 | GLBuffer buffer; |
| 218 | glBindBuffer(GL_ARRAY_BUFFER, buffer.get()); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 219 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 220 | constexpr size_t bufferSize = 1024; |
| 221 | std::vector<uint8_t> data(bufferSize); |
| 222 | FillVectorWithRandomUBytes(&data); |
| 223 | |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 224 | glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW); |
| 225 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 226 | constexpr size_t subDataCount = 16; |
| 227 | constexpr size_t sliceSize = bufferSize / subDataCount; |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 228 | for (size_t i = 0; i < subDataCount; i++) |
| 229 | { |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 230 | size_t offset = i * sliceSize; |
| 231 | glBufferSubData(GL_ARRAY_BUFFER, offset, sliceSize, &data[offset]); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 232 | } |
| 233 | |
Jamie Madill | cc6ac25 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 234 | verifyBuffer(data, GL_ARRAY_BUFFER); |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 235 | |
| 236 | EXPECT_GL_NO_ERROR(); |
| 237 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 238 | |
| 239 | // 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] | 240 | ANGLE_INSTANTIATE_TEST(SimpleOperationTest, |
| 241 | ES2_D3D9(), |
Austin Kinross | 2a63b3f | 2016-02-08 12:29:08 -0800 | [diff] [blame] | 242 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE), |
| 243 | ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE), |
Geoff Lang | e0cc2a4 | 2016-01-20 10:58:17 -0500 | [diff] [blame] | 244 | ES3_D3D11(), |
| 245 | ES2_OPENGL(), |
| 246 | ES3_OPENGL(), |
| 247 | ES2_OPENGLES(), |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 248 | ES3_OPENGLES(), |
| 249 | ES2_VULKAN()); |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 250 | |
| 251 | } // namespace |