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 | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 13 | using namespace angle; |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 14 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 15 | namespace |
| 16 | { |
| 17 | |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 18 | class SimpleOperationTest : public ANGLETest |
| 19 | { |
| 20 | protected: |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 21 | SimpleOperationTest() |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 22 | { |
| 23 | setWindowWidth(128); |
| 24 | setWindowHeight(128); |
| 25 | setConfigRedBits(8); |
| 26 | setConfigGreenBits(8); |
| 27 | setConfigBlueBits(8); |
| 28 | setConfigAlphaBits(8); |
| 29 | } |
| 30 | }; |
| 31 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 32 | TEST_P(SimpleOperationTest, CompileVertexShader) |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 33 | { |
| 34 | const std::string source = SHADER_SOURCE |
| 35 | ( |
| 36 | attribute vec4 a_input; |
| 37 | void main() |
| 38 | { |
| 39 | gl_Position = a_input; |
| 40 | } |
| 41 | ); |
| 42 | |
| 43 | GLuint shader = CompileShader(GL_VERTEX_SHADER, source); |
| 44 | EXPECT_NE(shader, 0u); |
| 45 | glDeleteShader(shader); |
| 46 | |
| 47 | EXPECT_GL_NO_ERROR(); |
| 48 | } |
| 49 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 50 | TEST_P(SimpleOperationTest, CompileFragmentShader) |
Geoff Lang | f1e8592 | 2015-02-23 14:40:04 -0500 | [diff] [blame] | 51 | { |
| 52 | const std::string source = SHADER_SOURCE |
| 53 | ( |
| 54 | precision mediump float; |
| 55 | varying vec4 v_input; |
| 56 | void main() |
| 57 | { |
| 58 | gl_FragColor = v_input; |
| 59 | } |
| 60 | ); |
| 61 | |
| 62 | GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source); |
| 63 | EXPECT_NE(shader, 0u); |
| 64 | glDeleteShader(shader); |
| 65 | |
| 66 | EXPECT_GL_NO_ERROR(); |
| 67 | } |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 68 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 69 | TEST_P(SimpleOperationTest, LinkProgram) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 70 | { |
| 71 | const std::string vsSource = SHADER_SOURCE |
| 72 | ( |
| 73 | void main() |
| 74 | { |
| 75 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 76 | } |
| 77 | ); |
| 78 | |
| 79 | const std::string fsSource = SHADER_SOURCE |
| 80 | ( |
| 81 | void main() |
| 82 | { |
| 83 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 84 | } |
| 85 | ); |
| 86 | |
| 87 | GLuint program = CompileProgram(vsSource, fsSource); |
| 88 | EXPECT_NE(program, 0u); |
| 89 | glDeleteProgram(program); |
| 90 | |
| 91 | EXPECT_GL_NO_ERROR(); |
| 92 | } |
| 93 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 94 | TEST_P(SimpleOperationTest, LinkProgramWithUniforms) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 95 | { |
| 96 | const std::string vsSource = SHADER_SOURCE |
| 97 | ( |
| 98 | void main() |
| 99 | { |
| 100 | gl_Position = vec4(1.0, 1.0, 1.0, 1.0); |
| 101 | } |
| 102 | ); |
| 103 | |
| 104 | const std::string fsSource = SHADER_SOURCE |
| 105 | ( |
| 106 | precision mediump float; |
| 107 | uniform vec4 u_input; |
| 108 | void main() |
| 109 | { |
| 110 | gl_FragColor = u_input; |
| 111 | } |
| 112 | ); |
| 113 | |
| 114 | GLuint program = CompileProgram(vsSource, fsSource); |
| 115 | EXPECT_NE(program, 0u); |
| 116 | |
| 117 | GLint uniformLoc = glGetUniformLocation(program, "u_input"); |
| 118 | EXPECT_NE(-1, uniformLoc); |
| 119 | |
| 120 | glDeleteProgram(program); |
| 121 | |
| 122 | EXPECT_GL_NO_ERROR(); |
| 123 | } |
| 124 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 125 | TEST_P(SimpleOperationTest, LinkProgramWithAttributes) |
Geoff Lang | b1f435e | 2015-02-20 10:01:01 -0500 | [diff] [blame] | 126 | { |
| 127 | const std::string vsSource = SHADER_SOURCE |
| 128 | ( |
| 129 | attribute vec4 a_input; |
| 130 | void main() |
| 131 | { |
| 132 | gl_Position = a_input; |
| 133 | } |
| 134 | ); |
| 135 | |
| 136 | const std::string fsSource = SHADER_SOURCE |
| 137 | ( |
| 138 | void main() |
| 139 | { |
| 140 | gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); |
| 141 | } |
| 142 | ); |
| 143 | |
| 144 | GLuint program = CompileProgram(vsSource, fsSource); |
| 145 | EXPECT_NE(program, 0u); |
| 146 | |
| 147 | GLint attribLoc = glGetAttribLocation(program, "a_input"); |
| 148 | EXPECT_NE(-1, attribLoc); |
| 149 | |
| 150 | glDeleteProgram(program); |
| 151 | |
| 152 | EXPECT_GL_NO_ERROR(); |
| 153 | } |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 154 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 155 | TEST_P(SimpleOperationTest, BufferDataWithData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 156 | { |
| 157 | GLuint buffer; |
| 158 | glGenBuffers(1, &buffer); |
| 159 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
| 160 | |
| 161 | std::vector<uint8_t> data(1024); |
| 162 | glBufferData(GL_ARRAY_BUFFER, data.size(), &data[0], GL_STATIC_DRAW); |
| 163 | |
| 164 | glDeleteBuffers(1, &buffer); |
| 165 | |
| 166 | EXPECT_GL_NO_ERROR(); |
| 167 | } |
| 168 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 169 | TEST_P(SimpleOperationTest, BufferDataWithNoData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 170 | { |
| 171 | GLuint buffer; |
| 172 | glGenBuffers(1, &buffer); |
| 173 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
| 174 | glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW); |
| 175 | glDeleteBuffers(1, &buffer); |
| 176 | |
| 177 | EXPECT_GL_NO_ERROR(); |
| 178 | } |
| 179 | |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 180 | TEST_P(SimpleOperationTest, BufferSubData) |
Geoff Lang | 36c7901 | 2015-02-24 11:47:20 -0500 | [diff] [blame] | 181 | { |
| 182 | GLuint buffer; |
| 183 | glGenBuffers(1, &buffer); |
| 184 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
| 185 | |
| 186 | const size_t bufferSize = 1024; |
| 187 | glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW); |
| 188 | |
| 189 | const size_t subDataCount = 16; |
| 190 | std::vector<uint8_t> data(bufferSize / subDataCount); |
| 191 | for (size_t i = 0; i < subDataCount; i++) |
| 192 | { |
| 193 | glBufferSubData(GL_ARRAY_BUFFER, data.size() * i, data.size(), &data[0]); |
| 194 | } |
| 195 | |
| 196 | glDeleteBuffers(1, &buffer); |
| 197 | |
| 198 | EXPECT_GL_NO_ERROR(); |
| 199 | } |
Jamie Madill | fa05f60 | 2015-05-07 13:47:11 -0400 | [diff] [blame] | 200 | |
| 201 | // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. |
| 202 | ANGLE_INSTANTIATE_TEST( |
| 203 | SimpleOperationTest, |
| 204 | ES2_D3D9(), ES2_D3D11(), ES3_D3D11(), ES2_OPENGL(), ES3_OPENGL()); |
| 205 | |
| 206 | } // namespace |