1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-02 23:00:04 -04:00

Add screenshot support for eframe web (#5438)

This implements web support for taking screenshots in an eframe app (and
adds a nice demo).
It also updates the native screenshot implementation to work with the
wgpu gl backend.

The wgpu implementation is quite different than the native one because
we can't block to wait for the screenshot result, so instead I use a
channel to pass the result to a future frame asynchronously.

* Closes <https://github.com/emilk/egui/issues/5425>
* [x] I have followed the instructions in the PR template


https://github.com/user-attachments/assets/67cad40b-0384-431d-96a3-075cc3cb98fb
This commit is contained in:
lucasmerlin
2024-12-12 19:17:42 +01:00
committed by GitHub
parent de8ac88c0e
commit 6c1d695fc6
13 changed files with 613 additions and 272 deletions

View File

@@ -0,0 +1,43 @@
struct VertexOutput {
@builtin(position) position: vec4<f32>,
};
var<private> positions: array<vec2f, 3> = array<vec2f, 3>(
vec2f(-1.0, -3.0),
vec2f(-1.0, 1.0),
vec2f(3.0, 1.0)
);
// meant to be called with 3 vertex indices: 0, 1, 2
// draws one large triangle over the clip space like this:
// (the asterisks represent the clip space bounds)
//-1,1 1,1
// ---------------------------------
// | * .
// | * .
// | * .
// | * .
// | * .
// | * .
// |***************
// | . 1,-1
// | .
// | .
// | .
// | .
// |.
@vertex
fn vs_main(@builtin(vertex_index) vertex_index: u32) -> VertexOutput {
var result: VertexOutput;
result.position = vec4f(positions[vertex_index], 0.0, 1.0);
return result;
}
@group(0)
@binding(0)
var r_color: texture_2d<f32>;
@fragment
fn fs_main(vertex: VertexOutput) -> @location(0) vec4<f32> {
return textureLoad(r_color, vec2i(vertex.position.xy), 0);
}