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
9 #include "test_utils/ANGLETest.h"
10
11 #include <vector>
12
13 using namespace angle;
14
15 namespace
16 {
17
18 class SimpleOperationTest : public ANGLETest
19 {
20 protected:
SimpleOperationTest()21 SimpleOperationTest()
22 {
23 setWindowWidth(128);
24 setWindowHeight(128);
25 setConfigRedBits(8);
26 setConfigGreenBits(8);
27 setConfigBlueBits(8);
28 setConfigAlphaBits(8);
29 }
30 };
31
TEST_P(SimpleOperationTest,CompileVertexShader)32 TEST_P(SimpleOperationTest, CompileVertexShader)
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
TEST_P(SimpleOperationTest,CompileFragmentShader)50 TEST_P(SimpleOperationTest, CompileFragmentShader)
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 }
68
TEST_P(SimpleOperationTest,LinkProgram)69 TEST_P(SimpleOperationTest, LinkProgram)
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
TEST_P(SimpleOperationTest,LinkProgramWithUniforms)94 TEST_P(SimpleOperationTest, LinkProgramWithUniforms)
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
TEST_P(SimpleOperationTest,LinkProgramWithAttributes)125 TEST_P(SimpleOperationTest, LinkProgramWithAttributes)
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 }
154
TEST_P(SimpleOperationTest,BufferDataWithData)155 TEST_P(SimpleOperationTest, BufferDataWithData)
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
TEST_P(SimpleOperationTest,BufferDataWithNoData)169 TEST_P(SimpleOperationTest, BufferDataWithNoData)
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
TEST_P(SimpleOperationTest,BufferSubData)180 TEST_P(SimpleOperationTest, BufferSubData)
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 }
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(SimpleOperationTest,
203 ES2_D3D9(),
204 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE),
205 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE),
206 ES3_D3D11(),
207 ES2_OPENGL(),
208 ES3_OPENGL(),
209 ES2_OPENGLES(),
210 ES3_OPENGLES());
211
212 } // namespace
213