pub(crate) trait Drawable: Bindable {
    fn get_vertices(&self) -> Result<Array1<f32>, Error>;
    fn get_indices(&self) -> Result<&Array1<u32>, Error>;
    fn get_max_length(&self) -> Result<f32, Error>;

    fn send_to_gpu(&self) -> Result<(), Error> { ... }
    fn draw(&self) -> Result<(), Error> { ... }
}
Expand description

General Information

All objects that can be drawn by OpenGL should implement a drawable trait. The main functions are setup and draw. Both which contain general implementations to setup drawable object in GPU and draw it respectively.

Required Methods§

Creates a way to obtain vertices from drawable object. Getter.

Creates a way to obtain indices to draw vertices (and triangles). Getter.

Creates a way to obtain order of object’s dimensions. Getter.

Provided Methods§

General Information

Once an object with Drawable trait has been created it can be sent to gpu. This function will send vertex and indices information to GPU to be drawn on screen. There’s a couple of steps that should never be skipped:

  • Object’s binder has to have been initialized prior to this function call.
  • Always bind object’s binder’s vao and/or texture.
  • There’s no need to bind ebo or vbo once vao is bound.
Parameters
  • &self - All information is stored inside the object an accesed through the getter methods above.
General Information

A simple call to glDrawElements in triangles mode. It assumes all information to be drawn has been sent and is stored in a single vbo, veo pair. (Making multiple calls to draw is, in general, not a good idea, since it can really slow down a program reducing the FPS. When drawing multiple objects, it’s better to use the so called ‘batch rendering’).

Parameters
  • &self - A reference to the object which is attached to a binder and knows how to get the indices and indices length.

Implementors§