-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Backend-specific primitives #1932
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0ae1baa
Introduce custom backend-specific primitives
hecrj 2128472
Remove `layout` method from `core::Renderer` trait
hecrj fa5650c
Decouple `Mesh` primitives from main `Primitive` type
hecrj 6921564
Write missing docs in `iced_graphics` and `iced_wgpu`
hecrj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| //! Draw triangles! | ||
| use crate::color; | ||
| use crate::core::{Rectangle, Size}; | ||
| use crate::gradient; | ||
| use crate::Damage; | ||
|
|
||
| use bytemuck::{Pod, Zeroable}; | ||
|
|
||
| /// A low-level primitive to render a mesh of triangles. | ||
| #[derive(Debug, Clone, PartialEq)] | ||
| pub enum Mesh { | ||
| /// A mesh with a solid color. | ||
| Solid { | ||
| /// The vertices and indices of the mesh. | ||
| buffers: Indexed<SolidVertex2D>, | ||
|
|
||
| /// The size of the drawable region of the mesh. | ||
| /// | ||
| /// Any geometry that falls out of this region will be clipped. | ||
| size: Size, | ||
| }, | ||
| /// A mesh with a gradient. | ||
| Gradient { | ||
| /// The vertices and indices of the mesh. | ||
| buffers: Indexed<GradientVertex2D>, | ||
|
|
||
| /// The size of the drawable region of the mesh. | ||
| /// | ||
| /// Any geometry that falls out of this region will be clipped. | ||
| size: Size, | ||
| }, | ||
| } | ||
|
|
||
| impl Damage for Mesh { | ||
| fn bounds(&self) -> Rectangle { | ||
| match self { | ||
| Self::Solid { size, .. } | Self::Gradient { size, .. } => { | ||
| Rectangle::with_size(*size) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// A set of [`Vertex2D`] and indices representing a list of triangles. | ||
| #[derive(Clone, Debug, PartialEq, Eq)] | ||
| pub struct Indexed<T> { | ||
| /// The vertices of the mesh | ||
| pub vertices: Vec<T>, | ||
|
|
||
| /// The list of vertex indices that defines the triangles of the mesh. | ||
| /// | ||
| /// Therefore, this list should always have a length that is a multiple of 3. | ||
| pub indices: Vec<u32>, | ||
| } | ||
|
|
||
| /// A two-dimensional vertex with a color. | ||
| #[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] | ||
| #[repr(C)] | ||
| pub struct SolidVertex2D { | ||
| /// The vertex position in 2D space. | ||
| pub position: [f32; 2], | ||
|
|
||
| /// The color of the vertex in __linear__ RGBA. | ||
| pub color: color::Packed, | ||
| } | ||
|
|
||
| /// A vertex which contains 2D position & packed gradient data. | ||
| #[derive(Copy, Clone, Debug, PartialEq, Zeroable, Pod)] | ||
| #[repr(C)] | ||
| pub struct GradientVertex2D { | ||
| /// The vertex position in 2D space. | ||
| pub position: [f32; 2], | ||
|
|
||
| /// The packed vertex data of the gradient. | ||
| pub gradient: gradient::Packed, | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.