pass hwrunner gl context into engine
authoralfadur
Fri, 09 Nov 2018 23:03:45 +0300
changeset 14188 3b83ec44e10b
parent 14187 675aa499a70e
child 14189 b15014125f67
pass hwrunner gl context into engine
rust/hwrunner/Cargo.toml
rust/hwrunner/src/main.rs
rust/lib-hedgewars-engine/Cargo.toml
rust/lib-hedgewars-engine/src/lib.rs
--- a/rust/hwrunner/Cargo.toml	Fri Nov 09 20:15:29 2018 +0300
+++ b/rust/hwrunner/Cargo.toml	Fri Nov 09 23:03:45 2018 +0300
@@ -7,4 +7,6 @@
 [dependencies]
 gfx = "0.17"
 glutin = "0.18"
-gfx_device_gl = "0.15"
+gfx_window_glutin = "0.26"
+
+lib-hedgewars-engine = { path = "../lib-hedgewars-engine" }
--- a/rust/hwrunner/src/main.rs	Fri Nov 09 20:15:29 2018 +0300
+++ b/rust/hwrunner/src/main.rs	Fri Nov 09 23:03:45 2018 +0300
@@ -4,8 +4,19 @@
     WindowEvent,
     EventsLoop,
     GlWindow,
+    GlContext
 };
 
+use gfx::{
+    texture,
+    format,
+    Encoder
+};
+
+use gfx_window_glutin::init_existing;
+
+use hedgewars_engine::EngineInstance;
+
 fn init(event_loop: &EventsLoop, size: LogicalSize) -> GlWindow {
     use glutin::{
         ContextBuilder,
@@ -24,6 +35,13 @@
     let mut event_loop = EventsLoop::new();
     let window = init(&event_loop, LogicalSize::new(1024.0, 768.0));
 
+    let (mut device, mut factory, color_view, depth_view) =
+        init_existing::<format::Rgba8, format::Depth>(&window);
+
+    let mut encoder: Encoder<_, _> = factory.create_command_buffer().into();
+
+    let engine = EngineInstance::new();
+
     let mut is_running = true;
     while is_running {
         event_loop.poll_events(|event| {
@@ -36,6 +54,13 @@
                 },
                 _ => ()
             }
-        })
+        });
+
+        encoder.clear(&color_view, [0.5, 0.0, 0.0, 1.0]);
+        engine.render(&mut encoder, &color_view);
+
+        encoder.flush(&mut device);
+
+        window.swap_buffers().unwrap();
     }
 }
--- a/rust/lib-hedgewars-engine/Cargo.toml	Fri Nov 09 20:15:29 2018 +0300
+++ b/rust/lib-hedgewars-engine/Cargo.toml	Fri Nov 09 23:03:45 2018 +0300
@@ -4,6 +4,9 @@
 authors = ["Andrey Korotaev <a.korotaev@hedgewars.org>"]
 
 [dependencies]
+gfx = "0.17"
+gfx_device_gl = "0.15"
+
 land2d = { path = "../land2d" }
 lfprng = { path = "../lfprng" }
 integral-geometry = { path = "../integral-geometry" }
--- a/rust/lib-hedgewars-engine/src/lib.rs	Fri Nov 09 20:15:29 2018 +0300
+++ b/rust/lib-hedgewars-engine/src/lib.rs	Fri Nov 09 23:03:45 2018 +0300
@@ -2,6 +2,8 @@
 extern crate land2d;
 extern crate landgen;
 extern crate lfprng;
+extern crate gfx;
+extern crate gfx_device_gl;
 
 mod world;
 mod engine_message;
@@ -12,6 +14,23 @@
     world: world::World,
 }
 
+impl EngineInstance {
+    pub fn new() -> Self {
+        let world = world::World::new();
+        Self { world }
+    }
+
+    pub fn render<R, C>(
+        &self,
+        context: &mut gfx::Encoder<R, C>,
+        target: &gfx::handle::RenderTargetView<R, gfx::format::Rgba8>)
+        where R: gfx::Resources,
+              C: gfx::CommandBuffer<R>
+    {
+        context.clear(target, [0.0, 0.5, 0.0, 1.0]);
+    }
+}
+
 #[repr(C)]
 #[derive(Copy, Clone)]
 pub struct PreviewInfo {