add function to retrieve texture data
authoralfadur
Sat, 03 Aug 2019 04:16:36 +0300
changeset 15294 fd20e0a134af
parent 15293 0f734fa371e1
child 15295 fcf0fb0cddbf
add function to retrieve texture data
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)]