1pub mod vkcore;
2pub use vkcore::*;
3
4#[cfg(test)]
5mod tests {
6 use std::{
7 ffi::{c_void, CString},
8 ptr::null,
9 };
10 use glfw::{Action, Context, Key, SwapInterval};
11 use crate::vkcore::*;
12
13 unsafe extern "C" {
14 fn glfwGetInstanceProcAddress(instance: VkInstance, procname: *const i8) -> *const c_void;
15 }
16
17 const TEST_TIME: f64 = 10.0;
18
19 #[test]
20 fn test() {
21 let test_time: Option<f64> = Some(TEST_TIME);
22 let mut glfw = glfw::init(glfw::fail_on_errors).unwrap();
23 glfw.window_hint(WindowHint::ClientApi(ClientApiHint::NoApi));
24 let (mut window, events) = glfw.create_window(1024, 768, "GLFW Window", glfw::WindowMode::Windowed).expect("Failed to create VKFW window.");
25
26 window.set_key_polling(true);
27
28 let app_name = CString::new("vkcore-rs test").unwrap();
29 let engine_name = CString::new("vkcore-rs").unwrap();
30 let app_info = VkApplicationInfo {
31 sType: VkStructureType::VK_STRUCTURE_TYPE_APPLICATION_INFO,
32 pNext: null(),
33 pApplicationName: app_name.as_ptr(),
34 applicationVersion: vk_make_version(1, 0, 0),
35 pEngineName: engine_name.as_ptr(),
36 engineVersion: vk_make_version(1, 0, 0),
37 apiVersion: VK_API_VERSION_1_0,
38 };
39 let vkcore = VkCore::new(app_info, |instance, proc_name|unsafe {glfwGetInstanceProcAddress(instance, CString::new(proc_name).unwrap().as_ptr())});
40 dbg!(vkcore);
41
42 let start_time = glfw.get_time();
43 while !window.should_close() {
44 let cur_frame_time = glfw.get_time();
45
46 window.swap_buffers();
47 glfw.poll_events();
48 for (_, event) in glfw::flush_messages(&events) {
49 match event {
50 glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
51 window.set_should_close(true)
52 }
53 _ => {}
54 }
55 }
56 if let Some(test_time) = test_time {
57 if cur_frame_time - start_time >= test_time {
58 window.set_should_close(true)
59 }
60 }
61 }
62 }
63}