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

Basic wgpu renderer #22

Merged
merged 53 commits into from
Oct 23, 2019
Merged

Basic wgpu renderer #22

merged 53 commits into from
Oct 23, 2019

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented Oct 14, 2019

This PR sets up the foundations for:

  • iced_wgpu, a renderer for Iced on top of wgpu. Fixes Implement a low-level renderer #8.
  • iced_winit, a renderer-agnostic runtime and conversion functions for winit.
  • iced, a batteries-included cross-platform GUI library using iced_wgpu, iced_winit, and iced_web.

As a consequence, the tour example depends only on iced now. All its previous direct dependencies, including ggez, have been dropped and the whole example fits in a single file now! 🎉

Implementation details

The most important new concepts are:

  • The iced_native::Renderer trait with an Output associated type. A Widget returns a value of this type in Widget::draw, instead of a MouseCursor.
  • The iced_native::renderer::Windowed trait, which uses raw-window-handle to define a reusable interface for graphical renderers.
  • The Application traits in both iced_winit and iced, which can be directly used to implement a GUI application easily. It should be a matter of implementing the trait and calling its run method! The iced_winit one allows users to choose a renderer with its Renderer associated type, while the iced one chooses iced_wgpu as the default renderer on native platforms (at least for now).

iced_wgpu

iced_wgpu implements the new Renderer and Windowed traits and defines its Output as (Primitive, MouseCursor). The Primitive type in iced_wgpu is a simple enum listing the different supported primitives. Currently, three primitives are supported:

  1. Text with a size, color, alignment, and specific boundaries. wgpu_glyph is used to render primitives of this kind.
  2. Quad with a background color (gradient and image backgrounds are not done yet!), border radius, and some boundaries. A pipeline with a simple fragment shader is used to render multiple instances of this primitive at once.
  3. Group, a group of primitives.

UserInterface::draw can be used to obtain a tree describing the different primitives that comprise the GUI. These primitives can be then drawn in the next frame using Renderer::draw.

iced_winit

iced_winit implements a renderer-agnostic runtime on top of winit in its Application trait. This new trait can be implemented by simply providing Renderer and Message types, and implementing the update and view logic of the GUI. Once implemented, Application::run can be called, which will take control of the current thread, create a window, and run the application.

It is important to note that using the new Application trait is optional. winit users can still build their own event loop and use iced_native::UserInterface directly. For this purpose, a conversion module is exposed and can be used to convert winit events into iced_native events easily.

Changelog

Added

  • iced_wgpu crate, a simple renderer for iced_native on top of wgpu.
  • iced_winit crate, a renderer-agnostic runtime for iced_native on top of winit.
  • Renderer trait in iced_native with an Output associated type.
  • renderer::Windowed trait in iced_native, which defines a reusable interface for graphical renderers thanks to raw-window-handle.
  • Background type in iced_core, it only supports a Color variant for now.
  • Button::padding, a method to define the padding of a button.
  • Button::background, a method to define the Background of a button.
  • Button::border_radius, a method for displaying buttons with rounded borders.
  • Color::WHITE constant.
  • Color::into_linear, which converts a Color into its linear values.

Changed

  • Button supports any element as content, instead of just a label.
  • Widget::draw returns a Renderer::Output.
  • Every widget Renderer extends the new iced_native::Renderer trait.
  • Image does not have generic handle now, it always takes a String representing a path or URI.

Removed

  • button::Class enum. Given that buttons are now customizable, it is no longer necessary.
  • Button::class method.

Pending work before merge

We only enable the `vulkan` feature for now.
Now it supports:
  - Any kind of content
  - Custom border radius
  - Custom background
- Added new `renderer::Windowed` trait. This shoud allow users to easily
  try different renderers by simply changing one line.
- Renamed `UserInterface` traits to `Application`, as the `run` method
  takes total control of the current thread.
- Moved `MouseCursor` back to `iced_native`. The new
  `renderer::Windowed` trait returns one on `draw`.
- Split `iced_native` renderer in multiple modules, for consistency.
@hecrj hecrj added improvement An internal improvement feature New feature or request labels Oct 14, 2019
@hecrj hecrj added this to the 0.1.0 milestone Oct 14, 2019
@hecrj hecrj self-assigned this Oct 14, 2019
@hecrj hecrj merged commit 4769272 into master Oct 23, 2019
@hecrj hecrj deleted the basic-renderer branch October 23, 2019 02:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request improvement An internal improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement a low-level renderer
1 participant