pub fn transfer_image_data_to_texture(
ctx: &RenderContext,
image_data: ImageDataDesc<'_>,
target_texture: &Arc<DynamicResource<GpuTextureHandle, TextureDesc, GpuTextureInternal>>
) -> Result<(), ImageDataToTextureError>
Expand description
Takes raw image data and transfers & converts it to a GPU texture.
Schedules render passes to convert the data to a samplable textures if needed.
Generally, we currently do not use sRGB converting formats like wgpu::TextureFormat::Rgba8UnormSrgb
in order to…
- have the same shader code path for high precision formats (e.g. an f16 texture that still encodes sRGB data)
- handle alpha pre-multiply on the fly (needs to happen before sRGB decode to linear)
Implementation note: Since we’re targeting WebGL, all data has always to be uploaded into textures (we can’t use raw buffers!). Buffer->Texture copies have restrictions on row padding, so any approach where we first allocate gpu readable memory and hand it to the user would make the API a lot more complicated.