Skip to content

Commit 443d116

Browse files
committed
Added Vulkan support
1 parent 4bb6b9a commit 443d116

File tree

4 files changed

+676
-15
lines changed

4 files changed

+676
-15
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,55 @@ fn main() {
459459
This method is useful when you don't care about sdl2's render capabilities, but you do care about
460460
its audio, controller and other neat features that sdl2 has.
461461

462+
# Vulkan
463+
464+
To use Vulkan, you need a Vulkan library for Rust. This example uses the [Vulkano][vulkano]
465+
library. Other libraries may use different data types for raw Vulkan object handles. The
466+
procedure to interface SDL2's Vulkan functions with these will be different for each one.
467+
468+
```rust
469+
extern crate sdl2;
470+
extern crate vulkano;
471+
472+
use sdl2::event::Event;
473+
use sdl2::keyboard::Keycode;
474+
use std::ffi::CString;
475+
use vulkano::VulkanObject;
476+
use vulkano::instance::{Instance, RawInstanceExtensions};
477+
use vulkano::swapchain::Surface;
478+
479+
fn main() {
480+
let sdl_context = sdl2::init().unwrap();
481+
let video_subsystem = sdl_context.video().unwrap();
482+
483+
let window = video_subsystem.window("Window", 800, 600)
484+
.vulkan()
485+
.build()
486+
.unwrap();
487+
488+
let instance_extensions = window.vulkan_instance_extensions().unwrap();
489+
let raw_instance_extensions = RawInstanceExtensions::new(instance_extensions.iter().map(|&v| CString::new(v).unwrap()));
490+
let instance = Instance::new(None, raw_instance_extensions, None).unwrap();
491+
let surface_handle = window.vulkan_create_surface(instance.internal_object()).unwrap();
492+
let surface = unsafe { Surface::from_raw_surface(instance, surface_handle, window.context()) };
493+
494+
let mut event_pump = sdl_context.event_pump().unwrap();
495+
496+
'running: loop {
497+
for event in event_pump.poll_iter() {
498+
match event {
499+
Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
500+
break 'running
501+
},
502+
_ => {}
503+
}
504+
}
505+
::std::thread::sleep(::std::time::Duration::new(0, 1_000_000_000u32 / 60));
506+
}
507+
}
508+
509+
```
510+
462511
# When things go wrong
463512
Rust, and Rust-SDL2, are both still heavily in development, and you may run
464513
into teething issues when using this. Before panicking, check that you're using

0 commit comments

Comments
 (0)