Creates a new render surface for the specified window and dimensions.
(
surface: Surface<'w>,
surface_renderer_config: SurfaceRendererConfiguration,
intermediate_texture_config: Option<TextureConfiguration>,
device_handle: DeviceHandle,
| 105 | /// View formats of the same format as the texture are always allowed. |
| 106 | /// |
| 107 | /// Note: currently, only the srgb-ness is allowed to change. (ex: `Rgba8Unorm` texture + `Rgba8UnormSrgb` view) |
| 108 | pub view_formats: Vec<TextureFormat>, |
| 109 | } |
| 110 | |
| 111 | struct IntermediateTextureStuff { |
| 112 | pub config: TextureConfiguration, |
| 113 | // TextureView for the intermediate Texture which we sometimes render to because compute shaders |
| 114 | // cannot always render directly to surfaces. Since WGPU 26, the underlying Texture can be accessed |
| 115 | // from the TextureView so we don't need to store both. |
| 116 | pub texture_view: TextureView, |
| 117 | // Blitter for blitting from the intermediate texture to the surface. |
| 118 | pub blitter: IntermediateBlitter, |
| 119 | } |
| 120 | |
| 121 | /// Combination of surface and its configuration. |
| 122 | pub struct SurfaceRenderer<'s> { |
| 123 | // The device and queue for rendering to the surface |
| 124 | pub device_handle: DeviceHandle, |
| 125 | |
| 126 | // The surface and it's configuration |
| 127 | pub surface: Surface<'s>, |
| 128 | pub config: SurfaceConfiguration, |
| 129 | |
| 130 | current_surface_texture: Option<SurfaceTexture>, |
| 131 | intermediate_texture: Option<Box<IntermediateTextureStuff>>, |
| 132 | } |
| 133 | |
| 134 | impl std::fmt::Debug for SurfaceRenderer<'_> { |
| 135 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { |
| 136 | f.debug_struct("SurfaceRenderer") |
| 137 | .field("surface_config", &self.config) |
| 138 | .field("has_intermediate_texture", &true) |
| 139 | .finish() |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | impl<'s> SurfaceRenderer<'s> { |
| 144 | /// Creates a new render surface for the specified window and dimensions. |
| 145 | pub fn new<'w>( |
| 146 | surface: Surface<'w>, |
| 147 | surface_renderer_config: SurfaceRendererConfiguration, |
| 148 | intermediate_texture_config: Option<TextureConfiguration>, |
| 149 | device_handle: DeviceHandle, |
| 150 | ) -> Result<SurfaceRenderer<'w>, WgpuContextError> { |
| 151 | // Convert SurfaceRendererConfiguration to SurfaceConfiguration. |
| 152 | // The difference is that `format` is a Vec in SurfaceRendererConfiguration and a single value in SurfaceConfiguration |
| 153 | let surface_config = SurfaceConfiguration { |
| 154 | usage: surface_renderer_config.usage, |
| 155 | format: surface |
| 156 | .get_capabilities(&device_handle.adapter) |
| 157 | .formats |
nothing calls this directly
no test coverage detected