vulkan_test2

annotate src/main.c @ 16:236f923a00a3

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