Skip to main content

SecondaryStreamWriter

Struct SecondaryStreamWriter 

Source
pub struct SecondaryStreamWriter {
    pub flags: SecondaryFlags,
}
Expand description

The optional per-vertex channels of a secondary vertex stream: the UV, color and normal that a mesh carries beside its position.

Each channel adds one attribute to crate::pipeline::SECONDARY_SLOT, in the order UV, color then normal, so the packed stream matches the shader’s declared locations for any combination. Self::write compresses the raw attributes and interleaves them straight into the target buffer.

Fields§

§flags: SecondaryFlags

The channels this stream writes.

Implementations§

Source§

impl SecondaryStreamWriter

Source

pub fn uv(&self) -> bool

Whether the UV attribute is written.

Source

pub fn color(&self) -> bool

Whether the color attribute is written.

Source

pub fn normal(&self) -> bool

Whether the normal attribute is written.

Source

pub fn uncompressed_uv(&self) -> bool

Whether the UV is written full precision rather than compressed to Snorm16x2.

An uncompressed UV needs no decode parameters, so Self::write leaves the metadata alone.

Source

pub fn is_empty(&self) -> bool

Whether the variant declares no attributes at all, in which case the slot must be omitted from the vertex-buffer list.

Source

pub fn channels(&self) -> StreamChannels

The channels this stream carries, in attribute order.

The single description the stride, the attribute offsets and the packed bytes are all derived from.

Source

pub fn stride(&self) -> u32

Bytes per vertex of the packed stream.

Source

pub fn byte_len(&self, vertex_count: usize) -> usize

Bytes one vertex_count-long stream occupies.

Source

pub fn write( &self, uvs: &[[f32; 2]], colors: &[CompressedColor], normals: &[[f32; 3]], metadata: &mut MeshMetadata, out: WriteOnly<'_, [u8]>, )

Compress the raw uvs and normals and write the interleaved result, together with the already compressed colors, into out — which must be exactly Self::byte_len(vertex_count) bytes, normally a mapped-at-creation vertex buffer, so the vertices land in GPU memory without an intermediate byte buffer.

Colors are taken as CompressedColor because that is what the stream stores; float colors from a [glam::Vec4] can be quantized with quantize_colors first. Normals need no such preparation: the octahedral encoding is absolute, so they are compressed here.

metadata receives the UV decode parameters the compression derives, exactly as compress_uvs would.

Nothing is allocated: the compressed UVs are produced lazily and written as they are computed. Use Self::write_compressed to write channels that are already compressed, for example to share one stream across several meshes.

§Panics

If an enabled channel has no matching slice, if the channel lengths disagree, or if out is not exactly one stream long.

Source

pub fn write_compressed( &self, uvs: &[CompressedUv], colors: &[CompressedColor], normals: &[CompressedNormal], out: WriteOnly<'_, [u8]>, )

Write the already compressed uvs, colors and normals into out as the interleaved vertex stream, which must be exactly Self::byte_len(vertex_count) bytes.

Takes the packed form produced by compress_uvs, quantize_colors and compress_normals, so one compressed stream can be uploaded for several meshes without recompressing it.

§Panics

If an enabled channel has no matching slice, if the channel lengths disagree, or if out is not exactly one stream long.

Source

fn raw_vertex_count( &self, uvs: &[[f32; 2]], colors: &[CompressedColor], normals: &[[f32; 3]], ) -> usize

Number of vertices the raw channel slices describe.

Every enabled channel describes the same vertices, so the first one sets the count and the rest must agree; a stream whose channels disagree has no length that would pack them together.

Source

fn compressed_vertex_count( &self, uvs: &[CompressedUv], colors: &[CompressedColor], normals: &[CompressedNormal], ) -> usize

Number of vertices the compressed channel slices describe.

Trait Implementations§

Source§

impl Clone for SecondaryStreamWriter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for SecondaryStreamWriter

Source§

impl Debug for SecondaryStreamWriter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SecondaryStreamWriter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for SecondaryStreamWriter

Source§

impl PartialEq for SecondaryStreamWriter

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SecondaryStreamWriter

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
§

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

§

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

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

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

§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

§

fn simd_from(_simd: S, value: T) -> T

§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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