pub struct TextureCompressor { /* private fields */ }Expand description
GPU-accelerated texture compressor for BC1 and BC4 block formats.
Create once with TextureCompressor::new, then call TextureCompressor::compress
for each image. The width and height supplied at construction time are
fixed for the lifetime of this object.
When no wgpu backend is available (e.g., headless CI) compress falls back
automatically to the CPU path provided by compress_bc1_block_cpu and
compress_bc4_block_cpu.
Implementations§
Source§impl TextureCompressor
impl TextureCompressor
Sourcepub fn new(
ctx: &GpuContext,
format: TextureFormat,
width: u32,
height: u32,
) -> GpuResult<Self>
pub fn new( ctx: &GpuContext, format: TextureFormat, width: u32, height: u32, ) -> GpuResult<Self>
Create a new TextureCompressor.
§Arguments
ctx— Active GPU context.format— Target compressed format (Bc1RgbUnormorBc4RUnorm).width— Pixel width of images to compress (must be a multiple of 4).height— Pixel height of images to compress (must be a multiple of 4).
§Errors
Returns GpuError::InvalidKernelParams when either dimension is not a
multiple of 4, or a pipeline error when WGSL compilation fails.
Sourcepub fn format(&self) -> TextureFormat
pub fn format(&self) -> TextureFormat
The target texture format.
Sourcepub fn compress(&self, ctx: &GpuContext, input: &[u8]) -> GpuResult<Vec<u8>>
pub fn compress(&self, ctx: &GpuContext, input: &[u8]) -> GpuResult<Vec<u8>>
Compress input using this compressor’s format.
- BC1:
inputmust bewidth × height × 4bytes (RGBA8 row-major). - BC4:
inputmust bewidth × heightbytes (R8 row-major).
Returns (width/4) × (height/4) × 8 bytes of block-compressed data.
§GPU path
When a wgpu backend is available the method dispatches a compute shader and reads back the result synchronously.
§CPU fallback
When self.pipeline is None (shader compilation failed or no backend)
or when wgpu dispatch fails, the method falls back to the pure-Rust
block encoders compress_bc1_block_cpu / compress_bc4_block_cpu.
§Errors
Returns an error when the input length does not match the expected size for the configured format and dimensions.