mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-11 05:28:35 +00:00
Use SamplerBehavior in the Texture struct
This commit is contained in:
parent
d0c65f534d
commit
f2b4e4c482
@ -6,7 +6,7 @@ use std::rc::Rc;
|
||||
use glium::{
|
||||
backend::Facade,
|
||||
texture::{ClientFormat, RawImage2d},
|
||||
uniforms::{MagnifySamplerFilter, MinifySamplerFilter},
|
||||
uniforms::{MagnifySamplerFilter, MinifySamplerFilter, SamplerBehavior},
|
||||
Texture2d,
|
||||
};
|
||||
use image::{jpeg::JpegDecoder, ImageDecoder};
|
||||
@ -59,8 +59,11 @@ impl CustomTexturesApp {
|
||||
let gl_texture = Texture2d::new(gl_ctx, raw)?;
|
||||
let texture = Texture {
|
||||
texture: Rc::new(gl_texture),
|
||||
mag_filter: MagnifySamplerFilter::Linear,
|
||||
min_filter: MinifySamplerFilter::Linear,
|
||||
sampler: SamplerBehavior {
|
||||
magnify_filter: MagnifySamplerFilter::Linear,
|
||||
minify_filter: MinifySamplerFilter::Linear,
|
||||
.. Default::default()
|
||||
},
|
||||
};
|
||||
let texture_id = textures.insert(texture);
|
||||
|
||||
@ -113,8 +116,11 @@ impl Lenna {
|
||||
let gl_texture = Texture2d::new(gl_ctx, raw)?;
|
||||
let texture = Texture {
|
||||
texture: Rc::new(gl_texture),
|
||||
mag_filter: MagnifySamplerFilter::Linear,
|
||||
min_filter: MinifySamplerFilter::Linear,
|
||||
sampler: SamplerBehavior {
|
||||
magnify_filter: MagnifySamplerFilter::Linear,
|
||||
minify_filter: MinifySamplerFilter::Linear,
|
||||
.. Default::default()
|
||||
},
|
||||
};
|
||||
let texture_id = textures.insert(texture);
|
||||
Ok(Lenna {
|
||||
|
||||
@ -5,7 +5,7 @@ use glium::backend::{Context, Facade};
|
||||
use glium::index::{self, PrimitiveType};
|
||||
use glium::program::ProgramChooserCreationError;
|
||||
use glium::texture::{ClientFormat, MipmapsOption, RawImage2d, TextureCreationError};
|
||||
use glium::uniforms::{MagnifySamplerFilter, MinifySamplerFilter, SamplerWrapFunction};
|
||||
use glium::uniforms::{Sampler, SamplerBehavior};
|
||||
use glium::{
|
||||
program, uniform, vertex, Blend, DrawError, DrawParameters, IndexBuffer, Program, Rect,
|
||||
Surface, Texture2d, VertexBuffer,
|
||||
@ -88,8 +88,7 @@ impl From<DrawError> for RendererError {
|
||||
|
||||
pub struct Texture {
|
||||
pub texture: Rc<Texture2d>,
|
||||
pub mag_filter: MagnifySamplerFilter,
|
||||
pub min_filter: MinifySamplerFilter,
|
||||
pub sampler: SamplerBehavior,
|
||||
}
|
||||
|
||||
pub struct Renderer {
|
||||
@ -193,7 +192,7 @@ impl Renderer {
|
||||
&& clip_rect[2] >= 0.0
|
||||
&& clip_rect[3] >= 0.0
|
||||
{
|
||||
let entry = self.lookup_texture(texture_id)?;
|
||||
let texture = self.lookup_texture(texture_id)?;
|
||||
|
||||
target.draw(
|
||||
&vtx_buffer,
|
||||
@ -203,10 +202,7 @@ impl Renderer {
|
||||
&self.program,
|
||||
&uniform! {
|
||||
matrix: matrix,
|
||||
tex: entry.texture.sampled()
|
||||
.minify_filter(entry.min_filter)
|
||||
.magnify_filter(entry.mag_filter)
|
||||
.wrap_function(SamplerWrapFunction::BorderClamp)
|
||||
tex: Sampler(texture.texture.as_ref(), texture.sampler)
|
||||
},
|
||||
&DrawParameters {
|
||||
blend: Blend::alpha_blending(),
|
||||
@ -250,8 +246,7 @@ fn upload_font_texture(
|
||||
fonts.tex_id = TextureId::from(usize::MAX);
|
||||
Ok(Texture {
|
||||
texture: Rc::new(font_texture),
|
||||
mag_filter: MagnifySamplerFilter::Linear,
|
||||
min_filter: MinifySamplerFilter::Linear,
|
||||
sampler: SamplerBehavior::default(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user