vulkan_test2

view src/main.c @ 15:196122a2b8c2

...
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 26 Jun 2018 08:39:30 +0300
parents d34f84bede17
children f8bd29f124a8
line source
1 #include <stdio.h>
2 #include "wsys.h"
3 #include "vku.h"
4 #include "vkpipe.h"
5 #include "vkgl.h"
7 static void display(void);
8 static void reshape(int x, int y);
9 static void keyboard(int key, int pressed);
11 static struct vku_pipeline pipeline;
12 static VkShaderModule vsdr, psdr;
14 int main(void)
15 {
16 if(vku_create_dev() == -1) {
17 return 1;
18 }
20 if(wsys_create_window(800, 600) == -1) {
21 return 1;
22 }
23 wsys_set_window_title("Vulkan test 2");
25 wsys_display_callback(display);
26 wsys_reshape_callback(reshape);
27 wsys_keyboard_callback(keyboard);
29 wsys_process_events(WSYS_NONBLOCK);
31 if(!(vsdr = vku_load_shader("sdr/vertex.spv")) ||
32 !(psdr = vku_load_shader("sdr/pixel.spv"))) {
33 return 1;
34 }
36 vku_init_pipeline(&pipeline);
37 vku_pipeline_shader(&pipeline, vsdr, VK_SHADER_STAGE_VERTEX_BIT);
38 vku_pipeline_shader(&pipeline, psdr, VK_SHADER_STAGE_FRAGMENT_BIT);
39 vku_pipeline_viewport(&pipeline, 0, 0, 800, 600);
40 vku_pipeline_renderpass(&pipeline, vkrpass);
41 if(!vku_create_pipeline(&pipeline)) {
42 return 1;
43 }
46 while(wsys_process_events(WSYS_BLOCKING) != -1);
48 wsys_destroy_window();
49 vku_cleanup();
50 return 0;
51 }
53 static void display(void)
54 {
55 vkgl_clear_color(1, 0, 0, 1);
56 vkgl_clear(VKGL_COLOR_BUFFER_BIT);
58 vku_begin_cmdbuf(vkcmdbuf, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT);
59 vku_begin_renderpass(vkcmdbuf, vkrpass, swapchain_framebuf[next_swapchain_image],
60 VK_SUBPASS_CONTENTS_INLINE);
61 vkCmdBindPipeline(vkcmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline.pipeline);
62 vkCmdDraw(vkcmdbuf, 3, 1, 0, 0);
63 vku_end_renderpass(vkcmdbuf);
64 vku_end_cmdbuf(vkcmdbuf);
66 vku_submit_cmdbuf(vkq, vkcmdbuf, 0);
68 wsys_swap_buffers();
69 }
71 static void reshape(int x, int y)
72 {
73 }
75 static void keyboard(int key, int pressed)
76 {
77 if(key == 27) {
78 wsys_quit();
79 }
80 }