Commit graph

80 commits

Author SHA1 Message Date
Jay Oster 4c6682e65b
Configurable clear color (#236)
- Closes #235
- Now using alpha blending (non-premultiplied) in the scaling renderer
  so that the clear color can be blended with the texture. This can be
  made configurable, but we'll go with this for now.
2021-12-05 14:23:06 -08:00
Jay Oster 2a4ebbf19d
Fix half-pixel offsets in scaling renderer (#231)
* Fix half-pixel offsets in scaling renderer

- This bug was very subtle. It can be hard to notice!
- Context: When the scaling renderer transformation matrix is created,
  it needs to center the image within the border.
- The previous code always evaluated the translation to (0, 0)
- This PR makes half-pixel adjustments to the translation when needed,
  making it impossible to rasterize the texture on a half-pixel
  boundary.
- I spotted this while working on pixel-aspect-ratio support, but it can
  most easily be witnessed in the `conway` example by grabbing the top
  or bottom resize handle on the window and slow dragging it up and down
  by 1-pixel-at-a-time. When you hit a half-pixel bug the entire texture
  will change slightly; some pixels will become hidden or duplicated.

* Bump MSRV
2021-12-01 21:36:56 -08:00
Jay Oster b2b8f1140d
Fix inverted Y-axis in window_pos_to_pixel() (#229)
- This fixes a regression caused by #228
2021-12-01 08:08:48 -08:00
Jay Oster c2454b01ab
Simplify vertex attributes (#228)
- Vertex UVs can be computed from the positions, which saves a small amount of code and a small amount of bandwidth (both inconsequential).
- This is mostly for readability.
- Fixes vertically-flipped pixel buffer in the `custom-shader` example.
2021-11-20 14:06:23 -08:00
Jay Oster b185ec32e9
Initial WebGL2 support. (#218)
Co-authored-by: MarkAnthonyM <37249494+MarkAnthonyM@users.noreply.github.com>
2021-11-16 11:37:56 -08:00
Jay Oster acd42495f2
Use adapter limits (unless overridden) (#226)
- Fixes a regression caused by #223
- `downlevel_webgl2_defaults` only supports 2048x2048 pixels buffers
- This will allow pixel buffers up to the max supported by the hardware
2021-11-14 17:20:57 -08:00
Jay Oster 6662fec55b
Set default device limits to downlevel_webgl2_defaults (#223)
- Fixes #139
- See also #115
2021-11-12 11:01:32 -08:00
Jay Oster 0fc722e011
Refactor public API (#222)
* Simplify constructor return types

* Render methods do not need an exclusive borrow
2021-11-08 20:03:38 -08:00
Jay Oster 5b00f7e32f
Make SurfaceSize private (#220)
- This struct is only used internally. No need to make it public.
- Technically a breaking change, so this will bump the SemVer.
2021-11-02 22:05:10 -07:00
Jay Oster 0295a54e30
Prepare 0.7.0 (#210) 2021-10-08 12:11:43 -07:00
JMS55 800dd931b7
Update to wgpu 0.11 (#209)
Co-authored-by: Jay Oster <jay@kodewerx.org>
2021-10-08 11:49:51 -07:00
Jay Oster c94dab65b7
Use wgpu environment variables (#198)
- Enables projects using `pixels` to select GPU and backend with
  the same environment variables used by `wgpu` examples.
- cc #142
2021-09-04 15:26:30 -07:00
Jay Oster 50c77a5f83
Add Send + Sync bounds for user-defined errors (#197)
- This enables compatibility with anyhow and the async ecosystem
2021-09-04 14:41:43 -07:00
Jay Oster db00a67c60
Add user-defined errors for render functions (#196)
- Fixes #189
2021-09-04 09:00:25 -07:00
Jay Oster b00c65fc55
Properly clip pixel buffer when larger than surface texture (#190)
- Fixes #186
2021-09-01 20:53:08 -07:00
Jay Oster e08c91bfd2
Update to wgpu 0.10 (#187)
- It would be nice to return an error from the render function
- imgui-winit is still a WIP (open PR: https://github.com/Yatekii/imgui-wgpu-rs/pull/66)
- Update README

Co-authored-by: Mohammed Alyousef <mohammed.alyousef@neurosrg.com>
2021-09-01 14:50:43 -07:00
Jay Oster 288da3675f
Use the swapchain-preferred texture format by default (#182)
- Fixes #140
- Adds a public method to get the current GPU framebuffer texture format (AKA the render texture format).
- This wasn't as difficult as it seemed; the extra API is used by the examples to get the right texture format instead of being hardcoded.
2021-07-17 08:21:49 -07:00
Jay Oster c4df23f65d
Update to wgpu 0.9 (#179)
* Update to wgpu 0.9

* Fix validation error in WGSL shader

- This moves the hardcoded vertex positions and texture coordinates to
  the vertex buffer.
- Replaces the two-triangle quad to 1 full-screen triangle (fixes #180)
- Rewrites the custom shader example to fix a bug with large surface
  textures;
  - The input texture size was used for the output texture, causing the
    purple rectangle to appear very jumpy on large displays in full screen.
- The `ScalingRenderer` now exposes its clipping rectangle. The custom
  shader example uses this for its own clipping rectangle, but it can
  also be used for interacting with the border in general.

* Switch to `wgpu::include_wgsl!()`

- This is a nice little simplification.
- Thanks to @JMS55 for the suggestion!
2021-06-27 11:09:29 -07:00
Jay Oster 338a63a40e
Minor improvement: only one shader module is necessary (#175) 2021-06-08 07:09:58 -07:00
Jay Oster 8d77ac2f8b
Rewrite shaders in WGSL (#172)
- Fixes #141
2021-06-05 18:40:33 -07:00
Jay Oster cdcfe57868
Validate width and height inputs (#162)
* Validate width and height inputs

- Fixes #157

* Add window size check to `imgui-winit` demo

- There is really nothing better that can be done in this case.
- The surface, buffer, and world sizes must all be non-zero.
- A zero-length surface would (previously) panic in `wgpu`.
- A zero-length buffer would panic with the new assertions.
- A zero-length world would cause a divide-by-zero panic when drawing.
2021-05-08 17:26:21 -07:00
Jay Oster f238814d12
Update wgpu to 0.8 (#160)
- Also update other dependencies
2021-05-07 23:52:11 -07:00
Jay Oster 9bfed17a7f
Various fixes (#154)
* Cargo clippy

* Fix typo
2021-03-29 00:52:43 -07:00
JMS55 11c5961e4c
Use default() when making wgpu::RenderPipelineDescriptor (#152) 2021-03-11 18:14:34 -08:00
Jay Oster 8071f34a1f
Rename resize to resize_surface (#149)
- Also cleanup documentation.
- Workaround FLTK window resize issues by disabling resizability.
2021-03-09 04:15:24 -08:00
Jay Oster 5dbe87d0c0
Fix matrix when creating a scaling renderer (#143)
- This issue can be seen when creating a window and pixel buffer that have differing sizes; the image will be stretched to fill the window.
- If the window supports the resize callback to correct the image aspect ratio, resizing the window will correct the matrix immediately, adding the black border as expected. This is a jarring effect when the texture size ratio is not an integer.
- This bug also causes issues with the new `resize_buffer()` API.
2021-03-03 10:45:14 -08:00
JMS55 f2d4a4f084
Upgrade to wgpu 0.7 (#134)
Co-authored-by: Jay Oster <jay@kodewerx.org>
2021-02-28 15:29:36 -08:00
Jay Oster 0709161e02 Remove commented code 2021-02-28 14:08:41 -08:00
Josh 26ae25c3d8
Resize buffer (#136)
- Fixes #125
2021-02-28 14:05:28 -08:00
Jay Oster 70ff52948b
Refactor builder (#128)
* Refactor PixelsBuilder into its own module

* Remove HasRawWindowHandle from public interface
2020-12-13 19:15:00 -08:00
schnippl0r fb243b8973
Expose new API method render_texture_format(). (#123)
This method is needed to let the user of the API configure the texture
format of the target texture/render texture that the surface texture is
rendered on. This texture format is hardware/platform dependent.

For example, this method makes it possible to use the pixels crate on
Android because Android seems not to use the previously hard-coded
texture format wgpu::TextureFormat::Bgra8UnormSrgb.
2020-12-10 18:40:06 -08:00
Jay Oster b6526c27e5
Remove pixels-dragons (#114)
- I don't want to publish this crate.
- Can't publish pixels 0.2.0 if it depends on an internal unpublished crate.
- This requires allowing unsafe code, and removing the safety dance badge.
2020-08-20 17:19:40 -07:00
Jay Oster 265ba2e5b3
Render API v2 (#112)
* WIP: Render API v2

* Fix doctests

* Expose all of PixelsContext (#110)

* Fix ScalingRenderer::new() taking &mut Device

* Replace getters with direct access to &mut PixelsContext

* Fix wrong reference type

* Fix unneeded mut

* Remove unnecessary mutable borrow, resurrect the shorter getter methods

* Initial port to wgpu master (0.6)
Surface creation is broken (see examples)
Does not support compressed textures

* Fix SurfaceTexture and examples

* Add support for compressed texture formats

* resize doesn't need mutability

* Update documentation

* Update wgpu

* Prepare release

* Goodbye Travis! Thanks for all the fish

Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
2020-08-20 16:49:19 -07:00
Jay Oster e3b10ab83b
Fix the doc issue described in #80 (#99) 2020-07-19 01:56:52 -07:00
Jay Oster 7e38a7262d
Some documentation fixes. (#97) 2020-07-18 22:25:51 -07:00
Jay Oster 27e7bfe998
New render api (#96)
* Extreme WIP: New wgpu access api

* Add getters for device and queue to Pixels

* Don't run ScalingRenderer in render_custom()

* Expose Pixels::scaling_renderer

* Fix exposing ScalingRenderer

* Tweak Pixels::render_custom()

* Cleanup

* More cleanup

* Fix doc comment

* Clippy

* Fix doctests

Co-authored-by: JMS55 <47158642+JMS55@users.noreply.github.com>
2020-07-18 18:12:37 -07:00
Jay Oster 755b1fed28
Add environment variable overrides for wgpu::PowerPreference (#94)
* Add environment variable overrides for `wgpu::PowerPreference`

* Bump MSRV
2020-07-17 17:31:16 -07:00
Jay Oster b397eb4e48
Change Vsync setting to use Fifo present mode (#93)
And add a method to set `Mailbox` or other explicit modes.

Closes #88
2020-07-17 16:34:54 -07:00
Jay Oster 7779d682cf
Fix compatible_surface overrides when RequestAdapterOptions is provided (#85)
- This will use the default `compatible_surface` from `SurfaceTexture` when `RequestAdapterOptions` is configured without `compatible_surface`.
2020-06-05 02:20:17 -07:00
JMS55 4991d2cddc
Switch from futures-executor to pollster (#84) 2020-05-29 05:29:12 -07:00
JMS55 b55f75e157
Fix include_spv!() documentation (#81) 2020-05-23 16:59:11 -07:00
Aeledfyr c96e46d3d4
Add a method to convert cursor coords to pixel coords (#77)
* Add a method to convert cursor coords to pixel coords

* Add method `window_pos_to_pixel` to Pixels struct
   * Converts cursor / window physical coordinates to pixel coords

* Fix formatting

* Return result rather than clamping pixel coordinates

* Use transformation matrices to convert from cursor coord to pixel

* Adds a struct ScalingMatrix that manages the creation and usage
  of the transformation matrix used in the renderer.
* Added an inverse function on ScalingMatrix - 4x4 matrix inverse
  (This should probably use a library, but it doesn't seem worth
  adding a dependancy for one function)

* Optimize matrix multiplication for cursor position calculation

* Use ultraviolet for matrix and vector math

* Add suggested changes

This keeps the split between usize and isize
This also changes the input cursor position to f32, because it was
immediately cast to an f32 for the transformations.
2020-05-20 21:37:29 -07:00
Aeledfyr b43336d45d
Add builder methods for VSync and setting wgpu backend (#78)
* Add builder methods for VSync and setting wgpu backends

* enable_vsync sets the VSync mode
* wgpu_backend sets the wgpu BackendBit struct
* Made RequestAdapterOptions use compatible_surface by default

* Internally store wgpu::PresentMode for enabling vsync

This doesn't expose the PresentMode for the external api, because
the variants of PresentMode aren't very obvious to people without
wgpu experience.  Mailbox corresponds to VSync enabled, and
Immediate corresponds to VSync disabled.
2020-05-19 18:09:57 -07:00
Jay Oster 774b749145
Slim dependencies (#71) 2020-04-13 21:06:01 -07:00
Jay Oster 9de2383712
Fix dependency bloat (#67)
* Move all examples to individual crates

* CI: Add libsdl2

* Use Ubuntu bionic for updated libsdl; 2.0.8

* Clippy

* libudev-dev is a dependency of libsdl2-dev

* Clippy

* Remove unnecessary dev-dependency

* `winit` is actually used in unit tests

* Fix a typo

* Move `simple-invaders` crate
2020-04-13 10:12:18 -07:00
Jay Oster 37b90fe6b4
Fix transform for wgpu 0.5 (#66) 2020-04-12 23:51:04 -07:00
Bernardo Meurer 246375f0e9
treewide: bump dependencies (#60) 2020-04-12 23:13:40 -07:00
Jay Oster b38363a602
Fix CI (#58)
* Replace bespoke Error impl with `thiserror`

* cargo update

* Finix winit version in dev-dependencies
2020-03-17 20:36:08 -07:00
Jay Oster 17c94574a2
Safety dance (#50)
* Update Cargo.lock

* Forbid unsafe

* Update README
2019-11-19 22:10:08 -08:00
fuckwit c5718cc041 Remove Unsafe in macro.rs (#43)
* remove unsafe slice::from_raw_parts

this should be a way to remove the unsafe code in the Spirv Deref impl.
Not sure how it affects performance yet.
I will take a look at the bytecode and see if maybe the compiler is
smart enough to optimize that away.

* change renderers to accomodate new Deref

Let the deref return a `Vec<u32>` instead of a slice reference. This
should not hurt performance too much as this will be done a finite
amount of times att startup.

* replaced deref with normal impl

* fixed endianness, fixed offset + rustfmt

* bump version

* fixed clippy lints

* respect the target endianness

* use wgpu::read_spirv()

* remove an unneccessary allocation of a vec

* move borrow into macro
2019-11-19 21:27:55 -08:00