vkcore_rs/
lib.rs

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		let (mut window, events) = glfw.create_window(1024, 768, "GLFW Window", glfw::WindowMode::Windowed).expect("Failed to create VKFW window.");
24
25		window.set_key_polling(true);
26		window.make_current();
27		glfw.set_swap_interval(SwapInterval::Adaptive);
28
29		let app_name = CString::new("vkcore-rs test").unwrap();
30		let engine_name = CString::new("vkcore-rs").unwrap();
31		let app_info = VkApplicationInfo {
32			sType: VkStructureType::VK_STRUCTURE_TYPE_APPLICATION_INFO,
33			pNext: null(),
34			pApplicationName: app_name.as_ptr(),
35			applicationVersion: vk_make_version(1, 0, 0),
36			pEngineName: engine_name.as_ptr(),
37			engineVersion: vk_make_version(1, 0, 0),
38			apiVersion: VK_API_VERSION_1_0,
39		};
40		let vkcore = VkCore::new(app_info, |instance, proc_name|unsafe {glfwGetInstanceProcAddress(instance, CString::new(proc_name).unwrap().as_ptr())});
41		dbg!(vkcore);
42
43		let start_time = glfw.get_time();
44		while !window.should_close() {
45			let cur_frame_time = glfw.get_time();
46
47			window.swap_buffers();
48			glfw.poll_events();
49			for (_, event) in glfw::flush_messages(&events) {
50				match event {
51					glfw::WindowEvent::Key(Key::Escape, _, Action::Press, _) => {
52						window.set_should_close(true)
53					}
54					_ => {}
55				}
56			}
57			if let Some(test_time) = test_time {
58				if cur_frame_time - start_time >= test_time {
59					window.set_should_close(true)
60				}
61			}
62		}
63	}
64}