[−][src]Struct golem::ShaderProgram
A GPU program that draws data to the screen
Methods
impl ShaderProgram
[src]
pub fn new(
ctx: &Context,
desc: ShaderDescription
) -> Result<ShaderProgram, GolemError>
[src]
ctx: &Context,
desc: ShaderDescription
) -> Result<ShaderProgram, GolemError>
Create a shader program with the given ShaderDescription
pub fn is_bound(&self) -> bool
[src]
Check if this shader program is currently bound to be operated on
pub fn set_uniform(
&self,
name: &str,
uniform: UniformValue
) -> Result<(), GolemError>
[src]
&self,
name: &str,
uniform: UniformValue
) -> Result<(), GolemError>
Set a uniform value, assuming the shader is bound by ShaderProgram::bind
pub fn bind(&mut self)
[src]
Bind this shader to use it, either to set a uniform
or to draw
pub unsafe fn draw(
&self,
vb: &VertexBuffer,
eb: &ElementBuffer,
range: Range<usize>,
geometry: GeometryMode
) -> Result<(), GolemError>
[src]
&self,
vb: &VertexBuffer,
eb: &ElementBuffer,
range: Range<usize>,
geometry: GeometryMode
) -> Result<(), GolemError>
Draw the given elements from the element buffer with this shader
The range should fall within the elements of the buffer (which is checked for via an
assert!
.) The GeometryMode determines what the set of indices produces: triangles
consumes 3 vertices into a filled triangle, lines consumes 2 vertices into a thin line,
etc.
The ShaderProgram
must be bound first, see ShaderProgram::bind
.
Safety
The safety concerns to keep in mind:
- The elements in the
ElementBuffer
are not checked against the size of theVertexBuffer
. If they are illegal indices, this will result in out-of-bounds reads on the GPU and therefore undefined behavior. The caller is responsible for ensuring all elements are valid and in-bounds.
pub fn prepare_draw(
&self,
vb: &VertexBuffer,
eb: &ElementBuffer
) -> Result<(), GolemError>
[src]
&self,
vb: &VertexBuffer,
eb: &ElementBuffer
) -> Result<(), GolemError>
Set up a VertexBuffer
and ElementBuffer
to draw multiple times with the same
buffers.
The ShaderProgram
must be bound first, see ShaderProgram::bind
.
See ShaderProgram::draw_prepared
to execute the draw calls. If you're only drawing the
buffers once before replacing their data, see ShaderProgram::draw
.
pub unsafe fn draw_prepared(&self, range: Range<usize>, geometry: GeometryMode)
[src]
Draw the given elements from the prepared element buffer with this shader
This relies on the caller having a valid prepared state: see prepare_draw
.
Safety
The safety concerns to keep in mind:
prepare_draw
must be called before this method, and the buffers passed to it must not have their underlying storage changed. Their values can change, but calls toset_data
may cause them to expand and move to a new memory location on the GPU, invalidating the cal to preparation. Some calls toset_data
are optimized to calls toset_sub_data
; do not rely on this implementation detail.- No other buffers may be operated on between
prepare_draw
anddraw_prepared
. Any calls toset_data
orset_sub_data
from a buffer that wasn't passed toprepare_draw
will result in the wrong buffer being bound whendraw_prepared
is called. - The elements in the prepared buffer must correspond to valid locations within the vertex
buffer. See
draw
for details. - This shader must still be bound (see
bind
)
Trait Implementations
impl Drop for ShaderProgram
[src]
Auto Trait Implementations
impl !RefUnwindSafe for ShaderProgram
impl !Send for ShaderProgram
impl !Sync for ShaderProgram
impl Unpin for ShaderProgram
impl !UnwindSafe for ShaderProgram
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,