summaryrefslogtreecommitdiffstats
path: root/src/base/base_render.cpp
blob: bea119fb74e32c2ee3b8b9d045d16317b6465d5a (plain) (blame)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
internal void
vk_render_entrypoint(Engine *engine, MemArena *arena)
{
    
    breakpoint();
    
    {
        // TODO: create a window using the platform layer
    }
    
    VkApplicationInfo    app_info{};
    VkInstanceCreateInfo create_info{};
    
    //  fill in app info
    {
        app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
        app_info.pApplicationName = engine->name;
        app_info.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
        app_info.pEngineName = "TB Engine";
        app_info.engineVersion = VK_MAKE_VERSION(1, 0, 0);
        app_info.apiVersion = VK_API_VERSION_1_0;
    }
    
    // fill in create info
    {
        create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
        create_info.pApplicationInfo = &app_info;
        
#if 0
        // TODO: fill in the extenions for windows.
        // where do we find these?
        create_info.enabledExtensionCount   = ...;
        create_info.ppEnabledExtensionNames = ...;
#endif
    }
    
    
#ifdef  BASE_DEBUG
    bool enable_validation_layer = true;
#else
    bool enable_validation_layer = false;
#endif
    
    
    bool layer_found  = false;
    // check validation support
    ScratchArena scratch = scratch_start(arena);
    
    
    // gather the validation layers and available layers
    u32 layer_count;
    vkEnumerateInstanceLayerProperties(&layer_count, NULL);
    VkLayerProperties *available_layers;
    String8List       *validation_layers = PushStructZero(arena, String8List);
    String8Node vk_layer_khronos_validation_node = ToString8Node(str8("VK_LAYER_KHRONOS_validation"));
    str8_list_push_node(validation_layers, &vk_layer_khronos_validation_node);
    available_layers = PushArrayZero(arena, VkLayerProperties, layer_count);
    vkEnumerateInstanceLayerProperties(&layer_count, available_layers);
    
    for(String8Node *current_node = validation_layers->first; !is_nil_str8_node(current_node); current_node = current_node->next)
    {
        for(u32 index = 0; index < layer_count; ++index)
        {
            VkLayerProperties *current_layer = &available_layers[index];
            String8 current_layer_name = str8(current_layer->layerName);
            if(str8_is_match(current_node->value, current_layer_name))
            {
                layer_found = true;
                break;
            }
        }
    }
    
    // check if we found that specific layer and we can continue
    
    if(enable_validation_layer) // check the avalaiobe layers after creating the instance
    {
        if(!layer_found)
        {
            Log("requested validation layer not found!");
        }
        
        
        // extract names, null terminated
        String8 *names_in_one_str8_lit = PushStructZero(arena, String8);
        for(u32 index = 0; index < layer_count; ++index)
        {
            VkLayerProperties *current_layer = &available_layers[index];
            String8 current_layer_name;
            if(current_layer != NULL)
            {
                current_layer_name       = str8(current_layer->layerName);
            }
            else
            {
                breakpoint();
            }
            str8_append(names_in_one_str8_lit, &current_layer_name);
        }
        
        create_info.enabledLayerCount   = layer_count;
        create_info.ppEnabledLayerNames = (const char *const *)names_in_one_str8_lit->data; // TODO: maybe use the String8 to get a single buffer that we can pass to available layers
        breakpoint();
        
    }
    
    
    
    VkInstance instance = VK_NULL_HANDLE;
    VkResult result = vkCreateInstance(&create_info, NULL, &instance);
    
    if(result != VK_SUCCESS) // check the return code of the instance creation
    {
        Log("Failed to create a VkInstance");
    }
    else
    {
        scratch_end(&scratch);
        
        {
            // TODO: window polling untill it closes
        }
    }
    
    if(instance != VK_NULL_HANDLE)
    {
        vkDestroyInstance(instance, nullptr);
    }
}