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

OpenGL renderer and backend-agnostic graphics subcrate #354

Merged
merged 33 commits into from May 28, 2020

Conversation

hecrj
Copy link
Member

@hecrj hecrj commented May 23, 2020

This PR implements an OpenGL renderer on top of glow, introduces a glutin shell, and abstracts a bunch of backend-agnostic rendering logic in a new graphics subcrate.

iced_glow

iced_glow is an OpenGL renderer powered by glow (GL on Whatever). This renderer is meant to be an alternative (not a replacement!) to iced_wgpu while wgpu and its ecosystem mature.

As iced_glow uses OpenGL, it should offer us better compatibility, stability, and maintainability for the time being. Furthermore, users that currently have OpenGL-based applications should be able to integrate them directly with iced.

On a related note, my work on this renderer also prompted me to write and open-source glow_glyph, a direct port of wgpu_glyph for glow.

Please, feel free to give the renderer a try by switching to the feature/glow-renderer branch and running any of the examples! Keep in mind that Image and Svg widgets are not supported yet.

iced_glutin

iced_glutin is a shell on top of glutin. It can be used to easily initialize OpenGL-based renderers, as it will create and properly configure an OpenGL context for them.

Given that glutin is built on top of winit itself, iced_winit and iced_glutin both share a good amount of logic. However, while iced_winit provides a raw-window-handle to initialize the chosen renderer, iced_glutin provides an OpenGL loader function instead.

The work on this crate also introduced a couple of new concepts in iced_native that should ease the integration of iced in existing projects (#313). Specifically, a Program trait has been added which can be used together with some program::State to feed events to a user interface and obtain its drawing primitives. The integration example has been updated accordingly to showcase how to use them!

iced_graphics

The first draft of iced_glow was implemented by copy-pasting a lot of code from iced_wgpu. As most of this code was backend-agnostic and shared between renderers, it was abstracted away and moved to an intermediate crate: iced_graphics.

iced_graphics contains a bunch of backend-agnostic types that can be leveraged to build a renderer. The most important concepts it contains are:

  • The current Primitive type from iced_wgpu.
  • A Layer type that flattens a Primitive tree for rendering.
  • A default renderer that can be customized with a generic backend. It implements the Renderer trait for all the built-in widgets.
  • Other useful types like Transformation, Viewport, a font loader on top of font-kit, etc.

And I think that's about it! I am aware there is a lot to unpack here. Once I finish writing the documentation for all the changes, I will share a link.

As always, any feedback appreciated and feel free to ask any questions!


@hecrj hecrj added bug Something isn't working improvement An internal improvement feature New feature or request labels May 23, 2020
@hecrj hecrj added this to the 0.2.0 milestone May 23, 2020
@hecrj hecrj self-assigned this May 23, 2020

/// The type of __messages__ your [`Program`] will produce.
///
/// [`Application`]: trait.Program.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little copy paste accident I guess:
Application -> Program

Love your work!

@hecrj
Copy link
Member Author

hecrj commented May 28, 2020

The new documentation is available at https://iced-docs.now.sh/iced/index.html

Copy link
Contributor

@Imberflur Imberflur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The iced_native top level docs still mention window::Backend which was moved

@hecrj
Copy link
Member Author

hecrj commented May 28, 2020

I think this is ready to be merged!

The OpenGL renderer still does not support the Image and Svg widgets, but I believe we can tackle that in another PR. There are many foundational changes in this one and it's important we merge it so we can build on top of them.

Given that the OpenGL renderer isn't feature-complete yet, I have kept iced_wgpu as the default one. The iced_glow renderer can be toggled using the new glow feature flag.

@hecrj hecrj merged commit d3db055 into master May 28, 2020
@hecrj hecrj deleted the feature/glow-renderer branch May 28, 2020 19:52
@draivin
Copy link

draivin commented May 29, 2020

Currently there is no way to create a glow renderer backend (as it is a pub(crate) export), is this intentional until things are more complete?

@hecrj
Copy link
Member Author

hecrj commented May 29, 2020

@draivin Not intentional. I forgot about exposing it 😅

@hecrj
Copy link
Member Author

hecrj commented May 30, 2020

@draivin I have exported it in 6cb9057.

@m4b
Copy link

m4b commented Jun 24, 2020

Does this PR indicate that iced will slowly move away from using wgpu (and eventually not at all)?

@hecrj
Copy link
Member Author

hecrj commented Jun 24, 2020

@m4b

No, as the description says:

This renderer is meant to be an alternative (not a replacement!) to iced_wgpu while wgpu and its ecosystem mature.

@m4b
Copy link

m4b commented Jun 24, 2020

Gosh, sorry I missed that, thanks for clarification :)

@0x7CFE
Copy link
Contributor

0x7CFE commented Jul 6, 2020

Are there any estimates on how hard it is to implement image support for OpenGL renderer? It's the only thing that prevents me from using iced on Raspberry Pi (see #428). With just a couple of shader hacks, everything else works fine.

@hecrj
Copy link
Member Author

hecrj commented Jul 7, 2020

@0x7CFE It shouldn't be hard to get a similar implementation to the iced_wgpu one.

However, we should try to abstract and move the atlas logic to iced_graphics instead of duplicating code. Additionally, it would be great to set the foundations for asynchronous loading of images at the same time. This is the hard part.

@Tarnadas
Copy link

@hecrj is there a tracking issue for Image and Svg support for the glow feature?

Also, could it be that the current master fails to compile with the glow feature? I'm getting lots of errors.

@MCOfficer
Copy link

MCOfficer commented Mar 8, 2021

@hecrj is there a tracking issue for Image and Svg support for the glow feature?

Seconded. I would create an issue myself, but i feel like the OP of a tracking issue should contain all meaningful information, and it would be much better if you had control over that OP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment