Struct gfx::Slice

source ·
pub struct Slice<R: Resources> {
    pub start: VertexCount,
    pub end: VertexCount,
    pub base_vertex: VertexCount,
    pub instances: Option<InstanceParams>,
    pub buffer: IndexBuffer<R>,
}
Expand description

A Slice dictates in which and in what order vertices get processed. It is required for processing a PSO.

Overview

A Slice in gfx has a different meaning from the term slice as employed more broadly in rust (&[T]).

A Slice object in essence dictates in what order the vertices in a VertexBuffer get processed. To do this, it contains an internal index-buffer. This Buffer is a list of indices into this VertexBuffer (vertex-index). A vertex-index of 0 represents the first vertex in the VertexBuffer, a vertex-index of 1 represents the second, 2 represents the third, and so on. The vertex-indices in the index-buffer are read in order; every vertex-index tells the pipeline which vertex to process next.

Because the same index can re-appear multiple times, duplicate-vertices can be avoided. For instance, if you want to draw a square, you need two triangles, and thus six vertices. Because the same index can reappear multiple times, this means we can instead use 4 vertices, and 6 vertex-indices.

This index-buffer has a few variants. See the IndexBuffer documentation for a detailed description.

The start and end fields say where in the index-buffer to start and stop reading. Setting start to 0, and end to the length of the index-buffer, will cause the entire index-buffer to be processed. The base_vertex dictates the index of the first vertex in the VertexBuffer. This essentially moves the the start of the VertexBuffer, to the vertex with this index.

Constuction & Handling

The Slice structure can be constructed automatically when using a Factory to create a vertex buffer. If needed, it can also be created manually.

A Slice is required to process a PSO, as it contains the needed information on in what order to draw which vertices. As such, every draw call on an Encoder requires a Slice.

Fields§

§start: VertexCount

The start index of the index-buffer. Processing will start at this location in the index-buffer.

§end: VertexCount

The end index in the index-buffer. Processing will stop at this location (exclusive) in the index buffer.

§base_vertex: VertexCount

This is the index of the first vertex in the VertexBuffer. This value will be added to every index in the index-buffer, effectively moving the start of the VertexBuffer to this base-vertex.

§instances: Option<InstanceParams>

Instancing configuration.

§buffer: IndexBuffer<R>

Represents the type of index-buffer used.

Implementations§

source§

impl<R: Resources> Slice<R>

source

pub fn from_vertex_count(count: VertexCount) -> Self

Creates a new Slice with a given vertex count.

source

pub fn new_match_vertex_buffer<V>(vbuf: &Buffer<R, V>) -> Selfwhere V: Structure<Format>,

Creates a new Slice to match the supplied vertex buffer, from start to end, in order.

source

pub fn get_prim_count(&self, prim: Primitive) -> u32

Calculates the number of primitives of the specified type in this Slice.

source

pub fn split_at(&self, mid: VertexCount) -> (Self, Self)

Divides one slice into two at an index.

The first will contain the range in the index-buffer [self.start, mid) (excluding the index mid itself) and the second will contain the range [mid, self.end).

Trait Implementations§

source§

impl<R: Clone + Resources> Clone for Slice<R>

source§

fn clone(&self) -> Slice<R>

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl<R: Debug + Resources> Debug for Slice<R>

source§

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

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

impl<R: Hash + Resources> Hash for Slice<R>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<R: PartialEq + Resources> PartialEq<Slice<R>> for Slice<R>

source§

fn eq(&self, other: &Slice<R>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<R: Eq + Resources> Eq for Slice<R>

source§

impl<R: Resources> StructuralEq for Slice<R>

source§

impl<R: Resources> StructuralPartialEq for Slice<R>

Auto Trait Implementations§

§

impl<R> !RefUnwindSafe for Slice<R>

§

impl<R> Send for Slice<R>

§

impl<R> Sync for Slice<R>

§

impl<R> Unpin for Slice<R>

§

impl<R> !UnwindSafe for Slice<R>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToOwned for Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.