blob: 40d12aaa341826fe8776b7a60a2359219c420d0d [file] [log] [blame]
Jamie Madillfa05f602015-05-07 13:47:11 -04001//
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 Wallezd3970de2015-05-14 11:07:48 -04009#include "test_utils/ANGLETest.h"
Geoff Langf1e85922015-02-23 14:40:04 -050010
11#include <vector>
12
Jamie Madillcc6ac252017-01-25 12:57:21 -080013#include "random_utils.h"
14#include "test_utils/gl_raii.h"
15
Jamie Madillfa05f602015-05-07 13:47:11 -040016using namespace angle;
Geoff Langf1e85922015-02-23 14:40:04 -050017
Jamie Madillfa05f602015-05-07 13:47:11 -040018namespace
19{
20
Geoff Langf1e85922015-02-23 14:40:04 -050021class SimpleOperationTest : public ANGLETest
22{
23 protected:
Jamie Madillfa05f602015-05-07 13:47:11 -040024 SimpleOperationTest()
Geoff Langf1e85922015-02-23 14:40:04 -050025 {
26 setWindowWidth(128);
27 setWindowHeight(128);
28 setConfigRedBits(8);
29 setConfigGreenBits(8);
30 setConfigBlueBits(8);
31 setConfigAlphaBits(8);
32 }
Jamie Madillcc6ac252017-01-25 12:57:21 -080033
34 void verifyBuffer(const std::vector<uint8_t> &data, GLenum binding);
Geoff Langf1e85922015-02-23 14:40:04 -050035};
36
Jamie Madillcc6ac252017-01-25 12:57:21 -080037void 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 Madillfa05f602015-05-07 13:47:11 -040055TEST_P(SimpleOperationTest, CompileVertexShader)
Geoff Langf1e85922015-02-23 14:40:04 -050056{
Olli Etuahoa20af6d2017-09-18 13:32:29 +030057 const std::string source =
58 R"(attribute vec4 a_input;
Geoff Langf1e85922015-02-23 14:40:04 -050059 void main()
60 {
61 gl_Position = a_input;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030062 })";
Geoff Langf1e85922015-02-23 14:40:04 -050063
64 GLuint shader = CompileShader(GL_VERTEX_SHADER, source);
65 EXPECT_NE(shader, 0u);
66 glDeleteShader(shader);
67
68 EXPECT_GL_NO_ERROR();
69}
70
Jamie Madillfa05f602015-05-07 13:47:11 -040071TEST_P(SimpleOperationTest, CompileFragmentShader)
Geoff Langf1e85922015-02-23 14:40:04 -050072{
Olli Etuahoa20af6d2017-09-18 13:32:29 +030073 const std::string source =
74 R"(precision mediump float;
Geoff Langf1e85922015-02-23 14:40:04 -050075 varying vec4 v_input;
76 void main()
77 {
78 gl_FragColor = v_input;
Olli Etuahoa20af6d2017-09-18 13:32:29 +030079 })";
Geoff Langf1e85922015-02-23 14:40:04 -050080
81 GLuint shader = CompileShader(GL_FRAGMENT_SHADER, source);
82 EXPECT_NE(shader, 0u);
83 glDeleteShader(shader);
84
85 EXPECT_GL_NO_ERROR();
86}
Geoff Langb1f435e2015-02-20 10:01:01 -050087
Jamie Madillefb5a5c2018-01-29 15:56:59 -050088// Covers a simple bug in Vulkan to do with dependencies between the Surface and the default
89// Framebuffer.
90TEST_P(SimpleOperationTest, ClearAndSwap)
91{
92 glClearColor(1.0, 0.0, 0.0, 1.0);
93 glClear(GL_COLOR_BUFFER_BIT);
94 swapBuffers();
95
96 // Can't check the pixel result after the swap, and checking the pixel result affects the
97 // behaviour of the test on the Vulkan back-end, so don't bother checking correctness.
98 EXPECT_GL_NO_ERROR();
99 EXPECT_EGL_SUCCESS();
100}
101
Jamie Madillfa05f602015-05-07 13:47:11 -0400102TEST_P(SimpleOperationTest, LinkProgram)
Geoff Langb1f435e2015-02-20 10:01:01 -0500103{
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300104 const std::string vsSource =
105 R"(void main()
Geoff Langb1f435e2015-02-20 10:01:01 -0500106 {
107 gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300108 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500109
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300110 const std::string fsSource =
111 R"(void main()
Geoff Langb1f435e2015-02-20 10:01:01 -0500112 {
113 gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300114 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500115
116 GLuint program = CompileProgram(vsSource, fsSource);
117 EXPECT_NE(program, 0u);
118 glDeleteProgram(program);
119
120 EXPECT_GL_NO_ERROR();
121}
122
Jamie Madillfa05f602015-05-07 13:47:11 -0400123TEST_P(SimpleOperationTest, LinkProgramWithUniforms)
Geoff Langb1f435e2015-02-20 10:01:01 -0500124{
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300125 const std::string vsSource =
126 R"(void main()
Geoff Langb1f435e2015-02-20 10:01:01 -0500127 {
128 gl_Position = vec4(1.0, 1.0, 1.0, 1.0);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300129 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500130
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300131 const std::string fsSource =
132 R"(precision mediump float;
Geoff Langb1f435e2015-02-20 10:01:01 -0500133 uniform vec4 u_input;
134 void main()
135 {
136 gl_FragColor = u_input;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300137 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500138
139 GLuint program = CompileProgram(vsSource, fsSource);
140 EXPECT_NE(program, 0u);
141
142 GLint uniformLoc = glGetUniformLocation(program, "u_input");
143 EXPECT_NE(-1, uniformLoc);
144
145 glDeleteProgram(program);
146
147 EXPECT_GL_NO_ERROR();
148}
149
Jamie Madillfa05f602015-05-07 13:47:11 -0400150TEST_P(SimpleOperationTest, LinkProgramWithAttributes)
Geoff Langb1f435e2015-02-20 10:01:01 -0500151{
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300152 const std::string vsSource =
153 R"(attribute vec4 a_input;
Geoff Langb1f435e2015-02-20 10:01:01 -0500154 void main()
155 {
156 gl_Position = a_input;
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300157 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500158
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300159 const std::string fsSource =
160 R"(void main()
Geoff Langb1f435e2015-02-20 10:01:01 -0500161 {
162 gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
Olli Etuahoa20af6d2017-09-18 13:32:29 +0300163 })";
Geoff Langb1f435e2015-02-20 10:01:01 -0500164
165 GLuint program = CompileProgram(vsSource, fsSource);
166 EXPECT_NE(program, 0u);
167
168 GLint attribLoc = glGetAttribLocation(program, "a_input");
169 EXPECT_NE(-1, attribLoc);
170
171 glDeleteProgram(program);
172
173 EXPECT_GL_NO_ERROR();
174}
Geoff Lang36c79012015-02-24 11:47:20 -0500175
Jamie Madillfa05f602015-05-07 13:47:11 -0400176TEST_P(SimpleOperationTest, BufferDataWithData)
Geoff Lang36c79012015-02-24 11:47:20 -0500177{
Jamie Madillcc6ac252017-01-25 12:57:21 -0800178 GLBuffer buffer;
179 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
Geoff Lang36c79012015-02-24 11:47:20 -0500180
181 std::vector<uint8_t> data(1024);
Jamie Madillcc6ac252017-01-25 12:57:21 -0800182 FillVectorWithRandomUBytes(&data);
Geoff Lang36c79012015-02-24 11:47:20 -0500183 glBufferData(GL_ARRAY_BUFFER, data.size(), &data[0], GL_STATIC_DRAW);
184
Jamie Madillcc6ac252017-01-25 12:57:21 -0800185 verifyBuffer(data, GL_ARRAY_BUFFER);
Geoff Lang36c79012015-02-24 11:47:20 -0500186
187 EXPECT_GL_NO_ERROR();
188}
189
Jamie Madillfa05f602015-05-07 13:47:11 -0400190TEST_P(SimpleOperationTest, BufferDataWithNoData)
Geoff Lang36c79012015-02-24 11:47:20 -0500191{
Jamie Madillcc6ac252017-01-25 12:57:21 -0800192 GLBuffer buffer;
193 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
Geoff Lang36c79012015-02-24 11:47:20 -0500194 glBufferData(GL_ARRAY_BUFFER, 1024, nullptr, GL_STATIC_DRAW);
Geoff Lang36c79012015-02-24 11:47:20 -0500195
196 EXPECT_GL_NO_ERROR();
197}
198
Jamie Madillfa05f602015-05-07 13:47:11 -0400199TEST_P(SimpleOperationTest, BufferSubData)
Geoff Lang36c79012015-02-24 11:47:20 -0500200{
Jamie Madillcc6ac252017-01-25 12:57:21 -0800201 GLBuffer buffer;
202 glBindBuffer(GL_ARRAY_BUFFER, buffer.get());
Geoff Lang36c79012015-02-24 11:47:20 -0500203
Jamie Madillcc6ac252017-01-25 12:57:21 -0800204 constexpr size_t bufferSize = 1024;
205 std::vector<uint8_t> data(bufferSize);
206 FillVectorWithRandomUBytes(&data);
207
Geoff Lang36c79012015-02-24 11:47:20 -0500208 glBufferData(GL_ARRAY_BUFFER, bufferSize, nullptr, GL_STATIC_DRAW);
209
Jamie Madillcc6ac252017-01-25 12:57:21 -0800210 constexpr size_t subDataCount = 16;
211 constexpr size_t sliceSize = bufferSize / subDataCount;
Geoff Lang36c79012015-02-24 11:47:20 -0500212 for (size_t i = 0; i < subDataCount; i++)
213 {
Jamie Madillcc6ac252017-01-25 12:57:21 -0800214 size_t offset = i * sliceSize;
215 glBufferSubData(GL_ARRAY_BUFFER, offset, sliceSize, &data[offset]);
Geoff Lang36c79012015-02-24 11:47:20 -0500216 }
217
Jamie Madillcc6ac252017-01-25 12:57:21 -0800218 verifyBuffer(data, GL_ARRAY_BUFFER);
Geoff Lang36c79012015-02-24 11:47:20 -0500219
220 EXPECT_GL_NO_ERROR();
221}
Jamie Madillfa05f602015-05-07 13:47:11 -0400222
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500223// Simple quad test.
224TEST_P(SimpleOperationTest, DrawQuad)
225{
226 const std::string &vertexShader =
227 "attribute vec3 position;\n"
228 "void main()\n"
229 "{\n"
230 " gl_Position = vec4(position, 1);\n"
231 "}";
232 const std::string &fragmentShader =
233 "void main()\n"
234 "{\n"
235 " gl_FragColor = vec4(0, 1, 0, 1);\n"
236 "}";
237 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
238
239 drawQuad(program.get(), "position", 0.5f, 1.0f, true);
240
241 EXPECT_GL_NO_ERROR();
242 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
243}
244
Jamie Madilld03a8492017-10-03 15:46:06 -0400245// Simple repeated draw and swap test.
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500246TEST_P(SimpleOperationTest, DrawQuadAndSwap)
247{
248 const std::string &vertexShader =
249 "attribute vec3 position;\n"
250 "void main()\n"
251 "{\n"
252 " gl_Position = vec4(position, 1);\n"
253 "}";
254 const std::string &fragmentShader =
255 "void main()\n"
256 "{\n"
257 " gl_FragColor = vec4(0, 1, 0, 1);\n"
258 "}";
259 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
260
261 for (int i = 0; i < 8; ++i)
262 {
263 drawQuad(program.get(), "position", 0.5f, 1.0f, true);
264 EXPECT_GL_NO_ERROR();
Jamie Madill4c26fc22017-02-24 11:04:10 -0500265 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
Jamie Madilldf68a6f2017-01-13 17:29:53 -0500266 swapBuffers();
267 }
268
269 EXPECT_GL_NO_ERROR();
270}
271
Jamie Madilld03a8492017-10-03 15:46:06 -0400272// Simple indexed quad test.
273TEST_P(SimpleOperationTest, DrawIndexedQuad)
274{
275 const std::string vertexShader =
276 "attribute vec3 position;\n"
277 "void main()\n"
278 "{\n"
279 " gl_Position = vec4(position, 1);\n"
280 "}";
281 const std::string fragmentShader =
282 "void main()\n"
283 "{\n"
284 " gl_FragColor = vec4(0, 1, 0, 1);\n"
285 "}";
286 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
287
288 drawIndexedQuad(program.get(), "position", 0.5f, 1.0f, true);
289
290 EXPECT_GL_NO_ERROR();
291 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
292}
293
Jamie Madill76e471e2017-10-21 09:56:01 -0400294// Draw with a fragment uniform.
295TEST_P(SimpleOperationTest, DrawQuadWithFragmentUniform)
296{
297 const std::string &vertexShader =
298 "attribute vec3 position;\n"
299 "void main()\n"
300 "{\n"
301 " gl_Position = vec4(position, 1);\n"
302 "}";
303 const std::string &fragmentShader =
304 "uniform mediump vec4 color;\n"
305 "void main()\n"
306 "{\n"
307 " gl_FragColor = color;\n"
308 "}";
309 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
310
311 GLint location = glGetUniformLocation(program, "color");
312 ASSERT_NE(-1, location);
313
314 glUseProgram(program);
315 glUniform4f(location, 0.0f, 1.0f, 0.0f, 1.0f);
316
317 drawQuad(program.get(), "position", 0.5f, 1.0f, true);
318
319 EXPECT_GL_NO_ERROR();
320 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
321}
322
323// Draw with a vertex uniform.
324TEST_P(SimpleOperationTest, DrawQuadWithVertexUniform)
325{
326 const std::string &vertexShader =
327 "attribute vec3 position;\n"
328 "uniform vec4 color;\n"
329 "varying vec4 vcolor;\n"
330 "void main()\n"
331 "{\n"
332 " gl_Position = vec4(position, 1);\n"
333 " vcolor = color;\n"
334 "}";
335 const std::string &fragmentShader =
336 "varying mediump vec4 vcolor;\n"
337 "void main()\n"
338 "{\n"
339 " gl_FragColor = vcolor;\n"
340 "}";
341 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
342
343 GLint location = glGetUniformLocation(program, "color");
344 ASSERT_NE(-1, location);
345
346 glUseProgram(program);
347 glUniform4f(location, 0.0f, 1.0f, 0.0f, 1.0f);
348
349 drawQuad(program.get(), "position", 0.5f, 1.0f, true);
350
351 EXPECT_GL_NO_ERROR();
352 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
353}
354
355// Draw with two uniforms.
356TEST_P(SimpleOperationTest, DrawQuadWithTwoUniforms)
357{
358 const std::string &vertexShader =
359 "attribute vec3 position;\n"
360 "uniform vec4 color1;\n"
361 "varying vec4 vcolor1;\n"
362 "void main()\n"
363 "{\n"
364 " gl_Position = vec4(position, 1);\n"
365 " vcolor1 = color1;\n"
366 "}";
367 const std::string &fragmentShader =
368 "uniform mediump vec4 color2;\n"
369 "varying mediump vec4 vcolor1;\n"
370 "void main()\n"
371 "{\n"
372 " gl_FragColor = vcolor1 + color2;\n"
373 "}";
374 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
375
376 GLint location1 = glGetUniformLocation(program, "color1");
377 ASSERT_NE(-1, location1);
378
379 GLint location2 = glGetUniformLocation(program, "color2");
380 ASSERT_NE(-1, location2);
381
382 glUseProgram(program);
383 glUniform4f(location1, 0.0f, 1.0f, 0.0f, 1.0f);
384 glUniform4f(location2, 1.0f, 0.0f, 0.0f, 1.0f);
385
386 drawQuad(program.get(), "position", 0.5f, 1.0f, true);
387
388 EXPECT_GL_NO_ERROR();
389 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::yellow);
390}
391
Jamie Madill2a9e1072017-09-22 11:31:57 -0400392// Tests a shader program with more than one vertex attribute, with vertex buffers.
393TEST_P(SimpleOperationTest, ThreeVertexAttributes)
394{
395 const std::string vertexShader =
396 R"(attribute vec2 position;
397attribute vec4 color1;
398attribute vec4 color2;
399varying vec4 color;
400void main()
401{
402 gl_Position = vec4(position, 0, 1);
403 color = color1 + color2;
404})";
405
406 const std::string fragmentShader =
407 R"(precision mediump float;
408varying vec4 color;
409void main()
410{
411 gl_FragColor = color;
412}
413)";
414
415 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
416
417 glUseProgram(program);
418
419 GLint color1Loc = glGetAttribLocation(program, "color1");
420 GLint color2Loc = glGetAttribLocation(program, "color2");
421 ASSERT_NE(-1, color1Loc);
422 ASSERT_NE(-1, color2Loc);
423
424 const auto &indices = GetQuadIndices();
425
426 // Make colored corners with red == x or 1 -x , and green = y or 1 - y.
427
428 std::array<GLColor, 4> baseColors1 = {
429 {GLColor::black, GLColor::red, GLColor::green, GLColor::yellow}};
430 std::array<GLColor, 4> baseColors2 = {
431 {GLColor::yellow, GLColor::green, GLColor::red, GLColor::black}};
432
433 std::vector<GLColor> colors1;
434 std::vector<GLColor> colors2;
435
436 for (GLushort index : indices)
437 {
438 colors1.push_back(baseColors1[index]);
439 colors2.push_back(baseColors2[index]);
440 }
441
442 GLBuffer color1Buffer;
443 glBindBuffer(GL_ARRAY_BUFFER, color1Buffer);
444 glBufferData(GL_ARRAY_BUFFER, colors1.size() * sizeof(GLColor), colors1.data(), GL_STATIC_DRAW);
445 glVertexAttribPointer(color1Loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, nullptr);
446 glEnableVertexAttribArray(color1Loc);
447
448 GLBuffer color2Buffer;
449 glBindBuffer(GL_ARRAY_BUFFER, color2Buffer);
450 glBufferData(GL_ARRAY_BUFFER, colors2.size() * sizeof(GLColor), colors2.data(), GL_STATIC_DRAW);
451 glVertexAttribPointer(color2Loc, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, nullptr);
452 glEnableVertexAttribArray(color2Loc);
453
454 // Draw a non-indexed quad with all vertex buffers. Should draw yellow to the entire window.
455 drawQuad(program, "position", 0.5f, 1.0f, true);
456 ASSERT_GL_NO_ERROR();
457 EXPECT_PIXEL_RECT_EQ(0, 0, getWindowWidth(), getWindowHeight(), GLColor::yellow);
458}
459
Jamie Madill035fd6b2017-10-03 15:43:22 -0400460// Creates a texture, no other operations.
461TEST_P(SimpleOperationTest, CreateTexture2DNoData)
462{
463 GLTexture texture;
464 glBindTexture(GL_TEXTURE_2D, texture);
465 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
466 ASSERT_GL_NO_ERROR();
467}
468
469// Creates a texture, no other operations.
470TEST_P(SimpleOperationTest, CreateTexture2DWithData)
471{
472 std::vector<GLColor> colors(16 * 16, GLColor::red);
473
474 GLTexture texture;
475 glBindTexture(GL_TEXTURE_2D, texture);
476 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors.data());
477 ASSERT_GL_NO_ERROR();
478}
479
Jamie Madillde03e002017-10-21 14:04:20 -0400480// Creates a program with a texture.
481TEST_P(SimpleOperationTest, LinkProgramWithTexture)
482{
483 ASSERT_NE(0u, get2DTexturedQuadProgram());
484 EXPECT_GL_NO_ERROR();
485}
486
Jamie Madill5547b382017-10-23 18:16:01 -0400487// Creates a program with a texture and renders with it.
488TEST_P(SimpleOperationTest, DrawWithTexture)
489{
490 std::array<GLColor, 4> colors = {
491 {GLColor::red, GLColor::green, GLColor::blue, GLColor::yellow}};
492
493 GLTexture tex;
494 glBindTexture(GL_TEXTURE_2D, tex);
495 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, colors.data());
496 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
497 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
498
499 draw2DTexturedQuad(0.5f, 1.0f, true);
500 EXPECT_GL_NO_ERROR();
501
502 int w = getWindowWidth() - 2;
503 int h = getWindowHeight() - 2;
504
505 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::red);
506 EXPECT_PIXEL_COLOR_EQ(w, 0, GLColor::green);
507 EXPECT_PIXEL_COLOR_EQ(0, h, GLColor::blue);
508 EXPECT_PIXEL_COLOR_EQ(w, h, GLColor::yellow);
509}
510
Jamie Madillb79e7bb2017-10-24 13:55:50 -0400511// Tests rendering to a user framebuffer.
512TEST_P(SimpleOperationTest, RenderToTexture)
513{
514 constexpr int kSize = 16;
515
516 GLTexture texture;
517 glBindTexture(GL_TEXTURE_2D, texture);
518 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kSize, kSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
519 ASSERT_GL_NO_ERROR();
520
521 GLFramebuffer framebuffer;
522 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
523 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
524 ASSERT_GL_NO_ERROR();
525 ASSERT_GLENUM_EQ(GL_FRAMEBUFFER_COMPLETE, glCheckFramebufferStatus(GL_FRAMEBUFFER));
526
527 glViewport(0, 0, kSize, kSize);
528
529 const std::string &vertexShader =
530 "attribute vec3 position;\n"
531 "void main()\n"
532 "{\n"
533 " gl_Position = vec4(position, 1);\n"
534 "}";
535 const std::string &fragmentShader =
536 "void main()\n"
537 "{\n"
538 " gl_FragColor = vec4(0, 1, 0, 1);\n"
539 "}";
540 ANGLE_GL_PROGRAM(program, vertexShader, fragmentShader);
541 drawQuad(program, "position", 0.5f, 1.0f, true);
542 ASSERT_GL_NO_ERROR();
543 EXPECT_PIXEL_COLOR_EQ(0, 0, GLColor::green);
544}
545
Jamie Madillfa05f602015-05-07 13:47:11 -0400546// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
Geoff Lange0cc2a42016-01-20 10:58:17 -0500547ANGLE_INSTANTIATE_TEST(SimpleOperationTest,
548 ES2_D3D9(),
Austin Kinross2a63b3f2016-02-08 12:29:08 -0800549 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_COPY_ANGLE),
550 ES2_D3D11(EGL_EXPERIMENTAL_PRESENT_PATH_FAST_ANGLE),
Geoff Lange0cc2a42016-01-20 10:58:17 -0500551 ES3_D3D11(),
552 ES2_OPENGL(),
553 ES3_OPENGL(),
554 ES2_OPENGLES(),
Jamie Madillb8353b02017-01-25 12:57:21 -0800555 ES3_OPENGLES(),
556 ES2_VULKAN());
Jamie Madillfa05f602015-05-07 13:47:11 -0400557
558} // namespace