Capture the Bloom framebuffer as PNG. Called from the geisterhand pump BEFORE end_frame in bloom_end_drawing. The vertices_3d/2d and VP matrix from the game loop are still populated; we render to a fresh surface texture with screenshot capture, producing the same visual output as the real frame.
(out_len: *mut usize)
| 2789 | /// texture with screenshot capture, producing the same visual output as |
| 2790 | /// the real frame. |
| 2791 | extern "C" fn bloom_screenshot_capture(out_len: *mut usize) -> *mut u8 { |
| 2792 | let eng = engine(); |
| 2793 | |
| 2794 | eng.renderer.screenshot_requested = true; |
| 2795 | eng.scene.prepare( |
| 2796 | &eng.renderer.device, |
| 2797 | &eng.renderer.queue, |
| 2798 | &eng.renderer.vp_matrix(), |
| 2799 | &eng.renderer.prev_vp_matrix, |
| 2800 | eng.renderer.uniform_3d_layout(), |
| 2801 | ); |
| 2802 | eng.scene.prepare_materials(&eng.renderer); |
| 2803 | { |
| 2804 | let t = eng.get_time() as f32; |
| 2805 | let dt = eng.delta_time as f32; |
| 2806 | eng.renderer.material_system_begin_frame(t, dt); |
| 2807 | } |
| 2808 | eng.renderer.end_frame_with_scene(&mut eng.scene, &mut eng.profiler); |
| 2809 | |
| 2810 | match eng.renderer.screenshot_data.take() { |
| 2811 | Some((width, height, rgba)) => { |
| 2812 | match encode_png(width, height, &rgba) { |
| 2813 | Some(png_data) => { |
| 2814 | let len = png_data.len(); |
| 2815 | let ptr = unsafe { libc::malloc(len) as *mut u8 }; |
| 2816 | if ptr.is_null() { |
| 2817 | unsafe { *out_len = 0; } |
| 2818 | return std::ptr::null_mut(); |
| 2819 | } |
| 2820 | unsafe { |
| 2821 | std::ptr::copy_nonoverlapping(png_data.as_ptr(), ptr, len); |
| 2822 | *out_len = len; |
| 2823 | } |
| 2824 | ptr |
| 2825 | } |
| 2826 | None => { |
| 2827 | unsafe { *out_len = 0; } |
| 2828 | std::ptr::null_mut() |
| 2829 | } |
| 2830 | } |
| 2831 | } |
| 2832 | None => { |
| 2833 | unsafe { *out_len = 0; } |
| 2834 | std::ptr::null_mut() |
| 2835 | } |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | /// Minimal PNG encoder (no external dependency). Matches the macOS |
| 2840 | /// implementation byte-for-byte so screenshots are identical across |
nothing calls this directly
no test coverage detected