Created
February 17, 2016 11:19
-
-
Save tomaka/8b6ac2ded718fa70cfef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
let app = vulkano::instance::ApplicationInfo { application_name: "test", application_version: 1, engine_name: "test", engine_version: 1 }; | |
let instance = vulkano::instance::Instance::new(Some(&app), None).expect("failed to create instance"); | |
let physical = vulkano::instance::PhysicalDevice::enumerate(&instance) | |
.next().expect("no device available"); | |
println!("Using device: {} (type: {:?})", physical.name(), physical.ty()); | |
let window = unsafe { create_window() }; | |
let (width, height) = unsafe { | |
let mut rect: winapi::RECT = mem::uninitialized(); | |
user32::GetClientRect(window, &mut rect); | |
((rect.right - rect.left) as u32, (rect.bottom - rect.top) as u32) | |
}; | |
let surface = unsafe { vulkano::swapchain::Surface::from_hwnd(&instance, kernel32::GetModuleHandleW(ptr::null()), window).unwrap() }; | |
println!("{:?}", surface.get_capabilities(&physical)); | |
let queue = physical.queue_families().find(|q| q.supports_graphics() && | |
surface.is_supported(q).unwrap_or(false)) | |
.expect("couldn't find a graphical queue family"); | |
let (device, queues) = vulkano::device::Device::new(&physical, | |
&vulkano::instance::Features::none(), | |
[(queue, 0.5)].iter().cloned()) | |
.expect("failed to create device"); | |
let queue = queues.into_iter().next().unwrap(); | |
let swapchain = vulkano::swapchain::Swapchain::new(&device, &surface, 3, | |
vulkano::formats::B8G8R8A8Srgb, [1244, 699], | |
1, vulkano::swapchain::SurfaceTransform::Identity, | |
vulkano::swapchain::CompositeAlpha::Opaque, | |
vulkano::swapchain::PresentMode::Immediate, | |
true).expect("failed to create swapchain"); | |
let renderpass = renderpass!{ | |
device: &device, | |
attachments: { | |
color [Clear] | |
} | |
}.unwrap(); | |
let cb_pool = vulkano::command_buffer::CommandBufferPool::new(&device, &queue.lock().unwrap().family()) | |
.expect("failed to create command buffer pool"); | |
let command_buffer = vulkano::command_buffer::PrimaryCommandBufferBuilder::new(&cb_pool).unwrap() | |
// TODO: | |
/*.draw() | |
.draw_end()*/ | |
.build().unwrap(); | |
loop { | |
let mut queue = queue.lock().unwrap(); | |
command_buffer.submit(&mut queue).unwrap(); | |
// TODO: present | |
drop(queue); | |
unsafe { | |
let mut msg = mem::uninitialized(); | |
if user32::GetMessageW(&mut msg, ptr::null_mut(), 0, 0) == 0 { | |
break; | |
} | |
user32::TranslateMessage(&msg); | |
user32::DispatchMessageW(&msg); | |
} | |
thread::sleep_ms(16); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment