add blending to map
authoralfadur
Sun, 24 Mar 2019 20:40:12 +0300
changeset 14724 abc6aaf481c4
parent 14723 5915a199cb81
child 14725 b110cbe52e51
add blending to map
rust/lib-hedgewars-engine/src/render/gl.rs
rust/lib-hedgewars-engine/src/render/map.rs
--- a/rust/lib-hedgewars-engine/src/render/gl.rs	Sun Mar 24 20:11:55 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/render/gl.rs	Sun Mar 24 20:40:12 2019 +0300
@@ -2,6 +2,34 @@
 
 use std::{ffi, ffi::CString, mem, ptr, slice};
 
+#[derive(Default)]
+pub struct PipelineState {
+    blending: bool,
+}
+
+impl PipelineState {
+    pub fn new() -> Self {
+        Self::default()
+    }
+
+    pub fn with_blend(mut self) -> Self {
+        unsafe {
+            gl::Enable(gl::BLEND);
+            gl::BlendFunc(gl::SRC_ALPHA, gl::ONE_MINUS_SRC_ALPHA);
+        }
+        self.blending = true;
+        self
+    }
+}
+
+impl Drop for PipelineState {
+    fn drop(&mut self) {
+        if self.blending {
+            unsafe { gl::Disable(gl::BLEND) }
+        }
+    }
+}
+
 #[derive(Debug)]
 pub struct Texture2D {
     pub handle: u32,
--- a/rust/lib-hedgewars-engine/src/render/map.rs	Sun Mar 24 20:11:55 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/render/map.rs	Sun Mar 24 20:40:12 2019 +0300
@@ -5,8 +5,9 @@
 use super::{
     camera::Camera,
     gl::{
-        Buffer, InputElement, InputFormat, InputLayout, Shader, Texture2D, VariableBinding,
-    }
+        Buffer, InputElement, InputFormat, InputLayout, PipelineState, Shader, Texture2D,
+        VariableBinding,
+    },
 };
 
 // TODO: temp
@@ -277,7 +278,10 @@
         let projection = camera.projection();
 
         self.tile_shader.bind();
-        self.tile_shader.set_matrix("Projection", projection.as_ptr());
+        self.tile_shader
+            .set_matrix("Projection", projection.as_ptr());
+
+        let _state = PipelineState::new().with_blend();
 
         let mut draw_offset = 0;
         for draw_call in &self.tile_draw_calls {