Skip to content

Commit

Permalink
Merge pull request Rust-SDL2#785 from Rua/master
Browse files Browse the repository at this point in the history
Vulkan support
  • Loading branch information
Cobrand authored Sep 13, 2018
2 parents 3e6ec82 + 1e9ebfb commit d23f559
Show file tree
Hide file tree
Showing 4 changed files with 692 additions and 15 deletions.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,58 @@ fn main() {
This method is useful when you don't care about sdl2's render capabilities, but you do care about
its audio, controller and other neat features that sdl2 has.

# Vulkan

To use Vulkan, you need a Vulkan library for Rust. This example uses the
[Vulkano](https://github.com/vulkano-rs/vulkano) library. Other libraries may use different data
types for raw Vulkan object handles. The procedure to interface SDL2's Vulkan functions with these
will be different for each one.

```rust
extern crate sdl2;
extern crate vulkano;

use sdl2::event::Event;
use sdl2::keyboard::Keycode;
use std::ffi::CString;
use vulkano::VulkanObject;
use vulkano::instance::{Instance, RawInstanceExtensions};
use vulkano::swapchain::Surface;

fn main() {
let sdl_context = sdl2::init().unwrap();
let video_subsystem = sdl_context.video().unwrap();

let window = video_subsystem.window("Window", 800, 600)
.vulkan()
.build()
.unwrap();

let instance_extensions = window.vulkan_instance_extensions().unwrap();
let raw_instance_extensions = RawInstanceExtensions::new(instance_extensions.iter().map(
|&v| CString::new(v).unwrap()
));
let instance = Instance::new(None, raw_instance_extensions, None).unwrap();
let surface_handle = window.vulkan_create_surface(instance.internal_object()).unwrap();
let surface = unsafe { Surface::from_raw_surface(instance, surface_handle, window.context()) };

let mut event_pump = sdl_context.event_pump().unwrap();

'running: loop {
for event in event_pump.poll_iter() {
match event {
Event::Quit {..} | Event::KeyDown { keycode: Some(Keycode::Escape), .. } => {
break 'running
},
_ => {}
}
}
::std::thread::sleep(::std::time::Duration::new(0, 1_000_000_000u32 / 60));
}
}

```

# When things go wrong
Rust, and Rust-SDL2, are both still heavily in development, and you may run
into teething issues when using this. Before panicking, check that you're using
Expand Down
Loading

0 comments on commit d23f559

Please sign in to comment.