Advertisement
Skytrias

odin vulkan fails at instance creation ^cstring at fault

Aug 13th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.81 KB | None | 0 0
  1. package main
  2.  
  3. import glfw "shared:odin-glfw"
  4. import fmt "core:fmt"
  5. import vk "shared:odin-vulkan"
  6.  
  7. main :: proc() {
  8.     window := init_window(500, 500, "hi");
  9.    
  10.     fmt.println("start");
  11.    
  12.     instance := create_instance();
  13.     defer vk.destroy_instance(instance, nil);
  14.    
  15.     fmt.println("end");
  16.    
  17.     for !glfw.window_should_close(window) {
  18.         glfw.poll_events();
  19.     }
  20. }
  21.  
  22. init_window :: proc(width, height: int, title: string) -> glfw.Window_Handle {
  23.     error_callback :: proc"c"(error: i32, desc: cstring) {
  24.         fmt.printf("Error code %d: %s\n", error, desc);
  25.     }
  26.    
  27.     glfw.set_error_callback(error_callback);
  28.    
  29.     glfw.init();
  30.    
  31.     glfw.window_hint(glfw.CLIENT_API, cast(int) glfw.NO_API);
  32.     glfw.window_hint(glfw.RESIZABLE, cast(int) glfw.FALSE);
  33.    
  34.     window := glfw.create_window(width, height, title, nil, nil);
  35.     if window == nil do panic("window couldnt be created");
  36.    
  37.     return window;
  38. }
  39.  
  40. // c macro to check the result of a create call
  41. VK_CHECK :: proc(call: vk.Result) {
  42.     assert(call == vk.Result.Success);
  43. }
  44.  
  45. // c macro to create a vulkan api version
  46. vk_make_version :: proc(major, minor, patch: u32) -> u32 {
  47.     return (((major) << 22) | ((minor) << 12) | (patch));
  48. }
  49.  
  50. debug_layers := [1]cstring {
  51.     "VK_LAYER_LUNARG_standard_validation",
  52. };
  53.  
  54. create_instance :: proc() -> vk.Instance {
  55.     using vk;
  56.    
  57.     app_info: ApplicationInfo;
  58.     app_info.sType = StructureType.ApplicationInfo;
  59.     app_info.apiVersion = API_VERSION_1_1;
  60.    
  61.     create_info: InstanceCreateInfo;
  62.     create_info.sType = StructureType.InstanceCreateInfo;
  63.     create_info.pApplicationInfo = &app_info;
  64.    
  65.     // without these we can normally compile
  66.     create_info.ppEnabledLayerNames = &debug_layers[0];
  67.     create_info.enabledLayerCount = len(debug_layers);
  68.  
  69.     instance: vk.Instance;
  70.     VK_CHECK(vk.create_instance(&create_info, nil, &instance));
  71.    
  72.     return instance;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement