Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rendering of Meshes seems to break depending on the order they are added #2600

Closed
4 tasks done
edwloef opened this issue Sep 21, 2024 · 0 comments · Fixed by #2601
Closed
4 tasks done

Rendering of Meshes seems to break depending on the order they are added #2600

edwloef opened this issue Sep 21, 2024 · 0 comments · Fixed by #2601
Labels
bug Something isn't working

Comments

@edwloef
Copy link
Contributor

edwloef commented Sep 21, 2024

Is your issue REALLY a bug?

  • My issue is indeed a bug!
  • 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?

  • I have searched the existing issues.

Is this issue related to iced?

  • 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:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant