Add support for texture filters in WGPU backend

This commit is contained in:
Emil Ernerfeldt 2022-05-22 17:40:56 +02:00
parent 5d15e3d367
commit a29154233b
10 changed files with 17 additions and 12 deletions

View file

@ -416,10 +416,14 @@ impl RenderPass {
format: wgpu::TextureFormat::Rgba8UnormSrgb, format: wgpu::TextureFormat::Rgba8UnormSrgb,
usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST, usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
}); });
let filter = match image_delta.filter {
egui::TextureFilter::Nearest => wgpu::FilterMode::Nearest,
egui::TextureFilter::Linear => wgpu::FilterMode::Linear,
};
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
label: None, label: None,
mag_filter: wgpu::FilterMode::Linear, mag_filter: filter,
min_filter: wgpu::FilterMode::Linear, min_filter: filter,
..Default::default() ..Default::default()
}); });
let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor { let bind_group = device.create_bind_group(&wgpu::BindGroupDescriptor {
@ -488,11 +492,12 @@ impl RenderPass {
/// The `Texture` must have the format `TextureFormat::Rgba8UnormSrgb` and usage /// The `Texture` must have the format `TextureFormat::Rgba8UnormSrgb` and usage
/// `TextureUsage::SAMPLED`. Any compare function supplied in the `SamplerDescriptor` will be /// `TextureUsage::SAMPLED`. Any compare function supplied in the `SamplerDescriptor` will be
/// ignored. /// ignored.
#[allow(clippy::needless_pass_by_value)] // false positive
pub fn register_native_texture_with_sampler_options( pub fn register_native_texture_with_sampler_options(
&mut self, &mut self,
device: &wgpu::Device, device: &wgpu::Device,
texture: &wgpu::TextureView, texture: &wgpu::TextureView,
sampler_descriptor: wgpu::SamplerDescriptor, sampler_descriptor: wgpu::SamplerDescriptor<'_>,
) -> egui::TextureId { ) -> egui::TextureId {
let sampler = device.create_sampler(&wgpu::SamplerDescriptor { let sampler = device.create_sampler(&wgpu::SamplerDescriptor {
compare: None, compare: None,

View file

@ -697,7 +697,7 @@ impl Context {
/// ui.ctx().load_texture( /// ui.ctx().load_texture(
/// "my-image", /// "my-image",
/// egui::ColorImage::example(), /// egui::ColorImage::example(),
/// egui::epaint::textures::TextureFilter::Linear /// egui::TextureFilter::Linear
/// ) /// )
/// }); /// });
/// ///

View file

@ -327,7 +327,7 @@ pub use epaint::hex_color;
pub use epaint::{ pub use epaint::{
color, mutex, color, mutex,
text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak}, text::{FontData, FontDefinitions, FontFamily, FontId, FontTweak},
textures::TexturesDelta, textures::{TextureFilter, TexturesDelta},
ClippedPrimitive, Color32, ColorImage, FontImage, ImageData, Mesh, PaintCallback, ClippedPrimitive, Color32, ColorImage, FontImage, ImageData, Mesh, PaintCallback,
PaintCallbackInfo, Rgba, Rounding, Shape, Stroke, TextureHandle, TextureId, PaintCallbackInfo, Rgba, Rounding, Shape, Stroke, TextureHandle, TextureId,
}; };

View file

@ -1529,7 +1529,7 @@ impl Ui {
/// ui.ctx().load_texture( /// ui.ctx().load_texture(
/// "my-image", /// "my-image",
/// egui::ColorImage::example(), /// egui::ColorImage::example(),
/// egui::epaint::textures::TextureFilter::Linear /// egui::TextureFilter::Linear
/// ) /// )
/// }); /// });
/// ///

View file

@ -18,7 +18,7 @@ use emath::Rot2;
/// ui.ctx().load_texture( /// ui.ctx().load_texture(
/// "my-image", /// "my-image",
/// egui::ColorImage::example(), /// egui::ColorImage::example(),
/// egui::epaint::textures::TextureFilter::Linear /// egui::TextureFilter::Linear
/// ) /// )
/// }); /// });
/// ///

View file

@ -1,4 +1,4 @@
use egui::{color::*, epaint::textures::TextureFilter, widgets::color_picker::show_color, *}; use egui::{color::*, widgets::color_picker::show_color, TextureFilter, *};
use std::collections::HashMap; use std::collections::HashMap;
const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0); const GRADIENT_SIZE: Vec2 = vec2(256.0, 24.0);

View file

@ -552,7 +552,7 @@ impl ItemsDemo {
ui.ctx().load_texture( ui.ctx().load_texture(
"plot_demo", "plot_demo",
egui::ColorImage::example(), egui::ColorImage::example(),
egui::epaint::textures::TextureFilter::Linear, egui::TextureFilter::Linear,
) )
}); });
let image = PlotImage::new( let image = PlotImage::new(

View file

@ -118,7 +118,7 @@ impl WidgetGallery {
ui.ctx().load_texture( ui.ctx().load_texture(
"example", "example",
egui::ColorImage::example(), egui::ColorImage::example(),
egui::epaint::textures::TextureFilter::Linear, egui::TextureFilter::Linear,
) )
}); });

View file

@ -1,5 +1,5 @@
use egui::epaint::textures::TextureFilter;
use egui::mutex::Mutex; use egui::mutex::Mutex;
use egui::TextureFilter;
/// An image to be shown in egui. /// An image to be shown in egui.
/// ///

View file

@ -20,7 +20,7 @@ pub use glow::Context;
const VERT_SRC: &str = include_str!("shader/vertex.glsl"); const VERT_SRC: &str = include_str!("shader/vertex.glsl");
const FRAG_SRC: &str = include_str!("shader/fragment.glsl"); const FRAG_SRC: &str = include_str!("shader/fragment.glsl");
pub type TextureFilter = egui::epaint::textures::TextureFilter; pub type TextureFilter = egui::TextureFilter;
trait TextureFilterExt { trait TextureFilterExt {
fn glow_code(&self) -> u32; fn glow_code(&self) -> u32;