Buffer:setData
EditChanges data in a temporary Buffer using a table or a Blob. Permanent buffers can be changed using Pass:copy
.
Arguments
Name | Type | Default | Description |
data | table | A flat or nested table of items to copy to the Buffer (see notes for format). | |
sourceIndex | number | 1 | The index in the table to copy from. |
destinationIndex | number | 1 | The index of the first value in the Buffer to update. |
count | number | nil |
The number of values to update. nil will copy as many items as possible, based on the lengths of the source and destination.
|
Returns
Nothing
Arguments
Name | Type | Default | Description |
blob | Blob | The Blob to copy data from. | |
sourceOffset | number | 0 | A byte offset into the Blob to copy from. |
destinationOffset | number | 0 | A byte offset in the Buffer to copy to. |
size | number | nil | The number of bytes to copy. If nil, copies as many bytes as possible. |
Returns
Nothing
Notes
When using a table, the table can contain a nested table for each value in the Buffer, or it can be a flat list of field component values. It is not possible to mix both nested tables and flat values.
For each item updated, components of each field in the item (according to the Buffer's format) are read from either the nested subtable or the table itself. A single number can be used to update a field with a scalar type. Multiple numbers or a lovr.math
vector can be used to update a field with a vector or mat4 type. Multiple numbers can be used to update mat2 and mat3 fields. When updating normalized field types, components read from the table will be clamped to the normalized range ([0,1] or [-1,1]). In the Buffer, each field is written at its byte offset according to the Buffer's format, and subsequent items are separated by the byte stride of the Buffer. Any missing components for an updated field will be set to zero.
Example
function lovr.draw(pass)
buffer = lovr.graphics.getBuffer(3, 'floats')
buffer:setData({ { 1.0 }, { 2.0 }, { 3.0 } })
buffer:setData({ 1.0, 2.0, 3.0 })
buffer = lovr.graphics.getBuffer(5, { 'vec3', 'vec3', 'vec2' })
buffer:setData({ vec3(1, 2, 3), vec3(4, 5, 6), vec2(7, 8) })
buffer:setData({ { 1, 2, 3, 4, 5, 6, 7, 8 } })
buffer:setData({ 1, 2, 3, 4, 5, 6, 7, 8 })
buffer:setData({
{ x1, y1, z1, nx1, ny1, nz1, u1, v1 },
{ x2, y2, z2, vec3(nx, ny, nz) }
}, 1, 3, 2)
end
See also
Pass:copy
Buffer