Repository: iced-rs/iced (language: rust)

Issue:
Rendering of `Mesh`es seems to break depending on the order they are added
### Is your issue REALLY a bug?

- [X] My issue is indeed a bug!
- [X] I am not crazy! I will not fill out this form just to ask a question or request a feature. Pinky promise.

### Is there an existing issue for this?

- [X] I have searched the existing issues.

### Is this issue related to iced?

- [X] My hardware is compatible and my graphics drivers are up-to-date.

### What happened?

If a `Mesh` that has a clip bound with a dimension below 1 pixel is drawn before another `Mesh` with a larger clip bound, the second is not drawn.

Minimum example:
```rs
use iced::{
    advanced::{
        graphics::{
            color,
            mesh::{self, Renderer as _, SolidVertex2D},
            Mesh,
        },
        layout::{Limits, Node},
        renderer::Style,
        widget::Tree,
        Layout, Widget,
    },
    mouse::Cursor,
    Length, Rectangle, Renderer, Size, Theme, Transformation,
};

fn main() {
    iced::application("", App::update, App::view).run().unwrap();
}

struct App;

#[derive(Debug)]
enum Message {}

impl App {
    fn new() -> Self {
        Self
    }

    fn update(&mut self, _: Message) {}

    fn view(&self) -> iced::Element<'_, Message> {
        iced::Element::new(Test)
    }
}

impl Default for App {
    fn default() -> Self {
        Self::new()
    }
}

struct Test;

impl Widget<Message, Theme, Renderer> for Test {
    fn size(&self) -> Size<Length> {
        Size::new(Length::Fill, Length::Fill)
    }

    fn layout(&self, _tree: &mut Tree, _renderer: &Renderer, limits: &Limits) -> Node {
        Node::new(Size::new(limits.max().width, limits.max().height))
    }

    fn draw(
        &self,
        _tree: &Tree,
        renderer: &mut Renderer,
        theme: &Theme,
        _style: &Style,
        _layout: Layout<'_>,
        _cursor: Cursor,
        _viewport: &Rectangle,
    ) {
        let mesh1 = Mesh::Solid {
            buffers: mesh::Indexed {
                vertices: vec![
                    SolidVertex2D {
                        position: [0.0, 0.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                    SolidVertex2D {
                        position: [0.0, 100.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                    SolidVertex2D {
                        position: [100.0, 100.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                ],
                indices: vec![0, 1, 2],
            },
            transformation: Transformation::IDENTITY,
            clip_bounds: Rectangle {
                x: 0.0,
                y: 0.0,
                width: 100.0,
                height: 0.9999999,
            },
        };

        let mesh2 = Mesh::Solid {
            buffers: mesh::Indexed {
                vertices: vec![
                    SolidVertex2D {
                        position: [0.0, 100.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                    SolidVertex2D {
                        position: [0.0, 200.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                    SolidVertex2D {
                        position: [100.0, 200.0],
                        color: color::pack(theme.extended_palette().secondary.base.text),
                    },
                ],
                indices: vec![0, 1, 2],
            },
            transformation: Transformation::IDENTITY,
            clip_bounds: Rectangle {
                x: 0.0,
                y: 100.0,
                width: 100.0,
                height: 100.0,
            },
        };

        renderer.draw_mesh(mesh1);
        renderer.draw_mesh(mesh2);
    }
}
```
`mesh2` doesn't render here. Swapping the two `draw_mesh` calls makes `mesh2` render correctly.

This affects both this release and the master branch.

### What is the expected behavior?

The mesh with the large clip bound is rendered.

### Version

crates.io release

### Operating System

Linux

### Do you have any log output?

_No response_


Discussion / hints:

Fix patch:
diff --git a/wgpu/src/triangle.rs b/wgpu/src/triangle.rs
index 3d0869e717..fb858c1088 100644
--- a/wgpu/src/triangle.rs
+++ b/wgpu/src/triangle.rs
@@ -505,6 +505,14 @@ impl Layer {
                 .intersection(&(mesh.clip_bounds() * transformation))
                 .and_then(Rectangle::snap)
             else {
+                match mesh {
+                    Mesh::Solid { .. } => {
+                        num_solids += 1;
+                    }
+                    Mesh::Gradient { .. } => {
+                        num_gradients += 1;
+                    }
+                }
                 continue;
             };
 


Test patch: