Use SamplerBehavior in the Texture struct

This commit is contained in:
Cosmic Chip Socket 2020-07-14 18:48:13 -04:00
parent d0c65f534d
commit f2b4e4c482
2 changed files with 16 additions and 15 deletions

View File

@ -6,7 +6,7 @@ use std::rc::Rc;
use glium::{ use glium::{
backend::Facade, backend::Facade,
texture::{ClientFormat, RawImage2d}, texture::{ClientFormat, RawImage2d},
uniforms::{MagnifySamplerFilter, MinifySamplerFilter}, uniforms::{MagnifySamplerFilter, MinifySamplerFilter, SamplerBehavior},
Texture2d, Texture2d,
}; };
use image::{jpeg::JpegDecoder, ImageDecoder}; use image::{jpeg::JpegDecoder, ImageDecoder};
@ -59,8 +59,11 @@ impl CustomTexturesApp {
let gl_texture = Texture2d::new(gl_ctx, raw)?; let gl_texture = Texture2d::new(gl_ctx, raw)?;
let texture = Texture { let texture = Texture {
texture: Rc::new(gl_texture), texture: Rc::new(gl_texture),
mag_filter: MagnifySamplerFilter::Linear, sampler: SamplerBehavior {
min_filter: MinifySamplerFilter::Linear, magnify_filter: MagnifySamplerFilter::Linear,
minify_filter: MinifySamplerFilter::Linear,
.. Default::default()
},
}; };
let texture_id = textures.insert(texture); let texture_id = textures.insert(texture);
@ -113,8 +116,11 @@ impl Lenna {
let gl_texture = Texture2d::new(gl_ctx, raw)?; let gl_texture = Texture2d::new(gl_ctx, raw)?;
let texture = Texture { let texture = Texture {
texture: Rc::new(gl_texture), texture: Rc::new(gl_texture),
mag_filter: MagnifySamplerFilter::Linear, sampler: SamplerBehavior {
min_filter: MinifySamplerFilter::Linear, magnify_filter: MagnifySamplerFilter::Linear,
minify_filter: MinifySamplerFilter::Linear,
.. Default::default()
},
}; };
let texture_id = textures.insert(texture); let texture_id = textures.insert(texture);
Ok(Lenna { Ok(Lenna {

View File

@ -5,7 +5,7 @@ use glium::backend::{Context, Facade};
use glium::index::{self, PrimitiveType}; use glium::index::{self, PrimitiveType};
use glium::program::ProgramChooserCreationError; use glium::program::ProgramChooserCreationError;
use glium::texture::{ClientFormat, MipmapsOption, RawImage2d, TextureCreationError}; use glium::texture::{ClientFormat, MipmapsOption, RawImage2d, TextureCreationError};
use glium::uniforms::{MagnifySamplerFilter, MinifySamplerFilter, SamplerWrapFunction}; use glium::uniforms::{Sampler, SamplerBehavior};
use glium::{ use glium::{
program, uniform, vertex, Blend, DrawError, DrawParameters, IndexBuffer, Program, Rect, program, uniform, vertex, Blend, DrawError, DrawParameters, IndexBuffer, Program, Rect,
Surface, Texture2d, VertexBuffer, Surface, Texture2d, VertexBuffer,
@ -88,8 +88,7 @@ impl From<DrawError> for RendererError {
pub struct Texture { pub struct Texture {
pub texture: Rc<Texture2d>, pub texture: Rc<Texture2d>,
pub mag_filter: MagnifySamplerFilter, pub sampler: SamplerBehavior,
pub min_filter: MinifySamplerFilter,
} }
pub struct Renderer { pub struct Renderer {
@ -193,7 +192,7 @@ impl Renderer {
&& clip_rect[2] >= 0.0 && clip_rect[2] >= 0.0
&& clip_rect[3] >= 0.0 && clip_rect[3] >= 0.0
{ {
let entry = self.lookup_texture(texture_id)?; let texture = self.lookup_texture(texture_id)?;
target.draw( target.draw(
&vtx_buffer, &vtx_buffer,
@ -203,10 +202,7 @@ impl Renderer {
&self.program, &self.program,
&uniform! { &uniform! {
matrix: matrix, matrix: matrix,
tex: entry.texture.sampled() tex: Sampler(texture.texture.as_ref(), texture.sampler)
.minify_filter(entry.min_filter)
.magnify_filter(entry.mag_filter)
.wrap_function(SamplerWrapFunction::BorderClamp)
}, },
&DrawParameters { &DrawParameters {
blend: Blend::alpha_blending(), blend: Blend::alpha_blending(),
@ -250,8 +246,7 @@ fn upload_font_texture(
fonts.tex_id = TextureId::from(usize::MAX); fonts.tex_id = TextureId::from(usize::MAX);
Ok(Texture { Ok(Texture {
texture: Rc::new(font_texture), texture: Rc::new(font_texture),
mag_filter: MagnifySamplerFilter::Linear, sampler: SamplerBehavior::default(),
min_filter: MinifySamplerFilter::Linear,
}) })
} }