Skip to content

Commit

Permalink
Image sampler set to linear/clamp (#158)
Browse files Browse the repository at this point in the history
If a Bevy application override the default sample to repeat,
Egui window backgrounds are incorrectly transparent.
  • Loading branch information
galop1n committed Mar 12, 2023
1 parent e739d78 commit 14a0192
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions src/egui_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ use bevy::{
render::{
render_graph::{Node, NodeRunError, RenderGraphContext},
render_resource::{
BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry, BindingType,
BlendComponent, BlendFactor, BlendOperation, BlendState, Buffer, BufferAddress,
BufferBindingType, BufferDescriptor, BufferUsages, ColorTargetState, ColorWrites,
Extent3d, FragmentState, FrontFace, IndexFormat, LoadOp, MultisampleState, Operations,
PipelineCache, PrimitiveState, RenderPassColorAttachment, RenderPassDescriptor,
RenderPipelineDescriptor, SamplerBindingType, Shader, ShaderStages, ShaderType,
SpecializedRenderPipeline, TextureDimension, TextureFormat, TextureSampleType,
TextureViewDimension, VertexBufferLayout, VertexFormat, VertexState, VertexStepMode,
AddressMode, BindGroupLayout, BindGroupLayoutDescriptor, BindGroupLayoutEntry,
BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState, Buffer,
BufferAddress, BufferBindingType, BufferDescriptor, BufferUsages, ColorTargetState,
ColorWrites, Extent3d, FragmentState, FrontFace, IndexFormat, LoadOp, MultisampleState,
Operations, PipelineCache, PrimitiveState, RenderPassColorAttachment,
RenderPassDescriptor, RenderPipelineDescriptor, SamplerBindingType, SamplerDescriptor,
Shader, ShaderStages, ShaderType, SpecializedRenderPipeline, TextureDimension,
TextureFormat, TextureSampleType, TextureViewDimension, VertexBufferLayout,
VertexFormat, VertexState, VertexStepMode,
},
renderer::{RenderContext, RenderDevice, RenderQueue},
texture::Image,
texture::{Image, ImageSampler},
view::ExtractedWindows,
},
};
Expand Down Expand Up @@ -431,14 +432,21 @@ pub(crate) fn color_image_as_bevy_image(egui_image: &egui::ColorImage) -> Image
.flat_map(|color| color.to_srgba_unmultiplied())
.collect();

Image::new(
Extent3d {
width: egui_image.width() as u32,
height: egui_image.height() as u32,
depth_or_array_layers: 1,
},
TextureDimension::D2,
pixels,
TextureFormat::Rgba8UnormSrgb,
)
Image {
sampler_descriptor: ImageSampler::Descriptor(SamplerDescriptor {
address_mode_u: AddressMode::ClampToEdge,
address_mode_v: AddressMode::ClampToEdge,
..ImageSampler::linear_descriptor()
}),
..Image::new(
Extent3d {
width: egui_image.width() as u32,
height: egui_image.height() as u32,
depth_or_array_layers: 1,
},
TextureDimension::D2,
pixels,
TextureFormat::Rgba8UnormSrgb,
)
}
}

0 comments on commit 14a0192

Please sign in to comment.