vulkan_test2

annotate src/main.c @ 13:d34f84bede17

pipeline madness
author John Tsiombikas <nuclear@member.fsf.org>
date Mon, 25 Jun 2018 08:00:57 +0300
parents 20eb42197ab8
children 196122a2b8c2
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@4 58 wsys_swap_buffers();
nuclear@4 59 }
nuclear@4 60
nuclear@4 61 static void reshape(int x, int y)
nuclear@4 62 {
nuclear@4 63 }
nuclear@4 64
nuclear@4 65 static void keyboard(int key, int pressed)
nuclear@4 66 {
nuclear@4 67 if(key == 27) {
nuclear@4 68 wsys_quit();
nuclear@4 69 }
nuclear@4 70 }