Provide actual bounds to Shader primitives
... and allow for proper translation and scissoring.
This commit is contained in:
parent
100d15f306
commit
ab7dae554c
8 changed files with 54 additions and 40 deletions
|
|
@ -192,9 +192,9 @@ impl Backend {
|
|||
format,
|
||||
device,
|
||||
queue,
|
||||
pipeline.bounds,
|
||||
target_size,
|
||||
scale_factor,
|
||||
transformation,
|
||||
&mut self.pipeline_storage,
|
||||
);
|
||||
}
|
||||
|
|
@ -327,17 +327,17 @@ impl Backend {
|
|||
let _ = ManuallyDrop::into_inner(render_pass);
|
||||
|
||||
for pipeline in &layer.pipelines {
|
||||
let bounds = (pipeline.bounds * scale_factor).snap();
|
||||
let viewport = (pipeline.viewport * scale_factor).snap();
|
||||
|
||||
if bounds.width < 1 || bounds.height < 1 {
|
||||
if viewport.width < 1 || viewport.height < 1 {
|
||||
continue;
|
||||
}
|
||||
|
||||
pipeline.primitive.render(
|
||||
&self.pipeline_storage,
|
||||
bounds,
|
||||
target,
|
||||
target_size,
|
||||
viewport,
|
||||
encoder,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
//! Organize rendering primitives into a flattened list of layers.
|
||||
mod image;
|
||||
mod pipeline;
|
||||
mod text;
|
||||
|
||||
pub mod mesh;
|
||||
|
||||
pub use image::Image;
|
||||
pub use mesh::Mesh;
|
||||
pub use pipeline::Pipeline;
|
||||
pub use text::Text;
|
||||
|
||||
use crate::core;
|
||||
|
|
@ -36,7 +38,7 @@ pub struct Layer<'a> {
|
|||
pub images: Vec<Image>,
|
||||
|
||||
/// The custom pipelines of this [`Layer`].
|
||||
pub pipelines: Vec<primitive::Pipeline>,
|
||||
pub pipelines: Vec<Pipeline>,
|
||||
}
|
||||
|
||||
impl<'a> Layer<'a> {
|
||||
|
|
@ -314,17 +316,14 @@ impl<'a> Layer<'a> {
|
|||
},
|
||||
primitive::Custom::Pipeline(pipeline) => {
|
||||
let layer = &mut layers[current_layer];
|
||||
|
||||
let bounds = Rectangle::new(
|
||||
Point::new(translation.x, translation.y),
|
||||
pipeline.bounds.size(),
|
||||
);
|
||||
let bounds = pipeline.bounds + translation;
|
||||
|
||||
if let Some(clip_bounds) =
|
||||
layer.bounds.intersection(&bounds)
|
||||
{
|
||||
layer.pipelines.push(primitive::Pipeline {
|
||||
bounds: clip_bounds,
|
||||
layer.pipelines.push(Pipeline {
|
||||
bounds,
|
||||
viewport: clip_bounds,
|
||||
primitive: pipeline.primitive.clone(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
17
wgpu/src/layer/pipeline.rs
Normal file
17
wgpu/src/layer/pipeline.rs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
use crate::core::Rectangle;
|
||||
use crate::primitive::pipeline::Primitive;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
/// A custom primitive which can be used to render primitives associated with a custom pipeline.
|
||||
pub struct Pipeline {
|
||||
/// The bounds of the [`Pipeline`].
|
||||
pub bounds: Rectangle,
|
||||
|
||||
/// The viewport of the [`Pipeline`].
|
||||
pub viewport: Rectangle,
|
||||
|
||||
/// The [`Primitive`] to render.
|
||||
pub primitive: Arc<dyn Primitive>,
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
//! Draw primitives using custom pipelines.
|
||||
use crate::core::{Rectangle, Size};
|
||||
use crate::graphics::Transformation;
|
||||
|
||||
use std::any::{Any, TypeId};
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -41,9 +40,9 @@ pub trait Primitive: Debug + Send + Sync + 'static {
|
|||
format: wgpu::TextureFormat,
|
||||
device: &wgpu::Device,
|
||||
queue: &wgpu::Queue,
|
||||
bounds: Rectangle,
|
||||
target_size: Size<u32>,
|
||||
scale_factor: f32,
|
||||
transform: Transformation,
|
||||
storage: &mut Storage,
|
||||
);
|
||||
|
||||
|
|
@ -51,9 +50,9 @@ pub trait Primitive: Debug + Send + Sync + 'static {
|
|||
fn render(
|
||||
&self,
|
||||
storage: &Storage,
|
||||
bounds: Rectangle<u32>,
|
||||
target: &wgpu::TextureView,
|
||||
target_size: Size<u32>,
|
||||
viewport: Rectangle<u32>,
|
||||
encoder: &mut wgpu::CommandEncoder,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue