Struct TransformFeedbackSession

Source
pub struct TransformFeedbackSession<'a> { /* private fields */ }
Expand description

Transform feedback allows you to obtain in a buffer the list of the vertices generated by the vertex shader, geometry shader, or tessellation evaluation shader of your program. This is usually used to cache the result in order to draw the vertices multiple times with multiple different fragment shaders.

To use transform feedback, you must create a transform feedback session. A transform feedback session mutably borrows the buffer where the data will be written. Each draw command submitted with a session will continue to append data after the data written by the previous draw command. You can only use the data when the session is destroyed.

§Notes

Here are a few things to note if you aren’t familiar with transform feedback:

  • The program you use must have transform feedback enabled, either with attributes in the vertex shader’s source code (for recent OpenGL versions only) or by indicating a list of vertex attributes when building the program.

  • A transform feedback session is bound to a specific program and buffer. You can’t switch them once the session has been created. An error is generated if you draw with a different program than the one you created the session with.

  • The transform feedback process doesn’t necessarily fill the whole buffer. To retrieve the number of vertices that are written to the buffer, use a query object (see the draw_parameters module). It is however usually easy to determine in advance the number of vertices that will be written based on the input data.

  • The buffer will obtain either a list of points, a list of lines (two vertices), or a list of triangles (three vertices). If you draw a triangle strip or a triangle fan for example, individual triangles will be written to the buffer (meaning that some vertices will be duplicated).

  • You can use the same session multiple times in a row, in which case the data will continue to be pushed in the buffer after the existing data. However you must always use the same type of primitives and the same program.

§Example

#[derive(Copy, Clone, Debug, PartialEq)]
struct Vertex {
    output_val: (f32, f32),
}

implement_vertex!(Vertex, output_val);

let mut out_buffer: glium::VertexBuffer<Vertex> = glium::VertexBuffer::empty(&display, 6).unwrap();

{
    let session = glium::vertex::TransformFeedbackSession::new(&display, &program,
                                                               &mut out_buffer).unwrap();

    let params = glium::DrawParameters {
        transform_feedback: Some(&session),
        .. Default::default()
    };

    display.draw().draw(&vb, &ib, &program, &uniform!{}, &params).unwrap();
}

let result: Vec<Vertex> = out_buffer.read().unwrap();
println!("List of generated vertices: {:?}", result);

Implementations§

Source§

impl<'a> TransformFeedbackSession<'a>

Source

pub fn new<F, V>( facade: &F, program: &'a Program, buffer: &'a mut Buffer<[V]>, ) -> Result<TransformFeedbackSession<'a>, TransformFeedbackSessionCreationError>
where F: Facade + ?Sized, V: Vertex + Copy + Send + 'static,

Builds a new transform feedback session.

TODO: this constructor should ultimately support passing multiple buffers of different types

Trait Implementations§

Source§

impl<'a> Debug for TransformFeedbackSession<'a>

Source§

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

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

impl<'a> Drop for TransformFeedbackSession<'a>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> Erased for T