mirror of
https://github.com/eliasstepanik/imgui-rs.git
synced 2026-01-26 21:08:40 +00:00
User-selectable texture filters per-texture
This commit is contained in:
parent
c2bb0bd1e2
commit
4ab3aa6642
@ -13,6 +13,7 @@ use glium::{
|
|||||||
use imgui::internal::RawWrapper;
|
use imgui::internal::RawWrapper;
|
||||||
use imgui::{DrawCmd, DrawCmdParams, DrawData, ImString, TextureId, Textures};
|
use imgui::{DrawCmd, DrawCmdParams, DrawData, ImString, TextureId, Textures};
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -91,6 +92,7 @@ pub struct Renderer {
|
|||||||
program: Program,
|
program: Program,
|
||||||
font_texture: Texture2d,
|
font_texture: Texture2d,
|
||||||
textures: Textures<Rc<Texture2d>>,
|
textures: Textures<Rc<Texture2d>>,
|
||||||
|
filters: HashMap<TextureId, (MinifySamplerFilter, MagnifySamplerFilter)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Renderer {
|
impl Renderer {
|
||||||
@ -109,6 +111,7 @@ impl Renderer {
|
|||||||
program,
|
program,
|
||||||
font_texture,
|
font_texture,
|
||||||
textures: Textures::new(),
|
textures: Textures::new(),
|
||||||
|
filters: HashMap::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn reload_font_texture(&mut self, ctx: &mut imgui::Context) -> Result<(), RendererError> {
|
pub fn reload_font_texture(&mut self, ctx: &mut imgui::Context) -> Result<(), RendererError> {
|
||||||
@ -127,6 +130,14 @@ impl Renderer {
|
|||||||
Err(RendererError::BadTexture(texture_id))
|
Err(RendererError::BadTexture(texture_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn set_texture_filter(
|
||||||
|
&mut self,
|
||||||
|
texture_id: TextureId,
|
||||||
|
min_filter: MinifySamplerFilter,
|
||||||
|
mag_filter: MagnifySamplerFilter,
|
||||||
|
) {
|
||||||
|
self.filters.insert(texture_id, (min_filter, mag_filter));
|
||||||
|
}
|
||||||
pub fn render<T: Surface>(
|
pub fn render<T: Surface>(
|
||||||
&mut self,
|
&mut self,
|
||||||
target: &mut T,
|
target: &mut T,
|
||||||
@ -187,6 +198,16 @@ impl Renderer {
|
|||||||
&& clip_rect[2] >= 0.0
|
&& clip_rect[2] >= 0.0
|
||||||
&& clip_rect[3] >= 0.0
|
&& clip_rect[3] >= 0.0
|
||||||
{
|
{
|
||||||
|
let (min_filter, mag_filter) = self
|
||||||
|
.filters
|
||||||
|
.get(&texture_id)
|
||||||
|
.cloned()
|
||||||
|
.or(Some((
|
||||||
|
MinifySamplerFilter::Linear,
|
||||||
|
MagnifySamplerFilter::Linear,
|
||||||
|
)))
|
||||||
|
.expect("Bad texture filter");
|
||||||
|
|
||||||
target.draw(
|
target.draw(
|
||||||
&vtx_buffer,
|
&vtx_buffer,
|
||||||
&idx_buffer
|
&idx_buffer
|
||||||
@ -196,8 +217,8 @@ impl Renderer {
|
|||||||
&uniform! {
|
&uniform! {
|
||||||
matrix: matrix,
|
matrix: matrix,
|
||||||
tex: self.lookup_texture(texture_id)?.sampled()
|
tex: self.lookup_texture(texture_id)?.sampled()
|
||||||
.minify_filter(MinifySamplerFilter::Linear)
|
.minify_filter(min_filter)
|
||||||
.magnify_filter(MagnifySamplerFilter::Linear)
|
.magnify_filter(mag_filter)
|
||||||
.wrap_function(SamplerWrapFunction::BorderClamp)
|
.wrap_function(SamplerWrapFunction::BorderClamp)
|
||||||
},
|
},
|
||||||
&DrawParameters {
|
&DrawParameters {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user