shader_set_uniform_f_buffer

With this function you can set the value of a shader uniform to a list of floating point values that are stored in a buffer.

As floats are represented in a buffer using the buffer_f32 data type, this function expects the data in the range given by offset and count to be formatted as consecutive values of this type.

NOTE All uniforms must be set after calling the function shader_set and before calling shader_reset.

Syntax:

shader_set_uniform_f_buffer(uniform, buffer, offset, count);

ArgumentTypeDescription
handleShader Uniform HandleThe handle to the shader uniform as returned by shader_get_uniform
bufferBufferThe buffer to read the values from
offsetRealThe offset (in bytes) in the buffer
countRealThe number of values of type buffer_f32 to be used (see Buffer Data Type Constant)

 

Returns:

N/A

 

Example:

/// Create Event
var _values = 4;
var _size = buffer_sizeof(buffer_f32);
buffer = buffer_create(_values * _size, buffer_fixed, 1);

buffer_write(buffer, buffer_f32, 1);
buffer_write(buffer, buffer_f32, 0.7);
buffer_write(buffer, buffer_f32, 0.9);
buffer_write(buffer, buffer_f32, 1);

uni_blend_colour = shader_get_uniform(shader_Colorize, "u_vBlendColour");


/// Draw Event
shader_set(shader_Colorize);
shader_set_uniform_f_buffer(uni_blend_colour, _buffer, 0, 4);
vertex_submit(global.vb_character, pr_trianglelist, -1);
shader_reset();


/// Clean Up event
buffer_delete(buffer);

The above code first creates a new buffer buffer of a fixed size that has room to store four values (_values) of type buffer_f32. This is done in an object's Create event. Four values between 0 and 1 are then written to the buffer that represent, in order, the R, G, B and A component of a blend colour. After that a handle is retrieved to a uniform vec4 u_vBlendColour; uniform defined in a shader named "shader_Colorize". Next in the Draw event this shader is set, the four values in the buffer are passed to the shader using shader_set_uniform_f_buffer, and the model in a vertex buffer named vb_character is submitted (i.e. drawn). After that the shader is reset. Finally in the Clean Up event the buffer is deleted to avoid a memory leak.