1 pub mod instance; |
1 pub mod instance; |
2 mod ipc; |
2 mod ipc; |
3 mod render; |
3 mod render; |
4 mod world; |
4 mod world; |
5 |
5 |
6 use gfx::{format::Formatted, Encoder}; |
|
7 use std::{ |
6 use std::{ |
8 ffi::CString, |
7 ffi::CString, |
9 io::{Read, Write}, |
8 io::{Read, Write}, |
10 mem::replace, |
9 mem::replace, |
11 os::raw::{c_char, c_void}, |
10 os::raw::{c_char, c_void}, |
12 }; |
11 }; |
13 |
12 |
14 use gfx_device_gl as gfx_gl; |
13 use self::instance::{EngineInstance}; |
15 |
|
16 use self::instance::{EngineGlContext, EngineInstance}; |
|
17 |
14 |
18 #[repr(C)] |
15 #[repr(C)] |
19 #[derive(Copy, Clone)] |
16 #[derive(Copy, Clone)] |
20 pub struct PreviewInfo { |
17 pub struct PreviewInfo { |
21 width: u32, |
18 width: u32, |
82 engine_state: &mut EngineInstance, |
79 engine_state: &mut EngineInstance, |
83 width: u16, |
80 width: u16, |
84 height: u16, |
81 height: u16, |
85 gl_loader: extern "C" fn(*const c_char) -> *const c_void, |
82 gl_loader: extern "C" fn(*const c_char) -> *const c_void, |
86 ) { |
83 ) { |
87 let (device, mut factory) = gfx_gl::create(|name| { |
|
88 let c_name = CString::new(name).unwrap(); |
|
89 gl_loader(c_name.as_ptr()) |
|
90 }); |
|
91 |
|
92 let dimensions = (width, height, 1u16, gfx::texture::AaMode::Single); |
|
93 let (render_target, depth_buffer) = gfx_gl::create_main_targets_raw( |
|
94 dimensions, |
|
95 gfx::format::Rgba8::get_format().0, |
|
96 gfx::format::Depth::get_format().0, |
|
97 ); |
|
98 |
|
99 let mut command_buffer: Encoder<_, _> = factory.create_command_buffer().into(); |
|
100 |
|
101 engine_state.gl_context = Some(EngineGlContext { |
|
102 device, |
|
103 factory, |
|
104 render_target: gfx::memory::Typed::new(render_target), |
|
105 depth_buffer: gfx::memory::Typed::new(depth_buffer), |
|
106 command_buffer, |
|
107 }) |
|
108 } |
84 } |
109 |
85 |
110 #[no_mangle] |
86 #[no_mangle] |
111 pub extern "C" fn render_frame(engine_state: &mut EngineInstance) { |
87 pub extern "C" fn render_frame(engine_state: &mut EngineInstance) { |
112 let mut context = replace(&mut engine_state.gl_context, None); |
88 //engine_state.render() |
113 if let Some(ref mut c) = context { |
|
114 engine_state.render(&mut c.command_buffer, &mut c.render_target) |
|
115 } |
|
116 replace(&mut engine_state.gl_context, context); |
|
117 } |
89 } |
118 |
90 |
119 #[no_mangle] |
91 #[no_mangle] |
120 pub extern "C" fn advance_simulation(engine_state: &mut EngineInstance, ticks: u32) -> bool { |
92 pub extern "C" fn advance_simulation(engine_state: &mut EngineInstance, ticks: u32) -> bool { |
121 engine_state.world.step(); |
93 engine_state.world.step(); |