Skip to main content

TextureCompressor

Struct TextureCompressor 

Source
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

Source

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 (Bc1RgbUnorm or Bc4RUnorm).
  • 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.

Source

pub fn format(&self) -> TextureFormat

The target texture format.

Source

pub fn width(&self) -> u32

Image width (pixels) supplied at construction time.

Source

pub fn height(&self) -> u32

Image height (pixels) supplied at construction time.

Source

pub fn compress(&self, ctx: &GpuContext, input: &[u8]) -> GpuResult<Vec<u8>>

Compress input using this compressor’s format.

  • BC1: input must be width × height × 4 bytes (RGBA8 row-major).
  • BC4: input must be width × height bytes (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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more