pub trait TextureSource {
// Required methods
fn texture_format(&self) -> TextureFormat;
fn texture_width(&self) -> u32;
fn texture_height(&self) -> u32;
fn texture_bytes(&self) -> &[u8] ⓘ;
fn bytes_per_row(&self) -> u32;
}Expand description
Zero-copy texture data source for GPU upload.
Provides format metadata and byte access in a single trait, suitable for passing directly to GPU texture creation and upload helpers.
This trait is blanket-implemented for any PlainImage image whose
pixel implements GpuPixel. You do not need to implement it manually.
§What implements TextureSource?
| Type | Implements? | Why |
|---|---|---|
Image<Srgba8> | ✅ Yes | PlainImage + GpuPixel |
Image<Mono8> | ✅ Yes | PlainImage + GpuPixel |
ImageArray<Rgba8, 4, 4> | ✅ Yes | PlainImage + GpuPixel |
Image<Rgb8> | ❌ No | Rgb8 has no GpuPixel impl (3-channel) |
ImageRef<'_, Srgba8> | ❌ No | No PlainImage (non-contiguous) |
§Examples
use fovea::image::{Image, PlainImage};
use fovea::pixel::Srgba8;
use fovea_display::{TextureSource, TextureFormat};
let img = Image::fill(16, 8, Srgba8::new(255, 0, 0, 255));
assert_eq!(img.texture_format(), TextureFormat::Rgba8Srgb);
assert_eq!(img.texture_width(), 16);
assert_eq!(img.texture_height(), 8);
assert_eq!(img.bytes_per_row(), 16 * 4); // 16 pixels × 4 bytes each
assert_eq!(img.texture_bytes().len(), 16 * 8 * 4);use fovea::image::Image;
use fovea::pixel::Rgb8;
use fovea_display::TextureSource;
// ERROR: Rgb8 does not implement GpuPixel — 3-channel types have
// no direct GPU representation. Convert to Rgba8 first.
let img = Image::fill(4, 4, Rgb8::new(0, 0, 0));
let _ = img.texture_format();Required Methods§
Sourcefn texture_format(&self) -> TextureFormat
fn texture_format(&self) -> TextureFormat
The GPU texture format for this image’s pixel type.
Sourcefn texture_width(&self) -> u32
fn texture_width(&self) -> u32
Image width in pixels.
Sourcefn texture_height(&self) -> u32
fn texture_height(&self) -> u32
Image height in pixels.
Sourcefn texture_bytes(&self) -> &[u8] ⓘ
fn texture_bytes(&self) -> &[u8] ⓘ
The raw pixel bytes, in row-major order with no padding.
The returned slice has length
texture_width() * texture_height() * texture_format().bytes_per_pixel().
Sourcefn bytes_per_row(&self) -> u32
fn bytes_per_row(&self) -> u32
Logical bytes per row (width × bytes per pixel), without GPU alignment padding.
Upload helpers are responsible for adding alignment padding if the target GPU API requires it (e.g. wgpu’s 256-byte row alignment).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".