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: SecondaryFlagsThe channels this stream writes.
Implementations§
Source§impl SecondaryStreamWriter
impl SecondaryStreamWriter
Sourcepub fn uncompressed_uv(&self) -> bool
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.
Sourcepub fn is_empty(&self) -> bool
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.
Sourcepub fn channels(&self) -> StreamChannels
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.
Sourcepub fn byte_len(&self, vertex_count: usize) -> usize
pub fn byte_len(&self, vertex_count: usize) -> usize
Bytes one vertex_count-long stream occupies.
Sourcepub fn write(
&self,
uvs: &[[f32; 2]],
colors: &[CompressedColor],
normals: &[[f32; 3]],
metadata: &mut MeshMetadata,
out: WriteOnly<'_, [u8]>,
)
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.
Sourcepub fn write_compressed(
&self,
uvs: &[CompressedUv],
colors: &[CompressedColor],
normals: &[CompressedNormal],
out: WriteOnly<'_, [u8]>,
)
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.
Sourcefn raw_vertex_count(
&self,
uvs: &[[f32; 2]],
colors: &[CompressedColor],
normals: &[[f32; 3]],
) -> usize
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.
Sourcefn compressed_vertex_count(
&self,
uvs: &[CompressedUv],
colors: &[CompressedColor],
normals: &[CompressedNormal],
) -> usize
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
impl Clone for SecondaryStreamWriter
impl Copy for SecondaryStreamWriter
Source§impl Debug for SecondaryStreamWriter
impl Debug for SecondaryStreamWriter
Source§impl Default for SecondaryStreamWriter
impl Default for SecondaryStreamWriter
impl Eq for SecondaryStreamWriter
Source§impl PartialEq for SecondaryStreamWriter
impl PartialEq for SecondaryStreamWriter
impl StructuralPartialEq for SecondaryStreamWriter
Auto Trait Implementations§
impl Forget for SecondaryStreamWriter
impl Freeze for SecondaryStreamWriter
impl RefUnwindSafe for SecondaryStreamWriter
impl Send for SecondaryStreamWriter
impl Sync for SecondaryStreamWriter
impl Unpin for SecondaryStreamWriter
impl UnsafeUnpin for SecondaryStreamWriter
impl UnwindSafe for SecondaryStreamWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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