vkcore_rs/
lib.rs

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