summaryrefslogtreecommitdiff
path: root/engine/src/opengl/texture.rs
diff options
context:
space:
mode:
Diffstat (limited to 'engine/src/opengl/texture.rs')
-rw-r--r--engine/src/opengl/texture.rs79
1 files changed, 21 insertions, 58 deletions
diff --git a/engine/src/opengl/texture.rs b/engine/src/opengl/texture.rs
index 56eb118..5d12729 100644
--- a/engine/src/opengl/texture.rs
+++ b/engine/src/opengl/texture.rs
@@ -1,7 +1,7 @@
use std::ptr::null;
use crate::opengl::currently_bound::CurrentlyBound;
-use crate::texture::Id;
+use crate::texture::{Id, Properties};
use crate::vector::Vec2;
#[derive(Debug)]
@@ -49,7 +49,24 @@ impl Texture
}
}
- pub fn set_wrap(_: CurrentlyBound<Self>, wrapping: Wrapping)
+ pub fn apply_properties(&self, properties: &Properties)
+ {
+ self.bind(|texture_curr_bound| {
+ Texture::set_wrap(&texture_curr_bound, properties.wrap);
+
+ Texture::set_magnifying_filter(
+ &texture_curr_bound,
+ properties.magnifying_filter,
+ );
+
+ Texture::set_minifying_filter(
+ &texture_curr_bound,
+ properties.minifying_filter,
+ );
+ });
+ }
+
+ pub fn set_wrap(_: &CurrentlyBound<Self>, wrapping: Wrapping)
{
let wrapping_gl = wrapping.to_gl();
@@ -60,7 +77,7 @@ impl Texture
}
}
- pub fn set_magnifying_filter(_: CurrentlyBound<Self>, filtering: Filtering)
+ pub fn set_magnifying_filter(_: &CurrentlyBound<Self>, filtering: Filtering)
{
let filtering_gl = filtering.to_gl();
@@ -74,7 +91,7 @@ impl Texture
}
}
- pub fn set_minifying_filter(_: CurrentlyBound<Self>, filtering: Filtering)
+ pub fn set_minifying_filter(_: &CurrentlyBound<Self>, filtering: Filtering)
{
let filtering_gl = filtering.to_gl();
@@ -88,60 +105,6 @@ impl Texture
}
}
- /// Creates a copy of the texture & the texture images.
- ///
- /// `src_offset` and `dst_offset` are source & destination offsets from the
- /// bottom-left of the images.
- ///
- /// New mipmaps are generated using the largest mipmap.
- pub fn copy(
- &self,
- dimensions: &Vec2<u32>,
- pixel_data_format: PixelDataFormat,
- src_offset: &Vec2<u32>,
- dst_offset: &Vec2<u32>,
- ) -> Self
- {
- let new_texture = Self::new();
-
- new_texture.bind(|curr_bound| {
- Self::alloc_image(&curr_bound, pixel_data_format, dimensions, None);
-
- // Mipmap have to be generated since CopyImageSubData demands that the
- // destination texture is completed
- unsafe {
- gl::GenerateMipmap(gl::TEXTURE_2D);
- }
- });
-
- #[allow(clippy::cast_possible_wrap)]
- unsafe {
- gl::CopyImageSubData(
- self.texture,
- gl::TEXTURE_2D,
- 0,
- src_offset.x as i32,
- src_offset.y as i32,
- 0,
- new_texture.texture,
- gl::TEXTURE_2D,
- 0,
- dst_offset.x as i32,
- dst_offset.y as i32,
- 0,
- dimensions.x as i32,
- dimensions.y as i32,
- 1,
- );
- }
-
- unsafe {
- gl::GenerateMipmap(gl::TEXTURE_2D);
- }
-
- new_texture
- }
-
fn alloc_image(
_: &CurrentlyBound<Self>,
pixel_data_format: PixelDataFormat,