summaryrefslogtreecommitdiff
path: root/main/main.cpp
blob: 06455527d6e0af257567a60b898bd0169c2c20e6 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <deimos/core/api_registry.h>
#include <deimos/core/log.h>
#include <deimos/core/temp_allocator.h>
#include <deimos/core/os.h>
#include <deimos/core/status.h>
#include <deimos/vulkan/vulkan_loader.h>
#include <deimos/vulkan/vulkan_backend.h>
#include <deimos/render/backend.h>

using namespace deimos;

static LogApi* log_api;
static AllocatorApi* allocator_api;
static OsApi* os_api;
static VulkanBackendApi* vulkan_backend_api;

int main(int /* argc */, char* /* argv */[])
{
    auto* api_registry = InitializeGlobalApiRegistry();
    
    log_api = api_registry->Get<LogApi>();
    allocator_api = api_registry->Get<AllocatorApi>();
    os_api = api_registry->Get<OsApi>();
    log_api->LogInfo("Base APIs registered");
    
    RegisterVulkanLoaderApi(api_registry);
    RegisterVulkanBackendApi(api_registry);
    vulkan_backend_api = api_registry->Get<VulkanBackendApi>();

    OsWindow* window{};
    {
        auto s = os_api->window->Create("Deimos", 1280, 720);
        if (!s.ok())
        {
            log_api->LogError("Window error: $", s);
            return 1;
        }
        window = s.value();
    }

    IVulkanBackend* vulkan = nullptr;
    {
        StatusOr<IVulkanBackend*> s = vulkan_backend_api->CreateBackend(allocator_api->system, window);
        if (!s.ok())
        {
            log_api->LogError("Vulkan initialization error: $", s);
            return 1;
        }
        vulkan = s.value();
        log_api->LogInfo("Vulkan backend created");
    }

    IRenderBackend* render = vulkan->AsRenderBackend();
    
    RenderSwapchain* swapchain = nullptr;
    {
        auto s = render->CreateSwapchain();
        if (!s.ok())
        {
            log_api->LogError("Swapchain creation error: $", s);
            return 1;
        }
        swapchain = s.value();
        log_api->LogInfo("Swapchain created");
    }

    while (!os_api->window->QuitRequested(window))
    {
        os_api->window->Update(window);
        render->BeginFrame();
        render->EndFrame();
    }

    log_api->LogInfo("Goodbye");

    return 0;
}