Skip to content

Added gfx-rs support #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ git = "https://github.com/PistonDevelopers/piston"

git = "https://github.com/bjz/gl-rs"

[dependencies.gfx]

git = "https://github.com/gfx-rs/gfx-rs"

[[lib]]

name = "sdl2_game_window"
Expand Down
13 changes: 13 additions & 0 deletions src/concurrent_window_sdl2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//! RenderWindow and ConcurrentWindow implemented by SDL2 back-end.

// External crates.
use gfx;
use gfx::DeviceHelper;
use device;
use std;
use sdl2;
use piston::{
Expand Down Expand Up @@ -145,4 +148,14 @@ impl ConcurrentWindowSDL2 {
);

}

/// Creates a gfx device and front end.
pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) {
let mut device = device::GlDevice::new(|s| unsafe {
std::mem::transmute(sdl2::video::gl_get_proc_address(s))
});
let (w, h) = self.get_size();
let frontend = device.create_frontend(w as u16, h as u16).unwrap();
(device, frontend)
}
}
7 changes: 7 additions & 0 deletions src/game_window_sdl2.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! A window implemented by SDL2 back-end.

// External crates.
use gfx;
use device;
use sdl2;
use piston::{
GameWindow,
Expand Down Expand Up @@ -35,6 +37,11 @@ impl GameWindowSDL2 {
render_window: render_window,
}
}

/// Creates a gfx devince and front end.
pub fn gfx(&self) -> (device::GlDevice, gfx::FrontEnd) {
self.concurrent_window.gfx()
}
}

impl GameWindow for GameWindowSDL2 {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
extern crate sdl2;
extern crate piston;
extern crate gl;
extern crate gfx;
extern crate device;

pub use GameWindowSDL2 = game_window_sdl2::GameWindowSDL2;
pub use ConcurrentWindowSDL2 = concurrent_window_sdl2::ConcurrentWindowSDL2;
Expand Down