Skip to content

Commit

Permalink
Merge pull request #1873 from bungoboingo/fix/bg-gradient-layering
Browse files Browse the repository at this point in the history
[Fix] Quads of different background types not ordered
  • Loading branch information
hecrj authored May 29, 2023
2 parents 8ff2e01 + c319f51 commit 9253f76
Show file tree
Hide file tree
Showing 6 changed files with 440 additions and 389 deletions.
8 changes: 6 additions & 2 deletions wgpu/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ impl Backend {
}

if !layer.quads.is_empty() {
self.quad_pipeline
.render(quad_layer, bounds, &mut render_pass);
self.quad_pipeline.render(
quad_layer,
bounds,
&layer.quads,
&mut render_pass,
);

quad_layer += 1;
}
Expand Down
50 changes: 5 additions & 45 deletions wgpu/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ mod image;
mod text;

pub mod mesh;
pub mod quad;

pub use image::Image;
pub use mesh::Mesh;
pub use quad::Quad;
pub use text::Text;

use crate::core;
use crate::core::alignment;
use crate::core::{Background, Color, Font, Point, Rectangle, Size, Vector};
use crate::graphics::gradient;
use crate::core::{Color, Font, Point, Rectangle, Size, Vector};
use crate::graphics::{Primitive, Viewport};
use crate::quad::{self, Quad};

/// A group of primitives that should be clipped together.
#[derive(Debug)]
Expand All @@ -23,7 +21,7 @@ pub struct Layer<'a> {
pub bounds: Rectangle,

/// The quads of the [`Layer`].
pub quads: Quads,
pub quads: quad::Batch,

/// The triangle meshes of the [`Layer`].
pub meshes: Vec<Mesh<'a>>,
Expand All @@ -35,29 +33,12 @@ pub struct Layer<'a> {
pub images: Vec<Image>,
}

/// The quads of the [`Layer`].
#[derive(Default, Debug)]
pub struct Quads {
/// The solid quads of the [`Layer`].
pub solids: Vec<quad::Solid>,

/// The gradient quads of the [`Layer`].
pub gradients: Vec<quad::Gradient>,
}

impl Quads {
/// Returns true if there are no quads of any type in [`Quads`].
pub fn is_empty(&self) -> bool {
self.solids.is_empty() && self.gradients.is_empty()
}
}

impl<'a> Layer<'a> {
/// Creates a new [`Layer`] with the given clipping bounds.
pub fn new(bounds: Rectangle) -> Self {
Self {
bounds,
quads: Quads::default(),
quads: quad::Batch::default(),
meshes: Vec::new(),
text: Vec::new(),
images: Vec::new(),
Expand Down Expand Up @@ -174,28 +155,7 @@ impl<'a> Layer<'a> {
border_width: *border_width,
};

match background {
Background::Color(color) => {
layer.quads.solids.push(quad::Solid {
color: color.into_linear(),
quad,
});
}
Background::Gradient(gradient) => {
let quad = quad::Gradient {
gradient: gradient::pack(
gradient,
Rectangle::new(
quad.position.into(),
quad.size.into(),
),
),
quad,
};

layer.quads.gradients.push(quad);
}
};
layer.quads.add(quad, background);
}
Primitive::Image { handle, bounds } => {
let layer = &mut layers[current_layer];
Expand Down
51 changes: 0 additions & 51 deletions wgpu/src/layer/quad.rs

This file was deleted.

Loading

0 comments on commit 9253f76

Please sign in to comment.