# HG changeset patch
# User alfadur
# Date 1564794996 -10800
# Node ID fd20e0a134af13d2c026f52ce0d26b03fc1e241f
# Parent  0f734fa371e1242834f3a1171b906516d5bbda3b
add function to retrieve texture data

diff -r 0f734fa371e1 -r fd20e0a134af rust/lib-hedgewars-engine/src/render/gl.rs
--- a/rust/lib-hedgewars-engine/src/render/gl.rs	Sat Aug 03 02:51:19 2019 +0300
+++ b/rust/lib-hedgewars-engine/src/render/gl.rs	Sat Aug 03 04:16:36 2019 +0300
@@ -134,8 +134,8 @@
                     0,             // texture level
                     region.left(), // texture region
                     region.top(),
-                    region.right(),
-                    region.bottom(),
+                    region.width() as i32,
+                    region.height() as i32,
                     format,                    // data format
                     ty,                        // data type
                     data.as_ptr() as *const _, // data ptr
@@ -143,6 +143,21 @@
             }
         }
     }
+
+    pub fn retrieve(&self, data: &mut [u8]) {
+        if let Some(handle) = self.handle {
+            unsafe {
+                gl::BindTexture(gl::TEXTURE_2D, handle.get());
+                gl::GetTexImage(
+                    gl::TEXTURE_2D,
+                    0,                           // texture level
+                    gl::RGBA,                    // data format
+                    gl::UNSIGNED_BYTE,           // data type
+                    data.as_mut_ptr() as *mut _, // data ptr
+                );
+            }
+        }
+    }
 }
 
 #[derive(Debug)]