blank.engine.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <planet/log.hpp>
#include <planet/vk/engine/blank.hpp>
#include <planet/vk/engine/renderer.hpp>


using namespace std::literals;


namespace {
    struct blanking {
        planet::vk::engine::app &app;
        planet::vk::engine::renderer &renderer;
        planet::vk::colour colour;

        bool active = true;

        felspar::coro::task<void> loop() {
            while (active) {
                co_await renderer.start(colour);
                renderer.submit_and_present();
                co_await app.sdl.io.sleep(10ms);
            }
        }
    };
}


felspar::coro::task<void> planet::vk::engine::blank(
        planet::vk::engine::app &app,
        planet::vk::engine::renderer &renderer,
        planet::vk::colour const &colour) {
    planet::log::debug("Starting GPU blank");
    blanking blank{app, renderer, colour};
    felspar::coro::eager<> loop;
    loop.post(blank, &blanking::loop);
    co_await renderer.full_render_cycle();
    blank.active = false;
    co_await std::move(loop).release();
    planet::log::debug("Completed GPU blank");
}