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

Portable window transparency: alpha mode? #3486

Open
dhardy opened this issue Feb 14, 2023 · 2 comments
Open

Portable window transparency: alpha mode? #3486

dhardy opened this issue Feb 14, 2023 · 2 comments
Labels
area: documentation Documentation for crate items, public or private help required We need community help to make this happen. type: enhancement New feature or request

Comments

@dhardy
Copy link
Contributor

dhardy commented Feb 14, 2023

Continuing from #687, #2836: support for window transparency.

The status quo, as I understand it, is that an application window may use transparency by (1) enabling window transparency (e.g. winit::window::WindowBuilder::with_transparent) and (2) selecting a CompositeAlphaMode other than Opaque.

The problem

I may be wrong here, but the way I see it, WGPU is supposedly a medium-level portable graphics library. CompositeAlphaMode feels like a low-level control and is not portable (attempting to use any unsupported option is an error).

CompositeAlphaMode lists several options, of which only a subset are likely supported by the device/platform:

  • Auto: chooses Opaque or Inherit
  • Opaque: ignore alpha channel. May not be supported?
  • PreMultiplied: expect non-alpha channels are pre-multiplied by alpha. May not be supported?
  • PostMultiplied: non-alpha channels are not pre-multiplied. May not be supported.
  • Inherit: platform-specific result. Refers to "native WSI command" without further details.

Probing

Only a subset of the above are supported. This is described by SurfaceCapabilities::alpha_modes. Applications must select whichever of the supported modes is closest to their requirements.

Conversion

It appears that applications wishing to support portable transparency must be prepared to output textures compliant with multiple of the above modes, and thus must be able to convert depending on the mode selected.

Suggested solutions

High-level API

One alternative is a high-level API, supporting only the following modes, and supporting them on all platforms (with automatic conversion where required):

  • Opaque
  • PreMultiplied
  • PostMultiplied

Better docs

Otherwise, please better document the following:

  • On which platforms / devices one can expect each mode to be supported
  • More details on how to determine / select the behaviour of Inherit
  • How to convert one texture format to another where required (presumably there are standard approaches for this)
@teoxoy teoxoy added area: api Issues related to API surface type: enhancement New feature or request help required We need community help to make this happen. labels Feb 14, 2023
@cwfitzgerald cwfitzgerald added area: documentation Documentation for crate items, public or private and removed area: api Issues related to API surface labels Feb 15, 2023
@cwfitzgerald
Copy link
Member

Thanks for this very detailed issue!

As a general rule we don't want to be injecting any kind of conversions if we don't have to - we present as a bit higher level, but also go out of our way to not need to emulate (with some exception for some things in GL).

I think we should go the route of better documentation as this both will give the users the information they need to prepare for various situations and keep the explicit knowlege of how the swapchain is behaving.

@Diggsey
Copy link
Contributor

Diggsey commented Feb 15, 2023

A wgpu example showing how to use window transparency in a portable way would be useful (which handles the conversion in a sensible way).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: documentation Documentation for crate items, public or private help required We need community help to make this happen. type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants